// Copyright (C) 2010, Guy Barrand. All rights reserved. // See the file tools.license for terms. #ifndef tools_rroot_iros #define tools_rroot_iros #include "object" #include "../vmanip" #include "../forit" #include "../scast" #include "cids" namespace tools { namespace rroot { class iros : public virtual iro,protected std::vector { //proteced to avoid using std::vector::clear(). typedef std::vector parent; public: static const std::string& s_store_class() { static const std::string s_v("TObjArray"); return s_v; } public: static const std::string& s_class() { static const std::string s_v("tools::rroot::iros"); return s_v; } public: //iro virtual void* cast(const std::string& a_class) const { if(void* p = cmp_cast(this,a_class)) return p; return 0; } virtual const std::string& s_cls() const {return s_class();} public: static cid id_class() {return obj_list_cid();} virtual void* cast(cid a_class) const { if(void* p = cmp_cast(this,a_class)) {return p;} else return 0; } public: virtual iro* copy() const {return new iros(*this);} virtual bool stream(buffer& a_buffer) { ifac::args args; bool accept_null = false; return stream(a_buffer,args,accept_null); } public: iros(ifac& a_fac) :m_fac(a_fac) { } virtual ~iros(){ _clear(); } public: iros(const iros& a_from) :iro(a_from) ,parent() ,m_fac(a_from.m_fac) { tools_vforcit(iro*,a_from,it) { parent::push_back((*it)->copy()); m_owns.push_back(true); } } iros& operator=(const iros& a_from){ if(&a_from==this) return *this; _clear(); tools_vforcit(iro*,a_from,it) { parent::push_back((*it)->copy()); m_owns.push_back(true); } return *this; } public: parent::const_iterator begin() const {return parent::begin();} parent::iterator begin() {return parent::begin();} parent::const_iterator end() const {return parent::end();} parent::iterator end() {return parent::end();} parent::size_type size() const {return parent::size();} public: void cleanup() {_clear();} //warning : clear is a function of the parent std::vector. void dump(std::ostream& a_out) { a_out << " iros : size " << size() << std::endl; tools_vforcit(iro*,*this,it) { a_out << " class " << (*it)->s_cls() << std::endl; } } public: bool stream(buffer& a_buffer,const ifac::args& a_args,bool a_accept_null = false) { _clear(); short v; unsigned int s, c; if(!a_buffer.read_version(v,s,c)) return false; {uint32 id,bits; if(!Object_stream(a_buffer,id,bits)) return false;} std::string name; if(!a_buffer.read(name)) return false; int nobjects; if(!a_buffer.read(nobjects)) return false; int lowerBound; if(!a_buffer.read(lowerBound)) return false; for (int i=0;i::iterator itb_t; while(!parent::empty()) { it_t it = parent::begin(); itb_t itb = m_owns.begin(); iro* entry = (*it); bool own = (*itb); parent::erase(it); m_owns.erase(itb); if(own) delete entry; } } protected: ifac& m_fac; std::vector m_owns; }; }} #endif