Emergency 2017 Dokumentation  v3.0.1
qsf::ElementManager< KEY, ELEMENT, ALLOCATOR, ID_GENERATOR > Class Template Reference

Element manager class template. More...

#include <ElementManager.h>

Public Types

typedef boost::container::flat_map< KEY, ELEMENT * > ElementMap
 

Public Member Functions

 ElementManager ()
 Default constructor. More...
 
virtual ~ElementManager ()
 Destructor. More...
 
const ElementMapgetElements () const
 Return map of elements. More...
 
ELEMENT * findElement (const KEY &key) const
 Find a specific element by its key in either the element map. More...
 
void reserveElements (size_t numberOfElements)
 Reserve elements. More...
 
ELEMENT * createElement ()
 Create a new element. More...
 
ELEMENT * createElementById (const KEY &key)
 Create a new element with an enforced given unique element identifier. More...
 
bool insertElement (const KEY &key, ELEMENT &element)
 Insert an element with an enforced given unique element identifier. More...
 
bool destroyElement (const KEY &key)
 Destroy an element by its key. More...
 
ElementManager< KEY, ELEMENT, ALLOCATOR, ID_GENERATOR >::ElementMap::iterator destroyElement (typename ElementMap::iterator iterator)
 Destroy an element by iterator. More...
 
void destroyAllElements ()
 Destroy all elements. More...
 
ELEMENT * grabElement (const KEY &key)
 Remove an element from the element manager without destroying it. More...
 
KEY generateId ()
 Generate a new, unused key. More...
 

Protected Member Functions

ElementMapgetElementsWritable ()
 Return map of elements. More...
 
virtual void onElementInsertion (const KEY &key, ELEMENT &element)
 Called whenever an element is inserted into the element map. More...
 
virtual void onElementRemoval (const KEY &key, ELEMENT &element)
 Called whenever an element is actually going to be destroyed. More...
 
- Protected Member Functions inherited from qsf::Manager
 Manager ()
 Default constructor. More...
 
virtual ~Manager ()
 Destructor. More...
 

Detailed Description

template<typename KEY, typename ELEMENT, typename ALLOCATOR = detail::DirectAllocator<ELEMENT>, typename ID_GENERATOR = ConsecutiveIdGenerator<KEY>>
class qsf::ElementManager< KEY, ELEMENT, ALLOCATOR, ID_GENERATOR >

Element manager class template.

Remarks
This template implements a manager of elements mapped by a key (e.g. an integer ID or similar). The element manager is responsible for the creation and destruction of the elements managed by it.

Definition at line 71 of file ElementManager.h.

Member Typedef Documentation

template<typename KEY, typename ELEMENT, typename ALLOCATOR = detail::DirectAllocator<ELEMENT>, typename ID_GENERATOR = ConsecutiveIdGenerator<KEY>>
typedef boost::container::flat_map<KEY, ELEMENT*> qsf::ElementManager< KEY, ELEMENT, ALLOCATOR, ID_GENERATOR >::ElementMap

Definition at line 79 of file ElementManager.h.

Constructor & Destructor Documentation

template<typename KEY, typename ELEMENT, typename ALLOCATOR = detail::DirectAllocator<ELEMENT>, typename ID_GENERATOR = ConsecutiveIdGenerator<KEY>>
TEMPLATE_DEFINITION qsf::ElementManager< KEY, ELEMENT, ALLOCATOR, ID_GENERATOR >::ElementManager ( )

Default constructor.

Definition at line 23 of file ElementManager-inl.h.

template<typename KEY, typename ELEMENT, typename ALLOCATOR = detail::DirectAllocator<ELEMENT>, typename ID_GENERATOR = ConsecutiveIdGenerator<KEY>>
TEMPLATE_DEFINITION qsf::ElementManager< KEY, ELEMENT, ALLOCATOR, ID_GENERATOR >::~ElementManager ( )
virtual

Destructor.

Definition at line 28 of file ElementManager-inl.h.

Member Function Documentation

template<typename KEY, typename ELEMENT, typename ALLOCATOR = detail::DirectAllocator<ELEMENT>, typename ID_GENERATOR = ConsecutiveIdGenerator<KEY>>
TEMPLATE_DEFINITION ELEMENT * qsf::ElementManager< KEY, ELEMENT, ALLOCATOR, ID_GENERATOR >::createElement ( )

Create a new element.

Returns
The created element instance, null pointer on error, do no destroy the returned instance and do need keep a reference to it outside the C runtime stack (use the unique element ID instead)

Definition at line 51 of file ElementManager-inl.h.

template<typename KEY, typename ELEMENT, typename ALLOCATOR = detail::DirectAllocator<ELEMENT>, typename ID_GENERATOR = ConsecutiveIdGenerator<KEY>>
TEMPLATE_DEFINITION ELEMENT * qsf::ElementManager< KEY, ELEMENT, ALLOCATOR, ID_GENERATOR >::createElementById ( const KEY &  key)

Create a new element with an enforced given unique element identifier.

Parameters
[in]keyKey of the element to insert
Returns
The created element instance, null pointer on error, do no destroy the returned instance and do need keep a reference to it outside the C runtime stack (use the unique element ID instead)
Note
  • Use "createElement()" instead of "createElementById()" whenever possible, do not enforce unique element identifier if you can avoid it

Definition at line 69 of file ElementManager-inl.h.

template<typename KEY, typename ELEMENT, typename ALLOCATOR = detail::DirectAllocator<ELEMENT>, typename ID_GENERATOR = ConsecutiveIdGenerator<KEY>>
TEMPLATE_DEFINITION void qsf::ElementManager< KEY, ELEMENT, ALLOCATOR, ID_GENERATOR >::destroyAllElements ( )

Destroy all elements.

Definition at line 141 of file ElementManager-inl.h.

template<typename KEY, typename ELEMENT, typename ALLOCATOR = detail::DirectAllocator<ELEMENT>, typename ID_GENERATOR = ConsecutiveIdGenerator<KEY>>
TEMPLATE_DEFINITION bool qsf::ElementManager< KEY, ELEMENT, ALLOCATOR, ID_GENERATOR >::destroyElement ( const KEY &  key)

Destroy an element by its key.

Parameters
[in]keyKey of the element to destroy
Returns
"true" if all went fine, else "false"

Definition at line 110 of file ElementManager-inl.h.

template<typename KEY, typename ELEMENT, typename ALLOCATOR = detail::DirectAllocator<ELEMENT>, typename ID_GENERATOR = ConsecutiveIdGenerator<KEY>>
TEMPLATE_DEFINITION ElementManager< KEY, ELEMENT, ALLOCATOR, ID_GENERATOR >::ElementMap::iterator qsf::ElementManager< KEY, ELEMENT, ALLOCATOR, ID_GENERATOR >::destroyElement ( typename ElementMap::iterator  iterator)

Destroy an element by iterator.

Parameters
[in]iteratorIterator pointing to the element to destroy
Returns
Updated iterator

Definition at line 131 of file ElementManager-inl.h.

template<typename KEY, typename ELEMENT, typename ALLOCATOR = detail::DirectAllocator<ELEMENT>, typename ID_GENERATOR = ConsecutiveIdGenerator<KEY>>
TEMPLATE_DEFINITION ELEMENT * qsf::ElementManager< KEY, ELEMENT, ALLOCATOR, ID_GENERATOR >::findElement ( const KEY &  key) const

Find a specific element by its key in either the element map.

Returns
Specific element, null pointer on error, do not destroy the instance

Definition at line 39 of file ElementManager-inl.h.

template<typename KEY, typename ELEMENT, typename ALLOCATOR = detail::DirectAllocator<ELEMENT>, typename ID_GENERATOR = ConsecutiveIdGenerator<KEY>>
TEMPLATE_DEFINITION KEY qsf::ElementManager< KEY, ELEMENT, ALLOCATOR, ID_GENERATOR >::generateId ( )

Generate a new, unused key.

Returns
The new key

Definition at line 180 of file ElementManager-inl.h.

template<typename KEY, typename ELEMENT, typename ALLOCATOR = detail::DirectAllocator<ELEMENT>, typename ID_GENERATOR = ConsecutiveIdGenerator<KEY>>
TEMPLATE_DEFINITION const ElementManager< KEY, ELEMENT, ALLOCATOR, ID_GENERATOR >::ElementMap & qsf::ElementManager< KEY, ELEMENT, ALLOCATOR, ID_GENERATOR >::getElements ( ) const

Return map of elements.

Returns
Map of elements, do not destroy the instance

Definition at line 34 of file ElementManager-inl.h.

template<typename KEY, typename ELEMENT, typename ALLOCATOR = detail::DirectAllocator<ELEMENT>, typename ID_GENERATOR = ConsecutiveIdGenerator<KEY>>
TEMPLATE_DEFINITION ElementManager< KEY, ELEMENT, ALLOCATOR, ID_GENERATOR >::ElementMap & qsf::ElementManager< KEY, ELEMENT, ALLOCATOR, ID_GENERATOR >::getElementsWritable ( )
protected

Return map of elements.

Returns
Map of elements, do not destroy the instance

Definition at line 189 of file ElementManager-inl.h.

template<typename KEY, typename ELEMENT, typename ALLOCATOR = detail::DirectAllocator<ELEMENT>, typename ID_GENERATOR = ConsecutiveIdGenerator<KEY>>
TEMPLATE_DEFINITION ELEMENT * qsf::ElementManager< KEY, ELEMENT, ALLOCATOR, ID_GENERATOR >::grabElement ( const KEY &  key)

Remove an element from the element manager without destroying it.

Parameters
[in]keyKey of the element to insert
Returns
The element to grab, or null pointer if none was found under this key; you are responsible for destroying the instance

Definition at line 157 of file ElementManager-inl.h.

template<typename KEY, typename ELEMENT, typename ALLOCATOR = detail::DirectAllocator<ELEMENT>, typename ID_GENERATOR = ConsecutiveIdGenerator<KEY>>
TEMPLATE_DEFINITION bool qsf::ElementManager< KEY, ELEMENT, ALLOCATOR, ID_GENERATOR >::insertElement ( const KEY &  key,
ELEMENT &  element 
)

Insert an element with an enforced given unique element identifier.

Parameters
[in]keyKey of the element to insert
[in]elementThe element to insert; ownership is transferred to the element manager, so do no destroy the instance and do need keep a reference to it outside the C runtime stack (use the unique element ID instead)
Returns
"true" if insertion succeeds, "false" if the given key is already in use
Note
  • Use "createElement()" instead of "insertElement()" whenever possible, do not enforce unique element identifier if you can avoid it
  • Use this method in case you have to use your own construction process for elements, e.g. if you need to create sub-class instances of the ELEMENT class
  • You have to take care of assigning the given key to the element yourself

Definition at line 90 of file ElementManager-inl.h.

template<typename KEY, typename ELEMENT, typename ALLOCATOR = detail::DirectAllocator<ELEMENT>, typename ID_GENERATOR = ConsecutiveIdGenerator<KEY>>
TEMPLATE_DEFINITION void qsf::ElementManager< KEY, ELEMENT, ALLOCATOR, ID_GENERATOR >::onElementInsertion ( const KEY &  key,
ELEMENT &  element 
)
protectedvirtual

Called whenever an element is inserted into the element map.

Parameters
[in]keyKey of the inserted element
[in]elementInserted element
Note
  • The default implementation is empty

Definition at line 198 of file ElementManager-inl.h.

template<typename KEY, typename ELEMENT, typename ALLOCATOR = detail::DirectAllocator<ELEMENT>, typename ID_GENERATOR = ConsecutiveIdGenerator<KEY>>
TEMPLATE_DEFINITION void qsf::ElementManager< KEY, ELEMENT, ALLOCATOR, ID_GENERATOR >::onElementRemoval ( const KEY &  key,
ELEMENT &  element 
)
protectedvirtual

Called whenever an element is actually going to be destroyed.

Parameters
[in]keyKey of the destroyed element
[in]elementDestroyed element
Note
  • The default implementation is empty

Definition at line 203 of file ElementManager-inl.h.

template<typename KEY, typename ELEMENT, typename ALLOCATOR = detail::DirectAllocator<ELEMENT>, typename ID_GENERATOR = ConsecutiveIdGenerator<KEY>>
TEMPLATE_DEFINITION void qsf::ElementManager< KEY, ELEMENT, ALLOCATOR, ID_GENERATOR >::reserveElements ( size_t  numberOfElements)

Reserve elements.

Parameters
[in]numberOfElementsNumber of elements to reserve
Note
  • You might want to reserve elements before starting an insertion of element masses (performance)

Definition at line 46 of file ElementManager-inl.h.


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