Emergency 20 Dokumentation  4.1.0
Public Types | Public Member Functions | Protected Member Functions | List of all members
qsf::ElementManager< KEY, ELEMENT, ALLOCATOR, ID_GENERATOR > Class Template Reference

Element manager class template. More...

#include <ElementManager.h>

Inheritance diagram for qsf::ElementManager< KEY, ELEMENT, ALLOCATOR, ID_GENERATOR >:
Inheritance graph
[legend]
Collaboration diagram for qsf::ElementManager< KEY, ELEMENT, ALLOCATOR, ID_GENERATOR >:
Collaboration graph
[legend]

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.

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

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.

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.

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)
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
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.

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"
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
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
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
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
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
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
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
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
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
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)

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