1 | #ifndef __XIOS_CAttributeTemplate_impl__ |
---|
2 | #define __XIOS_CAttributeTemplate_impl__ |
---|
3 | |
---|
4 | #include "type.hpp" |
---|
5 | #include "buffer_in.hpp" |
---|
6 | #include "buffer_out.hpp" |
---|
7 | #include "generate_interface.hpp" |
---|
8 | #include "attribute_template.hpp" |
---|
9 | |
---|
10 | |
---|
11 | namespace xios |
---|
12 | { |
---|
13 | |
---|
14 | /// ////////////////////// Définitions ////////////////////// /// |
---|
15 | template <class T> |
---|
16 | CAttributeTemplate<T>::CAttributeTemplate(const StdString & id) |
---|
17 | : CAttribute(id) |
---|
18 | { /* Ne rien faire de plus */ } |
---|
19 | |
---|
20 | template <class T> |
---|
21 | CAttributeTemplate<T>::CAttributeTemplate(const StdString & id, const T & value) |
---|
22 | : CAttribute(id) |
---|
23 | { |
---|
24 | this->setValue(value); |
---|
25 | } |
---|
26 | /* |
---|
27 | template <class T> |
---|
28 | CAttributeTemplate<T>::CAttributeTemplate(const CAttribute & attribut) |
---|
29 | throw (CException) |
---|
30 | : CAttribute(attribut) |
---|
31 | { |
---|
32 | if (!attribut.isEmpty() && !attribut.isType<T>()) |
---|
33 | ERROR("CAttributeTemplate", << "Invalid instantiation !"); |
---|
34 | } |
---|
35 | */ |
---|
36 | template <class T> |
---|
37 | CAttributeTemplate<T>::CAttributeTemplate(const StdString & id, |
---|
38 | xios_map<StdString, CAttribute*> & umap) |
---|
39 | : CAttribute(id) |
---|
40 | { |
---|
41 | umap.insert(umap.end(), std::make_pair(id, this)); |
---|
42 | } |
---|
43 | |
---|
44 | template <class T> |
---|
45 | CAttributeTemplate<T>::CAttributeTemplate |
---|
46 | (const StdString & id, const T & value, |
---|
47 | xios_map<StdString, CAttribute*> & umap) |
---|
48 | : CAttribute(id) |
---|
49 | { |
---|
50 | this->setValue(value); |
---|
51 | umap.insert(umap.end(), std::make_pair(id, this)); |
---|
52 | } |
---|
53 | /* |
---|
54 | template <class T> |
---|
55 | CAttributeTemplate<T>::~CAttributeTemplate(void) |
---|
56 | { |
---|
57 | // this->CType<T>::reset() ; |
---|
58 | // this->clear(); |
---|
59 | } |
---|
60 | */ |
---|
61 | ///-------------------------------------------------------------- |
---|
62 | template <class T> |
---|
63 | void CAttributeTemplate<T>::reset(void) |
---|
64 | { |
---|
65 | CType<T>::reset() ; |
---|
66 | inheritedValue.reset() ; |
---|
67 | } |
---|
68 | |
---|
69 | template <class T> |
---|
70 | void CAttributeTemplate<T>::checkEmpty(void) const |
---|
71 | { |
---|
72 | if (CType<T>::empty) |
---|
73 | { |
---|
74 | StdString msg("On checking attribute with id="); |
---|
75 | msg.append(this->getId()); |
---|
76 | msg.append(" : "); |
---|
77 | msg.append("data is not initialized\n"); |
---|
78 | ERROR("template <typename T> void CType<T>::checkEmpty(void) const", << msg); |
---|
79 | } |
---|
80 | } |
---|
81 | |
---|
82 | template <class T> |
---|
83 | T CAttributeTemplate<T>::getValue(void) const |
---|
84 | { |
---|
85 | return CType<T>::get() ; |
---|
86 | } |
---|
87 | |
---|
88 | |
---|
89 | template <class T> |
---|
90 | void CAttributeTemplate<T>::setValue(const T & value) |
---|
91 | { |
---|
92 | CType<T>::set(value) ; |
---|
93 | // SuperClass::setValue<T>(value); |
---|
94 | } |
---|
95 | |
---|
96 | template <class T> |
---|
97 | void CAttributeTemplate<T>::set(const CAttribute& attr) |
---|
98 | { |
---|
99 | this->set(dynamic_cast<const CAttributeTemplate<T>& >(attr)) ; |
---|
100 | } |
---|
101 | |
---|
102 | template <class T> |
---|
103 | void CAttributeTemplate<T>::set(const CAttributeTemplate& attr) |
---|
104 | { |
---|
105 | CType<T>::set(attr) ; |
---|
106 | } |
---|
107 | |
---|
108 | template <class T> |
---|
109 | void CAttributeTemplate<T>::setInheritedValue(const CAttribute& attr) |
---|
110 | { |
---|
111 | this->setInheritedValue(dynamic_cast<const CAttributeTemplate<T>& >(attr)) ; |
---|
112 | } |
---|
113 | |
---|
114 | template <class T> |
---|
115 | void CAttributeTemplate<T>::setInheritedValue(const CAttributeTemplate& attr) |
---|
116 | { |
---|
117 | if (this->isEmpty() && _canInherite && attr.hasInheritedValue()) inheritedValue.set(attr.getInheritedValue()) ; |
---|
118 | } |
---|
119 | |
---|
120 | template <class T> |
---|
121 | T CAttributeTemplate<T>::getInheritedValue(void) const |
---|
122 | { |
---|
123 | if (this->isEmpty()) return inheritedValue.get() ; |
---|
124 | else return getValue() ; |
---|
125 | } |
---|
126 | |
---|
127 | template <class T> |
---|
128 | bool CAttributeTemplate<T>::hasInheritedValue(void) const |
---|
129 | { |
---|
130 | return !this->isEmpty() || !inheritedValue.isEmpty() ; |
---|
131 | } |
---|
132 | |
---|
133 | template <class T> |
---|
134 | bool CAttributeTemplate<T>::isEqual(const CAttribute& attr) |
---|
135 | { |
---|
136 | const CAttributeTemplate<T>& tmp = dynamic_cast<const CAttributeTemplate<T>& >(attr); |
---|
137 | return this->isEqual_(tmp); |
---|
138 | } |
---|
139 | |
---|
140 | template <class T> |
---|
141 | bool CAttributeTemplate<T>::isEqual_(const CAttributeTemplate& attr) |
---|
142 | { |
---|
143 | if ((!this->hasInheritedValue() && !attr.hasInheritedValue())) |
---|
144 | return true; |
---|
145 | if (this->hasInheritedValue() && attr.hasInheritedValue()) |
---|
146 | return (this->getInheritedValue() == attr.getInheritedValue()); |
---|
147 | else |
---|
148 | return false; |
---|
149 | } |
---|
150 | |
---|
151 | //--------------------------------------------------------------- |
---|
152 | |
---|
153 | template <class T> |
---|
154 | CAttributeTemplate<T>& CAttributeTemplate<T>::operator=(const T & value) |
---|
155 | { |
---|
156 | this->setValue(value); |
---|
157 | // return (this->getValue()); |
---|
158 | return *this; |
---|
159 | } |
---|
160 | |
---|
161 | //--------------------------------------------------------------- |
---|
162 | |
---|
163 | template <class T> |
---|
164 | StdString CAttributeTemplate<T>::_toString(void) const |
---|
165 | { |
---|
166 | StdOStringStream oss; |
---|
167 | if (!CType<T>::isEmpty() && this->hasId()) |
---|
168 | oss << this->getName() << "=\"" << CType<T>::toString() << "\""; |
---|
169 | return (oss.str()); |
---|
170 | } |
---|
171 | |
---|
172 | template <class T> |
---|
173 | void CAttributeTemplate<T>::_fromString(const StdString & str) |
---|
174 | { |
---|
175 | CType<T>::fromString(str) ; |
---|
176 | } |
---|
177 | |
---|
178 | //--------------------------------------------------------------- |
---|
179 | /* |
---|
180 | template <class T> |
---|
181 | void CAttributeTemplate<T>::toBinary (StdOStream & os) const |
---|
182 | { |
---|
183 | this->getValue()->toBinary(os); |
---|
184 | } |
---|
185 | |
---|
186 | template <class T> |
---|
187 | void CAttributeTemplate<T>::fromBinary(StdIStream & is) |
---|
188 | { |
---|
189 | T value; |
---|
190 | FromBinary(is, value); |
---|
191 | this->setValue(value); |
---|
192 | } |
---|
193 | */ |
---|
194 | template <class T> |
---|
195 | bool CAttributeTemplate<T>::_toBuffer (CBufferOut& buffer) const |
---|
196 | { |
---|
197 | return CType<T>::toBuffer(buffer) ; |
---|
198 | /* |
---|
199 | if (isEmpty()) return buffer.put(true) ; |
---|
200 | else |
---|
201 | { |
---|
202 | bool ret=true ; |
---|
203 | CType<T> val(*boost::any_cast<T>(&value)) ; |
---|
204 | ret&=buffer.put(false) ; |
---|
205 | ret&=val.toBuffer(buffer) ; |
---|
206 | return ret ; |
---|
207 | } |
---|
208 | */ |
---|
209 | } |
---|
210 | |
---|
211 | template <class T> |
---|
212 | bool CAttributeTemplate<T>::_fromBuffer(CBufferIn& buffer) |
---|
213 | { |
---|
214 | return CType<T>::fromBuffer(buffer) ; |
---|
215 | /* |
---|
216 | bool empty ; |
---|
217 | bool ret=true ; |
---|
218 | ret&=buffer.get(empty) ; |
---|
219 | if (empty) |
---|
220 | { |
---|
221 | clear() ; |
---|
222 | return ret ; |
---|
223 | } |
---|
224 | else |
---|
225 | { |
---|
226 | if (isEmpty()) |
---|
227 | { |
---|
228 | T val ; |
---|
229 | setValue(val) ; |
---|
230 | } |
---|
231 | T* V=const_cast<T*>(boost::any_cast<T>(&value)) ; |
---|
232 | CType<T> val(*V) ; |
---|
233 | return val.fromBuffer(buffer) ; |
---|
234 | } |
---|
235 | */ |
---|
236 | } |
---|
237 | /* |
---|
238 | template <class T> |
---|
239 | size_t CAttributeTemplate<T>::size(void) const |
---|
240 | { |
---|
241 | return CType<T>::size() ;*/ |
---|
242 | /* |
---|
243 | if (isEmpty()) return sizeof(bool) ; |
---|
244 | else |
---|
245 | { |
---|
246 | CType<T> val(*const_cast<T*>(boost::any_cast<T>(&value))) ; |
---|
247 | return val.size()+sizeof(bool) ; |
---|
248 | } |
---|
249 | */ |
---|
250 | /* }*/ |
---|
251 | |
---|
252 | template <typename T> |
---|
253 | void CAttributeTemplate<T>::generateCInterface(ostream& oss,const string& className) |
---|
254 | { |
---|
255 | CInterface::AttributeCInterface<T>(oss, className, this->getName()); |
---|
256 | } |
---|
257 | |
---|
258 | template <typename T> |
---|
259 | void CAttributeTemplate<T>::generateFortran2003Interface(ostream& oss,const string& className) |
---|
260 | { |
---|
261 | CInterface::AttributeFortran2003Interface<T>(oss, className, this->getName()); |
---|
262 | } |
---|
263 | |
---|
264 | template <typename T> |
---|
265 | void CAttributeTemplate<T>::generateFortranInterfaceDeclaration_(ostream& oss,const string& className) |
---|
266 | { |
---|
267 | CInterface::AttributeFortranInterfaceDeclaration<T>(oss, className, this->getName() + "_"); |
---|
268 | } |
---|
269 | |
---|
270 | template <typename T> |
---|
271 | void CAttributeTemplate<T>::generateFortranInterfaceBody_(ostream& oss,const string& className) |
---|
272 | { |
---|
273 | CInterface::AttributeFortranInterfaceBody<T>(oss, className, this->getName()); |
---|
274 | } |
---|
275 | |
---|
276 | template <typename T> |
---|
277 | void CAttributeTemplate<T>::generateFortranInterfaceDeclaration(ostream& oss,const string& className) |
---|
278 | { |
---|
279 | CInterface::AttributeFortranInterfaceDeclaration<T>(oss, className, this->getName()); |
---|
280 | } |
---|
281 | |
---|
282 | template <typename T> |
---|
283 | void CAttributeTemplate<T>::generateFortranInterfaceGetDeclaration_(ostream& oss,const string& className) |
---|
284 | { |
---|
285 | CInterface::AttributeFortranInterfaceGetDeclaration<T>(oss, className, this->getName() + "_"); |
---|
286 | } |
---|
287 | |
---|
288 | |
---|
289 | template <typename T> |
---|
290 | void CAttributeTemplate<T>::generateFortranInterfaceGetBody_(ostream& oss,const string& className) |
---|
291 | { |
---|
292 | CInterface::AttributeFortranInterfaceGetBody<T>(oss, className, this->getName()); |
---|
293 | } |
---|
294 | |
---|
295 | template <typename T> |
---|
296 | void CAttributeTemplate<T>::generateFortranInterfaceGetDeclaration(ostream& oss,const string& className) |
---|
297 | { |
---|
298 | CInterface::AttributeFortranInterfaceGetDeclaration<T>(oss, className, this->getName()); |
---|
299 | } |
---|
300 | |
---|
301 | |
---|
302 | /* |
---|
303 | //--------------------------------------------------------------- |
---|
304 | |
---|
305 | // Spécialisations des templates pour la fonction [toString] |
---|
306 | |
---|
307 | template <> |
---|
308 | StdString CAttributeTemplate<bool>::toString(void) const; |
---|
309 | |
---|
310 | //--------------------------------------------------------------- |
---|
311 | |
---|
312 | // Spécialisations des templates pour la fonction [fromString] |
---|
313 | |
---|
314 | template <> // Chaîne de caractÚres. |
---|
315 | void CAttributeTemplate<StdString>::fromString(const StdString & str); |
---|
316 | |
---|
317 | template <> // Entier |
---|
318 | void CAttributeTemplate<int>::fromString(const StdString & str); |
---|
319 | |
---|
320 | template <> // Booléen |
---|
321 | void CAttributeTemplate<bool>::fromString(const StdString & str); |
---|
322 | |
---|
323 | template <> // Double |
---|
324 | void CAttributeTemplate<double>::fromString(const StdString & str); |
---|
325 | |
---|
326 | template<> // Tableau |
---|
327 | void CAttributeTemplate<ARRAY(double, 1)>::fromString(const StdString & str); |
---|
328 | |
---|
329 | //--------------------------------------------------------------- |
---|
330 | |
---|
331 | // Spécialisations des templates pour la fonction [toBinary] // |
---|
332 | |
---|
333 | template <> // Chaîne de caractÚres. |
---|
334 | void CAttributeTemplate<StdString>::toBinary (StdOStream & os) const; |
---|
335 | |
---|
336 | template <> // Entier |
---|
337 | void CAttributeTemplate<int>::toBinary(StdOStream & os) const; |
---|
338 | |
---|
339 | template <> // Booléen |
---|
340 | void CAttributeTemplate<bool>::toBinary(StdOStream & os) const; |
---|
341 | |
---|
342 | template <> // Double |
---|
343 | void CAttributeTemplate<double>::toBinary(StdOStream & os) const; |
---|
344 | |
---|
345 | //--------------------------------------------------------------- |
---|
346 | |
---|
347 | // Spécialisations des templates pour la fonction [fromBinary] // |
---|
348 | |
---|
349 | template <> // Chaîne de caractÚres. |
---|
350 | void CAttributeTemplate<StdString>::fromBinary(StdIStream & is); |
---|
351 | |
---|
352 | template <> // Entier |
---|
353 | void CAttributeTemplate<int>::fromBinary(StdIStream & is); |
---|
354 | |
---|
355 | template <> // Booléen |
---|
356 | void CAttributeTemplate<bool>::fromBinary(StdIStream & is); |
---|
357 | |
---|
358 | template <> // Double |
---|
359 | void CAttributeTemplate<double>::fromBinary(StdIStream & is); |
---|
360 | |
---|
361 | ///-------------------------------------------------------------- |
---|
362 | */ |
---|
363 | } // namespace xios |
---|
364 | |
---|
365 | #endif // __XIOS_CAttributeTemplate_impl__ |
---|