-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvaluelist.h
136 lines (101 loc) · 3.07 KB
/
valuelist.h
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
131
132
133
134
135
136
#ifndef _H_ValueList
#define _H_ValueList
#include "tomlbase.h"
#include "parameter.h"
#include <iostream>
// ValueList should not be crippled by placing "all the same thing" checks
// on each call to push. Since TomlBase has a "Tag" facility, force the
// tag usage and value type matching here, for use by Toml Arrays which must be
// all of the same type, and the parser code will have to do a check
// Drawback is there is an extra PHP object tag for every
// Array representation.
namespace pun {
class VL_Iterator : public Php::Iterator {
ValueArray &_ref;
ValueArray::const_iterator _iter;
public:
VL_Iterator(Php::Base* pobj, ValueArray& aRef)
: Php::Iterator(pobj), _ref(aRef), _iter(aRef.begin())
{
}
virtual ~VL_Iterator() {}
virtual bool valid() override
{
return _iter != _ref.end();
}
virtual Php::Value current() override
{
return (*_iter);
}
virtual Php::Value key() override
{
return (int) (_iter - _ref.begin());
}
virtual void next() override
{
_iter++;
}
virtual void rewind() override
{
_iter = _ref.begin();
}
};
/*!
ValueList is a PHP wrapper of C++ std::vector<Php::Value>.
It supports random access, foreach, count, and is serializable.
ValueList supports push and pop operations.
*/
class ValueList : public TomlBase, public Php::Countable,
public Php::Traversable , public Php::Serializable
{
public:
static const char* PHP_NAME;
static void setup_ext(Php::Extension& ext /*, Php::Interface& if1*/);
ValueList() {}
void pushBack(Php::Parameters& param);
void popBack();
Php::Value getV(Php::Parameters& params) const;
void setV(Php::Parameters& param);
Php::Value back() const;
virtual long count() override { return (long) _store.size(); }
Php::Value size() const;
/*! function resize(int newLength [, newValue]);
Resize the container to newLength elements. If the new length is
greater, newValue or null are assigned to new elements.
*/
void resize(Php::Parameters& param);
void clear() { _store.clear(); }
virtual Php::Iterator *getIterator() override
{
return new VL_Iterator( this, _store);
}
// Return the Array as stored
Php::Value toArray();
Php::Value getTag() const;
void setTag(Php::Parameters& param);
Php::Value __toString();
virtual std::string serialize();
virtual void unserialize(const char *input, size_t size);
public:
void fn_pushBack(Php::Value& vtype);
int fn_endIndex() override;
Php::Value fn_getLast() const;
//std::string fn_typeConflict(Php::Type odd);
//std::string fn_classConflict(Php::Value& val);
unsigned int fn_size() { return _store.size(); }
Php::Value fn_object();
void fn_unserialize(std::istream& ins);
void fn_serialize(std::ostream& out);
ValueArray::iterator begin() { return _store.begin(); }
ValueArray::iterator end() { return _store.end(); }
ValueArray& fn_store() { return _store;}
private:
ValueArray _store;
// if storing objects, require same class name
// store it to avoid more calls to "get_class"
//Php::Value _className;
// require same value type
//Php::Type _type;
};
}; // end namespace pun
#endif