Geant4 Cross Reference |
1 // Copyright (C) 2010, Guy Barrand. All rights reserved. 2 // See the file tools.license for terms. 3 4 #ifndef tools_rroot_base_leaf 5 #define tools_rroot_base_leaf 6 7 #ifdef TOOLS_MEM 8 #include "../mem" 9 #endif 10 11 #include "named" 12 13 namespace tools { 14 namespace rroot { 15 16 class base_leaf : public virtual iro { 17 public: 18 static const std::string& s_class() { 19 static const std::string s_v("tools::rroot::base_leaf"); 20 return s_v; 21 } 22 public: //iro 23 virtual void* cast(const std::string& a_class) const { 24 if(void* p = cmp_cast<base_leaf>(this,a_class)) return p; 25 return 0; 26 } 27 virtual const std::string& s_cls() const {return s_class();} 28 public: 29 static cid id_class() {return base_leaf_cid();} 30 virtual void* cast(cid a_class) const { 31 if(void* p = cmp_cast<base_leaf>(this,a_class)) {return p;} 32 else return 0; 33 } 34 public: 35 virtual bool stream(buffer& a_buffer) { 36 if(m_own_leaf_count) { 37 if(a_buffer.map_objs()) a_buffer.remove_in_map(m_leaf_count); 38 delete m_leaf_count; 39 } 40 m_leaf_count = 0; 41 m_own_leaf_count = false; 42 43 int fOffset; 44 bool fIsUnsigned; 45 46 short v; 47 unsigned int _s,_c; 48 if(!a_buffer.read_version(v,_s,_c)) return false; 49 //FIXME if (v > 1) { 50 //TLeaf::Class()->ReadBuffer(b, this, R__v, R__s, R__c); 51 //FIXME } else { 52 //====process old versions before automatic schema evolution 53 if(!Named_stream(a_buffer,m_name,m_title)) return false; 54 55 // Ok with v 1 & 2 56 if(!a_buffer.read(m_length)) return false; 57 if(!a_buffer.read(m_length_type)) return false; 58 if(!a_buffer.read(fOffset)) return false; 59 if(!a_buffer.read(m_is_range)) return false; 60 if(!a_buffer.read(fIsUnsigned)) return false; 61 62 {ifac::args args; 63 iro* obj; 64 bool created; 65 if(!a_buffer.read_object(m_fac,args,obj,created)) { 66 m_out << "tools::rroot::base_leaf::stream :" 67 << " can't read object." 68 << std::endl; 69 return false; 70 } 71 if(!obj) { 72 //m_out << "tools::rroot::base_leaf::stream :" 73 // << " null leaf count object." 74 // << std::endl; 75 } else { 76 m_leaf_count = safe_cast<iro,base_leaf>(*obj); 77 if(!m_leaf_count) { 78 m_out << "tools::rroot::base_leaf::stream :" 79 << " can't cast base_leaf." 80 << std::endl; 81 m_leaf_count = 0; 82 if(created) { 83 if(a_buffer.map_objs()) a_buffer.remove_in_map(obj); 84 delete obj; 85 } 86 return false; 87 } 88 if(created) m_own_leaf_count = true; 89 }} 90 91 if(!a_buffer.check_byte_count(_s,_c,"TLeaf")) return false; 92 93 if(!m_length) m_length = 1; 94 /* 95 fNewValue = false; 96 if(!setAddress(0)) return false; 97 */ 98 return true; 99 } 100 public: 101 virtual bool read_buffer(buffer&) = 0; 102 virtual bool print_value(std::ostream&,uint32) const = 0; 103 virtual uint32 num_elem() const = 0; 104 public: 105 base_leaf(std::ostream& a_out,ifac& a_fac) 106 :m_out(a_out) 107 ,m_fac(a_fac) 108 ,m_name("") 109 ,m_title("") 110 111 //,fIndirectAddress(false) 112 //,fNewValue(false) 113 //,m_ndata(0) 114 ,m_length(0) 115 ,m_length_type(0) 116 //,fOffset(0) 117 ,m_is_range(false) 118 //,fIsUnsigned(false) 119 ,m_leaf_count(0) 120 ,m_own_leaf_count(false) 121 { 122 #ifdef TOOLS_MEM 123 mem::increment(s_class().c_str()); 124 #endif 125 } 126 virtual ~base_leaf(){ 127 if(m_own_leaf_count) delete m_leaf_count; 128 #ifdef TOOLS_MEM 129 mem::decrement(s_class().c_str()); 130 #endif 131 } 132 protected: 133 base_leaf(const base_leaf& a_from) 134 :iro(a_from) 135 ,m_out(a_from.m_out) 136 ,m_fac(a_from.m_fac) 137 //,m_ndata(0) 138 ,m_length(0) 139 ,m_length_type(0) 140 ,m_is_range(false) 141 ,m_leaf_count(0) 142 ,m_own_leaf_count(false) 143 {} 144 base_leaf& operator=(const base_leaf&){return *this;} 145 public: 146 const std::string& name() const {return m_name;} 147 const std::string& title() const {return m_title;} 148 const base_leaf* leaf_count() const {return m_leaf_count;} 149 /* 150 uint32 length() const { 151 // Return the number of effective elements of this leaf. 152 if(m_leaf_count) { 153 m_out << "tools::rroot::base_leaf::length :" 154 << " m_leaf_count not null. Case not yet handled." 155 << std::endl; 156 return m_length; 157 158 //uint32 len = m_leaf_count->number(); 159 //if (len > fLeafCount->maximum()) { 160 // m_out << "tools::rroot::base_leaf::length :" 161 // << fName << ", len=" << len << " and max=" 162 // << fLeafCount->maximum() 163 // << std::endl; 164 // len = fLeafCount->maximum(); 165 //} 166 //return len * fLength; 167 168 } else { 169 return m_length; 170 } 171 } 172 */ 173 protected: 174 std::ostream& m_out; 175 ifac& m_fac; 176 protected: //Named 177 std::string m_name; 178 std::string m_title; 179 //bool fIndirectAddress; 180 //bool fNewValue; 181 //uint32 m_ndata; //! Number of elements in fAddress data buffer 182 uint32 m_length; // Number of fixed length elements 183 uint32 m_length_type; // Number of bytes for this data type 184 //int fOffset; // Offset in ClonesArray object (if one) 185 bool m_is_range; // (=true if leaf has a range, false otherwise) 186 //bool fIsUnsigned; // (=kTRUE if unsigned, kFALSE otherwise) 187 base_leaf* m_leaf_count; // Pointer to Leaf count if variable length 188 bool m_own_leaf_count; 189 }; 190 191 }} 192 193 #endif