VR-Forces 4.0.4 Class Documentation
include/tdbutil/stringKeyFactory.h
Go to the documentation of this file.
00001 /*******************************************************************************
00002 ** Copyright (c) 2007 MAK Technologies, Inc.
00003 ** All rights reserved.
00004 *******************************************************************************/
00005 /*******************************************************************************
00006 ** $RCSfile: stringKeyFactory.h,v $ $Revision: 1.1 $ $State: Exp $
00007 *******************************************************************************/
00008 
00011 
00012 #ifndef stringKeyFactory_h
00013 #define stringKeyFactory_h
00014 
00015 #include <map>
00016 #include <vlutil/vlString.h>
00017 
00018 // Template for creating factory classes that are keyed off a string type 
00019 // identifier.
00020 // Instances if this template are created by specifying the data type that
00021 // is to be created by the factory.  A creator function prototype is then provided
00022 // by the DtCreatorFcn typedef in the new class.
00023 // The creation method for classes created from this factory must not take 
00024 // any parameters.  For a version of this template where the creation method
00025 // takes a parameters, see DtStringKeyFactoryWithParam.
00026 template <typename T_CreationType>
00027 class DtStringKeyFactory
00028 {
00029 
00030 public:
00031    // The creator function signature used by this factory.
00032    typedef T_CreationType* (*DtCreatorFcn)();
00033    typedef std::map<DtString, DtCreatorFcn> DtCreatorFunctionMap;
00034 
00035 public:
00036    // constructor
00037    DtStringKeyFactory();
00038 
00039 private:
00040    // Not implemented.
00041    DtStringKeyFactory(const DtStringKeyFactory& orig);
00042    // Not implemented.
00043    const DtStringKeyFactory& operator=(const DtStringKeyFactory& 
00044       orig);
00045 
00046 public:
00047    // Destructor: deletes factory and any entries on the factory.
00048    virtual ~DtStringKeyFactory();
00049 
00050    // Add a creator function to the factory.
00051    virtual void addCreatorFcn(const DtString& type, DtCreatorFcn fcn);
00052 
00053    // Create and return a new instance of the type based on the creator
00054    // functions and the type specified.
00055    // Prints a warning if not found.  
00056    virtual T_CreationType* createItem(const DtString& type) const;
00057 
00058    // Static creator function for this factory, so it can be created
00059    // though a factory itself.
00060    static DtStringKeyFactory<T_CreationType>* create();
00061    const DtCreatorFunctionMap& functionMap() const
00062    {
00063       return myCreatorFunctionMap;
00064    }
00065 
00066 protected:
00067    DtCreatorFunctionMap myCreatorFunctionMap;
00068    
00069 };
00070 
00071 // Template for creating factory classes that are keyed off a string type 
00072 // identifier and take a single argument in the creation method.
00073 // Instances if this template are created by specifying the data type that
00074 // is to be created by the factory.  A creator function prototype is then provided
00075 // by the DtCreatorFcn typedef in the new class.
00076 // The creation method for classes created from this factory must take  
00077 // a single parameter.  For a version of this template where the creation method
00078 // takes no parameters, see DtStringKeyFactory.
00079 template <typename T_CreationType, typename T_ConstructorParam>
00080 class DtStringKeyFactoryWithParam
00081 {
00082 public:
00083    // The creator function signature used by this factory.
00084    typedef T_CreationType* (*DtCreatorFcn)(T_ConstructorParam);
00085    typedef std::map<DtString, DtCreatorFcn> DtCreatorFunctionMap;
00086 
00087 public:
00088    // constructor
00089    DtStringKeyFactoryWithParam();
00090 
00091 private:
00092    // Not implemented.
00093    DtStringKeyFactoryWithParam(const DtStringKeyFactoryWithParam& orig);
00094    // Not implemented.
00095    const DtStringKeyFactoryWithParam& operator=(const DtStringKeyFactoryWithParam& 
00096       orig);
00097 
00098 public:
00099    // Destructor: deletes factory and any entries on the factory.
00100    virtual ~DtStringKeyFactoryWithParam();
00101 
00102    // Add a creator function to the factory.
00103    virtual void addCreatorFcn(const DtString& type, DtCreatorFcn fcn);
00104 
00105    // Create and return a new instance of the type based on the creator
00106    // functions and the type specified passing the specified parameter 
00107    // to the creation method.
00108    // Prints a warning if not found.  
00109    virtual T_CreationType* createItem(const DtString& type, 
00110       T_ConstructorParam param) const;
00111 
00112    // Static creator function for this factory, so it can be created
00113    // though a factory itself.
00114    static DtStringKeyFactoryWithParam<T_CreationType, T_ConstructorParam>* create();
00115 
00116    const DtCreatorFunctionMap& functionMap() const
00117    {
00118       return myCreatorFunctionMap;
00119    }
00120 
00121 protected:
00122    DtCreatorFunctionMap myCreatorFunctionMap;
00123 
00124 };
00125 
00126 #define stringKeyFactory_inl_
00127 #include "tdbutil/stringKeyFactory.inl"
00128 #undef  stringKeyFactory_inl_
00129 
00130 #endif

Document ID: Generated on Fri Jun 29 16:33:32 EDT 2012 from SVN revision 116588
Copyright © 2005-2012 VT MÄK Inc. All Rights Reserved (www.mak.com)