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