1 |
tim |
1740 |
/* |
2 |
|
|
* Copyright (C) 2000-2004 Object Oriented Parallel Simulation Engine (OOPSE) project |
3 |
|
|
* |
4 |
|
|
* Contact: oopse@oopse.org |
5 |
|
|
* |
6 |
|
|
* This program is free software; you can redistribute it and/or |
7 |
|
|
* modify it under the terms of the GNU Lesser General Public License |
8 |
|
|
* as published by the Free Software Foundation; either version 2.1 |
9 |
|
|
* of the License, or (at your option) any later version. |
10 |
|
|
* All we ask is that proper credit is given for our work, which includes |
11 |
|
|
* - but is not limited to - adding the above copyright notice to the beginning |
12 |
|
|
* of your source code files, and to any copyright notice that you may distribute |
13 |
|
|
* with programs based on this work. |
14 |
|
|
* |
15 |
|
|
* This program is distributed in the hope that it will be useful, |
16 |
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
17 |
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
18 |
|
|
* GNU Lesser General Public License for more details. |
19 |
|
|
* |
20 |
|
|
* You should have received a copy of the GNU Lesser General Public License |
21 |
|
|
* along with this program; if not, write to the Free Software |
22 |
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
23 |
|
|
* |
24 |
|
|
*/ |
25 |
|
|
|
26 |
|
|
/** |
27 |
|
|
* @file ForceFieldFactory.hpp |
28 |
|
|
* @author Teng Lin |
29 |
|
|
* @date 10/24/2004 |
30 |
|
|
* @version 1.0 |
31 |
|
|
*/ |
32 |
|
|
#ifndef USETHEFORCE_FORCEFIELDFACTORY_HPP |
33 |
|
|
#define USETHEFORCE_FORCEFIELDFACTORY_HPP |
34 |
|
|
#include <cassert> |
35 |
|
|
#include <map> |
36 |
|
|
#include <string> |
37 |
|
|
#include <vector> |
38 |
tim |
1783 |
#include <iostream> |
39 |
tim |
1740 |
namespace oopse { |
40 |
|
|
|
41 |
|
|
//forward declaration |
42 |
|
|
class ForceField; |
43 |
tim |
1837 |
class ForceFieldCreator; |
44 |
tim |
1740 |
/** |
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 |
tim |
1837 |
|
51 |
|
|
typedef std::map<std::string, ForceFieldCreator*> CreatorMapType; |
52 |
tim |
1740 |
typedef std::vector<std::string> IdentVectorType; |
53 |
|
|
typedef std::vector<std::string>::iterator IdentVectorIterator; |
54 |
|
|
|
55 |
|
|
/** |
56 |
|
|
* Returns an instance of ForceField factory |
57 |
|
|
* @return an instance of ForceField factory |
58 |
|
|
*/ |
59 |
tim |
1824 |
static ForceFieldFactory* getInstance() { |
60 |
tim |
1740 |
|
61 |
tim |
1824 |
if (instance_ == NULL) { |
62 |
|
|
instance_ = new ForceFieldFactory(); |
63 |
|
|
} |
64 |
|
|
return instance_; |
65 |
|
|
|
66 |
|
|
} |
67 |
|
|
|
68 |
tim |
1740 |
/** |
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 |
tim |
1837 |
bool registerForceField(ForceFieldCreator* creator); |
75 |
tim |
1740 |
|
76 |
|
|
/** |
77 |
|
|
* Unregisters the creator for the given type identifier. If the type identifier |
78 |
|
|
* was previously registered, the function returns true. |
79 |
|
|
* @return truethe type identifier was previously registered and the creator is removed, |
80 |
|
|
* otherwise return false |
81 |
|
|
* @id the identification of the concrete object |
82 |
|
|
*/ |
83 |
|
|
bool unregisterForceField(const std::string& id); |
84 |
|
|
/** |
85 |
|
|
* Looks up the type identifier in the internal map. If it is found, it invokes the |
86 |
|
|
* corresponding creator for the type identifier and returns its result. |
87 |
|
|
* @return a pointer of the concrete object, return NULL if no creator is registed for |
88 |
|
|
* creating this concrete object |
89 |
|
|
* @param id the identification of the concrete object |
90 |
|
|
*/ |
91 |
|
|
ForceField* createForceField(const std::string& id); |
92 |
|
|
|
93 |
|
|
/** |
94 |
|
|
* Returns all of the registed type identifiers |
95 |
|
|
* @return all of the registed type identifiers |
96 |
|
|
*/ |
97 |
|
|
IdentVectorType getIdents(); |
98 |
|
|
|
99 |
|
|
private: |
100 |
|
|
static ForceFieldFactory* instance_; |
101 |
|
|
CreatorMapType creatorMap_; |
102 |
|
|
}; |
103 |
|
|
|
104 |
|
|
/** write out all of the type identifiers to an output stream */ |
105 |
|
|
std::ostream& operator <<(std::ostream& o, ForceFieldFactory& factory); |
106 |
|
|
|
107 |
|
|
}//namespace oopse |
108 |
|
|
#endif //USETHEFORCE_FORCEFIELDFACTORY_HPP |