00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012 #ifndef ROOT_TObjArray
00013 #define ROOT_TObjArray
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #ifndef ROOT_TSeqCollection
00026 #include "TSeqCollection.h"
00027 #endif
00028
00029 #include <iterator>
00030
00031 #if (__GNUC__ >= 3) && !defined(__INTEL_COMPILER)
00032
00033
00034 #pragma GCC system_header
00035 #endif
00036
00037 class TObjArrayIter;
00038
00039 class TObjArray : public TSeqCollection {
00040
00041 friend class TObjArrayIter;
00042 friend class TClonesArray;
00043
00044 protected:
00045 TObject **fCont;
00046 Int_t fLowerBound;
00047 Int_t fLast;
00048
00049 Bool_t BoundsOk(const char *where, Int_t at) const;
00050 void Init(Int_t s, Int_t lowerBound);
00051 Bool_t OutOfBoundsError(const char *where, Int_t i) const;
00052 Int_t GetAbsLast() const;
00053
00054 public:
00055 typedef TObjArrayIter Iterator_t;
00056
00057 TObjArray(Int_t s = TCollection::kInitCapacity, Int_t lowerBound = 0);
00058 TObjArray(const TObjArray &a);
00059 virtual ~TObjArray();
00060 TObjArray& operator=(const TObjArray&);
00061 virtual void Clear(Option_t *option="");
00062 virtual void Compress();
00063 virtual void Delete(Option_t *option="");
00064 virtual void Expand(Int_t newSize);
00065 Int_t GetEntries() const;
00066 Int_t GetEntriesFast() const {
00067 return GetAbsLast() + 1;
00068 }
00069 Int_t GetLast() const;
00070 TObject **GetObjectRef(const TObject *obj) const;
00071 Bool_t IsEmpty() const { return GetAbsLast() == -1; }
00072 TIterator *MakeIterator(Bool_t dir = kIterForward) const;
00073
00074 void Add(TObject *obj) { AddLast(obj); }
00075 virtual void AddFirst(TObject *obj);
00076 virtual void AddLast(TObject *obj);
00077 virtual void AddAt(TObject *obj, Int_t idx);
00078 virtual void AddAtAndExpand(TObject *obj, Int_t idx);
00079 virtual Int_t AddAtFree(TObject *obj);
00080 virtual void AddAfter(const TObject *after, TObject *obj);
00081 virtual void AddBefore(const TObject *before, TObject *obj);
00082 virtual TObject *FindObject(const char *name) const;
00083 virtual TObject *FindObject(const TObject *obj) const;
00084 virtual TObject *RemoveAt(Int_t idx);
00085 virtual TObject *Remove(TObject *obj);
00086 virtual void RemoveRange(Int_t idx1, Int_t idx2);
00087 virtual void RecursiveRemove(TObject *obj);
00088
00089 TObject *At(Int_t idx) const;
00090 TObject *UncheckedAt(Int_t i) const { return fCont[i-fLowerBound]; }
00091 TObject *Before(const TObject *obj) const;
00092 TObject *After(const TObject *obj) const;
00093 TObject *First() const;
00094 TObject *Last() const;
00095 virtual TObject *&operator[](Int_t i);
00096 virtual TObject *operator[](Int_t i) const;
00097 Int_t LowerBound() const { return fLowerBound; }
00098 Int_t IndexOf(const TObject *obj) const;
00099 void SetLast(Int_t last);
00100
00101 virtual void Randomize(Int_t ntimes=1);
00102 virtual void Sort(Int_t upto = kMaxInt);
00103 virtual Int_t BinarySearch(TObject *obj, Int_t upto = kMaxInt);
00104
00105 ClassDef(TObjArray,3)
00106 };
00107
00108
00109
00110 #if (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__) >= 40600
00111 #pragma GCC diagnostic push
00112 #pragma GCC diagnostic ignored "-Weffc++"
00113 #endif
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123 class TObjArrayIter : public TIterator,
00124 public std::iterator<std::bidirectional_iterator_tag,
00125 TObject*, std::ptrdiff_t,
00126 const TObject**, const TObject*&> {
00127
00128 private:
00129 const TObjArray *fArray;
00130 Int_t fCurCursor;
00131 Int_t fCursor;
00132 Bool_t fDirection;
00133
00134 TObjArrayIter() : fArray(0), fCurCursor(0), fCursor(0), fDirection(kIterForward) { }
00135
00136 public:
00137 TObjArrayIter(const TObjArray *arr, Bool_t dir = kIterForward);
00138 TObjArrayIter(const TObjArrayIter &iter);
00139 ~TObjArrayIter() { }
00140 TIterator &operator=(const TIterator &rhs);
00141 TObjArrayIter &operator=(const TObjArrayIter &rhs);
00142
00143 const TCollection *GetCollection() const { return fArray; }
00144 TObject *Next();
00145 void Reset();
00146 bool operator!=(const TIterator &aIter) const;
00147 bool operator!=(const TObjArrayIter &aIter) const;
00148 TObject *operator*() const;
00149
00150 ClassDef(TObjArrayIter,0)
00151 };
00152
00153 #if (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__) >= 40600
00154 #pragma GCC diagnostic pop
00155 #endif
00156
00157
00158
00159 inline Bool_t TObjArray::BoundsOk(const char *where, Int_t at) const
00160 {
00161 return (at < fLowerBound || at-fLowerBound >= fSize)
00162 ? OutOfBoundsError(where, at)
00163 : kTRUE;
00164 }
00165
00166 inline TObject *TObjArray::At(Int_t i) const
00167 {
00168
00169 int j = i-fLowerBound;
00170 if (j >= 0 && j < fSize) return fCont[j];
00171 BoundsOk("At", i);
00172 return 0;
00173 }
00174
00175 #endif