LTI-Lib latest version v1.9 - last update 24 Nov 2005
Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

lti::objectFactory< T > Class Template Reference

This class defines a factory for objects. More...

#include <ltiObjectFactory.h>

Inheritance diagram for lti::objectFactory< T >:

Inheritance graph
[legend]
Collaboration diagram for lti::objectFactory< T >:

Collaboration graph
[legend]
List of all members.

Public Member Functions

 objectFactory (const char **names, const T *const *objs)
 objectFactory (const T *const *objs)
virtual ~objectFactory ()
virtual const char * getTypeName () const
virtual T * newInstance (const char *name) const
virtual T * newInstance (const std::string &name) const

Detailed Description

template<class T>
class lti::objectFactory< T >

This class defines a factory for objects.

The instantiation of this class will fail if the template argument T is not a class which defines the clone() method. Usually, you will use an instance of this class as a class variable (C jargon: static class member). This class is thread-safe.

Please note that the C-type lists used in the constructor must be null-terminated.


Constructor & Destructor Documentation

template<class T>
lti::objectFactory< T >::objectFactory const char **  names,
const T *const *  objs
 

Constructor.

Creates an object factory which is able to handle the types whose names and prototypes are given in these two tables. names is an array of (char*) which must be terminated by a null pointer. objs is a corresponding array of object pointers, and must also be null-terminated. Example:

 const char* names[]={ "object1", "object2", "object3", 0 };
 const obj_type* prototypes[] = {
   new object1(), new object2(), new object3(), 0 };
 objectFactor<obj_type> t(names,prototypes);
Parameters:
names array of pointers to const char buffers. It must be null-terminated
objs array of pointers to const objects. It must be null-terminated.

template<class T>
lti::objectFactory< T >::objectFactory const T *const *  objs  ) 
 

Constructor.

Creates an object factory which is able to handle the types whose prototypes are given in this table. The parameter is a null-terminated array of pointers.

The names of the prototypes are determined via the className functor.

Example:

 const obj_type* prototypes[] = {
   new object1(), new object2(), new object3(), 0 };
 objectFactor<obj_type> t(prototypes);
Parameters:
objs array of pointers to const objects. It must be null-terminated.

template<class T>
virtual lti::objectFactory< T >::~objectFactory  )  [virtual]
 

Destructor.


Member Function Documentation

template<class T>
virtual const char* lti::objectFactory< T >::getTypeName  )  const [virtual]
 

returns the name of this type ("objectFactory")

Reimplemented from lti::object.

template<class T>
virtual T* lti::objectFactory< T >::newInstance const std::string &  name  )  const [inline, virtual]
 

Creates a new instance of the class whose name is given as parameter, if this class is known to the factory.

Otherwise, it returns null.

Parameters:
name name of the to-be instantiated class.
Returns:
a new instance.

template<class T>
virtual T* lti::objectFactory< T >::newInstance const char *  name  )  const [virtual]
 

Creates a new instance of the class whose name is given as parameter, if this class is known to the factory.

Otherwise, it returns null.

Parameters:
name name of the to-be instantiated class.
Returns:
a new instance.


The documentation for this class was generated from the following file:
Generated on Thu Nov 24 16:30:24 2005 for LTI-Lib by Doxygen 1.4.4