source: XMLIO_V2/trunk/src/XMLIO/attribut_registrar.hpp @ 68

Last change on this file since 68 was 68, checked in by ymipsl, 14 years ago

ajout trunk xmlioserver
YM

File size: 1.3 KB
Line 
1#ifndef ATTRIBUT_REGISTRAR_HPP
2#define ATTRIBUT_REGISTRAR_HPP
3
4#include "base_attribut.hpp"
5#include "xmlio_std.hpp"
6
7class CAttributRegistrar
8{
9  public :
10 
11 
12  void RegisterAttribut(CBaseAttribut & attribut) ;
13  ostream & PrintAttribut(ostream & o) ;
14
15  unordered_map<string,CBaseAttribut *> attrMap ;
16  vector<CBaseAttribut *> attrVector ;
17
18  bool hasAttribut(const string& att_name)
19  {
20    if (attrMap.find(att_name)!=attrMap.end()) return true ;
21    else return false ;
22  }
23 
24  template <class ValueType>
25  void setAttribut(const string& att_name, ValueType value)
26  {
27    unordered_map<string,CBaseAttribut *>::iterator it ;
28   
29    it=attrMap.find(att_name) ;
30    if (it!=attrMap.end()) (*it).second->setValue(value) ;
31    else error("CAttributRegistrar::setAttribut<ValueType>")
32         <<"Could not find <<"<<att_name<<">> attribut in registred list"<<endl ;
33   
34  }
35 
36} ;
37
38inline void CAttributRegistrar::RegisterAttribut(CBaseAttribut& Attribut)
39{
40  attrMap.insert(make_pair(Attribut.getName(),&Attribut)) ;
41  attrVector.push_back(&Attribut) ;
42}
43
44inline ostream & CAttributRegistrar::PrintAttribut(ostream& o)
45{
46  vector<CBaseAttribut *>::iterator it ;
47  o<<"List of attribut"<<IncIndent ;
48  for(it=attrVector.begin(); it!=attrVector.end();it++)
49  {
50    o<<iendl ;
51    (*it)->print(o) ;
52  }
53  o<<DecIndent ;
54  return o ;
55}
56
57
58#endif
Note: See TracBrowser for help on using the repository browser.