source: XMLIO_V2/dev/dev_rv/src/XMLIO/context.hpp @ 107

Last change on this file since 107 was 107, checked in by hozdoba, 14 years ago

Commit intermédiaire ...
Remontée de plusieurs fonctionnalités dans l'arbre des héritages.
Amélioration de la lisibilité du code.
etc.

File size: 6.8 KB
Line 
1#ifndef __CONTEXT__
2#define __CONTEXT__
3
4
5namespace 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 <<  "<?xml version=\"1.0\"?>" << std::endl;
19            clog <<  "<simulation>" << 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               clog << *((*it).second)[(*it).first] << std::endl;
24            clog << "</simulation>" << 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               // Résolution des héritages des descendands (càd des héritages de groupes) pour chacun des contextes.
39               ((*it).second)[(*it).first]->resolveDescInheritance();
40         }
41
42         static void SetCurrentContext(const string& id)
43         {
44            // On modifie le context courrant pour tout les ObjectTemplate
45            Context::SetContext(id);
46
47            // Changement de context pour les champs et groupes de champs.
48            FieldGroup::SetContext(id);
49            CField::SetContext(id);
50
51            // Changement de context pour les fichiers et groupes de fichiers.
52            FileGroup::SetContext(id);
53            CFile::SetContext(id);
54
55            // Changement de context pour les grilles et groupes de grilles.
56            //GridGroup::SetContext(id);
57            //CGrid::SetContext(id);
58
59            // Changement de context pour les axes et groupes d'axes.
60            //AxisGroup::SetContext(id);
61            //CAxis::SetContext(id);
62         }
63
64         void parse (XMLNode& _node)
65         {
66            THashAttributes attributes;
67
68            /// PARSING POUR GESTION DES ENFANTS
69            if (_node.getElementName().compare(Context::GetName()))
70               WARNING("Le noeud est mal nommé mais sera traité comme un context !");
71
72            if (!(_node.goToChildElement()))
73               WARNING("Le context ne contient pas d'enfant !");
74            else
75            {
76              do { // Parcours des contexts pour traitement.
77
78                  string name = _node.getElementName();
79                  attributes.clear();
80                  _node.getAttributes(attributes);
81
82                  if (attributes.end() != attributes.find("id"))
83                  { WARNING("Le noeud de définition possÚde un identifiant, ce dernier ne sera pas pris en compte lors du traitement !"); }
84
85                  if (name.compare(FieldDefinition::GetDefName()) == 0) // Parsing définition des champs.
86                  { fieldDef = CreateInstanceAndParse<FieldDefinition>(attributes, _node, "field_definition"); continue; }
87                  if (name.compare(FileDefinition::GetDefName()) == 0) // Parsing définition des fichiers.
88                  { fileDef = CreateInstanceAndParse<FileDefinition>(attributes, _node, "file_definition"); continue; }
89
90                  if (name.compare("axis_definition") == 0)
91                  { // Parsing pour la définition des axes.
92                     INFO("Le parsing des définitions d'axes n'est pas encore implémenté");
93                     //axisDef = CreateInstance<AxisDefinition>(attributes, _node, "axis_definition");
94                     continue;
95                  }
96
97                  if (name.compare("grid_definition") == 0)
98                  { // Parsing pour la définition des grilles.
99                     INFO("Le parsing des définitions de grilles n'est pas encore implémenté");
100                     //gridDef = CreateInstance<GridDefinition>(attributes, _node, "grid_definition");
101                     continue;
102                  }
103
104                  WARNING("La définition est invalide, seules les champs, grilles, axes et fichiers peuvent être définis !");
105
106               } while (_node.goToNextElement());
107
108               _node.goToParentElement(); // Retour au parent
109            }
110
111            return;
112         }
113
114         static string GetName(void) {return ("context"); }
115
116         virtual bool hasChild(void) const
117         { return ((fieldDef != NULL) or (fileDef != NULL) /* or (axisDef != NULL) or (gridDef != NULL) */); }
118         virtual void printChild(ostream& out) const
119         {
120            if(fieldDef != NULL) out << *(FieldGroup*)fieldDef << std::endl;
121            if(fileDef != NULL)  out << *(FileGroup*) fileDef  << std::endl;
122            //if(axisDef != NULL) out << *(AxisDefinition*)axisDef << std::endl;
123            //if(gridDef != NULL) out << *(GridDefinition*)gridDef << std::endl;
124         }
125         virtual void resolveDescInheritance(const AttributRegistrar* _parent = 0)
126         {
127            // Résolution des héritages descendants pour chacun des groupes de définitions.
128            if(fieldDef != NULL) fieldDef->resolveDescInheritance();
129            if(fileDef != NULL)  fileDef ->resolveDescInheritance();
130            //if(axisDef != NULL)  axisDef ->resolveDescInheritance();
131            //if(gridDef != NULL)  gridDef ->resolveDescInheritance();
132         }
133
134         FieldDefinition* getFieldDefinition(void) { return (this->fieldDef); }
135         FileDefinition*  getFileDefinition(void)  { return (this->fileDef);  }
136         //AxisDefinition* getAxisDefinition(void) { return (this->axisDef); }
137         //GridDefinition*  getGridDefinition(void)  { return (this->gridDef); }
138
139         ~Context()
140         {
141            if(fieldDef != NULL) delete fieldDef;
142            if(fileDef != NULL)  delete fileDef;
143            //if(axisDef != NULL)  delete axisDef;
144            //if(gridDef != NULL)  delete gridDef;
145         }
146
147
148      private:
149
150         FieldDefinition*  fieldDef;
151         FileDefinition*   fileDef;
152         /*AxisDefinition*   axisDef;
153         GridDefinition*   gridDef;*/
154
155
156   }; //class Context
157}// namespace XMLIOSERVER
158
159#endif  // __CONTEXT__
Note: See TracBrowser for help on using the repository browser.