| Debug.h | | Debug.h | |
| #ifndef libJSON_DEBUG_H | | #ifndef libJSON_DEBUG_H | |
| #define libJSON_DEBUG_H | | #define libJSON_DEBUG_H | |
| | | | |
| #ifdef DEBUG | | #ifdef DEBUG | |
|
| | | #ifdef JSON_SAFE | |
| | | #define libJSON_ASSERT_SAFE(condition, message, failcode)\ | |
| | | if (!(condition)){ if (Error){Error(message);} failcode } | |
| | | #define libJSON_FAIL_SAFE(message, failcode)\ | |
| | | { if (Error){ Error(message); } failcode } | |
| | | #else | |
| | | #define libJSON_ASSERT_SAFE(condition, message, failcode)\ | |
| | | if ((!(condition)) && (Error)) Error(message); | |
| | | #define libJSON_FAIL_SAFE(message, failcode)\ | |
| | | if (Error) Error(message); | |
| | | #endif | |
| | | | |
| #define libJSON_ASSERT(condition, message)\ | | #define libJSON_ASSERT(condition, message)\ | |
| if ((!(condition)) && (Error)) Error(message); | | if ((!(condition)) && (Error)) Error(message); | |
| #define libJSON_FAIL(message)\ | | #define libJSON_FAIL(message)\ | |
| if (Error) Error(message); | | if (Error) Error(message); | |
| | | | |
| #include "JSON_Strings.h" | | #include "JSON_Strings.h" | |
| | | | |
| extern "C"{ | | extern "C"{ | |
| typedef void (*ErrorCallback)(const json_char *); | | typedef void (*ErrorCallback)(const json_char *); | |
| } | | } | |
| #else | | #else | |
|
| | | #ifdef JSON_SAFE | |
| | | #define libJSON_ASSERT_SAFE(condition, message, failcode)\ | |
| | | if (!(condition)){ failcode; } | |
| | | #define libJSON_FAIL_SAFE(message, failcode)\ | |
| | | {failcode} | |
| | | #else | |
| | | #define libJSON_ASSERT_SAFE(condition, message, failcode) | |
| | | #define libJSON_FAIL_SAFE(message, failcode) | |
| | | #endif | |
| | | | |
| #define libJSON_ASSERT(condition, message) | | #define libJSON_ASSERT(condition, message) | |
| #define libJSON_FAIL(message) | | #define libJSON_FAIL(message) | |
| #endif | | #endif | |
| | | | |
| #endif | | #endif | |
| | | | |
End of changes. 2 change blocks. |
| 0 lines changed or deleted | | 22 lines changed or added | |
|
| JSONNode.h | | JSONNode.h | |
| #ifndef libJSON_NODE_H | | #ifndef libJSON_NODE_H | |
| #define libJSON_NODE_H | | #define libJSON_NODE_H | |
| | | | |
| #include <string> | | #include <string> | |
|
| #include <vector> | | | |
| #include "JSON_Strings.h" | | #include "JSON_Strings.h" | |
|
| | | #include "JSONChildren.h" | |
| | | | |
| #define foreach(iterator, container)\ | | #define foreach(iterator, container)\ | |
| for (typeof(container.begin()) iterator = container.begin(), iterator##
_end = container.end();\ | | for (typeof(container.begin()) iterator = container.begin(), iterator##
_end = container.end();\ | |
| iterator != iterator##_end;\ | | iterator != iterator##_end;\ | |
| ++iterator) | | ++iterator) | |
| | | | |
| using namespace std; | | using namespace std; | |
| | | | |
| union value_union_t { | | union value_union_t { | |
| bool _bool; | | bool _bool; | |
|
| double _number; | | #ifdef JSON_LESS_MEMORY | |
| size_t lastreal; //This is used to determine the last real entry in th | | float _number; | |
| e Children, because it's possible to have comments at the end, we don't wan | | size_t lastreal: 20; | |
| t commas before them | | #else | |
| | | double _number; | |
| | | size_t lastreal; //This is used to determine the last real entry i | |
| | | n the Children, because it's possible to have comments at the end, we don't | |
| | | want commas before them | |
| | | #endif | |
| }; | | }; | |
| | | | |
| class JSONNode { | | class JSONNode { | |
| public: | | public: | |
| JSONNode(const json_string & name_t, const json_string & value_t)
; | | JSONNode(const json_string & name_t, const json_string & value_t)
; | |
| JSONNode(void){}; //Used ONLY for duplicating | | JSONNode(void){}; //Used ONLY for duplicating | |
| JSONNode(JSONNode * parent); | | JSONNode(JSONNode * parent); | |
| ~JSONNode(void); | | ~JSONNode(void); | |
| void SetMyValue(const json_string & value_t); | | void SetMyValue(const json_string & value_t); | |
|
| void PurgeChildren(void); | | | |
| void Fetch(void); | | | |
| void CloneTo(JSONNode * node); | | void CloneTo(JSONNode * node); | |
| json_string Write(unsigned int indent, bool & commaafter); //pas
s 0xFFFFFFFF to do no formatting | | json_string Write(unsigned int indent, bool & commaafter); //pas
s 0xFFFFFFFF to do no formatting | |
| void Add(JSONNode * child); | | void Add(JSONNode * child); | |
| | | | |
|
| char type; //an enumerated type that tells the engine how to tre | | #ifdef JSON_LESS_MEMORY | |
| at it | | char type : 4; | |
| bool Fetched; //if the value has been parsed yet or not | | #else | |
| | | char type; //an enumerated type that tells the engine how to t | |
| | | reat it | |
| | | #endif | |
| | | | |
| | | #ifndef JSON_PREPARSE | |
| | | void Fetch(void); | |
| | | bool Fetched; //if the value has been parsed yet or not | |
| | | #endif | |
| | | | |
| #ifndef JSON_DLL //These are the only methods you should actuall
y use | | #ifndef JSON_DLL //These are the only methods you should actuall
y use | |
|
| void Preparse(void); | | #ifndef JSON_PREPARSE | |
| | | void Preparse(void); | |
| | | #endif | |
| | | | |
| JSONNode * GetNode(const json_string & name); | | JSONNode * GetNode(const json_string & name); | |
| JSONNode * GetNode_NoCase(const json_string & name); | | JSONNode * GetNode_NoCase(const json_string & name); | |
| JSONNode * NodeAt(unsigned int position); | | JSONNode * NodeAt(unsigned int position); | |
| unsigned int NodeSize(void); | | unsigned int NodeSize(void); | |
| JSONNode * PopNode(const json_string & name); | | JSONNode * PopNode(const json_string & name); | |
| JSONNode * PopNode_NoCase(const json_string & name); | | JSONNode * PopNode_NoCase(const json_string & name); | |
| JSONNode * PopNodeAt(unsigned int position); | | JSONNode * PopNodeAt(unsigned int position); | |
| | | | |
| char NodeType(void); | | char NodeType(void); | |
| const json_string & NodeName(void); | | const json_string & NodeName(void); | |
| const json_string & NodeAsString(void); | | const json_string & NodeAsString(void); | |
| int NodeAsInt(void); | | int NodeAsInt(void); | |
| bool NodeAsBool(void); | | bool NodeAsBool(void); | |
|
| double NodeAsFloat(void); | | #ifdef JSON_LESS_MEMORY | |
| | | float NodeAsFloat(void); | |
| | | #else | |
| | | double NodeAsFloat(void); | |
| | | #endif | |
| | | | |
| JSONNode * AddNewChild(const json_string & name, const jso
n_string & value); | | JSONNode * AddNewChild(const json_string & name, const jso
n_string & value); | |
| JSONNode * AddNewStringChild(const json_string & name, con
st json_string & value); | | JSONNode * AddNewStringChild(const json_string & name, con
st json_string & value); | |
| JSONNode * Duplicate(void); | | JSONNode * Duplicate(void); | |
| | | | |
| void AddChild(const JSONNode * node); | | void AddChild(const JSONNode * node); | |
| void SetValue(const json_string & value); | | void SetValue(const json_string & value); | |
| void SetStringValue(const json_string & value); | | void SetStringValue(const json_string & value); | |
| | | | |
| void AddComment(const json_string & comment); | | void AddComment(const json_string & comment); | |
| json_string Write(unsigned int indent = 0xFFFFFFFF); | | json_string Write(unsigned int indent = 0xFFFFFFFF); | |
| json_string WriteFormatted(void); | | json_string WriteFormatted(void); | |
| | | | |
| #ifdef DEBUG | | #ifdef DEBUG | |
| json_string Dump(void); | | json_string Dump(void); | |
| #endif | | #endif | |
| #endif | | #endif | |
| | | | |
|
| | | #ifdef JSON_SAFE | |
| | | void Nullify(void); | |
| | | #endif | |
| | | | |
| #ifdef DEBUG | | #ifdef DEBUG | |
| unsigned int GetMemoryUsage(void); | | unsigned int GetMemoryUsage(void); | |
| json_string MemDump(unsigned int indent = 0); | | json_string MemDump(unsigned int indent = 0); | |
| #endif | | #endif | |
| | | | |
| //This is the name of the node, the encoded flag tells the writer wh
ether or not to re-escape it when it gets written | | //This is the name of the node, the encoded flag tells the writer wh
ether or not to re-escape it when it gets written | |
| json_string _name; bool name_encoded; | | json_string _name; bool name_encoded; | |
| | | | |
| //This is the json_string that is the value of the node, this mig
ht be a json_string, a number, or even a set of nodes or array that hasn't
been parsed yet | | //This is the json_string that is the value of the node, this mig
ht be a json_string, a number, or even a set of nodes or array that hasn't
been parsed yet | |
| json_string _string; bool string_encoded; | | json_string _string; bool string_encoded; | |
| | | | |
| //internal structure changes depending on type | | //internal structure changes depending on type | |
| value_union_t _value; | | value_union_t _value; | |
| | | | |
|
| vector<JSONNode *> Children; | | jsonChildren Children; | |
| private: | | private: | |
|
| | | void FetchString(void); | |
| | | void FetchNode(void); | |
| | | void FetchArray(void); | |
| | | void FetchNumber(void); | |
| | | | |
| json_string WriteChildren(unsigned int indent); | | json_string WriteChildren(unsigned int indent); | |
| json_string WriteName(bool formatted) const; | | json_string WriteName(bool formatted) const; | |
| json_string WriteComment(unsigned int indent) const; | | json_string WriteComment(unsigned int indent) const; | |
| }; | | }; | |
| | | | |
| #endif | | #endif | |
| | | | |
End of changes. 10 change blocks. |
| 13 lines changed or deleted | | 39 lines changed or added | |
|
| JSON_Worker.h | | JSON_Worker.h | |
| | | | |
| skipping to change at line 13 | | skipping to change at line 13 | |
| | | | |
| #include <string> | | #include <string> | |
| #include "JSONNode.h" | | #include "JSONNode.h" | |
| | | | |
| using namespace std; | | using namespace std; | |
| | | | |
| class Worker { | | class Worker { | |
| public: | | public: | |
| static void DoArray(JSONNode * parent, const json_string & value_
t); | | static void DoArray(JSONNode * parent, const json_string & value_
t); | |
| static void DoNode(JSONNode * parent, const json_string & value_t
); | | static void DoNode(JSONNode * parent, const json_string & value_t
); | |
|
| #ifdef DEBUG | | #if defined DEBUG || defined JSON_SAFE | |
| static json_char * RemoveWhiteSpace(const json_string & value_t
, json_char & last); | | static json_char * RemoveWhiteSpace(const json_string & value_t
, json_char & last); | |
| #else | | #else | |
| static json_char * RemoveWhiteSpace(const json_string & value_t
); | | static json_char * RemoveWhiteSpace(const json_string & value_t
); | |
| #endif | | #endif | |
| static json_string FixString(const json_string & value_t, bool &
flag); | | static json_string FixString(const json_string & value_t, bool &
flag); | |
| static json_string UnfixString(const json_string & value_t, bool
flag); | | static json_string UnfixString(const json_string & value_t, bool
flag); | |
| private: | | private: | |
| static json_char Hex(const json_char * & pos); | | static json_char Hex(const json_char * & pos); | |
| static unsigned json_char UTF8(const json_char * & pos); | | static unsigned json_char UTF8(const json_char * & pos); | |
| static json_string toUTF8(unsigned json_char p); | | static json_string toUTF8(unsigned json_char p); | |
| #ifdef JSON_UNICODE | | #ifdef JSON_UNICODE | |
| static json_string UTF(const json_char * & pos); | | static json_string UTF(const json_char * & pos); | |
| static json_string toSurrogatePair(unsigned json_char pos); | | static json_string toSurrogatePair(unsigned json_char pos); | |
| #endif | | #endif | |
|
| static json_char FromOctal(const json_char * & pos); | | | |
| static void SpecialChar(const json_char * & pos, json_string & re
s); | | static void SpecialChar(const json_char * & pos, json_string & re
s); | |
| static size_t FindNextRelevant(json_char ch, const json_string &
value_t, const size_t pos); | | static size_t FindNextRelevant(json_char ch, const json_string &
value_t, const size_t pos); | |
| }; | | }; | |
| | | | |
| #endif | | #endif | |
| | | | |
End of changes. 2 change blocks. |
| 2 lines changed or deleted | | 1 lines changed or added | |
|
| jsonmain.h | | jsonmain.h | |
| | | | |
| skipping to change at line 28 | | skipping to change at line 28 | |
| * Check included Open Document for documentation | | * Check included Open Document for documentation | |
| * | | * | |
| */ | | */ | |
| | | | |
| #ifdef JSON_DLL | | #ifdef JSON_DLL | |
| //DLL interface | | //DLL interface | |
| extern "C" { | | extern "C" { | |
| //These are for creating and deleting json document | | //These are for creating and deleting json document | |
| JSONNODE JSON_Parse(const json_char * json); | | JSONNODE JSON_Parse(const json_char * json); | |
| void JSON_Delete(const JSONNODE node); | | void JSON_Delete(const JSONNODE node); | |
|
| void JSON_Preparse(const JSONNODE node); | | #ifndef JSON_PREPARSE | |
| | | void JSON_Preparse(const JSONNODE node); | |
| | | #endif | |
| | | | |
| //These are for getting nodes out of that document | | //These are for getting nodes out of that document | |
| JSONNODE JSON_GetNode(const JSONNODE parent, const json_char * na
me); | | JSONNODE JSON_GetNode(const JSONNODE parent, const json_char * na
me); | |
| JSONNODE JSON_GetNode_NoCase(const JSONNODE parent, const json_ch
ar * name); | | JSONNODE JSON_GetNode_NoCase(const JSONNODE parent, const json_ch
ar * name); | |
| JSONNODE JSON_NodeAt(const JSONNODE parent, unsigned int position
); | | JSONNODE JSON_NodeAt(const JSONNODE parent, unsigned int position
); | |
| unsigned int JSON_NodeSize(const JSONNODE node); | | unsigned int JSON_NodeSize(const JSONNODE node); | |
| JSONNODE JSON_PopNode(const JSONNODE parent, const json_char * na
me); | | JSONNODE JSON_PopNode(const JSONNODE parent, const json_char * na
me); | |
| JSONNODE JSON_PopNode_NoCase(const JSONNODE parent, const json_ch
ar * name); | | JSONNODE JSON_PopNode_NoCase(const JSONNODE parent, const json_ch
ar * name); | |
| JSONNODE JSON_PopNodeAt(const JSONNODE parent, unsigned int posit
ion); | | JSONNODE JSON_PopNodeAt(const JSONNODE parent, unsigned int posit
ion); | |
| | | | |
| | | | |
End of changes. 1 change blocks. |
| 1 lines changed or deleted | | 3 lines changed or added | |
|