matador::factory< K, V > Class Template Reference

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_baseproducer_ptr
 
typedef std::map< key_type, producer_ptrcontainer_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_typecreate (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 matador::factory< K, V >

A generic factory class.

Template Parameters
KThe type for the key value.
VThe 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.

Member Typedef Documentation

◆ const_iterator

template<class K , class V >
typedef container_t::const_iterator matador::factory< K, V >::const_iterator

Shortcut for const_iterator.

◆ container_t

template<class K , class V >
typedef std::map<key_type, producer_ptr> matador::factory< K, V >::container_t

Shortcut for map type.

◆ iterator

template<class K , class V >
typedef container_t::iterator matador::factory< K, V >::iterator

Shortcut for iterator.

◆ key_type

template<class K , class V >
typedef K matador::factory< K, V >::key_type

Shortcut for key type.

◆ producer_ptr

template<class K , class V >
typedef std::shared_ptr<producer_base> matador::factory< K, V >::producer_ptr

Shortcut for producer pointer class.

◆ size_type

template<class K , class V >
typedef container_t::size_type matador::factory< K, V >::size_type

Shortcut for size type.

◆ value_type

template<class K , class V >
typedef V matador::factory< K, V >::value_type

Shortcut for value type.

Constructor & Destructor Documentation

◆ factory()

template<class K , class V >
matador::factory< K, V >::factory ( )
default

Creates an empty factory.

Member Function Documentation

◆ begin() [1/2]

template<class K , class V >
iterator matador::factory< K, V >::begin ( )
inline

Return the begin iterator

Returns
The begin iterator.

◆ begin() [2/2]

template<class K , class V >
const_iterator matador::factory< K, V >::begin ( ) const
inline

Return the const begin iterator

Returns
The const begin iterator.

◆ count()

template<class K , class V >
size_type matador::factory< K, V >::count ( const key_type key) const
inline

Returns the number of producers with the given key.

Parameters
keyThe key type to search.
Returns
The number of producers with key.

◆ create()

template<class K , class V >
value_type * matador::factory< K, V >::create ( const key_type key) const
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.

Parameters
keyThe key type to erase.
Returns
A new serializable of value_type or null.

◆ empty()

template<class K , class V >
bool matador::factory< K, V >::empty ( ) const
inline

Return true if the factory is empty.

Returns
Returns true on empty factory.

◆ end() [1/2]

template<class K , class V >
iterator matador::factory< K, V >::end ( )
inline

Return the end iterator

Returns
The end iterator.

◆ end() [2/2]

template<class K , class V >
const_iterator matador::factory< K, V >::end ( ) const
inline

Return the const end iterator

Returns
The const end iterator.

◆ erase()

template<class K , class V >
size_type matador::factory< K, V >::erase ( const key_type key)
inline

Erase the value with given key and returns the number of erased values.

Parameters
keyThe key type to erase.
Returns
The number of erased values.

◆ find() [1/2]

template<class K , class V >
iterator matador::factory< K, V >::find ( const key_type key)
inline

Returns the iterator with the producer of given type or end if key isn't found.

Parameters
keyThe key type to search.
Returns
The iterator corresponding to the key.

◆ find() [2/2]

template<class K , class V >
const_iterator matador::factory< K, V >::find ( const key_type key) const
inline

Returns the iterator with the producer of given type or end if key isn't found.

Parameters
keyThe key type to search.
Returns
The iterator corresponding to the key.

◆ insert()

template<class K , class V >
std::pair< iterator, bool > matador::factory< K, V >::insert ( const key_type key,
producer_base p 
)
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
keyThe key value for the producer.
pThe producer.
Returns
A pair containing the new or existing iterator and a boolean value indicating if the insertion succeeded.

◆ size()

template<class K , class V >
size_type matador::factory< K, V >::size ( ) const
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:
  • matador/utils/factory.hpp