mbl_cloneables_factory< BASE > Class Template Reference

#include <mbl_cloneables_factory.h>

List of all members.


Detailed Description

template<class BASE>
class mbl_cloneables_factory< BASE >

A general factory pattern.

After templating this on a base class, and loading in a bunch of concrete instantiations of the derived classes, you can create any of the derived classes simply from the class's name.

BASE must define a clone() and is_a() members

 class BASE
 {
   ...
 public:
   virtual BASE* clone() const=0; // Derived classes must copy themselves.
   virtual vcl_string BASE::is_a() const; {
     return "BASE";} // Derived classes need unique names.
 }

Example:

 mbl_cloneables_factory<vimt_image>::add(vimt_image_2d());
 mbl_cloneables_factory<vimt_image>::add(vimt_image_3d());

 vcl_auto_ptr<vimt_image> p = mbl_cloneables_factory<vimt_image>::get_clone("vimt_image_2d()");
 assert(dynamic_cast<vimt_image_2d>(p));

Definition at line 47 of file mbl_cloneables_factory.h.


Static Public Member Functions

static void add (const BASE &object)
 Add an object for later cloning by the factory.
static void add (const BASE &object, const vcl_string &name)
 Add an object for later cloning by the factory.
static vcl_auto_ptr< BASE > get_clone (const vcl_string &name)
 Get a pointer to a new copy of the object identified by name.

Private Types

typedef vcl_map< vcl_string,
mbl_cloneable_ptr< BASE > > 
MAP

Static Private Member Functions

static MAPobjects ()
 Get singleton instance.

Static Private Attributes

static vcl_auto_ptr< MAPobjects_
 Singleton array of names, and association concrete instantiations of BASE.

Member Typedef Documentation

template<class BASE>
typedef vcl_map<vcl_string, mbl_cloneable_ptr<BASE> > mbl_cloneables_factory< BASE >::MAP [private]

Definition at line 50 of file mbl_cloneables_factory.h.


Member Function Documentation

template<class BASE>
static MAP& mbl_cloneables_factory< BASE >::objects (  )  [inline, static, private]

Get singleton instance.

Definition at line 58 of file mbl_cloneables_factory.h.

template<class BASE>
static void mbl_cloneables_factory< BASE >::add ( const BASE &  object  )  [inline, static]

Add an object for later cloning by the factory.

Use the object's class name via the is_a() member.

Definition at line 70 of file mbl_cloneables_factory.h.

template<class BASE>
static void mbl_cloneables_factory< BASE >::add ( const BASE &  object,
const vcl_string &  name 
) [inline, static]

Add an object for later cloning by the factory.

If there already is an object called name, it will be overwritten.

Definition at line 75 of file mbl_cloneables_factory.h.

template<class BASE>
static vcl_auto_ptr<BASE > mbl_cloneables_factory< BASE >::get_clone ( const vcl_string &  name  )  [inline, static]

Get a pointer to a new copy of the object identified by name.

An exception will be thrown if name does not exist.

Definition at line 82 of file mbl_cloneables_factory.h.


Member Data Documentation

template<class BASE>
vcl_auto_ptr<MAP> mbl_cloneables_factory< BASE >::objects_ [static, private]

Singleton array of names, and association concrete instantiations of BASE.

Definition at line 53 of file mbl_cloneables_factory.h.


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

Generated on Sun Nov 22 06:23:13 2009 for contrib/mul/mbl by  doxygen 1.5.5