Public Types | Public Member Functions | Static Public Member Functions | Protected Types | Protected Attributes

jmitie::CjVisitorFactory< FacEntryType > Class Template Reference

Represents an object factory.
. More...

#include <CjVisitorFactory.hh>

Collaboration diagram for jmitie::CjVisitorFactory< FacEntryType >:
Collaboration graph
[legend]

List of all members.

Public Types

typedef FacEntryType::f_create_t f_create_t
 A local typedef copy of the function pointer type for the create function in a sub-factory (copied from FacEntryType).
typedef FacEntryType::f_destroy_t f_destroy_t
 A local typedef copy of the function pointer type for the destroy function in a sub-factory (copied from FacEntryType).
typedef FacEntryType::f_getNames_t f_getNames_t
 A local typedef copy of the function pointer type for the name lookup function in a sub-factory (copied from FacEntryType).
typedef
FacEntryType::f_getProperty_t 
f_getProperty_t
 A local typedef copy of the function pointer type for the property lookup function in a sub-factory (copied from FacEntryType).
typedef FacEntryType::VisitorType VisitorType
 A local typedef copy of the base type being produced by this factory (copied from FacEntryType).
typedef boost::shared_ptr
< VisitorType
Visitor_shared_ptr
 A typedef of the boost::share_ptr to the created instances.
typedef VisitorType::ctor_va_t VisitorArgumentType
 A typedef of the fixed variable argument object passed to the create function of a sub-factory.

Public Member Functions

 CjVisitorFactory (const char *desc)
 Create an empty factory with the given description.
std::string description () const
 Factory description accessor.
 ~CjVisitorFactory ()
 The CjVisitorFactory destructor.
void clear ()
 Clears all the entries in the factory.
void registerStaticEntry (f_create_t c, f_destroy_t d, f_getNames_t n, f_getProperty_t p)
 Registers static function pointers in this factory.
void loadAll (const char *create_name, const char *destroy_name, const char *getnames_name, const char *getproperty_name, const char *dir=NULL, const bool continueOnFail=false, const bool overwriteExisting=false)
 Loads all the DLLs in the given directory and attempts to find the specified symbols in each.
void loadOne (const char *fname, const char *create_name, const char *destroy_name, const char *getnames_name, const char *getproperty_name, bool continueOnDupe=false, const bool overwriteExisting=false)
 Loads the specified DLL and attempts to find the specified symbols.
Visitor_shared_ptr createInstance_sharedptr (const std::string &name, const std::string &args, const VisitorArgumentType &va) const
 Creates a new instance of the named object type.
std::string getProperty (const std::string &name, const std::string &prop_name) const
 Attempts to get the requested property string for the given object name.
std::vector< std::string > getRegisteredNames () const
 Returns a list of all of the object names registered with this factory.

Static Public Member Functions

static factory_t loadOneDLLToFactoryCopy (const char *fname, const char *create_name, const char *destroy_name, const char *getnames_name, const char *getproperty_name, const bool continueOnDupe, const bool overwriteExisting, const factory_t *old_factory=0)
 Loads the secified DLL and adds the object names that it offers into a copy of the specified factory.

Protected Types

typedef std::map< std::string,
boost::shared_ptr
< FacEntryType >, std::less
< std::string > > 
factory_t
 A map of class names to object makers - boost::share_ptr is used because a single FacEntryType object can create multiple object types so a single FacEntryType may map to many names.

Protected Attributes

factory_t m_factory
 A mapping of class names to object makers.
std::string m_description
 A free form description of this factory - not used internally, but could be used externally to identify the factory contents.

Detailed Description

template<typename FacEntryType>
class jmitie::CjVisitorFactory< FacEntryType >

Represents an object factory.
.

The user registers sub-factories with this class - either statically linked function pointers or details of a DLL or directory of DLLs. The class then interrogates the sub-factories for the names of the classes of the objects that they can create and keeps and internal mapping of registered names to sub-factories. Upon request the factory looks up a class name and calls the sub-factory's create method to create an instance of the requested object type.

Template Parameters:
<FacEntryType> { The class or super-class of the objects that can be created by this factory entry. }

Constructor & Destructor Documentation

template<typename FacEntryType >
jmitie::CjVisitorFactory< FacEntryType >::~CjVisitorFactory (  )  [inline]

The CjVisitorFactory destructor.

when the factory is cleared all references to registered sub-factories will be deleted and then DLL will unload automatically


Member Function Documentation

template<typename FacEntryType >
void jmitie::CjVisitorFactory< FacEntryType >::clear (  )  [inline]

Clears all the entries in the factory.

Clears the mapping of object type names to sub-factories. If the sub-factory is a DLL then it will be unloaded.

template<typename FacEntryType >
Visitor_shared_ptr jmitie::CjVisitorFactory< FacEntryType >::createInstance_sharedptr ( const std::string &  name,
const std::string &  args,
const VisitorArgumentType va 
) const [inline]

Creates a new instance of the named object type.

This method can throw anything the object constructor can throw, e.g. CjNP_parseFail A boost::share_ptr is returned because it allows for the custom desctructor to be bundled with it - and since the destructor is potentially in the translation unit of the DLL it could have a custom delete and all kinds of fun

Parameters:
name The name of the object type to create
args The free-form argument to pass the object constructor
va The variable argument object to pass the object constructor
Exceptions:
Cj_NotFoundInFactoryException if name is not found in this factory
template<typename FacEntryType >
std::string jmitie::CjVisitorFactory< FacEntryType >::getProperty ( const std::string &  name,
const std::string &  prop_name 
) const [inline]

Attempts to get the requested property string for the given object name.

Parameters:
name The name of the object to get properties of
prop_name The name of the property to retrieve
Exceptions:
Cj_NotFoundInFactoryException if name is not found in this factory
template<typename FacEntryType >
void jmitie::CjVisitorFactory< FacEntryType >::loadAll ( const char *  create_name,
const char *  destroy_name,
const char *  getnames_name,
const char *  getproperty_name,
const char *  dir = NULL,
const bool  continueOnFail = false,
const bool  overwriteExisting = false 
) [inline]

Loads all the DLLs in the given directory and attempts to find the specified symbols in each.

Parameters:
create_name The name of the create function in the DLL
destroy_name The name of the destroy function in the DLL
getnames_name The name of the function in the DLL that returns a list of classes that it can create
getproperty_name The name of the function in the DLL that returns allows for the interrogation of class properties in the sub-factory in the DLL
dir The name of the directory in which to search for DLLs (defaults to current directory)
continueOnFail If set then when any failures occur (including name collision, symbols not found etc..) the search will not continue
overwriteExisting Existing entries in the factory will be overwritten if a DLL is found which can create objects of the same name
Exceptions:
Cj_FileSystemException If an error occurs with file handling (e.g. no read access to DLL)
Cj_NameCollisionException If a newly loaded sub-factory offers an object name which is the same as one already in the factory
Cj_SymbolMissingException The DLL being loaded didn't contain the necessary symbols specified (the *_name arguments)
template<typename FacEntryType >
void jmitie::CjVisitorFactory< FacEntryType >::loadOne ( const char *  fname,
const char *  create_name,
const char *  destroy_name,
const char *  getnames_name,
const char *  getproperty_name,
bool  continueOnDupe = false,
const bool  overwriteExisting = false 
) [inline]

Loads the specified DLL and attempts to find the specified symbols.

Parameters:
fname The filename of the DLL
create_name The name of the create function in the DLL
destroy_name The name of the destroy function in the DLL
getnames_name The name of the function in the DLL that returns a list of classes that it can create
getproperty_name The name of the function in the DLL that returns allows for the interrogation of class properties in the sub-factory in the DLL
continueOnDupe If set then when the DLL offers an object name which already exists in the factory the whole operation will undo and no further object names will be registered
overwriteExisting Existing entries in the factory will be overwritten if the DLL can create objects of the same name as an existing entry in the factory
Exceptions:
Cj_FileSystemException If an error occurs with file handling (e.g. no read access to DLL)
Cj_NameCollisionException If a newly loaded sub-factory offers an object name which is the same as one already in the factory
Cj_SymbolMissingException The DLL being loaded didn't contain the necessary symbols specified (the *_name arguments)
template<typename FacEntryType >
static factory_t jmitie::CjVisitorFactory< FacEntryType >::loadOneDLLToFactoryCopy ( const char *  fname,
const char *  create_name,
const char *  destroy_name,
const char *  getnames_name,
const char *  getproperty_name,
const bool  continueOnDupe,
const bool  overwriteExisting,
const factory_t old_factory = 0 
) [inline, static]

Loads the secified DLL and adds the object names that it offers into a copy of the specified factory.

Returns:
A copy of old_factory with the names of objects offered by the DLL added to it
Parameters:
fname The filename of the DLL
create_name The name of the create function in the DLL
destroy_name The name of the destroy function in the DLL
getnames_name The name of the function in the DLL that returns a list of classes that it can create
getproperty_name The name of the function in the DLL that returns allows for the interrogation of class properties in the sub-factory in the DLL
continueOnDupe If set then when the DLL offers an object name which already exists in the factory the whole operation will undo and no further object names will be registered
overwriteExisting Existing entries in the factory will be overwritten if the DLL can create objects of the same name as an existing entry in the factory
old_factory The factory to copy. The name offered by the loaded sub-factory will be added to the copy and the reslting factory returned
Exceptions:
Cj_FileSystemException If an error occurs with file handling (e.g. no read access to DLL)
Cj_NameCollisionException If a newly loaded sub-factory offers an object name which is the same as one already in the factory
Cj_SymbolMissingException The DLL being loaded didn't contain the necessary symbols specified (the *_name arguments)
template<typename FacEntryType >
void jmitie::CjVisitorFactory< FacEntryType >::registerStaticEntry ( f_create_t  c,
f_destroy_t  d,
f_getNames_t  n,
f_getProperty_t  p 
) [inline]

Registers static function pointers in this factory.

Parameters:
c A function pointer to the static create function
d A function pointer to the static destroy function
n A function pointer to the static function that returns the names that can be created by this sub-factory
p A function pointer to the static function that returns properties of the objects that can be created by this sub-factory

The documentation for this class was generated from the following file:
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator