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