g4tools  5.4.0
Public Member Functions | Static Public Member Functions | Protected Attributes | List of all members
tools::rroot::obj_list Class Reference
Inheritance diagram for tools::rroot::obj_list:
Inheritance graph
[legend]
Collaboration diagram for tools::rroot::obj_list:
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_list (ifac &a_fac)
 
virtual ~obj_list ()
 
 obj_list (const obj_list &a_from)
 
obj_listoperator= (const obj_list &a_from)
 
parent::const_iterator begin () const
 
parent::iterator begin ()
 
parent::const_iterator end () const
 
parent::iterator end ()
 
parent::size_type size () const
 
bool empty () const
 
void add_object (iro *a_obj)
 
template<class T >
T * get_entry (std::ostream &a_out, size_t a_index) const
 
void safe_clear ()
 
void cleanup ()
 
- Public Member Functions inherited from tools::rroot::iro
virtual ~iro ()
 

Static Public Member Functions

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

Protected Attributes

ifacm_fac
 
std::vector< bool > m_owns
 

Detailed Description

Definition at line 20 of file obj_list.

Constructor & Destructor Documentation

◆ obj_list() [1/2]

tools::rroot::obj_list::obj_list ( ifac a_fac)
inline

Definition at line 99 of file obj_list.

100  :m_fac(a_fac)
101  {
102 #ifdef TOOLS_MEM
103  mem::increment(s_class().c_str());
104 #endif
105  }

◆ ~obj_list()

virtual tools::rroot::obj_list::~obj_list ( )
inlinevirtual

Definition at line 106 of file obj_list.

106  {
107  safe_clear();
108 #ifdef TOOLS_MEM
109  mem::decrement(s_class().c_str());
110 #endif
111  }

◆ obj_list() [2/2]

tools::rroot::obj_list::obj_list ( const obj_list a_from)
inline

Definition at line 113 of file obj_list.

114  :iro(a_from)
115  ,parent()
116  ,m_fac(a_from.m_fac)
117  {
118 #ifdef TOOLS_MEM
119  mem::increment(s_class().c_str());
120 #endif
121  tools_vforcit(iro*,a_from,it) {
122  parent::push_back((*it)->copy());
123  m_owns.push_back(true);
124  }
125  }

Member Function Documentation

◆ add_object()

void tools::rroot::obj_list::add_object ( iro a_obj)
inline

Definition at line 146 of file obj_list.

146  { //take ownership.
147  parent::push_back(a_obj);
148  m_owns.push_back(true);
149  }

◆ begin() [1/2]

parent::iterator tools::rroot::obj_list::begin ( )
inline

Definition at line 140 of file obj_list.

140 {return parent::begin();}

◆ begin() [2/2]

parent::const_iterator tools::rroot::obj_list::begin ( ) const
inline

Definition at line 139 of file obj_list.

139 {return parent::begin();}

◆ cast() [1/2]

virtual void* tools::rroot::obj_list::cast ( cid  a_class) const
inlinevirtual

Implements tools::rroot::iro.

Definition at line 40 of file obj_list.

40  {
41  if(void* p = cmp_cast<obj_list>(this,a_class)) {return p;}
42  else return 0;
43  }

◆ cast() [2/2]

virtual void* tools::rroot::obj_list::cast ( const std::string &  a_class) const
inlinevirtual

Implements tools::rroot::iro.

Definition at line 33 of file obj_list.

33  {
34  if(void* p = cmp_cast<obj_list>(this,a_class)) return p;
35  return 0;
36  }

◆ cleanup()

void tools::rroot::obj_list::cleanup ( )
inline

Definition at line 179 of file obj_list.

179 {safe_clear();}

◆ copy()

virtual iro* tools::rroot::obj_list::copy ( ) const
inlinevirtual

Implements tools::rroot::iro.

Definition at line 46 of file obj_list.

46 {return new obj_list(*this);}

◆ empty()

bool tools::rroot::obj_list::empty ( ) const
inline

Definition at line 144 of file obj_list.

144 {return parent::empty();}

◆ end() [1/2]

parent::iterator tools::rroot::obj_list::end ( )
inline

Definition at line 142 of file obj_list.

142 {return parent::end();}

◆ end() [2/2]

parent::const_iterator tools::rroot::obj_list::end ( ) const
inline

Definition at line 141 of file obj_list.

141 {return parent::end();}

◆ get_entry()

template<class T >
T* tools::rroot::obj_list::get_entry ( std::ostream &  a_out,
size_t  a_index 
) const
inline

Definition at line 152 of file obj_list.

152  {
153  if(a_index>=size()) return 0;
154  iro* _obj = parent::operator[](a_index);
155  if(!_obj) return 0;
156  T* od = id_cast<iro,T>(*_obj);
157  if(!od) {
158  a_out << "tools::rroot::obj_list::get_entry :"
159  << " object of class " << sout(_obj->s_cls()) << " not a " << T::s_class() << std::endl;
160  return 0;
161  }
162  return od;
163  }

◆ id_class()

static cid tools::rroot::obj_list::id_class ( )
inlinestatic

Definition at line 39 of file obj_list.

39 {return obj_list_cid();}

◆ operator=()

obj_list& tools::rroot::obj_list::operator= ( const obj_list a_from)
inline

Definition at line 126 of file obj_list.

126  {
127  if(&a_from==this) return *this;
128 
129  safe_clear();
130 
131  tools_vforcit(iro*,a_from,it) {
132  parent::push_back((*it)->copy());
133  m_owns.push_back(true);
134  }
135 
136  return *this;
137  }

◆ s_class()

static const std::string& tools::rroot::obj_list::s_class ( )
inlinestatic

Definition at line 28 of file obj_list.

28  {
29  static const std::string s_v("tools::rroot::obj_list");
30  return s_v;
31  }

◆ s_cls()

virtual const std::string& tools::rroot::obj_list::s_cls ( ) const
inlinevirtual

Implements tools::rroot::iro.

Definition at line 37 of file obj_list.

37 {return s_class();}

◆ s_store_class()

static const std::string& tools::rroot::obj_list::s_store_class ( )
inlinestatic

Definition at line 23 of file obj_list.

23  {
24  static const std::string s_v("TList");
25  return s_v;
26  }

◆ safe_clear()

void tools::rroot::obj_list::safe_clear ( )
inline

Definition at line 165 of file obj_list.

165  {
166  typedef parent::iterator it_t;
167  typedef std::vector<bool>::iterator itb_t;
168  while(!parent::empty()) {
169  it_t it = parent::begin();
170  itb_t itb = m_owns.begin();
171  iro* entry = (*it);
172  bool own = (*itb);
173  parent::erase(it);
174  m_owns.erase(itb);
175  if(own) delete entry;
176  }
177  }

◆ size()

parent::size_type tools::rroot::obj_list::size ( ) const
inline

Definition at line 143 of file obj_list.

143 {return parent::size();}

◆ stream()

virtual bool tools::rroot::obj_list::stream ( buffer a_buffer)
inlinevirtual

Implements tools::rroot::iro.

Definition at line 47 of file obj_list.

47  {
48  safe_clear();
49 
50  short v;
51  unsigned int s, c;
52  if(!a_buffer.read_version(v,s,c)) return false;
53 
54  //::printf("debug : obj_list::stream : version %d, byte count %d\n",v,c);
55 
56  {uint32 id,bits;
57  if(!Object_stream(a_buffer,id,bits)) return false;}
58 
59  std::string name;
60  if(!a_buffer.read(name)) return false;
61  int nobjects;
62  if(!a_buffer.read(nobjects)) return false;
63 
64  //::printf("debug : obj_list : name \"%s\", nobject %d\n",
65  // name.c_str(),nobjects);
66 
67  ifac::args args;
68  for (int i=0;i<nobjects;i++) {
69  //::printf("debug : obj_list : n=%d i=%d ...\n",nobjects,i);
70 
71  iro* obj;
72  bool created;
73  if(!a_buffer.read_object(m_fac,args,obj,created)){
74  a_buffer.out() << "tools::rroot::obj_list::stream : can't read object." << std::endl;
75  return false;
76  }
77 
78  unsigned char nch;
79  if(!a_buffer.read(nch)) return false;
80  if(nch) {
81  char readOption[256];
82  if(!a_buffer.read_fast_array(readOption,nch)) return false;
83  readOption[nch] = 0;
84  }
85  if(obj) {
86  if(created) {
87  parent::push_back(obj);
88  m_owns.push_back(true);
89  } else { //someone else may manage this object.
90  parent::push_back(obj);
91  m_owns.push_back(false);
92  }
93  }
94  }
95 
96  return a_buffer.check_byte_count(s,c,s_store_class());
97  }

Member Data Documentation

◆ m_fac

ifac& tools::rroot::obj_list::m_fac
protected

Definition at line 181 of file obj_list.

◆ m_owns

std::vector<bool> tools::rroot::obj_list::m_owns
protected

Definition at line 182 of file obj_list.


The documentation for this class was generated from the following file:
tools::rroot::obj_list::size
parent::size_type size() const
Definition: obj_list:143
tools::rroot::Object_stream
bool Object_stream(buffer &a_buffer, uint32 &a_id, uint32 &a_bits)
Definition: object:12
tools::rroot::obj_list::m_owns
std::vector< bool > m_owns
Definition: obj_list:182
tools::rroot::obj_list::m_fac
ifac & m_fac
Definition: obj_list:181
tools::waxml::begin
void begin(std::ostream &a_writer)
Definition: begend:15
tools::rroot::obj_list::obj_list
obj_list(ifac &a_fac)
Definition: obj_list:99
tools::rroot::obj_list::s_store_class
static const std::string & s_store_class()
Definition: obj_list:23
tools::rroot::obj_list::safe_clear
void safe_clear()
Definition: obj_list:165
tools::file::size
bool size(const std::string &a_file, long &a_size)
Definition: fsize:13
tools::rroot::obj_list::s_class
static const std::string & s_class()
Definition: obj_list:28
tools::waxml::end
void end(std::ostream &a_writer)
Definition: begend:31
tools::rroot::ifac::args
std::map< char, void * > args
Definition: ifac:21
tools_vforcit
#define tools_vforcit(a__T, a__v, a__it)
Definition: forit:7
tools::rroot::obj_list_cid
cid obj_list_cid()
Definition: cids:17
tools::uint32
unsigned int uint32
Definition: typedefs:71