00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012 #ifndef ROOT_TOrdCollection
00013 #define ROOT_TOrdCollection
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #ifndef ROOT_TSeqCollection
00025 #include "TSeqCollection.h"
00026 #endif
00027
00028 #include <iterator>
00029
00030
00031 class TOrdCollectionIter;
00032
00033
00034 class TOrdCollection : public TSeqCollection {
00035
00036 friend class TOrdCollectionIter;
00037
00038 private:
00039 TObject **fCont;
00040 Int_t fCapacity;
00041 Int_t fGapStart;
00042 Int_t fGapSize;
00043
00044 Int_t PhysIndex(Int_t idx) const;
00045 Int_t LogIndex(Int_t idx) const;
00046 void MoveGapTo(Int_t newGapStart);
00047 Bool_t IllegalIndex(const char *method, Int_t idx) const;
00048 void Init(Int_t capacity);
00049 Bool_t LowWaterMark() const;
00050 void SetCapacity(Int_t newCapacity);
00051
00052 TOrdCollection(const TOrdCollection&);
00053 TOrdCollection& operator=(const TOrdCollection&);
00054
00055 public:
00056 enum { kDefaultCapacity = 1, kMinExpand = 8, kShrinkFactor = 2 };
00057
00058 typedef TOrdCollectionIter Iterator_t;
00059
00060 TOrdCollection(Int_t capacity = kDefaultCapacity);
00061 ~TOrdCollection();
00062 void Clear(Option_t *option="");
00063 void Delete(Option_t *option="");
00064 TObject **GetObjectRef(const TObject *obj) const;
00065 Int_t IndexOf(const TObject *obj) const;
00066 TIterator *MakeIterator(Bool_t dir = kIterForward) const;
00067
00068 void AddFirst(TObject *obj);
00069 void AddLast(TObject *obj);
00070 void AddAt(TObject *obj, Int_t idx);
00071 void AddAfter(const TObject *after, TObject *obj);
00072 void AddBefore(const TObject *before, TObject *obj);
00073 void PutAt(TObject *obj, Int_t idx);
00074 TObject *RemoveAt(Int_t idx);
00075 TObject *Remove(TObject *obj);
00076
00077 TObject *At(Int_t idx) const;
00078 TObject *Before(const TObject *obj) const;
00079 TObject *After(const TObject *obj) const;
00080 TObject *First() const;
00081 TObject *Last() const;
00082
00083 void Sort();
00084 Int_t BinarySearch(TObject *obj);
00085
00086 ClassDef(TOrdCollection,0)
00087 };
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098 class TOrdCollectionIter : public TIterator,
00099 public std::iterator<std::bidirectional_iterator_tag,
00100 TObject*, std::ptrdiff_t,
00101 const TObject**, const TObject*&> {
00102
00103 private:
00104 const TOrdCollection *fCol;
00105 Int_t fCurCursor;
00106 Int_t fCursor;
00107 Bool_t fDirection;
00108
00109 TOrdCollectionIter() : fCol(0), fCurCursor(0), fCursor(0), fDirection(kIterForward) { }
00110
00111 public:
00112 TOrdCollectionIter(const TOrdCollection *col, Bool_t dir = kIterForward);
00113 TOrdCollectionIter(const TOrdCollectionIter &iter);
00114 ~TOrdCollectionIter() { }
00115 TIterator &operator=(const TIterator &rhs);
00116 TOrdCollectionIter &operator=(const TOrdCollectionIter &rhs);
00117
00118 const TCollection *GetCollection() const { return fCol; }
00119 TObject *Next();
00120 void Reset();
00121 bool operator!=(const TIterator &aIter) const;
00122 bool operator!=(const TOrdCollectionIter &aIter) const;
00123 TObject *operator*() const;
00124
00125 ClassDef(TOrdCollectionIter,0)
00126 };
00127
00128
00129
00130
00131 inline Bool_t TOrdCollection::LowWaterMark() const
00132 {
00133 return (fSize < (fCapacity / 4) && fSize > TCollection::kInitCapacity);
00134 }
00135
00136 inline Int_t TOrdCollection::PhysIndex(Int_t idx) const
00137 { return (idx < fGapStart) ? idx : idx + fGapSize; }
00138
00139 inline Int_t TOrdCollection::LogIndex(Int_t idx) const
00140 { return (idx < fGapStart) ? idx : idx - fGapSize; }
00141
00142 #endif