oos::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::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_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 oos::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 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

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

Shortcut for const_iterator.

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

Shortcut for map type.

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

Shortcut for iterator.

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

Shortcut for key type.

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

Shortcut for producer pointer class.

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

Shortcut for size type.

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

Shortcut for value type.

Constructor & Destructor Documentation

template<class K , class V >
oos::factory< K, V >::factory ( )
inline

Creates an empty factory.

Member Function Documentation

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

Return the begin iterator

Returns
The begin iterator.
template<class K , class V >
const_iterator oos::factory< K, V >::begin ( ) const
inline

Return the const begin iterator

Returns
The const begin iterator.
template<class K , class V >
size_type oos::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.
template<class K , class V >
value_type* oos::factory< K, V >::create ( const key_type key) const
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
keyThe key type to erase.
Returns
A new object of value_type or null.
template<class K , class V >
bool oos::factory< K, V >::empty ( ) const
inline

Return true if the factory is empty.

Returns
Returns true on empty factory.
template<class K , class V >
iterator oos::factory< K, V >::end ( )
inline

Return the end iterator

Returns
The end iterator.
template<class K , class V >
const_iterator oos::factory< K, V >::end ( ) const
inline

Return the const end iterator

Returns
The const end iterator.
template<class K , class V >
size_type oos::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.
template<class K , class V >
iterator oos::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.
template<class K , class V >
const_iterator oos::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.
template<class K , class V >
std::pair<iterator, bool> oos::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.
template<class K , class V >
size_type oos::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:
  • tools/factory.hpp