15 #ifndef DETECTORGRAPH_INCLUDE_STATICTYPEDALLOCATOR_LITE_HPP_ 16 #define DETECTORGRAPH_INCLUDE_STATICTYPEDALLOCATOR_LITE_HPP_ 70 struct DefaultStaticTypedAllocatorCtxt {};
73 template<
class TBase,
class Ctxt = DefaultStaticTypedAllocatorCtxt>
78 NodeHeader(uint8_t* aStorage)
80 , next(NULL), busy(
false)
87 return reinterpret_cast<TBase*
>(storage);
105 template <
class TChild,
typename... TChildArgs>
106 #if defined(BUILD_FEATURE_DETECTORGRAPH_CONFIG_PERFECT_FORWARDING) 107 TChild* New(TChildArgs&&... constructor_args)
109 TChild*
New(TChildArgs&... constructor_args)
112 NodeHeader* node = GetNodeHeader<TChild>();
117 #if defined(BUILD_FEATURE_DETECTORGRAPH_CONFIG_PERFECT_FORWARDING) 119 new(node->storage) TChild(std::forward<TChildArgs>(constructor_args)...);
122 new(node->storage) TChild(constructor_args...);
139 NodeHeader** fromPtr = &mHeadNode;
142 NodeHeader* nodeIt = mHeadNode;
145 TBase* storedObject = nodeIt->GetObjectPtr();
147 while(nodeIt && storedObject != targetObject)
150 fromPtr = &(nodeIt->next);
151 nodeIt = nodeIt->next;
152 storedObject = nodeIt->GetObjectPtr();
158 *fromPtr = nodeIt->next;
161 storedObject->~TBase();
164 nodeIt->busy =
false;
174 NodeHeader* nodeIt = mHeadNode;
177 TBase* storedObject = nodeIt->GetObjectPtr();
178 storedObject->~TBase();
179 nodeIt->busy =
false;
181 NodeHeader* tmp = nodeIt;
182 nodeIt = nodeIt->next;
194 void LinkNode(NodeHeader* node)
199 NodeHeader** nextPtr = &mHeadNode;
202 nextPtr = &((*nextPtr)->next);
211 NodeHeader* mHeadNode;
213 template<
class TChild>
214 NodeHeader* GetNodeHeader()
216 static uint8_t mNodeStorage[
sizeof(TChild)];
217 static NodeHeader node = NodeHeader(mNodeStorage);
224 #endif // DETECTORGRAPH_INCLUDE_STATICTYPEDALLOCATOR_LITE_HPP_
TChild * New(TChildArgs &... constructor_args)
Constructs & Allocates new object of type TChild with arguments.
void Delete(TBase *targetObject)
Deletes/Frees an allocated object via the base ptr.
void clear()
Deletes all allocated objects.
#define DG_ASSERT(condition)