Geant4 Cross Reference |
1 // Copyright (C) 2010, Guy Barrand. All rights 2 // See the file tools.license for terms. 3 4 #ifndef tools_rroot_iros 5 #define tools_rroot_iros 6 7 #include "object" 8 #include "../vmanip" 9 #include "../forit" 10 #include "../scast" 11 12 #include "cids" 13 14 namespace tools { 15 namespace rroot { 16 17 class iros : public virtual iro,protected std: 18 typedef std::vector<iro*> parent; 19 public: 20 static const std::string& s_store_class() { 21 static const std::string s_v("TObjArray"); 22 return s_v; 23 } 24 public: 25 static const std::string& s_class() { 26 static const std::string s_v("tools::rroot 27 return s_v; 28 } 29 public: //iro 30 virtual void* cast(const std::string& a_clas 31 if(void* p = cmp_cast<iros>(this,a_class)) 32 return 0; 33 } 34 virtual const std::string& s_cls() const {re 35 public: 36 static cid id_class() {return obj_list_cid() 37 virtual void* cast(cid a_class) const { 38 if(void* p = cmp_cast<iros>(this,a_class)) 39 else return 0; 40 } 41 public: 42 virtual iro* copy() const {return new iros(* 43 virtual bool stream(buffer& a_buffer) { 44 ifac::args args; 45 bool accept_null = false; 46 return stream(a_buffer,args,accept_null); 47 } 48 public: 49 iros(ifac& a_fac) 50 :m_fac(a_fac) 51 { 52 #ifdef TOOLS_MEM 53 mem::increment(s_class().c_str()); 54 #endif 55 } 56 virtual ~iros(){ 57 _clear(); 58 #ifdef TOOLS_MEM 59 mem::decrement(s_class().c_str()); 60 #endif 61 } 62 public: 63 iros(const iros& a_from) 64 :iro(a_from) 65 ,parent() 66 ,m_fac(a_from.m_fac) 67 { 68 #ifdef TOOLS_MEM 69 mem::increment(s_class().c_str()); 70 #endif 71 tools_vforcit(iro*,a_from,it) { 72 parent::push_back((*it)->copy()); 73 m_owns.push_back(true); 74 } 75 } 76 iros& operator=(const iros& a_from){ 77 if(&a_from==this) return *this; 78 79 _clear(); 80 81 tools_vforcit(iro*,a_from,it) { 82 parent::push_back((*it)->copy()); 83 m_owns.push_back(true); 84 } 85 86 return *this; 87 } 88 public: 89 parent::const_iterator begin() const {return 90 parent::iterator begin() {return parent::beg 91 parent::const_iterator end() const {return p 92 parent::iterator end() {return parent::end() 93 parent::size_type size() const {return paren 94 public: 95 void cleanup() {_clear();} //warning : clea 96 void dump(std::ostream& a_out) { 97 a_out << " iros : size " << size() << std: 98 tools_vforcit(iro*,*this,it) { 99 a_out << " class " << (*it)->s_cls() << 100 } 101 } 102 public: 103 bool stream(buffer& a_buffer,const ifac::arg 104 _clear(); 105 106 short v; 107 unsigned int s, c; 108 if(!a_buffer.read_version(v,s,c)) return f 109 110 //::printf("debug : iros::stream : version 111 112 {uint32 id,bits; 113 if(!Object_stream(a_buffer,id,bits)) retur 114 std::string name; 115 if(!a_buffer.read(name)) return false; 116 int nobjects; 117 if(!a_buffer.read(nobjects)) return false; 118 int lowerBound; 119 if(!a_buffer.read(lowerBound)) return fals 120 121 //::printf("debug : iros : name \"%s\", no 122 // name.c_str(),nobjects,lowerBound); 123 124 for (int i=0;i<nobjects;i++) { 125 //::printf("debug : iros : n=%d i=%d 126 127 iro* obj; 128 bool created; 129 if(!a_buffer.read_object(m_fac,a_args,ob 130 a_buffer.out() << "tools::rroot::iros: 131 return false; 132 } 133 //::printf("debug : iros : n=%d i=%d 134 if(obj) { 135 if(created) { 136 parent::push_back(obj); 137 m_owns.push_back(true); 138 } else { //someone else manage this object. 139 parent::push_back(obj); 140 m_owns.push_back(false); 141 } 142 } else { 143 //a_accept_null for branch::stream m_b 144 if(a_accept_null) { 145 parent::push_back(0); 146 m_owns.push_back(false); 147 } 148 } 149 } 150 151 return a_buffer.check_byte_count(s,c,s_sto 152 } 153 protected: 154 void _clear() { 155 typedef parent::iterator it_t; 156 typedef std::vector<bool>::iterator itb_t; 157 while(!parent::empty()) { 158 it_t it = parent::begin(); 159 itb_t itb = m_owns.begin(); 160 iro* entry = (*it); 161 bool own = (*itb); 162 parent::erase(it); 163 m_owns.erase(itb); 164 if(own) delete entry; 165 } 166 } 167 protected: 168 ifac& m_fac; 169 std::vector<bool> m_owns; 170 }; 171 172 /* 173 inline bool dummy_TObjArray_pointer_stream(buf 174 iros oa(a_fac,a_owner,a_warn); 175 iros oa(a_fac,true,true); 176 ifac::args args; 177 return oa.stream(a_buffer,args); 178 } 179 */ 180 181 }} 182 183 #endif