// Author: Pierre-Luc Drouin // Copyright Carleton University ////////////////////////////////////////////////////////////////////////// // // // QList // // // // Template list class that can contain any data type and any class // // instance. However, when the type is a class, the implicit conversion // // constructor U::U(const U&) and the operator=(const U&) must be // // overloaded properly, i.e. member variables must be copied by value // // and not by address, since QList class considers that it owns its // // memory. operator== must be defined properly too. If these conditions // // are not respected, a list of instance pointers can be created, but // // in this case, member functions like Del, Find and friend functions // // like operator==,operator!=,operator<= and operator< have not the // // same meaning, and the copy functions (operator=, Clone and // // QList(const QList&)) don't create new independant instances. // // // // PLEASE REFER TO FILE QList_cxx.h FOR DESCRIPTION OF MEMBER FUNCTIONS // // // ////////////////////////////////////////////////////////////////////////// #ifndef _QLIST_ #define _QLIST_ #include #include #include #include "TObject.h" #include "Rtypes.h" #include //#define DEBUG //#define DEBUG2 #include "debugger.h" using std::cout; template class QList: public TObject { public: QList():TObject(),fNElements(0),fUArray(NULL),fChild(NULL){PRINTF4(this,"\tQList<",typeid(U).name(),">::QList()\n") } QList(const QList& newqlist); QList(const U& newelement):TObject(),fNElements(0),fUArray(NULL),fChild(NULL){PRINTF4(this,"\tQList<",typeid(U).name(),">::QList(const U& newelement)\n") Add(newelement); } QList(const U* newelements, Int_t nelements):TObject(),fNElements(0),fUArray(NULL),fChild(NULL){PRINTF6(this,"\tQList<",typeid(U).name(),">::QList(const U* newelements, Int_t nelements<",nelements,">)\n") Add(newelements, nelements); } virtual ~QList(){PRINTF4(this,"\tQList<",typeid(U).name(),">::~QList()\n") Clear();} void Add(const QList& newqlist, Int_t index=-1); void Add(const U& newelement,Int_t index=-1); void Add(const U* newelements, Int_t nelements, Int_t index=-1); void Set(const QList& newqlist); void Set(const U& newelement); void Set(const U* newelements, Int_t nelements); Int_t Del(const QList& delqlist, Int_t maxmatches=1); // Int_t Del(const U& delu, Int_t maxmatches=1); Int_t Del(const U* delus, Int_t nelements=1, Int_t maxmatches=1); void Del(Int_t index=-1); const QList& operator=(const QList& newqlist){PRINTF4(this,"\tconst QList& QList<",typeid(U).name(),">::operator=(const QList& newqlist)\n") Set(newqlist); return *this;} const QList& operator=(const U& newelement){PRINTF4(this,"\tconst QList& QList<",typeid(U).name(),">::operator=(const U& newelement)\n") Set(newelement); return *this;} operator U*() const; const QList& operator+=(const QList& newqlist){PRINTF4(this,"\tconst QList& QList<",typeid(U).name(),">::operator+=(const QList& newqlist)\n") Add(newqlist); return *this;} const QList& operator+=(const U& newu){PRINTF4(this,"\tconst QList& QList<",typeid(U).name(),">::operator+=(const U& newu)\n") Add(newu); return *this;} const QList& operator-=(const QList& delqlist){PRINTF4(this,"\tconst QList& QList<",typeid(U).name(),">::operator-=(const QList& delqlist)\n") Del(delqlist); return *this;} const QList& operator-=(const U& delu){PRINTF4(this,"\tconst QList& QList<",typeid(U).name(),">::operator-=(const U& delu)\n") Del(&delu); return *this;} Int_t Count() const{PRINTF4(this,"\tInt_t& QList<",typeid(U).name(),">::Count()\n") return fNElements;} QList Find(const QList& qlist,Int_t maxmatches=0) const; QList Find(const U& u,Int_t maxmatches=0) const; QList Find(const U* us, Int_t nelements, Int_t maxmatches=0) const; template friend Bool_t operator==(const QList& lhs,const QList& rhs); template friend Bool_t operator!=(const QList& lhs,const QList& rhs); template friend Bool_t operator<=(const QList& lhs,const QList& rhs); template friend Bool_t operator>=(const QList& lhs,const QList& rhs); template friend Bool_t operator<(const QList& lhs,const QList& rhs); template friend Bool_t operator>(const QList& lhs,const QList& rhs); U& operator[](Int_t index) const; const QList& operator()(Int_t index1,Int_t index2,Int_t step=1) const; QList* Clone(const char* newname = "") const{PRINTF4(this,"\tQList* QList<",typeid(U).name(),">::Clone()\n") newname=0; return new QList(*this); } Int_t RedimList(Int_t newdim,Int_t index=-1); void Clear(Option_t* option = "") { PRINTF6(this,"\tvoid QList<",typeid(U).name(),">::Clear(Option_t* option<",option,">)\n") option=0; if(fChild){ delete fChild; fChild=NULL; } fUArray=NULL; fNElements=0; } private: Int_t fNElements; U* fUArray; //[fNElements] mutable QList* fChild; //! Do not write this member variable into a ROOT file ClassDef(QList,1) //Generic list template class }; #include "debugger.h" #include "QList_cxx.h" #endif