1 | #ifndef FIELD_HPP |
---|
2 | #define FIELD_HPP |
---|
3 | |
---|
4 | #include "xmlio_std.hpp" |
---|
5 | #include "xml_parser.hpp" |
---|
6 | |
---|
7 | #include "base_object.hpp" |
---|
8 | #include "object_template.hpp" |
---|
9 | #include "group_template.hpp" |
---|
10 | |
---|
11 | #include "field_attribut.hpp" |
---|
12 | |
---|
13 | // Utilisation de la biliothÚque XmlIOServer |
---|
14 | using XmlIOServer::XML::XMLElement; |
---|
15 | using XmlIOServer::XML::TNodeType; |
---|
16 | using XmlIOServer::XML::THashAttributes; |
---|
17 | using XmlIOServer::XML::TListElements; |
---|
18 | |
---|
19 | using XmlIOServer::XML::XMLParser; |
---|
20 | |
---|
21 | // Utilisation de la STL |
---|
22 | using std::string; |
---|
23 | using std::pair; |
---|
24 | |
---|
25 | |
---|
26 | class FieldGroup : public group<CBase_object>, public XMLElement,public CFieldGroupAttribut |
---|
27 | { |
---|
28 | public : |
---|
29 | |
---|
30 | FieldGroup(XMLElement* pgr, bool fd = false) : group<CBase_object>(), CFieldGroupAttribut() |
---|
31 | { this->pgroup = pgr; this->fdefinition = fd; } |
---|
32 | |
---|
33 | void setAttributes(const THashAttributes& attr) |
---|
34 | { |
---|
35 | for (THashAttributes::ConstIterator it = attr.begin(); it != attr.end(); it++) |
---|
36 | if ((*it).first.compare(string("id"))) // Non prise en compte de l'identifiant lors de l'affectation des attributs. |
---|
37 | this->setSAttribut((*it).first, (*it).second); |
---|
38 | |
---|
39 | return; |
---|
40 | } |
---|
41 | |
---|
42 | bool isFieldDefinition(void) { return (this->fdefinition); } |
---|
43 | |
---|
44 | void parseIncludedFile(const string& path, const TListElements& tpath) |
---|
45 | { |
---|
46 | std::cout << "^^^^^^^^^^^^^^^^^^^^^^^^^" << std::endl; |
---|
47 | string elname; |
---|
48 | if (fdefinition) elname.assign("field_definition"); |
---|
49 | else elname.assign("field_group"); |
---|
50 | |
---|
51 | {// PARSING DE FICHIER INCLU |
---|
52 | XMLParser parser(path, elname); |
---|
53 | parser.setTreePath(tpath); |
---|
54 | parser.parse(this); |
---|
55 | } |
---|
56 | std::cout << "^^^^^^^^^^^^^^^^^^^^^^^^^" << std::endl; |
---|
57 | } |
---|
58 | |
---|
59 | friend ostream& operator<< (ostream& out, const FieldGroup& c) |
---|
60 | { |
---|
61 | if (c.fdefinition) out << "[field_definition " ; |
---|
62 | else out << "[field_group" ; |
---|
63 | if(c.hasId) out << " id=\'" << c.id << "\'"; |
---|
64 | for (unordered_map<string,CBaseAttribut *>::const_iterator it = c.attrMap.begin(); it != c.attrMap.end(); it++) |
---|
65 | out << " " <<(*it).first << "=\'" << *((*it).second) << "\'"; |
---|
66 | out << "]"; |
---|
67 | return out; |
---|
68 | } |
---|
69 | |
---|
70 | FieldGroup* getFieldGroupChild(const string & Id) {return ((FieldGroup*)getGroup(Id)); } |
---|
71 | |
---|
72 | template <typename T> |
---|
73 | T getFieldChild(const string & Id) {return ((T)getChild(Id)); } |
---|
74 | |
---|
75 | /// IMPORTANT POUR PARSING /// |
---|
76 | virtual XMLElement* addChild(TNodeType type, TListElements& path, THashAttributes& attr); |
---|
77 | virtual XMLElement* getPReference(void){ return (this->pgroup);} |
---|
78 | |
---|
79 | ~FieldGroup() {/* Ne rien faire de plus */} |
---|
80 | |
---|
81 | protected : |
---|
82 | |
---|
83 | // Vide pour le moment. |
---|
84 | |
---|
85 | private : |
---|
86 | |
---|
87 | XMLElement* pgroup; |
---|
88 | bool fdefinition; |
---|
89 | |
---|
90 | }; // class FieldGroup |
---|
91 | |
---|
92 | class Field : public XMLElement, public CObjectTemplate<Field>, public CFieldAttribut |
---|
93 | { |
---|
94 | public: |
---|
95 | |
---|
96 | Field(void) : CObjectTemplate<Field>(), CFieldAttribut() {} ; |
---|
97 | Field(const string & Id) : CObjectTemplate<Field>(Id), CFieldAttribut() {} ; |
---|
98 | |
---|
99 | void setAttributes(const THashAttributes& attr, const TListElements& path) |
---|
100 | { |
---|
101 | // Mise en place des attributs hérités |
---|
102 | for(unsigned int i = 1; i < path.size()-1; i++) |
---|
103 | for (THashAttributes::ConstIterator it = path[i].list.begin(); it != path[i].list.end(); it++) |
---|
104 | if ((*it).first.compare(string("id")) |
---|
105 | and (*it).first.compare(string("name")) |
---|
106 | and (*it).first.compare(string("description")) |
---|
107 | and (*it).first.compare(string("src"))) |
---|
108 | this->setSAttribut((*it).first, (*it).second); |
---|
109 | |
---|
110 | // Mise en place des attributs locaux |
---|
111 | for (THashAttributes::ConstIterator it = attr.begin(); it != attr.end(); it++) |
---|
112 | if ((*it).first.compare(string("id")))// Non prise en compte de l'identifiant lors de l'affectation des attributs. |
---|
113 | this->setSAttribut((*it).first, (*it).second); |
---|
114 | |
---|
115 | return; |
---|
116 | } |
---|
117 | |
---|
118 | // IMPORTANT : constructeur pour parsing |
---|
119 | Field(FieldGroup* pgr) : CObjectTemplate<Field>(), CFieldAttribut(){ this->pgroup = pgr; } |
---|
120 | Field(FieldGroup* pgr, const string & Id) : CObjectTemplate<Field>(Id), CFieldAttribut() { this->pgroup = pgr; } |
---|
121 | |
---|
122 | // getName est-elle vraiment nécessaire? |
---|
123 | static const char * getName(void) { return ("field") ; } |
---|
124 | |
---|
125 | /// IMPORTANT POUR PARSING /// |
---|
126 | virtual XMLElement* addChild(TNodeType type, TListElements& path, THashAttributes& attr) { return (NULL); } // Aucun retour car élément en fin d'arbre. |
---|
127 | virtual XMLElement* getPReference(void){ return (this->pgroup);} |
---|
128 | |
---|
129 | friend ostream& operator<< (ostream& out, const Field& c) |
---|
130 | { |
---|
131 | out << "[field" ; |
---|
132 | if(c.hasId) out << " id=\'" << c.id << "\'"; |
---|
133 | for (unordered_map<string,CBaseAttribut *>::const_iterator it = c.attrMap.begin(); it != c.attrMap.end(); it++) |
---|
134 | out << " " <<(*it).first << "=\'" << *((*it).second) << "\'"; |
---|
135 | out << "]"; |
---|
136 | return out; |
---|
137 | } |
---|
138 | |
---|
139 | ~Field() |
---|
140 | {/* Ne rien faire de plus */} |
---|
141 | |
---|
142 | protected : |
---|
143 | |
---|
144 | // Vide pour le moment. |
---|
145 | |
---|
146 | private : |
---|
147 | |
---|
148 | FieldGroup* pgroup; |
---|
149 | |
---|
150 | }; // class Field |
---|
151 | |
---|
152 | XMLElement* FieldGroup::addChild(TNodeType type, TListElements& path, THashAttributes& attr) |
---|
153 | { |
---|
154 | FieldGroup* childgroup = NULL; |
---|
155 | Field* childfield = NULL; |
---|
156 | |
---|
157 | switch (type) |
---|
158 | { |
---|
159 | case (TNodeType::FIELD_GROUP): // FIELD_GROUP |
---|
160 | { |
---|
161 | // Autres actions à effectuer ici... // |
---|
162 | childgroup = new FieldGroup(this); |
---|
163 | this->groupList->push_back(childgroup) ; |
---|
164 | |
---|
165 | |
---|
166 | if (attr.end() != attr.find("id")) |
---|
167 | { |
---|
168 | pair<string,FieldGroup*> value(attr["id"], childgroup) ; |
---|
169 | this->groupListId->insert(value); |
---|
170 | childgroup->setId(attr["id"]); |
---|
171 | } |
---|
172 | childgroup->setAttributes(attr); |
---|
173 | |
---|
174 | for(int i = 0; i<path.size(); i++) std::cout << " "; |
---|
175 | std::cout << *childgroup << std::endl; |
---|
176 | |
---|
177 | // Gestion de l'inclusion de fichier. |
---|
178 | if (attr.end() != attr.find("src")) |
---|
179 | childgroup->parseIncludedFile(attr["src"], path); |
---|
180 | |
---|
181 | return (childgroup); |
---|
182 | } |
---|
183 | |
---|
184 | case (TNodeType::FIELD): // FIELD |
---|
185 | { |
---|
186 | // Autres actions à effectuer ici... // |
---|
187 | childfield = new Field(this); |
---|
188 | this->childList->push_back(childfield) ; |
---|
189 | |
---|
190 | if (attr.end() != attr.find("id")) |
---|
191 | { |
---|
192 | pair<string,Field*> value(attr["id"], childfield) ; |
---|
193 | this->childListId->insert(value); |
---|
194 | childfield->setId(attr["id"]); |
---|
195 | } |
---|
196 | childfield->setAttributes(attr, path); |
---|
197 | |
---|
198 | for(int i = 0; i<path.size(); i++) std::cout << " "; |
---|
199 | std::cout << *childfield << std::endl; |
---|
200 | |
---|
201 | return (childfield); |
---|
202 | } |
---|
203 | |
---|
204 | default : |
---|
205 | |
---|
206 | std::cerr << "Balise inconnue sur FieldGroup"<< std::endl; |
---|
207 | return (NULL); |
---|
208 | } |
---|
209 | };// Méthode FieldGroup::addChild |
---|
210 | |
---|
211 | #endif |
---|
212 | |
---|
213 | |
---|
214 | |
---|