A factory to create and destroy shared objects. More...
#include <Factory.h>
Public Types | |
typedef C(* | constructor )(K key) |
Function pointer to the factory objects constructor. | |
Public Member Functions | |
Factory (constructor ctor) | |
Creates a factory that creates objects from keys with the given constructor function. | |
C | get (K key) |
Returns the object corresponding to the given key. | |
void | put (K key) |
Releases the object corresponding to the given key. |
A factory to create and destroy shared objects.
Each object is constructed from a key, and is destructed when it is no longer used. Clients of this factory must call get to get the object corresponding to a given key, and must call put when this object is no longer used. The object will be destroyed automatically when all clients have called put (if this object is managed via smart pointers).
typedef C(* ork::Factory< K, C >::constructor)(K key) |
Function pointer to the factory objects constructor.
ork::Factory< K, C >::Factory | ( | constructor | ctor | ) | [inline] |
Creates a factory that creates objects from keys with the given constructor function.
ctor | a constructor function. |
C ork::Factory< K, C >::get | ( | K | key | ) | [inline] |
Returns the object corresponding to the given key.
If this object does not exist yet it is created with the constructor function of this factory. Otherwise a reference counter is incremented to know when this object is no longer used.
void ork::Factory< K, C >::put | ( | K | key | ) | [inline] |
Releases the object corresponding to the given key.
If the reference count of this object becomes 0, the object is automatically destroyed.