6 |
|
* redistribute this software in source and binary code form, provided |
7 |
|
* that the following conditions are met: |
8 |
|
* |
9 |
< |
* 1. Acknowledgement of the program authors must be made in any |
10 |
< |
* publication of scientific results based in part on use of the |
11 |
< |
* program. An acceptable form of acknowledgement is citation of |
12 |
< |
* the article in which the program was described (Matthew |
13 |
< |
* A. Meineke, Charles F. Vardeman II, Teng Lin, Christopher |
14 |
< |
* J. Fennell and J. Daniel Gezelter, "OOPSE: An Object-Oriented |
15 |
< |
* Parallel Simulation Engine for Molecular Dynamics," |
16 |
< |
* J. Comput. Chem. 26, pp. 252-271 (2005)) |
17 |
< |
* |
18 |
< |
* 2. Redistributions of source code must retain the above copyright |
9 |
> |
* 1. Redistributions of source code must retain the above copyright |
10 |
|
* notice, this list of conditions and the following disclaimer. |
11 |
|
* |
12 |
< |
* 3. Redistributions in binary form must reproduce the above copyright |
12 |
> |
* 2. Redistributions in binary form must reproduce the above copyright |
13 |
|
* notice, this list of conditions and the following disclaimer in the |
14 |
|
* documentation and/or other materials provided with the |
15 |
|
* distribution. |
29 |
|
* University of Notre Dame has been advised of the possibility of |
30 |
|
* such damages. |
31 |
|
* |
32 |
+ |
* SUPPORT OPEN SCIENCE! If you use OpenMD or its source code in your |
33 |
+ |
* research, please cite the appropriate papers when you publish your |
34 |
+ |
* work. Good starting points are: |
35 |
+ |
* |
36 |
+ |
* [1] Meineke, et al., J. Comp. Chem. 26, 252-271 (2005). |
37 |
+ |
* [2] Fennell & Gezelter, J. Chem. Phys. 124, 234104 (2006). |
38 |
+ |
* [3] Sun, Lin & Gezelter, J. Chem. Phys. 128, 24107 (2008). |
39 |
+ |
* [4] Vardeman & Gezelter, in progress (2009). |
40 |
|
* |
41 |
|
* ParameterManager.hpp |
43 |
– |
* OOPSE-2.0 |
42 |
|
* |
43 |
|
* Created by Charles F. Vardeman II on 11/16/05. |
44 |
|
* @author Charles F. Vardeman II |
45 |
< |
* @version $Id: ParameterManager.hpp,v 1.3 2006-05-17 21:51:42 tim Exp $ |
45 |
> |
* @version $Id: ParameterManager.hpp,v 1.6 2009-11-25 20:02:04 gezelter Exp $ |
46 |
|
* |
47 |
|
*/ |
48 |
|
|
58 |
|
#include "config.h" |
59 |
|
|
60 |
|
|
61 |
+ |
#include "utils/simError.h" |
62 |
+ |
#include "utils/StringTokenizer.hpp" |
63 |
|
#include "utils/CaseConversion.hpp" |
64 |
|
|
65 |
|
|
66 |
– |
|
66 |
|
template<typename T> |
67 |
|
struct ParameterTraits; |
68 |
|
|
83 |
|
template<typename T> static bool convert(T, RepType&){return false;} |
84 |
|
template<typename T> static RepType convert(T v) {RepType tmp; convert(v,tmp);return tmp;} |
85 |
|
static bool convert(std::string v, RepType& r) { |
86 |
< |
oopse::toLower(v); |
86 |
> |
OpenMD::toLower(v); |
87 |
|
bool result = false; |
88 |
|
if (v == "true") { |
89 |
|
r = true; |
108 |
|
static std::string getParamType() { return "int";} |
109 |
|
}; |
110 |
|
|
111 |
+ |
//int |
112 |
+ |
template<> |
113 |
+ |
struct ParameterTraits<unsigned long int>{ |
114 |
+ |
typedef unsigned long int RepType; |
115 |
+ |
template<typename T> static bool convert(T, RepType&){return false;} |
116 |
+ |
template<typename T> static RepType convert(T v) {RepType tmp; convert(v,tmp);return tmp;} |
117 |
+ |
static bool convert(RepType v, RepType& r) { r=v; return true;} |
118 |
+ |
static bool convert(int v, RepType& r) {r = static_cast<unsigned long int>(v); return true;} |
119 |
+ |
static std::string getParamType() { return "unsigned long int";} |
120 |
+ |
}; |
121 |
+ |
|
122 |
|
//RealType |
123 |
|
template<> |
124 |
|
struct ParameterTraits<RealType>{ |
127 |
|
template<typename T> static RepType convert(T v) {RepType tmp; convert(v,tmp);return tmp;} |
128 |
|
static bool convert(RepType v, RepType& r) {r=v; return true;} |
129 |
|
static bool convert(int v, RepType& r) {r = static_cast<RealType>(v); return true;} |
130 |
+ |
static bool convert(unsigned long int v, RepType& r) {r = static_cast<RealType>(v); return true;} |
131 |
|
static std::string getParamType() { return "RealType";} |
132 |
|
}; |
133 |
|
|
134 |
+ |
//Pair of ints |
135 |
+ |
template<> |
136 |
+ |
struct ParameterTraits<std::pair<int, int> >{ |
137 |
+ |
typedef std::pair<int, int> RepType; |
138 |
+ |
template<typename T> static bool convert(T, RepType&){return false;} |
139 |
+ |
template<typename T> static RepType convert(T v) {RepType tmp; convert(v,tmp);return tmp;} |
140 |
+ |
static bool convert(RepType v, RepType& r) {r=v; return true;} |
141 |
+ |
static bool convert(std::string v, RepType& r) { |
142 |
+ |
OpenMD::StringTokenizer tokenizer(v," ;,\t\n\r"); |
143 |
+ |
if (tokenizer.countTokens() == 2) { |
144 |
+ |
int atom1 = tokenizer.nextTokenAsInt(); |
145 |
+ |
int atom2 = tokenizer.nextTokenAsInt(); |
146 |
+ |
r = std::make_pair(atom1, atom2); |
147 |
+ |
return true; |
148 |
+ |
} else { |
149 |
+ |
sprintf(painCave.errMsg, |
150 |
+ |
"ParameterManager Error: " |
151 |
+ |
"Not enough tokens to make pair!\n"); |
152 |
+ |
painCave.severity = OPENMD_ERROR; |
153 |
+ |
painCave.isFatal = 1; |
154 |
+ |
simError(); |
155 |
+ |
} |
156 |
+ |
return false; |
157 |
+ |
} |
158 |
+ |
static std::string getParamType() { return "std::pair<int, int>";} |
159 |
+ |
}; |
160 |
|
|
161 |
+ |
|
162 |
|
class ParameterBase { |
163 |
|
public: |
164 |
|
ParameterBase() : keyword_(), optional_(false), defaultValue_(false), empty_(true) {} |
172 |
|
bool empty() {return empty_;} |
173 |
|
virtual bool setData(std::string) = 0; |
174 |
|
virtual bool setData(int) = 0; |
175 |
+ |
virtual bool setData(unsigned long int) = 0; |
176 |
|
virtual bool setData(RealType) = 0; |
177 |
+ |
virtual bool setData(std::pair<int, int>) = 0; |
178 |
|
virtual std::string getParamType() = 0; |
179 |
|
protected: |
180 |
< |
std::string keyword_; |
180 |
> |
std::string keyword_; |
181 |
|
bool optional_; |
182 |
|
bool defaultValue_; |
183 |
|
bool empty_; |
193 |
|
virtual bool setData(std::string sval) { |
194 |
|
return internalSetData<std::string>(sval); |
195 |
|
} |
196 |
+ |
|
197 |
|
virtual bool setData(int ival) { |
198 |
|
return internalSetData<int>(ival); |
199 |
|
} |
200 |
+ |
|
201 |
+ |
virtual bool setData(unsigned long int lival) { |
202 |
+ |
return internalSetData<unsigned long int>(lival); |
203 |
+ |
} |
204 |
|
|
205 |
|
virtual bool setData(RealType dval) { |
206 |
|
return internalSetData<RealType>(dval); |
207 |
|
} |
208 |
+ |
|
209 |
+ |
virtual bool setData(std::pair<int, int> pval) { |
210 |
+ |
return internalSetData<std::pair<int, int> >(pval); |
211 |
+ |
} |
212 |
|
|
213 |
|
virtual std::string getParamType() { return ParameterTraits<ParamType>::getParamType();} |
214 |
|
private: |
249 |
|
parameters_.insert(std::map<std::string, ParameterBase*>::value_type(std::string(KEYWORD), static_cast<ParameterBase*>(&NAME))); |
250 |
|
|
251 |
|
#define CheckParameter(NAME, CONSTRAINT) \ |
252 |
< |
if (!NAME.empty()) { if (!(CONSTRAINT)(NAME.getData())) { sprintf(painCave.errMsg,"Error in checking %s : should be %s\n",NAME.getKeyword().c_str(),(CONSTRAINT).getConstraintDescription().c_str()); painCave.isFatal = 1; painCave.severity = OOPSE_ERROR; simError();} } |
252 |
> |
if (!NAME.empty()) { if (!(CONSTRAINT)(NAME.getData())) { sprintf(painCave.errMsg,"Error in checking %s : should be %s\n",NAME.getKeyword().c_str(),(CONSTRAINT).getConstraintDescription().c_str()); painCave.isFatal = 1; painCave.severity = OPENMD_ERROR; simError();} } |
253 |
|
|
254 |
|
|
255 |
|
|