1 | #ifndef __FIELD_GROUP__ |
---|
2 | #define __FIELD_GROUP__ |
---|
3 | |
---|
4 | |
---|
5 | using XMLIOSERVER::XML::THashAttributes; |
---|
6 | |
---|
7 | namespace XMLIOSERVER |
---|
8 | { |
---|
9 | class FieldGroup : public GroupTemplate<Field, FieldAttribut> |
---|
10 | { |
---|
11 | public: |
---|
12 | |
---|
13 | FieldGroup(void) : GroupTemplate<Field, FieldAttribut>() |
---|
14 | {/* Ne rien faire de plus */} |
---|
15 | FieldGroup(const string& _id) : GroupTemplate<Field, FieldAttribut>(_id) |
---|
16 | {/* Ne rien faire de plus */} |
---|
17 | |
---|
18 | void setAttributes(const THashAttributes& _attr) |
---|
19 | { |
---|
20 | for (THashAttributes::ConstIterator it = _attr.begin(); it != _attr.end(); it++) |
---|
21 | if ((*it).first.compare(string("id"))!= 0 and (*it).first.compare(string("src"))!=0) |
---|
22 | // (Au dessus) Non prise en compte de l'identifiant et de l'inclusion de fichiers externes lors de l'affectation des attributs. |
---|
23 | this->setSAttribut((*it).first, (*it).second); |
---|
24 | |
---|
25 | return; |
---|
26 | } |
---|
27 | |
---|
28 | const char* getName(void) const {return ("Field_Group"); } |
---|
29 | |
---|
30 | friend ostream& operator<< (ostream& out, const FieldGroup& c) |
---|
31 | { |
---|
32 | out << IncIndent << "<" << c.getName(); |
---|
33 | if(c.hasId()) out << " id=\"" << c.getId() << "\""; |
---|
34 | for(unsigned int i = 0; i < c.attrList.getVectorSize(); i++) out << *c.attrList.getVector()[i]; |
---|
35 | out << ">" << std::endl; |
---|
36 | |
---|
37 | |
---|
38 | for(unsigned int i = 0; i < c.groupList.getVector().size() ; i++) |
---|
39 | out << *((FieldGroup*)c.groupList.getVector()[i]) << std::endl; |
---|
40 | |
---|
41 | for(unsigned int i = 0; i < c.childList.getVector().size() ; i++) |
---|
42 | out << *(c.childList.getVector()[i]) << std::endl; |
---|
43 | |
---|
44 | out << NIndent << "</" << c.getName()<< ">" << DecEndl; |
---|
45 | return (out); |
---|
46 | } |
---|
47 | |
---|
48 | void addAttributes(const StrHashMap<BaseAttribut>& _pattr) |
---|
49 | { |
---|
50 | StrHashMap<BaseAttribut>& _lattr = getAttributList(); |
---|
51 | |
---|
52 | //_pattr contient les attributs du parent, _lattr les attributs locaux. |
---|
53 | |
---|
54 | for(unsigned int i = 0; i < _lattr.getVectorSize(); i++) |
---|
55 | { |
---|
56 | if(_lattr.getVector()[i]->_hasValue() or !_pattr.getVector()[i]->_hasValue()) continue; |
---|
57 | _lattr.getVector()[i]->assignValue(_pattr.getVector()[i]); |
---|
58 | } |
---|
59 | } |
---|
60 | |
---|
61 | void resolveDescInheritance(StrHashMap<BaseAttribut>* _pattr = 0) |
---|
62 | { |
---|
63 | const vector<Field*>& childvect = childList.getVector(); |
---|
64 | const vector<GroupTemplate<Field, FieldAttribut>*>& groupvect = groupList.getVector(); |
---|
65 | |
---|
66 | // On complÚte les propres attributs du groupe. |
---|
67 | if (_pattr!= NULL) addAttributes(*_pattr); |
---|
68 | |
---|
69 | for(unsigned int i = 0; i < childvect.size() ; i++) |
---|
70 | // on complÚte les attributs des champs enfants |
---|
71 | childvect[i] -> addAttributes(this->attrList); |
---|
72 | |
---|
73 | for(unsigned int i = 0; i < groupvect.size() ; i++) |
---|
74 | // on complÚte les attributs des groupes de champs enfants |
---|
75 | ((FieldGroup*)groupvect[i]) -> resolveDescInheritance(&this->attrList); |
---|
76 | } |
---|
77 | |
---|
78 | void parse (XMLNode& _node) |
---|
79 | { |
---|
80 | string name = _node.getElementName(); |
---|
81 | THashAttributes attributes; |
---|
82 | |
---|
83 | /// PARSING GESTION DES ATTRIBUTS /// |
---|
84 | _node.getAttributes(attributes); |
---|
85 | this->setAttributes(attributes); |
---|
86 | |
---|
87 | if (attributes.end() != attributes.find("src")) |
---|
88 | { // Si une demande d'inclusion de fichier est trouvé. |
---|
89 | XMLNode _node_inc = getNodeIncludedFile(attributes["src"], name); |
---|
90 | parse (_node_inc); |
---|
91 | } |
---|
92 | |
---|
93 | attributes.clear(); |
---|
94 | |
---|
95 | /// PARSING POUR GESION DES ENFANTS |
---|
96 | if (!(_node.goToChildElement())) |
---|
97 | WARNING("Le groupe de champ ne contient pas d'enfant !"); |
---|
98 | else |
---|
99 | { |
---|
100 | ////////////////////////////////////// |
---|
101 | do { // Parcours des contexts pour traitement. |
---|
102 | |
---|
103 | string name = _node.getElementName(); |
---|
104 | attributes.clear(); |
---|
105 | _node.getAttributes(attributes); |
---|
106 | |
---|
107 | if (name.compare("field_group") == 0) |
---|
108 | { // Parsing pour les groupes de champs |
---|
109 | |
---|
110 | FieldGroup* fgroup = NULL; |
---|
111 | |
---|
112 | if (attributes.end() != attributes.find("id")) |
---|
113 | {// Si l'identifiant est défini. |
---|
114 | if (FieldGroup::HasObject(attributes["id"])) |
---|
115 | WARNING("Dans le context actuel, un groupe de champ du même nom existe déjà , le second fera référence au premier par défaut !"); // TODO TODO |
---|
116 | fgroup = (FieldGroup*)(&createGroup(attributes["id"])); |
---|
117 | fgroup->parse(_node); |
---|
118 | } |
---|
119 | else |
---|
120 | {// Si l'identifiant n'est pas défini. |
---|
121 | fgroup = (FieldGroup*)(&createGroup()); |
---|
122 | fgroup->parse(_node); |
---|
123 | } |
---|
124 | |
---|
125 | continue; |
---|
126 | |
---|
127 | } |
---|
128 | else if (name.compare("field") == 0) |
---|
129 | { // Parsing pour les champs |
---|
130 | |
---|
131 | Field* field = NULL; |
---|
132 | |
---|
133 | if (attributes.end() != attributes.find("id")) |
---|
134 | {// Si l'identifiant est défini. |
---|
135 | if (Field::HasObject(attributes["id"])) |
---|
136 | WARNING("Dans le context actuel, un champ du même nom existe déjà , le second fera référence au premier par défaut !"); // TODO TODO |
---|
137 | field = (Field*)(&createChild(attributes["id"])); |
---|
138 | field->parse(_node); |
---|
139 | } |
---|
140 | else |
---|
141 | {// Si l'identifiant n'est pas défini. |
---|
142 | field = (Field*)(&createChild()); |
---|
143 | field->parse(_node); |
---|
144 | } |
---|
145 | |
---|
146 | continue; |
---|
147 | } |
---|
148 | else |
---|
149 | WARNING("Un groupe de champs ne peut contenir qu'un champ ou un autre groupe de champs !"); |
---|
150 | |
---|
151 | } while (_node.goToNextElement()); |
---|
152 | ////////////////////////////////////// |
---|
153 | _node.goToParentElement(); // Retour au parent |
---|
154 | } |
---|
155 | |
---|
156 | return; |
---|
157 | } |
---|
158 | |
---|
159 | virtual ~FieldGroup(void) |
---|
160 | {/* Ne rien faire de plus */ } |
---|
161 | |
---|
162 | }; // class FieldGroup |
---|
163 | |
---|
164 | typedef FieldGroup FieldDefinition ; |
---|
165 | |
---|
166 | }; // namespace XMLIOSERVER |
---|
167 | |
---|
168 | #endif // __FIELD_GROUP__ |
---|
169 | |
---|