Commit 4e6a400a authored by Niels's avatar Niels

- reorganized payload

parent ec6e628d
This diff is collapsed.
......@@ -39,18 +39,44 @@ class JSON {
array, object, null, string, boolean, number, number_float
} json_t;
private:
/// the type of this object
json_t _type;
/// the payload
void* _payload;
public:
/// a type for an object
typedef std::map<std::string, JSON> object_t;
/// a type for an array
typedef std::vector<JSON> array_t;
/// a type for a string
typedef std::string string_t;
/// a type for a Boolean
typedef bool boolean_t;
/// a type for an integer number
typedef int number_t;
/// a type for a floating point number
typedef double number_float_t;
/// a JSON value
union value {
array_t* array;
object_t* object;
string_t* string;
boolean_t* boolean;
number_t* number;
number_float_t* number_float;
value() {}
value(array_t* array): array(array) {}
value(object_t* object): object(object) {}
value(string_t* string): string(string) {}
value(boolean_t* boolean) : boolean(boolean) {}
value(number_t* number) : number(number) {}
value(number_float_t* number_float) : number_float(number_float) {}
};
private:
/// the type of this object
json_t _type;
/// the payload
value _value;
#ifdef __cplusplus11
/// a type for array initialization
......@@ -190,9 +216,9 @@ class JSON {
const_iterator find(const char*) const;
/// direct access to the underlying payload
void* data();
value data();
/// direct access to the underlying payload
const void* data() const;
const value data() const;
/// lexicographically compares the values
bool operator==(const JSON&) const;
......
......@@ -145,7 +145,7 @@ void test_string() {
{
// get payload
std::string* s1 = static_cast<std::string*>(a.data());
std::string* s1 = a.data().string;
std::string s2 = a;
assert(*s1 == s2);
}
......@@ -271,7 +271,7 @@ void test_array() {
{
// get payload
std::vector<JSON>* array = static_cast<std::vector<JSON>*>(a.data());
std::vector<JSON>* array = a.data().array;
assert(array->size() == a.size());
assert(array->empty() == a.empty());
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment