1 | #ifndef ATTRIBUT_REGISTRAR_HPP |
---|
2 | #define ATTRIBUT_REGISTRAR_HPP |
---|
3 | |
---|
4 | #include "base_attribut.hpp" |
---|
5 | #include "xmlio_std.hpp" |
---|
6 | |
---|
7 | using Poco::HashMap; |
---|
8 | |
---|
9 | class CAttributRegistrar |
---|
10 | { |
---|
11 | public : |
---|
12 | |
---|
13 | |
---|
14 | void RegisterAttribut(CBaseAttribut & attribut) ; |
---|
15 | ostream & PrintAttribut(ostream & o) ; |
---|
16 | |
---|
17 | unordered_map<string,CBaseAttribut *> attrMap ; |
---|
18 | vector<CBaseAttribut *> attrVector ; |
---|
19 | |
---|
20 | bool hasAttribut(const string& att_name) |
---|
21 | { |
---|
22 | if (attrMap.find(att_name)!=attrMap.end()) return true ; |
---|
23 | else return false ; |
---|
24 | } |
---|
25 | |
---|
26 | void setSAttribut(const string& att_name, const std::string& value) |
---|
27 | { |
---|
28 | unordered_map<string,CBaseAttribut *>::iterator it ; |
---|
29 | |
---|
30 | |
---|
31 | std::cout << "lol" << std::endl; |
---|
32 | it=attrMap.find(att_name) ; |
---|
33 | std::cout << "lol" << std::endl; |
---|
34 | if (it!=attrMap.end()) (*it).second->setFromString(value) ; |
---|
35 | else error("CAttributRegistrar::setAttribut<ValueType>") |
---|
36 | <<"Could not find <<"<<att_name<<">> attribut in registred list"<<endl ; |
---|
37 | |
---|
38 | } |
---|
39 | |
---|
40 | template <class ValueType> |
---|
41 | void setAttribut(const string& att_name, ValueType value) |
---|
42 | { |
---|
43 | unordered_map<string,CBaseAttribut *>::iterator it ; |
---|
44 | |
---|
45 | it=attrMap.find(att_name) ; |
---|
46 | |
---|
47 | if (it!=attrMap.end()) (*it).second->setValue(value) ; |
---|
48 | else error("CAttributRegistrar::setAttribut<ValueType>") |
---|
49 | <<"Could not find <<"<<att_name<<">> attribut in registred list"<<endl ; |
---|
50 | |
---|
51 | } |
---|
52 | |
---|
53 | } ; |
---|
54 | |
---|
55 | inline void CAttributRegistrar::RegisterAttribut(CBaseAttribut& Attribut) |
---|
56 | { |
---|
57 | attrMap.insert(make_pair(Attribut.getName(),&Attribut)) ; |
---|
58 | attrVector.push_back(&Attribut) ; |
---|
59 | } |
---|
60 | |
---|
61 | inline ostream & CAttributRegistrar::PrintAttribut(ostream& o) |
---|
62 | { |
---|
63 | vector<CBaseAttribut *>::iterator it ; |
---|
64 | o<<"List of attribut"<<IncIndent ; |
---|
65 | for(it=attrVector.begin(); it!=attrVector.end();it++) |
---|
66 | { |
---|
67 | o<<iendl ; |
---|
68 | (*it)->print(o) ; |
---|
69 | } |
---|
70 | o<<DecIndent ; |
---|
71 | return o ; |
---|
72 | } |
---|
73 | |
---|
74 | |
---|
75 | #endif |
---|