source: XMLIO_V2/dev/dev_rv/src/XMLIO/attribut_registrar.hpp @ 125

Last change on this file since 125 was 124, checked in by hozdoba, 14 years ago

Commit pour sauvegarde - diverses corrections de bogues et améliorations du code.

File size: 2.7 KB
Line 
1#ifndef __ATTRIBUT_REGISTRAR__
2#define __ATTRIBUT_REGISTRAR__
3
4#include "attribut.hpp"
5
6using XMLIOSERVER::XML::THashAttributes;
7
8namespace XMLIOSERVER
9{
10   class AttributRegistrar
11   {
12      protected :
13
14         AttributRegistrar():attrList()
15         {/* Ne rien faire de plus */}
16
17         void RegisterAttribut(BaseAttribut* attribut){ attrList.addObject(attribut); }
18         const StrHashMap<BaseAttribut>& getAttributList(void) const { return (attrList); }
19         size_t getNbAttributes() const {return (attrList.getSize()); }
20         bool hasAttribut(const string& _id) const { return (attrList.hasMappedValue(_id)); }
21
22         BaseAttribut* getAttribut(const string& _id) throw (XMLIOUndefinedValueException) { return (attrList[_id]); }
23
24         friend ostream& operator<< (ostream& out, const AttributRegistrar& c)
25         {
26            for(unsigned int i = 0; i < c.attrList.getVectorSize(); i++)
27               if (c.attrList.getVector()[i]->hasValue())
28                  out << *c.attrList.getVector()[i];
29            return (out);
30         }
31
32         void setAttributes(const THashAttributes& _attr)
33         {
34            for (THashAttributes::ConstIterator it = _attr.begin(); it != _attr.end(); it++)
35               if ((*it).first.compare(string("id"))!= 0 and (*it).first.compare(string("src"))!=0)
36               // (Au dessus) Non prise en compte de l'identifiant et de l'inclusion de fichiers externes lors de l'affectation des attributs.
37                  this->setSAttribut((*it).first, (*it).second);
38            return;
39         }
40
41         void addAttributes(const AttributRegistrar& _parent)
42         {
43            const StrHashMap<BaseAttribut>& _pattr = _parent.getAttributList();
44            const StrHashMap<BaseAttribut>& _lattr = getAttributList();
45            //_pattr contient les attributs du parent, _lattr les attributs locaux.
46
47            for(unsigned int i = 0; i < _lattr.getVectorSize(); i++)
48            {
49               if(_lattr.getVector()[i]->hasValue() or !_pattr.getVector()[i]->hasValue()) continue;
50               _lattr.getVector()[i]->assignValue(_pattr.getVector()[i]);
51            }
52         }
53
54         void setSAttribut(const string& att_name, const std::string& value)
55         {
56            if (hasAttribut(att_name)) getAttribut(att_name)->setFromString(value);
57            else throw XMLIOUndefinedValueException("Impossible de trouver l'attribut nommé \"" + att_name +"\" dans la liste des attributs enregistrés !");
58         }
59
60        ~AttributRegistrar(void)
61        {/* Ne rien faire de plus */}
62
63      private :
64
65         StrHashMap<BaseAttribut> attrList;
66
67
68   }; // class AttributRegistrar
69} // namespace XMLIOSERVER
70
71
72#endif //__ATTRIBUT_REGISTRAR__
Note: See TracBrowser for help on using the repository browser.