-
Notifications
You must be signed in to change notification settings - Fork 0
/
array.h
62 lines (48 loc) · 1.41 KB
/
array.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
#include "value.h"
#include <vector>
namespace jsonlite
{
class Array
{
public:
Array();
Array(const Value& value);
Array(const Array& other);
~Array();
size_t size() const;
bool empty() const;
typedef std::vector<Value*> container;
typedef container::const_iterator constIterator;
void clear();
bool parse(std::istream& input);
bool parse(const std::string& input);
void append(const Array& other);
void append(const Value& value);
template<typename T> T& get(UInt32 index);
template<typename T> const T& get(UInt32 index) const;
constIterator begin() const;
constIterator end() const;
// operators overload
Array& operator <<(const Array& other);
Array& operator <<(const Value& value);
Array& operator =(const Array& other);
Array& operator =(const Value& value);
friend std::ostream& operator <<(std::ostream& os, const Array& value);
private:
static bool parse(std::istream& input, Array& array);
void internalAdd(const Array& other);
void internalAdd(const Value& value);
container values;
};
template<typename T>
T& Array::get(UInt32 index) {
JSONLITE_ASSERT(index < size());
return values.at(index)->get<T>();
}
template<typename T>
const T& Array::get(UInt32 index) const {
JSONLITE_ASSERT(index < size());
const Value* v = values.at(index);
return v->get<T>();
}
}