1 |
< |
#ifndef __GENERICDATA_H__ |
2 |
< |
#define __GENERICDATA_H__ |
1 |
> |
/* |
2 |
> |
* Copyright (c) 2005 The University of Notre Dame. All Rights Reserved. |
3 |
> |
* |
4 |
> |
* The University of Notre Dame grants you ("Licensee") a |
5 |
> |
* non-exclusive, royalty free, license to use, modify and |
6 |
> |
* redistribute this software in source and binary code form, provided |
7 |
> |
* that the following conditions are met: |
8 |
> |
* |
9 |
> |
* 1. Redistributions of source code must retain the above copyright |
10 |
> |
* notice, this list of conditions and the following disclaimer. |
11 |
> |
* |
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. |
16 |
> |
* |
17 |
> |
* This software is provided "AS IS," without a warranty of any |
18 |
> |
* kind. All express or implied conditions, representations and |
19 |
> |
* warranties, including any implied warranty of merchantability, |
20 |
> |
* fitness for a particular purpose or non-infringement, are hereby |
21 |
> |
* excluded. The University of Notre Dame and its licensors shall not |
22 |
> |
* be liable for any damages suffered by licensee as a result of |
23 |
> |
* using, modifying or distributing the software or its |
24 |
> |
* derivatives. In no event will the University of Notre Dame or its |
25 |
> |
* licensors be liable for any lost revenue, profit or data, or for |
26 |
> |
* direct, indirect, special, consequential, incidental or punitive |
27 |
> |
* damages, however caused and regardless of the theory of liability, |
28 |
> |
* arising out of the use of or inability to use software, even if the |
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] Kuang & Gezelter, J. Chem. Phys. 133, 164101 (2010). |
40 |
> |
* [5] Vardeman, Stocker & Gezelter, J. Chem. Theory Comput. 7, 834 (2011). |
41 |
> |
*/ |
42 |
> |
|
43 |
> |
/** |
44 |
> |
* @file GenericData.hpp |
45 |
> |
* @brief |
46 |
> |
* @author tlin |
47 |
> |
* @date 09/20/2004 |
48 |
> |
* @time 9:30am |
49 |
> |
* @version 1.0 |
50 |
> |
*/ |
51 |
> |
|
52 |
> |
#ifndef UTIL_GENERICDATA_HPP |
53 |
> |
#define UTIL_GENERICDATA_HPP |
54 |
|
|
55 |
< |
#include <algorithm> |
55 |
> |
#include <list> |
56 |
|
#include <string> |
57 |
|
#include <vector> |
58 |
+ |
#include "config.h" |
59 |
+ |
namespace OpenMD{ |
60 |
|
|
61 |
< |
#define ZCONSTIME_ID "ZCONSTIME" |
62 |
< |
#define ZCONSPARADATA_ID "ZCONSPARA" |
63 |
< |
#define ZCONSFILENAME_ID "ZCONSFILENAME" |
64 |
< |
#define ZCONSTOL_ID "ZCONSTOL" |
65 |
< |
#define ZCONSFORCEPOLICY_ID "ZCONSFORCEPOLICY" |
66 |
< |
#define ZCONSGAP_ID "ZCONSGAP" |
67 |
< |
#define ZCONSFIXTIME_ID "ZCONSFIXTIME" |
15 |
< |
#define ZCONSUSINGSMD_ID "ZCONSUSINGSMD" |
61 |
> |
/** |
62 |
> |
* @ class GenericData GenericData.hpp "utils/GenericData.hpp" |
63 |
> |
* @brief Base class for generic data which is associated with an id |
64 |
> |
*/ |
65 |
> |
class GenericData{ |
66 |
> |
public: |
67 |
> |
GenericData() : id_("UndefinedGenericData"){} |
68 |
|
|
69 |
< |
#define CHIVALUE_ID "CHIVALUE" |
18 |
< |
#define INTEGRALOFCHIDT_ID "INTEGRALOFCHIDT" |
19 |
< |
#define ETAVALUE_ID "ETAVALUE" |
69 |
> |
GenericData(const std::string& id) { setID(id); } |
70 |
|
|
71 |
< |
using namespace std; |
22 |
< |
//////////////////////////////////////////////////////////////////////////////// |
23 |
< |
//Declaration of GenericData |
24 |
< |
//////////////////////////////////////////////////////////////////////////////// |
25 |
< |
class GenericData |
26 |
< |
{ |
27 |
< |
public: |
28 |
< |
GenericData(); |
29 |
< |
GenericData(const GenericData& rhs) { id = rhs.getID(); } |
30 |
< |
GenericData& operator =(const GenericData& rhs); |
71 |
> |
/** virtual destructor */ |
72 |
|
virtual ~GenericData() {} |
73 |
|
|
33 |
– |
const string& getID() const { return id; } |
34 |
– |
void setID(const string& rhs) { id = rhs; } |
74 |
|
|
75 |
< |
protected: |
76 |
< |
string id; |
77 |
< |
}; |
75 |
> |
/** |
76 |
> |
* Returns the id of this generic data |
77 |
> |
* |
78 |
> |
* @return the id of this generic data |
79 |
> |
* |
80 |
> |
* @see #setID |
81 |
> |
*/ |
82 |
> |
const std::string getID() const { return id_; } |
83 |
|
|
84 |
< |
/** |
85 |
< |
* Something we can improve it here is to use template |
86 |
< |
*/ |
87 |
< |
//////////////////////////////////////////////////////////////////////////////// |
88 |
< |
//Declaration of IntData |
89 |
< |
//////////////////////////////////////////////////////////////////////////////// |
90 |
< |
class IntData : public GenericData{ |
84 |
> |
/** |
85 |
> |
* Sets the id of this generic data |
86 |
> |
* |
87 |
> |
* @param id the id to be set |
88 |
> |
* |
89 |
> |
* @see #getID |
90 |
> |
*/ |
91 |
> |
void setID(const std::string& id) { id_ = id; } |
92 |
|
|
93 |
< |
public: |
93 |
> |
|
94 |
> |
private: |
95 |
> |
GenericData(const GenericData&); |
96 |
> |
GenericData& operator=(GenericData&); |
97 |
> |
std::string id_; |
98 |
|
|
99 |
< |
double getData() { return data; } |
51 |
< |
void setData(int rhs) { data = rhs; } |
99 |
> |
}; |
100 |
|
|
101 |
< |
protected: |
102 |
< |
int data; |
103 |
< |
}; |
101 |
> |
/** |
102 |
> |
* @class SimpleTypeData |
103 |
> |
* @brief SimpleTypeData class is a POD repository class |
104 |
> |
* @warning ElemDataType must be copy constructible, and copy assignable |
105 |
> |
*/ |
106 |
> |
template<typename ElemDataType> class SimpleTypeData : public GenericData{ |
107 |
|
|
57 |
– |
//////////////////////////////////////////////////////////////////////////////// |
58 |
– |
//Declaration of DoubleData |
59 |
– |
//////////////////////////////////////////////////////////////////////////////// |
60 |
– |
class DoubleData : public GenericData{ |
61 |
– |
|
108 |
|
public: |
109 |
+ |
SimpleTypeData() : GenericData(), data_(ElemDataType()) {} |
110 |
+ |
SimpleTypeData(const std::string& id) : GenericData(id), data_(ElemDataType()) {} |
111 |
+ |
SimpleTypeData(const std::string&id , const ElemDataType& data) : GenericData(id), data_(data) {} |
112 |
+ |
template<typename T> |
113 |
+ |
SimpleTypeData(const SimpleTypeData<T>& s) { |
114 |
+ |
data_ = s.getData(); |
115 |
+ |
} |
116 |
|
|
117 |
< |
double getData() { return data; } |
118 |
< |
void setData(double rhs) { data = rhs; } |
117 |
> |
SimpleTypeData<ElemDataType>& operator =(const SimpleTypeData<ElemDataType>& s) { |
118 |
> |
if (this == &s) |
119 |
> |
return *this; |
120 |
> |
|
121 |
> |
data_ = s.getData(); |
122 |
> |
return *this; |
123 |
> |
} |
124 |
> |
|
125 |
> |
template<typename T> |
126 |
> |
SimpleTypeData<ElemDataType>& operator =(const SimpleTypeData<T>& s) { |
127 |
> |
data_ = s.getData(); |
128 |
> |
return *this; |
129 |
> |
} |
130 |
> |
|
131 |
> |
/** Returns POD data */ |
132 |
> |
const ElemDataType& getData() const {return data_;} |
133 |
> |
ElemDataType& getData() {return data_;} |
134 |
> |
/** |
135 |
> |
* Sets POD data |
136 |
> |
* @data POD data to be set |
137 |
> |
*/ |
138 |
> |
void setData(const ElemDataType& data) { data_ = data; } |
139 |
|
|
140 |
< |
protected: |
141 |
< |
double data; |
142 |
< |
}; |
140 |
> |
private: |
141 |
> |
ElemDataType data_; |
142 |
> |
}; |
143 |
|
|
144 |
< |
//////////////////////////////////////////////////////////////////////////////// |
145 |
< |
//Declaration of StringData |
73 |
< |
//////////////////////////////////////////////////////////////////////////////// |
74 |
< |
class StringData : public GenericData{ |
144 |
> |
/** BoolGenericData is a generic data type contains a bool variable */ |
145 |
> |
typedef SimpleTypeData<bool> BoolGenericData; |
146 |
|
|
147 |
< |
public: |
148 |
< |
const string& getData() const { return data; } |
78 |
< |
void setData(const string& rhs) { data = rhs; } |
79 |
< |
protected: |
80 |
< |
string data; |
81 |
< |
}; |
147 |
> |
/** IntGenericData is a generic data type contains an integer variable */ |
148 |
> |
typedef SimpleTypeData<int> IntGenericData; |
149 |
|
|
150 |
< |
//////////////////////////////////////////////////////////////////////////////// |
151 |
< |
//Declaration of BoolData |
85 |
< |
//////////////////////////////////////////////////////////////////////////////// |
86 |
< |
class BoolData : public GenericData{ |
87 |
< |
public: |
88 |
< |
bool getData() const { return data; } |
89 |
< |
void setData(const bool rhs) { data = rhs; } |
90 |
< |
protected: |
91 |
< |
bool data; |
150 |
> |
/** FloatGenericData is a generic data type contains a float variable */ |
151 |
> |
typedef SimpleTypeData<float> FloatGenericData; |
152 |
|
|
153 |
< |
}; |
153 |
> |
/** DoubleGenericData is a generic data type contains a RealType variable */ |
154 |
> |
typedef SimpleTypeData<RealType> DoubleGenericData; |
155 |
> |
|
156 |
> |
/** |
157 |
> |
* @typedef StringGenericData |
158 |
> |
* A generic data type contains a std::string variable |
159 |
> |
* |
160 |
> |
* @code |
161 |
> |
* StringGenericData* s = new StringGenericData("MyStringGenericData"); |
162 |
> |
* PropertyMap propMap; |
163 |
> |
* GenericData* gdata; |
164 |
> |
* |
165 |
> |
* s->setData("OpenMD"); |
166 |
> |
* propMap->addProperty(s); |
167 |
> |
* |
168 |
> |
* gdata = propMap->getPropertyByName("MyStringGenericData"); |
169 |
> |
* if (gdata != NULL){ |
170 |
> |
* s = dynamic_cast<StringGenericData*>(gdata); |
171 |
> |
* if (s != NULL) |
172 |
> |
* std::cout << s->getData() << std::endl; |
173 |
> |
* } |
174 |
> |
* |
175 |
> |
* @endcode |
176 |
> |
*/ |
177 |
> |
typedef SimpleTypeData<std::string> StringGenericData; |
178 |
|
|
179 |
< |
//////////////////////////////////////////////////////////////////////////////// |
180 |
< |
//Declaration of ZConsParaData |
181 |
< |
//////////////////////////////////////////////////////////////////////////////// |
182 |
< |
struct ZConsParaItem { |
183 |
< |
int zconsIndex; |
184 |
< |
bool havingZPos; |
185 |
< |
double zPos; |
186 |
< |
double kRatio; |
187 |
< |
bool havingCantVel; |
188 |
< |
double cantVel; |
189 |
< |
}; |
179 |
> |
/** |
180 |
> |
* @class STLContainerTypeData |
181 |
> |
* @brief STL container type generic data which is associated with an id |
182 |
> |
* |
183 |
> |
* @template ContainerType |
184 |
> |
* @template ElemDataType |
185 |
> |
*/ |
186 |
> |
template <typename ElemDataType > |
187 |
> |
class VectorTypeData : public GenericData { |
188 |
> |
public: |
189 |
> |
typedef VectorTypeData<ElemDataType> SelfType; |
190 |
|
|
191 |
< |
class ZConsParaData : public GenericData{ |
191 |
> |
VectorTypeData(const std::string& id) |
192 |
> |
: GenericData(id){} |
193 |
> |
|
194 |
> |
VectorTypeData(const SelfType& s) : data_(s){} |
195 |
|
|
196 |
< |
public: |
197 |
< |
ZConsParaData(); |
198 |
< |
void addItem(ZConsParaItem& item) {data.push_back(item);} |
112 |
< |
vector<ZConsParaItem>* getData() {return &data;} |
113 |
< |
void setData(vector<ZConsParaItem>& theData) {data = theData;} |
114 |
< |
void sortByIndex(); |
115 |
< |
bool isIndexUnique(); |
196 |
> |
SelfType& operator =(const SelfType& s){ |
197 |
> |
if (this == &s) |
198 |
> |
return *this; |
199 |
|
|
200 |
+ |
this->data_ = s.data_; |
201 |
+ |
return *this; |
202 |
+ |
} |
203 |
+ |
|
204 |
|
private: |
205 |
< |
vector<ZConsParaItem> data; |
205 |
> |
std::vector<ElemDataType> data_; |
206 |
|
}; |
207 |
|
|
208 |
< |
class ZConsParaSortCriterion{ |
209 |
< |
public: |
210 |
< |
bool operator ()(const ZConsParaItem& item1, const ZConsParaItem& item2){ |
211 |
< |
return item1.zconsIndex < item2.zconsIndex; |
212 |
< |
} |
208 |
> |
/** |
209 |
> |
* @typedef IntVectorGenericData |
210 |
> |
* A generic data type contains a std::vector<int> variable. |
211 |
> |
*/ |
212 |
> |
typedef VectorTypeData<int> IntVectorGenericData; |
213 |
|
|
214 |
< |
}; |
214 |
> |
/** |
215 |
> |
* @typedef IntVectorGenericData |
216 |
> |
* A generic data type contains a std::vector<float> variable. |
217 |
> |
*/ |
218 |
> |
typedef VectorTypeData<float> FloatVectorGenericData; |
219 |
|
|
220 |
< |
//////////////////////////////////////////////////////////////////////////////// |
221 |
< |
//Declaration of IntData |
222 |
< |
//////////////////////////////////////////////////////////////////////////////// |
223 |
< |
class DoubleArrayData : public GenericData{ |
220 |
> |
/** |
221 |
> |
* @typedef IntVectorGenericData |
222 |
> |
* A generic data type contains a std::vector<RealType> variable. |
223 |
> |
*/ |
224 |
> |
typedef VectorTypeData<RealType> DoubleVectorGenericData; |
225 |
|
|
226 |
< |
public: |
227 |
< |
vector<double> getData() const { return data; } |
228 |
< |
void setData(double* source, int num){ |
229 |
< |
data.clear(); |
230 |
< |
for(int i = 0; i < num; i++) |
231 |
< |
data.push_back(source[i]); |
232 |
< |
} |
233 |
< |
protected: |
234 |
< |
vector<double> data; |
235 |
< |
}; |
226 |
> |
/** |
227 |
> |
* @typedef StringVectorGenericData |
228 |
> |
* A generic data type contains a std::vector<string> variable. |
229 |
> |
* |
230 |
> |
* @code |
231 |
> |
* StringVectorGenericData* sv = new StringVectorGenericData("MyStringVector"); |
232 |
> |
* GenericData* gdata; |
233 |
> |
* PropertyMap propMap; |
234 |
> |
* std::vector<std::string>::iterator iter; |
235 |
> |
* |
236 |
> |
* sv->push_back("Hello World"); |
237 |
> |
* sv->push_back("OpenMD"); |
238 |
> |
* |
239 |
> |
* propMap.addProperty(sv); |
240 |
> |
* |
241 |
> |
* gdata = propMap.getPropertyByName("MyStringVector"); |
242 |
> |
* |
243 |
> |
* if (gdata != NULL){ |
244 |
> |
* |
245 |
> |
* sv = dynamic_cast<StringVectorGenericData*>(gdata); |
246 |
> |
* |
247 |
> |
* if (sv != NULL){ |
248 |
> |
* for (iter = sv->begin(); iter != sv->end(); ++ iter) |
249 |
> |
* std::cout << *iter << std::endl; |
250 |
> |
* } |
251 |
> |
* } |
252 |
> |
* @endcode |
253 |
> |
*/ |
254 |
> |
typedef VectorTypeData<std::string> StringVectorGenericData; |
255 |
> |
|
256 |
|
|
257 |
< |
//////////////////////////////////////////////////////////////////////////////// |
258 |
< |
//Declaration of AtomData |
147 |
< |
//////////////////////////////////////////////////////////////////////////////// |
148 |
< |
struct AtomInfo : public GenericData{ |
149 |
< |
public: |
150 |
< |
string AtomType; |
151 |
< |
double pos[3]; |
152 |
< |
double dipole[3]; |
153 |
< |
}; |
154 |
< |
|
155 |
< |
class AtomData : public GenericData{ |
156 |
< |
public: |
157 |
< |
~AtomData(); |
158 |
< |
void addAtomInfo(AtomInfo* info) {data.push_back(info);} |
159 |
< |
void clearAllAtomInfo(); |
160 |
< |
AtomInfo* beginAtomInfo(vector<AtomInfo*>::iterator& i){ |
161 |
< |
i = data.begin(); |
162 |
< |
return i != data.end()? *i : NULL; |
163 |
< |
} |
164 |
< |
AtomInfo* nextAtomInfo(vector<AtomInfo*>::iterator& i){ |
165 |
< |
++i; |
166 |
< |
return i != data.end()? *i: NULL; |
167 |
< |
} |
168 |
< |
vector<AtomInfo*> getData() {return data;} |
169 |
< |
int getSize() {return data.size();} |
170 |
< |
protected: |
171 |
< |
vector<AtomInfo*> data; |
172 |
< |
}; |
173 |
< |
|
174 |
< |
#endif |
257 |
> |
} // namespace OpenMD |
258 |
> |
#endif //UTIL _GENERICDATA_HPP |