diff --git a/Control/AthContainers/AthContainers/tools/AuxTypeVectorFactory.h b/Control/AthContainers/AthContainers/tools/AuxTypeVectorFactory.h index 73ffb9bd3c0b7ec8d28a0895c86155a5337d385c..0192b0c8eaa1f8e7b07a80a3ca7fcb9e19b7868c 100644 --- a/Control/AthContainers/AthContainers/tools/AuxTypeVectorFactory.h +++ b/Control/AthContainers/AthContainers/tools/AuxTypeVectorFactory.h @@ -1,10 +1,7 @@ // This file's extension implies that it's C, but it's really -*- C++ -*-. - /* - Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration */ - -// $Id$ /** * @file AthContainers/tools/AuxTypeVectorFactory.h * @author scott snyder <snyder@bnl.gov> @@ -30,7 +27,7 @@ namespace SG { * This is an implementation of @c IAuxTypeVectorFactory that makes * vectors using the @c AuxTypeVector implementation. */ -template <class T> +template <class T, class ALLOC = std::allocator<T> > class AuxTypeVectorFactory : public IAuxTypeVectorFactory { diff --git a/Control/AthContainers/AthContainers/tools/AuxTypeVectorFactory.icc b/Control/AthContainers/AthContainers/tools/AuxTypeVectorFactory.icc index a858db038888e1ef6488c89b2faed4688b893704..e5ad07be5053c7c8e87ae971cf4717582839f3c5 100644 --- a/Control/AthContainers/AthContainers/tools/AuxTypeVectorFactory.icc +++ b/Control/AthContainers/AthContainers/tools/AuxTypeVectorFactory.icc @@ -17,11 +17,11 @@ namespace SG { * @param size Initial size of the new vector. * @param capacity Initial capacity of the new vector. */ -template <class T> +template <class T, class ALLOC> std::unique_ptr<IAuxTypeVector> -AuxTypeVectorFactory<T>::create (size_t size, size_t capacity) const +AuxTypeVectorFactory<T, ALLOC>::create (size_t size, size_t capacity) const { - return std::make_unique<AuxTypeVector<T> > (size, capacity); + return std::make_unique<AuxTypeVector<T, ALLOC> > (size, capacity); } @@ -34,22 +34,23 @@ AuxTypeVectorFactory<T>::create (size_t size, size_t capacity) const * * This is for types which are packable. */ -template <class T> +template <class T, class ALLOC> std::unique_ptr<IAuxTypeVector> -AuxTypeVectorFactory<T>::createFromData (void* data, - bool isPacked, - bool ownFlag, - std::true_type) const +AuxTypeVectorFactory<T, ALLOC>::createFromData (void* data, + bool isPacked, + bool ownFlag, + std::true_type) const { if (isPacked) { - typedef typename SG::AuxDataTraits<T>::vector_type unpacked_vector_type; - typedef typename unpacked_vector_type::value_type element_type; - typedef SG::PackedContainer<element_type> vector_type; + using unpacked_vector_type = typename SG::AuxDataTraits<T, ALLOC>::vector_type; + using element_type = typename unpacked_vector_type::value_type; + using unpacked_vector_allocator_type = typename SG::AuxDataTraits<T, ALLOC>::allocator_type; + using vector_type = SG::PackedContainer<element_type, unpacked_vector_allocator_type>; return std::make_unique<AuxTypeVectorHolder<T, vector_type > > (reinterpret_cast<vector_type*>(data), ownFlag); } else { - using vector_type = typename SG::AuxDataTraits<T>::vector_type; + using vector_type = typename SG::AuxDataTraits<T, ALLOC>::vector_type; return std::make_unique<AuxTypeVectorHolder<T, vector_type> > (reinterpret_cast<vector_type*>(data), true); } } @@ -64,15 +65,15 @@ AuxTypeVectorFactory<T>::createFromData (void* data, * * This is for types which are not packable. */ -template <class T> +template <class T, class ALLOC> std::unique_ptr<IAuxTypeVector> -AuxTypeVectorFactory<T>::createFromData (void* data, - bool isPacked, - bool ownFlag, - std::false_type) const +AuxTypeVectorFactory<T, ALLOC>::createFromData (void* data, + bool isPacked, + bool ownFlag, + std::false_type) const { if (isPacked) std::abort(); - using vector_type = typename SG::AuxDataTraits<T>::vector_type; + using vector_type = typename SG::AuxDataTraits<T, ALLOC>::vector_type; return std::make_unique<AuxTypeVectorHolder<T, vector_type> > (reinterpret_cast<vector_type*>(data), ownFlag); } @@ -92,11 +93,11 @@ AuxTypeVectorFactory<T>::createFromData (void* data, * * Returns a newly-allocated object. */ -template <class T> +template <class T, class ALLOC> std::unique_ptr<IAuxTypeVector> -AuxTypeVectorFactory<T>::createFromData (void* data, - bool isPacked, - bool ownFlag) const +AuxTypeVectorFactory<T, ALLOC>::createFromData (void* data, + bool isPacked, + bool ownFlag) const { return createFromData (data, isPacked, ownFlag, typename DataModel_detail::can_pack<T>::type()); @@ -112,11 +113,11 @@ AuxTypeVectorFactory<T>::createFromData (void* data, * * @c dst and @ src can be either the same or different. */ -template <class T> -void AuxTypeVectorFactory<T>::copy (void* dst, size_t dst_index, - const void* src, size_t src_index) const +template <class T, class ALLOC> +void AuxTypeVectorFactory<T, ALLOC>::copy (void* dst, size_t dst_index, + const void* src, size_t src_index) const { - return AuxTypeVector<T>::copy (dst, dst_index, src, src_index); + return AuxTypeVector<T, ALLOC>::copy (dst, dst_index, src, src_index); } @@ -129,11 +130,11 @@ void AuxTypeVectorFactory<T>::copy (void* dst, size_t dst_index, * * @c dst and @ src can be either the same or different. */ -template <class T> -void AuxTypeVectorFactory<T>::copyForOutput (void* dst, size_t dst_index, - const void* src, size_t src_index) const +template <class T, class ALLOC> +void AuxTypeVectorFactory<T, ALLOC>::copyForOutput (void* dst, size_t dst_index, + const void* src, size_t src_index) const { - return AuxTypeVector<T>::copyForOutput (dst, dst_index, src, src_index); + return AuxTypeVector<T, ALLOC>::copyForOutput (dst, dst_index, src, src_index); } @@ -146,11 +147,11 @@ void AuxTypeVectorFactory<T>::copyForOutput (void* dst, size_t dst_index, * * @c a and @ b can be either the same or different. */ -template <class T> -void AuxTypeVectorFactory<T>::swap (void* a, size_t aindex, - void* b, size_t bindex) const +template <class T, class ALLOC> +void AuxTypeVectorFactory<T, ALLOC>::swap (void* a, size_t aindex, + void* b, size_t bindex) const { - return AuxTypeVector<T>::swap (a, aindex, b, bindex); + return AuxTypeVector<T, ALLOC>::swap (a, aindex, b, bindex); } @@ -159,30 +160,30 @@ void AuxTypeVectorFactory<T>::swap (void* a, size_t aindex, * @param dst Pointer to the start of the vector's data. * @param dst_index Index of the element in the vector. */ -template <class T> -void AuxTypeVectorFactory<T>::clear (void* dst, size_t dst_index) const +template <class T, class ALLOC> +void AuxTypeVectorFactory<T, ALLOC>::clear (void* dst, size_t dst_index) const { - return AuxTypeVector<T>::clear (dst, dst_index); + return AuxTypeVector<T, ALLOC>::clear (dst, dst_index); } /** * @brief Return the size of an element of this vector type. */ -template <class T> -size_t AuxTypeVectorFactory<T>::getEltSize() const +template <class T, class ALLOC> +size_t AuxTypeVectorFactory<T, ALLOC>::getEltSize() const { - return sizeof (typename AuxTypeVector<T>::vector_type::value_type); + return sizeof (typename AuxTypeVector<T, ALLOC>::vector_type::value_type); } /** * @brief Return the @c type_info of the vector. */ -template <class T> -const std::type_info* AuxTypeVectorFactory<T>::tiVec() const +template <class T, class ALLOC> +const std::type_info* AuxTypeVectorFactory<T, ALLOC>::tiVec() const { - return &typeid (typename AuxTypeVector<T>::vector_type); + return &typeid (typename AuxTypeVector<T, ALLOC>::vector_type); } @@ -191,8 +192,8 @@ const std::type_info* AuxTypeVectorFactory<T>::tiVec() const * emulation (via @c TVirtualCollectionProxy or similar); false * if the std::vector code is used directly. */ -template <class T> -bool AuxTypeVectorFactory<T>::isDynamic() const +template <class T, class ALLOC> +bool AuxTypeVectorFactory<T, ALLOC>::isDynamic() const { return false; } diff --git a/Control/AthContainers/test/AuxTypeVectorFactory_test.cxx b/Control/AthContainers/test/AuxTypeVectorFactory_test.cxx index 28f560d61ba1a060b77b61260276edda40b2f3d4..85058be5866432107f74be24e7c2182698ebac49 100644 --- a/Control/AthContainers/test/AuxTypeVectorFactory_test.cxx +++ b/Control/AthContainers/test/AuxTypeVectorFactory_test.cxx @@ -13,6 +13,7 @@ #include "AthContainers/tools/AuxTypeVectorFactory.h" +#include "TestTools/TestAlloc.h" #include <iostream> #include <cassert> @@ -30,16 +31,16 @@ T makeT(int x=0) { return T(x); } bool makeT(int x=0) { return (x&1) != 0; } -template <class T> +template <class T, template<typename> class ALLOC = std::allocator> void test_vector() { - SG::AuxTypeVectorFactory<T> fac; + SG::AuxTypeVectorFactory<T, ALLOC<T> > fac; assert (fac.getEltSize() == sizeof(T)); assert (!fac.isDynamic()); if (typeid(T) == typeid(bool)) - assert (fac.tiVec() == &typeid (std::vector<char>)); + assert (fac.tiVec() == &typeid (std::vector<char, ALLOC<char> >)); else - assert (fac.tiVec() == &typeid (std::vector<T>)); + assert (fac.tiVec() == &typeid (std::vector<T, ALLOC<T> >)); std::unique_ptr<SG::IAuxTypeVector> v = fac.create (10, 20); T* ptr = reinterpret_cast<T*> (v->toPtr()); @@ -66,7 +67,7 @@ void test_vector() assert (ptr2[0] == makeT()); assert (ptr2[1] == makeT(11)); - using vector_type = typename SG::AuxDataTraits<T>::vector_type; + using vector_type = typename SG::AuxDataTraits<T, ALLOC<T> >::vector_type; vector_type* vec3 = new vector_type; vec3->push_back (makeT(3)); vec3->push_back (makeT(2)); @@ -80,11 +81,11 @@ void test_vector() } -template <class T> +template <class T, template<typename> class ALLOC = std::allocator> void test_vector2() { - SG::AuxTypeVectorFactory<T> fac; - SG::PackedContainer<T>* vec4 = new SG::PackedContainer<T>; + SG::AuxTypeVectorFactory<T, ALLOC<T> > fac; + auto vec4 = new SG::PackedContainer<T, ALLOC<T> >; vec4->push_back (makeT(4)); vec4->push_back (makeT(3)); vec4->push_back (makeT(2)); @@ -107,6 +108,12 @@ void test1() test_vector<bool>(); test_vector<float>(); test_vector2<float>(); + + test_vector<int, Athena_test::TestAlloc>(); + test_vector2<int, Athena_test::TestAlloc>(); + test_vector<bool, Athena_test::TestAlloc>(); + test_vector<float, Athena_test::TestAlloc>(); + test_vector2<float, Athena_test::TestAlloc>(); }