VR-Forces 4.5 Class Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
stringKeyFactory.h
Go to the documentation of this file.
1 /*******************************************************************************
2 ** Copyright (c) 2007 MAK Technologies, Inc.
3 ** All rights reserved.
4 *******************************************************************************/
5 /*******************************************************************************
6 ** $RCSfile: stringKeyFactory.h,v $ $Revision: 1.1 $ $State: Exp $
7 *******************************************************************************/
8 
11 
12 #ifndef stringKeyFactory_h
13 #define stringKeyFactory_h
14 
15 #include <map>
16 #include <vlutil/vlString.h>
17 
18 // Template for creating factory classes that are keyed off a string type
19 // identifier.
20 // Instances if this template are created by specifying the data type that
21 // is to be created by the factory. A creator function prototype is then provided
22 // by the DtCreatorFcn typedef in the new class.
23 // The creation method for classes created from this factory must not take
24 // any parameters. For a version of this template where the creation method
25 // takes a parameters, see DtStringKeyFactoryWithParam.
26 template <typename T_CreationType>
28 {
29 
30 public:
31  // The creator function signature used by this factory.
32  typedef T_CreationType* (*DtCreatorFcn)();
33  typedef std::map<DtString, DtCreatorFcn> DtCreatorFunctionMap;
34 
35 public:
36  // constructor
38 
39 private:
40  // Not implemented.
42  // Not implemented.
44  orig);
45 
46 public:
47  // Destructor: deletes factory and any entries on the factory.
48  virtual ~DtStringKeyFactory();
49 
50  // Add a creator function to the factory.
51  virtual void addCreatorFcn(const DtString& type, DtCreatorFcn fcn);
52 
53  // Create and return a new instance of the type based on the creator
54  // functions and the type specified.
55  // Prints a warning if not found.
56  virtual T_CreationType* createItem(const DtString& type) const;
57 
58  // Static creator function for this factory, so it can be created
59  // though a factory itself.
62  {
63  return myCreatorFunctionMap;
64  }
65 
66 protected:
68 
69 };
70 
71 // Template for creating factory classes that are keyed off a string type
72 // identifier and take a single argument in the creation method.
73 // Instances if this template are created by specifying the data type that
74 // is to be created by the factory. A creator function prototype is then provided
75 // by the DtCreatorFcn typedef in the new class.
76 // The creation method for classes created from this factory must take
77 // a single parameter. For a version of this template where the creation method
78 // takes no parameters, see DtStringKeyFactory.
79 template <typename T_CreationType, typename T_ConstructorParam>
81 {
82 public:
83  // The creator function signature used by this factory.
84  typedef T_CreationType* (*DtCreatorFcn)(T_ConstructorParam);
85  typedef std::map<DtString, DtCreatorFcn> DtCreatorFunctionMap;
86 
87 public:
88  // constructor
90 
91 private:
92  // Not implemented.
94  // Not implemented.
96  orig);
97 
98 public:
99  // Destructor: deletes factory and any entries on the factory.
101 
102  // Add a creator function to the factory.
103  virtual void addCreatorFcn(const DtString& type, DtCreatorFcn fcn);
104 
105  // Create and return a new instance of the type based on the creator
106  // functions and the type specified passing the specified parameter
107  // to the creation method.
108  // Prints a warning if not found.
109  virtual T_CreationType* createItem(const DtString& type,
110  T_ConstructorParam param) const;
111 
112  // Static creator function for this factory, so it can be created
113  // though a factory itself.
115 
117  {
118  return myCreatorFunctionMap;
119  }
120 
121 protected:
123 
124 };
125 
126 #define stringKeyFactory_inl_
127 #include "tdbutil/stringKeyFactory.inl"
128 #undef stringKeyFactory_inl_
129 
130 #endif

Document ID: Generated on Thu Mar 23 18:54:12 EDT 2017 from SVN revision 174804
Copyright © 2005-2017 VT MÄK. All Rights Reserved (www.mak.com)