// 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,public std::vector { 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,bool a_owner,bool a_warn /*= true*/) //a_warn used if a_owner=false. :m_fac(a_fac) ,m_owner(a_owner) ,m_warn(a_warn) { #ifdef TOOLS_MEM mem::increment(s_class().c_str()); #endif } virtual ~iros(){ _clear(); #ifdef TOOLS_MEM mem::decrement(s_class().c_str()); #endif } public: iros(const iros& a_from) :iro(a_from) ,std::vector() ,m_fac(a_from.m_fac) ,m_owner(a_from.m_owner) ,m_warn(a_from.m_warn) { #ifdef TOOLS_MEM mem::increment(s_class().c_str()); #endif if(a_from.m_owner) { tools_vforcit(iro*,a_from,it) push_back((*it)->copy()); } else { tools_vforcit(iro*,a_from,it) push_back((*it)); } } iros& operator=(const iros& a_from){ if(&a_from==this) return *this; _clear(); m_owner = a_from.m_owner; m_warn = a_from.m_warn; if(a_from.m_owner) { tools_vforcit(iro*,a_from,it) push_back((*it)->copy()); } else { tools_vforcit(iro*,a_from,it) push_back((*it)); } return *this; } public: void cleanup() {_clear();} 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; //::printf("debug : iros::stream : version %d, byte count %d\n",v,c); {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; //::printf("debug : iros : name \"%s\", nobject %d, lowerBound %d\n", // name.c_str(),nobjects,lowerBound); for (int i=0;is_cls()) << " not managed." << std::endl; } push_back(obj); } } else { //someone else may manage this object. if(m_owner) { a_buffer.out() << "tools::rroot::iros::stream : warning : not created object can't be manage here." << std::endl; return false; } else { push_back(obj); } } } else { //a_accept_null for branch::stream m_baskets. if(a_accept_null) push_back(0); } } return a_buffer.check_byte_count(s,c,s_store_class()); } protected: void _clear() { if(m_owner) { safe_clear(*this); } else { std::vector::clear(); } } protected: ifac& m_fac; bool m_owner; bool m_warn; }; inline bool dummy_TObjArray_pointer_stream(buffer& a_buffer,ifac& a_fac,bool a_owner,bool a_warn) { iros oa(a_fac,a_owner,a_warn); ifac::args args; return oa.stream(a_buffer,args); } }} #endif