[141] | 1 | #include "attribute_map.hpp" |
---|
| 2 | |
---|
| 3 | namespace xmlioserver |
---|
| 4 | { |
---|
| 5 | namespace tree |
---|
| 6 | { |
---|
| 7 | /// ////////////////////// Définitions ////////////////////// /// |
---|
| 8 | CAttributeMap * CAttributeMap::Current = NULL; |
---|
| 9 | |
---|
| 10 | CAttributeMap::CAttributeMap(void) |
---|
| 11 | : boost::unordered_map<StdString, CAttribute*>() |
---|
| 12 | { CAttributeMap::Current = this; } |
---|
| 13 | |
---|
| 14 | CAttributeMap::~CAttributeMap(void) |
---|
| 15 | { /* Ne rien faire de plus */ } |
---|
| 16 | |
---|
| 17 | bool CAttributeMap::hasAttribute(const StdString & key) const |
---|
| 18 | { return (this->find(key) != this->end()); } |
---|
| 19 | |
---|
| 20 | void CAttributeMap::setAttribute(const StdString & key, CAttribute * const attr) |
---|
| 21 | { |
---|
| 22 | if (!this->hasAttribute(key)) |
---|
| 23 | ERROR("CAttributeMap::setAttribute(key, attr)", |
---|
| 24 | << "[ key = " << key << "] key not found !"); |
---|
| 25 | if (attr == NULL) |
---|
| 26 | ERROR("CAttributeMap::setAttribute(key, attr)", |
---|
| 27 | << "[ key = " << key << "] attr is null !"); |
---|
| 28 | this->find(key)->second->setAnyValue(attr->getAnyValue()); |
---|
| 29 | } |
---|
| 30 | |
---|
| 31 | CAttribute * CAttributeMap::operator[](const StdString & key) |
---|
| 32 | { |
---|
| 33 | if (!this->hasAttribute(key)) |
---|
| 34 | ERROR("CAttributeMap::operator[](const StdString & key)", |
---|
| 35 | << "[ key = " << key << "] key not found !"); |
---|
| 36 | return (SuperClassMap::operator[](key)); |
---|
| 37 | } |
---|
| 38 | |
---|
| 39 | StdString CAttributeMap::toString(void) const |
---|
| 40 | { |
---|
[150] | 41 | typedef std::pair<StdString, CAttribute*> StdStrAttPair; |
---|
[141] | 42 | StdOStringStream oss; |
---|
[150] | 43 | |
---|
| 44 | SuperClassMap::const_iterator it = SuperClassMap::begin(), end = SuperClassMap::end(); |
---|
| 45 | for (; it != end; it++) |
---|
| 46 | { |
---|
| 47 | const StdStrAttPair & att = *it; |
---|
[141] | 48 | if (!att.second->isEmpty()) |
---|
| 49 | oss << *att.second << " "; |
---|
[150] | 50 | } |
---|
[141] | 51 | return (oss.str()); |
---|
| 52 | } |
---|
| 53 | |
---|
| 54 | void CAttributeMap::fromString(const StdString & str) |
---|
| 55 | { ERROR("CAttributeMap::fromString(const StdString & str)", |
---|
| 56 | << "[ str = " << str << "] Not implemented yet !"); } |
---|
| 57 | |
---|
| 58 | //StdOStream & operator << (StdOStream & os, const CAttributeMap & attributmap) |
---|
| 59 | //{ os << attributmap.toString(); return (os); } |
---|
| 60 | |
---|
| 61 | void CAttributeMap::setAttributes(const xml::THashAttributes & attributes) |
---|
| 62 | { |
---|
| 63 | for (xml::THashAttributes::const_iterator it = attributes.begin(); |
---|
| 64 | it != attributes.end(); |
---|
| 65 | it ++) |
---|
| 66 | if ((*it).first.compare(StdString("id")) != 0 && |
---|
| 67 | (*it).first.compare(StdString("src"))!= 0) |
---|
| 68 | { |
---|
| 69 | //if (CAttributeMap::operator[]((*it).first)->isEmpty()) |
---|
| 70 | CAttributeMap::operator[]((*it).first)->fromString((*it).second); |
---|
| 71 | } |
---|
| 72 | } |
---|
| 73 | |
---|
| 74 | void CAttributeMap::setAttributes(const CAttributeMap * const _parent) |
---|
| 75 | { |
---|
| 76 | typedef std::pair<StdString, CAttribute*> StdStrAttPair; |
---|
[150] | 77 | |
---|
| 78 | SuperClassMap::const_iterator it = _parent->begin(), end = _parent->end(); |
---|
| 79 | for (; it != end; it++) |
---|
[141] | 80 | { |
---|
[150] | 81 | const StdStrAttPair & el = *it; |
---|
[141] | 82 | if (this->hasAttribute(el.first)) |
---|
| 83 | { |
---|
| 84 | CAttribute * currAtt = CAttributeMap::operator[](el.first); |
---|
| 85 | if (currAtt->isEmpty() && !el.second->isEmpty()) |
---|
| 86 | { |
---|
| 87 | this->setAttribute(el.first, el.second); |
---|
| 88 | } |
---|
| 89 | } |
---|
| 90 | } |
---|
| 91 | } |
---|
| 92 | |
---|
| 93 | } // namespace tree |
---|
| 94 | } // namespace xmlioser |
---|