2 Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
5 * @file AthAllocators/ArenaHandleBaseAllocT.icc
8 * @brief Base class for @c Handle classes, containing parts that
9 * depend only on the Allocator.
10 * Inline and template implementations.
19 * @param name Name of the Allocator.
20 * @param makeFunc Function that creates an Allocator given a set of parameters.
21 * @param params Allocator parameters.
23 * This initializes the @c Creator for creating an Allocator.
24 * The name in @c params will be replaced with the @c name argument.
26 template <typename ALLOC>
27 ArenaHandleBaseAllocT<ALLOC>::Creator::Creator (const std::string& name,
29 const typename ALLOC::Params& params)
30 : m_makeFunc (makeFunc),
38 * @brief Create an allocator instance.
40 template <typename ALLOC>
41 std::unique_ptr<ArenaAllocatorBase>
42 ArenaHandleBaseAllocT<ALLOC>::Creator::create()
44 return m_makeFunc (m_params);
49 * @brief Return the name of the Allocator we create.
51 template <typename ALLOC>
53 ArenaHandleBaseAllocT<ALLOC>::Creator::name() const
60 * @brief Constructor, passing in an index.
61 * @param header The group of Arenas which this Handle may reference.
62 * May be null to select the global default.
63 * @param index The index of this Handle's Allocator type.
65 template <typename ALLOC>
66 ArenaHandleBaseAllocT<ALLOC>::ArenaHandleBaseAllocT
67 (ArenaHeader* header, size_t index)
68 : ArenaHandleBase (header, index)
74 * @brief Constructor, passing in an index, for a specific event slot.
75 * @param header The group of Arenas which this Handle may reference.
76 * May be null to select the global default.
77 * @param ctx Event context identifying the event slot.
78 * @param index The index of this Handle's Allocator type.
80 template <typename ALLOC>
81 ArenaHandleBaseAllocT<ALLOC>::ArenaHandleBaseAllocT (ArenaHeader* header,
82 const EventContext& ctx,
84 : ArenaHandleBase (header, ctx, index)
90 * @brief Constructor, passing in an index, for a specific Arena.
91 * @param arena The Arena in which to find the allocator.
92 * @param index The index of this Handle's Allocator type.
94 template <typename ALLOC>
95 ArenaHandleBaseAllocT<ALLOC>::ArenaHandleBaseAllocT (ArenaBase* arena, size_t index)
96 : ArenaHandleBase (arena, index)
102 * @brief Return our Allocator's parameters.
104 template <typename ALLOC>
105 const typename ALLOC::Params&
106 ArenaHandleBaseAllocT<ALLOC>::params() const
108 const ALLOC* alloc = dynamic_cast<const ALLOC*>(this->baseAllocator());
109 if (!alloc) std::abort();
110 return alloc->params();
115 * @brief Return our current Allocator.
117 * This is on the fast path for allocation. It should be kept
120 template <typename ALLOC>
122 ALLOC* ArenaHandleBaseAllocT<ALLOC>::allocator()
124 return reinterpret_cast<ALLOC*> (this->baseAllocator());
129 * @brief Return our current Allocator.
131 * This is on the fast path for allocation. It should be kept
134 template <typename ALLOC>
136 const ALLOC* ArenaHandleBaseAllocT<ALLOC>::allocator() const
138 return reinterpret_cast<const ALLOC*> (this->baseAllocator());
143 * @brief Find the index for creating an allocator.
144 * @param params Pointer to the supplied parameters.
145 * If null, use the result of DEFPARAMS().
147 * We look up in the registry the Allocator name we get from @c params
148 * (if this is blank, a name is derived from @c ALLOC).
149 * If not found, then we register Allocator and return the new index.
151 template <typename ALLOC>
152 template <class HANDLE, class DEFPARAMS>
154 ArenaHandleBaseAllocT<ALLOC>::makeIndex (const typename ALLOC::Params* params)
156 ArenaAllocatorRegistry* reg = ArenaAllocatorRegistry::instance();
162 const static std::string sname = System::typeinfoName (typeid (HANDLE));
165 size_t i = reg->lookup (name);
166 if (i != std::string::npos)
168 return reg->registerCreator (name,
169 std::make_unique<Creator> (name,
170 HANDLE::makeAllocator,
171 params ? *params : DEFPARAMS()));