40 |
|
|
41 |
|
//forward declaration |
42 |
|
class ForceField; |
43 |
< |
|
43 |
> |
class ForceFieldCreator; |
44 |
|
/** |
45 |
|
* @class ForceFieldFactory ForceFieldFactory.hpp "UseTheForce/ForceFieldFactory.hpp" |
46 |
|
* Factory pattern and Singleton Pattern are used to define an interface for creating an ForceField. |
47 |
|
*/ |
48 |
|
class ForceFieldFactory { |
49 |
|
public: |
50 |
< |
|
51 |
< |
/** a function pointer which has not parameter and return a pointer pointer to a ForceField instance*/ |
52 |
< |
typedef ForceField* (*ForceFieldCreatorType)(); |
53 |
< |
|
54 |
< |
typedef std::map<std::string, ForceFieldCreatorType> CreatorMapType; |
50 |
> |
|
51 |
> |
typedef std::map<std::string, ForceFieldCreator*> CreatorMapType; |
52 |
|
typedef std::vector<std::string> IdentVectorType; |
53 |
|
typedef std::vector<std::string>::iterator IdentVectorIterator; |
54 |
|
|
56 |
|
* Returns an instance of ForceField factory |
57 |
|
* @return an instance of ForceField factory |
58 |
|
*/ |
59 |
< |
static ForceFieldFactory* getInstance(); |
59 |
> |
static ForceFieldFactory* getInstance() { |
60 |
|
|
61 |
+ |
if (instance_ == NULL) { |
62 |
+ |
instance_ = new ForceFieldFactory(); |
63 |
+ |
} |
64 |
+ |
return instance_; |
65 |
+ |
|
66 |
+ |
} |
67 |
+ |
|
68 |
|
/** |
69 |
|
* Registers a creator with a type identifier |
70 |
|
* @return true if registration is succeed, otherwise return false |
71 |
|
* @id the identification of the concrete object |
72 |
|
* @creator the object responsible to create the concrete object |
73 |
|
*/ |
74 |
< |
bool registerForceField(const std::string& id, ForceFieldCreatorType creator); |
74 |
> |
bool registerForceField(ForceFieldCreator* creator); |
75 |
|
|
76 |
|
/** |
77 |
|
* Unregisters the creator for the given type identifier. If the type identifier |