Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
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
30
31
33
34friend class TOrdCollectionIter;
35
36private:
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
52
53public:
55
57
60 void Clear(Option_t *option="") override;
61 void Delete(Option_t *option="") override;
62 TObject **GetObjectRef(const TObject *obj) const override;
63 Int_t IndexOf(const TObject *obj) const override;
64 TIterator *MakeIterator(Bool_t dir = kIterForward) const override;
65
66 void AddFirst(TObject *obj) override;
67 void AddLast(TObject *obj) override;
68 void AddAt(TObject *obj, Int_t idx) override;
69 void AddAfter(const TObject *after, TObject *obj) override;
70 void AddBefore(const TObject *before, TObject *obj) override;
71 void PutAt(TObject *obj, Int_t idx);
72 TObject *RemoveAt(Int_t idx) override;
73 TObject *Remove(TObject *obj) override;
74
75 TObject *At(Int_t idx) const override;
76 TObject *Before(const TObject *obj) const override;
77 TObject *After(const TObject *obj) const override;
78 TObject *First() const override;
79 TObject *Last() const override;
80
81 void Sort();
83
84 ClassDefOverride(TOrdCollection,0) //An ordered collection
85};
86
87
88//////////////////////////////////////////////////////////////////////////
89// //
90// TOrdCollectionIter //
91// //
92// Iterator of ordered collection. //
93// //
94//////////////////////////////////////////////////////////////////////////
95
97
98private:
99 const TOrdCollection *fCol; //collection being iterated
100 Int_t fCurCursor; //current position in collection
101 Int_t fCursor; //next position in collection
102 Bool_t fDirection; //iteration direction
103
105
106public:
107 using iterator_category = std::bidirectional_iterator_tag;
109 using difference_type = std::ptrdiff_t;
110 using pointer = TObject **;
111 using const_pointer = const TObject **;
112 using reference = const TObject *&;
113
117 TIterator &operator=(const TIterator &rhs) override;
119
120 const TCollection *GetCollection() const override { return fCol; }
121 TObject *Next() override;
122 void Reset() override;
123 Bool_t operator!=(const TIterator &aIter) const override;
124 Bool_t operator!=(const TOrdCollectionIter &aIter) const;
125 TObject *operator*() const override;
126
127 ClassDefOverride(TOrdCollectionIter,0) //Ordered collection iterator
128};
129
130//---- inlines -----------------------------------------------------------------
131
133{
134 return (fSize < (fCapacity / 4) && fSize > TCollection::kInitCapacity);
135}
136
138 { return (idx < fGapStart) ? idx : idx + fGapSize; }
139
141 { return (idx < fGapStart) ? idx : idx - fGapSize; }
142
143#endif
bool Bool_t
Definition RtypesCore.h:63
const char Option_t
Definition RtypesCore.h:66
#define ClassDefOverride(name, id)
Definition Rtypes.h:341
const Bool_t kIterForward
Definition TCollection.h:42
Option_t Option_t option
Collection abstract base class.
Definition TCollection.h:65
Iterator abstract base class.
Definition TIterator.h:30
Mother of all ROOT objects.
Definition TObject.h:41
Iterator of ordered collection.
TIterator & operator=(const TIterator &rhs) override
Overridden assignment operator.
TObject * operator*() const override
Return current object or nullptr.
void Reset() override
Reset collection iterator.
const TOrdCollection * fCol
std::ptrdiff_t difference_type
TObject * Next() override
Return next object in collection.
const TCollection * GetCollection() const override
std::bidirectional_iterator_tag iterator_category
Bool_t operator!=(const TIterator &aIter) const override
This operator compares two TIterator objects.
Ordered collection.
void AddFirst(TObject *obj) override
Insert object at beginning of collection.
TObject * After(const TObject *obj) const override
Return the object after object obj.
TObject * First() const override
Return the first object in the collection.
Bool_t LowWaterMark() const
TOrdCollection(const TOrdCollection &)=delete
TOrdCollection & operator=(const TOrdCollection &)=delete
void PutAt(TObject *obj, Int_t idx)
Put object at index idx. Overwrites what was at idx before.
TObject ** fCont
void AddBefore(const TObject *before, TObject *obj) override
Insert object before object before in the collection.
void AddLast(TObject *obj) override
Add object at the end of the collection.
void Clear(Option_t *option="") override
Remove all objects from the collection.
void AddAfter(const TObject *after, TObject *obj) override
Insert object after object after in the collection.
~TOrdCollection()
Delete the collection.
Int_t PhysIndex(Int_t idx) const
void Sort()
If objects in collection are sortable (i.e.
Int_t IndexOf(const TObject *obj) const override
Return index of object in collection.
TObject * Last() const override
Return the last object in the collection.
Int_t LogIndex(Int_t idx) const
TObject * Remove(TObject *obj) override
Remove object from collection.
TObject * Before(const TObject *obj) const override
Returns the object before object obj.
TOrdCollectionIter Iterator_t
void AddAt(TObject *obj, Int_t idx) override
Insert object at position idx in the collection.
TObject * RemoveAt(Int_t idx) override
Remove object at index idx.
void Init(Int_t capacity)
Initialize ordered collection.
void Delete(Option_t *option="") override
Remove all objects from the collection AND delete all heap based objects.
Bool_t IllegalIndex(const char *method, Int_t idx) const
Return true when index out of bounds and print error.
TObject * At(Int_t idx) const override
Returns the object at position idx. Returns 0 if idx is out of range.
TObject ** GetObjectRef(const TObject *obj) const override
return address of pointer obj
void MoveGapTo(Int_t newGapStart)
Move gap to new position.
TIterator * MakeIterator(Bool_t dir=kIterForward) const override
Return an ordered collection iterator.
Int_t BinarySearch(TObject *obj)
Find object using a binary search.
void SetCapacity(Int_t newCapacity)
Set/change ordered collection capacity.
Sequenceable collection abstract base class.