g4tools  5.4.0
named
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_rroot_named
5 #define tools_rroot_named
6 
7 #include "object"
8 #include "../scast"
9 #include "../vdata"
10 #include "cids"
11 
12 namespace tools {
13 namespace rroot {
14 
15 inline bool Named_stream(buffer& a_buffer,std::string& a_name,std::string& a_title) {
16  short v;
17  unsigned int s, c;
18  if(!a_buffer.read_version(v,s,c)) return false;
19  {uint32 id,bits;
20  if(!Object_stream(a_buffer,id,bits)) return false;}
21  if(!a_buffer.read(a_name)) return false;
22  if(!a_buffer.read(a_title)) return false;
23  if(!a_buffer.check_byte_count(s,c,"TNamed")) return false;
24  return true;
25 }
26 
27 inline bool AttLine_stream(buffer& a_buffer,short& a_color,short& a_style,short& a_width){
28  short v;
29  unsigned int s, c;
30  if(!a_buffer.read_version(v,s,c)) return false;
31  if(!a_buffer.read(a_color)) return false;
32  if(!a_buffer.read(a_style)) return false;
33  if(!a_buffer.read(a_width)) return false;
34  if(!a_buffer.check_byte_count(s,c,"TAttLine")) return false;
35  return true;
36 }
37 
38 inline bool AttFill_stream(buffer& a_buffer,short& a_color,short& a_style){
39  short v;
40  unsigned int s, c;
41  if(!a_buffer.read_version(v,s,c)) return false;
42  if(!a_buffer.read(a_color)) return false;
43  if(!a_buffer.read(a_style)) return false;
44  if(!a_buffer.check_byte_count(s,c,"TAttFill")) return false;
45  return true;
46 }
47 
48 inline bool AttMarker_stream(buffer& a_buffer) {
49  short fMarkerColor;
50  short fMarkerStyle;
51  float fMarkerWidth;
52  short v;
53  unsigned int s, c;
54  if(!a_buffer.read_version(v,s,c)) return false;
55  if(!a_buffer.read(fMarkerColor)) return false;
56  if(!a_buffer.read(fMarkerStyle)) return false;
57  if(!a_buffer.read(fMarkerWidth)) return false;
58  if(!a_buffer.check_byte_count(s,c,"TAttMarker")) return false;
59  return true;
60 }
61 
62 inline bool GeoAtt_stream(buffer& a_buffer) {
63  unsigned int fGeoAtt; // option flags
64  short v;
65  unsigned int s, c;
66  if(!a_buffer.read_version(v,s,c)) return false;
67  if(!a_buffer.read(fGeoAtt)) return false;
68  if(!a_buffer.check_byte_count(s,c,"TGeoAtt")) return false;
69  return true;
70 }
71 
72 inline bool Att3D_stream(buffer& a_buffer) {
73  short v;
74  unsigned int s, c;
75  if(!a_buffer.read_version(v,s,c)) return false;
76  if(!a_buffer.check_byte_count(s,c,"TAtt3D")) return false;
77  return true;
78 }
79 
80 template <class T>
81 inline bool Array_stream(buffer& a_buffer,std::vector<T>& a_v) {
82  a_v.clear();
83  int sz;
84  if(!a_buffer.read(sz)) return false;
85  //check sz is not crazy :
86  if(!a_buffer.check_eob(sz)) return false;
87  a_v.resize(sz);
88  if(!a_buffer.read_fast_array<T>(vec_data(a_v),sz)) return false;
89  return true;
90 }
91 
92 template <class T>
93 inline bool dummy_array_stream(buffer& a_buffer,int a_n){
94  char is_array;
95  if(!a_buffer.read(is_array)) return false;
96  if(!is_array) return true;
97  if(!a_n) return true;
98  T* v = new T[a_n];
99  bool status = a_buffer.read_fast_array<T>(v,a_n);
100  delete [] v;
101  return status;
102 }
103 
104 class named : public virtual iro {
105  static const std::string& s_store_class() {
106  static const std::string s_v("TNamed");
107  return s_v;
108  }
109 public:
110  static const std::string& s_class() {
111  static const std::string s_v("tools::rroot::named");
112  return s_v;
113  }
114 public: //iro
115  virtual void* cast(const std::string& a_class) const {
116  if(void* p = cmp_cast<named>(this,a_class)) return p;
117  return 0;
118  }
119  virtual const std::string& s_cls() const {return s_class();}
120 public:
121  static cid id_class() {return named_cid();}
122  virtual void* cast(cid a_class) const {
123  if(void* p = cmp_cast<named>(this,a_class)) {return p;}
124  else return 0;
125  }
126  //virtual void* cast(cid) const {return named_cid();}
127 public:
128  virtual iro* copy() const {return new named(*this);}
129  virtual bool stream(buffer& a_buffer) {
130  return Named_stream(a_buffer,m_name,m_title);
131  }
132 public:
133  named() {
134 #ifdef TOOLS_MEM
135  mem::increment(s_class().c_str());
136 #endif
137  }
138  virtual ~named() {
139 #ifdef TOOLS_MEM
140  mem::decrement(s_class().c_str());
141 #endif
142  }
143 protected:
144  named(const named& a_from):iro(a_from),m_name(a_from.m_name),m_title(a_from.m_title) {
145 #ifdef TOOLS_MEM
146  mem::increment(s_class().c_str());
147 #endif
148  }
149  named& operator=(const named& a_from){
150  m_name = a_from.m_name;
151  m_title = a_from.m_title;
152  return *this;
153  }
154 protected:
155  std::string m_name;
156  std::string m_title;
157 };
158 
159 }}
160 
161 #endif
tools::rroot::AttMarker_stream
bool AttMarker_stream(buffer &a_buffer)
Definition: named:48
tools::rroot::Object_stream
bool Object_stream(buffer &a_buffer, uint32 &a_id, uint32 &a_bits)
Definition: object:12
tools::rroot::rbuf::read_fast_array
bool read_fast_array(bool *b, uint32 n)
Definition: rbuf:261
tools::rroot::named::cast
virtual void * cast(const std::string &a_class) const
Definition: named:115
tools::rroot::buffer::check_byte_count
bool check_byte_count(uint32 a_start_pos, uint32 a_byte_count, const std::string &a_store_cls)
Definition: buffer:568
tools::vec_data
const T * vec_data(const std::vector< T > &a_vec)
Definition: vdata:18
tools::rroot::AttLine_stream
bool AttLine_stream(buffer &a_buffer, short &a_color, short &a_style, short &a_width)
Definition: named:27
tools::rroot::named::operator=
named & operator=(const named &a_from)
Definition: named:149
tools::rroot::Named_stream
bool Named_stream(buffer &a_buffer, std::string &a_name, std::string &a_title)
Definition: named:15
tools::rroot::named::cast
virtual void * cast(cid a_class) const
Definition: named:122
tools::rroot::named::~named
virtual ~named()
Definition: named:138
tools::rroot::named::m_title
std::string m_title
Definition: named:156
tools::rroot::named::copy
virtual iro * copy() const
Definition: named:128
tools::rroot::named::m_name
std::string m_name
Definition: named:155
tools::rroot::buffer::read_version
bool read_version(short &a_version)
Definition: buffer:503
tools::rroot::named::s_class
static const std::string & s_class()
Definition: named:110
tools::rroot::AttFill_stream
bool AttFill_stream(buffer &a_buffer, short &a_color, short &a_style)
Definition: named:38
tools::rroot::Array_stream
bool Array_stream(buffer &a_buffer, std::vector< T > &a_v)
Definition: named:81
tools::rroot::rbuf::check_eob
bool check_eob(uint32 n)
Definition: rbuf:375
tools::rroot::named_cid
cid named_cid()
Definition: cids:39
tools::rroot::named::named
named()
Definition: named:133
tools
inlined C code : ///////////////////////////////////
Definition: aida_ntuple:26
tools::rroot::named::stream
virtual bool stream(buffer &a_buffer)
Definition: named:129
tools::rroot::dummy_array_stream
bool dummy_array_stream(buffer &a_buffer, int a_n)
Definition: named:93
tools::rroot::buffer
Definition: buffer:43
tools::rroot::named::id_class
static cid id_class()
Definition: named:121
tools::rroot::GeoAtt_stream
bool GeoAtt_stream(buffer &a_buffer)
Definition: named:62
tools::rroot::rbuf::read
bool read(unsigned char &a_x)
Definition: rbuf:146
tools::rroot::Att3D_stream
bool Att3D_stream(buffer &a_buffer)
Definition: named:72
tools::rroot::iro
Definition: iro:19
cids
tools::rroot::named::named
named(const named &a_from)
Definition: named:144
object
tools::uint32
unsigned int uint32
Definition: typedefs:71
tools::rroot::named
Definition: named:104
tools::rroot::named::s_cls
virtual const std::string & s_cls() const
Definition: named:119
tools::cid
unsigned short cid
Definition: cid:9