Library of Assembled Shared Sources
lass::util::CloneFactory< AbstractProduct, IdentifierType, ProductCloner > Class Template Reference

object creation by cloning prototypes More...

#include <clone_factory.h>

Public Member Functions

 CloneFactory (typename CallTraits< ProductCloner >::TParam iCloner)
 create a clone factory by specifying its cloner function iCloner.
 
bool subscribe (typename CallTraits< IdentifierType >::TParam iIdentifier, std::unique_ptr< AbstractProduct > iPrototype)
 register a concrete product to the CloneFactory by a iIdentifier that will identify the product, and an iPrototype that will be cloned.
 
bool unsubscribe (typename CallTraits< IdentifierType >::TParam iIdentifier)
 unregister a concrete product by its iIdentifier
 
AbstractProduct * make (typename CallTraits< IdentifierType >::TParam iIdentifier) const
 Create a new concrete product by cloning the prototype only to be used if maker don't want any parameters.
 
template<typename P1>
AbstractProduct * make (typename CallTraits< IdentifierType >::TParam iIdentifier, P1 &iP1) const
 create a new concrete product by cloning the prototype with 1 additional parameter(s).
 
template<typename P1, typename P2>
AbstractProduct * make (typename CallTraits< IdentifierType >::TParam iIdentifier, P1 &iP1, P2 &iP2) const
 create a new concrete product by cloning the prototype with 2 additional parameter(s).
 
template<typename P1, typename P2, typename P3>
AbstractProduct * make (typename CallTraits< IdentifierType >::TParam iIdentifier, P1 &iP1, P2 &iP2, P3 &iP3) const
 create a new concrete product by cloning the prototype with 3 additional parameter(s).
 
template<typename P1, typename P2, typename P3, typename P4>
AbstractProduct * make (typename CallTraits< IdentifierType >::TParam iIdentifier, P1 &iP1, P2 &iP2, P3 &iP3, P4 &iP4) const
 create a new concrete product by cloning the prototype with 4 additional parameter(s).
 
template<typename P1, typename P2, typename P3, typename P4, typename P5>
AbstractProduct * make (typename CallTraits< IdentifierType >::TParam iIdentifier, P1 &iP1, P2 &iP2, P3 &iP3, P4 &iP4, P5 &iP5) const
 create a new concrete product by cloning the prototype with 5 additional parameter(s).
 
template<typename P1, typename P2, typename P3, typename P4, typename P5, typename P6>
AbstractProduct * make (typename CallTraits< IdentifierType >::TParam iIdentifier, P1 &iP1, P2 &iP2, P3 &iP3, P4 &iP4, P5 &iP5, P6 &iP6) const
 create a new concrete product by cloning the prototype with 6 additional parameter(s).
 
template<typename P1, typename P2, typename P3, typename P4, typename P5, typename P6, typename P7>
AbstractProduct * make (typename CallTraits< IdentifierType >::TParam iIdentifier, P1 &iP1, P2 &iP2, P3 &iP3, P4 &iP4, P5 &iP5, P6 &iP6, P7 &iP7) const
 create a new concrete product by cloning the prototype with 7 additional parameter(s).
 
template<typename P1, typename P2, typename P3, typename P4, typename P5, typename P6, typename P7, typename P8>
AbstractProduct * make (typename CallTraits< IdentifierType >::TParam iIdentifier, P1 &iP1, P2 &iP2, P3 &iP3, P4 &iP4, P5 &iP5, P6 &iP6, P7 &iP7, P8 &iP8) const
 create a new concrete product by cloning the prototype with 8 additional parameter(s).
 
template<typename P1, typename P2, typename P3, typename P4, typename P5, typename P6, typename P7, typename P8, typename P9>
AbstractProduct * make (typename CallTraits< IdentifierType >::TParam iIdentifier, P1 &iP1, P2 &iP2, P3 &iP3, P4 &iP4, P5 &iP5, P6 &iP6, P7 &iP7, P8 &iP8, P9 &iP9) const
 create a new concrete product by cloning the prototype with 9 additional parameter(s).
 
template<typename P1, typename P2, typename P3, typename P4, typename P5, typename P6, typename P7, typename P8, typename P9, typename P10>
AbstractProduct * make (typename CallTraits< IdentifierType >::TParam iIdentifier, P1 &iP1, P2 &iP2, P3 &iP3, P4 &iP4, P5 &iP5, P6 &iP6, P7 &iP7, P8 &iP8, P9 &iP9, P10 &iP10) const
 create a new concrete product by cloning the prototype with 10 additional parameter(s).
 
template<typename P1, typename P2, typename P3, typename P4, typename P5, typename P6, typename P7, typename P8, typename P9, typename P10, typename P11>
AbstractProduct * make (typename CallTraits< IdentifierType >::TParam iIdentifier, P1 &iP1, P2 &iP2, P3 &iP3, P4 &iP4, P5 &iP5, P6 &iP6, P7 &iP7, P8 &iP8, P9 &iP9, P10 &iP10, P11 &iP11) const
 create a new concrete product by cloning the prototype with 11 additional parameter(s).
 
template<typename P1, typename P2, typename P3, typename P4, typename P5, typename P6, typename P7, typename P8, typename P9, typename P10, typename P11, typename P12>
AbstractProduct * make (typename CallTraits< IdentifierType >::TParam iIdentifier, P1 &iP1, P2 &iP2, P3 &iP3, P4 &iP4, P5 &iP5, P6 &iP6, P7 &iP7, P8 &iP8, P9 &iP9, P10 &iP10, P11 &iP11, P12 &iP12) const
 create a new concrete product by cloning the prototype with 12 additional parameter(s).
 
template<typename P1, typename P2, typename P3, typename P4, typename P5, typename P6, typename P7, typename P8, typename P9, typename P10, typename P11, typename P12, typename P13>
AbstractProduct * make (typename CallTraits< IdentifierType >::TParam iIdentifier, P1 &iP1, P2 &iP2, P3 &iP3, P4 &iP4, P5 &iP5, P6 &iP6, P7 &iP7, P8 &iP8, P9 &iP9, P10 &iP10, P11 &iP11, P12 &iP12, P13 &iP13) const
 create a new concrete product by cloning the prototype with 13 additional parameter(s).
 
template<typename P1, typename P2, typename P3, typename P4, typename P5, typename P6, typename P7, typename P8, typename P9, typename P10, typename P11, typename P12, typename P13, typename P14>
AbstractProduct * make (typename CallTraits< IdentifierType >::TParam iIdentifier, P1 &iP1, P2 &iP2, P3 &iP3, P4 &iP4, P5 &iP5, P6 &iP6, P7 &iP7, P8 &iP8, P9 &iP9, P10 &iP10, P11 &iP11, P12 &iP12, P13 &iP13, P14 &iP14) const
 create a new concrete product by cloning the prototype with 14 additional parameter(s).
 
template<typename P1, typename P2, typename P3, typename P4, typename P5, typename P6, typename P7, typename P8, typename P9, typename P10, typename P11, typename P12, typename P13, typename P14, typename P15>
AbstractProduct * make (typename CallTraits< IdentifierType >::TParam iIdentifier, P1 &iP1, P2 &iP2, P3 &iP3, P4 &iP4, P5 &iP5, P6 &iP6, P7 &iP7, P8 &iP8, P9 &iP9, P10 &iP10, P11 &iP11, P12 &iP12, P13 &iP13, P14 &iP14, P15 &iP15) const
 create a new concrete product by cloning the prototype with 15 additional parameter(s).
 

Detailed Description

template<class AbstractProduct, class IdentifierType, class ProductCloner = AbstractProduct*(*)(const AbstractProduct&)>
class lass::util::CloneFactory< AbstractProduct, IdentifierType, ProductCloner >

object creation by cloning prototypes

Author
Bram de Greve [Bramz]

A clone factory is much like an object factory (lass::util::ObjectFactory), except that it will clone existings object rather than creating new ones from the ground up using maker functions.

A clone factory creates objects of the same hierarchy, i.e. objects that have a common base class. The base class is an abstract product and the derived classes are concrete products. The factory let you decide what concrete product to create at runtime by using a specific identifier. These identifiers can be integers or strings or any type you can use in a std::map.

Before you can create any products, you must subscribe prototypes and cloner methods to the factory. A prototype is an object instance that will be cloned by the cloner function. Together, a pair of a prototype and a cloner function provides the functionality of one maker function in the ObjectFactory.

Again, all this cloners must have the same signature and should return a pointer to the abstract product. Their first argument will be a reference to the prototype being cloned. The following arguments will be filled by the iP1, iP2, iP3, ... that are provided to the make() method of the clone factory.

class Base
{
public:
Base(const std::string& iName): name_(iName) {}
virtual std::string who() const { return std::string("Base ") + name_; }
virtual Base* clone() const { return new Base(*this); }
protected:
std::string name_;
};
class Foo: public Base
{
public:
Foo(const std::string& iName): Base(iName) {}
virtual std::string who() const { return std::string("Foo ") + name_; }
virtual Base* clone() const { return new Foo(*this); }
};
class Bar: public Base
{
public:
Bar(const std::string& iName): Base(iName) {}
virtual std::string who() const { return std::string("Bar ") + name_; }
virtual Base* clone() const { return new Bar(*this); }
};
Base* clone(const Base& iPrototype) { return iPrototype.clone(); }
typedef util::CloneFactory<Base, std::string> TFactory;
typedef std::auto_ptr<Base> TBasePtr;
TFactory factory(clone);
factory.subscribe("Joe", TBasePtr(new Base("Joe")));
factory.subscribe("Moe", TBasePtr(new Foo("Moe")));
factory.subscribe("Doe", TBasePtr(new Bar("Doe")));
TBasePtr a(factory.make("Joe"));
LASS_COUT << a->who() << "\n"; // Base Joe
TBasePtr b(factory.make("Moe"));
LASS_COUT << b->who() << "\n"; // Foo Moe
TBasePtr c(factory.make("Doe"));
LASS_COUT << c->who() << "\n"; // Bar Doe
#define LASS_COUT
return reference to 'cout' proxy stream of the lass::io::ProxyMan singleton.
Definition io_fwd.h:69

Definition at line 138 of file clone_factory.h.

Member Function Documentation

◆ make() [1/15]

template<class AbstractProduct, class IdentifierType, class ProductCloner = AbstractProduct*(*)(const AbstractProduct&)>
template<typename P1>
AbstractProduct * lass::util::CloneFactory< AbstractProduct, IdentifierType, ProductCloner >::make ( typename CallTraits< IdentifierType >::TParam iIdentifier,
P1 & iP1 ) const
inline

create a new concrete product by cloning the prototype with 1 additional parameter(s).

only to be used if it can be mapped on iCloner function.

Definition at line 189 of file clone_factory.h.

◆ make() [2/15]

template<class AbstractProduct, class IdentifierType, class ProductCloner = AbstractProduct*(*)(const AbstractProduct&)>
template<typename P1, typename P2>
AbstractProduct * lass::util::CloneFactory< AbstractProduct, IdentifierType, ProductCloner >::make ( typename CallTraits< IdentifierType >::TParam iIdentifier,
P1 & iP1,
P2 & iP2 ) const
inline

create a new concrete product by cloning the prototype with 2 additional parameter(s).

only to be used if it can be mapped on iCloner function.

Definition at line 205 of file clone_factory.h.

◆ make() [3/15]

template<class AbstractProduct, class IdentifierType, class ProductCloner = AbstractProduct*(*)(const AbstractProduct&)>
template<typename P1, typename P2, typename P3>
AbstractProduct * lass::util::CloneFactory< AbstractProduct, IdentifierType, ProductCloner >::make ( typename CallTraits< IdentifierType >::TParam iIdentifier,
P1 & iP1,
P2 & iP2,
P3 & iP3 ) const
inline

create a new concrete product by cloning the prototype with 3 additional parameter(s).

only to be used if it can be mapped on iCloner function.

Definition at line 221 of file clone_factory.h.

◆ make() [4/15]

template<class AbstractProduct, class IdentifierType, class ProductCloner = AbstractProduct*(*)(const AbstractProduct&)>
template<typename P1, typename P2, typename P3, typename P4>
AbstractProduct * lass::util::CloneFactory< AbstractProduct, IdentifierType, ProductCloner >::make ( typename CallTraits< IdentifierType >::TParam iIdentifier,
P1 & iP1,
P2 & iP2,
P3 & iP3,
P4 & iP4 ) const
inline

create a new concrete product by cloning the prototype with 4 additional parameter(s).

only to be used if it can be mapped on iCloner function.

Definition at line 237 of file clone_factory.h.

◆ make() [5/15]

template<class AbstractProduct, class IdentifierType, class ProductCloner = AbstractProduct*(*)(const AbstractProduct&)>
template<typename P1, typename P2, typename P3, typename P4, typename P5>
AbstractProduct * lass::util::CloneFactory< AbstractProduct, IdentifierType, ProductCloner >::make ( typename CallTraits< IdentifierType >::TParam iIdentifier,
P1 & iP1,
P2 & iP2,
P3 & iP3,
P4 & iP4,
P5 & iP5 ) const
inline

create a new concrete product by cloning the prototype with 5 additional parameter(s).

only to be used if it can be mapped on iCloner function.

Definition at line 253 of file clone_factory.h.

◆ make() [6/15]

template<class AbstractProduct, class IdentifierType, class ProductCloner = AbstractProduct*(*)(const AbstractProduct&)>
template<typename P1, typename P2, typename P3, typename P4, typename P5, typename P6>
AbstractProduct * lass::util::CloneFactory< AbstractProduct, IdentifierType, ProductCloner >::make ( typename CallTraits< IdentifierType >::TParam iIdentifier,
P1 & iP1,
P2 & iP2,
P3 & iP3,
P4 & iP4,
P5 & iP5,
P6 & iP6 ) const
inline

create a new concrete product by cloning the prototype with 6 additional parameter(s).

only to be used if it can be mapped on iCloner function.

Definition at line 269 of file clone_factory.h.

◆ make() [7/15]

template<class AbstractProduct, class IdentifierType, class ProductCloner = AbstractProduct*(*)(const AbstractProduct&)>
template<typename P1, typename P2, typename P3, typename P4, typename P5, typename P6, typename P7>
AbstractProduct * lass::util::CloneFactory< AbstractProduct, IdentifierType, ProductCloner >::make ( typename CallTraits< IdentifierType >::TParam iIdentifier,
P1 & iP1,
P2 & iP2,
P3 & iP3,
P4 & iP4,
P5 & iP5,
P6 & iP6,
P7 & iP7 ) const
inline

create a new concrete product by cloning the prototype with 7 additional parameter(s).

only to be used if it can be mapped on iCloner function.

Definition at line 285 of file clone_factory.h.

◆ make() [8/15]

template<class AbstractProduct, class IdentifierType, class ProductCloner = AbstractProduct*(*)(const AbstractProduct&)>
template<typename P1, typename P2, typename P3, typename P4, typename P5, typename P6, typename P7, typename P8>
AbstractProduct * lass::util::CloneFactory< AbstractProduct, IdentifierType, ProductCloner >::make ( typename CallTraits< IdentifierType >::TParam iIdentifier,
P1 & iP1,
P2 & iP2,
P3 & iP3,
P4 & iP4,
P5 & iP5,
P6 & iP6,
P7 & iP7,
P8 & iP8 ) const
inline

create a new concrete product by cloning the prototype with 8 additional parameter(s).

only to be used if it can be mapped on iCloner function.

Definition at line 301 of file clone_factory.h.

◆ make() [9/15]

template<class AbstractProduct, class IdentifierType, class ProductCloner = AbstractProduct*(*)(const AbstractProduct&)>
template<typename P1, typename P2, typename P3, typename P4, typename P5, typename P6, typename P7, typename P8, typename P9>
AbstractProduct * lass::util::CloneFactory< AbstractProduct, IdentifierType, ProductCloner >::make ( typename CallTraits< IdentifierType >::TParam iIdentifier,
P1 & iP1,
P2 & iP2,
P3 & iP3,
P4 & iP4,
P5 & iP5,
P6 & iP6,
P7 & iP7,
P8 & iP8,
P9 & iP9 ) const
inline

create a new concrete product by cloning the prototype with 9 additional parameter(s).

only to be used if it can be mapped on iCloner function.

Definition at line 317 of file clone_factory.h.

◆ make() [10/15]

template<class AbstractProduct, class IdentifierType, class ProductCloner = AbstractProduct*(*)(const AbstractProduct&)>
template<typename P1, typename P2, typename P3, typename P4, typename P5, typename P6, typename P7, typename P8, typename P9, typename P10>
AbstractProduct * lass::util::CloneFactory< AbstractProduct, IdentifierType, ProductCloner >::make ( typename CallTraits< IdentifierType >::TParam iIdentifier,
P1 & iP1,
P2 & iP2,
P3 & iP3,
P4 & iP4,
P5 & iP5,
P6 & iP6,
P7 & iP7,
P8 & iP8,
P9 & iP9,
P10 & iP10 ) const
inline

create a new concrete product by cloning the prototype with 10 additional parameter(s).

only to be used if it can be mapped on iCloner function.

Definition at line 333 of file clone_factory.h.

◆ make() [11/15]

template<class AbstractProduct, class IdentifierType, class ProductCloner = AbstractProduct*(*)(const AbstractProduct&)>
template<typename P1, typename P2, typename P3, typename P4, typename P5, typename P6, typename P7, typename P8, typename P9, typename P10, typename P11>
AbstractProduct * lass::util::CloneFactory< AbstractProduct, IdentifierType, ProductCloner >::make ( typename CallTraits< IdentifierType >::TParam iIdentifier,
P1 & iP1,
P2 & iP2,
P3 & iP3,
P4 & iP4,
P5 & iP5,
P6 & iP6,
P7 & iP7,
P8 & iP8,
P9 & iP9,
P10 & iP10,
P11 & iP11 ) const
inline

create a new concrete product by cloning the prototype with 11 additional parameter(s).

only to be used if it can be mapped on iCloner function.

Definition at line 349 of file clone_factory.h.

◆ make() [12/15]

template<class AbstractProduct, class IdentifierType, class ProductCloner = AbstractProduct*(*)(const AbstractProduct&)>
template<typename P1, typename P2, typename P3, typename P4, typename P5, typename P6, typename P7, typename P8, typename P9, typename P10, typename P11, typename P12>
AbstractProduct * lass::util::CloneFactory< AbstractProduct, IdentifierType, ProductCloner >::make ( typename CallTraits< IdentifierType >::TParam iIdentifier,
P1 & iP1,
P2 & iP2,
P3 & iP3,
P4 & iP4,
P5 & iP5,
P6 & iP6,
P7 & iP7,
P8 & iP8,
P9 & iP9,
P10 & iP10,
P11 & iP11,
P12 & iP12 ) const
inline

create a new concrete product by cloning the prototype with 12 additional parameter(s).

only to be used if it can be mapped on iCloner function.

Definition at line 365 of file clone_factory.h.

◆ make() [13/15]

template<class AbstractProduct, class IdentifierType, class ProductCloner = AbstractProduct*(*)(const AbstractProduct&)>
template<typename P1, typename P2, typename P3, typename P4, typename P5, typename P6, typename P7, typename P8, typename P9, typename P10, typename P11, typename P12, typename P13>
AbstractProduct * lass::util::CloneFactory< AbstractProduct, IdentifierType, ProductCloner >::make ( typename CallTraits< IdentifierType >::TParam iIdentifier,
P1 & iP1,
P2 & iP2,
P3 & iP3,
P4 & iP4,
P5 & iP5,
P6 & iP6,
P7 & iP7,
P8 & iP8,
P9 & iP9,
P10 & iP10,
P11 & iP11,
P12 & iP12,
P13 & iP13 ) const
inline

create a new concrete product by cloning the prototype with 13 additional parameter(s).

only to be used if it can be mapped on iCloner function.

Definition at line 381 of file clone_factory.h.

◆ make() [14/15]

template<class AbstractProduct, class IdentifierType, class ProductCloner = AbstractProduct*(*)(const AbstractProduct&)>
template<typename P1, typename P2, typename P3, typename P4, typename P5, typename P6, typename P7, typename P8, typename P9, typename P10, typename P11, typename P12, typename P13, typename P14>
AbstractProduct * lass::util::CloneFactory< AbstractProduct, IdentifierType, ProductCloner >::make ( typename CallTraits< IdentifierType >::TParam iIdentifier,
P1 & iP1,
P2 & iP2,
P3 & iP3,
P4 & iP4,
P5 & iP5,
P6 & iP6,
P7 & iP7,
P8 & iP8,
P9 & iP9,
P10 & iP10,
P11 & iP11,
P12 & iP12,
P13 & iP13,
P14 & iP14 ) const
inline

create a new concrete product by cloning the prototype with 14 additional parameter(s).

only to be used if it can be mapped on iCloner function.

Definition at line 397 of file clone_factory.h.

◆ make() [15/15]

template<class AbstractProduct, class IdentifierType, class ProductCloner = AbstractProduct*(*)(const AbstractProduct&)>
template<typename P1, typename P2, typename P3, typename P4, typename P5, typename P6, typename P7, typename P8, typename P9, typename P10, typename P11, typename P12, typename P13, typename P14, typename P15>
AbstractProduct * lass::util::CloneFactory< AbstractProduct, IdentifierType, ProductCloner >::make ( typename CallTraits< IdentifierType >::TParam iIdentifier,
P1 & iP1,
P2 & iP2,
P3 & iP3,
P4 & iP4,
P5 & iP5,
P6 & iP6,
P7 & iP7,
P8 & iP8,
P9 & iP9,
P10 & iP10,
P11 & iP11,
P12 & iP12,
P13 & iP13,
P14 & iP14,
P15 & iP15 ) const
inline

create a new concrete product by cloning the prototype with 15 additional parameter(s).

only to be used if it can be mapped on iCloner function.

Definition at line 413 of file clone_factory.h.


The documentation for this class was generated from the following file: