source: XMLIO_V2/dev/dev_rv/src/attribute_map.cpp @ 143

Last change on this file since 143 was 141, checked in by hozdoba, 13 years ago

Mise à jour depuis un autre dépôt

File size: 3.1 KB
Line 
1#include "attribute_map.hpp"
2
3namespace 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      {
41         typedef std::pair<StdString, CAttribute *> PairStrAtt;
42         StdOStringStream oss;
43         BOOST_FOREACH(PairStrAtt att, *this )
44            if (!att.second->isEmpty())
45               oss << *att.second << " ";
46         return (oss.str());
47      }
48
49      void CAttributeMap::fromString(const StdString & str)
50      { ERROR("CAttributeMap::fromString(const StdString & str)",
51             << "[ str = " << str << "] Not implemented yet !"); }
52
53      //StdOStream & operator << (StdOStream & os, const CAttributeMap & attributmap)
54      //{ os << attributmap.toString(); return (os); }
55
56      void CAttributeMap::setAttributes(const xml::THashAttributes & attributes)
57      {
58         for (xml::THashAttributes::const_iterator it  = attributes.begin();
59                                                   it != attributes.end();
60                                                   it ++)
61            if ((*it).first.compare(StdString("id")) != 0 &&
62                (*it).first.compare(StdString("src"))!= 0)
63            {
64               //if (CAttributeMap::operator[]((*it).first)->isEmpty())
65               CAttributeMap::operator[]((*it).first)->fromString((*it).second);
66            }
67      }
68
69      void CAttributeMap::setAttributes(const CAttributeMap * const _parent)
70      {
71         typedef std::pair<StdString, CAttribute*> StdStrAttPair;
72         BOOST_FOREACH(StdStrAttPair el, *_parent)
73         {
74            if (this->hasAttribute(el.first))
75            {
76               CAttribute * currAtt = CAttributeMap::operator[](el.first);
77               if (currAtt->isEmpty() && !el.second->isEmpty())
78               {
79                  this->setAttribute(el.first, el.second);
80               }
81            }
82         }
83      }
84
85   } // namespace tree
86} // namespace xmlioser
Note: See TracBrowser for help on using the repository browser.