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10.5.p1 ] [ 10.6 ] [ 10.6.p1 ] [ 10.6.p2 ] [ 10.6.p3 ] [ 10.7 ] [ 10.7.p1 ] [ 10.7.p2 ] [ 10.7.p3 ] [ 10.7.p4 ] [ 11.0 ] [ 11.0.p1 ] [ 11.0.p2 ] [ 11.0.p3, ] [ 11.0.p4 ] [ 11.1 ] [ 11.1.1 ] [ 11.1.2 ] [ 11.1.3 ] [ 11.2 ] [ 11.2.1 ] [ 11.2.2 ] [ 11.3.0 ]

Diff markup

Differences between /externals/g4tools/include/tools/xml/element (Version 11.3.0) and /externals/g4tools/include/tools/xml/element (Version 10.3.p1)


  1 // Copyright (C) 2010, Guy Barrand. All rights    
  2 // See the file tools.license for terms.          
  3                                                   
  4 #ifndef tools_xml_element                         
  5 #define tools_xml_element                         
  6                                                   
  7 #include "../srep"                                
  8 #include "../sto"                                 
  9 #include "../scast"                               
 10                                                   
 11 #ifdef TOOLS_MEM                                  
 12 #include "../mem"                                 
 13 #include "../S_STRING"                            
 14 #endif                                            
 15                                                   
 16 namespace tools {                                 
 17 namespace xml {                                   
 18                                                   
 19 class ielem {                                     
 20 public:                                           
 21   virtual ~ielem(){}                              
 22 public:                                           
 23   virtual void* cast(cid) const = 0;              
 24 };                                                
 25                                                   
 26 class element : public virtual ielem {            
 27 #ifdef TOOLS_MEM                                  
 28   TOOLS_SCLASS(tools::xml::element)               
 29 #endif                                            
 30 public:                                           
 31   static cid id_class() {return 0;}               
 32   virtual void* cast(cid a_class) const {         
 33     if(void* p = cmp_cast<element>(this,a_clas    
 34     else return 0;                                
 35   }                                               
 36 public:                                           
 37   typedef std::pair<std::string,std::string> a    
 38 public:                                           
 39   element(const std::string& a_name,              
 40           const std::vector<atb>& a_atbs,         
 41           const std::string& a_value){            
 42 #ifdef TOOLS_MEM                                  
 43     mem::increment(s_class().c_str());            
 44 #endif                                            
 45     m_name = a_name;                              
 46     m_atbs = a_atbs;                              
 47     m_value = a_value;                            
 48   }                                               
 49   virtual ~element(){                             
 50 #ifdef TOOLS_MEM                                  
 51     mem::decrement(s_class().c_str());            
 52 #endif                                            
 53   }                                               
 54 public:                                           
 55   element(const element& a_from)                  
 56   :ielem(a_from) {                                
 57 #ifdef TOOLS_MEM                                  
 58     mem::increment(s_class().c_str());            
 59 #endif                                            
 60     m_name = a_from.m_name;                       
 61     m_atbs = a_from.m_atbs;                       
 62     m_value = a_from.m_value;                     
 63   }                                               
 64   element& operator=(const element& a_from) {     
 65     m_name = a_from.m_name;                       
 66     m_atbs = a_from.m_atbs;                       
 67     m_value = a_from.m_value;                     
 68     return *this;                                 
 69   }                                               
 70 public:                                           
 71   const std::string& name() const {return m_na    
 72   const std::vector<atb>& attributes() const {    
 73   const std::string& value() const {return m_v    
 74                                                   
 75   void set_value(const std::string& a_value) {    
 76   bool is_attribute(const std::string& a_name)    
 77     tools_vforcit(atb,m_atbs,it) {                
 78       if((*it).first==a_name) return true;        
 79     }                                             
 80     return false;                                 
 81   }                                               
 82   void add_attribute(const std::string& a_name    
 83     // No check is done about an existing a_na    
 84     m_atbs.push_back(atb(a_name,a_value));        
 85   }                                               
 86                                                   
 87   bool attribute_value(const std::string& a_at    
 88     tools_vforcit(atb,m_atbs,it) {                
 89       if((*it).first==a_atb) {                    
 90         a_value = (*it).second;                   
 91         return true;                              
 92       }                                           
 93     }                                             
 94     a_value.clear();                              
 95     return false;                                 
 96   }                                               
 97                                                   
 98   template <class T>                              
 99   bool attribute_value(const std::string& a_at    
100     std::string sv;                               
101     if(!attribute_value(a_atb,sv)) {a_value=T(    
102     return to<T>(sv,a_value);                     
103   }                                               
104                                                   
105                                                   
106   bool set_attribute_value(const std::string&     
107     tools_vforit(atb,m_atbs,it) {                 
108       if((*it).first==a_atb) {                    
109         (*it).second = a_value;                   
110         return true;                              
111       }                                           
112     }                                             
113     // Not found, add one :                       
114     m_atbs.push_back(atb(a_atb,a_value));         
115     return true;                                  
116   }                                               
117                                                   
118   void remove_attributes(const std::string& a_    
119     std::vector<atb>::iterator it;                
120     for(it=m_atbs.begin();it!=m_atbs.end();) {    
121       if((*it).first==a_atb) {                    
122         it = m_atbs.erase(it);                    
123       } else {                                    
124         ++it;                                     
125       }                                           
126     }                                             
127   }                                               
128                                                   
129   void replace(const std::string& a_old,const     
130     // Used by the obuild template system.        
131     tools_vforit(atb,m_atbs,it) {                 
132       replace_((*it).second,a_old,a_new);         
133     }                                             
134     replace_(m_value,a_old,a_new);                
135   }                                               
136                                                   
137 protected:                                        
138   std::string m_name;                             
139   std::vector<atb> m_atbs;                        
140   std::string m_value;                            
141 };                                                
142                                                   
143 }}                                                
144                                                   
145 #endif