OpenMD 3.1
Molecular Dynamics in the Open
Loading...
Searching...
No Matches
GenericData.hpp
Go to the documentation of this file.
1/*
2 * Copyright (c) 2004-present, The University of Notre Dame. All rights
3 * reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 *
8 * 1. Redistributions of source code must retain the above copyright notice,
9 * this list of conditions and the following disclaimer.
10 *
11 * 2. Redistributions in binary form must reproduce the above copyright notice,
12 * this list of conditions and the following disclaimer in the documentation
13 * and/or other materials provided with the distribution.
14 *
15 * 3. Neither the name of the copyright holder nor the names of its
16 * contributors may be used to endorse or promote products derived from
17 * this software without specific prior written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
23 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
30 *
31 * SUPPORT OPEN SCIENCE! If you use OpenMD or its source code in your
32 * research, please cite the appropriate papers when you publish your
33 * work. Good starting points are:
34 *
35 * [1] Meineke, et al., J. Comp. Chem. 26, 252-271 (2005).
36 * [2] Fennell & Gezelter, J. Chem. Phys. 124, 234104 (2006).
37 * [3] Sun, Lin & Gezelter, J. Chem. Phys. 128, 234107 (2008).
38 * [4] Vardeman, Stocker & Gezelter, J. Chem. Theory Comput. 7, 834 (2011).
39 * [5] Kuang & Gezelter, Mol. Phys., 110, 691-701 (2012).
40 * [6] Lamichhane, Gezelter & Newman, J. Chem. Phys. 141, 134109 (2014).
41 * [7] Lamichhane, Newman & Gezelter, J. Chem. Phys. 141, 134110 (2014).
42 * [8] Bhattarai, Newman & Gezelter, Phys. Rev. B 99, 094106 (2019).
43 */
44
45/**
46 * @file GenericData.hpp
47 * @brief
48 * @author tlin
49 * @date 09/20/2004
50 * @version 1.0
51 */
52
53#ifndef UTIL_GENERICDATA_HPP
54#define UTIL_GENERICDATA_HPP
55
56#include <config.h>
57
58#include <list>
59#include <string>
60#include <vector>
61
62namespace OpenMD {
63
64 /**
65 * @ class GenericData GenericData.hpp "utils/GenericData.hpp"
66 * @brief Base class for generic data which is associated with an id
67 */
69 public:
70 GenericData() : id_("UndefinedGenericData") {}
71
72 GenericData(const std::string& id) { setID(id); }
73
74 /** virtual destructor */
75 virtual ~GenericData() {}
76
77 /**
78 * Returns the id of this generic data
79 *
80 * @return the id of this generic data
81 *
82 * @see #setID
83 */
84 const std::string getID() const { return id_; }
85
86 /**
87 * Sets the id of this generic data
88 *
89 * @param id the id to be set
90 *
91 * @see #getID
92 */
93 void setID(const std::string& id) { id_ = id; }
94
95 private:
97 GenericData& operator=(GenericData&);
98 std::string id_;
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>
108 public:
109 SimpleTypeData() : GenericData(), data_(ElemDataType()) {}
110 SimpleTypeData(const std::string& id) :
111 GenericData(id), data_(ElemDataType()) {}
112 SimpleTypeData(const std::string& id, const ElemDataType& data) :
113 GenericData(id), data_(data) {}
114 template<typename T>
116 data_ = s.getData();
117 }
118
121 if (this == &s) return *this;
122
123 data_ = s.getData();
124 return *this;
125 }
126
127 template<typename T>
129 data_ = s.getData();
130 return *this;
131 }
132
133 /** Returns POD data */
134 const ElemDataType& getData() const { return data_; }
135 ElemDataType& getData() { return data_; }
136 /**
137 * Sets POD data
138 * @param data POD data to be set
139 */
140 void setData(const ElemDataType& data) { data_ = data; }
141
142 private:
143 ElemDataType data_;
144 };
145
146 /** BoolGenericData is a generic data type contains a bool variable */
148
149 /** IntGenericData is a generic data type contains an integer variable */
151
152 /** FloatGenericData is a generic data type contains a float variable */
154
155 /** DoubleGenericData is a generic data type contains a RealType variable */
157
158 /**
159 * @typedef StringGenericData
160 * A generic data type contains a std::string variable
161 *
162 * @code
163 * StringGenericData* s = new StringGenericData("MyStringGenericData");
164 * PropertyMap propMap;
165 * GenericData* gdata;
166 *
167 * s->setData("OpenMD");
168 * propMap->addProperty(s);
169 *
170 * gdata = propMap->getPropertyByName("MyStringGenericData");
171 * if (gdata != NULL){
172 * s = dynamic_cast<StringGenericData*>(gdata);
173 * if (s != NULL)
174 * std::cout << s->getData() << std::endl;
175 * }
176 *
177 * @endcode
178 */
180
181 /**
182 * @class STLContainerTypeData
183 * @brief STL container type generic data which is associated with an id
184 *
185 * \tparam ContainerType
186 * \tparam ElemDataType
187 */
188 template<typename ElemDataType>
190 public:
192
193 VectorTypeData(const std::string& id) : GenericData(id) {}
194
195 VectorTypeData(const SelfType& s) : data_(s) {}
196
197 SelfType& operator=(const SelfType& s) {
198 if (this == &s) 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 */
213
214 /**
215 * @typedef IntVectorGenericData
216 * A generic data type contains a std::vector<float> variable.
217 */
219
220 /**
221 * @typedef IntVectorGenericData
222 * A generic data type contains a std::vector<RealType> variable.
223 */
225
226 /**
227 * @typedef StringVectorGenericData
228 * A generic data type contains a std::vector<string> variable.
229 *
230 * @code
231 * StringVectorGenericData* sv = new
232 * StringVectorGenericData("MyStringVector"); GenericData* gdata; PropertyMap
233 * propMap; std::vector<std::string>::iterator iter;
234 *
235 * sv->push_back("Hello World");
236 * sv->push_back("OpenMD");
237 *
238 * propMap.addProperty(sv);
239 *
240 * gdata = propMap.getPropertyByName("MyStringVector");
241 *
242 * if (gdata != NULL){
243 *
244 * sv = dynamic_cast<StringVectorGenericData*>(gdata);
245 *
246 * if (sv != NULL){
247 * for (iter = sv->begin(); iter != sv->end(); ++ iter)
248 * std::cout << *iter << std::endl;
249 * }
250 * }
251 * @endcode
252 */
254} // namespace OpenMD
255
256#endif // UTIL _GENERICDATA_HPP
@ class GenericData GenericData.hpp "utils/GenericData.hpp"
void setID(const std::string &id)
Sets the id of this generic data.
const std::string getID() const
Returns the id of this generic data.
virtual ~GenericData()
virtual destructor
SimpleTypeData class is a POD repository class.
const ElemDataType & getData() const
Returns POD data.
void setData(const ElemDataType &data)
Sets POD data.
This basic Periodic Table class was originally taken from the data.cpp file in OpenBabel.