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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/wroot/leaf (Version 11.3.0) and /externals/g4tools/include/tools/wroot/leaf (Version 10.2.p1)


  1 // Copyright (C) 2010, Guy Barrand. All rights    
  2 // See the file tools.license for terms.          
  3                                                   
  4 #ifndef tools_wroot_leaf                          
  5 #define tools_wroot_leaf                          
  6                                                   
  7 #include "base_leaf"                              
  8                                                   
  9 #include "../cids"                                
 10 #include "../vdata"                               
 11                                                   
 12 namespace tools {                                 
 13 namespace wroot {                                 
 14                                                   
 15 inline const std::string& leaf_store_class(cha    
 16   static const std::string s_v("TLeafB");         
 17   return s_v;                                     
 18 }                                                 
 19 inline const std::string& leaf_store_class(sho    
 20   static const std::string s_v("TLeafS");         
 21   return s_v;                                     
 22 }                                                 
 23 inline const std::string& leaf_store_class(int    
 24   static const std::string s_v("TLeafI");         
 25   return s_v;                                     
 26 }                                                 
 27 inline const std::string& leaf_store_class(flo    
 28   static const std::string s_v("TLeafF");         
 29   return s_v;                                     
 30 }                                                 
 31 inline const std::string& leaf_store_class(dou    
 32   static const std::string s_v("TLeafD");         
 33   return s_v;                                     
 34 }                                                 
 35 inline const std::string& leaf_string_store_cl    
 36   static const std::string s_v("TLeafC");         
 37   return s_v;                                     
 38 }                                                 
 39 inline const std::string& leaf_element_store_c    
 40   static const std::string s_v("TLeafElement")    
 41   return s_v;                                     
 42 }                                                 
 43 inline const std::string& leaf_object_store_cl    
 44   static const std::string s_v("TLeafObject");    
 45   return s_v;                                     
 46 }                                                 
 47                                                   
 48 template <class T>                                
 49 class leaf_ref : public base_leaf {               
 50   typedef base_leaf parent;                       
 51 public:                                           
 52   static cid id_class() {return base_leaf_cid(    
 53   virtual void* cast(cid a_class) const {         
 54     if(void* p = cmp_cast<leaf_ref>(this,a_cla    
 55     return parent::cast(a_class);                 
 56   }                                               
 57   virtual cid id_cls() const {return id_class(    
 58 public: //ibo                                     
 59   virtual const std::string& store_cls() const    
 60   virtual bool stream(buffer& a_buffer) const     
 61     unsigned int c;                               
 62     if(!a_buffer.write_version(1,c)) return fa    
 63     if(!parent::stream(a_buffer)) return false    
 64     if(!a_buffer.write(m_min)) return false;      
 65     if(!a_buffer.write(m_max)) return false;      
 66     if(!a_buffer.set_byte_count(c)) return fal    
 67     return true;                                  
 68   }                                               
 69 public: //base_leaf                               
 70   virtual bool fill_buffer(buffer& a_buffer) c    
 71     if(m_is_range) {                              
 72       if(m_ref>=m_max) {                          
 73         leaf_ref& self = const_cast<leaf_ref&>    
 74         self.m_max = m_ref;                       
 75       }                                           
 76     }                                             
 77     return a_buffer.write<T>(m_ref);              
 78   }                                               
 79 public:                                           
 80   leaf_ref(std::ostream& a_out,const std::stri    
 81   :parent(a_out,a_name,a_name)                    
 82   ,m_min(T()),m_max(T())                          
 83   ,m_ref(a_ref)                                   
 84   {                                               
 85     m_length = 1;                                 
 86     m_length_type = sizeof(T);                    
 87   }                                               
 88   virtual ~leaf_ref(){}                           
 89 protected:                                        
 90   leaf_ref(const leaf_ref& a_from):ibo(a_from)    
 91   leaf_ref& operator=(const leaf_ref&){return     
 92 public:                                           
 93   T get_max() const {return m_max;}               
 94   void set_max(const T& a_value) {m_max = a_va    
 95 public:                                           
 96   const T& variable() const {return m_ref;}       
 97   T& variable() {return const_cast<T&>(m_ref);    
 98 protected:                                        
 99   T m_min;    //Minimum value if leaf range is    
100   T m_max;    //Maximum value if leaf range is    
101   const T& m_ref;                                 
102 };                                                
103                                                   
104 template <class T>                                
105 class leaf : public leaf_ref<T> {                 
106   typedef leaf_ref<T> parent;                     
107 public:                                           
108   static cid id_class() {return base_leaf_cid(    
109   virtual void* cast(cid a_class) const {         
110     if(void* p = cmp_cast<leaf>(this,a_class))    
111     return parent::cast(a_class);                 
112   }                                               
113   virtual cid id_cls() const {return id_class(    
114 public:                                           
115   leaf(std::ostream& a_out,const std::string&     
116   :parent(a_out,a_name,m_value)                   
117   ,m_value(T())                                   
118   {}                                              
119   virtual ~leaf(){}                               
120 protected:                                        
121   leaf(const leaf& a_from):ibo(a_from),parent(    
122   leaf& operator=(const leaf&){return *this;}     
123 public:                                           
124   void fill(const T& a_value) {m_value = a_val    
125 protected:                                        
126   T m_value;                                      
127 };                                                
128                                                   
129 class leaf_string_ref : public base_leaf {        
130   typedef base_leaf parent;                       
131 public:                                           
132   static cid id_class() {return leaf_string_ci    
133   virtual void* cast(cid a_class) const {         
134     if(void* p = cmp_cast<leaf_string_ref>(thi    
135     return parent::cast(a_class);                 
136   }                                               
137   virtual cid id_cls() const {return id_class(    
138 public: //ibo                                     
139   virtual const std::string& store_cls() const    
140   virtual bool stream(buffer& a_buffer) const     
141     unsigned int c;                               
142     if(!a_buffer.write_version(1,c)) return fa    
143     if(!parent::stream(a_buffer)) return false    
144     if(!a_buffer.write(m_min)) return false;      
145     if(!a_buffer.write(m_max)) return false;      
146     if(!a_buffer.set_byte_count(c)) return fal    
147     return true;                                  
148   }                                               
149 public: //base_leaf                               
150   virtual bool fill_buffer(buffer& a_buffer) c    
151     leaf_string_ref& self = const_cast<leaf_st    
152     size_t len = ::strlen(m_ref.c_str());         
153     if(len >= (size_t)m_max) self.m_max = int(    
154     if(len >= m_length) self.m_length = uint32    
155     if(len < 255) {                               
156       if(!a_buffer.write<unsigned char>((unsig    
157     } else {                                      
158       if(!a_buffer.write<unsigned char>(255))     
159       if(!a_buffer.write<uint32>(uint32(len)))    
160     }                                             
161     if(len) if(!a_buffer.write_fast_array(m_re    
162     return true;                                  
163   }                                               
164 public:                                           
165   leaf_string_ref(std::ostream& a_out,const st    
166   :parent(a_out,a_name,a_name)                    
167   ,m_min(0),m_max(0)                              
168   ,m_ref(a_ref)                                   
169   {                                               
170     m_length_type = 1;                            
171   }                                               
172   virtual ~leaf_string_ref(){}                    
173 protected:                                        
174   leaf_string_ref(const leaf_string_ref& a_fro    
175   leaf_string_ref& operator=(const leaf_string    
176 public:                                           
177   int get_max() const {return m_max;}             
178   void set_max(int a_value) {m_max = a_value;}    
179 public:                                           
180   const std::string& variable() const {return     
181   std::string& variable() {return const_cast<s    
182 protected:                                        
183   int m_min; //Minimum value if leaf range is     
184   int m_max; //Maximum value if leaf range is     
185   const std::string& m_ref;                       
186 };                                                
187                                                   
188 class leaf_string : public leaf_string_ref {      
189   typedef leaf_string_ref parent;                 
190 public:                                           
191   static cid id_class() {return leaf_string_ci    
192   virtual void* cast(cid a_class) const {         
193     if(void* p = cmp_cast<leaf_string>(this,a_    
194     return parent::cast(a_class);                 
195   }                                               
196   virtual cid id_cls() const {return id_class(    
197 public:                                           
198   leaf_string(std::ostream& a_out,const std::s    
199   :parent(a_out,a_name,m_value)                   
200   {}                                              
201   virtual ~leaf_string(){}                        
202 protected:                                        
203   leaf_string(const leaf_string& a_from):ibo(a    
204   leaf_string& operator=(const leaf_string&){r    
205 public:                                           
206   void fill(const std::string& a_value) {m_val    
207 protected:                                        
208   std::string m_value;                            
209 };                                                
210                                                   
211 // to store vector columns of a row_wise ntupl    
212 template <class T>                                
213 class leaf_std_vector_ref : public base_leaf {    
214   typedef base_leaf parent;                       
215 public:                                           
216   static cid id_class() {return base_leaf_cid(    
217   virtual void* cast(cid a_class) const {         
218     if(void* p = cmp_cast<leaf_std_vector_ref>    
219     return parent::cast(a_class);                 
220   }                                               
221   virtual cid id_cls() const {return id_class(    
222 public: //ibo                                     
223   virtual const std::string& store_cls() const    
224   virtual bool stream(buffer& a_buffer) const     
225     unsigned int c;                               
226     if(!a_buffer.write_version(1,c)) return fa    
227     if(!parent::stream(a_buffer)) return false    
228     if(!a_buffer.write(m_min)) return false;      
229     if(!a_buffer.write(m_max)) return false;      
230     if(!a_buffer.set_byte_count(c)) return fal    
231     return true;                                  
232   }                                               
233 public: //base_leaf                               
234   virtual bool fill_buffer(buffer& a_buffer) c    
235     if(!a_buffer.write_fast_array(vec_data(m_r    
236     return true;                                  
237   }                                               
238 public:                                           
239   leaf_std_vector_ref(std::ostream& a_out,cons    
240                       base_leaf& a_leaf_count,    
241   :parent(a_out,a_name,a_name)                    
242   ,m_min(T()),m_max(T())                          
243   ,m_ref(a_ref)                                   
244   {                                               
245     parent::m_leaf_count = &a_leaf_count;         
246     a_leaf_count.set_is_range(true);              
247     m_length = 1;                                 
248     m_length_type = sizeof(T);                    
249   }                                               
250   virtual ~leaf_std_vector_ref(){}                
251 protected:                                        
252   leaf_std_vector_ref(const leaf_std_vector_re    
253   leaf_std_vector_ref& operator=(const leaf_st    
254 public:                                           
255   T get_max() const {return m_max;}               
256   void set_max(const T& a_value) {m_max = a_va    
257 public:                                           
258   const std::vector<T>& variable() const {retu    
259   std::vector<T>& variable() {return const_cas    
260 protected:                                        
261   T m_min;    //Minimum value if leaf range is    
262   T m_max;    //Maximum value if leaf range is    
263   const std::vector<T>& m_ref;                    
264 };                                                
265                                                   
266 class leaf_element : public base_leaf {           
267   typedef base_leaf parent;                       
268 public:                                           
269   static cid id_class() {return leaf_element_c    
270   virtual void* cast(cid a_class) const {         
271     if(void* p = cmp_cast<leaf_element>(this,a    
272     return base_leaf::cast(a_class);              
273   }                                               
274   virtual cid id_cls() const {return id_class(    
275 public:                                           
276   virtual const std::string& store_cls() const    
277   virtual bool stream(buffer& a_buffer) const     
278     unsigned int c;                               
279     if(!a_buffer.write_version(1,c)) return fa    
280     if(!parent::stream(a_buffer)) return false    
281                                                   
282     if(!a_buffer.write(fID)) return false;        
283     if(!a_buffer.write(fType)) return false;      
284                                                   
285     if(!a_buffer.set_byte_count(c)) return fal    
286     return true;                                  
287   }                                               
288 public: //base_leaf                               
289   virtual bool fill_buffer(buffer&) const {       
290     m_out << "tools::wroot::leaf_element::fill    
291     return false;                                 
292   }                                               
293 public:                                           
294   leaf_element(std::ostream& a_out,const std::    
295   :parent(a_out,a_name,a_name)                    
296   ,fID(a_id)                                      
297   ,fType(a_type)                                  
298   {}                                              
299   virtual ~leaf_element(){}                       
300 protected:                                        
301   leaf_element(const leaf_element& a_from):ibo    
302   leaf_element& operator=(const leaf_element&     
303     parent::operator=(a_from);                    
304     return *this;                                 
305   }                                               
306 protected:                                        
307   int fID;   //element serial number in fInfo     
308   int fType; //leaf type                          
309 };                                                
310                                                   
311 }}                                                
312                                                   
313 #include "iobject"                                
314                                                   
315 namespace tools {                                 
316 namespace wroot {                                 
317                                                   
318 class leaf_object : public base_leaf {            
319   typedef base_leaf parent;                       
320 public:                                           
321   static cid id_class() {return leaf_object_ci    
322   virtual void* cast(cid a_class) const {         
323     if(void* p = cmp_cast<leaf_object>(this,a_    
324     return base_leaf::cast(a_class);              
325   }                                               
326   virtual cid id_cls() const {return id_class(    
327 public:                                           
328   virtual const std::string& store_cls() const    
329   virtual bool stream(buffer& a_buffer) const     
330     unsigned int c;                               
331     if(!a_buffer.write_version(4,c)) return fa    
332     if(!parent::stream(a_buffer)) return false    
333     if(!a_buffer.write(fVirtual)) return false    
334     if(!a_buffer.set_byte_count(c)) return fal    
335     return true;                                  
336   }                                               
337 public: //base_leaf                               
338   virtual bool fill_buffer(buffer& a_buffer) c    
339     if(fVirtual) {                                
340       const std::string& _class = m_obj.store_    
341       if(_class.size()>255) return false;         
342       unsigned char n = (unsigned char)_class.    
343       if(!a_buffer.write(n)) return false;        
344       if(!a_buffer.write_fast_array(_class.c_s    
345     }                                             
346     return m_obj.stream(a_buffer);                
347   }                                               
348 public:                                           
349   leaf_object(std::ostream& a_out,const std::s    
350   :parent(a_out,a_name,a_obj.store_class_name(    
351   ,m_obj(a_obj)                                   
352   ,fVirtual(true)                                 
353   {}                                              
354   virtual ~leaf_object(){}                        
355 protected:                                        
356   leaf_object(const leaf_object& a_from):ibo(a    
357   leaf_object& operator=(const leaf_object& a_    
358     parent::operator=(a_from);                    
359     return *this;                                 
360   }                                               
361 protected:                                        
362   const iobject& m_obj;                           
363   bool fVirtual; // Support for Virtuality        
364 };                                                
365                                                   
366 }}                                                
367                                                   
368 #endif