summaryrefslogtreecommitdiff
path: root/include/valueiterator.h
blob: 95cdac62f2a14f8c4411cae7c5269bf4ed545207 (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
122
123
124
125
126
127
128
129
130
/**
 *  ValueIterator.h
 *
 *  This is an internal helper class that is used when iterating over a
 *  Php::Value object - 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
 */

/**
 *  Set up namespace
 */
namespace Php {

/**
 *  Forward declarations
 */
class ValueIteratorImpl;

/**
 *  Class definition
 */
class ValueIterator
{
public:
    /**
     *  Constructor
     *  @param  impl        Implementation iterator
     */
    ValueIterator(ValueIteratorImpl *impl) : _impl(impl) {}
    
    /**
     *  Copy constructor
     *  @param  that
     */
    ValueIterator(const ValueIterator &that);
    
    /**
     *  Destructor
     */
    virtual ~ValueIterator();

    /**
     *  Increment position (pre-increment)
     *  @return ValueIterator
     */
    ValueIterator &operator++();
    
    /**
     *  Increment position (post-increment)
     *  @return ValueIterator
     */
    ValueIterator operator++(int)
    {
        // make a copy
        ValueIterator copy(*this);
        
        // increment current object
        ++(*this);
        
        // and return the unchanged original
        return copy;
    }
    
    /**
     *  Decrement position (pre-decrement)
     *  @return ValueIterator
     */
    ValueIterator &operator--();

    /**
     *  Increment position (post-decrement)
     *  @return ValueIterator
     */
    ValueIterator operator--(int)
    {
        // make a copy
        ValueIterator copy(*this);
        
        // decrement current object
        --(*this);
        
        // and return the unchanged original
        return copy;
    }
    
    /**
     *  Compare with other iterator
     *  @param  that
     *  @return bool
     */
    bool operator==(const ValueIterator &that) const;

    /**
     *  Compare with other iterator
     *  @param  that
     *  @return bool
     */
    bool operator!=(const ValueIterator &that) const;

    /**
     *  Derefecence, this returns a std::pair with the current key and value
     *  @return std::pair
     */
    const std::pair<Value,Value> &operator*() const;
    
    /**
     *  Dereference, this returns a std::pair with the current key and value
     *  @return std::pair
     */
    const std::pair<Value,Value> *operator->() const;

private:
    /**
     *  Pointer to the actual implementation
     *  @var    std::unique_ptr
     */
    ValueIteratorImpl *_impl;

};

/**
 *  End namespace
 */
}