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

# 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 gezelter 1665 * [4] Kuang & Gezelter, J. Chem. Phys. 133, 164101 (2010).
40     * [5] Vardeman, Stocker & Gezelter, J. Chem. Theory Comput. 7, 834 (2011).
41 tim 132 */
42 gezelter 246
43 tim 132 /**
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 gezelter 2 #include <string>
57     #include <vector>
58 tim 963 #include "config.h"
59 gezelter 1390 namespace OpenMD{
60 gezelter 2
61 gezelter 507 /**
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 gezelter 2
69 gezelter 507 GenericData(const std::string& id) { setID(id); }
70 gezelter 2
71 gezelter 507 /** virtual destructor */
72     virtual ~GenericData() {}
73 gezelter 2
74    
75 gezelter 507 /**
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 gezelter 2
84 gezelter 507 /**
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 gezelter 2
93 tim 132
94 gezelter 507 private:
95     GenericData(const GenericData&);
96     GenericData& operator=(GenericData&);
97     std::string id_;
98 gezelter 2
99 gezelter 507 };
100 gezelter 2
101 gezelter 507 /**
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 gezelter 2
108 gezelter 507 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 gezelter 2
117 gezelter 507 SimpleTypeData<ElemDataType>& operator =(const SimpleTypeData<ElemDataType>& s) {
118     if (this == &s)
119     return *this;
120 tim 132
121 gezelter 507 data_ = s.getData();
122     return *this;
123     }
124 tim 132
125 gezelter 507 template<typename T>
126     SimpleTypeData<ElemDataType>& operator =(const SimpleTypeData<T>& s) {
127     data_ = s.getData();
128     return *this;
129     }
130 tim 132
131 gezelter 507 /** 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 gezelter 2
140 gezelter 507 private:
141     ElemDataType data_;
142     };
143 gezelter 2
144 gezelter 507 /** BoolGenericData is a generic data type contains a bool variable */
145     typedef SimpleTypeData<bool> BoolGenericData;
146 gezelter 2
147 gezelter 507 /** IntGenericData is a generic data type contains an integer variable */
148     typedef SimpleTypeData<int> IntGenericData;
149 gezelter 2
150 gezelter 507 /** FloatGenericData is a generic data type contains a float variable */
151     typedef SimpleTypeData<float> FloatGenericData;
152 gezelter 2
153 tim 963 /** DoubleGenericData is a generic data type contains a RealType variable */
154     typedef SimpleTypeData<RealType> DoubleGenericData;
155 tim 132
156 gezelter 507 /**
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 gezelter 1390 * s->setData("OpenMD");
166 gezelter 507 * 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 gezelter 2
179 gezelter 507 /**
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 gezelter 2
191 gezelter 507 VectorTypeData(const std::string& id)
192     : GenericData(id){}
193 tim 132
194 gezelter 877 VectorTypeData(const SelfType& s) : data_(s){}
195 gezelter 2
196 gezelter 507 SelfType& operator =(const SelfType& s){
197     if (this == &s)
198     return *this;
199 gezelter 2
200 gezelter 507 this->data_ = s.data_;
201     return *this;
202     }
203 tim 385
204 gezelter 507 private:
205     std::vector<ElemDataType> data_;
206     };
207 gezelter 2
208 gezelter 507 /**
209     * @typedef IntVectorGenericData
210     * A generic data type contains a std::vector<int> variable.
211     */
212     typedef VectorTypeData<int> IntVectorGenericData;
213 gezelter 2
214 gezelter 507 /**
215     * @typedef IntVectorGenericData
216     * A generic data type contains a std::vector<float> variable.
217     */
218     typedef VectorTypeData<float> FloatVectorGenericData;
219 gezelter 2
220 gezelter 507 /**
221     * @typedef IntVectorGenericData
222 tim 963 * A generic data type contains a std::vector<RealType> variable.
223 gezelter 507 */
224 tim 963 typedef VectorTypeData<RealType> DoubleVectorGenericData;
225 gezelter 2
226 gezelter 507 /**
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 gezelter 1390 * sv->push_back("OpenMD");
238 gezelter 507 *
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 tim 132
256 gezelter 2
257 gezelter 1390 } // namespace OpenMD
258 tim 132 #endif //UTIL _GENERICDATA_HPP

Properties

Name Value
svn:keywords Author Id Revision Date