1 |
< |
/* |
1 |
> |
/* |
2 |
|
* Copyright (c) 2005 The University of Notre Dame. All Rights Reserved. |
3 |
|
* |
4 |
|
* The University of Notre Dame grants you ("Licensee") a |
54 |
|
#include <list> |
55 |
|
#include <string> |
56 |
|
#include <vector> |
57 |
+ |
#include "config.h" |
58 |
|
namespace oopse{ |
59 |
|
|
60 |
< |
/** |
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"){} |
60 |
> |
/** |
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 |
|
|
68 |
< |
GenericData(const std::string& id) { setID(id); } |
68 |
> |
GenericData(const std::string& id) { setID(id); } |
69 |
|
|
70 |
< |
/** virtual destructor */ |
71 |
< |
virtual ~GenericData() {} |
70 |
> |
/** virtual destructor */ |
71 |
> |
virtual ~GenericData() {} |
72 |
|
|
73 |
|
|
74 |
< |
/** |
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_; } |
74 |
> |
/** |
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 |
|
|
83 |
< |
/** |
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; } |
83 |
> |
/** |
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 |
|
|
92 |
|
|
93 |
< |
private: |
94 |
< |
GenericData(const GenericData&); |
95 |
< |
GenericData& operator=(GenericData&); |
96 |
< |
std::string id_; |
93 |
> |
private: |
94 |
> |
GenericData(const GenericData&); |
95 |
> |
GenericData& operator=(GenericData&); |
96 |
> |
std::string id_; |
97 |
|
|
98 |
< |
}; |
98 |
> |
}; |
99 |
|
|
100 |
< |
/** |
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{ |
100 |
> |
/** |
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 |
|
|
107 |
< |
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 |
< |
} |
107 |
> |
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 |
|
|
116 |
< |
SimpleTypeData<ElemDataType>& operator =(const SimpleTypeData<ElemDataType>& s) { |
117 |
< |
if (this == &s) |
118 |
< |
return *this; |
116 |
> |
SimpleTypeData<ElemDataType>& operator =(const SimpleTypeData<ElemDataType>& s) { |
117 |
> |
if (this == &s) |
118 |
> |
return *this; |
119 |
|
|
120 |
< |
data_ = s.getData(); |
121 |
< |
return *this; |
122 |
< |
} |
120 |
> |
data_ = s.getData(); |
121 |
> |
return *this; |
122 |
> |
} |
123 |
|
|
124 |
< |
template<typename T> |
125 |
< |
SimpleTypeData<ElemDataType>& operator =(const SimpleTypeData<T>& s) { |
126 |
< |
data_ = s.getData(); |
127 |
< |
return *this; |
128 |
< |
} |
124 |
> |
template<typename T> |
125 |
> |
SimpleTypeData<ElemDataType>& operator =(const SimpleTypeData<T>& s) { |
126 |
> |
data_ = s.getData(); |
127 |
> |
return *this; |
128 |
> |
} |
129 |
|
|
130 |
< |
/** 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; } |
130 |
> |
/** 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 |
|
|
139 |
< |
private: |
140 |
< |
ElemDataType data_; |
141 |
< |
}; |
139 |
> |
private: |
140 |
> |
ElemDataType data_; |
141 |
> |
}; |
142 |
|
|
143 |
< |
/** BoolGenericData is a generic data type contains a bool variable */ |
144 |
< |
typedef SimpleTypeData<bool> BoolGenericData; |
143 |
> |
/** BoolGenericData is a generic data type contains a bool variable */ |
144 |
> |
typedef SimpleTypeData<bool> BoolGenericData; |
145 |
|
|
146 |
< |
/** IntGenericData is a generic data type contains an integer variable */ |
147 |
< |
typedef SimpleTypeData<int> IntGenericData; |
146 |
> |
/** IntGenericData is a generic data type contains an integer variable */ |
147 |
> |
typedef SimpleTypeData<int> IntGenericData; |
148 |
|
|
149 |
< |
/** FloatGenericData is a generic data type contains a float variable */ |
150 |
< |
typedef SimpleTypeData<float> FloatGenericData; |
149 |
> |
/** FloatGenericData is a generic data type contains a float variable */ |
150 |
> |
typedef SimpleTypeData<float> FloatGenericData; |
151 |
|
|
152 |
< |
/** DoubleGenericData is a generic data type contains a double variable */ |
153 |
< |
typedef SimpleTypeData<double> DoubleGenericData; |
152 |
> |
/** DoubleGenericData is a generic data type contains a RealType variable */ |
153 |
> |
typedef SimpleTypeData<RealType> DoubleGenericData; |
154 |
|
|
155 |
< |
/** |
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 |
< |
* s->setData("OOPSE"); |
165 |
< |
* 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; |
155 |
> |
/** |
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 |
> |
* s->setData("OOPSE"); |
165 |
> |
* 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 |
|
|
178 |
< |
/** |
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, public std::vector<ElemDataType>{ |
187 |
< |
public: |
188 |
< |
typedef VectorTypeData<ElemDataType> SelfType; |
178 |
> |
/** |
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 |
|
|
190 |
< |
VectorTypeData(const std::string& id) |
191 |
< |
: GenericData(id), std::vector() {} |
190 |
> |
VectorTypeData(const std::string& id) |
191 |
> |
: GenericData(id){} |
192 |
|
|
193 |
< |
VectorTypeData(const SelfType& s) : SelfType(s){} |
193 |
> |
VectorTypeData(const SelfType& s) : data_(s){} |
194 |
|
|
195 |
< |
SelfType& operator =(const SelfType& s){ |
196 |
< |
if (this == &s) |
197 |
< |
return *this; |
195 |
> |
SelfType& operator =(const SelfType& s){ |
196 |
> |
if (this == &s) |
197 |
> |
return *this; |
198 |
|
|
199 |
< |
VectorTypeData::operator=(s); |
200 |
< |
return *this; |
201 |
< |
} |
202 |
< |
}; |
199 |
> |
this->data_ = s.data_; |
200 |
> |
return *this; |
201 |
> |
} |
202 |
> |
|
203 |
> |
private: |
204 |
> |
std::vector<ElemDataType> data_; |
205 |
> |
}; |
206 |
|
|
207 |
< |
/** |
208 |
< |
* @typedef IntVectorGenericData |
209 |
< |
* A generic data type contains a std::vector<int> variable. |
210 |
< |
*/ |
211 |
< |
typedef VectorTypeData<int> IntVectorGenericData; |
207 |
> |
/** |
208 |
> |
* @typedef IntVectorGenericData |
209 |
> |
* A generic data type contains a std::vector<int> variable. |
210 |
> |
*/ |
211 |
> |
typedef VectorTypeData<int> IntVectorGenericData; |
212 |
|
|
213 |
< |
/** |
214 |
< |
* @typedef IntVectorGenericData |
215 |
< |
* A generic data type contains a std::vector<float> variable. |
216 |
< |
*/ |
217 |
< |
typedef VectorTypeData<float> FloatVectorGenericData; |
213 |
> |
/** |
214 |
> |
* @typedef IntVectorGenericData |
215 |
> |
* A generic data type contains a std::vector<float> variable. |
216 |
> |
*/ |
217 |
> |
typedef VectorTypeData<float> FloatVectorGenericData; |
218 |
|
|
219 |
< |
/** |
220 |
< |
* @typedef IntVectorGenericData |
221 |
< |
* A generic data type contains a std::vector<double> variable. |
222 |
< |
*/ |
223 |
< |
typedef VectorTypeData<double> DoubleVectorGenericData; |
219 |
> |
/** |
220 |
> |
* @typedef IntVectorGenericData |
221 |
> |
* A generic data type contains a std::vector<RealType> variable. |
222 |
> |
*/ |
223 |
> |
typedef VectorTypeData<RealType> DoubleVectorGenericData; |
224 |
|
|
225 |
< |
/** |
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 |
< |
* sv->push_back("OOPSE"); |
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 |
< |
*/ |
253 |
< |
typedef VectorTypeData<std::string> StringVectorGenericData; |
225 |
> |
/** |
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 |
> |
* sv->push_back("OOPSE"); |
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 |
> |
*/ |
253 |
> |
typedef VectorTypeData<std::string> StringVectorGenericData; |
254 |
|
|
255 |
|
|
256 |
|
} // namespace oopse |