1 | #ifndef __CONTEXT__ |
---|
2 | #define __CONTEXT__ |
---|
3 | |
---|
4 | #include "xmlio_std.hpp" |
---|
5 | #include "xml_parser.hpp" |
---|
6 | |
---|
7 | // Gestion des attributs |
---|
8 | #include "attribut_registrar.hpp" |
---|
9 | #include "attribut.hpp" |
---|
10 | #include "declare_attribut.hpp" |
---|
11 | #include "base_object.hpp" |
---|
12 | |
---|
13 | // Pour les champs |
---|
14 | #include "field.hpp" |
---|
15 | |
---|
16 | /// HISTORIQUE /// |
---|
17 | // <RV> 26/04/10- 27/04/10 : Nouvelle implémentation classes Simulation (racine) et Context séparées. |
---|
18 | // <RV> 30/04/10 : Vérification de la classe avec XmlIOServer::XML::XMLClassTest comme enfant >> OK. |
---|
19 | |
---|
20 | /** |
---|
21 | * \file context.hpp |
---|
22 | * \brief Ce fichier contient le code source permettant d'analyser différents contexts de sortie. |
---|
23 | * \author Ozdoba Hervé (contact: herve.ozdoba@glsce.ipsl.fr) |
---|
24 | * \author Meurdesoif Yann (contact Yann.Meurdesoif@cea.fr) |
---|
25 | * \version 0.1.0 |
---|
26 | * \date Avril - Mai 2010 |
---|
27 | */ |
---|
28 | |
---|
29 | // Utilisation de la biliothÚque XmlIOServer |
---|
30 | using XmlIOServer::XML::XMLElement; |
---|
31 | using XmlIOServer::XML::TNodeType; |
---|
32 | using XmlIOServer::XML::THashAttributes; |
---|
33 | using XmlIOServer::XML::TListElements; |
---|
34 | |
---|
35 | // Utilisation de la STL |
---|
36 | using std::string; |
---|
37 | |
---|
38 | // Utilisation de la biliothÚque POCO |
---|
39 | using Poco::HashMap; |
---|
40 | |
---|
41 | namespace XmlIOServer |
---|
42 | { |
---|
43 | class Simulation : public XMLElement |
---|
44 | { |
---|
45 | public: |
---|
46 | Simulation() |
---|
47 | { /*std::cout << "[simulation]" << std::endl;*/ } // sortie pour test uniquement. |
---|
48 | |
---|
49 | virtual XMLElement* addChild(TNodeType type, TListElements& path, THashAttributes& attr); |
---|
50 | |
---|
51 | virtual XMLElement* getPReference(void) {return (NULL);} |
---|
52 | |
---|
53 | friend ostream& operator<< (ostream& out, const Simulation& c) |
---|
54 | { out << "[simulation]"; return out; } |
---|
55 | |
---|
56 | protected: |
---|
57 | |
---|
58 | private: |
---|
59 | |
---|
60 | }; // class Simulation |
---|
61 | |
---|
62 | // Pas nécessaire de créer cette classe mais utile pour vérification. |
---|
63 | class ContextAttribut : public virtual CBase_object |
---|
64 | { |
---|
65 | public : |
---|
66 | |
---|
67 | /*DECLARE_ATTR(id, string) ; */ |
---|
68 | // Déclaration des autres attributs de la classe Context ici. |
---|
69 | |
---|
70 | ContextAttribut() |
---|
71 | { /*RegisterAttribut(id);*/ } |
---|
72 | |
---|
73 | }; // class ContextAttribut |
---|
74 | |
---|
75 | class Context : public XMLElement, public ContextAttribut |
---|
76 | { |
---|
77 | public: |
---|
78 | |
---|
79 | typedef HashMap<string, Context*> THashContext; |
---|
80 | |
---|
81 | Context() |
---|
82 | : field_definition(NULL, true), file_definition(this), grid_definition(this), axis_definition(this) |
---|
83 | {std::cerr << "Context() > Ne devrait pas être appelé" << std::endl;} |
---|
84 | |
---|
85 | Context(TNodeType type, THashAttributes& attr) |
---|
86 | : field_definition(this, true), file_definition(this), grid_definition(this), axis_definition(this) |
---|
87 | { |
---|
88 | // Ajout des attributs ... |
---|
89 | AllContext[attr["id"]] = this; |
---|
90 | |
---|
91 | // TODO Vérifier l'existence de l'identifiant. |
---|
92 | this->setId(attr["id"]) ; |
---|
93 | Context::SetCurrentContext(attr["id"]); |
---|
94 | } |
---|
95 | |
---|
96 | static Simulation* GetRootElement() {return (Context::Root);} |
---|
97 | static const THashContext& GetAllContext() {return (Context::AllContext);} |
---|
98 | |
---|
99 | static bool SetCurrentContext(const string& id) |
---|
100 | { |
---|
101 | if(Context::AllContext.end() == Context::AllContext.find(id))return (false); |
---|
102 | CurrentContextID = id; |
---|
103 | |
---|
104 | return (true); |
---|
105 | } |
---|
106 | static Context* GetCurrentContext(void) { return(Context::AllContext[CurrentContextID]);} |
---|
107 | static string& GetCurrentContextID(void){ return(Context::CurrentContextID); } |
---|
108 | |
---|
109 | /// POUR PARSING /// |
---|
110 | virtual XMLElement* addChild(TNodeType type, TListElements& path, THashAttributes& attr) |
---|
111 | { |
---|
112 | switch (type) |
---|
113 | { |
---|
114 | case (TNodeType::FIELD_GROUP): // FIELD_GROUP |
---|
115 | // Autres actions à effectuer ici... // |
---|
116 | if (attr.end() != attr.find("id")) this->field_definition.setId(attr["id"]); // l'id est-il utile ici? |
---|
117 | this->field_definition.setAttributes(attr); |
---|
118 | std::cout << " " << this->field_definition << std::endl; |
---|
119 | return (&field_definition); |
---|
120 | |
---|
121 | case (TNodeType::FILE_GROUP): // FILE_GROUP |
---|
122 | // Autres actions à effectuer ici... // |
---|
123 | return (&file_definition); |
---|
124 | |
---|
125 | case (TNodeType::AXIS_GROUP): // AXIS_GROUP |
---|
126 | // Autres actions à effectuer ici... // |
---|
127 | return (&axis_definition); |
---|
128 | |
---|
129 | case (TNodeType::GRID_GROUP): // GRID_GROUP |
---|
130 | // Autres actions à effectuer ici... // |
---|
131 | return (&grid_definition); |
---|
132 | default : |
---|
133 | std::cerr << "Balise inconnue sur context"<< std::endl; |
---|
134 | return (NULL); |
---|
135 | } |
---|
136 | } |
---|
137 | |
---|
138 | friend ostream& operator<< (ostream& out, const Context& c) |
---|
139 | { out << " [context id=\'" << c.id << "\']"; return out; } |
---|
140 | |
---|
141 | virtual XMLElement* getPReference(void) {return (Context::GetRootElement());} |
---|
142 | |
---|
143 | FieldGroup& getFieldDefinition(void) {return (this->field_definition);} |
---|
144 | |
---|
145 | const XmlIOServer::XML::XMLClassTest& getFileDefinition (void) {return (this->file_definition);} |
---|
146 | const XmlIOServer::XML::XMLClassTest& getGridDefinition (void) {return (this->grid_definition);} |
---|
147 | const XmlIOServer::XML::XMLClassTest& getAxisDefinition (void) {return (this->axis_definition);} |
---|
148 | |
---|
149 | ~Context() |
---|
150 | {/* Ne rien faire de plus pour le moment */ } |
---|
151 | |
---|
152 | protected: |
---|
153 | |
---|
154 | private: |
---|
155 | |
---|
156 | FieldGroup field_definition; |
---|
157 | |
---|
158 | XmlIOServer::XML::XMLClassTest file_definition, grid_definition, axis_definition; |
---|
159 | |
---|
160 | static string CurrentContextID; |
---|
161 | static Simulation* Root; |
---|
162 | static THashContext AllContext; |
---|
163 | |
---|
164 | }; //class Context |
---|
165 | |
---|
166 | // Variables statiques |
---|
167 | Simulation* Context::Root = new Simulation(); |
---|
168 | Context::THashContext Context::AllContext; |
---|
169 | string Context::CurrentContextID; |
---|
170 | |
---|
171 | // Définition de Simulation::addChild reportée ici car Class Context non définie précédemment. |
---|
172 | XMLElement* Simulation::addChild(TNodeType type, TListElements& path, THashAttributes& attr) |
---|
173 | { |
---|
174 | if (type != 1) std::cerr << "Type reçu sur Simulation invalide" << std::endl; |
---|
175 | Context *ct = new Context(type, attr); |
---|
176 | std::cout << *ct << std::endl; |
---|
177 | return (ct); |
---|
178 | } |
---|
179 | |
---|
180 | }// namespace XmlIOServer |
---|
181 | |
---|
182 | #endif //__CONTEXT__ |
---|