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

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)
 
 obj_array (ifac &a_fac)
 
virtual ~obj_array ()
 
 obj_array (const obj_array &a_from)
 
obj_arrayoperator= (const obj_array &a_from)
 
void cleanup ()
 
bool stream (buffer &a_buffer, const ifac::args &a_args, bool a_accept_null=false)
 
- Public Member Functions inherited from tools::rroot::iro
virtual ~iro ()
 

Static Public Member Functions

static const std::string & s_class ()
 
static cid id_class ()
 

Protected Member Functions

void _clear ()
 

Protected Attributes

ifacm_fac
 
std::vector< bool > m_owns
 

Detailed Description

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

Definition at line 17 of file obj_array.

Constructor & Destructor Documentation

◆ obj_array() [1/2]

template<class T >
tools::rroot::obj_array< T >::obj_array ( ifac a_fac)
inline

Definition at line 48 of file obj_array.

49  :m_fac(a_fac)
50  {
51 #ifdef TOOLS_MEM
52  mem::increment(s_class().c_str());
53 #endif
54  }

◆ ~obj_array()

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

Definition at line 55 of file obj_array.

55  {
56  _clear();
57 #ifdef TOOLS_MEM
58  mem::decrement(s_class().c_str());
59 #endif
60  }

◆ obj_array() [2/2]

template<class T >
tools::rroot::obj_array< T >::obj_array ( const obj_array< T > &  a_from)
inline

Definition at line 62 of file obj_array.

63  :iro(a_from)
64  ,parent()
65  ,m_fac(a_from.m_fac)
66  {
67 #ifdef TOOLS_MEM
68  mem::increment(s_class().c_str());
69 #endif
70  typedef typename parent::const_iterator it_t;
71  for(it_t it=a_from.begin();it!=a_from.end();++it) {
72  if(!(*it)) {
73  parent::push_back(0);
74  m_owns.push_back(false);
75  } else {
76  iro* _obj = (*it)->copy();
77  T* obj = safe_cast<iro,T>(*_obj);
78  if(!obj) {
79  m_fac.out() << "tools::rroot::obj_array::obj_array :"
80  << " inlib::cast failed."
81  << std::endl;
82  delete _obj;
83  parent::push_back(0);
84  m_owns.push_back(false);
85  } else {
86  parent::push_back(obj);
87  m_owns.push_back(true);
88  }
89  }
90  }
91  }

Member Function Documentation

◆ _clear()

template<class T >
void tools::rroot::obj_array< T >::_clear ( )
inlineprotected

Definition at line 191 of file obj_array.

191  {
192  typedef typename parent::iterator it_t;
193  typedef std::vector<bool>::iterator itb_t;
194  while(!parent::empty()) {
195  it_t it = parent::begin();
196  itb_t itb = m_owns.begin();
197  T* entry = (*it);
198  bool own = (*itb);
199  parent::erase(it);
200  m_owns.erase(itb);
201  if(own) delete entry;
202  }
203  }

◆ cast() [1/2]

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

Implements tools::rroot::iro.

Definition at line 37 of file obj_array.

37  {
38  if(void* p = cmp_cast<obj_array>(this,a_class)) {return p;}
39  return 0;
40  }

◆ cast() [2/2]

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

Implements tools::rroot::iro.

Definition at line 30 of file obj_array.

30  {
31  if(void* p = cmp_cast< obj_array<T> >(this,a_class)) return p;
32  return 0;
33  }

◆ cleanup()

template<class T >
void tools::rroot::obj_array< T >::cleanup ( )
inline

Definition at line 122 of file obj_array.

122 {_clear();}

◆ copy()

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

Implements tools::rroot::iro.

Definition at line 41 of file obj_array.

41 {return new obj_array<T>(*this);}

◆ id_class()

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

Definition at line 36 of file obj_array.

36 {return obj_array_cid()+T::id_class();}

◆ operator=()

template<class T >
obj_array& tools::rroot::obj_array< T >::operator= ( const obj_array< T > &  a_from)
inline

Definition at line 92 of file obj_array.

92  {
93  if(&a_from==this) return *this;
94 
95  _clear();
96 
97  typedef typename parent::const_iterator it_t;
98  for(it_t it=a_from.begin();it!=a_from.end();++it) {
99  if(!(*it)) {
100  parent::push_back(0);
101  m_owns.push_back(false);
102  } else {
103  iro* _obj = (*it)->copy();
104  T* obj = safe_cast<iro,T>(*_obj);
105  if(!obj) {
106  m_fac.out() << "tools::rroot::obj_array::operator= :"
107  << " inlib::cast failed."
108  << std::endl;
109  delete _obj;
110  parent::push_back(0);
111  m_owns.push_back(false);
112  } else {
113  parent::push_back(obj);
114  m_owns.push_back(true);
115  }
116  }
117  }
118 
119  return *this;
120  }

◆ s_class()

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

Definition at line 25 of file obj_array.

25  {
26  static const std::string s_v("tools::rroot::obj_array<"+T::s_class()+">");
27  return s_v;
28  }

◆ s_cls()

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

Implements tools::rroot::iro.

Definition at line 34 of file obj_array.

34 {return s_class();}

◆ stream() [1/2]

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

Implements tools::rroot::iro.

Definition at line 42 of file obj_array.

42  {
43  ifac::args args;
44  bool accept_null = false;
45  return stream(a_buffer,args,accept_null);
46  }

◆ stream() [2/2]

template<class T >
bool tools::rroot::obj_array< T >::stream ( buffer a_buffer,
const ifac::args a_args,
bool  a_accept_null = false 
)
inline

Definition at line 124 of file obj_array.

124  {
125  _clear();
126 
127  //::printf("debug : obj_array::stream : %lu : begin\n",(unsigned long)this);
128 
129  short v;
130  unsigned int sp, bc;
131  if(!a_buffer.read_version(v,sp,bc)) return false;
132 
133  //::printf("debug : obj_array::stream : version %d, byte count %d\n",v,bc);
134 
135  {uint32 id,bits;
136  if(!Object_stream(a_buffer,id,bits)) return false;}
137  std::string name;
138  if(!a_buffer.read(name)) return false;
139  int nobjects;
140  if(!a_buffer.read(nobjects)) return false;
141  int lowerBound;
142  if(!a_buffer.read(lowerBound)) return false;
143 
144  //::printf("debug : obj_array : name \"%s\", nobject %d, lowerBound %d\n",name.c_str(),nobjects,lowerBound);
145 
146  for (int i=0;i<nobjects;i++) {
147  //::printf("debug : obj_array::stream : %lu : n=%d i=%d ...\n",(unsigned long)this,nobjects,i);
148 
149  iro* obj;
150  bool created;
151  if(!a_buffer.read_object(m_fac,a_args,obj,created)){
152  a_buffer.out() << "tools::rroot::obj_array::stream : can't read object"
153  << " in obj_array : name " << sout(name)
154  << ", nobjects " << nobjects << ", iobject " << i << std::endl;
155  return false;
156  }
157  //::printf("debug : obj_array::stream : %lu : n=%d i=%d : ok, obj %lu\n",(unsigned long)this,
158  // nobjects,i,(unsigned long)obj);
159  if(obj) {
160  T* to = safe_cast<iro,T>(*obj);
161  if(!to) {
162  a_buffer.out() << "tools::rroot::obj_array::stream :"
163  << " inlib::cast failed."
164  << " " << obj->s_cls() << " is not a " << T::s_class() << "."
165  << std::endl;
166  if(created) {
167  if(a_buffer.map_objs()) a_buffer.remove_in_map(obj);
168  delete obj;
169  }
170  } else {
171  if(created) {
172  parent::push_back(to);
173  m_owns.push_back(true);
174  } else { //someone else manage this object.
175  parent::push_back(to);
176  m_owns.push_back(false);
177  }
178  }
179  } else {
180  //a_accept_null for branch::stream m_baskets.
181  if(a_accept_null) {
182  parent::push_back(0);
183  m_owns.push_back(false);
184  }
185  }
186  }
187 
188  return a_buffer.check_byte_count(sp,bc,s_store_class());
189  }

Member Data Documentation

◆ m_fac

template<class T >
ifac& tools::rroot::obj_array< T >::m_fac
protected

Definition at line 205 of file obj_array.

◆ m_owns

template<class T >
std::vector<bool> tools::rroot::obj_array< T >::m_owns
protected

Definition at line 206 of file obj_array.


The documentation for this class was generated from the following file:
tools::rroot::obj_array::m_owns
std::vector< bool > m_owns
Definition: obj_array:206
tools::rroot::Object_stream
bool Object_stream(buffer &a_buffer, uint32 &a_id, uint32 &a_bits)
Definition: object:12
tools::rroot::obj_array_cid
cid obj_array_cid()
Definition: cids:19
tools::rroot::obj_array::stream
virtual bool stream(buffer &a_buffer)
Definition: obj_array:42
tools::waxml::begin
void begin(std::ostream &a_writer)
Definition: begend:15
tools::rroot::obj_array::_clear
void _clear()
Definition: obj_array:191
tools::to
std::vector< std::string > to(int a_argc, char **a_argv)
Definition: args:507
tools::cmp_cast
void * cmp_cast(const TO *a_this, const std::string &a_class)
Definition: scast:15
tools::rroot::obj_array::s_class
static const std::string & s_class()
Definition: obj_array:25
tools::rroot::ifac::args
std::map< char, void * > args
Definition: ifac:21
tools::uint32
unsigned int uint32
Definition: typedefs:71
tools::rroot::ifac::out
virtual std::ostream & out() const =0
tools::rroot::obj_array::m_fac
ifac & m_fac
Definition: obj_array:205