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

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

Le code respecte davantage la norme C++ 98 pour le portage sur les différentes plate-formes,

Une compilation plus restrictive passe sans problÚme sous gcc avec les options de compilation suivantes :
"-W -Wall -Wextra -Werror -ansi -pedantic "
et le retrait de certain avertissements :
-Wno-ignored-qualifiers < plusieurs avertissements dans Blitz.
-Wno-unused-parameter < des paramÚtres ne sont pas utilisés dans la classe BaseAttribut? (voir les get/set)
-Wno-long-long < besoin des long long pour le calendrier.

File size: 7.1 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            os << NIndent << "<?xml version=\"1.0\"?>" << std::endl;
19            os << 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); os << *((*it).second)[(*it).first] << std::endl; }
24            os << 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         virtual 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>(_node, FieldDefinition::GetDefName().c_str()); continue; }
94
95                  if (name.compare(FileDefinition::GetDefName()) == 0) // Parsing définition des fichiers.
96                  { fileDef  = CreateInstanceAndParse<FileDefinition >(_node, FileDefinition ::GetDefName().c_str()); continue; }
97
98                  if (name.compare(AxisDefinition::GetDefName()) == 0) // Parsing pour la définition des axes.
99                  { axisDef  = CreateInstanceAndParse<AxisDefinition >(_node, AxisDefinition ::GetDefName().c_str()); continue; }
100
101                  if (name.compare(GridDefinition::GetDefName()) == 0) // Parsing pour la définition des grilles.
102                  { gridDef  = CreateInstanceAndParse<GridDefinition >(_node, GridDefinition ::GetDefName().c_str()); continue; }
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         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__
Note: See TracBrowser for help on using the repository browser.