#ifndef __XIOS_CAttributeTemplate_impl__ #define __XIOS_CAttributeTemplate_impl__ #include "type.hpp" #include "buffer_in.hpp" #include "buffer_out.hpp" #include "generate_interface.hpp" #include "attribute_template.hpp" namespace xios { /// ////////////////////// Définitions ////////////////////// /// template CAttributeTemplate::CAttributeTemplate(const StdString & id) : CAttribute(id) { /* Ne rien faire de plus */ } template CAttributeTemplate::CAttributeTemplate(const StdString & id, const T & value) : CAttribute(id) { this->setValue(value); } /* template CAttributeTemplate::CAttributeTemplate(const CAttribute & attribut) throw (CException) : CAttribute(attribut) { if (!attribut.isEmpty() && !attribut.isType()) ERROR("CAttributeTemplate", << "Invalid instantiation !"); } */ template CAttributeTemplate::CAttributeTemplate(const StdString & id, xios_map & umap) : CAttribute(id) { umap.insert(umap.end(), std::make_pair(id, this)); } template CAttributeTemplate::CAttributeTemplate (const StdString & id, const T & value, xios_map & umap) : CAttribute(id) { this->setValue(value); umap.insert(umap.end(), std::make_pair(id, this)); } /* template CAttributeTemplate::~CAttributeTemplate(void) { // this->CType::reset() ; // this->clear(); } */ ///-------------------------------------------------------------- template void CAttributeTemplate::reset(void) { CType::reset() ; inheritedValue.reset() ; } template T CAttributeTemplate::getValue(void) const { try { return CType::get() ; } catch (xios::CException & exc) { StdString msg("On checking attribute with id="); msg.append(this->getId()); msg.append(" : "); msg.append("data is not initialized\n"); ERROR("template void CType::checkEmpty(void) const", << msg); } /* if (SuperClass::isEmpty()) { ERROR("T CAttributeTemplate::getValue(void) const", << "[ id = " << this->getId() << "]" << " L'attribut est requis mais n'est pas défini !"); } return (SuperClass::getValue()); */ } /* template T* CAttributeTemplate::getRef(void) { if (SuperClass::isEmpty()) { ERROR("T CAttributeTemplate::getValue(void) const", << "[ id = " << this->getId() << "]" << " L'attribut est requis mais n'est pas défini !"); } return (SuperClass::getRef()); } */ template void CAttributeTemplate::setValue(const T & value) { CType::set(value) ; // SuperClass::setValue(value); } template void CAttributeTemplate::set(const CAttribute& attr) { this->set(dynamic_cast& >(attr)) ; } template void CAttributeTemplate::set(const CAttributeTemplate& attr) { CType::set(attr) ; } template void CAttributeTemplate::setInheritedValue(const CAttribute& attr) { this->setInheritedValue(dynamic_cast& >(attr)) ; } template void CAttributeTemplate::setInheritedValue(const CAttributeTemplate& attr) { if (this->isEmpty() && _canInherite && attr.hasInheritedValue()) inheritedValue.set(attr.getInheritedValue()) ; } template T CAttributeTemplate::getInheritedValue(void) const { if (this->isEmpty()) return inheritedValue.get() ; else return getValue() ; } template bool CAttributeTemplate::hasInheritedValue(void) const { return !this->isEmpty() || !inheritedValue.isEmpty() ; } template bool CAttributeTemplate::isEqual(const CAttribute& attr) { const CAttributeTemplate& tmp = dynamic_cast& >(attr); return this->isEqual_(tmp); } template bool CAttributeTemplate::isEqual_(const CAttributeTemplate& attr) { if ((!this->hasInheritedValue() && !attr.hasInheritedValue())) return true; if (this->hasInheritedValue() && attr.hasInheritedValue()) return (this->getInheritedValue() == attr.getInheritedValue()); else return false; } //--------------------------------------------------------------- template CAttributeTemplate& CAttributeTemplate::operator=(const T & value) { this->setValue(value); // return (this->getValue()); return *this; } //--------------------------------------------------------------- template StdString CAttributeTemplate::_toString(void) const { StdOStringStream oss; if (!CType::isEmpty() && this->hasId()) oss << this->getName() << "=\"" << CType::toString() << "\""; return (oss.str()); } template void CAttributeTemplate::_fromString(const StdString & str) { CType::fromString(str) ; } //--------------------------------------------------------------- /* template void CAttributeTemplate::toBinary (StdOStream & os) const { this->getValue()->toBinary(os); } template void CAttributeTemplate::fromBinary(StdIStream & is) { T value; FromBinary(is, value); this->setValue(value); } */ template bool CAttributeTemplate::_toBuffer (CBufferOut& buffer) const { return CType::toBuffer(buffer) ; /* if (isEmpty()) return buffer.put(true) ; else { bool ret=true ; CType val(*boost::any_cast(&value)) ; ret&=buffer.put(false) ; ret&=val.toBuffer(buffer) ; return ret ; } */ } template bool CAttributeTemplate::_fromBuffer(CBufferIn& buffer) { return CType::fromBuffer(buffer) ; /* bool empty ; bool ret=true ; ret&=buffer.get(empty) ; if (empty) { clear() ; return ret ; } else { if (isEmpty()) { T val ; setValue(val) ; } T* V=const_cast(boost::any_cast(&value)) ; CType val(*V) ; return val.fromBuffer(buffer) ; } */ } /* template size_t CAttributeTemplate::size(void) const { return CType::size() ;*/ /* if (isEmpty()) return sizeof(bool) ; else { CType val(*const_cast(boost::any_cast(&value))) ; return val.size()+sizeof(bool) ; } */ /* }*/ template void CAttributeTemplate::generateCInterface(ostream& oss,const string& className) { CInterface::AttributeCInterface(oss, className, this->getName()); } template void CAttributeTemplate::generateFortran2003Interface(ostream& oss,const string& className) { CInterface::AttributeFortran2003Interface(oss, className, this->getName()); } template void CAttributeTemplate::generateFortranInterfaceDeclaration_(ostream& oss,const string& className) { CInterface::AttributeFortranInterfaceDeclaration(oss, className, this->getName() + "_"); } template void CAttributeTemplate::generateFortranInterfaceBody_(ostream& oss,const string& className) { CInterface::AttributeFortranInterfaceBody(oss, className, this->getName()); } template void CAttributeTemplate::generateFortranInterfaceDeclaration(ostream& oss,const string& className) { CInterface::AttributeFortranInterfaceDeclaration(oss, className, this->getName()); } template void CAttributeTemplate::generateFortranInterfaceGetDeclaration_(ostream& oss,const string& className) { CInterface::AttributeFortranInterfaceGetDeclaration(oss, className, this->getName() + "_"); } template void CAttributeTemplate::generateFortranInterfaceGetBody_(ostream& oss,const string& className) { CInterface::AttributeFortranInterfaceGetBody(oss, className, this->getName()); } template void CAttributeTemplate::generateFortranInterfaceGetDeclaration(ostream& oss,const string& className) { CInterface::AttributeFortranInterfaceGetDeclaration(oss, className, this->getName()); } /* //--------------------------------------------------------------- // Spécialisations des templates pour la fonction [toString] template <> StdString CAttributeTemplate::toString(void) const; //--------------------------------------------------------------- // Spécialisations des templates pour la fonction [fromString] template <> // Chaîne de caractères. void CAttributeTemplate::fromString(const StdString & str); template <> // Entier void CAttributeTemplate::fromString(const StdString & str); template <> // Booléen void CAttributeTemplate::fromString(const StdString & str); template <> // Double void CAttributeTemplate::fromString(const StdString & str); template<> // Tableau void CAttributeTemplate::fromString(const StdString & str); //--------------------------------------------------------------- // Spécialisations des templates pour la fonction [toBinary] // template <> // Chaîne de caractères. void CAttributeTemplate::toBinary (StdOStream & os) const; template <> // Entier void CAttributeTemplate::toBinary(StdOStream & os) const; template <> // Booléen void CAttributeTemplate::toBinary(StdOStream & os) const; template <> // Double void CAttributeTemplate::toBinary(StdOStream & os) const; //--------------------------------------------------------------- // Spécialisations des templates pour la fonction [fromBinary] // template <> // Chaîne de caractères. void CAttributeTemplate::fromBinary(StdIStream & is); template <> // Entier void CAttributeTemplate::fromBinary(StdIStream & is); template <> // Booléen void CAttributeTemplate::fromBinary(StdIStream & is); template <> // Double void CAttributeTemplate::fromBinary(StdIStream & is); ///-------------------------------------------------------------- */ } // namespace xios #endif // __XIOS_CAttributeTemplate_impl__