source: XMLIO_V2/dev/common/src/attribute_template_impl.hpp @ 293

Last change on this file since 293 was 274, checked in by hozdoba, 13 years ago

nouvelle interface fortran et corrections

File size: 5.6 KB
Line 
1#ifndef __XMLIO_CAttributeTemplate_impl__
2#define __XMLIO_CAttributeTemplate_impl__
3
4#include "array.hpp"
5
6namespace xmlioserver
7{
8   namespace tree
9   {
10      /// ////////////////////// Définitions ////////////////////// ///
11      template <class T>
12         CAttributeTemplate<T>::CAttributeTemplate(const StdString & id)
13         : CAttribute(id)
14      { /* Ne rien faire de plus */ }
15
16      template <class T>
17         CAttributeTemplate<T>::CAttributeTemplate(const StdString & id, const T & value)
18         : CAttribute(id)
19      {
20         this->setValue(value);
21      }
22
23      template <class T>
24         CAttributeTemplate<T>::CAttributeTemplate(const CAttribute & attribut)
25         throw (CException)
26         : CAttribute(attribut)
27      {
28         if (!attribut.isEmpty() && !attribut.isType<T>())
29            ERROR("CAttributeTemplate", << "Invalid instantiation !");
30      }
31
32      template <class T>
33         CAttributeTemplate<T>::CAttributeTemplate(const StdString & id,
34                              xios_map<StdString, CAttribute*> & umap)
35         : CAttribute(id)
36      {
37         umap.insert(umap.end(), std::make_pair(id, this));
38      }
39
40      template <class T>
41         CAttributeTemplate<T>::CAttributeTemplate
42            (const StdString & id, const T & value,
43             xios_map<StdString, CAttribute*> & umap)
44         : CAttribute(id)
45      {
46         this->setValue(value);
47         umap.insert(umap.end(), std::make_pair(id, this));
48      }
49
50      template <class T>
51         CAttributeTemplate<T>::~CAttributeTemplate(void)
52      { 
53         this->clear();
54      }
55
56      ///--------------------------------------------------------------
57
58      template <class T>
59         T CAttributeTemplate<T>::getValue(void) const
60      {
61         if (SuperClass::isEmpty())
62         {
63            ERROR("T CAttributeTemplate<T>::getValue(void) const",
64                  << "[ id = " << this->getId() << "]"
65                  << " L'attribut est requis mais n'est pas défini !");
66          }
67         return (SuperClass::getValue<T>());
68      }
69
70      template <class T>
71         void CAttributeTemplate<T>::setValue(const T & value)
72      {
73         SuperClass::setValue<T>(value);
74      }
75
76      //---------------------------------------------------------------
77
78      template <class T>
79         T CAttributeTemplate<T>::operator=(const T & value)
80      {
81         this->setValue(value);
82         return (this->getValue());
83      }
84
85      //---------------------------------------------------------------
86
87      template <class T>
88         StdString CAttributeTemplate<T>::toString(void) const
89      {
90         StdOStringStream oss;
91         if (!this->isEmpty() && this->hasId())
92            oss << this->getName() << "=\"" << this->getValue() << "\"";
93         return (oss.str());
94      }
95
96      template <class T>
97         void CAttributeTemplate<T>::fromString(const StdString & str)
98      {
99         ERROR("CAttributeTemplate<T>::fromString(const StdString & str)",
100               << "[ str = " << str << " ] Not implemented yet !");
101      }
102
103      //---------------------------------------------------------------
104
105      template <class T>
106         void CAttributeTemplate<T>::toBinary (StdOStream & os) const
107      {
108         this->getValue()->toBinary(os);
109      }
110
111      template <class T>
112         void CAttributeTemplate<T>::fromBinary(StdIStream & is)
113      {
114         T value;
115         FromBinary(is, value);
116         this->setValue(value);
117      }
118
119      //---------------------------------------------------------------
120
121      /** Spécialisations des templates pour la fonction [toString] **/
122
123      template <>
124         StdString CAttributeTemplate<bool>::toString(void) const;
125
126      //---------------------------------------------------------------
127
128      /** Spécialisations des templates pour la fonction [fromString] **/
129
130      template <> // Chaîne de caractÚres.
131         void CAttributeTemplate<StdString>::fromString(const StdString & str);
132
133      template <> // Entier
134         void CAttributeTemplate<int>::fromString(const StdString & str);
135
136      template <> // Booléen
137         void CAttributeTemplate<bool>::fromString(const StdString & str);
138
139      template <> // Double
140         void CAttributeTemplate<double>::fromString(const StdString & str);
141
142      template<> // Tableau
143         void CAttributeTemplate<ARRAY(double, 1)>::fromString(const StdString & str);
144
145      //---------------------------------------------------------------
146
147      /** Spécialisations des templates pour la fonction [toBinary] **/
148
149      template <> // Chaîne de caractÚres.
150         void CAttributeTemplate<StdString>::toBinary (StdOStream & os) const;
151
152      template <> // Entier
153         void CAttributeTemplate<int>::toBinary(StdOStream & os) const;
154
155      template <> // Booléen
156         void CAttributeTemplate<bool>::toBinary(StdOStream & os) const;
157         
158      template <> // Double
159         void CAttributeTemplate<double>::toBinary(StdOStream & os) const;
160
161      //---------------------------------------------------------------
162
163      /** Spécialisations des templates pour la fonction [fromBinary] **/
164
165      template <> // Chaîne de caractÚres.
166         void CAttributeTemplate<StdString>::fromBinary(StdIStream & is);
167
168      template <> // Entier
169         void CAttributeTemplate<int>::fromBinary(StdIStream & is);
170
171      template <> // Booléen
172         void CAttributeTemplate<bool>::fromBinary(StdIStream & is);
173         
174      template <> // Double
175         void CAttributeTemplate<double>::fromBinary(StdIStream & is);
176
177      ///--------------------------------------------------------------
178   } // namespace tree
179} // namespace xmlioserver
180
181#endif // __XMLIO_CAttributeTemplate_impl__
Note: See TracBrowser for help on using the repository browser.