Ignore:
Timestamp:
10/07/10 10:29:38 (14 years ago)
Author:
hozdoba
Message:

Amélioration de quelques portions de code.
Ajout de contructeurs par copie.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • XMLIO_V2/dev/dev_rv/src/XMLIO/context.hpp

    r125 r126  
    1616            fieldDef(NULL), fileDef(NULL), axisDef(NULL), gridDef(NULL), domainDef(NULL) 
    1717         {/* Ne rien faire de plus */} 
    18  
    19          static void ShowTree(ostream& os = std::clog) 
    20          { 
    21             os << NIndent << "<?xml version=\"1.0\"?>" << std::endl; 
    22             os << NIndent << "<" << Context::GetRootName() << ">" << std::endl; 
    23  
    24             Poco::HashMap<string, StrHashMap<Context> > &AllListContext = Context::GetAllListObject(); 
    25             for (Poco::HashMap<string, StrHashMap<Context> >::Iterator it = AllListContext.begin(); it != AllListContext.end(); it++) 
    26                // On sort chacun des contextes successivement. 
    27             { Context::SetCurrentContext((*it).first); os << *((*it).second)[(*it).first] << std::endl; } 
    28  
    29             os << NIndent << "</" << Context::GetRootName() << ">" << std::endl  ; 
    30          } 
    31  
    32          static void FreeMemory(void) 
    33          { 
    34             Poco::HashMap<string, StrHashMap<Context> > &AllListContext = Context::GetAllListObject(); 
    35             for (Poco::HashMap<string, StrHashMap<Context> >::Iterator it = AllListContext.begin(); it != AllListContext.end(); it++) 
    36             { Context::SetCurrentContext((*it).first); delete ((*it).second)[(*it).first]; } 
    37          } 
    38  
    39          // Ne plus utiliser, disponible dans les classe treatment. 
    40          static void ResolveInheritance(void) 
    41          { 
    42             Poco::HashMap<string, StrHashMap<Context> > &AllListContext = Context::GetAllListObject(); 
    43             for (Poco::HashMap<string, StrHashMap<Context> >::Iterator it = AllListContext.begin(); it != AllListContext.end(); it++) 
    44             { 
    45                // Résolution des héritages descendants (càd des héritages de groupes) pour chacun des contextes. 
    46                Context::SetCurrentContext((*it).first); 
    47                ((*it).second)[(*it).first]->resolveDescInheritance(); 
    48  
    49                // Résolution des héritages par référence au niveau des fichiers. 
    50                const std::vector<CFile*>& allFiles = CFile::GetCurrentListObject().getVector(); 
    51                for (unsigned int i = 0; i < allFiles.size(); i++) allFiles[i]->resolveFieldRefInheritance(); 
    52             } 
    53          } 
    54  
    55          static Context* SwapContext(void) 
    56          { 
    57             if (Stid.size() == 0) 
    58             { 
    59                WARNING("SwapContext impossible car le pile des contextes est vides !"); 
    60                return (NULL); 
    61             } 
    62             string lastId = Stid.top (); Stid.pop (); 
    63             return (Context::GetObject(lastId)); 
    64          } 
    65  
    66          static Context* GetCurrentContext(void) 
    67          { return (Context::GetObject(Context::GetCurrentContextId())); } 
    68  
    69          static void SetCurrentContext(const string& id, bool withSwap = false) 
    70          { 
    71             if (withSwap) Stid.push (Context::GetCurrentContextId()); 
    72  
    73             // On modifie le context courrant pour tout les ObjectTemplate 
    74             Context::SetContext(id); 
    75  
    76             // Changement de context pour les champs et groupes de champs. 
    77             FieldGroup::SetContext(id);  CField::SetContext(id); 
    78  
    79             // Changement de context pour les fichiers et groupes de fichiers. 
    80             FileGroup::SetContext(id);   CFile::SetContext(id); 
    81  
    82             // Changement de context pour les grilles et groupes de grilles. 
    83             GridGroup::SetContext(id);   CGrid::SetContext(id); 
    84  
    85             // Changement de context pour les axes et groupes d'axes. 
    86             AxisGroup::SetContext(id);   CAxis::SetContext(id); 
    87  
    88             // Changement de context pour les domaines et groupes de domaines. 
    89             DomainGroup::SetContext(id); CDomain::SetContext(id); 
    90          } 
    91  
    92          virtual void parse (XMLNode& _node) 
    93          { 
    94             THashAttributes attributes; 
    95  
    96             /// PARSING POUR GESTION DES ENFANTS 
    97             if (_node.getElementName().compare(Context::GetName())) 
    98                WARNING("Le noeud est mal nommé mais sera traité comme un context !"); 
    99  
    100             if (!(_node.goToChildElement())) 
    101                WARNING("Le context ne contient pas d'enfant !"); 
    102             else 
    103             { 
    104               do { // Parcours des contexts pour traitement. 
    105  
    106                   string name = _node.getElementName(); 
    107                   attributes.clear(); 
    108                   _node.getAttributes(attributes); 
    109  
    110                   if (attributes.end() != attributes.find("id")) 
    111                   { WARNING("Le noeud de définition possÚde un identifiant, ce dernier ne sera pas pris en compte lors du traitement !"); } 
    112  
    113                   if (name.compare(FieldDefinition::GetDefName())  == 0) // Parsing pour la définition des champs. 
    114                   { fieldDef  = CreateInstanceAndParse<FieldDefinition >(_node, FieldDefinition::GetDefName().c_str()); continue; } 
    115  
    116                   if (name.compare(FileDefinition::GetDefName())  == 0) // Parsing pour la définition des fichiers. 
    117                   { fileDef   = CreateInstanceAndParse<FileDefinition  >(_node, FileDefinition  ::GetDefName().c_str()); continue; } 
    118  
    119                   if (name.compare(AxisDefinition::GetDefName())  == 0) // Parsing pour la définition des axes. 
    120                   { axisDef   = CreateInstanceAndParse<AxisDefinition  >(_node, AxisDefinition  ::GetDefName().c_str()); continue; } 
    121  
    122                   if (name.compare(GridDefinition::GetDefName())  == 0) // Parsing pour la définition des grilles. 
    123                   { gridDef   = CreateInstanceAndParse<GridDefinition  >(_node, GridDefinition  ::GetDefName().c_str()); continue; } 
    124  
    125                   if (name.compare(DomainDefinition::GetDefName()) == 0) // Parsing pour la définition des domaines. 
    126                   { domainDef = CreateInstanceAndParse<DomainDefinition>(_node, DomainDefinition::GetDefName().c_str()); continue; } 
    127  
    128                   WARNING("La définition est invalide, seuls les champs, grilles, axes et fichiers peuvent être définis !"); 
    129  
    130                } while (_node.goToNextElement()); 
    131  
    132                _node.goToParentElement(); // Retour au parent 
    133             } 
    134          } 
    135  
    136          static string GetRootName(void) { return ("simulation"); } 
    137          static string GetName(void)     { return ("context"); } 
    138          static string GetDefName(void)  { return (Context::GetName()); } 
    139  
    140  
    141          virtual bool hasChild(void) const 
    142          { return ((fieldDef != NULL) or (fileDef != NULL)  or (axisDef != NULL) or (gridDef != NULL) or (domainDef != NULL)); } 
    143  
    144          virtual void printChild(ostream& out) const 
    145          { 
    146             if(fieldDef  != NULL) out << *(FieldGroup*)       fieldDef  << std::endl; 
    147             if(fileDef   != NULL) out << *(FileGroup*)        fileDef   << std::endl; 
    148             if(axisDef   != NULL) out << *(AxisDefinition*)   axisDef   << std::endl; 
    149             if(gridDef   != NULL) out << *(GridDefinition*)   gridDef   << std::endl; 
    150             if(domainDef != NULL) out << *(DomainDefinition*) domainDef << std::endl; 
    151          } 
    152  
    153          virtual void resolveDescInheritance(const AttributRegistrar* const _parent = 0) 
    154          { 
    155             if (_parent != 0) return; 
    156             // Résolution des héritages descendants pour chacun des groupes de définitions. 
    157             if(fieldDef  != NULL) fieldDef ->resolveDescInheritance(); 
    158             if(fileDef   != NULL) fileDef  ->resolveDescInheritance(); 
    159             if(axisDef   != NULL) axisDef  ->resolveDescInheritance(); 
    160             if(gridDef   != NULL) gridDef  ->resolveDescInheritance(); 
    161             if(domainDef != NULL) domainDef->resolveDescInheritance(); 
    162          } 
    16318 
    16419         FieldDefinition  * getFieldDefinition(void)  const { return (this->fieldDef ); } 
     
    19853         } 
    19954 
     55      public : /* virtual */ 
     56 
     57         virtual void parse (XMLNode& _node) 
     58         { 
     59            THashAttributes attributes; 
     60 
     61            /// PARSING POUR GESTION DES ENFANTS 
     62            if (_node.getElementName().compare(Context::GetName())) 
     63               WARNING("Le noeud est mal nommé mais sera traité comme un context !"); 
     64 
     65            if (!(_node.goToChildElement())) 
     66               WARNING("Le context ne contient pas d'enfant !"); 
     67            else 
     68            { 
     69              do { // Parcours des contexts pour traitement. 
     70 
     71                  string name = _node.getElementName(); 
     72                  attributes.clear(); 
     73                  _node.getAttributes(attributes); 
     74 
     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 !"); } 
     77 
     78                  if (name.compare(FieldDefinition::GetDefName())  == 0) // Parsing pour la définition des champs. 
     79                  { fieldDef  = CreateInstanceAndParse<FieldDefinition >(_node, FieldDefinition::GetDefName().c_str()); continue; } 
     80 
     81                  if (name.compare(FileDefinition::GetDefName())  == 0) // Parsing pour la définition des fichiers. 
     82                  { fileDef   = CreateInstanceAndParse<FileDefinition  >(_node, FileDefinition  ::GetDefName().c_str()); continue; } 
     83 
     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 
     93                  WARNING("La définition est invalide, seuls les champs, grilles, axes et fichiers peuvent être définis !"); 
     94 
     95               } while (_node.goToNextElement()); 
     96 
     97               _node.goToParentElement(); // Retour au parent 
     98            } 
     99         } 
     100 
     101         virtual bool hasChild(void) const 
     102         { return ((fieldDef != NULL) or (fileDef != NULL)  or (axisDef != NULL) or (gridDef != NULL) or (domainDef != NULL)); } 
     103 
     104         virtual void printChild(ostream& out) const 
     105         { 
     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; 
     111         } 
     112 
     113         virtual void resolveDescInheritance(const AttributRegistrar* const _parent = 0) 
     114         { 
     115            if (_parent != 0) return; 
     116            // Résolution des héritages descendants pour chacun des groupes de définitions. 
     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(); 
     122         } 
     123 
     124      public : /* static */ 
     125 
     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) 
     131         { 
     132            os << NIndent << "<?xml version=\"1.0\"?>" << std::endl; 
     133            os << NIndent << "<" << Context::GetRootName() << ">" << std::endl; 
     134 
     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            } 
     143 
     144            os << NIndent << std::endl; 
     145            os << NIndent << "</" << Context::GetRootName() << ">" << std::endl  ; 
     146         } 
     147 
     148         static void FreeMemory(void) 
     149         { 
     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         } 
     154 
     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            } 
     169         } 
     170 
     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 
    200208      private: 
    201209 
    202210         static stack<string> Stid; 
    203211 
    204          AbstractCalendar* ccalendar; 
    205  
    206          FieldDefinition* fieldDef; 
    207          FileDefinition fileDef; 
    208          AxisDefinition axisDef; 
    209          GridDefinition gridDef; 
    210          DomainDefinition* domainDef; 
     212         AbstractCalendar * ccalendar; 
     213 
     214         FieldDefinition  * fieldDef; 
     215         FileDefinition   * fileDef; 
     216         AxisDefinition   * axisDef; 
     217         GridDefinition   * gridDef; 
     218         DomainDefinition * domainDef; 
    211219 
    212220   }; //class Context 
    213221 
    214    //stack<string> Context::Stid(); 
     222   stack<string> Context::Stid; 
    215223 
    216224}// namespace XMLIOSERVER 
Note: See TracChangeset for help on using the changeset viewer.