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

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

Le code respecte davantage la norme C++ 98 pour le portage sur les différentes plate-formes,

Une compilation plus restrictive passe sans problÚme sous gcc avec les options de compilation suivantes :
"-W -Wall -Wextra -Werror -ansi -pedantic "
et le retrait de certain avertissements :
-Wno-ignored-qualifiers < plusieurs avertissements dans Blitz.
-Wno-unused-parameter < des paramÚtres ne sont pas utilisés dans la classe BaseAttribut? (voir les get/set)
-Wno-long-long < besoin des long long pour le calendrier.

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