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
RevLine 
[98]1#ifndef __ATTRIBUT_REGISTRAR__
2#define __ATTRIBUT_REGISTRAR__
[79]3
[98]4#include "attribut.hpp"
[79]5
[106]6using XMLIOSERVER::XML::THashAttributes;
7
[98]8namespace XMLIOSERVER
[79]9{
[98]10   class AttributRegistrar
11   {
[113]12      protected :
[107]13
[126]14         AttributRegistrar(void)
15            : attrList()
16         { /* Ne rien faire de plus */ }
[107]17
[126]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
[107]24         const StrHashMap<BaseAttribut>& getAttributList(void) const { return (attrList); }
[126]25
26         size_t getNbAttributes(void) const { return (attrList.getSize()); }
27
[113]28         bool hasAttribut(const string& _id) const { return (attrList.hasMappedValue(_id)); }
[107]29
[126]30         const StrHashMap<BaseAttribut>& getAttrList(void) const { return (attrList); }
31
[106]32         BaseAttribut* getAttribut(const string& _id) throw (XMLIOUndefinedValueException) { return (attrList[_id]); }
[107]33
34         friend ostream& operator<< (ostream& out, const AttributRegistrar& c)
35         {
[124]36            for(unsigned int i = 0; i < c.attrList.getVectorSize(); i++)
37               if (c.attrList.getVector()[i]->hasValue())
38                  out << *c.attrList.getVector()[i];
[106]39            return (out);
[107]40         }
41
[106]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.
[107]47                  this->setSAttribut((*it).first, (*it).second);
[106]48            return;
49         }
[107]50
[106]51         void addAttributes(const AttributRegistrar& _parent)
[107]52         {
[106]53            const StrHashMap<BaseAttribut>& _pattr = _parent.getAttributList();
[107]54            const StrHashMap<BaseAttribut>& _lattr = getAttributList();
[106]55            //_pattr contient les attributs du parent, _lattr les attributs locaux.
[107]56
[106]57            for(unsigned int i = 0; i < _lattr.getVectorSize(); i++)
58            {
[120]59               if(_lattr.getVector()[i]->hasValue() or !_pattr.getVector()[i]->hasValue()) continue;
[106]60               _lattr.getVector()[i]->assignValue(_pattr.getVector()[i]);
61            }
62         }
[107]63
[98]64         void setSAttribut(const string& att_name, const std::string& value)
65         {
[108]66            if (hasAttribut(att_name)) getAttribut(att_name)->setFromString(value);
[126]67            else throw XMLIOUndefinedValueException("Impossible de trouver l'attribut nommé \""
68               + att_name +"\" dans la liste des attributs enregistrés !");
[98]69         }
[107]70
[98]71        ~AttributRegistrar(void)
72        {/* Ne rien faire de plus */}
[107]73
[113]74      private :
75
[98]76         StrHashMap<BaseAttribut> attrList;
[107]77
78
79   }; // class AttributRegistrar
[114]80} // namespace XMLIOSERVER
[79]81
82
[98]83#endif //__ATTRIBUT_REGISTRAR__
Note: See TracBrowser for help on using the repository browser.