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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 ]

  1 // Copyright (C) 2010, Guy Barrand. All rights reserved.
  2 // See the file tools.license for terms.
  3 
  4 #ifndef tools_wroot_branch_element
  5 #define tools_wroot_branch_element
  6 
  7 #include "branch"
  8 
  9 namespace tools {
 10 namespace wroot {
 11 
 12 inline const std::string& branch_element_store_class() {
 13   static const std::string s_v("TBranchElement");
 14   return s_v;
 15 }
 16 
 17 class branch_element : public branch {
 18   typedef branch parent;
 19 #ifdef TOOLS_MEM
 20   static const std::string& s_class() {
 21     static const std::string s_v("tools::wroot::branch_element");
 22     return s_v;
 23   }
 24 #endif
 25 public: //ibo
 26   virtual const std::string& store_cls() const {return branch_element_store_class();}
 27   virtual bool stream(buffer& a_buffer) const {
 28     unsigned int c;
 29     if(!a_buffer.write_version(1,c)) return false;
 30     if(!parent::stream(a_buffer)) return false;
 31 
 32     if(!a_buffer.write(fClassName)) return false;
 33     if(!a_buffer.write(fClassVersion)) return false;
 34     if(!a_buffer.write(fID)) return false;
 35     if(!a_buffer.write(fType)) return false;
 36     if(!a_buffer.write(fStreamerType)) return false;
 37 
 38     if(!a_buffer.set_byte_count(c)) return false;
 39     return true;
 40   }
 41 
 42 public:
 43   branch_element(std::ostream& a_out,bool a_byte_swap,uint32 a_compression,
 44                  seek a_seek_directory,const std::string& a_name,const std::string& a_title,bool a_verbose)
 45   :parent(a_out,a_byte_swap,a_compression,a_seek_directory,a_name,a_title,a_verbose)
 46   ,fClassVersion(0)
 47   ,fID(0)
 48   ,fType(0)
 49   ,fStreamerType(-1)
 50   {
 51 #ifdef TOOLS_MEM
 52     mem::increment(s_class().c_str());
 53 #endif
 54   }
 55   virtual ~branch_element(){
 56 #ifdef TOOLS_MEM
 57     mem::decrement(s_class().c_str());
 58 #endif
 59   }
 60 protected:
 61   branch_element(const branch_element& a_from):ibo(a_from),parent(a_from) {}
 62   branch_element& operator=(const branch_element& a_from){parent::operator=(a_from);return *this;}
 63 public:
 64   leaf_element* create_leaf_element(const std::string& a_name){
 65     leaf_element* lf = new leaf_element(m_out,a_name,fID,fType);
 66     m_leaves.push_back(lf);
 67     return lf;
 68   }
 69 protected:
 70   virtual bool fill_leaves(buffer&) {return false;} //must be derived.
 71 protected:
 72   std::string fClassName; //Class name of referenced object
 73   int fClassVersion;      //Version number of class
 74   int fID;                //element serial number in fInfo
 75   int fType;              //branch type
 76   int fStreamerType;      //branch streamer type
 77 };
 78 
 79 template <class T>
 80 class std_vector_be_ref : public branch_element {
 81   typedef branch_element parent;
 82 #ifdef TOOLS_MEM
 83   static const std::string& s_class() {
 84     static const std::string s_v("tools::wroot::std_vector_be_ref");
 85     return s_v;
 86   }
 87 #endif
 88 public:
 89   std_vector_be_ref(std::ostream& a_out,bool a_byte_swap,uint32 a_compression,
 90                     seek a_seek_directory,
 91                     const std::string& a_name,const std::string& a_title,const std::vector<T>& a_ref,bool a_verbose)
 92   :parent(a_out,a_byte_swap,a_compression,a_seek_directory,a_name,a_title,a_verbose)
 93   ,m_ref(a_ref)
 94   {
 95 #ifdef TOOLS_MEM
 96     mem::increment(s_class().c_str());
 97 #endif
 98     fClassName = "vector<"+stype(T())+">";
 99     fClassVersion = 0;
100     fID = -1;
101     fType = 0;
102     fStreamerType  = -1; // TStreamerInfo::kSTLp;
103   }
104   virtual ~std_vector_be_ref(){
105 #ifdef TOOLS_MEM
106     mem::decrement(s_class().c_str());
107 #endif
108   }
109 protected:
110   std_vector_be_ref(const std_vector_be_ref& a_from)
111   :ibo(a_from)
112   ,parent(a_from)
113   ,m_ref(a_from.m_ref)
114   {}
115   std_vector_be_ref& operator=(const std_vector_be_ref& a_from){
116     parent::operator=(a_from);
117     return *this;
118   }
119 protected:
120   virtual bool fill_leaves(buffer& a_buffer) {
121     unsigned int c;
122     if(!a_buffer.write_version(4,c)) return false;
123     if(!a_buffer.write((int)m_ref.size())) return false;
124     if(m_ref.size()) {
125       // The awfull below is to pass T=bool :
126       const T& vr = m_ref[0];
127       if(!a_buffer.write_fast_array(&vr,(int)m_ref.size())) return false;
128     }
129     if(!a_buffer.set_byte_count(c)) return false;
130     return true;
131   }
132 public:
133   const std::vector<T>& variable() const {return m_ref;}
134   std::vector<T>& variable() {return const_cast< std::vector<T>& >(m_ref);}
135 protected:
136   const std::vector<T>& m_ref;
137 };
138 
139 template <class T>
140 class std_vector_be : public std_vector_be_ref<T> {
141   typedef std_vector_be_ref<T> parent;
142 #ifdef TOOLS_MEM
143   static const std::string& s_class() {
144     static const std::string s_v("tools::wroot::std_vector_be");
145     return s_v;
146   }
147 #endif
148 public:
149   std_vector_be(std::ostream& a_out,bool a_byte_swap,uint32 a_compression,
150                 seek a_seek_directory,
151                 const std::string& a_name,const std::string& a_title,const std::vector<T>& a_def,bool a_verbose)
152   :parent(a_out,a_byte_swap,a_compression,a_seek_directory,a_name,a_title,m_value,a_verbose)
153   ,m_def(a_def),m_value(a_def)
154   {
155 #ifdef TOOLS_MEM
156     mem::increment(s_class().c_str());
157 #endif
158   }
159   virtual ~std_vector_be(){
160 #ifdef TOOLS_MEM
161     mem::decrement(s_class().c_str());
162 #endif
163   }
164 protected:
165   std_vector_be(const std_vector_be& a_from)
166   :ibo(a_from)
167   ,parent(a_from)
168   ,m_def(a_from.m_def)
169   ,m_value(a_from.m_value)
170   {}
171   std_vector_be& operator=(const std_vector_be& a_from){
172     parent::operator=(a_from);
173     m_def = a_from.m_def;
174     m_value = a_from.m_value;
175     return *this;
176   }
177 protected:
178   std::vector<T> m_def;
179   std::vector<T> m_value;
180 };
181 
182 template <class T>
183 class std_vector_be_pointer : public branch_element {
184   typedef branch_element parent;
185 #ifdef TOOLS_MEM
186   static const std::string& s_class() {
187     static const std::string s_v("tools::wroot::std_vector_be_pointer");
188     return s_v;
189   }
190 #endif
191 public:
192   std_vector_be_pointer(std::ostream& a_out,bool a_byte_swap,uint32 a_compression,
193                     seek a_seek_directory,
194                     const std::string& a_name,const std::string& a_title,std::vector<T>* a_pointer,bool a_verbose)
195   :parent(a_out,a_byte_swap,a_compression,a_seek_directory,a_name,a_title,a_verbose)
196   ,m_pointer(a_pointer)
197   {
198 #ifdef TOOLS_MEM
199     mem::increment(s_class().c_str());
200 #endif
201     fClassName = "vector<"+stype(T())+">";
202     fClassVersion = 0;
203     fID = -1;
204     fType = 0;
205     fStreamerType  = -1; // TStreamerInfo::kSTLp;
206   }
207   virtual ~std_vector_be_pointer(){
208 #ifdef TOOLS_MEM
209     mem::decrement(s_class().c_str());
210 #endif
211   }
212 protected:
213   std_vector_be_pointer(const std_vector_be_pointer& a_from)
214   :ibo(a_from)
215   ,parent(a_from)
216   ,m_pointer(a_from.m_pointer)
217   {}
218   std_vector_be_pointer& operator=(const std_vector_be_pointer& a_from){
219     parent::operator=(a_from);
220     return *this;
221   }
222 protected:
223   virtual bool fill_leaves(buffer& a_buffer) {
224     if(!m_pointer) return false;
225     unsigned int c;
226     if(!a_buffer.write_version(4,c)) return false;
227     if(!a_buffer.write((int)m_pointer->size())) return false;
228     if(m_pointer->size()) {
229       // The awfull below is to pass T=bool :
230       T& vr = (*m_pointer)[0];
231       if(!a_buffer.write_fast_array(&vr,(int)m_pointer->size())) return false;
232     }
233     if(!a_buffer.set_byte_count(c)) return false;
234     return true;
235   }
236 public:
237   void set_pointer(std::vector<T>* a_pointer) {m_pointer = a_pointer;}
238   const std::vector<T>* get_pointer() const {return m_pointer;}
239   std::vector<T>* get_pointer() {return m_pointer;}
240 protected:
241   std::vector<T>* m_pointer;
242 };
243 
244 }}
245 
246 #endif