libUTL++
THeap.h
1 #pragma once
2 
4 
5 #include <libutl/THeapIt.h>
6 
8 
9 UTL_NS_BEGIN;
10 
12 
22 
24 template <class T>
25 class THeap : public Heap
26 {
29 
30 public:
39  THeap(size_t size,
40  size_t increment = uint_t_max,
41  bool owner = true,
42  bool multiSet = true,
43  Ordering* ordering = nullptr);
44 
50  THeap(bool owner, bool multiSet = true);
51 
52  bool
53  add(const T& object)
54  {
55  return super::add(const_cast<T&>(object));
56  }
57 
58  bool
59  add(const T* object)
60  {
61  return super::add(const_cast<T*>(object));
62  }
63 
64  void
65  add(const Collection& collection)
66  {
67  super::add(collection);
68  }
69 
71  begin() const
72  {
73  THeapIt<T> res;
74  res.copy(Heap::begin());
75  return res;
76  }
77 
79  begin()
80  {
81  THeapIt<T> res;
82  res.copy(Heap::begin());
83  return res;
84  }
85 
87  end() const
88  {
89  THeapIt<T> res;
90  res.copy(Heap::end());
91  return res;
92  }
93 
95  end()
96  {
97  THeapIt<T> res;
98  res.copy(Heap::end());
99  return res;
100  }
101 
103  T*
104  findT(const Object& key) const
105  {
106  return utl::cast<T>(Heap::find(key));
107  }
108 
109  T*
110  pop()
111  {
112  return utl::cast<T>(Heap::pop());
113  }
114 
115 public:
116  typedef T type;
117  typedef THeapIt<T> iterator;
118  typedef T* value_type; // for STL
119 };
120 
122 
123 template <class T>
124 THeap<T>::THeap(size_t size, size_t increment, bool owner, bool multiSet, Ordering* ordering)
125  : Heap(size, increment, owner, multiSet, ordering)
126 {
127 }
128 
130 
131 template <class T>
132 THeap<T>::THeap(bool owner, bool multiSet)
133  : Heap(owner, multiSet)
134 {
135 }
136 
138 
139 UTL_NS_END;
140 
142 
#define UTL_CLASS_IMPL_TPL(className, T)
Implementation of standard UTL++ functionality for a template class.
Definition: macros.h:906
#define UTL_CLASS_DEFID
Default init() and deInit() (which are merely place-holders).
Definition: macros.h:532
virtual void copy(const Object &rhs)
Copy another HeapIt.
THeap(size_t size, size_t increment=uint_t_max, bool owner=true, bool multiSet=true, Ordering *ordering=nullptr)
Constructor.
Definition: THeap.h:124
Object comparison abstraction.
Definition: Ordering.h:30
Template version of Heap.
Definition: THeap.h:25
Templated proxy for BidIt.
Definition: TBidIt.h:19
Heap data structure.
Definition: Heap.h:55
T * findT(const Object &key) const
See find().
Definition: THeap.h:104
const uint_t uint_t_max
Maximum uint_t value.
#define UTL_CLASS_DECL_TPL(DC, T, BC)
Declaration of standard UTL++ functionality for a template class with one parameter.
Definition: macros.h:713
Template version of HeapIt.
Definition: THeapIt.h:23
Root of UTL++ class hierarchy.
Definition: Object.h:52
A collection of objects.
Definition: Collection.h:62