Changeset 107


Ignore:
Timestamp:
06/17/10 16:44:31 (14 years ago)
Author:
hozdoba
Message:

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

Location:
XMLIO_V2/dev/dev_rv/src/XMLIO
Files:
15 edited

Legend:

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

    r106 r107  
    1111   { 
    1212      public : 
    13          
     13 
    1414         AttributRegistrar():attrList() 
    1515         {/* Ne rien faire de plus */} 
    16        
    17          void RegisterAttribut(BaseAttribut* attribut){ attrList.addObject(attribut); }          
    18          const StrHashMap<BaseAttribut>& getAttributList(void) const { return (attrList); }          
     16 
     17         void RegisterAttribut(BaseAttribut* attribut){ attrList.addObject(attribut); } 
     18         const StrHashMap<BaseAttribut>& getAttributList(void) const { return (attrList); } 
    1919         size_t getNbAttributes() const {return (attrList.getSize()); } 
    2020         bool hasAttribut(const string& _id) { return (attrList.hasMappedValue(_id)); } 
    21           
     21 
    2222         BaseAttribut* getAttribut(const string& _id) throw (XMLIOUndefinedValueException) { return (attrList[_id]); } 
    23           
    24          friend ostream& operator<< (ostream& out, const AttributRegistrar& c)  
    25          {             
    26             for(unsigned int i = 0; i < c.attrList.getVectorSize(); i++) out << *c.attrList.getVector()[i];           
     23 
     24         friend ostream& operator<< (ostream& out, const AttributRegistrar& c) 
     25         { 
     26            for(unsigned int i = 0; i < c.attrList.getVectorSize(); i++) out << *c.attrList.getVector()[i]; 
    2727            return (out); 
    28          }    
    29           
    30           
     28         } 
     29 
    3130         void setAttributes(const THashAttributes& _attr) 
    3231         { 
     
    3433               if ((*it).first.compare(string("id"))!= 0 and (*it).first.compare(string("src"))!=0) 
    3534               // (Au dessus) Non prise en compte de l'identifiant et de l'inclusion de fichiers externes lors de l'affectation des attributs. 
    36                   this->setSAttribut((*it).first, (*it).second);             
     35                  this->setSAttribut((*it).first, (*it).second); 
    3736            return; 
    3837         } 
    39           
     38 
    4039         void addAttributes(const AttributRegistrar& _parent) 
    41          {   
     40         { 
    4241            const StrHashMap<BaseAttribut>& _pattr = _parent.getAttributList(); 
    43             const StrHashMap<BaseAttribut>& _lattr = getAttributList();             
     42            const StrHashMap<BaseAttribut>& _lattr = getAttributList(); 
    4443            //_pattr contient les attributs du parent, _lattr les attributs locaux. 
    45              
     44 
    4645            for(unsigned int i = 0; i < _lattr.getVectorSize(); i++) 
    4746            { 
     
    5049            } 
    5150         } 
    52          
     51 
    5352         void setSAttribut(const string& att_name, const std::string& value) 
    5453         { 
     
    6261               oss << "CAttributRegistrar::setAttribut<ValueType>, could not find <<" << att_name <<">> attribut in registred list" <<">>"; 
    6362               throw XMLIOUndefinedValueException(oss.str()); 
    64             }          
     63            } 
    6564         } 
    66                          
     65 
    6766      public : 
    68           
     67 
    6968        ~AttributRegistrar(void) 
    7069        {/* Ne rien faire de plus */} 
    71          
     70 
    7271      protected : 
    7372         StrHashMap<BaseAttribut> attrList; 
    74          
    75    }; // class AttributRegistrar   
     73 
     74 
     75   }; // class AttributRegistrar 
    7676}; // namespace XMLIOSERVER 
    7777 
  • XMLIO_V2/dev/dev_rv/src/XMLIO/context.hpp

    r106 r107  
    11#ifndef __CONTEXT__ 
    2 #define __CONTEXT__  
     2#define __CONTEXT__ 
    33 
    4        
     4 
    55namespace XMLIOSERVER 
    6 {  
     6{ 
    77   class Context : public ObjectTemplate<Context> 
    88   { 
    99      public: 
    10              
    11          Context(void) : ObjectTemplate<Context>(), fieldDef(NULL), fileDef(NULL) 
    12          {/* Ne rien faire de plus */}                
    13          Context(const string& _id) : ObjectTemplate<Context>(_id), fieldDef(NULL), fileDef(NULL) 
     10 
     11         Context(void) : ObjectTemplate<Context>(), fieldDef(NULL), fileDef(NULL)//, axisDef(NULL), gridDef(NULL) 
    1412         {/* Ne rien faire de plus */} 
    15           
     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 
    1642         static void SetCurrentContext(const string& id) 
    1743         { 
    1844            // On modifie le context courrant pour tout les ObjectTemplate 
    1945            Context::SetContext(id); 
    20              
     46 
    2147            // Changement de context pour les champs et groupes de champs. 
    2248            FieldGroup::SetContext(id); 
    2349            CField::SetContext(id); 
    24              
    25             // Changement de context pour les champs et groupes de champs. 
     50 
     51            // Changement de context pour les fichiers et groupes de fichiers. 
    2652            FileGroup::SetContext(id); 
    2753            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); 
    2862         } 
    29           
    30          friend ostream& operator<< (ostream& out, const Context& c)  
    31          {  
    32             out << IncIndent << "<" << c.getName()<< " id=\"" <<  c.getId() << "\">" << std::endl; 
    33              
    34             if(c.fieldDef != NULL) out << *(FieldGroup*)c.fieldDef << std::endl; 
    35             if(c.fileDef != NULL)  out << *(FileGroup*) c.fileDef  << std::endl; 
    36              
    37             out << NIndent << "</" << c.getName()<< ">" << DecEndl; 
    38             return (out); 
    39          }  
    40           
    41          void resolveDescInheritance(void) 
     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) 
    42126         { 
    43127            // Résolution des héritages descendants pour chacun des groupes de définitions. 
    44128            if(fieldDef != NULL) fieldDef->resolveDescInheritance(); 
    45             if(fileDef != NULL)  fileDef->resolveDescInheritance(); 
     129            if(fileDef != NULL)  fileDef ->resolveDescInheritance(); 
     130            //if(axisDef != NULL)  axisDef ->resolveDescInheritance(); 
     131            //if(gridDef != NULL)  gridDef ->resolveDescInheritance(); 
    46132         } 
    47           
    48          void parse (XMLNode& _node) 
    49          { 
    50             THashAttributes attributes; 
    51             
    52             /// PARSING POUR GESTION DES ENFANTS 
    53             if (_node.getElementName().compare(string("context"))) 
    54                WARNING("Le noeud est mal nommé mais sera traité comme un context !"); 
    55              
    56             if (!(_node.goToChildElement())) 
    57                WARNING("Le context ne contient pas d'enfant !");  
    58             else 
    59             { 
    60                ////////////////////////////////////// 
    61               do { // Parcours des contexts pour traitement.         
    62                              
    63                   string name = _node.getElementName(); 
    64                   attributes.clear(); 
    65                   _node.getAttributes(attributes);    
    66                    
    67                   if (attributes.end() != attributes.find("id")) 
    68                   { WARNING("Le noeud de définition possÚde un identifiant, ce dernier ne sera pas pris en compte lors du traitement !"); } 
    69                    
    70                   if (name.compare("field_definition") == 0) 
    71                   { // Parsing pour la définition des champs. 
    72                    
    73                      if (FieldDefinition::HasObject("field_definition"))  
    74                         WARNING("Le context possÚde déjà un noeud de définition de champs, le dernier défini complétera le premier !"); 
    75                       
    76                      fieldDef = (FieldDefinition*)&FieldDefinition::CreateObject("field_definition"); // << Conversion possible car la classe Field n'a pas de propriétés. 
    77                      fieldDef->parse(_node); 
    78133 
    79                      continue; 
    80                   } 
    81                   else if (name.compare("file_definition") == 0) 
    82                   { // Parsing pour la définition des fichiers.  
    83                                     
    84                      if (FileDefinition::HasObject("file_definition"))  
    85                         WARNING("Le context possÚde déjà un noeud de définition de fichiers, le dernier défini complétera le premier !"); 
    86                       
    87                      fileDef = (FileDefinition*)&FileDefinition::CreateObject("file_definition"); // << Conversion possible car la classe Field n'a pas de propriétés. 
    88                      fileDef->parse(_node); 
    89  
    90                      continue; 
    91                   }  
    92                   else if (name.compare("axis_definition") == 0) 
    93                   { // Parsing pour la définition des axes. 
    94                      INFO("Le parsing des définitions d'axes n'est pas encore implémenté"); 
    95                   } 
    96                   else if (name.compare("grid_definition") == 0) 
    97                   { // Parsing pour la définition des grilles. 
    98                      INFO("Le parsing des définitions de grilles n'est pas encore implémenté"); 
    99                   }  
    100                   else 
    101                      WARNING("La définition est invalide, seules les champs, grilles, axes et fichiers peuvent être définis !"); 
    102                       
    103                       
    104                   // Traitement file, grid et axis à compléter. 
    105                } while (_node.goToNextElement()); 
    106                ////////////////////////////////////// 
    107                _node.goToParentElement(); // Retour au parent 
    108             } 
    109              
    110             return; 
    111          } 
    112           
    113          const char* getName(void) const {return ("Context"); } 
    114           
    115134         FieldDefinition* getFieldDefinition(void) { return (this->fieldDef); } 
    116135         FileDefinition*  getFileDefinition(void)  { return (this->fileDef);  } 
    117                    
     136         //AxisDefinition* getAxisDefinition(void) { return (this->axisDef); } 
     137         //GridDefinition*  getGridDefinition(void)  { return (this->gridDef); } 
     138 
    118139         ~Context() 
    119          {  
     140         { 
    120141            if(fieldDef != NULL) delete fieldDef; 
    121142            if(fileDef != NULL)  delete fileDef; 
    122          }       
     143            //if(axisDef != NULL)  delete axisDef; 
     144            //if(gridDef != NULL)  delete gridDef; 
     145         } 
    123146 
    124        
     147 
    125148      private: 
    126        
     149 
    127150         FieldDefinition*  fieldDef; 
    128151         FileDefinition*   fileDef; 
     
    130153         GridDefinition*   gridDef;*/ 
    131154 
    132        
     155 
    133156   }; //class Context 
    134157}// namespace XMLIOSERVER 
  • XMLIO_V2/dev/dev_rv/src/XMLIO/field.hpp

    r106 r107  
    1010   { 
    1111      public: 
    12        
     12 
    1313         CField(void) : ObjectTemplate<CField>(), FieldAttribut() 
    14                         {/* Ne rien faire de plus */}                    
    15                         CField(const string& _id) : ObjectTemplate<CField>(_id), FieldAttribut() 
    16          {/* Ne rien faire de plus */}   
    17           
    18          friend ostream& operator<< (ostream& out, const CField& c)  
     14         {/* Ne rien faire de plus */} 
     15         CField(const string& _id) : ObjectTemplate<CField>(_id), FieldAttribut() 
     16         {/* Ne rien faire de plus */} 
     17 
     18         static string GetName(void) {return ("field"); } 
     19 
     20         void parse (XMLNode& _node) 
    1921         { 
    20             const AttributRegistrar &ar = c; 
    21             out << IncIndent << "<" << c.getName() << c.printId() << ar << "/>" << DecEndl;                      
    22             return (out); 
    23          } 
    24                    
    25          const char* getName(void) const {return ("Field"); }    
     22            string name = _node.getElementName(); 
     23            THashAttributes attributes; 
    2624 
    27                         void parse (XMLNode& _node) 
    28                         { 
    29             string name = _node.getElementName();             
    30             THashAttributes attributes; 
    31              
    3225            /// PARSING GESTION DES ATTRIBUTS /// 
    33             _node.getAttributes(attributes);   
     26            _node.getAttributes(attributes); 
    3427            this->setAttributes(attributes); 
    3528            attributes.clear(); 
    36              
     29 
    3730            /// PARSING POUR GESION DES ENFANTS 
    3831            // Rien à faire. 
    39              
    40             return; 
    4132         } 
    42           
    43          ~CField(void)  
    44          { /* Ne rien faire de plus */ }     
    45        
    46    }; // class Field  
    47        
     33 
     34         ~CField(void) 
     35         { /* Ne rien faire de plus */ } 
     36 
     37   }; // class Field 
     38 
    4839}; // namespace XMLIOSERVER 
    49     
     40 
    5041#endif // __FIELD__ 
  • XMLIO_V2/dev/dev_rv/src/XMLIO/field_attribut.hpp

    r106 r107  
    11#ifndef __FIELD_ATTRIBUT__ 
    22#define __FIELD_ATTRIBUT__ 
    3  
    4 #include "declare_attribut.hpp" 
    5 #include "attribut_registrar.hpp" 
    63 
    74namespace XMLIOSERVER 
     
    107   { 
    118      public : 
    12        
     9 
    1310         DECLARE_ATTR(name, string) ; 
    14          DECLARE_ATTR(description, string) ;  
     11         DECLARE_ATTR(description, string) ; 
    1512         DECLARE_ATTR(unit, string) ; 
    1613         DECLARE_ATTR(operation, string); 
    17        
     14 
    1815         DECLARE_ATTR(freq_op, int) ; 
    1916         DECLARE_ATTR(level, int) ; 
    2017         DECLARE_ATTR(prec, int) ; 
    21                
     18 
    2219         DECLARE_ATTR(enabled, bool); 
    23        
     20 
    2421         DECLARE_ATTR(axis_ref, string); 
    2522         DECLARE_ATTR(grid_ref, string); 
    2623         DECLARE_ATTR(zoom_ref, string); 
    2724         DECLARE_ATTR(field_ref, string); 
    28        
     25 
    2926         FieldAttribut(void) : AttributRegistrar() 
    3027         { registerAllAttributes(); } 
    31                           
     28 
    3229      private : 
    33        
     30 
    3431         void registerAllAttributes(void) 
    3532         { 
    3633            RegisterAttribut(&name) ; 
    37             RegisterAttribut(&description) ;  
     34            RegisterAttribut(&description) ; 
    3835            RegisterAttribut(&unit) ; 
    3936            RegisterAttribut(&operation); 
    40        
     37 
    4138            RegisterAttribut(&freq_op) ; 
    4239            RegisterAttribut(&level) ; 
    4340            RegisterAttribut(&prec) ; 
    4441            RegisterAttribut(&enabled); 
    45        
     42 
    4643            RegisterAttribut(&axis_ref); 
    4744            RegisterAttribut(&grid_ref); 
     
    4946            RegisterAttribut(&field_ref); 
    5047         } 
    51       
     48 
    5249   } ; // class FieldAttribut 
    53     
     50 
    5451}// namespace XMLIOSERVER 
    5552 
  • XMLIO_V2/dev/dev_rv/src/XMLIO/field_group.hpp

    r106 r107  
    33 
    44namespace XMLIOSERVER 
    5 {    
     5{ 
    66   class FieldGroup : public GroupTemplate<CField, FieldAttribut> 
    77   { 
    88      public: 
    9        
     9 
    1010         FieldGroup(void) : GroupTemplate<CField, FieldAttribut>() 
    11          {/* Ne rien faire de plus */}                
     11         {/* Ne rien faire de plus */} 
    1212         FieldGroup(const string& _id) : GroupTemplate<CField, FieldAttribut>(_id) 
    1313         {/* Ne rien faire de plus */} 
    14                           
    15          const char* getName(void) const {return ("Field_Group"); }   
    16           
    17           
    18          /// TODO A remonter dans l'arbre des héritages 
    19          friend ostream& operator<< (ostream& out, const FieldGroup& c)  
    20          {    
    21             const AttributRegistrar &ar = c; 
    22             out << IncIndent << "<" << c.getName() << c.printId() << ar << ">" << std::endl;             
    23              
    24             // Ecriture des sous-groupes. 
    25             for(unsigned int i = 0; i < c.groupList.getVector().size() ; i++) 
    26                out << *((FieldGroup*)c.groupList.getVector()[i])  << std::endl; 
    27                 
    28             // Ecriture des enfants. 
    29             for(unsigned int i = 0; i < c.childList.getVector().size() ; i++) 
    30                out << *(c.childList.getVector()[i]) << std::endl; 
    31                 
    32             out << NIndent << "</" << c.getName()<< ">" << DecEndl; 
    33              
    34             return (out); 
    35          }    
    36           
    37          /// TODO A remonter dans l'arbre des héritages    
    38          void resolveDescInheritance(const AttributRegistrar* _parent = 0) 
    39          { 
    40             const vector<CField*>&  childvect = childList.getVector(); 
    41             const vector<GroupTemplate<CField, FieldAttribut>*>& groupvect = groupList.getVector(); 
    42              
    43             // On complÚte les propres attributs du groupe. 
    44             if (_parent!= NULL) addAttributes(*_parent); 
    45              
    46             for(unsigned int i = 0; i < childvect.size() ; i++) 
    47             // on complÚte les attributs des champs enfants 
    48                childvect[i] -> addAttributes(*this); 
    49                 
    50             for(unsigned int i = 0; i < groupvect.size() ; i++) 
    51             // on complÚte les attributs des groupes de champs enfants 
    52                ((FieldGroup*)groupvect[i]) -> resolveDescInheritance(this); 
    53          } 
    54           
     14 
    5515         void parse (XMLNode& _node, bool _withAttr = true) 
    5616         { 
    57             string name = _node.getElementName();             
     17            string name = _node.getElementName(); 
    5818            THashAttributes attributes; 
    5919 
     
    6121            if (_withAttr) 
    6222            { 
    63                _node.getAttributes(attributes);   
     23               _node.getAttributes(attributes); 
    6424               this->setAttributes(attributes); 
    65                 
     25 
    6626               if (attributes.end() != attributes.find("src")) 
    67                { // Si une demande d'inclusion de fichier est trouvé. 
     27               { // Si une demande d'inclusion de fichier est trouvée. 
    6828                  XMLNode _node_inc = getNodeIncludedFile(attributes["src"], name); 
    6929                  parse (_node_inc); 
    7030               } 
    71                 
    7231               attributes.clear(); 
    7332            } 
    74                 
     33 
    7534            /// PARSING POUR GESION DES ENFANTS 
    7635            if (!(_node.goToChildElement())) 
     
    7938            { 
    8039               ////////////////////////////////////// 
    81                do { // Parcours des contexts pour traitement.  
    82                              
     40               do { // Parcours des contexts pour traitement. 
     41 
    8342                  string name = _node.getElementName(); 
    8443                  attributes.clear(); 
    85                   _node.getAttributes(attributes);   
    86                                   
    87                   if (name.compare("field_group") == 0) 
    88                   { // Parsing pour les groupes de champs 
    89                    
    90                      FieldGroup* fgroup = NULL; 
    91                          
    92                      if (attributes.end() != attributes.find("id")) 
    93                      {// Si l'identifiant est défini. 
    94                         if (FieldGroup::HasObject(attributes["id"])) 
    95                            WARNING("Dans le context actuel, un groupe de champ du même nom existe déjà, le second fera référence au premier par défaut !"); // TODO TODO 
    96                         fgroup = (FieldGroup*)(&createGroup(attributes["id"])); 
    97                         fgroup->parse(_node); 
    98                      } 
    99                      else 
    100                      {// Si l'identifiant n'est pas défini. 
    101                         fgroup = (FieldGroup*)(&createGroup()); 
    102                         fgroup->parse(_node); 
    103                      }                         
    104                      continue; 
    105                          
    106                   } 
    107                   else if (name.compare("field") == 0) 
    108                   { // Parsing pour les champs. 
    109                    
    110                      CField* field = NULL; 
    111                    
    112                      if (attributes.end() != attributes.find("id")) 
    113                      {// Si l'identifiant est défini. 
    114                         if (CField::HasObject(attributes["id"])) 
    115                            WARNING("Dans le context actuel, un champ du même nom existe déjà, le second fera référence au premier par défaut !");  // TODO TODO 
    116                         field = (CField*)(&createChild(attributes["id"])); 
    117                         field->parse(_node); 
    118                      } 
    119                      else 
    120                      {// Si l'identifiant n'est pas défini. 
    121                         field = (CField*)(&createChild()); 
    122                         field->parse(_node); 
    123                      }                   
    124                      continue; 
    125                   }  
    126                   else 
    127                      WARNING("Un groupe de champs ne peut contenir qu'un champ ou un autre groupe de champs !"); 
    128                       
     44                  _node.getAttributes(attributes); 
     45 
     46                  if (name.compare(FieldGroup::GetName()) == 0) 
     47                  { createGroupAndParse<FieldGroup>(attributes, _node); continue; } 
     48 
     49                  if (name.compare(CField::GetName()) == 0) 
     50                  { createChildAndParse<CField>(attributes, _node); continue; } 
     51 
     52                  WARNING("Un groupe de champs ne peut contenir qu'un champ ou un autre groupe de champs !"); 
     53 
    12954               } while (_node.goToNextElement()); 
    13055               ////////////////////////////////////// 
    131                _node.goToParentElement(); // Retour au parent   
     56               _node.goToParentElement(); // Retour au parent 
    13257            } 
    133                                         
    134             return; 
    13558         } 
    136           
    137          virtual ~FieldGroup(void)  
     59 
     60         virtual ~FieldGroup(void) 
    13861         {/* Ne rien faire de plus */ } 
    139                   
     62 
    14063   }; // class FieldGroup 
    141       
     64 
    14265   typedef FieldGroup FieldDefinition ; 
    143     
     66 
    14467}; // namespace XMLIOSERVER 
    145     
     68 
    14669#endif // __FIELD_GROUP__ 
    14770 
  • XMLIO_V2/dev/dev_rv/src/XMLIO/file.hpp

    r106 r107  
    66 
    77namespace XMLIOSERVER 
    8 {  
     8{ 
    99   class CFile : public ObjectTemplate<CFile>, public FileAttribut 
    1010   { 
    1111      public: 
    12        
     12 
    1313         CFile(void) : ObjectTemplate<CFile>(), FileAttribut(), vfieldGroup(NULL) 
    14                         {/* Ne rien faire de plus */}                    
    15                         CFile(const string& _id) : ObjectTemplate<CFile>(_id), FileAttribut(), vfieldGroup(NULL) 
    16          {/* Ne rien faire de plus */}   
    17           
    18          friend ostream& operator<< (ostream& out, const CFile& c)  
     14         {/* Ne rien faire de plus */} 
     15         CFile(const string& _id) : ObjectTemplate<CFile>(_id), FileAttribut(), vfieldGroup(NULL) 
     16         {/* Ne rien faire de plus */} 
     17 
     18         static string GetName(void) { return ("file"); } 
     19 
     20         void parse (XMLNode& _node) 
    1921         { 
    20              
    21             const AttributRegistrar &ar = c; 
    22             out << IncIndent << "<" << c.getName() << c.printId() << ar << ">" << std::endl;            
    23             if(c.vfieldGroup != NULL) out << *c.vfieldGroup << std::endl;                
    24             out << NIndent << "</" << c.getName()<< ">" << DecEndl; 
    25              
    26             return (out); 
    27          } 
    28                    
    29          const char* getName(void) const {return ("File"); }    
     22            string name = _node.getElementName(); 
     23            THashAttributes attributes; 
    3024 
    31                         void parse (XMLNode& _node) 
    32                         { 
    33             string name = _node.getElementName();             
    34             THashAttributes attributes; 
    35              
    3625            /// PARSING GESTION DES ATTRIBUTS /// 
    37             _node.getAttributes(attributes);   
     26            _node.getAttributes(attributes); 
    3827            this->setAttributes(attributes); 
    3928            attributes.clear(); 
    40                         
    41             /// PARSING POUR GESION DES ENFANTS 
     29 
     30            /// PARSING POUR GESION DES ENFANTS /// 
    4231            if (_node.goToChildElement() and hasId()) 
    4332            { // Si la définition du fichier intégre des champs et si le fichier est identifié. 
    44              
    4533               _node.goToParentElement(); 
    46                 
    47                vfieldGroup = (FieldGroup*)(&FieldGroup::CreateObject(getId())); 
    48                vfieldGroup->parse(_node, false); 
    49                 
    50             } else _node.goToParentElement(); 
    51              
    52             return; 
     34               vfieldGroup = CreateInstanceAndParse<FieldGroup>(attributes, _node, getId().c_str(), false ); 
     35            } 
    5336         } 
    54           
     37 
     38         virtual bool hasChild(void) const { return (vfieldGroup != NULL); } 
     39         virtual void printChild(ostream& out) const { out << *vfieldGroup << std::endl; } 
     40         virtual void resolveDescInheritance(const AttributRegistrar* _parent = 0) 
     41         { addAttributes(*_parent); if(vfieldGroup != NULL) vfieldGroup->resolveDescInheritance(); } 
     42 
    5543         FieldGroup* getVirtualFieldGroup(void) { return (vfieldGroup); } 
    56          bool  hasVirtualFieldGroup(void) { return (vfieldGroup != NULL); } 
    57           
    58          ~CFile(void)  
    59          { if(vfieldGroup != NULL) delete vfieldGroup; }  
    60           
     44 
     45         ~CFile(void) 
     46         { if(vfieldGroup != NULL) delete vfieldGroup; } 
     47 
    6148      private : 
    62        
     49 
    6350         FieldGroup* vfieldGroup; // FieldGroup "virtuel" 
    64        
    65    }; // class CFile  
    66        
     51 
     52   }; // class CFile 
     53 
    6754}; // namespace XMLIOSERVER 
    68     
     55 
    6956#endif // __CFILE__ 
  • XMLIO_V2/dev/dev_rv/src/XMLIO/file_attribut.hpp

    r106 r107  
    11#ifndef __FILE_ATTRIBUT__ 
    22#define __FILE_ATTRIBUT__ 
    3  
    4 #include "declare_attribut.hpp" 
    5 #include "attribut_registrar.hpp" 
    63 
    74namespace XMLIOSERVER 
     
    107   { 
    118      public : 
    12        
     9 
    1310         DECLARE_ATTR(name, string) ; 
    14          DECLARE_ATTR(description, string) ;       
     11         DECLARE_ATTR(description, string) ; 
    1512         DECLARE_ATTR(output_freq, int) ; 
    16          DECLARE_ATTR(output_level, int) ;               
     13         DECLARE_ATTR(output_level, int) ; 
    1714         DECLARE_ATTR(enabled, bool); 
    18              
     15 
    1916         FileAttribut(void) : AttributRegistrar() 
    2017         { registerAllAttributes(); } 
    21                           
     18 
    2219      private : 
    23        
     20 
    2421         void registerAllAttributes(void) 
    2522         { 
    2623            RegisterAttribut(&name) ; 
    27             RegisterAttribut(&description) ;       
     24            RegisterAttribut(&description) ; 
    2825            RegisterAttribut(&output_freq) ; 
    2926            RegisterAttribut(&output_level) ; 
    30             RegisterAttribut(&enabled);       
     27            RegisterAttribut(&enabled); 
    3128         } 
    32       
     29 
    3330   } ; // class FileAttribut 
    34     
     31 
    3532}// namespace XMLIOSERVER 
    3633 
  • XMLIO_V2/dev/dev_rv/src/XMLIO/file_group.hpp

    r106 r107  
    33 
    44namespace XMLIOSERVER 
    5 {    
     5{ 
    66   class FileGroup : public GroupTemplate<CFile, FileAttribut> 
    77   { 
    88      public: 
    9        
     9 
    1010         FileGroup(void) : GroupTemplate<CFile, FileAttribut>() 
    11          {/* Ne rien faire de plus */}                
     11         {/* Ne rien faire de plus */} 
    1212         FileGroup(const string& _id) : GroupTemplate<CFile, FileAttribut>(_id) 
    1313         {/* Ne rien faire de plus */} 
    14                           
    15          const char* getName(void) const {return ("File_Group"); }   
    16           
    17           
    18          /// TODO A remonter dans l'arbre des héritages 
    19          friend ostream& operator<< (ostream& out, const FileGroup& c)  
    20          {    
    21             const AttributRegistrar &ar = c; 
    22             out << IncIndent << "<" << c.getName() << c.printId() << ar << ">" << std::endl;             
    23              
    24             // Ecriture des sous-groupes. 
    25             for(unsigned int i = 0; i < c.groupList.getVector().size() ; i++) 
    26                out << *((FileGroup*)c.groupList.getVector()[i])  << std::endl; 
    27                 
    28             // Ecriture des enfants. 
    29             for(unsigned int i = 0; i < c.childList.getVector().size() ; i++) 
    30                out << *((CFile*)c.childList.getVector()[i]) << std::endl; 
    31                 
    32             out << NIndent << "</" << c.getName()<< ">" << DecEndl; 
    33              
    34             return (out); 
    35          }    
    36           
    37          /// TODO A remonter dans l'arbre des héritages    
    38          void resolveDescInheritance(const AttributRegistrar* _parent = 0) 
     14 
     15         void parse (XMLNode& _node, bool _withAttr = true) 
    3916         { 
    40             const vector<CFile*>&  childvect = childList.getVector(); 
    41             const vector<GroupTemplate<CFile, FileAttribut>*>& groupvect = groupList.getVector(); 
    42              
    43             // On complÚte les propres attributs du groupe. 
    44             if (_parent!= NULL) addAttributes(*_parent); 
    45              
    46             for(unsigned int i = 0; i < childvect.size() ; i++) 
    47             { // on complÚte les attributs des champs enfants. 
    48                childvect[i] -> addAttributes(*this); 
    49                if (childvect[i]->hasVirtualFieldGroup()) 
    50                   childvect[i]->getVirtualFieldGroup()-> resolveDescInheritance(); 
    51             } 
    52                 
    53             for(unsigned int i = 0; i < groupvect.size() ; i++) 
    54             // on complÚte les attributs des groupes de champs enfants. 
    55                ((FileGroup*)groupvect[i]) -> resolveDescInheritance(this); 
    56          } 
    57           
    58          void parse (XMLNode& _node) 
    59          { 
    60             string name = _node.getElementName();             
     17            string name = _node.getElementName(); 
    6118            THashAttributes attributes; 
    6219 
    6320            /// PARSING GESTION DES ATTRIBUTS /// 
    64             _node.getAttributes(attributes);   
    65             this->setAttributes(attributes); 
    66              
    67             if (attributes.end() != attributes.find("src")) 
    68             { // Si une demande d'inclusion de fichier est trouvé. 
    69                XMLNode _node_inc = getNodeIncludedFile(attributes["src"], name); 
    70                parse (_node_inc); 
     21            if (_withAttr) 
     22            { 
     23               _node.getAttributes(attributes); 
     24               this->setAttributes(attributes); 
     25 
     26               if (attributes.end() != attributes.find("src")) 
     27               { // Si une demande d'inclusion de fichier est trouvée. 
     28                  XMLNode _node_inc = getNodeIncludedFile(attributes["src"], name); 
     29                  parse (_node_inc); 
     30               } 
     31 
     32               attributes.clear(); 
    7133            } 
    72              
    73             attributes.clear(); 
    74                 
    75             /// PARSING POUR GESION DES ENFANTS 
     34 
     35            /// PARSING POUR GESION DES ENFANTS /// 
    7636            if (!(_node.goToChildElement())) 
    7737               WARNING("Le groupe de fichier ne contient pas d'enfant !"); 
     
    7939            { 
    8040               ////////////////////////////////////// 
    81                do { // Parcours des contexts pour traitement.  
    82                              
     41               do { // Parcours des contexts pour traitement. 
     42 
    8343                  string name = _node.getElementName(); 
    8444                  attributes.clear(); 
    85                   _node.getAttributes(attributes);   
    86                                   
    87                   if (name.compare("file_group") == 0) 
    88                   { // Parsing pour les groupes de champs 
    89                    
    90                      FileGroup* fgroup = NULL; 
    91                          
    92                      if (attributes.end() != attributes.find("id")) 
    93                      {// Si l'identifiant est défini. 
    94                         if (FileGroup::HasObject(attributes["id"])) 
    95                            WARNING("Dans le context actuel, un groupe de fichier du même nom existe déjà, le second fera référence au premier par défaut !"); // TODO TODO 
    96                         fgroup = (FileGroup*)(&createGroup(attributes["id"])); 
    97                         fgroup->parse(_node); 
    98                      } 
    99                      else 
    100                      {// Si l'identifiant n'est pas défini. 
    101                         fgroup = (FileGroup*)(&createGroup()); 
    102                         fgroup->parse(_node); 
    103                      }                         
    104                      continue; 
    105                          
    106                   } 
    107                   else if (name.compare("file") == 0) 
    108                   { // Parsing pour les champs. 
    109                    
    110                      CFile* file = NULL; 
    111                    
    112                      if (attributes.end() != attributes.find("id")) 
    113                      {// Si l'identifiant est défini. 
    114                         if (CFile::HasObject(attributes["id"])) 
    115                            WARNING("Dans le context actuel, un fichier du même nom existe déjà, le second fera référence au premier par défaut !");  // TODO TODO 
    116                         file = (CFile*)(&createChild(attributes["id"])); 
    117                         file->parse(_node); 
    118                      } 
    119                      else 
    120                      {// Si l'identifiant n'est pas défini. 
    121                         file = (CFile*)(&createChild()); 
    122                         file->parse(_node); 
    123                      }                   
    124                      continue; 
    125                   }  
    126                   else 
    127                      WARNING("Un groupe de fichiers ne peut contenir qu'un fichier ou un autre groupe de fichiers !"); 
    128                       
     45                  _node.getAttributes(attributes); 
     46 
     47                  if (name.compare(FileGroup::GetName()) == 0) 
     48                  { createGroupAndParse<FileGroup>(attributes, _node); continue; } 
     49 
     50                  if (name.compare(CFile::GetName()) == 0) 
     51                  { createChildAndParse<CFile>(attributes, _node) ; continue; } 
     52 
     53                  WARNING("Un groupe de fichiers ne peut contenir qu'un fichier ou un autre groupe de fichiers !"); 
     54 
    12955               } while (_node.goToNextElement()); 
    13056               ////////////////////////////////////// 
    131                _node.goToParentElement(); // Retour au parent   
     57               _node.goToParentElement(); // Retour au parent 
    13258            } 
    133                                         
    134             return; 
    13559         } 
    136           
    137          virtual ~FileGroup(void)  
     60 
     61         virtual ~FileGroup(void) 
    13862         {/* Ne rien faire de plus */ } 
    139                   
     63 
    14064   }; // class FileGroup 
    141       
     65 
    14266   typedef FileGroup FileDefinition ; 
    143     
     67 
    14468}; // namespace XMLIOSERVER 
    145     
     69 
    14670#endif // __FILE_GROUP__ 
    14771 
  • XMLIO_V2/dev/dev_rv/src/XMLIO/main.f90

    r79 r107  
    33 
    44 
    5   CALL main_c 
    6    
     5   CALL main_c 
     6 
    77END PROGRAM main 
  • XMLIO_V2/dev/dev_rv/src/XMLIO/main_cpp.cpp

    r106 r107  
    99void main_c_ (void) 
    1010{ 
    11         try 
    12         { 
     11   try 
     12   { 
    1313      string file("/local/XMLIOSERVER_DEV/dev_rv/test/iodef_test.xml"); 
    14        
     14 
    1515      //string file("/local/XMLIOSERVER_DEV/dev_rv/iodef_test.xml"); 
    1616      ifstream istr( file.c_str() , ifstream::in ); 
    17        
     17 
    1818      // On commence la lecture du flux de donnée xml qui doit posséder pour racine un unique noeud nommé "simulation". 
    1919      XMLNode node = XMLNode::CreateNode(istr, "simulation"); 
    2020      // On parse le fichier xml noeud par noeud (ie on construit dynamiquement notre arbre d'objets). 
    21       XMLParser::Parse(node);  
     21      XMLParser::Parse(node); 
     22 
    2223      // On résoud les héritages descendants ainsi que les héritages par référence. 
    23       XMLParser::ResolveInheritance(); 
    24        
     24      Context::ResolveInheritance(); 
     25 
    2526      // On poursuit le traitement ... 
    26        
     27 
    2728      // On écrit l'arborescence resultante du traitement sur la sortie. 
    28       XMLParser::ShowTree(std::clog); 
    29        
     29      Context::ShowTree(std::clog); 
     30 
    3031      /*std::clog << "Nombre de Contexts listés : " << Context::GetCurrentListObject().getSize() << " contre 1 attendus."<< std::endl; 
    3132      std::clog << "Nombre de FieldGroups listés : " << FieldGroup::GetCurrentListObject().getSize() << " contre 5 attendus."<< std::endl; 
    3233      std::clog << "Description du champs votkeavt : " << Field::GetObject("votkeavt").axis_ref << " contre \"Vertical Eddy Diffusivity\" attendus."<< std::endl;*/ 
    3334 
    34         } 
    35         catch(const Exception &exc) 
    36         {  // Pour tout type d'exceptions, on note les informations sur la sortie paramétrée. 
    37                 ERROR(exc.displayText());  
    38                 // On retourne le code d'erreur en fin d'application pour traitements éventuels. 
    39       //        return (exc.code()); 
    40         } 
    41        
    42 //      return (0); 
    43 }  
     35   } 
     36   catch(const Exception &exc) 
     37   {  // Pour tout type d'exceptions, on note les informations sur la sortie paramétrée. 
     38      ERROR(exc.displayText()); 
     39      // On retourne le code d'erreur en fin d'application pour traitements éventuels. 
     40      // return (exc.code()); 
     41   } 
     42 
     43// return (0); 
     44} 
  • XMLIO_V2/dev/dev_rv/src/XMLIO/xmlio_container.hpp

    r106 r107  
    11#ifndef __XMLIO_CONTAINER__ 
    2 #define __XMLIO_CONTAINER__  
     2#define __XMLIO_CONTAINER__ 
    33 
    44// Classes utilisées issues de Poco 
     
    2222   { 
    2323      public : 
     24 
    2425         ExHashMap() :  HashMap<Key, Mapped*, Hash<Key> >(), _elemList() 
    2526         {/* Ne rien faire de plus */} 
    26                 
     27 
    2728         Mapped* operator[] (const Key& kval) throw (XMLIOUndefinedValueException) 
    28          {  
     29         { 
    2930            if(!hasMappedValue(kval)) 
    3031               throw XMLIOUndefinedValueException("Appel de la méthode ExHashMap::operator["+kval+"] invalide."); 
    31             return (find(kval)->second);  
     32            return (find(kval)->second); 
    3233         } 
    33            
     34 
    3435         bool hasMappedValue(const Key& kval) {return (find(kval) != this->end());} 
    35            
    36          const vector<Mapped*>& getVector(void) const { return (this->_elemList); }          
     36 
     37         const vector<Mapped*>& getVector(void) const { return (this->_elemList); } 
    3738 
    3839         size_t getVectorSize(void) const {return (this->_elemList.size());} 
    3940         size_t getSize(void) const {return (this->size());} 
    40           
     41 
    4142         virtual ~ExHashMap() 
    4243         {/* Ne rien faire de plus */} 
    43           
     44 
    4445      protected : 
    45        
     46 
    4647         bool addValue(const Key& kval, Mapped* element) 
    4748         { 
     
    5051            return (this->addValue(element)); 
    5152         } 
    52           
     53 
    5354         bool addValue(Mapped* element) 
    54          {   this->_elemList.insert(this->_elemList.end(), element);   return (true);   }    
    55           
    56           
     55         {   this->_elemList.insert(this->_elemList.end(), element);   return (true);   } 
     56 
     57 
    5758         void removeValue(const Key& kval) // Non testé 
    5859         { Mapped* element = find(kval)->second; removeValue(element); this->erase(kval); } 
    59           
     60 
    6061         void removeValue(const Mapped* element) // Non testé 
    6162         { 
    62             for (int i = 0; i < this->_elemList.size(); i++)              
     63            for (int i = 0; i < this->_elemList.size(); i++) 
    6364               if (*this->_elemList[i] == element ) 
    6465                  this->_elemList.erase(this->_elemList.begin()+i); 
    65                    
     66 
    6667            delete element; 
    6768         } 
    68           
    69       private :    
     69 
     70      private : 
    7071         vector<Mapped*> _elemList; 
    71           
     72 
    7273   }; // class ExHashMap 
    73     
     74 
    7475   ///////////////////////////////////////////////////////////// 
    75     
     76 
    7677   template<class Mapped> 
    7778      class StrHashMap 
     
    7980   { 
    8081      public : 
    81        
    82          StrHashMap() :  ExHashMap<string, Mapped, Hash<string> >()    
    83          {/* Ne rien faire de plus */}    
    84           
     82 
     83         StrHashMap() :  ExHashMap<string, Mapped, Hash<string> >() 
     84         {/* Ne rien faire de plus */} 
     85 
    8586         bool addObject(Mapped* element) 
    8687         { if(element->hasId()) return(addValue(element->getId(), element));   return(addValue(element)); } 
    87                    
     88 
    8889         bool removeObject(const string& kval) 
    89          {  
     90         { 
    9091            if(!ExHashMap<string, Mapped, Hash<string> >::hasMappedValue(kval)) return (false); 
    91             ExHashMap<string, Mapped, Hash<string> >::removeValue(kval); return (true);  
     92            ExHashMap<string, Mapped, Hash<string> >::removeValue(kval); return (true); 
    9293         } 
    93           
    94          virtual ~StrHashMap()    
     94 
     95         virtual ~StrHashMap() 
    9596         {/* Ne rien faire de plus */} 
    96           
     97 
    9798   }; // class StrHashMap 
    98              
     99 
    99100}; // namespace XMLIOSERVER 
    100101 
    101 #endif // __XMLIO_CONTAINER__  
     102#endif // __XMLIO_CONTAINER__ 
  • XMLIO_V2/dev/dev_rv/src/XMLIO/xmlio_group_template.hpp

    r106 r107  
    11#ifndef __XMLIO_GROUP_TEMPLATE__ 
    2 #define __XMLIO_GROUP_TEMPLATE__  
     2#define __XMLIO_GROUP_TEMPLATE__ 
    33 
    44namespace XMLIOSERVER 
     
    88   { 
    99      public: 
    10              
     10 
    1111         GroupTemplate(void) : ObjectTemplate<GroupTemplate<T, U> >(),  U(), childList(), groupList() 
    12          {/* Ne rien faire de plus */}                
     12         {/* Ne rien faire de plus */} 
    1313         GroupTemplate(const string& _id) : ObjectTemplate<GroupTemplate<T, U> >(_id), U(), childList(), groupList() 
    14          {/* Ne rien faire de plus */}             
    15            
     14         {/* Ne rien faire de plus */} 
     15 
    1616         /// Pour les groupes d'objets enfants /// 
    17           
    18          GroupTemplate<T, U>& createGroup(const string _id) throw (XMLIOUndefinedValueException)  
     17 
     18         static string GetName(void) {return (T::GetName().append("_group")); } 
     19         static string GetDefName(void) {return (T::GetName().append("_definition")); } 
     20 
     21         virtual bool hasChild(void) const { return ((getNbGroup() + getNbChild())>0); } 
     22         virtual void printChild(ostream& out) const 
     23         { 
     24            // Ecriture des sous-groupes. 
     25            for(unsigned int i = 0; i < groupList.getVector().size() ; i++) 
     26               out << *(groupList.getVector()[i])  << std::endl; 
     27            // Ecriture des enfants. 
     28            for(unsigned int i = 0; i < childList.getVector().size() ; i++) 
     29               out << *(childList.getVector()[i]) << std::endl; 
     30         } 
     31 
     32         virtual void resolveDescInheritance(const AttributRegistrar* _parent = 0) 
     33         { 
     34            const vector<T*>&  childvect = childList.getVector(); 
     35            const vector<GroupTemplate<T, U>*>& groupvect = groupList.getVector(); 
     36 
     37            // On complÚte les propres attributs du groupe. 
     38            if (_parent!= NULL) AttributRegistrar::addAttributes(*_parent); 
     39 
     40            for(unsigned int i = 0; i < childvect.size() ; i++) 
     41            // on complÚte les attributs des enfants. 
     42               childvect[i] -> resolveDescInheritance(this); 
     43            for(unsigned int i = 0; i < groupvect.size() ; i++) 
     44            // on complÚte les attributs des groupes enfants. 
     45               groupvect[i] -> resolveDescInheritance(this); 
     46         } 
     47 
     48         GroupTemplate<T, U>& createGroup(const string _id) throw (XMLIOUndefinedValueException) 
    1949         { 
    2050            GroupTemplate<T, U> &obj = GroupTemplate<T, U>::CreateObject(_id); 
    2151            groupList.addObject(&obj); 
    22                
     52 
    2353            return (GroupTemplate<T, U>::GetObject(_id)); 
    2454         } 
    25           
    26          XML::XMLNode getNodeIncludedFile(const string& path, const string& _rootName) 
    27          { 
    28             ifstream istr( path.c_str() , ifstream::in ); 
    29             return XML::XMLNode::CreateNode(istr, _rootName); 
    30          } 
    31           
     55 
    3256         GroupTemplate<T, U>& createGroup(void) 
    3357         { 
    3458            GroupTemplate<T, U>& obj = GroupTemplate<T, U>::CreateObject(); 
    3559            groupList.addObject(&obj); 
    36                       
     60 
    3761            return (obj); 
    3862         } 
    39           
     63 
    4064         GroupTemplate<T, U>& getGroup(const string _id) throw (XMLIOUndefinedValueException) { return (*groupList[_id]); } 
    4165         bool hasGroup(const string _id) { return (groupList.hasMappedValue(_id)); } 
    42           
     66 
    4367         const StrHashMap<GroupTemplate<T, U>* >& getGroupList(void) { return (groupList); } 
    44           
     68 
    4569         size_t getNbGroup() const {return (groupList.getVectorSize()); } 
    46           
     70 
    4771         /// Pour les objets enfants /// 
    48           
    49          T& createChild(const string _id) throw (XMLIOUndefinedValueException)  
     72 
     73         T& createChild(const string _id) throw (XMLIOUndefinedValueException) 
    5074         { 
    5175            T& obj = ObjectTemplate<T>::CreateObject(_id); 
     
    5377            return (obj); 
    5478         } 
    55           
     79 
    5680         T& createChild(void) 
    5781         { 
    5882            T& obj = ObjectTemplate<T>::CreateObject(); 
    59             childList.addObject(&obj);             
     83            childList.addObject(&obj); 
    6084            return (obj); 
    61          }          
    62           
     85         } 
     86 
    6387         T& getChild(const string _id) throw (XMLIOUndefinedValueException) { return (*childList[_id]); } 
    6488         bool hasChild(const string _id) { return (childList.hasMappedValue(_id)); } 
    65           
     89 
    6690         const StrHashMap<T*>& getCurrentListChild(void) { return (childList); } 
    67           
     91 
    6892         size_t getNbChild() const {return (childList.getVectorSize()); } 
    69              
    70          
     93 
    7194         virtual ~GroupTemplate() 
    7295         { 
     
    7699               delete groupList.getVector()[i]; 
    77100         } 
    78           
     101 
    79102      protected: 
    80        
     103 
     104         template <class V> V* createGroupAndParse(THashAttributes& attributes, XMLNode& _node) 
     105         { 
     106            V* instance_ptr = NULL; 
     107            if (attributes.end() != attributes.find("id")) 
     108            {// Si l'identifiant est défini. 
     109               if (V::HasObject(attributes["id"])) 
     110                  WARNING("Dans le context actuel, une instance de type "+V::GetName()+" nommée "+attributes["id"]+" existe déjà, le second fera référence au premier par défaut !"); // TODO TODO 
     111               instance_ptr = (V*)(&createGroup(attributes["id"])); 
     112               instance_ptr->parse(_node); 
     113            } 
     114            else 
     115            {// Si l'identifiant n'est pas défini. 
     116               instance_ptr = (V*)(&createGroup()); 
     117               instance_ptr->parse(_node); 
     118            } 
     119            return (instance_ptr); 
     120         } 
     121 
     122         template <class V> V* createChildAndParse(THashAttributes& attributes, XMLNode& _node) 
     123         { 
     124            V* instance_ptr = NULL; 
     125            if (attributes.end() != attributes.find("id")) 
     126            {// Si l'identifiant est défini. 
     127               if (V::HasObject(attributes["id"])) 
     128                  WARNING("Dans le context actuel, une instance de type "+V::GetName()+" nommée "+attributes["id"]+" existe déjà, le second fera référence au premier par défaut !"); // TODO TODO 
     129               instance_ptr = (V*)(&createChild(attributes["id"])); 
     130               instance_ptr->parse(_node); 
     131            } 
     132            else 
     133            {// Si l'identifiant n'est pas défini. 
     134               instance_ptr = (V*)(&createChild()); 
     135               instance_ptr->parse(_node); 
     136            } 
     137            return (instance_ptr); 
     138         } 
     139 
    81140         StrHashMap<T> childList; 
    82141         StrHashMap<GroupTemplate<T, U> > groupList; 
    83142 
    84143   }; // class GroupTemplate 
    85     
    86     
    87     
     144 
     145 
     146 
    88147}// namespace XMLIOSERVER 
    89148 
  • XMLIO_V2/dev/dev_rv/src/XMLIO/xmlio_object_template.hpp

    r104 r107  
    11#ifndef __XMLIO_OBJECT_TEMPLATE__ 
    2 #define __XMLIO_OBJECT_TEMPLATE__  
     2#define __XMLIO_OBJECT_TEMPLATE__ 
     3 
     4#include "declare_attribut.hpp" 
     5#include "attribut_registrar.hpp" 
    36 
    47// Classes utilisées issues de la STL 
     
    811 
    912using XMLIOSERVER::StrHashMap; 
    10     
     13 
     14using XMLIOSERVER::XML::XMLNode; 
     15using XMLIOSERVER::XML::THashAttributes; 
     16 
    1117namespace XMLIOSERVER 
    1218{ 
    1319   template <class T> 
    14       class ObjectTemplate : public AbstractObject 
     20      class ObjectTemplate : public AbstractObject, public virtual AttributRegistrar 
    1521   { 
    1622      public : 
    17           
    18          static T& CreateObject(const string _id) throw (XMLIOUndefinedValueException)  
     23 
     24 
     25         friend ostream& operator<< (ostream& out, const T& c) 
     26         { 
     27            const AttributRegistrar &ar = c; 
     28            if (c.hasChild()) 
     29            { 
     30               out << IncIndent  << "<" << c.getName()   << c.printId() << ar << ">" << std::endl; 
     31               c.printChild(out); // << Ecriture des objets enfants ici. 
     32               out << NIndent    << "</" << c.getName()  << ">" << DecEndl; 
     33            } 
     34            else out << IncIndent << "<" << c.getName()  << c.printId() << ar << "/>" << DecEndl; 
     35 
     36            return (out); 
     37         } 
     38 
     39         string getName(void) const {return (T::GetName()); } 
     40 
     41         virtual bool hasChild(void) const { return (false); } 
     42         virtual void printChild(ostream& out) const { /* Ne rien faire de plus */ } 
     43         virtual void resolveDescInheritance(const AttributRegistrar* _parent = 0) { addAttributes(*_parent); } 
     44 
     45         static T& CreateObject(const string _id) throw (XMLIOUndefinedValueException) 
    1946         { 
    2047            // Si l'identifiant est répertorié, on retourne l'élément existant. 
    2148            if(ObjectTemplate<T>::HasObject(_id)) 
    2249               return (ObjectTemplate<T>::GetObject(_id)); 
    23                                
    24             // Ajout d'un nouvel objet si l'identifiant n'est pas répertorié.            
     50 
     51            // Ajout d'un nouvel objet si l'identifiant n'est pas répertorié. 
    2552            ObjectTemplate<T>::AllListObj[CurrContext].addObject(new T(_id)); 
    26              
     53 
    2754            return (ObjectTemplate<T>::GetObject(_id)); 
    2855         } 
    29           
     56 
    3057         static T& CreateObject(void) 
    3158         { 
     
    3461            return (*value); 
    3562         } 
    36           
     63 
    3764         static T& GetObject(const string _id) throw (XMLIOUndefinedValueException) 
    3865         { return (*ObjectTemplate<T>::AllListObj[CurrContext][_id]); } 
    39           
     66 
    4067         static bool HasObject(const string _id) 
    4168         { 
     
    4370            return (ObjectTemplate<T>::AllListObj[CurrContext].hasMappedValue(_id)); 
    4471         } 
    45           
     72 
    4673         static const StrHashMap<T>& GetCurrentListObject(void) { return (AllListObj[CurrContext]); } 
    4774         static HashMap<string, StrHashMap<T> >& GetAllListObject(void) { return (AllListObj); } 
    48                  
    49          static void SetContext(const string& id){ ObjectTemplate<T>::CurrContext = id; }  
    50           
    51          static string& GetCurrentContextId(void) { return (CurrContext); }  
    52           
     75 
     76         static void SetContext(const string& id){ ObjectTemplate<T>::CurrContext = id; } 
     77 
     78         static string& GetCurrentContextId(void) { return (CurrContext); } 
     79 
    5380         virtual ~ObjectTemplate(void) 
    5481         {/* Ne rien faire de plus */} 
    55           
     82 
    5683      protected : 
    57        
     84 
    5885         ObjectTemplate(void) : AbstractObject() 
    59          {/* Ne rien faire de plus */}          
    60          ObjectTemplate(const string& _id) : AbstractObject(_id)  
    6186         {/* Ne rien faire de plus */} 
    62           
     87         ObjectTemplate(const string& _id) : AbstractObject(_id) 
     88         {/* Ne rien faire de plus */} 
     89 
     90         XML::XMLNode getNodeIncludedFile(const string& path, const string& _rootName) 
     91         { 
     92            ifstream istr( path.c_str() , ifstream::in ); 
     93            return XML::XMLNode::CreateNode(istr, _rootName); 
     94         } 
     95 
     96         template <class V> static V* CreateInstanceAndParse( THashAttributes& attributes, XMLNode& _node, const char* defaultId, bool parseAttr = true ) 
     97         { 
     98            V* instance_ptr = NULL; string did(defaultId); 
     99            if (defaultId != NULL) 
     100            { 
     101               if (V::HasObject(did)) 
     102                  WARNING("Le noeud nommé "+ did +" existe déjà pour les instances de type "+V::GetName()+", le dernier défini complétera le premier dans le context actuel!"); 
     103               instance_ptr = (V*)&V::CreateObject(did); 
     104               instance_ptr->parse(_node, parseAttr); 
     105            } 
     106            return (instance_ptr); 
     107         } 
     108 
    63109      private : 
    64           
     110 
    65111         static string CurrContext; 
    66112         static HashMap<string, StrHashMap<T> > AllListObj; 
    67        
     113 
    68114   };// class ObjectTemplate 
    69     
     115 
    70116   template <class T> string ObjectTemplate<T>::CurrContext ; 
    71117   template <class T> HashMap<string, StrHashMap<T> > ObjectTemplate<T>::AllListObj; 
    72     
     118 
    73119}// namespace XMLIOSERVER 
    74     
    75 #endif // __XMLIO_OBJECT_TEMPLATE__  
     120 
     121#endif // __XMLIO_OBJECT_TEMPLATE__ 
  • XMLIO_V2/dev/dev_rv/src/XMLIO/xmlio_xml_node.hpp

    r106 r107  
    11#ifndef __XMLIO_XML_NODE__ 
    2 #define __XMLIO_XML_NODE__  
     2#define __XMLIO_XML_NODE__ 
    33 
    44// Entêtes Poco DOM 
     
    4444   namespace XML 
    4545   { 
    46        
     46 
    4747      typedef HashMap<string, string> THashAttributes; 
    48           
    49       // TODO Mettre des auto_ptr ici car gestion de la mémoire lamentable sans. 
    50       typedef AutoPtr<Document> PDocument; 
    51       typedef Node*    PNode; 
    52           
     48 
    5349      class XMLNode 
    5450      { 
    5551         public : 
    56              
    57             XMLNode(const string& _rootName) : rootName(_rootName)  
    58             { /* Ne rien faire de plus */}           
     52 
     53            XMLNode(const string& _rootName) : rootName(_rootName) 
     54            { /* Ne rien faire de plus */} 
    5955 
    6056            static XMLNode CreateNode(istream& _istr, const string& _rootName = string("simulation")) 
     
    6561                  InputSource src(_istr); 
    6662                  DOMParser parser; 
    67                       
     63 
    6864                  // On parse la source XML et on vérifie que le premier noeud (racine) est du type "Element" 
    6965                  // ... et à pour valeur la chaîne rootName. 
     
    7268                  { node.setCNode(node.pDoc->documentElement()); } 
    7369                  else 
    74                   { 
    75                      ostringstream oss; 
    76                      oss << "L'élément racine doit avoir pour valeur <" << _rootName << "> (\"" <<  (node.pDoc->documentElement()->nodeName()) <<"\" lue)"; 
    77                      throw XMLParsingException(oss.str()); 
    78                   }     
     70                     throw XMLParsingException("L'élément racine doit avoir pour valeur <" + _rootName + "> (\"" + (node.pDoc->documentElement()->nodeName()) + "\" lue)"); 
    7971               } 
    8072               else 
    8173                  throw XMLIOStreamException("Impossible de lire le flux en entrée pour le parsing XML !"); 
    82                    
     74 
    8375               return (node); 
    8476            } 
    85                 
     77 
    8678            string getElementName(void) const {return (this->getCNode()->nodeName());} 
    87                  
    88             bool goToNextElement(void)  
     79 
     80            bool goToNextElement(void) 
    8981            { 
    90                PNode nextElement = this->getCNode()->nextSibling(); 
    91                
     82               Node* nextElement = this->getCNode()->nextSibling(); 
     83 
    9284               // On parcourt la liste des "siblings" jusqu'à trouver un élément quelconque. 
    9385               for(; ; nextElement = nextElement->nextSibling()) 
     
    9789                     this->setCNode(nextElement) ; 
    9890                     return (true); 
    99                   }  
     91                  } 
    10092               return (false); 
    10193            } 
    102               
     94 
    10395            bool goToChildElement(void) 
    10496            { 
    105                PNode nextElement = this->getCNode()->firstChild(); 
    106                 
     97               Node* nextElement = this->getCNode()->firstChild(); 
     98 
    10799               // On parcourt la liste des enfants jusqu'à trouver un élément quelconque. 
    108100               if (!IsPtrNull(nextElement)) 
     
    117109                  return (false); 
    118110               } 
    119                  
     111 
    120112               return (false); 
    121113            } 
    122               
     114 
    123115            bool goToParentElement(void) 
    124             {  
     116            { 
    125117               // Pas de retour au parent si on est à la racine. 
    126118               if (!(this->getElementName().compare(rootName))) return (false); 
     
    128120               return (true); 
    129121            } 
    130               
     122 
    131123            bool getAttributes(THashAttributes& attributes) const 
    132124            { 
    133                  
     125 
    134126               if(!this->getCNode()->hasAttributes()) return (false); 
    135127               AutoPtr<NamedNodeMap> map = this->getCNode()->attributes(); 
    136                
     128 
    137129               for(unsigned int i = 0; i< map->length(); i++) 
    138130                  attributes[map->item(i)->nodeName()] = map->item(i)->nodeValue(); 
     
    140132               return (true); 
    141133            } 
    142              
    143             ~XMLNode()  
     134 
     135            ~XMLNode() 
    144136            { /* Ne rien faire de plus */ } 
    145              
     137 
    146138         protected : 
    147           
    148             PNode getCNode(void) const {return (this->cNode); } 
    149             void setCNode(PNode other) { this->cNode = other; } 
    150              
    151             static bool IsPtrNull(PNode ptr) {return (ptr==NULL);} 
    152              
     139 
     140            Node* getCNode(void) const {return (this->cNode); } 
     141            void setCNode(Node* other) { this->cNode = other; } 
     142 
     143            static bool IsPtrNull(Node* ptr) {return (ptr==NULL);} 
     144 
    153145         private : 
    154             PDocument pDoc;  
    155             PNode  cNode; 
    156              
    157             string rootName;       
    158           
     146            AutoPtr<Document> pDoc; 
     147            Node*  cNode; 
     148 
     149            string rootName; 
     150 
    159151      };// class XMLNode 
    160        
     152 
    161153         }; // namespace XML 
    162154 
     
    164156 
    165157 
    166 #endif // __XMLIO_XML_NODE__  
     158#endif // __XMLIO_XML_NODE__ 
  • XMLIO_V2/dev/dev_rv/src/XMLIO/xmlio_xml_parser.hpp

    r106 r107  
    11#ifndef __XMLIO_XML_PARSER__ 
    2 #define __XMLIO_XML_PARSER__  
     2#define __XMLIO_XML_PARSER__ 
    33 
    44#include <stdlib.h> 
     
    1010{ 
    1111   namespace XML 
    12    {           
     12   { 
    1313      using XMLIOSERVER::Context; 
    14        
     14 
    1515      class XMLParser 
    1616      { 
    17          public :  
    18           
     17         public : 
     18 
    1919            static void Parse(XMLNode& _node) 
    2020            { 
    2121               THashAttributes attributes; 
    22                 
     22 
    2323               _node.goToChildElement(); // On se place sur le premier élément enfant du noeud racine. 
    24                atexit (&XMLParser::FreeMemory); // Pour supprimer la mémoire liée à l'allocation dynamique en fin d'exécution du programme.   
     24               atexit (&Context::FreeMemory); // Pour supprimer la mémoire liée à l'allocation dynamique en fin d'exécution du programme. 
    2525 
    26                                
    27                do {                 
     26               do { 
    2827                 // Traitement de l'identifiant 
    2928                  _node.getAttributes(attributes); 
    30                              
     29 
    3130                  if (attributes.end() == attributes.find("id")) 
    3231                  { WARNING("Le context ne sera pas traité car il n'est pas identifié !"); continue; } 
    33                    
     32 
    3433                  if( Context::HasObject(attributes["id"])) 
    3534                  { WARNING("Le context ne sera pas traité car il existe déjà un autre context possédant le même nom !"); continue; } 
    36                    
     35 
    3736                  Context::SetCurrentContext(attributes["id"]); 
    3837                  Context& context = Context::CreateObject(attributes["id"]); 
    39                    
     38 
    4039                  context.parse(_node); 
    4140                  attributes.clear(); 
    42                    
    43                } while (_node.goToNextElement());                
     41 
     42               } while (_node.goToNextElement()); 
    4443            } 
    45              
    46             static void ResolveInheritance(void) 
    47             { 
    48                HashMap<string, StrHashMap<Context> > &AllListContext = Context::GetAllListObject(); 
    49                 
    50                for (HashMap<string, StrHashMap<Context> >::Iterator it = AllListContext.begin(); it != AllListContext.end(); it++) 
    51                { 
    52                   string& id = (*it).first; 
    53                   StrHashMap<Context>& sc = (*it).second; 
    54                    
    55                   // Résolution des héritages des descendands (càd des héritages de groupes) pour chacun des contextes. 
    56                   sc[id]->resolveDescInheritance(); 
    57                }                
    58             } 
    59              
    60             static void ShowTree(ostream& os = std::clog) 
    61             { 
    62                clog <<  "<?xml version=\"1.0\"?>" << std::endl; 
    63                clog <<  "<Simulation>" << std::endl; 
    64                HashMap<string, StrHashMap<Context> > &AllListContext = Context::GetAllListObject(); 
    65                 
    66                for (HashMap<string, StrHashMap<Context> >::Iterator it = AllListContext.begin(); it != AllListContext.end(); it++) 
    67                { 
    68                   string& id = (*it).first; 
    69                   StrHashMap<Context>& sc = (*it).second; 
    70                    
    71                   // On sort chacun des contextes successivement. 
    72                   clog << *sc[id] << std::endl; 
    73                }  
    74                clog << "</Simulation>" << std::endl  ; 
    75             } 
    76              
    77             static void FreeMemory(void) 
    78             { 
    79                HashMap<string, StrHashMap<Context> > &AllListContext = Context::GetAllListObject(); 
    80                 
    81                for (HashMap<string, StrHashMap<Context> >::Iterator it = AllListContext.begin(); it != AllListContext.end(); it++) 
    82                { 
    83                   string& id = (*it).first; 
    84                   StrHashMap<Context>& sc = (*it).second; 
    85                   Context::SetCurrentContext(id); 
    86                   delete sc[id]; 
    87                } 
    88             } 
    89                   
    90       }; // class XMLParser      
     44      }; // class XMLParser 
    9145   }; // namespace XML 
    9246 
     
    9448 
    9549 
    96 #endif // __XMLIO_XML_PARSER__  
     50#endif // __XMLIO_XML_PARSER__ 
Note: See TracChangeset for help on using the changeset viewer.