Changeset 98


Ignore:
Timestamp:
06/04/10 16:18:34 (14 years ago)
Author:
ymipsl
Message:
 
Location:
XMLIO_V2/dev/trunk/src/XMLIO
Files:
11 added
10 deleted
9 edited

Legend:

Unmodified
Added
Removed
  • XMLIO_V2/dev/trunk/src/XMLIO/attribut.hpp

    r79 r98  
    1 #ifndef ATTRIBUT_HPP 
    2 #define ATTRIBUT_HPP 
     1#ifndef __ATTRIBUT__ 
     2#define __ATTRIBUT__ 
    33 
    44#include "base_attribut.hpp" 
    5 #include "xmlio_std.hpp" 
    65 
    7 template <class Ctype> 
    8 class CAttribut : public CBaseAttribut 
     6using XMLIOSERVER::BaseAttribut; 
     7using XMLIOSERVER::XMLIOUndefinedValueException; 
     8using std::ostringstream; 
     9 
     10namespace XMLIOSERVER 
    911{ 
    10   public : 
    11    
    12   bool hasValue ; 
    13   Ctype value ; 
    14  
    15   virtual const char * getName(void) const = 0 ; 
    16   CAttribut(void) : hasValue(false) {} ; 
    17   CAttribut(const Ctype& value_) : value(value_), hasValue(true) {} ; 
    18   CAttribut(const CAttribut& attr) : hasValue(attr.hasValue)  
    19   { 
    20      if (hasValue) value=attr.value ; 
    21   } ; 
    22  
    23   CAttribut& operator = (const CAttribut & attr) 
    24   {  
    25      hasValue=attr.hasValue ; 
    26      if (hasValue) value=attr.value ; 
    27      return *this ;  
    28   } ; 
    29  
    30   operator Ctype() 
    31   { 
    32     if (!hasValue) error("CAttribut& CAttribut<Ctype>::operator Ctype")<<"access to undefined value of attribut <<" 
    33                                                                        <<this->getName()<<">>"<<endl; 
    34     return value ; 
    35   } ; 
    36  
    37   virtual ostream& print(ostream & o) const 
    38   { 
    39     o<<"Attribut : "<<getName()<<"  ---->" ; 
    40     if (hasValue) o<<" value = "<<value ; 
    41     else o<<" undefined value" ; 
    42     return o ; 
    43   } 
    44  
    45   virtual void setValue(const Ctype & value_) 
    46   { 
    47      hasValue=true ; 
    48      value=value_ ; 
    49   } 
    50  
    51   virtual void getValue(Ctype & value_) const 
    52   { 
    53     if (!hasValue)  error("void CAttribut<Ctype>::getValue")<<"access to undefined value of attribut <<" 
    54                                                                <<this->getName()<<">>"<<endl; 
    55     value_=value ; 
    56   } 
    57  
    58 } ; 
     12   class IStringStream_alt 
     13   { 
     14      public :  
     15         IStringStream_alt(const std::string& str) : iss(str) 
     16         { /* Ne rien faire de plus */} 
     17          
     18         istream& operator>> (std::string& s) {s.assign(this->iss.str()); return (this->iss);} 
     19         istream& operator>> (int& s) { return (iss>>s); } 
     20         istream& operator>> (bool& s) 
     21         { 
     22            if(!this->iss.str().compare(string(".TRUE."))) s =  true; 
     23            else s = false; 
     24            return (this->iss); 
     25         } 
     26          
     27      private :  
     28         istringstream iss; 
     29          
     30   }; // class IStringStream_alt 
    5931 
    6032 
     33   template <class Ctype> 
     34      class Attribut : public BaseAttribut 
     35   { 
     36      public : 
     37      
     38         bool hasValue ; 
     39         Ctype value ; 
     40 
     41         virtual const char * getName(void) const = 0 ; 
     42       
     43         Attribut(void) : hasValue(false) {} ; 
     44         Attribut(const Ctype& value_) : hasValue(true), value(value_) {} ; 
     45          
     46         Attribut(const Attribut& attr) : hasValue(attr.hasValue)  
     47         {  if (hasValue) value=attr.value ; } 
     48 
     49         Attribut& operator = (const Attribut & attr) 
     50         {  
     51            hasValue=attr.hasValue ; 
     52            if (hasValue) value=attr.value ; 
     53            return *this ;  
     54         } 
     55      
     56         virtual const char * getType(void) const = 0; 
     57      
     58         virtual void setFromString(const std::string str)  
     59         {     
     60            IStringStream_alt iss(str); Ctype val; 
     61            iss >> val; 
     62            this->setValue(val); 
     63         }    
     64 
     65         operator Ctype() 
     66         { 
     67            if (!hasValue) 
     68            { 
     69               ostringstream oss; 
     70               oss << "CAttribut& CAttribut<Ctype>::operator Ctype , access to undefined value of attribut <<" << this->getName() <<">>"; 
     71                                                                           
     72               throw XMLIOUndefinedValueException(oss.str()); 
     73            } 
     74            return value ; 
     75         } 
     76 
     77         virtual ostream& print(ostream & o) const 
     78         { 
     79            o<<"Attribut : "<<getName()<<"  ---->" ; 
     80            if (hasValue) o<< boolalpha <<" value = "<< value ; 
     81            else o<< "/" ; 
     82            return o ; 
     83         } 
     84 
     85         virtual void setValue(const Ctype & value_) 
     86         { hasValue=true ; value=value_ ; } 
     87 
     88         virtual void getValue(Ctype & value_) const 
     89         { 
     90            if (!hasValue) 
     91            { 
     92               ostringstream oss; 
     93               oss << "CAttribut& CAttribut<Ctype>::operator Ctype , access to undefined value of attribut <<" << this->getName() <<">>"; 
     94                                                                           
     95               throw XMLIOUndefinedValueException(oss.str()); 
     96            } 
     97            value_=value ; 
     98         } 
     99 
     100   }; // class Attribut  
     101}; // namespace XMLIOSERVER 
    61102   
    62 #endif 
     103#endif //__ATTRIBUT__ 
  • XMLIO_V2/dev/trunk/src/XMLIO/attribut_registrar.hpp

    r79 r98  
    1 #ifndef ATTRIBUT_REGISTRAR_HPP 
    2 #define ATTRIBUT_REGISTRAR_HPP 
     1#ifndef __ATTRIBUT_REGISTRAR__ 
     2#define __ATTRIBUT_REGISTRAR__ 
    33 
    4 #include "base_attribut.hpp" 
    5 #include "xmlio_std.hpp" 
     4#include "attribut.hpp" 
    65 
    7 class CAttributRegistrar 
     6namespace XMLIOSERVER 
    87{ 
    9   public : 
    10    
    11    
    12   void RegisterAttribut(CBaseAttribut & attribut) ; 
    13   ostream & PrintAttribut(ostream & o) ; 
     8   class AttributRegistrar 
     9   { 
     10      public : 
     11         
     12         AttributRegistrar():attrList() 
     13         {/* Ne rien faire de plus */} 
     14       
     15         void RegisterAttribut(BaseAttribut* attribut){ attrList.addObject(attribut); }          
     16         StrHashMap<BaseAttribut>& getAttributList(void) { return (attrList); }          
     17         size_t getNbAttributes() const {return (attrList.getSize()); } 
     18         bool hasAttribut(const string _id) { return (attrList.hasMappedValue(_id)); } 
     19          
     20         BaseAttribut* getAttribut(const string _id) throw (XMLIOUndefinedValueException) { return (attrList[_id]); } 
     21         
     22         void setSAttribut(const string& att_name, const std::string& value) 
     23         { 
     24            //std::cout << "Attribut :" <<  att_name<< ", " << value<< std::endl; 
    1425 
    15   unordered_map<string,CBaseAttribut *> attrMap ; 
    16   vector<CBaseAttribut *> attrVector ; 
    17  
    18   bool hasAttribut(const string& att_name) 
    19   { 
    20     if (attrMap.find(att_name)!=attrMap.end()) return true ; 
    21     else return false ; 
    22   } 
    23    
    24   template <class ValueType> 
    25   void setAttribut(const string& att_name, ValueType value) 
    26   { 
    27     unordered_map<string,CBaseAttribut *>::iterator it ; 
    28      
    29     it=attrMap.find(att_name) ; 
    30     if (it!=attrMap.end()) (*it).second->setValue(value) ; 
    31     else error("CAttributRegistrar::setAttribut<ValueType>") 
    32          <<"Could not find <<"<<att_name<<">> attribut in registred list"<<endl ; 
    33      
    34   } 
    35    
    36 } ; 
    37  
    38 inline void CAttributRegistrar::RegisterAttribut(CBaseAttribut& Attribut) 
    39 { 
    40   attrMap.insert(make_pair(Attribut.getName(),&Attribut)) ; 
    41   attrVector.push_back(&Attribut) ; 
    42 } 
    43  
    44 inline ostream & CAttributRegistrar::PrintAttribut(ostream& o) 
    45 { 
    46   vector<CBaseAttribut *>::iterator it ; 
    47   o<<"List of attribut"<<IncIndent ; 
    48   for(it=attrVector.begin(); it!=attrVector.end();it++) 
    49   { 
    50     o<<iendl ; 
    51     (*it)->print(o) ; 
    52   } 
    53   o<<DecIndent ; 
    54   return o ; 
    55 } 
     26            if (hasAttribut(att_name)) 
     27            { getAttribut(att_name)->setFromString(value) ; } 
     28            else 
     29            { 
     30               ostringstream oss; 
     31               oss << "CAttributRegistrar::setAttribut<ValueType>, could not find <<" << att_name <<">> attribut in registred list" <<">>"; 
     32               throw XMLIOUndefinedValueException(oss.str()); 
     33            }          
     34         } 
     35          
     36         friend ostream& operator<< (ostream& out, const AttributRegistrar& c)  
     37         { out << c.toString(); return (out);}    
     38                
     39      protected : 
     40       
     41         string toString(void) const 
     42         { 
     43            ostringstream st("A réimplémenter"); 
     44            // A compléter 
     45            return (st.str()); 
     46         } 
     47          
     48      public : 
     49          
     50        ~AttributRegistrar(void) 
     51        {/* Ne rien faire de plus */} 
     52         
     53      private : 
     54         StrHashMap<BaseAttribut> attrList; 
     55         
     56   }; // class AttributRegistrar   
     57}; // namespace XMLIOSERVER 
    5658 
    5759 
    58 #endif 
     60#endif //__ATTRIBUT_REGISTRAR__ 
  • XMLIO_V2/dev/trunk/src/XMLIO/base_attribut.hpp

    r79 r98  
    1 #ifndef BASE_ATTRIBUT_HPP 
    2 #define BASE_ATTRIBUT_HPP 
    3 #include "xmlio_std.hpp" 
     1#ifndef __BASE_ATTRIBUT__ 
     2#define __BASE_ATTRIBUT__ 
    43 
    5 class CBaseAttribut 
    6 { 
    7   public: 
    8    
    9   virtual const char * getName(void) const = 0  ; 
    10       
    11   virtual ostream & print(ostream& o) const = 0  ; 
    12    
    13   friend ostream& operator <<(ostream& o,const CBaseAttribut& Attr) 
    14   { 
    15     return Attr.print(o) ; 
    16   } 
    17  
    18    
    19   virtual void setValue(const int & value)          { error_set() ; } 
    20   virtual void setValue(const Array<int,1>& value)  { error_set() ; } 
    21   virtual void setValue(const Array<int,2>& value)  { error_set() ; } 
    22   virtual void setValue(const Array<int,3>& value)  { error_set() ; } 
    23    
    24   virtual void setValue(const double & value)          { error_set() ; } 
    25   virtual void setValue(const Array<double,1>& value)  { error_set() ; } 
    26   virtual void setValue(const Array<double,2>& value)  { error_set() ; } 
    27   virtual void setValue(const Array<double,3>& value)  { error_set() ; } 
    28    
    29   virtual void setValue(const bool & value)          { error_set() ; } 
    30   virtual void setValue(const Array<bool,1>& value)  { error_set() ; } 
    31   virtual void setValue(const Array<bool,2>& value)  { error_set() ; } 
    32   virtual void setValue(const Array<bool,3>& value)  { error_set() ; } 
    33    
    34   virtual void setValue(const char * value)            { error_set() ; } 
    35   virtual void setValue(const string & value)          { error_set() ; } 
    36   virtual void setValue(const Array<string,1>& value)  { error_set() ; } 
    37   virtual void setValue(const Array<string,2>& value)  { error_set() ; } 
    38   virtual void setValue(const Array<string,3>& value)  { error_set() ; } 
    39    
    40   virtual void setValue(const char & value)          { error_set() ; } 
    41   virtual void setValue(const Array<char,1>& value)  { error_set() ; } 
    42   virtual void setValue(const Array<char,2>& value)  { error_set() ; } 
    43   virtual void setValue(const Array<char,3>& value)  { error_set() ; } 
     4using std::ostream; 
     5using namespace blitz ; 
    446 
    457 
    46   virtual void getValue(int & value) const        { error_get() ; } 
    47   virtual void getValue(Array<int,1>& value) const  { error_get() ; } 
    48   virtual void getValue(Array<int,2>& value) const  { error_get() ; } 
    49   virtual void getValue(Array<int,3>& value) const  { error_get() ; } 
     8using XMLIOSERVER::XMLIOIncompatibeTypeException; 
     9 
     10namespace XMLIOSERVER 
     11{ 
     12   class BaseAttribut 
     13   { 
     14     public: 
     15      
     16     virtual const char * getName(void) const = 0  ; 
     17         
     18     virtual ostream & print(ostream& o) const = 0  ; 
     19      
     20     friend ostream& operator <<(ostream& o,const BaseAttribut& Attr) 
     21     {return Attr.print(o) ; } 
     22      
     23     virtual const char * getId(void) {return getName();} ; 
     24     bool hasId(void){return (true);} 
     25 
     26     virtual void setFromString(const std::string str) = 0; 
     27       
     28     virtual void setValue(const int & value)          { error_set() ; } 
     29     virtual void setValue(const Array<int,1>& value)  { error_set() ; } 
     30     virtual void setValue(const Array<int,2>& value)  { error_set() ; } 
     31     virtual void setValue(const Array<int,3>& value)  { error_set() ; } 
     32      
     33     virtual void setValue(const double & value)          { error_set() ; } 
     34     virtual void setValue(const Array<double,1>& value)  { error_set() ; } 
     35     virtual void setValue(const Array<double,2>& value)  { error_set() ; } 
     36     virtual void setValue(const Array<double,3>& value)  { error_set() ; } 
     37      
     38     virtual void setValue(const bool & value)          { error_set() ; } 
     39     virtual void setValue(const Array<bool,1>& value)  { error_set() ; } 
     40     virtual void setValue(const Array<bool,2>& value)  { error_set() ; } 
     41     virtual void setValue(const Array<bool,3>& value)  { error_set() ; } 
     42      
     43     virtual void setValue(const char * value)            { error_set() ; } 
     44     virtual void setValue(const string & value)          { error_set() ; } 
     45     virtual void setValue(const Array<string,1>& value)  { error_set() ; } 
     46     virtual void setValue(const Array<string,2>& value)  { error_set() ; } 
     47     virtual void setValue(const Array<string,3>& value)  { error_set() ; } 
     48      
     49     virtual void setValue(const char & value)          { error_set() ; } 
     50     virtual void setValue(const Array<char,1>& value)  { error_set() ; } 
     51     virtual void setValue(const Array<char,2>& value)  { error_set() ; } 
     52     virtual void setValue(const Array<char,3>& value)  { error_set() ; } 
     53 
     54 
     55     virtual void getValue(int & value) const        { error_get() ; } 
     56     virtual void getValue(Array<int,1>& value) const  { error_get() ; } 
     57     virtual void getValue(Array<int,2>& value) const  { error_get() ; } 
     58     virtual void getValue(Array<int,3>& value) const  { error_get() ; } 
     59      
     60     virtual void getValue(double & value) const          { error_get() ; } 
     61     virtual void getValue(Array<double,1>& value) const  { error_get() ; } 
     62     virtual void getValue(Array<double,2>& value) const  { error_get() ; } 
     63     virtual void getValue(Array<double,3>& value) const  { error_get() ; } 
     64      
     65     virtual void getValue(bool & value) const          { error_get() ; } 
     66     virtual void getValue(Array<bool,1>& value) const  { error_get() ; } 
     67     virtual void getValue(Array<bool,2>& value) const  { error_get() ; } 
     68     virtual void getValue(Array<bool,3>& value) const  { error_get() ; } 
     69      
     70     virtual void getValue(char * value) const            { error_get() ; } 
     71     virtual void getValue(string & value) const          { error_get() ; } 
     72     virtual void getValue(Array<string,1>& value) const  { error_get() ; } 
     73     virtual void getValue(Array<string,2>& value) const  { error_get() ; } 
     74     virtual void getValue(Array<string,3>& value) const  { error_get() ; } 
     75      
     76     virtual void getValue(char & value) const          { error_get() ; } 
     77     virtual void getValue(Array<char,1>& value) const  { error_get() ; } 
     78     virtual void getValue(Array<char,2>& value) const  { error_get() ; } 
     79     virtual void getValue(Array<char,3>& value) const  { error_get() ; } 
     80 
     81     static void error_set(void) 
     82     { 
     83        throw XMLIOIncompatibeTypeException("BaseAttribut::set<type> > Setting value type is incompatible with attribut type"); 
     84     } 
     85 
     86     static void error_get(void) 
     87     { 
     88        throw XMLIOIncompatibeTypeException("BaseAttribut::set<type> >Getting value type is incompatible with attribut type"); 
     89     } 
     90   }; //class BaseAttribut 
     91} // namespace XMLIOSERVER 
     92 
     93#endif //__BASE_ATTRIBUT__ 
    5094   
    51   virtual void getValue(double & value) const          { error_get() ; } 
    52   virtual void getValue(Array<double,1>& value) const  { error_get() ; } 
    53   virtual void getValue(Array<double,2>& value) const  { error_get() ; } 
    54   virtual void getValue(Array<double,3>& value) const  { error_get() ; } 
    55    
    56   virtual void getValue(bool & value) const          { error_get() ; } 
    57   virtual void getValue(Array<bool,1>& value) const  { error_get() ; } 
    58   virtual void getValue(Array<bool,2>& value) const  { error_get() ; } 
    59   virtual void getValue(Array<bool,3>& value) const  { error_get() ; } 
    60    
    61   virtual void getValue(char * value) const            { error_get() ; } 
    62   virtual void getValue(string & value) const          { error_get() ; } 
    63   virtual void getValue(Array<string,1>& value) const  { error_get() ; } 
    64   virtual void getValue(Array<string,2>& value) const  { error_get() ; } 
    65   virtual void getValue(Array<string,3>& value) const  { error_get() ; } 
    66    
    67   virtual void getValue(char & value) const          { error_get() ; } 
    68   virtual void getValue(Array<char,1>& value) const  { error_get() ; } 
    69   virtual void getValue(Array<char,2>& value) const  { error_get() ; } 
    70   virtual void getValue(Array<char,3>& value) const  { error_get() ; } 
    71  
    72   static void error_set(void) 
    73   { 
    74      error("CBaseAttribut::set<type>")<<"Setting value type is incompatible" 
    75                                       <<" with attribut type"<<endl ; 
    76   } 
    77  
    78   static void error_get(void) 
    79   { 
    80      error("CBaseAttribut::set<type>")<<"Getting value type is incompatible" 
    81                                       <<" with attribut type"<<endl ; 
    82   } 
    83 } ; 
    84  
    85 #endif  
    86    
  • XMLIO_V2/dev/trunk/src/XMLIO/context.hpp

    r79 r98  
    1 #ifndef CONTEXT_HPP 
    2 #define CONTEXT_HPP 
     1#ifndef __CONTEXT__ 
     2#define __CONTEXT__  
    33 
     4       
     5namespace XMLIOSERVER 
     6{  
     7   class Context : public ObjectTemplate<Context> 
     8   { 
     9      public: 
     10             
     11         Context(void) : ObjectTemplate<Context>() 
     12         {/* Ne rien faire de plus */}                
     13         Context(const string& _id) : ObjectTemplate<Context>(_id) 
     14         {/* Ne rien faire de plus */} 
     15          
     16         static void SetCurrentContext(const string& id) 
     17         { 
     18            // On modifie le context courrant pour tout les ObjectTemplate 
     19            Context::SetContext(id); 
     20            FieldGroup::SetContext(id); 
     21            Field::SetContext(id); 
     22         } 
     23          
     24         void parse (XMLNode& _node) 
     25         { 
     26            THashAttributes attributes; 
     27            
     28            /// PARSING POUR GESTION DES ENFANTS 
     29            if (_node.getElementName().compare(string("context"))) 
     30               WARNING("Le noeud est mal nommé mais sera traité comme un context !"); 
     31             
     32            if (!(_node.goToChildElement())) 
     33               WARNING("Le context ne contient pas d'enfant !");  
     34            else 
     35            { 
     36               ////////////////////////////////////// 
     37              do { // Parcours des contexts pour traitement.         
     38                             
     39                  string name = _node.getElementName(); 
     40                  attributes.clear(); 
     41                  _node.getAttributes(attributes);    
     42                   
     43                  if (attributes.end() != attributes.find("id")) 
     44                  { WARNING("Le noeud de définition possÚde un identifiant, ce dernier ne sera pas pris en compte lors du traitement !"); } 
     45                   
     46                  if (name.compare("field_definition") == 0) 
     47                  { // Parsing pour la définition des champs. 
     48                   
     49                     if (FieldDefinition::HasObject("field_definition"))  
     50                        WARNING("Le context possÚde déjà un noeud de définition de champs, le dernier défini complétera le premier !"); 
     51                      
     52                     fieldDef = (FieldDefinition*)&FieldDefinition::CreateObject("field_definition"); // << Conversion possible car la classe Field n'a pas de propriétés. 
     53                     fieldDef->parse(_node); 
    454 
     55                     continue; 
     56                  } 
     57                  else if (name.compare("file_definition") == 0) 
     58                  { // Parsing pour la définition des fichiers.                   
     59                     INFO("Le parsing des définitions de fichiers n'est pas encore implémenté"); 
     60                  }  
     61                  else if (name.compare("axis_definition") == 0) 
     62                  { // Parsing pour la définition des axes. 
     63                     INFO("Le parsing des définitions d'axes n'est pas encore implémenté"); 
     64                  } 
     65                  else if (name.compare("grid_definition") == 0) 
     66                  { // Parsing pour la définition des grilles. 
     67                     INFO("Le parsing des définitions de grilles n'est pas encore implémenté"); 
     68                  }  
     69                  else 
     70                     WARNING("La définition est invalide, seules les champs, grilles, axes et fichiers peuvent être définis !"); 
     71                      
     72                      
     73                  // Traitement file, grid et axis à compléter. 
     74               } while (_node.goToNextElement()); 
     75               ////////////////////////////////////// 
     76               _node.goToParentElement(); // Retour au parent 
     77            } 
     78             
     79            return; 
     80         } 
     81          
     82         virtual const char* getName(void) const {return ("Context"); } 
     83          
     84         FieldDefinition* getFieldDefinition(void) { return (this->fieldDef); } 
     85                   
     86         ~Context() 
     87         { delete fieldDef; } 
     88          
     89      protected: 
     90       
     91      private: 
     92       
     93         FieldDefinition*  fieldDef; 
     94         /*FileDefinition* fileDef; 
     95         AxisDefinition*   axisDef; 
     96         GridDefinition*   gridDef;*/ 
    597 
     98       
     99   }; //class Context 
     100}// namespace XMLIOSERVER 
    6101 
    7  
    8  
    9  
    10  
    11  
    12  
    13  
    14 #endif 
     102#endif  // __CONTEXT__ 
  • XMLIO_V2/dev/trunk/src/XMLIO/declare_attribut.hpp

    r79 r98  
    1 #ifndef DECLARE_ATTRIBUT_HPP 
    2 #define DECLARE_ATTRIBUT_HPP 
     1#ifndef __DECLARE_ATTRIBUT__ 
     2#define __DECLARE_ATTRIBUT__ 
     3 
    34#include "attribut.hpp" 
    45 
    5 #define DECLARE_ATTR(att_name,att_type)                      \ 
    6   class attr_##att_name : public CAttribut<att_type>                         \ 
    7   {                                                          \ 
    8     public:                                                  \ 
    9     const char * getName(void) const { return #att_name ;} ; \ 
    10     attr_##att_name(void) : CAttribut<att_type>() {} ; \ 
    11     attr_##att_name(const att_type& value_) : CAttribut<att_type>(value_) {} ; \ 
    12     attr_##att_name(const attr_##att_name & att) : CAttribut<att_type>(att) {} ; \ 
    13   } att_name 
     6#define DECLARE_ATTR(att_name,att_type)               \ 
     7   class attr_##att_name : public Attribut<att_type>  \ 
     8   {                                                  \ 
     9      public:                                         \ 
     10         const char * getName(void) const { return #att_name ;}                     \ 
     11         virtual const char * getType(void) const { return #att_type ;}             \ 
     12         attr_##att_name(void) : Attribut<att_type>() {}                            \ 
     13         attr_##att_name(const att_type& value_) : Attribut<att_type>(value_) {}    \ 
     14         attr_##att_name(const attr_##att_name & att) : Attribut<att_type>(att) {}  \ 
     15   } att_name 
    1416 
    15 #endif 
     17#endif // __DECLARE_ATTRIBUT__ 
  • XMLIO_V2/dev/trunk/src/XMLIO/field.hpp

    r79 r98  
    1 #ifndef FIELD_HPP 
    2 #define FIELD_HPP 
     1#ifndef __FIELD__ 
     2#define __FIELD__ 
    33 
    4 #include "base_object.hpp" 
    5 #include "object_template.hpp" 
    6 #include "xmlio_std.hpp" 
     4using XMLIOSERVER::XML::XMLNode; 
     5using XMLIOSERVER::XML::THashAttributes; 
    76 
     7namespace XMLIOSERVER 
     8{ 
     9   class Field : public ObjectTemplate<Field>, public FieldAttribut 
     10   { 
     11      public: 
     12         Field(void) : ObjectTemplate<Field>(), FieldAttribut() 
     13                        {/* Ne rien faire de plus */}                    
     14                        Field(const string& _id) : ObjectTemplate<Field>(_id), FieldAttribut() 
     15         {/* Ne rien faire de plus */}   
     16          
     17         void setAttributes(const THashAttributes& attr) 
     18         { 
     19            for (THashAttributes::ConstIterator it = attr.begin(); it != attr.end(); it++) 
     20               if ((*it).first.compare(string("id"))) // Non prise en compte de l'identifiant lors de l'affectation des attributs. 
     21                  this->setSAttribut((*it).first, (*it).second); 
     22             
     23            return; 
     24         } 
     25          
     26         virtual const char* getName(void) const {return ("Field"); }    
    827 
    9 class Field : public CObjectTemplate<Field>, public CFieldAttribut 
    10 { 
    11   public: 
    12  
    13     Field(void) : CObjectTemplate<Field>() {} ; 
    14     Field(const string & Id) : CObjectTemplate<Field>(Id) {} ; 
    15     static const char * getName(void) { return "field" ; } 
    16 }; 
    17  
    18  
    19 #endif 
     28                        void parse (XMLNode& _node) 
     29                        { 
     30            string name = _node.getElementName();             
     31            THashAttributes attributes; 
     32             
     33            /// PARSING GESTION DES ATTRIBUTS /// 
     34            _node.getAttributes(attributes);   
     35            this->setAttributes(attributes); 
     36            attributes.clear(); 
     37             
     38            /// PARSING POUR GESION DES ENFANTS 
     39            // Rien à faire. 
     40             
     41            return; 
     42         } 
     43          
     44         ~Field(void)  
     45         { /* Ne rien faire de plus */ }     
     46       
     47   }; // class Field  
     48       
     49}; // namespace XMLIOSERVER 
     50    
     51#endif // __FIELD__ 
  • XMLIO_V2/dev/trunk/src/XMLIO/field_attribut.hpp

    r79 r98  
    1 #ifndef FIELD_ATTRIBUT_HPP 
    2 #define FIELD_ATTRIBUT_HPP 
     1#ifndef __FIELD_ATTRIBUT__ 
     2#define __FIELD_ATTRIBUT__ 
    33 
     4#include "declare_attribut.hpp" 
    45#include "attribut_registrar.hpp" 
    5 #include "attribut.hpp" 
    6 #include "declare_attribut.hpp" 
    76 
    8 class CFieldAttribut : public virtual CAttributRegistrar 
     7namespace XMLIOSERVER 
    98{ 
    10   public : 
     9   class FieldAttribut : public virtual AttributRegistrar 
     10   { 
     11      public : 
     12       
     13         DECLARE_ATTR(name, string) ; 
     14         DECLARE_ATTR(description, string) ;  
     15         DECLARE_ATTR(unit, string) ; 
     16         DECLARE_ATTR(operation, string); 
     17       
     18         DECLARE_ATTR(freq_op, int) ; 
     19         DECLARE_ATTR(level, int) ; 
     20         DECLARE_ATTR(prec, int) ; 
     21          
     22         DECLARE_ATTR(src, string) ; // TEMPORAIRE, pour fieldgroup uniquement 
     23       
     24         DECLARE_ATTR(enabled, bool); 
     25       
     26         DECLARE_ATTR(axis_ref, string); 
     27         DECLARE_ATTR(grid_ref, string); 
     28         DECLARE_ATTR(zoom_ref, string); 
     29         DECLARE_ATTR(field_ref, string); 
     30       
     31         FieldAttribut(void) 
     32         { registerAllAttributes(); } 
     33                          
     34         void registerAllAttributes(void) 
     35         { 
     36            RegisterAttribut(&name) ; 
     37            RegisterAttribut(&description) ;  
     38            RegisterAttribut(&unit) ; 
     39            RegisterAttribut(&operation); 
     40             
     41            RegisterAttribut(&src);// TEMPORAIRE, pour fieldgroup uniquement 
     42       
     43            RegisterAttribut(&freq_op) ; 
     44            RegisterAttribut(&level) ; 
     45            RegisterAttribut(&prec) ; 
     46            RegisterAttribut(&enabled); 
     47       
     48            RegisterAttribut(&axis_ref); 
     49            RegisterAttribut(&grid_ref); 
     50            RegisterAttribut(&zoom_ref); 
     51            RegisterAttribut(&field_ref); 
     52         } 
     53      
     54   } ; // class CFieldAttribut 
    1155    
    12    DECLARE_ATTR(name,string) ;  
    13    DECLARE_ATTR(level,int) ; 
    14     
    15   CFieldAttribut(void) 
    16   { 
    17     RegisterAttribut(name) ; 
    18     RegisterAttribut(level) ; 
    19   } 
    20    
    21 } ; 
     56}// namespace XMLIOSERVER 
    2257 
    23 #endif 
     58#endif //__FIELD_ATTRIBUT__ 
  • XMLIO_V2/dev/trunk/src/XMLIO/main_cpp.cpp

    r79 r98  
    1 #include "field_attribut.hpp" 
    2 #include "field.hpp" 
    3 #include "group_template.hpp" 
    4 #include "xmlio_std.hpp" 
     1#include "xmlio.hpp" 
    52 
     3using namespace XMLIOSERVER; 
     4using namespace XMLIOSERVER::XML; 
     5using namespace std; 
    66 
    77extern "C" void main_c_(void) ; 
    88 
    9    
    10 void main_c_(void) 
     9void main_c_ (void) 
    1110{ 
    12   try  
    13   { 
    14     group<Field>* FirstGroup=new group<Field>("1") ; 
    15     group<Field> * MyGroup=FirstGroup->getNewGroup("group"); 
    16     Field* MyField=MyGroup->getNewChild("toto") ; 
    17     MyField->setAttribut("name",string("titi")) ; 
    18     MyField->setAttribut("level",10) ; 
    19      
    20     MyField=MyGroup->getNewChild("tata") ; 
    21     MyField->setAttribut("name",string("tutu")) ; 
    22     MyField->setAttribut("level",25) ; 
    23  
    24     MyField=MyGroup->getOrAppendChild("tete") ; 
    25     MyField->setAttribut("level",1) ; 
    26      
    27     MyField=MyGroup->getChild("toto") ; 
    28     MyField->setAttribut("level",11) ; 
    29      
    30     MyField->level=1 ; 
    31      
    32     FirstGroup->Print() ; 
    33     StdOut<<iendl; 
    34     StdOut<<"This is the end"<<iendl ; 
    35   } 
    36   catch(ex_error x) 
    37   { 
    38     StdOut<<x.what<<endl ; 
    39   } 
    40 } 
     11        try 
     12        { 
     13                XMLParser::CLASS_TEST();             
     14                // Code à executer ici 
     15        } 
     16        catch(const XMLIOException &exc) 
     17        {  // Pour tout type d'exceptions, on note les informations sur la sortie paramétrée. 
     18                ERROR(exc.displayText());  
     19                // On retourne le code d'erreur en fin d'application pour traitements éventuels. 
     20//              return (exc.code()); 
     21        } 
     22       
     23//      return (0); 
     24}  
  • XMLIO_V2/dev/trunk/src/XMLIO/xmlio_exception.hpp

    r79 r98  
    1 #ifndef XMLIO_EXCEPTION_HPP 
    2 #define XMLIO_EXCEPTION_HPP 
     1#ifndef __XMLIO_EXCEPTION__ 
     2#define __XMLIO_EXCEPTION__  
    33 
    4 #include <sstream> 
    5 #include "xmlio_std.hpp" 
    6 using namespace std ; 
     4// Classes utilisées issues de la STL 
     5using std::string; 
    76 
    8 class ex_error 
     7// Classes utilisées issues de Poco 
     8using Poco::Exception; 
     9 
     10namespace XMLIOSERVER 
    911{ 
    10   public : 
    11   string what ; 
    12   ex_error(const string & what_ ) : what(what_) {} ; 
    13 } ; 
     12   class XMLIOException : public Exception 
     13   { 
     14      public : 
     15             
     16         XMLIOException(int _code): Exception(_code)                                                    
     17         { /* Ne rien faire de plus */ }                                                                      
     18         XMLIOException(const std::string& _msg, int _code): Exception(_msg, _code)                               
     19         { /* Ne rien faire de plus */ }                                                                         
     20         XMLIOException(const std::string& _msg, const std::string& _arg, int _code): Exception(_msg, _arg, _code)       
     21         { /* Ne rien faire de plus */ }                                                                         
     22         XMLIOException(const std::string& _msg, const Poco::Exception& _exc, int _code): Exception(_msg, _exc, _code)    
     23         { /* Ne rien faire de plus */ }    
     24          
     25                                                                               
     26         XMLIOException(const XMLIOException& _exc): Exception(_exc)                                                 
     27         { /* Ne rien faire de plus */ } 
     28          
     29         ~XMLIOException() throw() 
     30         { /* Ne rien faire de plus */ } 
     31          
     32         XMLIOException& operator = (const XMLIOException& _exc)                                              
     33         { Exception::operator = (_exc); return *this; }    
     34                                                                            
     35         virtual const char* name(void) const throw() { return ("XMLIO>XMLIOException"); }                                                                      
     36         virtual const char* className(void) const throw() { return (typeid(*this).name()); }       
     37                                                                      
     38         virtual Exception* clone(void) const {   return new XMLIOException(*this); }                                                                      
     39         virtual void rethrow(void) const { throw *this; } 
     40                
     41   };// class XMLIOException 
     42    
     43   class XMLIOUndefinedValueException : public XMLIOException 
     44   { 
     45      public : 
     46         XMLIOUndefinedValueException(const std::string& _msg): XMLIOException(_msg, 1001) {} 
     47         const char* name(void) const throw() { return ("XMLIO>UndefinedValueException"); } 
     48             
     49   }; //class XMLIOUndefinedException 
     50    
     51   class XMLIOStreamException : public XMLIOException 
     52   { 
     53      public : 
     54         XMLIOStreamException(const std::string& _msg): XMLIOException(_msg, 1002) {} 
     55         const char* name(void) const throw() { return ("XMLIO>StreamException"); } 
     56             
     57   }; //class XMLIOStreamException 
     58    
     59   class XMLParsingException : public XMLIOException 
     60   { 
     61      public : 
     62         XMLParsingException(const std::string& _msg): XMLIOException(_msg, 1003) {} 
     63         const char* name(void) const throw() { return ("XMLIO>XMLParsingException"); } 
     64             
     65   }; //class XMLParsingException 
     66    
     67   class XMLIOIncompatibeTypeException : public XMLIOException 
     68   { 
     69      public : 
     70         XMLIOIncompatibeTypeException(const std::string& _msg): XMLIOException(_msg, 1003) {} 
     71         const char* name(void) const throw() { return ("XMLIO>XMLIOIncompatibeTypeException"); } 
     72             
     73   }; //class XMLIOIncompatibeTypeException 
     74    
     75   // A compléter. 
     76    
     77};// namespace XMLIOSERVER 
    1478 
    15 //class error; 
    16 //ostringstream & operator << (const error & err,char const * str) ; 
    17 //ostringstream & operator << (const error & err,const string & str) ; 
    18  
    19  
    20 class error : public ostringstream 
    21 { 
    22   public : 
    23      
    24     error(const string & where) : ostringstream() 
    25     { 
    26       *this<<"*** Error **** in function : "<<where<<endl<<"------> "<<string("toto") ; 
    27     } ; 
    28      
    29     error(const char * where) : ostringstream() 
    30     { 
    31       *this<<"Error in function : "<<where<<endl<<"------> " ; 
    32     } ; 
    33  
    34     ~error() 
    35     { 
    36       StdErr<< this->str() <<endl ; 
    37       throw(ex_error(this->str())) ; 
    38     } ; 
    39  
    40    ostringstream & operator << (char const * str) const 
    41    { 
    42      ostringstream * tmp=const_cast <error *>(this) ; 
    43      *tmp<<str ; 
    44      return *tmp ; 
    45    } ; 
    46  
    47    ostringstream & operator << (const string& str) const 
    48    { 
    49      ostringstream * tmp=const_cast <error *>(this) ; 
    50      *tmp<<str ; 
    51      return *tmp ; 
    52    } ;  
    53  
    54 } ; 
    55  
    56 class warning : public ostringstream 
    57 { 
    58   public : 
    59      
    60     warning(const string & where) : ostringstream() 
    61     { 
    62       *this<<"*** Warning **** in function : "<<where<<endl<<"------> "; 
    63     } ; 
    64      
    65     warning(const char * where) : ostringstream() 
    66     { 
    67       *this<<"Error in function : "<<where<<endl<<"------> " ; 
    68     } ; 
    69  
    70     ~warning() 
    71     { 
    72       StdErr<< this->str() <<endl ; 
    73     } ; 
    74  
    75    ostringstream & operator << (char const * str) const 
    76    { 
    77      ostringstream * tmp=const_cast <warning *>(this) ; 
    78      *tmp<<str ; 
    79      return *tmp ; 
    80    } ; 
    81  
    82    ostringstream & operator << (const string& str) const 
    83    { 
    84      ostringstream * tmp=const_cast <warning *>(this) ; 
    85      *tmp<<str ; 
    86      return *tmp ; 
    87    } ;  
    88  
    89 } ; 
    90  
    91  
    92 #endif 
     79#endif // __XMLIO_EXCEPTION__  
Note: See TracChangeset for help on using the changeset viewer.