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

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

Amélioration de quelques portions de code.
Ajout de contructeurs par copie.

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