[369] | 1 | #ifndef __XIOS_ATTRIBUTE_ENUM_IMPL_HPP__ |
---|
| 2 | #define __XIOS_ATTRIBUTE_ENUM_IMPL_HPP__ |
---|
| 3 | |
---|
| 4 | #include "enum.hpp" |
---|
| 5 | #include "buffer_in.hpp" |
---|
| 6 | #include "buffer_out.hpp" |
---|
| 7 | #include "generate_interface.hpp" |
---|
| 8 | #include "attribute_enum.hpp" |
---|
| 9 | |
---|
[580] | 10 | |
---|
[369] | 11 | namespace xios |
---|
| 12 | { |
---|
[580] | 13 | /// ////////////////////// Définitions ////////////////////// /// |
---|
| 14 | template <class T> |
---|
| 15 | CAttributeEnum<T>::CAttributeEnum(const StdString & id) |
---|
| 16 | : CAttribute(id) |
---|
| 17 | { /* Ne rien faire de plus */ } |
---|
[369] | 18 | |
---|
[580] | 19 | template <class T> |
---|
| 20 | CAttributeEnum<T>::CAttributeEnum(const StdString & id, const T_enum & value) |
---|
| 21 | : CAttribute(id) |
---|
| 22 | { |
---|
| 23 | this->setValue(value); |
---|
| 24 | } |
---|
[369] | 25 | |
---|
[580] | 26 | template <class T> |
---|
| 27 | CAttributeEnum<T>::CAttributeEnum(const StdString & id, |
---|
| 28 | xios_map<StdString, CAttribute*> & umap) |
---|
| 29 | : CAttribute(id) |
---|
| 30 | { |
---|
| 31 | umap.insert(umap.end(), std::make_pair(id, this)); |
---|
| 32 | } |
---|
[369] | 33 | |
---|
[580] | 34 | template <class T> |
---|
| 35 | CAttributeEnum<T>::CAttributeEnum |
---|
| 36 | (const StdString & id, const T_enum & value, |
---|
| 37 | xios_map<StdString, CAttribute*> & umap) |
---|
| 38 | : CAttribute(id) |
---|
| 39 | { |
---|
| 40 | this->setValue(value); |
---|
| 41 | umap.insert(umap.end(), std::make_pair(id, this)); |
---|
| 42 | } |
---|
[369] | 43 | |
---|
[580] | 44 | ///-------------------------------------------------------------- |
---|
| 45 | template <class T> |
---|
| 46 | void CAttributeEnum<T>::reset(void) |
---|
| 47 | { |
---|
| 48 | CEnum<T>::reset(); |
---|
| 49 | inheritedValue.reset(); |
---|
| 50 | } |
---|
[369] | 51 | |
---|
[580] | 52 | template <class T> |
---|
| 53 | typename T::t_enum CAttributeEnum<T>::getValue(void) const |
---|
| 54 | { |
---|
| 55 | return CEnum<T>::get(); |
---|
| 56 | } |
---|
[369] | 57 | |
---|
[580] | 58 | template <class T> |
---|
| 59 | string CAttributeEnum<T>::getStringValue(void) const |
---|
| 60 | { |
---|
| 61 | return CEnum<T>::toString(); |
---|
| 62 | } |
---|
[369] | 63 | |
---|
[580] | 64 | template <class T> |
---|
| 65 | void CAttributeEnum<T>::setValue(const typename T::t_enum & value) |
---|
| 66 | { |
---|
| 67 | CEnum<T>::set(value); |
---|
| 68 | } |
---|
[369] | 69 | |
---|
[580] | 70 | template <class T> |
---|
| 71 | void CAttributeEnum<T>::set(const CAttribute& attr) |
---|
| 72 | { |
---|
| 73 | this->set(dynamic_cast<const CAttributeEnum<T>& >(attr)); |
---|
| 74 | } |
---|
[369] | 75 | |
---|
[580] | 76 | template <class T> |
---|
| 77 | void CAttributeEnum<T>::set(const CAttributeEnum& attr) |
---|
| 78 | { |
---|
| 79 | CEnum<T>::set(attr); |
---|
| 80 | } |
---|
[369] | 81 | |
---|
[580] | 82 | template <class T> |
---|
| 83 | void CAttributeEnum<T>::setInheritedValue(const CAttribute& attr) |
---|
| 84 | { |
---|
| 85 | this->setInheritedValue(dynamic_cast<const CAttributeEnum<T>& >(attr)); |
---|
| 86 | } |
---|
[445] | 87 | |
---|
[580] | 88 | template <class T> |
---|
| 89 | void CAttributeEnum<T>::setInheritedValue(const CAttributeEnum& attr) |
---|
| 90 | { |
---|
| 91 | if (this->isEmpty() && attr.hasInheritedValue()) inheritedValue.set(attr.getInheritedValue()); |
---|
| 92 | } |
---|
[445] | 93 | |
---|
[580] | 94 | template <class T> |
---|
| 95 | typename T::t_enum CAttributeEnum<T>::getInheritedValue(void) const |
---|
| 96 | { |
---|
| 97 | if (this->isEmpty()) return inheritedValue.get(); |
---|
| 98 | else return getValue(); |
---|
| 99 | } |
---|
[369] | 100 | |
---|
[580] | 101 | template <class T> |
---|
| 102 | string CAttributeEnum<T>::getInheritedStringValue(void) const |
---|
| 103 | { |
---|
| 104 | if (this->isEmpty()) return inheritedValue.toString(); |
---|
| 105 | else return CEnum<T>::toString(); |
---|
| 106 | } |
---|
[369] | 107 | |
---|
[580] | 108 | template <class T> |
---|
| 109 | bool CAttributeEnum<T>::hasInheritedValue(void) const |
---|
| 110 | { |
---|
| 111 | return !this->isEmpty() || !inheritedValue.isEmpty(); |
---|
| 112 | } |
---|
[369] | 113 | |
---|
[580] | 114 | //--------------------------------------------------------------- |
---|
[369] | 115 | |
---|
[580] | 116 | template <class T> |
---|
| 117 | CAttributeEnum<T>& CAttributeEnum<T>::operator=(const T_enum & value) |
---|
| 118 | { |
---|
| 119 | this->setValue(value); |
---|
| 120 | return *this; |
---|
| 121 | } |
---|
[369] | 122 | |
---|
[580] | 123 | //--------------------------------------------------------------- |
---|
[369] | 124 | |
---|
[580] | 125 | template <class T> |
---|
| 126 | StdString CAttributeEnum<T>::_toString(void) const |
---|
| 127 | { |
---|
| 128 | StdOStringStream oss; |
---|
| 129 | if (!CEnum<T>::isEmpty() && this->hasId()) |
---|
| 130 | oss << this->getName() << "=\"" << CEnum<T>::toString() << "\""; |
---|
| 131 | return (oss.str()); |
---|
| 132 | } |
---|
[369] | 133 | |
---|
[580] | 134 | template <class T> |
---|
| 135 | void CAttributeEnum<T>::_fromString(const StdString & str) |
---|
| 136 | { |
---|
| 137 | CEnum<T>::fromString(str); |
---|
| 138 | } |
---|
[369] | 139 | |
---|
[580] | 140 | template <class T> |
---|
| 141 | bool CAttributeEnum<T>::_toBuffer (CBufferOut& buffer) const |
---|
| 142 | { |
---|
| 143 | return CEnum<T>::toBuffer(buffer); |
---|
| 144 | } |
---|
[369] | 145 | |
---|
[580] | 146 | template <class T> |
---|
| 147 | bool CAttributeEnum<T>::_fromBuffer(CBufferIn& buffer) |
---|
| 148 | { |
---|
| 149 | return CEnum<T>::fromBuffer(buffer); |
---|
| 150 | } |
---|
| 151 | |
---|
| 152 | template <typename T> |
---|
| 153 | void CAttributeEnum<T>::generateCInterface(ostream& oss,const string& className) |
---|
| 154 | { |
---|
| 155 | CInterface::AttributeCInterface<CEnumBase>(oss, className, this->getName()); |
---|
| 156 | } |
---|
| 157 | |
---|
| 158 | template <typename T> |
---|
| 159 | void CAttributeEnum<T>::generateFortran2003Interface(ostream& oss,const string& className) |
---|
| 160 | { |
---|
| 161 | CInterface::AttributeFortran2003Interface<string>(oss, className, this->getName()); |
---|
| 162 | } |
---|
| 163 | |
---|
| 164 | template <typename T> |
---|
| 165 | void CAttributeEnum<T>::generateFortranInterfaceDeclaration_(ostream& oss,const string& className) |
---|
| 166 | { |
---|
| 167 | CInterface::AttributeFortranInterfaceDeclaration<string>(oss, className, this->getName()+"_"); |
---|
| 168 | } |
---|
| 169 | |
---|
| 170 | template <typename T> |
---|
| 171 | void CAttributeEnum<T>::generateFortranInterfaceBody_(ostream& oss,const string& className) |
---|
| 172 | { |
---|
| 173 | CInterface::AttributeFortranInterfaceBody<string>(oss, className, this->getName()); |
---|
| 174 | } |
---|
| 175 | |
---|
| 176 | template <typename T> |
---|
| 177 | void CAttributeEnum<T>::generateFortranInterfaceDeclaration(ostream& oss,const string& className) |
---|
| 178 | { |
---|
| 179 | CInterface::AttributeFortranInterfaceDeclaration<string>(oss, className, this->getName()); |
---|
| 180 | } |
---|
| 181 | |
---|
| 182 | template <typename T> |
---|
| 183 | void CAttributeEnum<T>::generateFortranInterfaceGetDeclaration_(ostream& oss,const string& className) |
---|
| 184 | { |
---|
| 185 | CInterface::AttributeFortranInterfaceGetDeclaration<string>(oss, className, this->getName()+"_"); |
---|
| 186 | } |
---|
| 187 | |
---|
| 188 | template <typename T> |
---|
| 189 | void CAttributeEnum<T>::generateFortranInterfaceGetBody_(ostream& oss,const string& className) |
---|
| 190 | { |
---|
| 191 | CInterface::AttributeFortranInterfaceGetBody<string>(oss, className, this->getName()); |
---|
| 192 | } |
---|
| 193 | |
---|
| 194 | template <typename T> |
---|
| 195 | void CAttributeEnum<T>::generateFortranInterfaceGetDeclaration(ostream& oss,const string& className) |
---|
| 196 | { |
---|
| 197 | CInterface::AttributeFortranInterfaceGetDeclaration<string>(oss, className, this->getName()); |
---|
| 198 | } |
---|
[369] | 199 | } // namespace xios |
---|
| 200 | |
---|
| 201 | #endif // __XIOS_ATTRIBUTE_ENUM_IMPL_HPP__ |
---|