Geant4 Cross Reference |
1 // Copyright (C) 2010, Guy Barrand. All rights 2 // See the file tools.license for terms. 3 4 #ifndef tools_wroot_base_leaf 5 #define tools_wroot_base_leaf 6 7 #ifdef TOOLS_MEM 8 #include "../mem" 9 #endif 10 11 #include "named" 12 13 #include "cids" 14 #include "../scast" 15 16 namespace tools { 17 namespace wroot { 18 19 class base_leaf : public virtual ibo { 20 static unsigned int kNullTag() {return 0;} 21 #ifdef TOOLS_MEM 22 public: 23 static const std::string& s_class() { 24 static const std::string s_v("tools::wroot 25 return s_v; 26 } 27 #endif 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_cl 32 else return 0; 33 } 34 virtual cid id_cls() const {return id_class( 35 public: //ibo 36 virtual bool stream(buffer& a_buffer) const 37 //::printf("debug : base_leaf::stream %s\n 38 //::printf("debug : m_length %d\n",m_len 39 //::printf("debug : m_is_range %d\n",m_i 40 //::printf("debug : m_leaf_count %lu\n", 41 unsigned int c; 42 if(!a_buffer.write_version(2,c)) return fa 43 if(!Named_stream(a_buffer,m_name,m_title)) 44 if(!a_buffer.write(m_length)) return false 45 if(!a_buffer.write(m_length_type)) return 46 uint32 fOffset = 0; 47 if(!a_buffer.write(fOffset)) return false; 48 if(!a_buffer.write(m_is_range)) return fal 49 bool fIsUnsigned = false; 50 if(!a_buffer.write(fIsUnsigned)) return fa 51 52 if(m_leaf_count) { 53 if(!a_buffer.write_object(*m_leaf_count) 54 } else { 55 if(!a_buffer.write(kNullTag())) return f 56 } 57 58 if(!a_buffer.set_byte_count(c)) return fal 59 return true; 60 } 61 public: 62 virtual bool fill_buffer(buffer&) const = 0; 63 public: 64 base_leaf(std::ostream& a_out,const std::str 65 :m_out(a_out) 66 ,m_name(a_name) 67 ,m_title(a_title) 68 69 ,m_length(0) 70 ,m_length_type(0) 71 ,m_leaf_count(0) 72 ,m_is_range(false) 73 { 74 #ifdef TOOLS_MEM 75 mem::increment(s_class().c_str()); 76 #endif 77 } 78 virtual ~base_leaf(){ 79 #ifdef TOOLS_MEM 80 mem::decrement(s_class().c_str()); 81 #endif 82 } 83 protected: 84 base_leaf(const base_leaf& a_from) 85 :ibo(a_from) 86 ,m_out(a_from.m_out) 87 ,m_length(0) 88 ,m_length_type(0) 89 ,m_leaf_count(0) 90 ,m_is_range(false) 91 {} 92 base_leaf& operator=(const base_leaf&){retur 93 public: 94 const std::string& name() const {return m_na 95 //const std::string& title() const {return m 96 void set_title(const std::string& a_value) { 97 uint32 length() const {return m_length;} 98 void set_length(uint32 a_value) {m_length = 99 void set_is_range(bool a_value) {m_is_range 100 protected: 101 std::ostream& m_out; 102 protected: //Named 103 std::string m_name; 104 std::string m_title; 105 uint32 m_length; // Number of fixe 106 uint32 m_length_type; // Number of byte 107 ibo* m_leaf_count; 108 bool m_is_range; 109 }; 110 111 }} 112 113 #endif