Warning, /include/Geant4/tools/rroot/base_leaf is written in an unsupported language. File is not indexed.
0001 // Copyright (C) 2010, Guy Barrand. All rights reserved.
0002 // See the file tools.license for terms.
0003
0004 #ifndef tools_rroot_base_leaf
0005 #define tools_rroot_base_leaf
0006
0007 #ifdef TOOLS_MEM
0008 #include "../mem"
0009 #endif
0010
0011 #include "named"
0012
0013 namespace tools {
0014 namespace rroot {
0015
0016 class base_leaf : public virtual iro {
0017 public:
0018 static const std::string& s_class() {
0019 static const std::string s_v("tools::rroot::base_leaf");
0020 return s_v;
0021 }
0022 public: //iro
0023 virtual void* cast(const std::string& a_class) const {
0024 if(void* p = cmp_cast<base_leaf>(this,a_class)) return p;
0025 return 0;
0026 }
0027 virtual const std::string& s_cls() const {return s_class();}
0028 public:
0029 static cid id_class() {return base_leaf_cid();}
0030 virtual void* cast(cid a_class) const {
0031 if(void* p = cmp_cast<base_leaf>(this,a_class)) {return p;}
0032 else return 0;
0033 }
0034 public:
0035 virtual bool stream(buffer& a_buffer) {
0036 if(m_own_leaf_count) {
0037 if(a_buffer.map_objs()) a_buffer.remove_in_map(m_leaf_count);
0038 delete m_leaf_count;
0039 }
0040 m_leaf_count = 0;
0041 m_own_leaf_count = false;
0042
0043 int fOffset;
0044 bool fIsUnsigned;
0045
0046 short v;
0047 unsigned int _s,_c;
0048 if(!a_buffer.read_version(v,_s,_c)) return false;
0049 //FIXME if (v > 1) {
0050 //TLeaf::Class()->ReadBuffer(b, this, R__v, R__s, R__c);
0051 //FIXME } else {
0052 //====process old versions before automatic schema evolution
0053 if(!Named_stream(a_buffer,m_name,m_title)) return false;
0054
0055 // Ok with v 1 & 2
0056 if(!a_buffer.read(m_length)) return false;
0057 if(!a_buffer.read(m_length_type)) return false;
0058 if(!a_buffer.read(fOffset)) return false;
0059 if(!a_buffer.read(m_is_range)) return false;
0060 if(!a_buffer.read(fIsUnsigned)) return false;
0061
0062 {ifac::args args;
0063 iro* obj;
0064 bool created;
0065 if(!a_buffer.read_object(m_fac,args,obj,created)) {
0066 m_out << "tools::rroot::base_leaf::stream :"
0067 << " can't read object."
0068 << std::endl;
0069 return false;
0070 }
0071 if(!obj) {
0072 //m_out << "tools::rroot::base_leaf::stream :"
0073 // << " null leaf count object."
0074 // << std::endl;
0075 } else {
0076 m_leaf_count = safe_cast<iro,base_leaf>(*obj);
0077 if(!m_leaf_count) {
0078 m_out << "tools::rroot::base_leaf::stream :"
0079 << " can't cast base_leaf."
0080 << std::endl;
0081 m_leaf_count = 0;
0082 if(created) {
0083 if(a_buffer.map_objs()) a_buffer.remove_in_map(obj);
0084 delete obj;
0085 }
0086 return false;
0087 }
0088 if(created) m_own_leaf_count = true;
0089 }}
0090
0091 if(!a_buffer.check_byte_count(_s,_c,"TLeaf")) return false;
0092
0093 if(!m_length) m_length = 1;
0094 /*
0095 fNewValue = false;
0096 if(!setAddress(0)) return false;
0097 */
0098 return true;
0099 }
0100 public:
0101 virtual bool read_buffer(buffer&) = 0;
0102 virtual bool print_value(std::ostream&,uint32) const = 0;
0103 virtual uint32 num_elem() const = 0;
0104 public:
0105 base_leaf(std::ostream& a_out,ifac& a_fac)
0106 :m_out(a_out)
0107 ,m_fac(a_fac)
0108 ,m_name("")
0109 ,m_title("")
0110
0111 //,fIndirectAddress(false)
0112 //,fNewValue(false)
0113 //,m_ndata(0)
0114 ,m_length(0)
0115 ,m_length_type(0)
0116 //,fOffset(0)
0117 ,m_is_range(false)
0118 //,fIsUnsigned(false)
0119 ,m_leaf_count(0)
0120 ,m_own_leaf_count(false)
0121 {
0122 #ifdef TOOLS_MEM
0123 mem::increment(s_class().c_str());
0124 #endif
0125 }
0126 virtual ~base_leaf(){
0127 if(m_own_leaf_count) delete m_leaf_count;
0128 #ifdef TOOLS_MEM
0129 mem::decrement(s_class().c_str());
0130 #endif
0131 }
0132 protected:
0133 base_leaf(const base_leaf& a_from)
0134 :iro(a_from)
0135 ,m_out(a_from.m_out)
0136 ,m_fac(a_from.m_fac)
0137 //,m_ndata(0)
0138 ,m_length(0)
0139 ,m_length_type(0)
0140 ,m_is_range(false)
0141 ,m_leaf_count(0)
0142 ,m_own_leaf_count(false)
0143 {}
0144 base_leaf& operator=(const base_leaf&){return *this;}
0145 public:
0146 const std::string& name() const {return m_name;}
0147 const std::string& title() const {return m_title;}
0148 const base_leaf* leaf_count() const {return m_leaf_count;}
0149 /*
0150 uint32 length() const {
0151 // Return the number of effective elements of this leaf.
0152 if(m_leaf_count) {
0153 m_out << "tools::rroot::base_leaf::length :"
0154 << " m_leaf_count not null. Case not yet handled."
0155 << std::endl;
0156 return m_length;
0157
0158 //uint32 len = m_leaf_count->number();
0159 //if (len > fLeafCount->maximum()) {
0160 // m_out << "tools::rroot::base_leaf::length :"
0161 // << fName << ", len=" << len << " and max="
0162 // << fLeafCount->maximum()
0163 // << std::endl;
0164 // len = fLeafCount->maximum();
0165 //}
0166 //return len * fLength;
0167
0168 } else {
0169 return m_length;
0170 }
0171 }
0172 */
0173 protected:
0174 std::ostream& m_out;
0175 ifac& m_fac;
0176 protected: //Named
0177 std::string m_name;
0178 std::string m_title;
0179 //bool fIndirectAddress;
0180 //bool fNewValue;
0181 //uint32 m_ndata; //! Number of elements in fAddress data buffer
0182 uint32 m_length; // Number of fixed length elements
0183 uint32 m_length_type; // Number of bytes for this data type
0184 //int fOffset; // Offset in ClonesArray object (if one)
0185 bool m_is_range; // (=true if leaf has a range, false otherwise)
0186 //bool fIsUnsigned; // (=kTRUE if unsigned, kFALSE otherwise)
0187 base_leaf* m_leaf_count; // Pointer to Leaf count if variable length
0188 bool m_own_leaf_count;
0189 };
0190
0191 }}
0192
0193 #endif