ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/OpenMD/branches/development/src/utils/GenericData.hpp
Revision: 1665
Committed: Tue Nov 22 20:38:56 2011 UTC (13 years, 5 months ago) by gezelter
File size: 7836 byte(s)
Log Message:
updated copyright notices

File Contents

# Content
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 <list>
56 #include <string>
57 #include <vector>
58 #include "config.h"
59 namespace OpenMD{
60
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 GenericData(const std::string& id) { setID(id); }
70
71 /** virtual destructor */
72 virtual ~GenericData() {}
73
74
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 * 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
94 private:
95 GenericData(const GenericData&);
96 GenericData& operator=(GenericData&);
97 std::string id_;
98
99 };
100
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
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 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 private:
141 ElemDataType data_;
142 };
143
144 /** BoolGenericData is a generic data type contains a bool variable */
145 typedef SimpleTypeData<bool> BoolGenericData;
146
147 /** IntGenericData is a generic data type contains an integer variable */
148 typedef SimpleTypeData<int> IntGenericData;
149
150 /** FloatGenericData is a generic data type contains a float variable */
151 typedef SimpleTypeData<float> FloatGenericData;
152
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 * @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 VectorTypeData(const std::string& id)
192 : GenericData(id){}
193
194 VectorTypeData(const SelfType& s) : data_(s){}
195
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 std::vector<ElemDataType> data_;
206 };
207
208 /**
209 * @typedef IntVectorGenericData
210 * A generic data type contains a std::vector<int> variable.
211 */
212 typedef VectorTypeData<int> IntVectorGenericData;
213
214 /**
215 * @typedef IntVectorGenericData
216 * A generic data type contains a std::vector<float> variable.
217 */
218 typedef VectorTypeData<float> FloatVectorGenericData;
219
220 /**
221 * @typedef IntVectorGenericData
222 * A generic data type contains a std::vector<RealType> variable.
223 */
224 typedef VectorTypeData<RealType> DoubleVectorGenericData;
225
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 } // namespace OpenMD
258 #endif //UTIL _GENERICDATA_HPP

Properties

Name Value
svn:keywords Author Id Revision Date