#include "attribute_map.hpp" namespace xmlioserver { namespace tree { /// ////////////////////// Définitions ////////////////////// /// CAttributeMap * CAttributeMap::Current = NULL; CAttributeMap::CAttributeMap(void) : boost::unordered_map() { CAttributeMap::Current = this; } CAttributeMap::~CAttributeMap(void) { /* Ne rien faire de plus */ } 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->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) { 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 * currAtt = CAttributeMap::operator[](el.first); if (currAtt->isEmpty() && !el.second->isEmpty()) { this->setAttribute(el.first, el.second); } } } } } // namespace tree } // namespace xmlioser