source: XMLIO_V2/dev/common/src/xmlio/attribute_template_impl.hpp @ 219

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

Préparation nouvelle arborescence

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            ERROR("T CAttributeTemplate<T>::getValue(void) const",
63                  << "[ id = " << this->getId() << "]"
64                  << " L'attribut est requis mais n'est pas défini !");
65         return (SuperClass::getValue<T>());
66      }
67
68      template <class T>
69         void CAttributeTemplate<T>::setValue(const T & value)
70      {
71         SuperClass::setValue<T>(value);
72      }
73
74      //---------------------------------------------------------------
75
76      template <class T>
77         T CAttributeTemplate<T>::operator=(const T & value)
78      {
79         this->setValue(value);
80         return (this->getValue());
81      }
82
83      //---------------------------------------------------------------
84
85      template <class T>
86         StdString CAttributeTemplate<T>::toString(void) const
87      {
88         StdOStringStream oss;
89         if (!this->isEmpty() && this->hasId())
90            oss << this->getName() << "=\"" << this->getValue() << "\"";
91         return (oss.str());
92      }
93
94      template <class T>
95         void CAttributeTemplate<T>::fromString(const StdString & str)
96      {
97         ERROR("CAttributeTemplate<T>::fromString(const StdString & str)",
98               << "[ str = " << str << " ] Not implemented yet !");
99      }
100
101      //---------------------------------------------------------------
102
103      template <class T>
104         void CAttributeTemplate<T>::toBinary (StdOStream & os) const
105      {
106         this->getValue()->toBinary(os);
107      }
108
109      template <class T>
110         void CAttributeTemplate<T>::fromBinary(StdIStream & is)
111      {
112         T value;
113         FromBinary(is, value);
114         this->setValue(value);
115      }
116
117      //---------------------------------------------------------------
118
119      /** Spécialisations des templates pour la fonction [toString] **/
120
121      template <>
122         StdString CAttributeTemplate<bool>::toString(void) const;
123
124      //---------------------------------------------------------------
125
126      /** Spécialisations des templates pour la fonction [fromString] **/
127
128      template <> // Chaîne de caractÚres.
129         void CAttributeTemplate<StdString>::fromString(const StdString & str);
130
131      template <> // Entier
132         void CAttributeTemplate<int>::fromString(const StdString & str);
133
134      template <> // Booléen
135         void CAttributeTemplate<bool>::fromString(const StdString & str);
136
137      template <> // Double
138         void CAttributeTemplate<double>::fromString(const StdString & str);
139
140      template<> // Tableau
141         void CAttributeTemplate<ARRAY(double, 1)>::fromString(const StdString & str);
142
143      //---------------------------------------------------------------
144
145      /** Spécialisations des templates pour la fonction [toBinary] **/
146
147      template <> // Chaîne de caractÚres.
148         void CAttributeTemplate<StdString>::toBinary (StdOStream & os) const;
149
150      template <> // Entier
151         void CAttributeTemplate<int>::toBinary(StdOStream & os) const;
152
153      template <> // Booléen
154         void CAttributeTemplate<bool>::toBinary(StdOStream & os) const;
155         
156      template <> // Double
157         void CAttributeTemplate<double>::toBinary(StdOStream & os) const;
158
159      //---------------------------------------------------------------
160
161      /** Spécialisations des templates pour la fonction [fromBinary] **/
162
163      template <> // Chaîne de caractÚres.
164         void CAttributeTemplate<StdString>::fromBinary(StdIStream & is);
165
166      template <> // Entier
167         void CAttributeTemplate<int>::fromBinary(StdIStream & is);
168
169      template <> // Booléen
170         void CAttributeTemplate<bool>::fromBinary(StdIStream & is);
171         
172      template <> // Double
173         void CAttributeTemplate<double>::fromBinary(StdIStream & is);
174
175      ///--------------------------------------------------------------
176   } // namespace tree
177} // namespace xmlioserver
178
179#endif // __XMLIO_CAttributeTemplate_impl__
Note: See TracBrowser for help on using the repository browser.