#include "attribute_map.hpp" #include "indent.hpp" namespace xios { /// ////////////////////// Définitions ////////////////////// /// CAttributeMap * CAttributeMap::Current = NULL; CAttributeMap::CAttributeMap(void) : xios_map() { CAttributeMap::Current = this; } CAttributeMap::~CAttributeMap(void) { /* Ne rien faire de plus */ } ///-------------------------------------------------------------- void CAttributeMap::clearAllAttributes(void) { typedef std::pair StdStrAttPair; SuperClassMap::const_iterator it = SuperClassMap::begin(), end = SuperClassMap::end(); for (; it != end; it++) { const StdStrAttPair & att = *it; att.second->reset(); } } //--------------------------------------------------------------- bool CAttributeMap::hasAttribute(const StdString & key) const { return (this->find(key) != this->end()); } //--------------------------------------------------------------- void CAttributeMap::setAttribute(const StdString & key, CAttribute * const attr) { if (!this->hasAttribute(key)) ERROR("CAttributeMap::setAttribute(key, attr)", << "[ key = " << key << "] key not found !"); if (attr == NULL) ERROR("CAttributeMap::setAttribute(key, attr)", << "[ key = " << key << "] attr is null !"); this->find(key)->second->set(*attr) ; // this->find(key)->second->setAnyValue(attr->getAnyValue()); } //--------------------------------------------------------------- CAttribute * CAttributeMap::operator[](const StdString & key) { if (!this->hasAttribute(key)) ERROR("CAttributeMap::operator[](const StdString & key)", << "[ key = " << key << "] key not found !"); return (SuperClassMap::operator[](key)); } //--------------------------------------------------------------- StdString CAttributeMap::toString(void) const { typedef std::pair StdStrAttPair; StdOStringStream oss; SuperClassMap::const_iterator it = SuperClassMap::begin(), end = SuperClassMap::end(); for (; it != end; it++) { const StdStrAttPair & att = *it; if (!att.second->isEmpty()) oss << *att.second << " "; } return (oss.str()); } //--------------------------------------------------------------- void CAttributeMap::fromString(const StdString & str) { ERROR("CAttributeMap::fromString(const StdString & str)", << "[ str = " << str << "] Not implemented yet !"); } //--------------------------------------------------------------- //StdOStream & operator << (StdOStream & os, const CAttributeMap & attributmap) //{ os << attributmap.toString(); return (os); } //--------------------------------------------------------------- void CAttributeMap::setAttributes(const xml::THashAttributes & attributes) { for (xml::THashAttributes::const_iterator it = attributes.begin(); it != attributes.end(); it ++) { if ((*it).first.compare(StdString("id")) != 0 && (*it).first.compare(StdString("src"))!= 0) { //if (CAttributeMap::operator[]((*it).first)->isEmpty()) CAttributeMap::operator[]((*it).first)->fromString((*it).second); } } } //--------------------------------------------------------------- void CAttributeMap::setAttributes(const CAttributeMap * const _parent, bool apply) { typedef std::pair StdStrAttPair; SuperClassMap::const_iterator it = _parent->begin(), end = _parent->end(); for (; it != end; it++) { const StdStrAttPair & el = *it; if (this->hasAttribute(el.first)) { CAttribute * currentAtt = CAttributeMap::operator[](el.first); CAttribute * parentAtt = el.second ; if (apply) { if (currentAtt->isEmpty() && !el.second->isEmpty()) { this->setAttribute(el.first, el.second); } } else currentAtt->setInheritedValue(*parentAtt) ; } } } //--------------------------------------------------------------- /* void CAttributeMap::toBinary(StdOStream & os) const { typedef std::pair StdStrAttPair; SuperClassMap::const_iterator it = this->begin(), end = this->end(); const StdSize nbatt = SuperClassMap::size(); os.write (reinterpret_cast(&nbatt) , sizeof(StdSize)); for (; it != end; it++) { const StdString & key = it->first; const CAttribute* value = it->second; const StdSize size = key.size(); os.write (reinterpret_cast(&size) , sizeof(StdSize)); os.write (key.data(), size * sizeof(char)); if (!value->isEmpty()) { bool b = true; os.write (reinterpret_cast(&b) , sizeof(bool)); value->toBinary(os); } else { bool b = false; os.write (reinterpret_cast(&b) , sizeof(bool)); } } } //--------------------------------------------------------------- void CAttributeMap::fromBinary(StdIStream & is) { StdSize nbatt = 0; is.read (reinterpret_cast(&nbatt), sizeof(StdSize)); for (StdSize i = 0; i < nbatt; i++) { bool hasValue = false; StdSize size = 0; is.read (reinterpret_cast(&size), sizeof(StdSize)); StdString key(size, ' '); is.read (const_cast(key.data()), size * sizeof(char)); if (!this->hasAttribute(key)) ERROR("CAttributeMap::fromBinary(StdIStream & is)", << "[ key = " << key << "] key not found !"); is.read (reinterpret_cast(&hasValue), sizeof(bool)); if (hasValue) this->operator[](key)->fromBinary(is); } } */ void CAttributeMap::generateCInterface(ostream& oss, const string& className) { SuperClassMap::const_iterator it = SuperClassMap::begin(), end = SuperClassMap::end(); for (; it != end; it++) { it->second->generateCInterface(oss,className) ; it->second->generateCInterfaceIsDefined(oss,className) ; oss<second->generateFortran2003Interface(oss,className) ; it->second->generateFortran2003InterfaceIsDefined(oss,className) ; oss<second->getName()<<"_" ; if (oss2->str().size()>90) { oss<str()<<" &"<str()<second->generateFortranInterfaceDeclaration_(oss,className) ; } oss<second->generateFortranInterfaceBody_(oss,className) ; oss<second->getName()<<"_" ; if (oss2->str().size()>90) { oss<str()<<" &"<str()<second->generateFortranInterfaceGetDeclaration_(oss,className) ; } oss<second->generateFortranInterfaceGetBody_(oss,className) ; oss<second->getName()<<"_" ; if (oss2->str().size()>90) { oss<str()<<" &"<str()<second->generateFortranInterfaceIsDefinedDeclaration_(oss,className) ; } oss<second->generateFortranInterfaceIsDefinedBody_(oss,className) ; oss<second->getName() ; if (oss2->str().size()>90) { oss<str()<<" &"<str()<second->generateFortranInterfaceDeclaration(oss,className) ; } oss<second->getName() ; if (oss2->str().size()>90) { oss<str()<<" &"<str() ; delete oss2 ; oss<second->getName() ; if (oss2->str().size()>90) { oss<str()<<" &"<str()<second->generateFortranInterfaceGetDeclaration(oss,className) ; } oss<second->getName() ; if (oss2->str().size()>90) { oss<str()<<" &"<str() ; delete oss2 ; oss<second->getName() ; if (oss2->str().size()>90) { oss<str()<<" &"<str()<second->generateFortranInterfaceIsDefinedDeclaration(oss,className) ; } oss<second->getName() ; if (oss2->str().size()>90) { oss<str()<<" &"<str() ; delete oss2 ; oss<second->getName() ; if (oss2->str().size()>90) { oss<str()<<" &"<str()<second->generateFortranInterfaceDeclaration(oss,className) ; } oss<second->getName() ; if (oss2->str().size()>90) { oss<str()<<" &"<str() ; delete oss2 ; oss<second->getName() ; if (oss2->str().size()>90) { oss<str()<<" &"<str()<second->generateFortranInterfaceGetDeclaration(oss,className) ; } oss<second->getName() ; if (oss2->str().size()>90) { oss<str()<<" &"<str() ; delete oss2 ; oss<second->getName() ; if (oss2->str().size()>90) { oss<str()<<" &"<str()<second->generateFortranInterfaceIsDefinedDeclaration(oss,className) ; } oss<second->getName() ; if (oss2->str().size()>90) { oss<str()<<" &"<str() ; delete oss2 ; oss<