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