A generic factory class. More...
#include <factory.hpp>
Classes | |
class | default_producer |
Default producer class for factory. More... | |
class | producer_base |
Base producer class for factory. More... | |
Public Types | |
typedef K | key_type |
typedef V | value_type |
typedef std::tr1::shared_ptr < producer_base > | producer_ptr |
typedef std::map< key_type, producer_ptr > | container_t |
typedef container_t::size_type | size_type |
typedef container_t::iterator | iterator |
typedef container_t::const_iterator | const_iterator |
Public Member Functions | |
factory () | |
std::pair< iterator, bool > | insert (const key_type &key, producer_base *p) |
size_type | erase (const key_type &key) |
value_type * | create (const key_type &key) const |
iterator | begin () |
const_iterator | begin () const |
iterator | end () |
const_iterator | end () const |
bool | empty () const |
size_type | size () const |
size_type | count (const key_type &key) const |
iterator | find (const key_type &key) |
const_iterator | find (const key_type &key) const |
Detailed Description
template<class K, class V>
class oos::factory< K, V >
A generic factory class.
- Template Parameters
-
K The type for the key value. V The value type.
This is a generic factory class where values are stored in producer objects as pointers wrapped by std::shared_ptr of type V. The key type is used to identify the producer. Once create is called a new object of value type V is created and returned. The class uses a producer interface of type producer_base and a defualt producer class default_producer is provided.
Member Typedef Documentation
typedef container_t::const_iterator oos::factory< K, V >::const_iterator |
Shortcut for const_iterator.
typedef std::map<key_type, producer_ptr> oos::factory< K, V >::container_t |
Shortcut for map type.
typedef container_t::iterator oos::factory< K, V >::iterator |
Shortcut for iterator.
typedef K oos::factory< K, V >::key_type |
Shortcut for key type.
typedef std::tr1::shared_ptr<producer_base> oos::factory< K, V >::producer_ptr |
Shortcut for producer pointer class.
typedef container_t::size_type oos::factory< K, V >::size_type |
Shortcut for size type.
typedef V oos::factory< K, V >::value_type |
Shortcut for value type.
Constructor & Destructor Documentation
|
inline |
Creates an empty factory.
Member Function Documentation
|
inline |
Return the begin iterator
- Returns
- The begin iterator.
|
inline |
Return the const begin iterator
- Returns
- The const begin iterator.
|
inline |
Returns the number of producers with the given key.
- Parameters
-
key The key type to search.
- Returns
- The number of producers with key.
|
inline |
Creates a new value for the given key. If the key is valid the underlaying producer calls create and returns a new object. If the key is invalid null is returned.
- Parameters
-
key The key type to erase.
- Returns
- A new object of value_type or null.
|
inline |
Return true if the factory is empty.
- Returns
- Returns true on empty factory.
|
inline |
Return the end iterator
- Returns
- The end iterator.
|
inline |
Return the const end iterator
- Returns
- The const end iterator.
|
inline |
Erase the value with given key and returns the number of erased values.
- Parameters
-
key The key type to erase.
- Returns
- The number of erased values.
|
inline |
Returns the iterator with the producer of given type or end if key isn't found.
- Parameters
-
key The key type to search.
- Returns
- The iterator corresponding to the key.
|
inline |
Returns the iterator with the producer of given type or end if key isn't found.
- Parameters
-
key The key type to search.
- Returns
- The iterator corresponding to the key.
|
inline |
Inserts a new producer for a type identified by the given key. If the key already exists the value of the second parameter is false and the returned iterator is the existing producer.
- Parameters
-
key The key value for the producer. p The producer.
- Returns
- A pair containing the new or existing iterator and a boolean value indicating if the insertion succeeded.
|
inline |
Returns the current number of producer in the factory.
- Returns
- Number of producers.
The documentation for this class was generated from the following file:
- tools/factory.hpp