[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 | |
---|
[119] | 11 | Context(void) : ObjectTemplate<Context>(), ccalendar(NULL), |
---|
[122] | 12 | fieldDef(NULL), fileDef(NULL), axisDef(NULL), gridDef(NULL), domainDef(NULL) |
---|
[98] | 13 | {/* Ne rien faire de plus */} |
---|
[119] | 14 | |
---|
| 15 | Context(const string& _id) : ObjectTemplate<Context>(_id), ccalendar(NULL), |
---|
[122] | 16 | fieldDef(NULL), fileDef(NULL), axisDef(NULL), gridDef(NULL), domainDef(NULL) |
---|
[107] | 17 | {/* Ne rien faire de plus */} |
---|
| 18 | |
---|
[126] | 19 | FieldDefinition * getFieldDefinition(void) const { return (this->fieldDef ); } |
---|
| 20 | FileDefinition * getFileDefinition(void) const { return (this->fileDef ); } |
---|
| 21 | AxisDefinition * getAxisDefinition(void) const { return (this->axisDef ); } |
---|
| 22 | GridDefinition * getGridDefinition(void) const { return (this->gridDef ); } |
---|
| 23 | DomainDefinition * getDomainDefinition(void) const { return (this->domainDef); } |
---|
| 24 | |
---|
| 25 | AbstractCalendar * getCalendar(void) const { return (this->ccalendar ); } |
---|
| 26 | AbstractCalendar * setCalendar(const string& _calName, const string& _dateStr) |
---|
[107] | 27 | { |
---|
[126] | 28 | if (_calName.compare("D360") == 0) |
---|
| 29 | return (ccalendar = new D360Calendar(_dateStr)); |
---|
| 30 | if (_calName.compare("AllLeap") == 0) |
---|
| 31 | return (ccalendar = new AllLeapCalendar(_dateStr)); |
---|
| 32 | if (_calName.compare("NoLeap") == 0) |
---|
| 33 | return (ccalendar = new NoLeapCalendar(_dateStr)); |
---|
| 34 | if (_calName.compare("Julian") == 0) |
---|
| 35 | return (ccalendar = new JulianCalendar(_dateStr)); |
---|
| 36 | if (_calName.compare("Gregorian") == 0) |
---|
| 37 | return (ccalendar = new GregorianCalendar(_dateStr)); |
---|
[115] | 38 | |
---|
[126] | 39 | WARNING("L'identifiant "+_calName+" est inconnu, le calendrier grégorien sera choisi par défault pour le contexte "+getId()); |
---|
[115] | 40 | |
---|
[126] | 41 | return (ccalendar = new GregorianCalendar(_dateStr)); |
---|
[107] | 42 | } |
---|
| 43 | |
---|
[126] | 44 | ~Context() |
---|
[107] | 45 | { |
---|
[126] | 46 | // Désallocation dynamique de mémoire pour chacun des groupes de définition si nécessaire. |
---|
| 47 | if(fieldDef != NULL) delete fieldDef ; if(fileDef != NULL) delete fileDef ; |
---|
| 48 | if(axisDef != NULL) delete axisDef ; if(gridDef != NULL) delete gridDef ; |
---|
| 49 | if(domainDef != NULL) delete domainDef ; |
---|
[107] | 50 | |
---|
[126] | 51 | // Désallocation dynamique de mémoire pour le calendrier associé au contexte courant si nécessaire. |
---|
| 52 | if(ccalendar != NULL) delete ccalendar; |
---|
[107] | 53 | } |
---|
| 54 | |
---|
[126] | 55 | public : /* virtual */ |
---|
[125] | 56 | |
---|
[110] | 57 | virtual void parse (XMLNode& _node) |
---|
[98] | 58 | { |
---|
| 59 | THashAttributes attributes; |
---|
[107] | 60 | |
---|
[98] | 61 | /// PARSING POUR GESTION DES ENFANTS |
---|
[107] | 62 | if (_node.getElementName().compare(Context::GetName())) |
---|
[98] | 63 | WARNING("Le noeud est mal nommé mais sera traité comme un context !"); |
---|
[107] | 64 | |
---|
[98] | 65 | if (!(_node.goToChildElement())) |
---|
[107] | 66 | WARNING("Le context ne contient pas d'enfant !"); |
---|
[98] | 67 | else |
---|
| 68 | { |
---|
[107] | 69 | do { // Parcours des contexts pour traitement. |
---|
| 70 | |
---|
[98] | 71 | string name = _node.getElementName(); |
---|
| 72 | attributes.clear(); |
---|
[107] | 73 | _node.getAttributes(attributes); |
---|
| 74 | |
---|
[98] | 75 | if (attributes.end() != attributes.find("id")) |
---|
| 76 | { WARNING("Le noeud de définition possÚde un identifiant, ce dernier ne sera pas pris en compte lors du traitement !"); } |
---|
[79] | 77 | |
---|
[122] | 78 | if (name.compare(FieldDefinition::GetDefName()) == 0) // Parsing pour la définition des champs. |
---|
| 79 | { fieldDef = CreateInstanceAndParse<FieldDefinition >(_node, FieldDefinition::GetDefName().c_str()); continue; } |
---|
[107] | 80 | |
---|
[122] | 81 | if (name.compare(FileDefinition::GetDefName()) == 0) // Parsing pour la définition des fichiers. |
---|
| 82 | { fileDef = CreateInstanceAndParse<FileDefinition >(_node, FileDefinition ::GetDefName().c_str()); continue; } |
---|
[107] | 83 | |
---|
[122] | 84 | if (name.compare(AxisDefinition::GetDefName()) == 0) // Parsing pour la définition des axes. |
---|
| 85 | { axisDef = CreateInstanceAndParse<AxisDefinition >(_node, AxisDefinition ::GetDefName().c_str()); continue; } |
---|
| 86 | |
---|
| 87 | if (name.compare(GridDefinition::GetDefName()) == 0) // Parsing pour la définition des grilles. |
---|
| 88 | { gridDef = CreateInstanceAndParse<GridDefinition >(_node, GridDefinition ::GetDefName().c_str()); continue; } |
---|
| 89 | |
---|
| 90 | if (name.compare(DomainDefinition::GetDefName()) == 0) // Parsing pour la définition des domaines. |
---|
| 91 | { domainDef = CreateInstanceAndParse<DomainDefinition>(_node, DomainDefinition::GetDefName().c_str()); continue; } |
---|
| 92 | |
---|
[120] | 93 | WARNING("La définition est invalide, seuls les champs, grilles, axes et fichiers peuvent être définis !"); |
---|
[107] | 94 | |
---|
[98] | 95 | } while (_node.goToNextElement()); |
---|
[107] | 96 | |
---|
[98] | 97 | _node.goToParentElement(); // Retour au parent |
---|
| 98 | } |
---|
| 99 | } |
---|
[107] | 100 | |
---|
| 101 | virtual bool hasChild(void) const |
---|
[122] | 102 | { return ((fieldDef != NULL) or (fileDef != NULL) or (axisDef != NULL) or (gridDef != NULL) or (domainDef != NULL)); } |
---|
[113] | 103 | |
---|
[107] | 104 | virtual void printChild(ostream& out) const |
---|
| 105 | { |
---|
[122] | 106 | if(fieldDef != NULL) out << *(FieldGroup*) fieldDef << std::endl; |
---|
| 107 | if(fileDef != NULL) out << *(FileGroup*) fileDef << std::endl; |
---|
| 108 | if(axisDef != NULL) out << *(AxisDefinition*) axisDef << std::endl; |
---|
| 109 | if(gridDef != NULL) out << *(GridDefinition*) gridDef << std::endl; |
---|
| 110 | if(domainDef != NULL) out << *(DomainDefinition*) domainDef << std::endl; |
---|
[107] | 111 | } |
---|
[114] | 112 | |
---|
[120] | 113 | virtual void resolveDescInheritance(const AttributRegistrar* const _parent = 0) |
---|
[107] | 114 | { |
---|
[114] | 115 | if (_parent != 0) return; |
---|
[107] | 116 | // Résolution des héritages descendants pour chacun des groupes de définitions. |
---|
[122] | 117 | if(fieldDef != NULL) fieldDef ->resolveDescInheritance(); |
---|
| 118 | if(fileDef != NULL) fileDef ->resolveDescInheritance(); |
---|
| 119 | if(axisDef != NULL) axisDef ->resolveDescInheritance(); |
---|
| 120 | if(gridDef != NULL) gridDef ->resolveDescInheritance(); |
---|
| 121 | if(domainDef != NULL) domainDef->resolveDescInheritance(); |
---|
[107] | 122 | } |
---|
| 123 | |
---|
[126] | 124 | public : /* static */ |
---|
[107] | 125 | |
---|
[126] | 126 | static string GetRootName(void) { return ("simulation"); } |
---|
| 127 | static string GetName(void) { return ("context"); } |
---|
| 128 | static string GetDefName(void) { return (Context::GetName()); } |
---|
| 129 | |
---|
| 130 | static void ShowTree(ostream& os = std::clog) |
---|
[119] | 131 | { |
---|
[126] | 132 | os << NIndent << "<?xml version=\"1.0\"?>" << std::endl; |
---|
| 133 | os << NIndent << "<" << Context::GetRootName() << ">" << std::endl; |
---|
[119] | 134 | |
---|
[126] | 135 | Poco::HashMap<string, StrHashMap<Context> > &AllListContext = Context::GetAllListObject(); |
---|
| 136 | for (Poco::HashMap<string, StrHashMap<Context> >::Iterator it = AllListContext.begin(); it != AllListContext.end(); it++) |
---|
| 137 | // On sort chacun des contextes successivement. |
---|
| 138 | { |
---|
| 139 | Context::SetCurrentContext((*it).first); |
---|
| 140 | os << NIndent << std::endl; |
---|
| 141 | os << *((*it).second)[(*it).first] << std::endl; |
---|
| 142 | } |
---|
[119] | 143 | |
---|
[126] | 144 | os << NIndent << std::endl; |
---|
| 145 | os << NIndent << "</" << Context::GetRootName() << ">" << std::endl ; |
---|
[119] | 146 | } |
---|
| 147 | |
---|
[126] | 148 | static void FreeMemory(void) |
---|
[107] | 149 | { |
---|
[126] | 150 | Poco::HashMap<string, StrHashMap<Context> > &AllListContext = Context::GetAllListObject(); |
---|
| 151 | for (Poco::HashMap<string, StrHashMap<Context> >::Iterator it = AllListContext.begin(); it != AllListContext.end(); it++) |
---|
| 152 | { Context::SetCurrentContext((*it).first); delete ((*it).second)[(*it).first]; } |
---|
| 153 | } |
---|
[120] | 154 | |
---|
[126] | 155 | // Ne plus utiliser, disponible dans les classe treatment. |
---|
| 156 | static void ResolveInheritance(void) |
---|
| 157 | { |
---|
| 158 | Poco::HashMap<string, StrHashMap<Context> > &AllListContext = Context::GetAllListObject(); |
---|
| 159 | for (Poco::HashMap<string, StrHashMap<Context> >::Iterator it = AllListContext.begin(); it != AllListContext.end(); it++) |
---|
| 160 | { |
---|
| 161 | // Résolution des héritages descendants (cà d des héritages de groupes) pour chacun des contextes. |
---|
| 162 | Context::SetCurrentContext((*it).first); |
---|
| 163 | ((*it).second)[(*it).first]->resolveDescInheritance(); |
---|
| 164 | |
---|
| 165 | // Résolution des héritages par référence au niveau des fichiers. |
---|
| 166 | const std::vector<CFile*>& allFiles = CFile::GetCurrentListObject().getVector(); |
---|
| 167 | for (unsigned int i = 0; i < allFiles.size(); i++) allFiles[i]->resolveFieldRefInheritance(); |
---|
| 168 | } |
---|
[107] | 169 | } |
---|
[104] | 170 | |
---|
[126] | 171 | static Context* SwapContext(void) |
---|
| 172 | { |
---|
| 173 | if (Stid.size() == 0) |
---|
| 174 | { |
---|
| 175 | WARNING("SwapContext impossible car le pile des contextes est vides !"); |
---|
| 176 | return (NULL); |
---|
| 177 | } |
---|
| 178 | string lastId = Stid.top (); Stid.pop (); |
---|
| 179 | return (Context::GetObject(lastId)); |
---|
| 180 | } |
---|
| 181 | |
---|
| 182 | static Context* GetCurrentContext(void) |
---|
| 183 | { return (Context::GetObject(Context::GetCurrentContextId())); } |
---|
| 184 | |
---|
| 185 | static void SetCurrentContext(const string& id, bool withSwap = false) |
---|
| 186 | { |
---|
| 187 | if (withSwap) Stid.push (Context::GetCurrentContextId()); |
---|
| 188 | |
---|
| 189 | // On modifie le context courrant pour tout les ObjectTemplate |
---|
| 190 | Context::SetContext(id); |
---|
| 191 | |
---|
| 192 | // Changement de context pour les champs et groupes de champs. |
---|
| 193 | FieldGroup::SetContext(id); CField::SetContext(id); |
---|
| 194 | |
---|
| 195 | // Changement de context pour les fichiers et groupes de fichiers. |
---|
| 196 | FileGroup::SetContext(id); CFile::SetContext(id); |
---|
| 197 | |
---|
| 198 | // Changement de context pour les grilles et groupes de grilles. |
---|
| 199 | GridGroup::SetContext(id); CGrid::SetContext(id); |
---|
| 200 | |
---|
| 201 | // Changement de context pour les axes et groupes d'axes. |
---|
| 202 | AxisGroup::SetContext(id); CAxis::SetContext(id); |
---|
| 203 | |
---|
| 204 | // Changement de context pour les domaines et groupes de domaines. |
---|
| 205 | DomainGroup::SetContext(id); CDomain::SetContext(id); |
---|
| 206 | } |
---|
| 207 | |
---|
[98] | 208 | private: |
---|
[107] | 209 | |
---|
[125] | 210 | static stack<string> Stid; |
---|
| 211 | |
---|
[126] | 212 | AbstractCalendar * ccalendar; |
---|
[119] | 213 | |
---|
[126] | 214 | FieldDefinition * fieldDef; |
---|
| 215 | FileDefinition * fileDef; |
---|
| 216 | AxisDefinition * axisDef; |
---|
| 217 | GridDefinition * gridDef; |
---|
| 218 | DomainDefinition * domainDef; |
---|
[79] | 219 | |
---|
[98] | 220 | }; //class Context |
---|
[125] | 221 | |
---|
[126] | 222 | stack<string> Context::Stid; |
---|
[125] | 223 | |
---|
[98] | 224 | }// namespace XMLIOSERVER |
---|
[79] | 225 | |
---|
[98] | 226 | #endif // __CONTEXT__ |
---|