Leviathan  0.8.0.0
Leviathan game engine
Leviathan::BasicPool< ElementType > Class Template Reference

A tiny wrapper around boost pool. More...

#include <ObjectPool.h>

Public Member Functions

 BasicPool ()
 
 ~BasicPool ()
 
template<typename... Args>
ElementType * ConstructNew (Args &&... args)
 Constructs a new component of the held type for entity. More...
 
void Destroy (ElementType *element)
 Destroys a created element. More...
 

Protected Attributes

boost::pool Elements
 Pool for objects. More...
 

Detailed Description

template<class ElementType>
class Leviathan::BasicPool< ElementType >

A tiny wrapper around boost pool.

Definition at line 22 of file ObjectPool.h.

Constructor & Destructor Documentation

◆ BasicPool()

template<class ElementType>
Leviathan::BasicPool< ElementType >::BasicPool ( )
inline

Definition at line 24 of file ObjectPool.h.

24 : Elements(sizeof(ElementType), 16) {}
boost::pool Elements
Pool for objects.
Definition: ObjectPool.h:63

◆ ~BasicPool()

template<class ElementType>
Leviathan::BasicPool< ElementType >::~BasicPool ( )
inline

Definition at line 26 of file ObjectPool.h.

26 {}

Member Function Documentation

◆ ConstructNew()

template<class ElementType>
template<typename... Args>
ElementType* Leviathan::BasicPool< ElementType >::ConstructNew ( Args &&...  args)
inline

Constructs a new component of the held type for entity.

Exceptions
Exceptionwhen component has not been created

Definition at line 31 of file ObjectPool.h.

32  {
33 
34  // Get memory to hold the object //
35  void* memoryForObject = Elements.malloc();
36 
37  if(!memoryForObject)
38  throw Exception("Out of memory for element");
39 
40  // Construct the object //
41  ElementType* created;
42  try {
43  created = new(memoryForObject) ElementType(std::forward<Args>(args)...);
44  } catch(...) {
45 
46  Elements.free(memoryForObject);
47  throw;
48  }
49 
50  return created;
51  }
boost::pool Elements
Pool for objects.
Definition: ObjectPool.h:63

◆ Destroy()

template<class ElementType>
void Leviathan::BasicPool< ElementType >::Destroy ( ElementType *  element)
inline

Destroys a created element.

Definition at line 54 of file ObjectPool.h.

55  {
56 
57  element->~ElementType();
58  Elements.free(element);
59  }
boost::pool Elements
Pool for objects.
Definition: ObjectPool.h:63

Member Data Documentation

◆ Elements

template<class ElementType>
boost::pool Leviathan::BasicPool< ElementType >::Elements
protected

Pool for objects.

Definition at line 63 of file ObjectPool.h.


The documentation for this class was generated from the following file: