inlib
1.2.0
|
00001 // Copyright (C) 2010, Guy Barrand. All rights reserved. 00002 // See the file inlib.license for terms. 00003 00004 #ifndef inlib_rroot_base_leaf 00005 #define inlib_rroot_base_leaf 00006 00007 #ifdef INLIB_MEM 00008 #include "../mem" 00009 #endif 00010 00011 #include "named" 00012 00013 namespace inlib { 00014 namespace rroot { 00015 class branch; 00016 }} 00017 00018 namespace inlib { 00019 namespace rroot { 00020 00021 class base_leaf : public virtual iro { 00022 public: 00023 static const std::string& s_class() { 00024 static const std::string s_v("inlib::rroot::base_leaf"); 00025 return s_v; 00026 } 00027 public: //iro 00028 virtual void* cast(const std::string& a_class) const { 00029 if(void* p = inlib::cmp_cast<base_leaf>(this,a_class)) {return p;} 00030 else return 0; 00031 } 00032 virtual bool stream(buffer& a_buffer) { 00033 delete m_leaf_count; 00034 m_leaf_count = 0; 00035 00036 int fLengthType; 00037 int fOffset; 00038 bool fIsRange; 00039 bool fIsUnsigned; 00040 00041 short v; 00042 unsigned int s,c; 00043 if(!a_buffer.read_version(v,s,c)) return false; 00044 //FIXME if (v > 1) { 00045 //TLeaf::Class()->ReadBuffer(b, this, R__v, R__s, R__c); 00046 //FIXME } else { 00047 //====process old versions before automatic schema evolution 00048 if(!Named_stream(a_buffer,m_name,m_title)) return false; 00049 00050 // Ok with v 1 & 2 00051 if(!a_buffer.read(m_length)) return false; 00052 if(!a_buffer.read(fLengthType)) return false; 00053 if(!a_buffer.read(fOffset)) return false; 00054 if(!a_buffer.read(fIsRange)) return false; 00055 if(!a_buffer.read(fIsUnsigned)) return false; 00056 00057 {ifac::args args; 00058 args[ifac::arg_branch()] = &m_branch; 00059 iro* obj; 00060 if(!a_buffer.read_object(m_fac,args,obj)) { 00061 m_out << "inlib::rroot::base_leaf::stream :" 00062 << " can't read object." 00063 << std::endl; 00064 return false; 00065 } 00066 if(!obj) { 00067 //m_out << "inlib::rroot::base_leaf::stream :" 00068 // << " null leaf count object." 00069 // << std::endl; 00070 } else { 00071 m_leaf_count = inlib::cast<iro,base_leaf>(*obj); 00072 if(!m_leaf_count) { 00073 m_out << "inlib::rroot::base_leaf::stream :" 00074 << " can't cast base_leaf." 00075 << std::endl; 00076 m_leaf_count = 0; 00077 delete obj; 00078 return false; 00079 } 00080 }} 00081 00082 if(!a_buffer.check_byte_count(s,c,"TLeaf")) return false; 00083 00084 if(!m_length) m_length = 1; 00085 /* 00086 fNewValue = false; 00087 if(!setAddress(0)) return false; 00088 */ 00089 return true; 00090 } 00091 public: 00092 virtual bool read_basket(buffer&) = 0; 00093 virtual bool print_value(std::ostream&,uint32) const = 0; 00094 virtual uint32 num_elem() const = 0; 00095 virtual const std::string& s_cls() const = 0; 00096 public: 00097 base_leaf(std::ostream& a_out,rroot::branch& a_branch,ifac& a_fac) 00098 :m_out(a_out) 00099 ,m_branch(a_branch) 00100 ,m_fac(a_fac) 00101 ,m_name("") 00102 ,m_title("") 00103 00104 //,fIndirectAddress(false) 00105 //,fNewValue(false) 00106 ,m_ndata(0) 00107 ,m_length(0) 00108 /* 00109 ,fLengthType(0) 00110 ,fOffset(0) 00111 ,fIsRange(false) 00112 ,fIsUnsigned(false) 00113 */ 00114 ,m_leaf_count(0) 00115 { 00116 #ifdef INLIB_MEM 00117 mem::increment(s_class().c_str()); 00118 #endif 00119 } 00120 virtual ~base_leaf(){ 00121 delete m_leaf_count; 00122 #ifdef INLIB_MEM 00123 mem::decrement(s_class().c_str()); 00124 #endif 00125 } 00126 protected: 00127 base_leaf(const base_leaf& a_from) 00128 : iro(a_from) 00129 ,m_out(a_from.m_out) 00130 ,m_branch(a_from.m_branch) 00131 ,m_fac(a_from.m_fac) 00132 {} 00133 base_leaf& operator=(const base_leaf&){return *this;} 00134 public: 00135 rroot::branch& branch() {return m_branch;} 00136 const std::string& name() const {return m_name;} 00137 const std::string& title() const {return m_title;} 00138 /* 00139 uint32 length() const { 00140 // Return the number of effective elements of this leaf. 00141 if(m_leaf_count) { 00142 m_out << "inlib::rroot::base_leaf::length :" 00143 << " m_leaf_count not null. Case not yet handled." 00144 << std::endl; 00145 return m_length; 00146 00147 //uint32 len = m_leaf_count->number(); 00148 //if (len > fLeafCount->maximum()) { 00149 // m_out << "inlib::rroot::base_leaf::length :" 00150 // << fName << ", len=" << len << " and max=" 00151 // << fLeafCount->maximum() 00152 // << std::endl; 00153 // len = fLeafCount->maximum(); 00154 //} 00155 //return len * fLength; 00156 00157 } else { 00158 return m_length; 00159 } 00160 } 00161 */ 00162 protected: 00163 std::ostream& m_out; 00164 rroot::branch& m_branch; 00165 ifac& m_fac; 00166 protected: //Named 00167 std::string m_name; 00168 std::string m_title; 00169 //bool fIndirectAddress; 00170 //bool fNewValue; 00171 uint32 m_ndata; 00172 uint32 m_length; // Number of fixed length elements 00173 /* 00174 int fLengthType; // Number of bytes for this data type 00175 int fOffset; // Offset in ClonesArray object (if one) 00176 bool fIsRange; // (=true if leaf has a range, false otherwise) 00177 bool fIsUnsigned; // (=kTRUE if unsigned, kFALSE otherwise) 00178 */ 00179 base_leaf* m_leaf_count; // Pointer to Leaf count if variable length 00180 }; 00181 00182 }} 00183 00184 #endif