1 | #ifndef __CONTEXT__ |
---|
2 | #define __CONTEXT__ |
---|
3 | |
---|
4 | |
---|
5 | namespace XMLIOSERVER |
---|
6 | { |
---|
7 | class Context : public ObjectTemplate<Context> |
---|
8 | { |
---|
9 | public: |
---|
10 | |
---|
11 | Context(void) : ObjectTemplate<Context>(), fieldDef(NULL), fileDef(NULL)//, axisDef(NULL), gridDef(NULL) |
---|
12 | {/* Ne rien faire de plus */} |
---|
13 | Context(const string& _id) : ObjectTemplate<Context>(_id), fieldDef(NULL), fileDef(NULL)//, axisDef(NULL), gridDef(NULL) |
---|
14 | {/* Ne rien faire de plus */} |
---|
15 | |
---|
16 | static void ShowTree(ostream& os = std::clog) |
---|
17 | { |
---|
18 | clog << NIndent << "<?xml version=\"1.0\"?>" << std::endl; |
---|
19 | clog << NIndent << "<"<< Context::GetRootName() << ">" << std::endl; |
---|
20 | HashMap<string, StrHashMap<Context> > &AllListContext = Context::GetAllListObject(); |
---|
21 | for (HashMap<string, StrHashMap<Context> >::Iterator it = AllListContext.begin(); it != AllListContext.end(); it++) |
---|
22 | // On sort chacun des contextes successivement. |
---|
23 | { Context::SetCurrentContext((*it).first); clog << *((*it).second)[(*it).first] << std::endl; } |
---|
24 | clog << NIndent << "</" << Context::GetRootName() << ">" << std::endl ; |
---|
25 | } |
---|
26 | |
---|
27 | static void FreeMemory(void) |
---|
28 | { |
---|
29 | HashMap<string, StrHashMap<Context> > &AllListContext = Context::GetAllListObject(); |
---|
30 | for (HashMap<string, StrHashMap<Context> >::Iterator it = AllListContext.begin(); it != AllListContext.end(); it++) |
---|
31 | { Context::SetCurrentContext((*it).first); delete ((*it).second)[(*it).first]; } |
---|
32 | } |
---|
33 | |
---|
34 | static void ResolveInheritance(void) |
---|
35 | { |
---|
36 | HashMap<string, StrHashMap<Context> > &AllListContext = Context::GetAllListObject(); |
---|
37 | for (HashMap<string, StrHashMap<Context> >::Iterator it = AllListContext.begin(); it != AllListContext.end(); it++) |
---|
38 | { |
---|
39 | // Résolution des héritages descendants (cà d des héritages de groupes) pour chacun des contextes. |
---|
40 | Context::SetCurrentContext((*it).first); |
---|
41 | ((*it).second)[(*it).first]->resolveDescInheritance(); |
---|
42 | |
---|
43 | // Résolution des héritages par référence au niveau des fichiers |
---|
44 | const std::vector<CFile*>& allFiles = CFile::GetCurrentListObject().getVector(); |
---|
45 | for (unsigned int i = 0; i < allFiles.size(); i++) allFiles[i]->resolveFieldRefInheritance(); |
---|
46 | } |
---|
47 | } |
---|
48 | |
---|
49 | static void SetCurrentContext(const string& id) |
---|
50 | { |
---|
51 | // On modifie le context courrant pour tout les ObjectTemplate |
---|
52 | Context::SetContext(id); |
---|
53 | |
---|
54 | // Changement de context pour les champs et groupes de champs. |
---|
55 | FieldGroup::SetContext(id); |
---|
56 | CField::SetContext(id); |
---|
57 | |
---|
58 | // Changement de context pour les fichiers et groupes de fichiers. |
---|
59 | FileGroup::SetContext(id); |
---|
60 | CFile::SetContext(id); |
---|
61 | |
---|
62 | // Changement de context pour les grilles et groupes de grilles. |
---|
63 | //GridGroup::SetContext(id); |
---|
64 | //CGrid::SetContext(id); |
---|
65 | |
---|
66 | // Changement de context pour les axes et groupes d'axes. |
---|
67 | //AxisGroup::SetContext(id); |
---|
68 | //CAxis::SetContext(id); |
---|
69 | } |
---|
70 | |
---|
71 | void parse (XMLNode& _node) |
---|
72 | { |
---|
73 | THashAttributes attributes; |
---|
74 | |
---|
75 | /// PARSING POUR GESTION DES ENFANTS |
---|
76 | if (_node.getElementName().compare(Context::GetName())) |
---|
77 | WARNING("Le noeud est mal nommé mais sera traité comme un context !"); |
---|
78 | |
---|
79 | if (!(_node.goToChildElement())) |
---|
80 | WARNING("Le context ne contient pas d'enfant !"); |
---|
81 | else |
---|
82 | { |
---|
83 | do { // Parcours des contexts pour traitement. |
---|
84 | |
---|
85 | string name = _node.getElementName(); |
---|
86 | attributes.clear(); |
---|
87 | _node.getAttributes(attributes); |
---|
88 | |
---|
89 | if (attributes.end() != attributes.find("id")) |
---|
90 | { WARNING("Le noeud de définition possÚde un identifiant, ce dernier ne sera pas pris en compte lors du traitement !"); } |
---|
91 | |
---|
92 | if (name.compare(FieldDefinition::GetDefName()) == 0) // Parsing définition des champs. |
---|
93 | { fieldDef = CreateInstanceAndParse<FieldDefinition>(attributes, _node, "field_definition"); continue; } |
---|
94 | if (name.compare(FileDefinition::GetDefName()) == 0) // Parsing définition des fichiers. |
---|
95 | { fileDef = CreateInstanceAndParse<FileDefinition>(attributes, _node, "file_definition"); continue; } |
---|
96 | |
---|
97 | if (name.compare("axis_definition") == 0) |
---|
98 | { // Parsing pour la définition des axes. |
---|
99 | INFO("Le parsing des définitions d'axes n'est pas encore implémenté"); |
---|
100 | //axisDef = CreateInstance<AxisDefinition>(attributes, _node, "axis_definition"); |
---|
101 | continue; |
---|
102 | } |
---|
103 | |
---|
104 | if (name.compare("grid_definition") == 0) |
---|
105 | { // Parsing pour la définition des grilles. |
---|
106 | INFO("Le parsing des définitions de grilles n'est pas encore implémenté"); |
---|
107 | //gridDef = CreateInstance<GridDefinition>(attributes, _node, "grid_definition"); |
---|
108 | continue; |
---|
109 | } |
---|
110 | |
---|
111 | WARNING("La définition est invalide, seules les champs, grilles, axes et fichiers peuvent être définis !"); |
---|
112 | |
---|
113 | } while (_node.goToNextElement()); |
---|
114 | |
---|
115 | _node.goToParentElement(); // Retour au parent |
---|
116 | } |
---|
117 | |
---|
118 | return; |
---|
119 | } |
---|
120 | |
---|
121 | static string GetName(void) {return ("context"); } |
---|
122 | static string GetRootName(void) {return ("simulation"); } |
---|
123 | |
---|
124 | virtual bool hasChild(void) const |
---|
125 | { return ((fieldDef != NULL) or (fileDef != NULL) /* or (axisDef != NULL) or (gridDef != NULL) */); } |
---|
126 | virtual void printChild(ostream& out) const |
---|
127 | { |
---|
128 | if(fieldDef != NULL) out << *(FieldGroup*)fieldDef << std::endl; |
---|
129 | if(fileDef != NULL) out << *(FileGroup*) fileDef << std::endl; |
---|
130 | //if(axisDef != NULL) out << *(AxisDefinition*)axisDef << std::endl; |
---|
131 | //if(gridDef != NULL) out << *(GridDefinition*)gridDef << std::endl; |
---|
132 | } |
---|
133 | virtual void resolveDescInheritance(const AttributRegistrar* _parent = 0) |
---|
134 | { |
---|
135 | // Résolution des héritages descendants pour chacun des groupes de définitions. |
---|
136 | if(fieldDef != NULL) fieldDef->resolveDescInheritance(); |
---|
137 | if(fileDef != NULL) fileDef ->resolveDescInheritance(); |
---|
138 | //if(axisDef != NULL) axisDef ->resolveDescInheritance(); |
---|
139 | //if(gridDef != NULL) gridDef ->resolveDescInheritance(); |
---|
140 | } |
---|
141 | |
---|
142 | FieldDefinition* getFieldDefinition(void) { return (this->fieldDef); } |
---|
143 | FileDefinition* getFileDefinition(void) { return (this->fileDef); } |
---|
144 | //AxisDefinition* getAxisDefinition(void) { return (this->axisDef); } |
---|
145 | //GridDefinition* getGridDefinition(void) { return (this->gridDef); } |
---|
146 | |
---|
147 | ~Context() |
---|
148 | { |
---|
149 | if(fieldDef != NULL) delete fieldDef; |
---|
150 | if(fileDef != NULL) delete fileDef; |
---|
151 | //if(axisDef != NULL) delete axisDef; |
---|
152 | //if(gridDef != NULL) delete gridDef; |
---|
153 | } |
---|
154 | |
---|
155 | |
---|
156 | private: |
---|
157 | |
---|
158 | FieldDefinition* fieldDef; |
---|
159 | FileDefinition* fileDef; |
---|
160 | /*AxisDefinition* axisDef; |
---|
161 | GridDefinition* gridDef;*/ |
---|
162 | |
---|
163 | |
---|
164 | }; //class Context |
---|
165 | }// namespace XMLIOSERVER |
---|
166 | |
---|
167 | #endif // __CONTEXT__ |
---|