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 #include "named"
0008
0009 namespace tools {
0010 namespace rroot {
0011
0012 class base_leaf : public virtual iro {
0013 public:
0014 static const std::string& s_class() {
0015 static const std::string s_v("tools::rroot::base_leaf");
0016 return s_v;
0017 }
0018 public: //iro
0019 virtual void* cast(const std::string& a_class) const {
0020 if(void* p = cmp_cast<base_leaf>(this,a_class)) return p;
0021 return 0;
0022 }
0023 virtual const std::string& s_cls() const {return s_class();}
0024 public:
0025 static cid id_class() {return base_leaf_cid();}
0026 virtual void* cast(cid a_class) const {
0027 if(void* p = cmp_cast<base_leaf>(this,a_class)) {return p;}
0028 else return 0;
0029 }
0030 public:
0031 virtual bool stream(buffer& a_buffer) {
0032 if(m_own_leaf_count) {
0033 if(a_buffer.map_objs()) a_buffer.remove_in_map(m_leaf_count);
0034 delete m_leaf_count;
0035 }
0036 m_leaf_count = 0;
0037 m_own_leaf_count = false;
0038
0039 int fOffset;
0040 bool fIsUnsigned;
0041
0042 short v;
0043 unsigned int _s,_c;
0044 if(!a_buffer.read_version(v,_s,_c)) return false;
0045 //FIXME if (v > 1) {
0046 //TLeaf::Class()->ReadBuffer(b, this, R__v, R__s, R__c);
0047 //FIXME } else {
0048 //====process old versions before automatic schema evolution
0049 if(!Named_stream(a_buffer,m_name,m_title)) return false;
0050
0051 // Ok with v 1 & 2
0052 if(!a_buffer.read(m_length)) return false;
0053 if(!a_buffer.read(m_length_type)) return false;
0054 if(!a_buffer.read(fOffset)) return false;
0055 if(!a_buffer.read(m_is_range)) return false;
0056 if(!a_buffer.read(fIsUnsigned)) return false;
0057
0058 {ifac::args args;
0059 iro* obj;
0060 bool created;
0061 if(!a_buffer.read_object(m_fac,args,obj,created)) {
0062 m_out << "tools::rroot::base_leaf::stream :"
0063 << " can't read object."
0064 << std::endl;
0065 return false;
0066 }
0067 if(!obj) {
0068 } else {
0069 m_leaf_count = safe_cast<iro,base_leaf>(*obj);
0070 if(!m_leaf_count) {
0071 m_out << "tools::rroot::base_leaf::stream :"
0072 << " can't cast base_leaf."
0073 << std::endl;
0074 m_leaf_count = 0;
0075 if(created) {
0076 if(a_buffer.map_objs()) a_buffer.remove_in_map(obj);
0077 delete obj;
0078 }
0079 return false;
0080 }
0081 if(created) m_own_leaf_count = true;
0082 }}
0083
0084 if(!a_buffer.check_byte_count(_s,_c,"TLeaf")) return false;
0085
0086 if(!m_length) m_length = 1;
0087 return true;
0088 }
0089 public:
0090 virtual bool read_buffer(buffer&) = 0;
0091 virtual bool print_value(std::ostream&,uint32) const = 0;
0092 virtual uint32 num_elem() const = 0;
0093 public:
0094 base_leaf(std::ostream& a_out,ifac& a_fac)
0095 :m_out(a_out)
0096 ,m_fac(a_fac)
0097 ,m_name("")
0098 ,m_title("")
0099 ,m_length(0)
0100 ,m_length_type(0)
0101 ,m_is_range(false)
0102 ,m_leaf_count(0)
0103 ,m_own_leaf_count(false)
0104 {
0105 }
0106 virtual ~base_leaf(){
0107 if(m_own_leaf_count) delete m_leaf_count;
0108 }
0109 protected:
0110 base_leaf(const base_leaf& a_from)
0111 :iro(a_from)
0112 ,m_out(a_from.m_out)
0113 ,m_fac(a_from.m_fac)
0114 ,m_length(0)
0115 ,m_length_type(0)
0116 ,m_is_range(false)
0117 ,m_leaf_count(0)
0118 ,m_own_leaf_count(false)
0119 {}
0120 base_leaf& operator=(const base_leaf&){return *this;}
0121 public:
0122 const std::string& name() const {return m_name;}
0123 const std::string& title() const {return m_title;}
0124 const base_leaf* leaf_count() const {return m_leaf_count;}
0125
0126 protected:
0127 std::ostream& m_out;
0128 ifac& m_fac;
0129 protected: //Named
0130 std::string m_name;
0131 std::string m_title;
0132 uint32 m_length; // Number of fixed length elements
0133 uint32 m_length_type; // Number of bytes for this data type
0134 bool m_is_range; // (=true if leaf has a range, false otherwise)
0135 base_leaf* m_leaf_count; // Pointer to Leaf count if variable length
0136 bool m_own_leaf_count;
0137 };
0138
0139 }}
0140
0141 #endif