#ifndef __XIOS_TYPE_REF_IMPL__ #define __XIOS_TYPE_REF_IMPL__ #include "xmlioserver_spl.hpp" #include "exception.hpp" #include "buffer_in.hpp" #include "buffer_out.hpp" #include "message.hpp" #include "type.hpp" namespace xios { using namespace std; template CType_ref::CType_ref(void) { empty=true ; } template CType_ref::CType_ref(T& val) { empty=true ; set_ref(val) ; } template CType_ref::CType_ref(CType& type) { empty=true ; set_ref(type) ; } template CType_ref::CType_ref(const CType_ref& type) { empty=true ; set_ref(type) ; } template void CType_ref::set_ref(T& val) { ptrValue=&val ; empty=false ; } template void CType_ref::set_ref(CType& type) { ptrValue=&type.get() ; empty=false ; } template void CType_ref::set_ref(const CType_ref& type) { ptrValue=type.ptrValue ; empty=type.empty ; } template void CType_ref::set(const T& val) const { checkEmpty() ; *ptrValue=val ; } template void CType_ref::set(const CType& type) const { checkEmpty() ; *ptrValue=type.get() ; } template void CType_ref::set(const CType_ref& type) const { checkEmpty() ; *ptrValue=type.get() ; } template T& CType_ref::get(void) const { checkEmpty() ; return *ptrValue ; } template const CType_ref& CType_ref::operator = (T& val) const { set(val) ; return *this ; } template const CType_ref& CType_ref::operator = (CType& type) const { set(type) ; return *this ; } template const CType_ref& CType_ref::operator = (const CType_ref& type) const { set(type) ; return *this ; } template CType_ref::operator T&() const { checkEmpty() ; return *ptrValue ; } template CType_ref* CType_ref::_clone(void) const { checkEmpty() ; return new CType_ref(*this) ; } template void CType_ref::_fromString(const string& str) const { istringstream iss(str); checkEmpty() ; iss>>*ptrValue ; } template void CType_ref::_fromString(const string& str) { istringstream iss(str); checkEmpty() ; iss>>*ptrValue ; } template string CType_ref::_toString(void) const { ostringstream oss; checkEmpty() ; oss<<*ptrValue ; return oss.str() ; } template bool CType_ref::_toBuffer(CBufferOut& buffer) const { checkEmpty() ; return buffer.put(*ptrValue) ; } template bool CType_ref::_fromBuffer(CBufferIn& buffer) { checkEmpty() ; return buffer.get(*ptrValue) ; } template bool CType_ref::_fromBuffer(CBufferIn& buffer) const { checkEmpty() ; return buffer.get(*ptrValue) ; } template size_t CType_ref::_size(void) const { return sizeof(T) ; } template bool CType_ref::_isEmpty(void) const { return empty ; } template void CType_ref::_reset(void) { empty=true ; } template void CType_ref::checkEmpty(void) const { if (empty) ERROR("template void CType_ref::checkEmpty(void)", <<"Type_ref reference is not assigned") ; } template CBufferOut& operator<<(CBufferOut& buffer, const CType_ref& type) { if (!type.toBuffer(buffer)) ERROR("CBuffer& operator<<(CBuffer& buffer, CType& type)", <<"Buffer remain size is to low for size type") ; return buffer ; } template CBufferOut& operator<<(CBufferOut& buffer, T& type) { if (!CType_ref(type).toBuffer(buffer)) ERROR("CBufferOut& operator<<(CBufferOut& buffer, T& type)", <<"Buffer remain size is to low for size type") ; return buffer ; } template CBufferIn& operator>>(CBufferIn& buffer, T& type) { if (! CType_ref(type).fromBuffer(buffer)) ERROR(" template CBufferIn& operator>>(CBufferIn& buffer, T& type)", <<"Buffer remain size is to low for size type") ; return buffer ; } template CBufferIn& operator>>(CBufferIn& buffer, const CType_ref& type) { if (! type.fromBuffer(buffer) ) ERROR("CBuffer& operator<<(CBuffer& buffer, CType& type)", <<"Buffer remain size is to low for size type") ; return buffer ; } template CMessage& operator<<(CMessage& msg, const CType_ref& type) { msg.push(*type.clone()) ; return msg ; } template CMessage& operator<<(CMessage& msg, T& type) { msg.push(*CType_ref(type).clone()) ; return msg ; } } #endif