diff options
Diffstat (limited to 'storage/connect/json.h')
-rw-r--r-- | storage/connect/json.h | 91 |
1 files changed, 55 insertions, 36 deletions
diff --git a/storage/connect/json.h b/storage/connect/json.h index da45157f124..4ea169e1b18 100644 --- a/storage/connect/json.h +++ b/storage/connect/json.h @@ -1,5 +1,5 @@ /**************** json H Declares Source Code File (.H) ****************/ -/* Name: json.h Version 1.1 */ +/* Name: json.h Version 1.2 */ /* */ /* (C) Copyright to the author Olivier BERTRAND 2014 - 2015 */ /* */ @@ -16,8 +16,9 @@ enum JTYP {TYPE_STRG = 1, TYPE_DBL = 2, TYPE_BOOL = 4, - TYPE_INTG = 7, - TYPE_JSON = 12, + TYPE_BINT = 5, + TYPE_INTG = 7, + TYPE_JSON = 12, TYPE_JAR, TYPE_JOB, TYPE_JVAL}; @@ -40,13 +41,13 @@ typedef struct { int len; } STRG, *PSG; -PJSON ParseJson(PGLOBAL g, char *s, int n, int prty, bool *b = NULL); -PJAR ParseArray(PGLOBAL g, int& i, STRG& src); -PJOB ParseObject(PGLOBAL g, int& i, STRG& src); -PJVAL ParseValue(PGLOBAL g, int& i, STRG& src); +PJSON ParseJson(PGLOBAL g, char *s, int n, int *prty = NULL, bool *b = NULL); +PJAR ParseArray(PGLOBAL g, int& i, STRG& src, bool *pty); +PJOB ParseObject(PGLOBAL g, int& i, STRG& src, bool *pty); +PJVAL ParseValue(PGLOBAL g, int& i, STRG& src, bool *pty); char *ParseString(PGLOBAL g, int& i, STRG& src); PVAL ParseNumeric(PGLOBAL g, int& i, STRG& src); -PSZ Serialize(PGLOBAL g, PJSON jsp, FILE *fs, int pretty); +PSZ Serialize(PGLOBAL g, PJSON jsp, char *fn, int pretty); bool SerializeArray(JOUT *js, PJAR jarp, bool b); bool SerializeObject(JOUT *js, PJOB jobp); bool SerializeValue(JOUT *js, PJVAL jvp); @@ -56,14 +57,16 @@ bool SerializeValue(JOUT *js, PJVAL jvp); /***********************************************************************/ class JOUT : public BLOCK { public: - JOUT(PGLOBAL gp) : BLOCK() {g = gp;} + JOUT(PGLOBAL gp) : BLOCK() {g = gp; Pretty = 3;} virtual bool WriteStr(const char *s) = 0; virtual bool WriteChr(const char c) = 0; virtual bool Escape(const char *s) = 0; + int Prty(void) {return Pretty;} // Member PGLOBAL g; + int Pretty; }; // end of class JOUT /***********************************************************************/ @@ -88,7 +91,7 @@ class JOUTSTR : public JOUT { /***********************************************************************/ class JOUTFILE : public JOUT { public: - JOUTFILE(PGLOBAL g, FILE *str) : JOUT(g) {Stream = str;} + JOUTFILE(PGLOBAL g, FILE *str, int pty) : JOUT(g) {Stream = str; Pretty = pty;} virtual bool WriteStr(const char *s); virtual bool WriteChr(const char c); @@ -103,7 +106,7 @@ class JOUTFILE : public JOUT { /***********************************************************************/ class JOUTPRT : public JOUTFILE { public: - JOUTPRT(PGLOBAL g, FILE *str) : JOUTFILE(g, str) {M = 0; B = false;} + JOUTPRT(PGLOBAL g, FILE *str) : JOUTFILE(g, str, 2) {M = 0; B = false;} virtual bool WriteStr(const char *s); virtual bool WriteChr(const char c); @@ -118,7 +121,8 @@ class JOUTPRT : public JOUTFILE { /***********************************************************************/ class JPAIR : public BLOCK { friend class JOBJECT; - friend PJOB ParseObject(PGLOBAL, int&, STRG&); + friend class JSNX; + friend PJOB ParseObject(PGLOBAL, int&, STRG&, bool*); friend bool SerializeObject(JOUT *, PJOB); public: JPAIR(PSZ key) : BLOCK() {Key = key; Val = NULL; Next = NULL;} @@ -145,28 +149,32 @@ class JSON : public BLOCK { virtual JTYP GetType(void) {return TYPE_JSON;} virtual JTYP GetValType(void) {X return TYPE_JSON;} virtual void InitArray(PGLOBAL g) {X} - virtual PJVAL AddValue(PGLOBAL g, PJVAL jvp = NULL) {X return NULL;} +//virtual PJVAL AddValue(PGLOBAL g, PJVAL jvp = NULL, int *x = NULL) {X return NULL;} virtual PJPR AddPair(PGLOBAL g, PSZ key) {X return NULL;} - virtual PJVAL GetValue(const char *key) {X return NULL;} + virtual PJAR GetKeyList(PGLOBAL g) {X return NULL;} + virtual PJVAL GetValue(const char *key) {X return NULL;} virtual PJOB GetObject(void) {return NULL;} virtual PJAR GetArray(void) {return NULL;} - virtual PJVAL GetValue(int i) {X return NULL;} + virtual PJVAL GetValue(int i) {X return NULL;} virtual PVAL GetValue(void) {X return NULL;} - virtual PJSON GetJson(void) {X return NULL;} + virtual PJSON GetJsp(void) { X return NULL; } + virtual PJSON GetJson(void) { X return NULL; } virtual PJPR GetFirst(void) {X return NULL;} virtual int GetInteger(void) {X return 0;} virtual double GetFloat() {X return 0.0;} virtual PSZ GetString() {X return NULL;} virtual PSZ GetText(PGLOBAL g, PSZ text) {X return NULL;} - virtual bool SetValue(PGLOBAL g, PJVAL jvp, int i) {X return true;} + virtual bool Merge(PGLOBAL g, PJSON jsp) { X return true; } + virtual bool SetValue(PGLOBAL g, PJVAL jvp, int i) { X return true; } virtual void SetValue(PGLOBAL g, PJVAL jvp, PSZ key) {X} virtual void SetValue(PVAL valp) {X} virtual void SetValue(PJSON jsp) {X} - virtual void SetString(PGLOBAL g, PSZ s) {X} + virtual void SetString(PGLOBAL g, PSZ s, short c) {X} virtual void SetInteger(PGLOBAL g, int n) {X} virtual void SetFloat(PGLOBAL g, double f) {X} - virtual bool DeleteValue(int i) {X return true;} - virtual bool IsNull(void) {X return true;} + virtual void DeleteKey(char *k) {X} + virtual bool DeleteValue(int i) {X return true;} + virtual bool IsNull(void) {X return true;} protected: int Size; @@ -176,8 +184,9 @@ class JSON : public BLOCK { /* Class JOBJECT: contains a list of value pairs. */ /***********************************************************************/ class JOBJECT : public JSON { - friend PJOB ParseObject(PGLOBAL, int&, STRG&); + friend PJOB ParseObject(PGLOBAL, int&, STRG&, bool*); friend bool SerializeObject(JOUT *, PJOB); + friend class JSNX; public: JOBJECT(void) : JSON() {First = Last = NULL;} @@ -189,9 +198,12 @@ class JOBJECT : public JSON { virtual PJPR AddPair(PGLOBAL g, PSZ key); virtual PJOB GetObject(void) {return this;} virtual PJVAL GetValue(const char* key); - virtual PSZ GetText(PGLOBAL g, PSZ text); - virtual void SetValue(PGLOBAL g, PJVAL jvp, PSZ key); - virtual bool IsNull(void); + virtual PJAR GetKeyList(PGLOBAL g); + virtual PSZ GetText(PGLOBAL g, PSZ text); + virtual bool Merge(PGLOBAL g, PJSON jsp); + virtual void SetValue(PGLOBAL g, PJVAL jvp, PSZ key); + virtual void DeleteKey(char *k); + virtual bool IsNull(void); protected: PJPR First; @@ -202,7 +214,7 @@ class JOBJECT : public JSON { /* Class JARRAY. */ /***********************************************************************/ class JARRAY : public JSON { - friend PJAR ParseArray(PGLOBAL, int&, STRG&); + friend PJAR ParseArray(PGLOBAL, int&, STRG&, bool*); public: JARRAY(void) : JSON() {Alloc = 0; First = Last = NULL; Mvals = NULL;} @@ -211,10 +223,11 @@ class JARRAY : public JSON { virtual void Clear(void) {First = Last = NULL; Size = 0;} virtual JTYP GetType(void) {return TYPE_JAR;} virtual PJAR GetArray(void) {return this;} - virtual PJVAL AddValue(PGLOBAL g, PJVAL jvp = NULL); + PJVAL AddValue(PGLOBAL g, PJVAL jvp = NULL, int *x = NULL); virtual void InitArray(PGLOBAL g); virtual PJVAL GetValue(int i); - virtual bool SetValue(PGLOBAL g, PJVAL jvp, int i); + virtual bool Merge(PGLOBAL g, PJSON jsp); + virtual bool SetValue(PGLOBAL g, PJVAL jvp, int i); virtual bool DeleteValue(int n); virtual bool IsNull(void); @@ -231,7 +244,8 @@ class JARRAY : public JSON { /***********************************************************************/ class JVALUE : public JSON { friend class JARRAY; - friend PJVAL ParseValue(PGLOBAL, int&, STRG&); + friend class JSNX; + friend PJVAL ParseValue(PGLOBAL, int&, STRG&, bool*); friend bool SerializeValue(JOUT *, PJVAL); public: JVALUE(void) : JSON() @@ -239,6 +253,7 @@ class JVALUE : public JSON { JVALUE(PJSON jsp) : JSON() {Jsp = jsp; Value = NULL; Next = NULL; Del = false;} JVALUE(PGLOBAL g, PVAL valp); + JVALUE(PGLOBAL g, PSZ strp); using JSON::GetValue; using JSON::SetValue; @@ -249,17 +264,21 @@ class JVALUE : public JSON { virtual PJOB GetObject(void); virtual PJAR GetArray(void); virtual PVAL GetValue(void) {return Value;} - virtual PJSON GetJson(void) {return (Jsp ? Jsp : this);} - virtual int GetInteger(void); - virtual double GetFloat(void); + virtual PJSON GetJsp(void) {return Jsp;} + virtual PJSON GetJson(void) { return (Jsp ? Jsp : this); } + virtual int GetInteger(void); + virtual long long GetBigint(void); + virtual double GetFloat(void); virtual PSZ GetString(void); virtual PSZ GetText(PGLOBAL g, PSZ text); - virtual void SetValue(PVAL valp) {Value = valp;} - virtual void SetValue(PJSON jsp) {Jsp = jsp;} - virtual void SetString(PGLOBAL g, PSZ s); + virtual void SetValue(PJSON jsp); + virtual void SetValue(PVAL valp) { Value = valp; Jsp = NULL; } + virtual void SetString(PGLOBAL g, PSZ s, short c = 0); virtual void SetInteger(PGLOBAL g, int n); - virtual void SetFloat(PGLOBAL g, double f); - virtual bool IsNull(void); + virtual void SetBigint(PGLOBAL g, longlong ll); + virtual void SetFloat(PGLOBAL g, double f); + virtual void SetTiny(PGLOBAL g, char f); + virtual bool IsNull(void); protected: PJSON Jsp; // To the json value |