blob: c37c22b85da982aaa140c70f7802c434b3edc259 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
|
/**
* HashIterator.h
*
* This is an internal helper class that is used when iterating over a
* Php::Value object that holds a hash table (an array or an object that
* does not implement the Traversable interface - stl style.
*
* Thus, when you do c++ things like "for (auto &iter : value)", internally
* a ValueIterator object is being used.
*
* @author Emiel Bruijntjes
* @copyright 2014 Copernica BV
*/
/**
* Forward declaration
*/
struct _hashtable;
struct bucket;
/**
* Set up namespace
*/
namespace Php {
/**
* Class definition
*/
class HashIterator : public IteratorImpl
{
public:
/**
* Constructor
* @param hashtable The hashtable to iterate over
* @param first Should it start on the first position?
*/
HashIterator(struct _hashtable *hashtable, bool first);
/**
* Copy constructor
* @param that
*/
HashIterator(const ValueIterator &that);
/**
* Destructor
*/
virtual ~HashIterator() {}
/**
* Increment position (pre-increment)
* @return bool
*/
virtual bool increment() override;
/**
* Decrement position (pre-decrement)
* @return bool
*/
virtual bool decrement() override;
/**
* Compare with other iterator
* @param that
* @return bool
*/
virtual bool equals(const IteratorImpl *that) const override
{
// this always is a hash iterator
HashIterator *other = (HashIterator *)that;
// compare the positions
return _position == other->_position;
}
/**
* Derefecence, this returns a std::pair with the current key and value
* @return std::pair
*/
virtual const std::pair<Value,Value> ¤t() const override
{
return _current;
}
private:
/**
* The hash table over which is being iterated
* @var HashTable
*/
struct _hashtable *_table = nullptr;
/**
* The position in the hash table
* @var HashPosition
*/
struct bucket *_position = nullptr;
/**
* The current key and value
* @var std::pair
*/
std::pair<Value,Value> _current;
/**
* Read current key and value
* @return bool
*/
bool read();
/**
* Invalidate the iterator
* @return bool
*/
bool invalidate();
};
/**
* End namespace
*/
}
|