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