g4tools  5.4.0
base_leaf
Go to the documentation of this file.
1 // Copyright (C) 2010, Guy Barrand. All rights reserved.
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::base_leaf");
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_class)) {return p;}
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",m_name.c_str());
38  //::printf("debug : m_length %d\n",m_length);
39  //::printf("debug : m_is_range %d\n",m_is_range);
40  //::printf("debug : m_leaf_count %lu\n",m_leaf_count);
41  unsigned int c;
42  if(!a_buffer.write_version(2,c)) return false;
43  if(!Named_stream(a_buffer,m_name,m_title)) return false;
44  if(!a_buffer.write(m_length)) return false;
45  if(!a_buffer.write(m_length_type)) return false;
46  uint32 fOffset = 0;
47  if(!a_buffer.write(fOffset)) return false;
48  if(!a_buffer.write(m_is_range)) return false;
49  bool fIsUnsigned = false;
50  if(!a_buffer.write(fIsUnsigned)) return false;
51 
52  if(m_leaf_count) {
53  if(!a_buffer.write_object(*m_leaf_count)) return false;
54  } else {
55  if(!a_buffer.write(kNullTag())) return false;
56  }
57 
58  if(!a_buffer.set_byte_count(c)) return false;
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::string& a_name,const std::string& a_title)
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&){return *this;}
93 public:
94  const std::string& name() const {return m_name;}
95  //const std::string& title() const {return m_title;}
96  void set_title(const std::string& a_value) {m_title = a_value;}
97  uint32 length() const {return m_length;}
98  void set_length(uint32 a_value) {m_length = a_value;}
99  void set_is_range(bool a_value) {m_is_range = a_value;}
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 fixed length elements
106  uint32 m_length_type; // Number of bytes for this data type
109 };
110 
111 }}
112 
113 #endif
tools::wroot::base_leaf::id_cls
virtual cid id_cls() const
Definition: base_leaf:34
tools::wroot::base_leaf::m_name
std::string m_name
Definition: base_leaf:103
tools::wroot::base_leaf::id_class
static cid id_class()
Definition: base_leaf:29
tools::wroot::base_leaf::~base_leaf
virtual ~base_leaf()
Definition: base_leaf:78
tools::wroot::ibo
Definition: ibo:17
tools::wroot::buffer::write_object
bool write_object(const ibo &a_obj)
Definition: buffer:231
tools::wroot::base_leaf_cid
cid base_leaf_cid()
Definition: cids:20
named
tools::wroot::buffer::set_byte_count
bool set_byte_count(uint32 a_pos)
Definition: buffer:199
tools::wroot::base_leaf::length
uint32 length() const
Definition: base_leaf:97
tools::wroot::Named_stream
bool Named_stream(buffer &a_buffer, const std::string &a_name, const std::string &a_title)
Definition: named:23
tools::wroot::base_leaf::set_length
void set_length(uint32 a_value)
Definition: base_leaf:98
tools::wroot::base_leaf::set_title
void set_title(const std::string &a_value)
Definition: base_leaf:96
tools::wroot::base_leaf::cast
virtual void * cast(cid a_class) const
Definition: base_leaf:30
tools::wroot::base_leaf
Definition: base_leaf:19
tools::wroot::buffer::write_version
bool write_version(short a_version)
Definition: buffer:169
tools::wroot::buffer::write
bool write(T x)
Definition: buffer:97
tools::wroot::base_leaf::set_is_range
void set_is_range(bool a_value)
Definition: base_leaf:99
tools::wroot::base_leaf::operator=
base_leaf & operator=(const base_leaf &)
Definition: base_leaf:92
tools::wroot::base_leaf::m_length
uint32 m_length
Definition: base_leaf:105
tools
inlined C code : ///////////////////////////////////
Definition: aida_ntuple:26
tools::wroot::base_leaf::m_out
std::ostream & m_out
Definition: base_leaf:101
tools::wroot::base_leaf::m_length_type
uint32 m_length_type
Definition: base_leaf:106
tools::wroot::base_leaf::fill_buffer
virtual bool fill_buffer(buffer &) const =0
tools::wroot::buffer
Definition: buffer:28
tools::wroot::base_leaf::name
const std::string & name() const
Definition: base_leaf:94
tools::wroot::base_leaf::stream
virtual bool stream(buffer &a_buffer) const
Definition: base_leaf:36
cids
tools::wroot::base_leaf::m_is_range
bool m_is_range
Definition: base_leaf:108
tools::wroot::base_leaf::base_leaf
base_leaf(std::ostream &a_out, const std::string &a_name, const std::string &a_title)
Definition: base_leaf:64
tools::uint32
unsigned int uint32
Definition: typedefs:71
tools::wroot::base_leaf::m_leaf_count
ibo * m_leaf_count
Definition: base_leaf:107
tools::wroot::base_leaf::m_title
std::string m_title
Definition: base_leaf:104
tools::cid
unsigned short cid
Definition: cid:9
tools::wroot::base_leaf::base_leaf
base_leaf(const base_leaf &a_from)
Definition: base_leaf:84