Logo ROOT   6.07/09
Reference Guide
TOrdCollection.h
Go to the documentation of this file.
1 // @(#)root/cont:$Id$
2 // Author: Fons Rademakers 13/09/95
3 
4 /*************************************************************************
5  * Copyright (C) 1995-2000, Rene Brun and Fons Rademakers. *
6  * All rights reserved. *
7  * *
8  * For the licensing terms see $ROOTSYS/LICENSE. *
9  * For the list of contributors see $ROOTSYS/README/CREDITS. *
10  *************************************************************************/
11 
12 #ifndef ROOT_TOrdCollection
13 #define ROOT_TOrdCollection
14 
15 
16 //////////////////////////////////////////////////////////////////////////
17 // //
18 // TOrdCollection //
19 // //
20 // Ordered collection. //
21 // //
22 //////////////////////////////////////////////////////////////////////////
23 
24 #ifndef ROOT_TSeqCollection
25 #include "TSeqCollection.h"
26 #endif
27 
28 #include <iterator>
29 
30 
31 class TOrdCollectionIter;
32 
33 
35 
36 friend class TOrdCollectionIter;
37 
38 private:
43 
44  Int_t PhysIndex(Int_t idx) const;
45  Int_t LogIndex(Int_t idx) const;
46  void MoveGapTo(Int_t newGapStart);
47  Bool_t IllegalIndex(const char *method, Int_t idx) const;
48  void Init(Int_t capacity);
49  Bool_t LowWaterMark() const;
50  void SetCapacity(Int_t newCapacity);
51 
52  TOrdCollection(const TOrdCollection&); // Not implemented
53  TOrdCollection& operator=(const TOrdCollection&); // Not implemented
54 
55 public:
56  enum { kDefaultCapacity = 1, kMinExpand = 8, kShrinkFactor = 2 };
57 
59 
62  void Clear(Option_t *option="");
63  void Delete(Option_t *option="");
64  TObject **GetObjectRef(const TObject *obj) const;
65  Int_t IndexOf(const TObject *obj) const;
67 
68  void AddFirst(TObject *obj);
69  void AddLast(TObject *obj);
70  void AddAt(TObject *obj, Int_t idx);
71  void AddAfter(const TObject *after, TObject *obj);
72  void AddBefore(const TObject *before, TObject *obj);
73  void PutAt(TObject *obj, Int_t idx);
74  TObject *RemoveAt(Int_t idx);
75  TObject *Remove(TObject *obj);
76 
77  TObject *At(Int_t idx) const;
78  TObject *Before(const TObject *obj) const;
79  TObject *After(const TObject *obj) const;
80  TObject *First() const;
81  TObject *Last() const;
82 
83  void Sort();
85 
86  ClassDef(TOrdCollection,0) //An ordered collection
87 };
88 
89 
90 //////////////////////////////////////////////////////////////////////////
91 // //
92 // TOrdCollectionIter //
93 // //
94 // Iterator of ordered collection. //
95 // //
96 //////////////////////////////////////////////////////////////////////////
97 
99  public std::iterator<std::bidirectional_iterator_tag,
100  TObject*, std::ptrdiff_t,
101  const TObject**, const TObject*&> {
102 
103 private:
104  const TOrdCollection *fCol; //collection being iterated
105  Int_t fCurCursor; //current position in collection
106  Int_t fCursor; //next position in collection
107  Bool_t fDirection; //iteration direction
108 
109  TOrdCollectionIter() : fCol(0), fCurCursor(0), fCursor(0), fDirection(kIterForward) { }
110 
111 public:
115  TIterator &operator=(const TIterator &rhs);
117 
118  const TCollection *GetCollection() const { return fCol; }
119  TObject *Next();
120  void Reset();
121  Bool_t operator!=(const TIterator &aIter) const;
122  Bool_t operator!=(const TOrdCollectionIter &aIter) const;
123  TObject *operator*() const;
124 
125  ClassDef(TOrdCollectionIter,0) //Ordered collection iterator
126 };
127 
128 
129 //---- inlines -----------------------------------------------------------------
130 
132 {
133  return (fSize < (fCapacity / 4) && fSize > TCollection::kInitCapacity);
134 }
135 
137  { return (idx < fGapStart) ? idx : idx + fGapSize; }
138 
140  { return (idx < fGapStart) ? idx : idx - fGapSize; }
141 
142 #endif
void Init(Int_t capacity)
Initialize ordered collection.
void Delete(Option_t *option="")
Remove all objects from the collection AND delete all heap based objects.
TObject * Last() const
Return the last object in the collection.
const char Option_t
Definition: RtypesCore.h:62
TObject * Before(const TObject *obj) const
Returns the object before object obj.
void AddLast(TObject *obj)
Add object at the end of the collection.
TObject * At(Int_t idx) const
Returns the object at position idx. Returns 0 if idx is out of range.
TObject * After(const TObject *obj) const
Return the object after object obj.
TObject * First() const
Return the first object in the collection.
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
void AddBefore(const TObject *before, TObject *obj)
Insert object before object before in the collection.
TObject ** GetObjectRef(const TObject *obj) const
return address of pointer obj
const TCollection * GetCollection() const
Iterator abstract base class.
Definition: TIterator.h:32
Int_t IndexOf(const TObject *obj) const
Return index of object in collection.
TIterator * MakeIterator(Bool_t dir=kIterForward) const
Return an ordered collection iterator.
Int_t LogIndex(Int_t idx) const
Sequenceable collection abstract base class.
#define ClassDef(name, id)
Definition: Rtypes.h:254
void PutAt(TObject *obj, Int_t idx)
Put object at index idx. Overwrites what was at idx before.
const Bool_t kIterForward
Definition: TCollection.h:43
Bool_t operator!=(const TDatime &d1, const TDatime &d2)
Definition: TDatime.h:103
TOrdCollection(const TOrdCollection &)
Int_t PhysIndex(Int_t idx) const
~TOrdCollection()
Delete the collection.
void SetCapacity(Int_t newCapacity)
Set/change ordered collection capacity.
TObject ** fCont
TTime operator*(const TTime &t1, const TTime &t2)
Definition: TTime.h:87
Collection abstract base class.
Definition: TCollection.h:48
Int_t fSize
Definition: TCollection.h:63
TObject * RemoveAt(Int_t idx)
Remove object at index idx.
void AddFirst(TObject *obj)
Insert object at beginning of collection.
TOrdCollection & operator=(const TOrdCollection &)
void Reset(Detail::TBranchProxy *x)
TObject * Remove(TObject *obj)
Remove object from collection.
Bool_t LowWaterMark() const
void MoveGapTo(Int_t newGapStart)
Move gap to new position.
void Sort()
If objects in collection are sortable (i.e.
Bool_t IllegalIndex(const char *method, Int_t idx) const
Return true when index out of bounds and print error.
Int_t BinarySearch(TObject *obj)
Find object using a binary search.
Mother of all ROOT objects.
Definition: TObject.h:44
const TOrdCollection * fCol
TOrdCollectionIter Iterator_t
void Clear(Option_t *option="")
Remove all objects from the collection.
Iterator of ordered collection.
void AddAfter(const TObject *after, TObject *obj)
Insert object after object after in the collection.
void AddAt(TObject *obj, Int_t idx)
Insert object at position idx in the collection.
Ordered collection.
friend class TOrdCollectionIter