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 24 of file ObjectPool.h.

Constructor & Destructor Documentation

◆ BasicPool()

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

Definition at line 26 of file ObjectPool.h.

28  :
29  Elements(sizeof(ElementType), 16)
30 #endif // LEVIATHAN_USE_ACTUAL_OBJECT_POOLS
31  {}
boost::pool Elements
Pool for objects.
Definition: ObjectPool.h:85

◆ ~BasicPool()

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

Definition at line 33 of file ObjectPool.h.

33 {}

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 40 of file ObjectPool.h.

41  {
42  // Get memory to hold the object //
43  void* memoryForObject = Elements.malloc();
44 
45  if(!memoryForObject)
46  throw Exception("Out of memory for element");
47 
48  // Construct the object //
49  ElementType* created;
50  try {
51  created = new(memoryForObject) ElementType(std::forward<Args>(args)...);
52  } catch(...) {
53 
54  Elements.free(memoryForObject);
55  throw;
56  }
57 
58  return created;
59  }
boost::pool Elements
Pool for objects.
Definition: ObjectPool.h:85

◆ Destroy()

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

Destroys a created element.

Definition at line 62 of file ObjectPool.h.

63  {
64 
65  element->~ElementType();
66  Elements.free(element);
67  }
boost::pool Elements
Pool for objects.
Definition: ObjectPool.h:85

Member Data Documentation

◆ Elements

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

Pool for objects.

Definition at line 85 of file ObjectPool.h.


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