Logo ROOT  
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 #include "TSeqCollection.h"
25 
26 #include <iterator>
27 
28 
29 class TOrdCollectionIter;
30 
31 
33 
34 friend class TOrdCollectionIter;
35 
36 private:
41 
42  Int_t PhysIndex(Int_t idx) const;
43  Int_t LogIndex(Int_t idx) const;
44  void MoveGapTo(Int_t newGapStart);
45  Bool_t IllegalIndex(const char *method, Int_t idx) const;
46  void Init(Int_t capacity);
47  Bool_t LowWaterMark() const;
48  void SetCapacity(Int_t newCapacity);
49 
50  TOrdCollection(const TOrdCollection&); // Not implemented
51  TOrdCollection& operator=(const TOrdCollection&); // Not implemented
52 
53 public:
54  enum { kDefaultCapacity = 1, kMinExpand = 8, kShrinkFactor = 2 };
55 
57 
60  void Clear(Option_t *option="");
61  void Delete(Option_t *option="");
62  TObject **GetObjectRef(const TObject *obj) const;
63  Int_t IndexOf(const TObject *obj) const;
65 
66  void AddFirst(TObject *obj);
67  void AddLast(TObject *obj);
68  void AddAt(TObject *obj, Int_t idx);
69  void AddAfter(const TObject *after, TObject *obj);
70  void AddBefore(const TObject *before, TObject *obj);
71  void PutAt(TObject *obj, Int_t idx);
72  TObject *RemoveAt(Int_t idx);
73  TObject *Remove(TObject *obj);
74 
75  TObject *At(Int_t idx) const;
76  TObject *Before(const TObject *obj) const;
77  TObject *After(const TObject *obj) const;
78  TObject *First() const;
79  TObject *Last() const;
80 
81  void Sort();
83 
84  ClassDef(TOrdCollection,0) //An ordered collection
85 };
86 
87 
88 //////////////////////////////////////////////////////////////////////////
89 // //
90 // TOrdCollectionIter //
91 // //
92 // Iterator of ordered collection. //
93 // //
94 //////////////////////////////////////////////////////////////////////////
95 
97  public std::iterator<std::bidirectional_iterator_tag,
98  TObject*, std::ptrdiff_t,
99  const TObject**, const TObject*&> {
100 
101 private:
102  const TOrdCollection *fCol; //collection being iterated
103  Int_t fCurCursor; //current position in collection
104  Int_t fCursor; //next position in collection
105  Bool_t fDirection; //iteration direction
106 
108 
109 public:
113  TIterator &operator=(const TIterator &rhs);
115 
116  const TCollection *GetCollection() const { return fCol; }
117  TObject *Next();
118  void Reset();
119  Bool_t operator!=(const TIterator &aIter) const;
120  Bool_t operator!=(const TOrdCollectionIter &aIter) const;
121  TObject *operator*() const;
122 
123  ClassDef(TOrdCollectionIter,0) //Ordered collection iterator
124 };
125 
126 
127 //---- inlines -----------------------------------------------------------------
128 
130 {
131  return (fSize < (fCapacity / 4) && fSize > TCollection::kInitCapacity);
132 }
133 
135  { return (idx < fGapStart) ? idx : idx + fGapSize; }
136 
138  { return (idx < fGapStart) ? idx : idx - fGapSize; }
139 
140 #endif
TOrdCollection::Last
TObject * Last() const
Return the last object in the collection.
Definition: TOrdCollection.cxx:234
TOrdCollection::PhysIndex
Int_t PhysIndex(Int_t idx) const
Definition: TOrdCollection.h:134
TOrdCollection::IllegalIndex
Bool_t IllegalIndex(const char *method, Int_t idx) const
Return true when index out of bounds and print error.
Definition: TOrdCollection.cxx:242
TOrdCollectionIter::operator*
TObject * operator*() const
Return current object or nullptr.
Definition: TOrdCollection.cxx:551
TOrdCollection::Delete
void Delete(Option_t *option="")
Remove all objects from the collection AND delete all heap based objects.
Definition: TOrdCollection.cxx:199
TOrdCollection::GetObjectRef
TObject ** GetObjectRef(const TObject *obj) const
return address of pointer obj
Definition: TOrdCollection.cxx:224
TOrdCollection::fGapStart
Int_t fGapStart
Definition: TOrdCollection.h:39
TOrdCollection::kMinExpand
@ kMinExpand
Definition: TOrdCollection.h:54
TOrdCollection
Definition: TOrdCollection.h:32
TOrdCollection::kDefaultCapacity
@ kDefaultCapacity
Definition: TOrdCollection.h:54
TOrdCollection::RemoveAt
TObject * RemoveAt(Int_t idx)
Remove object at index idx.
Definition: TOrdCollection.cxx:328
TOrdCollectionIter::fCursor
Int_t fCursor
Definition: TOrdCollection.h:104
TOrdCollection::SetCapacity
void SetCapacity(Int_t newCapacity)
Set/change ordered collection capacity.
Definition: TOrdCollection.cxx:378
TOrdCollection::AddBefore
void AddBefore(const TObject *before, TObject *obj)
Insert object before object before in the collection.
Definition: TOrdCollection.cxx:108
TOrdCollection::kShrinkFactor
@ kShrinkFactor
Definition: TOrdCollection.h:54
Bool_t
bool Bool_t
Definition: RtypesCore.h:63
TOrdCollection::~TOrdCollection
~TOrdCollection()
Delete the collection.
Definition: TOrdCollection.cxx:46
bool
TIterator
Definition: TIterator.h:30
TOrdCollection::AddAt
void AddAt(TObject *obj, Int_t idx)
Insert object at position idx in the collection.
Definition: TOrdCollection.cxx:59
kIterForward
const Bool_t kIterForward
Definition: TCollection.h:40
TOrdCollection::MakeIterator
TIterator * MakeIterator(Bool_t dir=kIterForward) const
Return an ordered collection iterator.
Definition: TOrdCollection.cxx:280
TOrdCollection::Before
TObject * Before(const TObject *obj) const
Returns the object before object obj.
Definition: TOrdCollection.cxx:170
TOrdCollection::TOrdCollection
TOrdCollection(const TOrdCollection &)
TOrdCollectionIter::fDirection
Bool_t fDirection
Definition: TOrdCollection.h:105
TOrdCollection::At
TObject * At(Int_t idx) const
Returns the object at position idx. Returns 0 if idx is out of range.
Definition: TOrdCollection.cxx:160
TOrdCollectionIter::fCurCursor
Int_t fCurCursor
Definition: TOrdCollection.h:103
Option_t
const typedef char Option_t
Definition: RtypesCore.h:66
TOrdCollection::IndexOf
Int_t IndexOf(const TObject *obj) const
Return index of object in collection.
Definition: TOrdCollection.cxx:255
TSeqCollection.h
TOrdCollectionIter::operator!=
Bool_t operator!=(const TIterator &aIter) const
This operator compares two TIterator objects.
Definition: TOrdCollection.cxx:531
TOrdCollectionIter::TOrdCollectionIter
TOrdCollectionIter()
Definition: TOrdCollection.h:107
TOrdCollection::operator=
TOrdCollection & operator=(const TOrdCollection &)
TCollection::fSize
Int_t fSize
Definition: TCollection.h:148
TOrdCollection::LowWaterMark
Bool_t LowWaterMark() const
Definition: TOrdCollection.h:129
TOrdCollectionIter::operator=
TIterator & operator=(const TIterator &rhs)
Overridden assignment operator.
Definition: TOrdCollection.cxx:472
TOrdCollection::After
TObject * After(const TObject *obj) const
Return the object after object obj.
Definition: TOrdCollection.cxx:147
TOrdCollection::PutAt
void PutAt(TObject *obj, Int_t idx)
Put object at index idx. Overwrites what was at idx before.
Definition: TOrdCollection.cxx:315
TOrdCollection::AddAfter
void AddAfter(const TObject *after, TObject *obj)
Insert object after object after in the collection.
Definition: TOrdCollection.cxx:129
TOrdCollectionIter
Definition: TOrdCollection.h:96
TOrdCollection::MoveGapTo
void MoveGapTo(Int_t newGapStart)
Move gap to new position.
Definition: TOrdCollection.cxx:289
TSeqCollection
Definition: TSeqCollection.h:28
TOrdCollection::Sort
void Sort()
If objects in collection are sortable (i.e.
Definition: TOrdCollection.cxx:397
TOrdCollectionIter::Next
TObject * Next()
Return next object in collection.
Definition: TOrdCollection.cxx:502
TOrdCollection::Remove
TObject * Remove(TObject *obj)
Remove object from collection.
Definition: TOrdCollection.cxx:365
TOrdCollection::BinarySearch
Int_t BinarySearch(TObject *obj)
Find object using a binary search.
Definition: TOrdCollection.cxx:415
TOrdCollection::Init
void Init(Int_t capacity)
Initialize ordered collection.
Definition: TOrdCollection.cxx:267
TOrdCollectionIter::Reset
void Reset()
Reset collection iterator.
Definition: TOrdCollection.cxx:518
TOrdCollection::fCapacity
Int_t fCapacity
Definition: TOrdCollection.h:38
TObject
Definition: TObject.h:37
ClassDef
#define ClassDef(name, id)
Definition: Rtypes.h:325
TOrdCollection::Iterator_t
TOrdCollectionIter Iterator_t
Definition: TOrdCollection.h:56
TCollection
Definition: TCollection.h:63
TOrdCollectionIter::GetCollection
const TCollection * GetCollection() const
Definition: TOrdCollection.h:116
TOrdCollection::AddFirst
void AddFirst(TObject *obj)
Insert object at beginning of collection.
Definition: TOrdCollection.cxx:92
TOrdCollection::Clear
void Clear(Option_t *option="")
Remove all objects from the collection.
Definition: TOrdCollection.cxx:184
TOrdCollection::fCont
TObject ** fCont
Definition: TOrdCollection.h:37
TOrdCollection::First
TObject * First() const
Return the first object in the collection.
Definition: TOrdCollection.cxx:216
TOrdCollectionIter::~TOrdCollectionIter
~TOrdCollectionIter()
Definition: TOrdCollection.h:112
TCollection::kInitCapacity
@ kInitCapacity
Definition: TCollection.h:157
int
TOrdCollection::fGapSize
Int_t fGapSize
Definition: TOrdCollection.h:40
TOrdCollection::AddLast
void AddLast(TObject *obj)
Add object at the end of the collection.
Definition: TOrdCollection.cxx:100
TOrdCollectionIter::fCol
const TOrdCollection * fCol
Definition: TOrdCollection.h:102
TOrdCollection::LogIndex
Int_t LogIndex(Int_t idx) const
Definition: TOrdCollection.h:137