g4tools  5.4.0
Public Types | Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
tools::rroot::leaf< T > Class Template Reference
Inheritance diagram for tools::rroot::leaf< T >:
Inheritance graph
[legend]
Collaboration diagram for tools::rroot::leaf< T >:
Collaboration graph
[legend]

Public Types

typedef T value_t
 

Public Member Functions

virtual void * cast (const std::string &a_class) const
 
virtual const std::string & s_cls () const
 
virtual void * cast (cid a_class) const
 
virtual irocopy () const
 
virtual bool stream (buffer &a_buffer)
 
virtual bool read_buffer (buffer &a_buffer)
 
virtual bool print_value (std::ostream &a_out, uint32 a_index) const
 
virtual uint32 num_elem () const
 
 leaf (std::ostream &a_out, ifac &a_fac)
 
virtual ~leaf ()
 
bool value (uint32 a_index, T &a_value) const
 
bool value (std::vector< T > &a_v) const
 
get_max () const
 
- Public Member Functions inherited from tools::rroot::base_leaf
 base_leaf (std::ostream &a_out, ifac &a_fac)
 
virtual ~base_leaf ()
 
const std::string & name () const
 
const std::string & title () const
 
const base_leafleaf_count () const
 
- Public Member Functions inherited from tools::rroot::iro
virtual ~iro ()
 

Static Public Member Functions

static const std::string & s_class ()
 
static cid id_class ()
 
- Static Public Member Functions inherited from tools::rroot::base_leaf
static const std::string & s_class ()
 
static cid id_class ()
 

Protected Member Functions

 leaf (const leaf &a_from)
 
leafoperator= (const leaf &)
 
- Protected Member Functions inherited from tools::rroot::base_leaf
 base_leaf (const base_leaf &a_from)
 
base_leafoperator= (const base_leaf &)
 

Protected Attributes

m_min
 
m_max
 
T * m_value
 
uint32 m_size
 Pointer to data buffer. More...
 
- Protected Attributes inherited from tools::rroot::base_leaf
std::ostream & m_out
 
ifacm_fac
 
std::string m_name
 
std::string m_title
 
uint32 m_length
 
uint32 m_length_type
 
bool m_is_range
 
base_leafm_leaf_count
 
bool m_own_leaf_count
 

Detailed Description

template<class T>
class tools::rroot::leaf< T >

Definition at line 57 of file leaf.

Member Typedef Documentation

◆ value_t

template<class T >
typedef T tools::rroot::leaf< T >::value_t

Definition at line 59 of file leaf.

Constructor & Destructor Documentation

◆ leaf() [1/2]

template<class T >
tools::rroot::leaf< T >::leaf ( std::ostream &  a_out,
ifac a_fac 
)
inline

Definition at line 169 of file leaf.

170  :base_leaf(a_out,a_fac)
171  ,m_min(T()),m_max(T())
172  ,m_value(0),m_size(0)
173  {}

◆ ~leaf()

template<class T >
virtual tools::rroot::leaf< T >::~leaf ( )
inlinevirtual

Definition at line 174 of file leaf.

174  {
175  delete [] m_value;
176  }

◆ leaf() [2/2]

template<class T >
tools::rroot::leaf< T >::leaf ( const leaf< T > &  a_from)
inlineprotected

Definition at line 178 of file leaf.

179  :iro(a_from)
180  ,base_leaf(a_from)
181  ,m_min(T()),m_max(T())
182  ,m_value(0),m_size(0)
183  {}

Member Function Documentation

◆ cast() [1/2]

template<class T >
virtual void* tools::rroot::leaf< T >::cast ( cid  a_class) const
inlinevirtual

Reimplemented from tools::rroot::base_leaf.

Definition at line 73 of file leaf.

73  {
74  if(void* p = cmp_cast<leaf>(this,a_class)) {return p;}
75  return base_leaf::cast(a_class);
76  }

◆ cast() [2/2]

template<class T >
virtual void* tools::rroot::leaf< T >::cast ( const std::string &  a_class) const
inlinevirtual

Reimplemented from tools::rroot::base_leaf.

Definition at line 66 of file leaf.

66  {
67  if(void* p = cmp_cast< leaf<T> >(this,a_class)) {return p;}
68  return base_leaf::cast(a_class);
69  }

◆ copy()

template<class T >
virtual iro* tools::rroot::leaf< T >::copy ( ) const
inlinevirtual

Implements tools::rroot::iro.

Definition at line 78 of file leaf.

78 {return new leaf<T>(*this);}

◆ get_max()

template<class T >
T tools::rroot::leaf< T >::get_max ( ) const
inline

Definition at line 198 of file leaf.

198 {return m_max;}

◆ id_class()

template<class T >
static cid tools::rroot::leaf< T >::id_class ( )
inlinestatic

Definition at line 72 of file leaf.

72 {return base_leaf_cid()+_cid(T());}

◆ num_elem()

template<class T >
virtual uint32 tools::rroot::leaf< T >::num_elem ( ) const
inlinevirtual

Implements tools::rroot::base_leaf.

Definition at line 167 of file leaf.

167 {return m_size;}

◆ operator=()

template<class T >
leaf& tools::rroot::leaf< T >::operator= ( const leaf< T > &  )
inlineprotected

Definition at line 184 of file leaf.

184 {return *this;}

◆ print_value()

template<class T >
virtual bool tools::rroot::leaf< T >::print_value ( std::ostream &  a_out,
uint32  a_index 
) const
inlinevirtual

Implements tools::rroot::base_leaf.

Definition at line 160 of file leaf.

160  {
161  if(!m_value) return false;
162  if(a_index>=m_size) return false;
163  a_out << m_value[a_index];
164  return true;
165  }

◆ read_buffer()

template<class T >
virtual bool tools::rroot::leaf< T >::read_buffer ( buffer a_buffer)
inlinevirtual

Implements tools::rroot::base_leaf.

Definition at line 90 of file leaf.

90  {
91  if(m_leaf_count) {
92  leaf<int>* leaf_i = safe_cast<base_leaf, leaf<int> >(*m_leaf_count);
93  if(!leaf_i) {
94  m_out << "tools::rroot::leaf::read_buffer : leaf_count not a leaf<int>." << std::endl;
95  return false;
96  }
97  int len;
98  if(!leaf_i->value(0,len)) {
99  m_out << "tools::rroot::leaf::read_buffer : leaf<int>.value() failed."
100  << " m_leaf_count " << m_leaf_count
101  << " leaf_i " << leaf_i
102  << " Name " << sout(leaf_i->name())
103  << " Size " << leaf_i->num_elem() << std::endl;
104  return false;
105  }
106 
107  if (len > leaf_i->get_max()) { //protection.
108  m_out << "tools::rroot::leaf::read_buffer : warning : " << sout(name())
109  << ", len = " << len << " > max = "
110  << leaf_i->get_max() << std::endl;
111  len = leaf_i->get_max();
112  }
113 
114  uint32 ndata = len * m_length;
115 
116  //if(!ndata) {
117  // delete [] m_value;
118  // m_value = new T[1];
119  // m_size = 0;
120  // return true;
121  //}
122 
123  if(ndata>m_size) {
124  delete [] m_value;
125  m_value = new T[ndata];
126  }
127 
128  m_size = ndata;
129  if(!a_buffer.read_fast_array(m_value,ndata)) {
130  m_out << "tools::rroot::leaf::read_buffer : \"" << name() << "\" :"
131  << " read_fast_array failed."
132  << std::endl;
133  return false;
134  }
135  return true;
136 
137  } else {
138  if(m_length) {
139  if(m_length>m_size) {
140  delete [] m_value;
141  m_value = new T[m_length];
142  }
143  m_size = m_length;
144  if(!a_buffer.read_fast_array<T>(m_value,m_length)) {
145  m_out << "tools::rroot::leaf::read_buffer :"
146  << " read_fast_array failed. m_length " << m_length
147  << std::endl;
148  return false;
149  }
150  return true;
151  } else {
152  m_out << "tools::rroot::leaf::read_buffer :"
153  << " read_fast_array failed. m_length is zero."
154  << std::endl;
155  return false;
156  }
157  }
158  return true;
159  }

◆ s_class()

template<class T >
static const std::string& tools::rroot::leaf< T >::s_class ( )
inlinestatic

Definition at line 61 of file leaf.

61  {
62  static const std::string s_v("tools::rroot::leaf<"+stype(T())+">");
63  return s_v;
64  }

◆ s_cls()

template<class T >
virtual const std::string& tools::rroot::leaf< T >::s_cls ( ) const
inlinevirtual

Reimplemented from tools::rroot::base_leaf.

Definition at line 70 of file leaf.

70 {return s_class();}

◆ stream()

template<class T >
virtual bool tools::rroot::leaf< T >::stream ( buffer a_buffer)
inlinevirtual

Reimplemented from tools::rroot::base_leaf.

Definition at line 79 of file leaf.

79  {
80  short v;
81  unsigned int s,c;
82  if(!a_buffer.read_version(v,s,c)) return false;
83  if(!base_leaf::stream(a_buffer)) return false;
84  if(!a_buffer.read(m_min)) return false;
85  if(!a_buffer.read(m_max)) return false;
86  if(!a_buffer.check_byte_count(s,c,leaf_store_class(T()))) return false;
87  return true;
88  }

◆ value() [1/2]

template<class T >
bool tools::rroot::leaf< T >::value ( std::vector< T > &  a_v) const
inline

Definition at line 192 of file leaf.

192  {
193  if(!m_value) {a_v.clear();return false;}
194  a_v.resize(m_size);
195  for(uint32 index=0;index<m_size;index++) a_v[index] = m_value[index];
196  return true;
197  }

◆ value() [2/2]

template<class T >
bool tools::rroot::leaf< T >::value ( uint32  a_index,
T &  a_value 
) const
inline

Definition at line 186 of file leaf.

186  {
187  if(!m_value) {a_value = T();return false;}
188  if(a_index>=m_size) {a_value = T();return false;}
189  a_value = m_value[a_index];
190  return true;
191  }

Member Data Documentation

◆ m_max

template<class T >
T tools::rroot::leaf< T >::m_max
protected

Definition at line 202 of file leaf.

◆ m_min

template<class T >
T tools::rroot::leaf< T >::m_min
protected

Definition at line 201 of file leaf.

◆ m_size

template<class T >
uint32 tools::rroot::leaf< T >::m_size
protected

Pointer to data buffer.

Definition at line 204 of file leaf.

◆ m_value

template<class T >
T* tools::rroot::leaf< T >::m_value
protected

Definition at line 203 of file leaf.


The documentation for this class was generated from the following file:
tools::rroot::base_leaf::m_out
std::ostream & m_out
Definition: base_leaf:174
tools::_cid
cid _cid(byte)
Definition: cids:14
tools::rroot::leaf::m_value
T * m_value
Definition: leaf:203
tools::rroot::leaf::m_size
uint32 m_size
Pointer to data buffer.
Definition: leaf:204
tools::rroot::base_leaf::name
const std::string & name() const
Definition: base_leaf:146
tools::rroot::base_leaf::num_elem
virtual uint32 num_elem() const =0
tools::rroot::leaf_store_class
const std::string & leaf_store_class(char)
Definition: leaf:14
tools::rroot::base_leaf_cid
cid base_leaf_cid()
Definition: cids:45
tools::rroot::base_leaf::m_leaf_count
base_leaf * m_leaf_count
Definition: base_leaf:187
tools::rroot::base_leaf::m_length
uint32 m_length
Definition: base_leaf:182
tools::rroot::leaf::m_max
T m_max
Definition: leaf:202
tools::rroot::base_leaf::stream
virtual bool stream(buffer &a_buffer)
Definition: base_leaf:35
tools::cmp_cast
void * cmp_cast(const TO *a_this, const std::string &a_class)
Definition: scast:15
tools::rroot::base_leaf::cast
virtual void * cast(const std::string &a_class) const
Definition: base_leaf:23
tools::rroot::leaf::m_min
T m_min
Definition: leaf:201
tools::rroot::leaf::s_class
static const std::string & s_class()
Definition: leaf:61
tools::stype
const std::string & stype(const mat4f &)
Definition: mat4f:73
tools::uint32
unsigned int uint32
Definition: typedefs:71
tools::rroot::base_leaf::base_leaf
base_leaf(std::ostream &a_out, ifac &a_fac)
Definition: base_leaf:105