libUTL++
HashtableIt.h
1 #pragma once
2 
4 
5 #include <libutl/BidIt.h>
6 
8 
9 UTL_NS_BEGIN;
10 
12 
20 
22 class HashtableIt : public BidIt
23 {
25 
26 public:
33  HashtableIt(const Hashtable* ht, size_t idx, ListNode* node)
34  : _ht(const_cast<Hashtable*>(ht))
35  , _idx(idx)
36  , _node(node)
37  {
38  IFDEBUG(FwdIt::setOwner(_ht));
39  }
40 
42  virtual int compare(const Object& rhs) const;
43 
45  virtual void copy(const Object& rhs);
46 
47  virtual void forward(size_t dist = 1);
48 
49  virtual Object* get() const;
50 
52  Hashtable*
53  getHashtable() const
54  {
55  return _ht;
56  }
57 
59  size_t
60  getIdx() const
61  {
62  return _idx;
63  }
64 
66  const ListNode*
67  getNode() const
68  {
69  return _node;
70  }
71 
72  virtual void reverse(size_t dist = 1);
73 
74  virtual void set(const Object* object);
75 
76  HashtableIt& operator++()
77  {
78  forward();
79  return *this;
80  }
81 
82  HashtableIt operator++(int)
83  {
84  HashtableIt res = *this;
85  forward();
86  return res;
87  }
88 
89  HashtableIt& operator--()
90  {
91  reverse();
92  return *this;
93  }
94 
95  HashtableIt operator--(int)
96  {
97  HashtableIt res = *this;
98  reverse();
99  return res;
100  }
101 
102 private:
103  void
104  init()
105  {
106  _ht = nullptr;
107  _idx = size_t_max;
108  _node = nullptr;
109  }
110  void
111  deInit()
112  {
113  }
114 
115 private:
116  Hashtable* _ht;
117  size_t _idx;
118  ListNode* _node;
119 };
120 
122 
124 Hashtable::end() const
125 {
126  HashtableIt it(this, size_t_max, nullptr);
127  IFDEBUG(it.setConst(true));
128  return it;
129 }
130 
132 
134 Hashtable::end()
135 {
136  return HashtableIt(this, size_t_max, nullptr);
137 }
138 
140 
141 UTL_NS_END;
size_t getIdx() const
Get the index of the hash chain.
Definition: HashtableIt.h:60
List node.
Definition: ListNode.h:28
void deInit()
De-initialize UTL++.
Hashtable * getHashtable() const
Get the associated Hashtable.
Definition: HashtableIt.h:53
#define UTL_CLASS_DECL(DC, BC)
Declaration of standard UTL++ functionality for a non-template class.
Definition: macros.h:688
void reverse(const BidIt &begin, const BidIt &end)
Reverse a sequence.
const size_t size_t_max
Maximum size_t value.
HashtableIt(const Hashtable *ht, size_t idx, ListNode *node)
Constructor.
Definition: HashtableIt.h:33
#define IFDEBUG(x)
Do x in DEBUG mode only.
void copy(T *dest, const T *src, size_t len)
Copy one array of objects to another.
Definition: util_inl.h:690
const ListNode * getNode() const
Get the hash chain node.
Definition: HashtableIt.h:67
void setConst(bool p_const)
Set the const flag.
Definition: FwdIt.h:68
Bi-directional Hashtable iterator.
Definition: HashtableIt.h:22
Bi-directional iterator abstraction.
Definition: BidIt.h:25
Chained hashing collection.
Definition: Hashtable.h:92
Root of UTL++ class hierarchy.
Definition: Object.h:52
int compare(bool lhs, bool rhs)
Compare two boolean values.
void init()
Initialize UTL++.