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::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 ()=default | |
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 |
A generic factory class.
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 serializable of value type V is created and returned. The class uses a producer interface of type producer_base and a default producer class default_producer is provided.
typedef container_t::const_iterator matador::factory< K, V >::const_iterator |
Shortcut for const_iterator.
typedef std::map<key_type, producer_ptr> matador::factory< K, V >::container_t |
Shortcut for map type.
typedef container_t::iterator matador::factory< K, V >::iterator |
Shortcut for iterator.
typedef K matador::factory< K, V >::key_type |
Shortcut for key type.
typedef std::shared_ptr<producer_base> matador::factory< K, V >::producer_ptr |
Shortcut for producer pointer class.
typedef container_t::size_type matador::factory< K, V >::size_type |
Shortcut for size type.
typedef V matador::factory< K, V >::value_type |
Shortcut for value type.
|
default |
Creates an empty factory.
|
inline |
Return the begin iterator
|
inline |
Return the const begin iterator
|
inline |
Returns the number of producers with the given key.
key | The key type to search. |
|
inline |
Creates a new value for the given key. If the key is valid the underlying producer calls create and returns a new serializable. If the key is invalid null is returned.
key | The key type to erase. |
|
inline |
Return true if the factory is empty.
|
inline |
Return the end iterator
|
inline |
Return the const end iterator
|
inline |
Erase the value with given key and returns the number of erased values.
key | The key type to erase. |
|
inline |
Returns the iterator with the producer of given type or end if key isn't found.
key | The key type to search. |
|
inline |
Returns the iterator with the producer of given type or end if key isn't found.
key | The key type to search. |
|
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.
key | The key value for the producer. |
p | The producer. |
|
inline |
Returns the current number of producer in the factory.