ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/OpenMD/branches/development/src/utils/GenericData.hpp
Revision: 1390
Committed: Wed Nov 25 20:02:06 2009 UTC (15 years, 5 months ago) by gezelter
Original Path: trunk/src/utils/GenericData.hpp
File size: 7770 byte(s)
Log Message:
Almost all of the changes necessary to create OpenMD out of our old
project (OOPSE-4)

File Contents

# User Rev Content
1 gezelter 507 /*
2 gezelter 246 * Copyright (c) 2005 The University of Notre Dame. All Rights Reserved.
3 tim 132 *
4 gezelter 246 * 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 gezelter 1390 * 1. Redistributions of source code must retain the above copyright
10 gezelter 246 * notice, this list of conditions and the following disclaimer.
11     *
12 gezelter 1390 * 2. Redistributions in binary form must reproduce the above copyright
13 gezelter 246 * 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 gezelter 1390 *
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 tim 132 */
41 gezelter 246
42 tim 132 /**
43     * @file GenericData.hpp
44     * @brief
45     * @author tlin
46     * @date 09/20/2004
47     * @time 9:30am
48     * @version 1.0
49     */
50    
51     #ifndef UTIL_GENERICDATA_HPP
52     #define UTIL_GENERICDATA_HPP
53    
54     #include <list>
55 gezelter 2 #include <string>
56     #include <vector>
57 tim 963 #include "config.h"
58 gezelter 1390 namespace OpenMD{
59 gezelter 2
60 gezelter 507 /**
61     * @ class GenericData GenericData.hpp "utils/GenericData.hpp"
62     * @brief Base class for generic data which is associated with an id
63     */
64     class GenericData{
65     public:
66     GenericData() : id_("UndefinedGenericData"){}
67 gezelter 2
68 gezelter 507 GenericData(const std::string& id) { setID(id); }
69 gezelter 2
70 gezelter 507 /** virtual destructor */
71     virtual ~GenericData() {}
72 gezelter 2
73    
74 gezelter 507 /**
75     * Returns the id of this generic data
76     *
77     * @return the id of this generic data
78     *
79     * @see #setID
80     */
81     const std::string getID() const { return id_; }
82 gezelter 2
83 gezelter 507 /**
84     * Sets the id of this generic data
85     *
86     * @param id the id to be set
87     *
88     * @see #getID
89     */
90     void setID(const std::string& id) { id_ = id; }
91 gezelter 2
92 tim 132
93 gezelter 507 private:
94     GenericData(const GenericData&);
95     GenericData& operator=(GenericData&);
96     std::string id_;
97 gezelter 2
98 gezelter 507 };
99 gezelter 2
100 gezelter 507 /**
101     * @class SimpleTypeData
102     * @brief SimpleTypeData class is a POD repository class
103     * @warning ElemDataType must be copy constructible, and copy assignable
104     */
105     template<typename ElemDataType> class SimpleTypeData : public GenericData{
106 gezelter 2
107 gezelter 507 public:
108     SimpleTypeData() : GenericData(), data_(ElemDataType()) {}
109     SimpleTypeData(const std::string& id) : GenericData(id), data_(ElemDataType()) {}
110     SimpleTypeData(const std::string&id , const ElemDataType& data) : GenericData(id), data_(data) {}
111     template<typename T>
112     SimpleTypeData(const SimpleTypeData<T>& s) {
113     data_ = s.getData();
114     }
115 gezelter 2
116 gezelter 507 SimpleTypeData<ElemDataType>& operator =(const SimpleTypeData<ElemDataType>& s) {
117     if (this == &s)
118     return *this;
119 tim 132
120 gezelter 507 data_ = s.getData();
121     return *this;
122     }
123 tim 132
124 gezelter 507 template<typename T>
125     SimpleTypeData<ElemDataType>& operator =(const SimpleTypeData<T>& s) {
126     data_ = s.getData();
127     return *this;
128     }
129 tim 132
130 gezelter 507 /** Returns POD data */
131     const ElemDataType& getData() const {return data_;}
132     ElemDataType& getData() {return data_;}
133     /**
134     * Sets POD data
135     * @data POD data to be set
136     */
137     void setData(const ElemDataType& data) { data_ = data; }
138 gezelter 2
139 gezelter 507 private:
140     ElemDataType data_;
141     };
142 gezelter 2
143 gezelter 507 /** BoolGenericData is a generic data type contains a bool variable */
144     typedef SimpleTypeData<bool> BoolGenericData;
145 gezelter 2
146 gezelter 507 /** IntGenericData is a generic data type contains an integer variable */
147     typedef SimpleTypeData<int> IntGenericData;
148 gezelter 2
149 gezelter 507 /** FloatGenericData is a generic data type contains a float variable */
150     typedef SimpleTypeData<float> FloatGenericData;
151 gezelter 2
152 tim 963 /** DoubleGenericData is a generic data type contains a RealType variable */
153     typedef SimpleTypeData<RealType> DoubleGenericData;
154 tim 132
155 gezelter 507 /**
156     * @typedef StringGenericData
157     * A generic data type contains a std::string variable
158     *
159     * @code
160     * StringGenericData* s = new StringGenericData("MyStringGenericData");
161     * PropertyMap propMap;
162     * GenericData* gdata;
163     *
164 gezelter 1390 * s->setData("OpenMD");
165 gezelter 507 * propMap->addProperty(s);
166     *
167     * gdata = propMap->getPropertyByName("MyStringGenericData");
168     * if (gdata != NULL){
169     * s = dynamic_cast<StringGenericData*>(gdata);
170     * if (s != NULL)
171     * std::cout << s->getData() << std::endl;
172     * }
173     *
174     * @endcode
175     */
176     typedef SimpleTypeData<std::string> StringGenericData;
177 gezelter 2
178 gezelter 507 /**
179     * @class STLContainerTypeData
180     * @brief STL container type generic data which is associated with an id
181     *
182     * @template ContainerType
183     * @template ElemDataType
184     */
185     template <typename ElemDataType >
186     class VectorTypeData : public GenericData {
187     public:
188     typedef VectorTypeData<ElemDataType> SelfType;
189 gezelter 2
190 gezelter 507 VectorTypeData(const std::string& id)
191     : GenericData(id){}
192 tim 132
193 gezelter 877 VectorTypeData(const SelfType& s) : data_(s){}
194 gezelter 2
195 gezelter 507 SelfType& operator =(const SelfType& s){
196     if (this == &s)
197     return *this;
198 gezelter 2
199 gezelter 507 this->data_ = s.data_;
200     return *this;
201     }
202 tim 385
203 gezelter 507 private:
204     std::vector<ElemDataType> data_;
205     };
206 gezelter 2
207 gezelter 507 /**
208     * @typedef IntVectorGenericData
209     * A generic data type contains a std::vector<int> variable.
210     */
211     typedef VectorTypeData<int> IntVectorGenericData;
212 gezelter 2
213 gezelter 507 /**
214     * @typedef IntVectorGenericData
215     * A generic data type contains a std::vector<float> variable.
216     */
217     typedef VectorTypeData<float> FloatVectorGenericData;
218 gezelter 2
219 gezelter 507 /**
220     * @typedef IntVectorGenericData
221 tim 963 * A generic data type contains a std::vector<RealType> variable.
222 gezelter 507 */
223 tim 963 typedef VectorTypeData<RealType> DoubleVectorGenericData;
224 gezelter 2
225 gezelter 507 /**
226     * @typedef StringVectorGenericData
227     * A generic data type contains a std::vector<string> variable.
228     *
229     * @code
230     * StringVectorGenericData* sv = new StringVectorGenericData("MyStringVector");
231     * GenericData* gdata;
232     * PropertyMap propMap;
233     * std::vector<std::string>::iterator iter;
234     *
235     * sv->push_back("Hello World");
236 gezelter 1390 * sv->push_back("OpenMD");
237 gezelter 507 *
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     */
253     typedef VectorTypeData<std::string> StringVectorGenericData;
254 tim 132
255 gezelter 2
256 gezelter 1390 } // namespace OpenMD
257 tim 132 #endif //UTIL _GENERICDATA_HPP