[152] | 1 | #ifndef __XMLIO_CAttributeTemplate_impl__ |
---|
| 2 | #define __XMLIO_CAttributeTemplate_impl__ |
---|
| 3 | |
---|
[173] | 4 | #include "array.hpp" |
---|
| 5 | |
---|
[152] | 6 | namespace 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 | { /* Ne rien faire de plus */ } |
---|
| 53 | |
---|
| 54 | ///-------------------------------------------------------------- |
---|
| 55 | |
---|
| 56 | template <class T> |
---|
| 57 | T CAttributeTemplate<T>::getValue(void) const |
---|
| 58 | { |
---|
| 59 | return (SuperClass::getValue<T>()); |
---|
| 60 | } |
---|
| 61 | |
---|
| 62 | template <class T> |
---|
| 63 | void CAttributeTemplate<T>::setValue(const T & value) |
---|
| 64 | { |
---|
| 65 | SuperClass::setValue<T>(value); |
---|
| 66 | } |
---|
| 67 | |
---|
| 68 | //--------------------------------------------------------------- |
---|
| 69 | |
---|
| 70 | template <class T> |
---|
| 71 | T CAttributeTemplate<T>::operator=(const T & value) |
---|
| 72 | { |
---|
| 73 | this->setValue(value); |
---|
| 74 | return (this->getValue()); |
---|
| 75 | } |
---|
| 76 | |
---|
| 77 | //--------------------------------------------------------------- |
---|
| 78 | |
---|
| 79 | template <class T> |
---|
| 80 | StdString CAttributeTemplate<T>::toString(void) const |
---|
| 81 | { |
---|
| 82 | StdOStringStream oss; |
---|
| 83 | if (!this->isEmpty() && this->hasId()) |
---|
| 84 | oss << this->getName() << "=\"" << this->getValue() << "\""; |
---|
| 85 | return (oss.str()); |
---|
| 86 | } |
---|
| 87 | |
---|
| 88 | template <class T> |
---|
| 89 | void CAttributeTemplate<T>::fromString(const StdString & str) |
---|
| 90 | { |
---|
| 91 | ERROR("CAttributeTemplate<T>::fromString(const StdString & str)", |
---|
| 92 | << "[ str = " << str << " ] Not implemented yet !"); |
---|
| 93 | } |
---|
| 94 | |
---|
| 95 | //--------------------------------------------------------------- |
---|
| 96 | |
---|
| 97 | template <class T> |
---|
| 98 | void CAttributeTemplate<T>::toBinary (StdOStream & os) const |
---|
| 99 | { |
---|
| 100 | this->getValue()->toBinary(os); |
---|
| 101 | } |
---|
| 102 | |
---|
| 103 | template <class T> |
---|
| 104 | void CAttributeTemplate<T>::fromBinary(StdIStream & is) |
---|
| 105 | { |
---|
[173] | 106 | T value; |
---|
| 107 | FromBinary(is, value); |
---|
| 108 | this->setValue(value); |
---|
[152] | 109 | } |
---|
| 110 | |
---|
| 111 | //--------------------------------------------------------------- |
---|
| 112 | |
---|
| 113 | /** Spécialisations des templates pour la fonction [toString] **/ |
---|
| 114 | |
---|
| 115 | template <> |
---|
| 116 | StdString CAttributeTemplate<bool>::toString(void) const; |
---|
| 117 | |
---|
| 118 | //--------------------------------------------------------------- |
---|
| 119 | |
---|
| 120 | /** Spécialisations des templates pour la fonction [fromString] **/ |
---|
| 121 | |
---|
| 122 | template <> // Chaîne de caractÚres. |
---|
| 123 | void CAttributeTemplate<StdString>::fromString(const StdString & str); |
---|
| 124 | |
---|
| 125 | template <> // Entier |
---|
| 126 | void CAttributeTemplate<int>::fromString(const StdString & str); |
---|
| 127 | |
---|
| 128 | template <> // Booléen |
---|
| 129 | void CAttributeTemplate<bool>::fromString(const StdString & str); |
---|
| 130 | |
---|
| 131 | template<> // Tableau |
---|
| 132 | void CAttributeTemplate<ARRAY(double, 1)>::fromString(const StdString & str); |
---|
| 133 | |
---|
| 134 | //--------------------------------------------------------------- |
---|
| 135 | |
---|
| 136 | /** Spécialisations des templates pour la fonction [toBinary] **/ |
---|
| 137 | |
---|
| 138 | template <> // Chaîne de caractÚres. |
---|
| 139 | void CAttributeTemplate<StdString>::toBinary (StdOStream & os) const; |
---|
| 140 | |
---|
| 141 | template <> // Entier |
---|
| 142 | void CAttributeTemplate<int>::toBinary(StdOStream & os) const; |
---|
| 143 | |
---|
| 144 | template <> // Booléen |
---|
| 145 | void CAttributeTemplate<bool>::toBinary(StdOStream & os) const; |
---|
| 146 | |
---|
| 147 | //--------------------------------------------------------------- |
---|
| 148 | |
---|
| 149 | /** Spécialisations des templates pour la fonction [fromBinary] **/ |
---|
| 150 | |
---|
| 151 | template <> // Chaîne de caractÚres. |
---|
| 152 | void CAttributeTemplate<StdString>::fromBinary(StdIStream & is); |
---|
| 153 | |
---|
| 154 | template <> // Entier |
---|
| 155 | void CAttributeTemplate<int>::fromBinary(StdIStream & is); |
---|
| 156 | |
---|
| 157 | template <> // Booléen |
---|
| 158 | void CAttributeTemplate<bool>::fromBinary(StdIStream & is); |
---|
| 159 | |
---|
| 160 | ///-------------------------------------------------------------- |
---|
| 161 | } // namespace tree |
---|
| 162 | } // namespace xmlioserver |
---|
| 163 | |
---|
| 164 | #endif // __XMLIO_CAttributeTemplate_impl__ |
---|