29 std::map<std::string, Value*>
objVal;
35 Value(std::istream & fromstream);
36 Value(
const std::string & val);
37 Value(
const char * val);
38 Value(
long long int val);
52 operator long long int()
const;
53 operator std::string()
const;
54 operator bool()
const;
56 const long long int asInt()
const;
59 const char *
c_str()
const;
79 bool isMember(
const std::string & name)
const;
86 unsigned int size()
const;
91 Value fromDTMI2(
const unsigned char * data,
unsigned int len,
unsigned int & i);
93 Value fromDTMI(
const unsigned char * data,
unsigned int len,
unsigned int & i);
97 void fromDTMI2(
const unsigned char * data,
unsigned int len,
unsigned int & i,
Value & ret);
99 void fromDTMI(
const unsigned char * data,
unsigned int len,
unsigned int & i,
Value & ret);
104 Value & operator*()
const;
105 Value* operator->()
const;
106 operator bool()
const;
108 const std::string & key()
const;
109 unsigned int num()
const;
114 std::deque<Value*>::iterator
aIt;
115 std::map<std::string, Value*>::iterator
oIt;
120 const Value & operator*()
const;
121 const Value* operator->()
const;
122 operator bool()
const;
124 const std::string & key()
const;
125 unsigned int num()
const;
130 std::deque<Value*>::const_iterator
aIt;
131 std::map<std::string, Value*>::const_iterator
oIt;
133 #define jsonForEach(val, i) for(JSON::Iter i(val); i; ++i) 134 #define jsonForEachConst(val, i) for(JSON::ConstIter i(val); i; ++i) 136 template <
typename T>
139 for (T it = begin; it != end; it++) {
140 long long int tmp = (*it);
141 while (tmp >= 0xFFFF) {
142 result += (char)0xFF;
143 result += (char)0xFF;
146 result += (char)(tmp / 256);
147 result += (char)(tmp % 256);
152 template <
typename T>
155 unsigned int tmp = 0;
156 for (
int i = 0; i < input.size(); i += 2) {
157 unsigned int curLen = (input[i] << 8) + input[i + 1];
159 if (curLen != 0xFFFF) {
160 result.push_back(tmp);
166 template <
typename T>
169 for (T it = begin; it != end; it++) {
170 long long int tmp = (*it);
171 while (tmp >= 0xFFFFFFFF) {
172 result += (char)0xFF;
173 result += (char)0xFF;
174 result += (char)0xFF;
175 result += (char)0xFF;
178 result += (char)((tmp & 0xFF000000) >> 24);
179 result += (char)((tmp & 0x00FF0000) >> 16);
180 result += (char)((tmp & 0x0000FF00) >> 8);
181 result += (char)((tmp & 0x000000FF));
186 template <
typename T>
189 unsigned int tmp = 0;
190 for (
int i = 0; i < input.size(); i += 4) {
191 unsigned int curLen = (input[i] << 24) + (input[i + 1] << 16) + (input[i + 2] << 8) + (input[i + 3]);
193 if (curLen != 0xFFFFFFFF) {
194 result.push_back(tmp);
bool isMember(const std::string &name) const
For object JSON::Value objects, returns true if the given name is a member.
Definition: json.cpp:1115
std::string strVal
Definition: json.h:27
bool isObject() const
Returns true if this object is an object.
Definition: json.cpp:1135
void null()
Completely clears the contents of this value, changing its type to NULL in the process.
Definition: json.cpp:473
std::string toPacked() const
Packs to a std::string for transfer over the network.
Definition: json.cpp:692
unsigned int size() const
Returns the total of the objects and array size combined.
Definition: json.cpp:1150
bool isString() const
Returns true if this object is a string.
Definition: json.cpp:1125
ValueType myType
Definition: json.h:111
const bool asBool() const
Explicit conversion to bool.
Definition: json.cpp:600
const std::string & asStringRef() const
Explicit conversion to std::string reference.
Definition: json.cpp:608
unsigned int packedSize() const
Returns the packed size of this Value.
Definition: json.cpp:830
void decodeVector(std::string input, T &result)
Definition: json.h:153
std::string & toNetPacked()
Packs any object-type JSON::Value to a std::string for transfer over the network, including proper DT...
Definition: json.cpp:932
std::string toString() const
Converts this JSON::Value to valid JSON notation and returns it.
Definition: json.cpp:948
Value fromString(std::string json)
Converts a std::string to a JSON::Value.
Definition: json.cpp:1155
A JSON::Value is either a string or an integer, but may also be an object, array or null...
Definition: json.h:21
bool isNull() const
Returns true if this object is null.
Definition: json.cpp:1145
std::deque< Value * >::iterator aIt
Definition: json.h:114
friend class ConstIter
Definition: json.h:23
ValueType myType
Definition: json.h:127
void sendTo(Socket::Connection &socket) const
Packs and transfers over the network.
Definition: json.cpp:745
void decodeVector4(std::string input, T &result)
Definition: json.h:187
bool operator!=(const Value &rhs) const
Compares a JSON::Value to another for equality.
Definition: json.cpp:467
std::map< std::string, Value * >::iterator oIt
Definition: json.h:115
bool isBool() const
Returns true if this object is a bool.
Definition: json.cpp:1130
Value * r
Definition: json.h:112
const char * c_str() const
Explicit conversion to c-string.
Definition: json.cpp:620
const std::string asString() const
Explicit conversion to std::string.
Definition: json.cpp:592
std::map< std::string, Value * > objVal
Definition: json.h:29
long long int intVal
Definition: json.h:26
std::deque< Value * > arrVal
Definition: json.h:28
std::string toPrettyString(int indentation=0) const
Converts this JSON::Value to valid JSON notation and returns it.
Definition: json.cpp:1006
Value()
Sets this JSON::Value to null;.
Definition: json.cpp:277
std::deque< Value * >::const_iterator aIt
Definition: json.h:130
void removeMember(const std::string &name)
For object JSON::Value objects, removes the member with the given name, if it exists.
Definition: json.cpp:1106
Value fromFile(std::string filename)
Converts a file to a JSON::Value.
Definition: json.cpp:1161
Value & operator[](const std::string i)
Retrieves or sets the JSON::Value at this position in the object.
Definition: json.cpp:629
const long long int asInt() const
Explicit conversion to long long int.
Definition: json.cpp:596
ValueType
Lists all types of JSON::Value.
Definition: json.h:15
Value fromDTMI2(std::string &data)
Definition: json.cpp:1280
bool operator==(const Value &rhs) const
Compares a JSON::Value to another for equality.
Definition: json.cpp:431
unsigned int i
Definition: json.h:129
void netPrepare()
Pre-packs any object-type JSON::Value to a std::string for transfer over the network, including proper DTMI header.
Definition: json.cpp:861
bool isInt() const
Returns true if this object is an integer.
Definition: json.cpp:1120
void append(const Value &rhs)
Appends the given value to the end of this JSON::Value array.
Definition: json.cpp:1069
std::string encodeVector4(T begin, T end)
Definition: json.h:167
~Value()
Sets this JSON::Value to null.
Definition: json.cpp:282
const Value * r
Definition: json.h:128
ValueType myType
Definition: json.h:25
Value fromDTMI(std::string &data)
Parses a std::string to a valid JSON::Value.
Definition: json.cpp:1269
std::string encodeVector(T begin, T end)
Definition: json.h:137
This class is for easy communicating through sockets, either TCP or Unix.
Definition: socket.h:47
void shrink(unsigned int size)
For array and object JSON::Value objects, reduces them so they contain at most size elements...
Definition: json.cpp:1093
JSON-related classes and functions.
Definition: json.h:12
std::map< std::string, Value * >::const_iterator oIt
Definition: json.h:131
friend class Iter
Definition: json.h:22
unsigned int i
Definition: json.h:113
Value & operator=(const Value &rhs)
Sets this JSON::Value to be equal to the given JSON::Value.
Definition: json.cpp:481
void prepend(const Value &rhs)
Prepends the given value to the beginning of this JSON::Value array.
Definition: json.cpp:1079
bool isArray() const
Returns true if this object is an array.
Definition: json.cpp:1140