1 #ifndef __XIOS_ENUM_REF_IMPL__
2 #define __XIOS_ENUM_REF_IMPL__
10 #include <boost/algorithm/string.hpp>
56 ptrValue=&type.
get() ;
78 *ptrValue=type.
get() ;
85 *ptrValue=type.
get() ;
102 template <
typename T>
109 template <
typename T>
116 template <
typename T>
123 template <
typename T>
130 template <
typename T>
133 istringstream iss(str);
138 template <
typename T>
142 string tmpStr=boost::to_lower_copy(boost::trim_copy(str)) ;
145 for(
int i=0;i<T::getSize();i++)
147 if (boost::to_lower_copy(
string(T::getStr()[i]))==tmpStr)
154 ostringstream strList ;
155 for(
int i=0;i<T::getSize();i++)
157 if (i>0) strList<<
", " ;
158 strList<<boost::to_lower_copy(
string(T::getStr()[i])) ;
161 ERROR(
"template <typename T> void CEnum_ref<T>::_fromString(const string& str)",
162 << tmpStr <<
" cannot be converted in a valid enumeration, possibilities are: " << strList.str());
165 template <
typename T>
168 if (empty)
return string(
"empty");
169 return string((T::getStr())[(
int)(*ptrValue)]) ;
173 template <
typename T>
177 if (
sizeof(*ptrValue)==
sizeof(
short int))
return buffer.
put((
short int) *ptrValue) ;
178 else if (
sizeof(*ptrValue)==
sizeof(
int))
return buffer.
put((
int) *ptrValue) ;
179 else if (
sizeof(*ptrValue)==
sizeof(
long int))
return buffer.
put((
long int) *ptrValue) ;
180 else ERROR(
"template <typename T> bool CEnum_ref<T>::_toBuffer(CBufferOut& buffer) const",
181 <<
"incompatibility between enumeration and standard integer type.");
185 template <
typename T>
190 if (
sizeof(*ptrValue)==
sizeof(
short int))
193 ret=buffer.
get(val) ;
194 if (ret) *ptrValue = (
T_enum) val ;
196 else if (
sizeof(*ptrValue)==
sizeof(int))
199 ret=buffer.
get(val) ;
200 if (ret) *ptrValue = (
T_enum) val ;
202 else if (
sizeof(*ptrValue)==
sizeof(
long int))
205 ret=buffer.
get(val) ;
206 if (ret) *ptrValue = (
T_enum) val ;
208 else ERROR(
"template <typename T> bool CEnum_ref<T>::_fromBuffer(CBufferIn& buffer)",
209 <<
"incompatibility between enumeration and standard integer type.");
213 template <
typename T>
218 if (
sizeof(*ptrValue)==
sizeof(
short int))
221 ret=buffer.
get(val) ;
222 if (ret) *ptrValue = (
T_enum) val ;
224 else if (
sizeof(*ptrValue)==
sizeof(int))
227 ret=buffer.
get(val) ;
228 if (ret) *ptrValue = (
T_enum) val ;
230 else if (
sizeof(*ptrValue)==
sizeof(
long int))
233 ret=buffer.
get(val) ;
234 if (ret) *ptrValue = (
T_enum) val ;
236 else ERROR(
"template <typename T> bool CEnum_ref<T>::_fromBuffer(CBufferIn& buffer)",
237 <<
"incompatibility between enumeration and standard integer type");
240 template <
typename T>
246 template <
typename T>
252 template <
typename T>
258 template <
typename T>
261 if (empty)
ERROR(
"template <typename T> void CEnum_ref<T>::checkEmpty(void)",
262 <<
"Enum reference is not initialized.") ;
265 template <
typename T>
268 if (lhs.
isEmpty())
return false;
269 return (lhs.
get() == rhs);
272 template <
typename T>
278 template <
typename T>
283 return (lhs.
get() == rhs.
get());
286 template <
typename T>
289 if (!
type.toBuffer(buffer))
ERROR(
"template <typename T> CBufferOut& operator<<(CBufferOut& buffer, const CEnum_ref<T>& type)",
290 <<
"Not enough free space in buffer to queue the enum.");
294 template <
typename T>
297 if (!
CEnum_ref<T>(type).toBuffer(buffer))
ERROR(
"template <typename T> CBufferOut& operator<<(CBufferOut& buffer, const typename T::t_enum& type)",
298 <<
"Not enough free space in buffer to queue the enum.");
302 template <
typename T>
305 if (!
CEnum_ref<T>(type).fromBuffer(buffer))
ERROR(
"template <typename T> CBufferIn& operator>>(CBufferIn& buffer, typename T::t_enum& type)",
306 <<
"Not enough data in buffer to unqueue the enum.");
310 template <
typename T>
313 if (!type.
fromBuffer(buffer))
ERROR(
"template <typename T> CBufferIn& operator>>(CBufferIn& buffer, const CEnum_ref<T>& type) ",
314 <<
"Not enough data in buffer to unqueue the enum.");
329 template <
typename T>
CEnum_ref * _clone(void) const
virtual bool fromBuffer(CBufferIn &buffer)
void set_ref(T_enum &val)
void checkEmpty(void) const
bool _fromBuffer(CBufferIn &buffer)
void _fromString(const string &str)
bool _toBuffer(CBufferOut &buffer) const
CBufferOut & operator<<(CBufferOut &buffer, const CArray< T_numtype, N_rank > &array)
virtual bool isEmpty() const
string _toString(void) const
CATCH CScalarAlgorithmReduceScalar::CScalarAlgorithmReduceScalar(CScalar *scalarDestination, CScalar *scalarSource, CReduceScalarToScalar *algo ERROR)("CScalarAlgorithmReduceScalar::CScalarAlgorithmReduceScalar(CScalar* scalarDestination, CScalar* scalarSource, CReduceScalarToScalar* algo)",<< "Operation must be defined."<< "Scalar source "<< scalarSource->getId()<< std::endl<< "Scalar destination "<< scalarDestination->getId())
CMessage & push(const CBaseType &type)
CBufferIn & operator>>(CBufferIn &buffer, CArray< T_numtype, N_rank > &array)
const CEnum_ref & operator=(T_enum &val) const
void set(const T_enum &val) const
bool operator==(const CDuration &ddr, const CDuration &dr)
Les opérateurs de comparaison. (Non testés pour le moment)