I l@ve RuBoard Previous Section Next Section

8.11 CloneFactory Class Template Quick Facts

  • CloneFactory declaration:

    
    
    template
    
    
    <
    
    
       class AbstractProduct,
    
    
       class ProductCreator =
    
    
          AbstractProduct* (*)(const AbstractProduct*),
    
    
       template<typename, class>
    
    
          class FactoryErrorPolicy = DefaultFactoryError
    
    
    >
    
    
    class CloneFactory;
    
    
    
  • AbstractProduct is the base class of the hierarchy for which you want to provide the clone factory.

  • ProductCreator has the role of duplicating the object received as a parameter and returning a pointer to the clone.

  • CloneFactory implements the following primitives:

    
    
    bool Register(const TypeInfo&, ProductCreator creator);
    
    
    

Registers a creator with an object of type TypeInfo (which accepts an implicit conversion constructor from std::type_info). Returns true if the registration was successful; false otherwise.



bool Unregister(const TypeInfo& typeInfo);


Unregisters the creator for the given type. If the type was previously registered, the function returns true.



AbstractProduct* CreateObject(const AbstractProduct* model);


Looks up the dynamic type of model in the internal map. If it is found, it invokes the corresponding creator for the type identifier and returns its result. If the type identifier is not found, the result of FactoryErrorPolicy<OrderedTypeInfo, AbstractProduct> ::OnUnknownType is returned.

    I l@ve RuBoard Previous Section Next Section