SNAP Library 3.0, User Reference  2016-07-20 17:56:49
SNAP, a general purpose, high performance system for analysis and manipulation of large networks
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
TJsonVal Class Reference

#include <json.h>

Public Member Functions

 TJsonVal ()
 
 TJsonVal (TSIn &SIn)
 
void Save (TSOut &SOut) const
 
TStr SaveStr ()
 
bool operator== (const TJsonVal &JsonVal) const
 
bool operator!= (const TJsonVal &JsonVal) const
 
void PutNull ()
 
void PutBool (const bool &BoolVal)
 
void PutNum (const double &NumVal)
 
void PutStr (const TStr &StrVal)
 
void PutArr ()
 
void AddToArr (const PJsonVal &Val)
 
void PutObj ()
 
void AddToObj (const TStr &KeyNm, const PJsonVal &Val)
 
void AddToObj (const TStr &KeyNm, const int &Val)
 
void AddToObj (const TStr &KeyNm, const double &Val)
 
void AddToObj (const TStr &KeyNm, const TStr &Val)
 
void AddToObj (const TStr &KeyNm, const char *Val)
 
void AddToObj (const TStr &KeyNm, const bool &Val)
 
void AddToObj (const TStr &KeyNm, const TJsonValV &ValV)
 
void AddToObj (const PJsonVal &Val)
 
TJsonValType GetJsonValType () const
 
bool IsDef () const
 
bool IsNull () const
 
bool IsBool () const
 
bool IsNum () const
 
bool IsStr () const
 
bool IsArr () const
 
bool IsObj () const
 
bool GetBool () const
 
double GetNum () const
 
TStr GetStr () const
 
int GetArrVals () const
 
PJsonVal GetArrVal (const int &ValN) const
 
int GetObjKeys () const
 
void GetObjKeyVal (const int &KeyValN, TStr &Key, PJsonVal &Val) const
 
bool IsObjKey (const TStr &Key) const
 
bool IsObjKey (const char *Key) const
 
PJsonVal GetObjKey (const TStr &Key) const
 
PJsonVal GetObjKey (const char *Key) const
 
bool GetObjBool (const TStr &Key) const
 
bool GetObjBool (const char *Key) const
 
double GetObjNum (const TStr &Key) const
 
double GetObjNum (const char *Key) const
 
TStr GetObjStr (const TStr &Key) const
 
TStr GetObjStr (const char *Key) const
 
bool GetObjBool (const TStr &Key, const bool &DefBool) const
 
bool GetObjBool (const char *Key, const bool &DefBool) const
 
double GetObjNum (const TStr &Key, const double &DefNum) const
 
double GetObjNum (const char *Key, const double &DefNum) const
 
TStr GetObjStr (const TStr &Key, const TStr &DefStr) const
 
TStr GetObjStr (const char *Key, const TStr &DefStr) const
 

Static Public Member Functions

static PJsonVal New ()
 
static PJsonVal Load (TSIn &SIn)
 
static PJsonVal NewNull ()
 
static PJsonVal NewBool (const bool &Bool)
 
static PJsonVal NewNum (const double &Num)
 
static PJsonVal NewStr (const TStr &Str)
 
static PJsonVal NewArr ()
 
static PJsonVal NewArr (const TJsonValV &ValV)
 
static PJsonVal NewArr (const TIntV &IntV)
 
static PJsonVal NewArr (const TFltV &FltV)
 
static PJsonVal NewArr (const TStrV &StrV)
 
static PJsonVal NewArr (const TFltPr &FltPr)
 
static PJsonVal NewObj ()
 
static PJsonVal NewObj (const TStr &KeyNm, const PJsonVal &ObjVal)
 
static PJsonVal NewObj (const TStr &KeyNm, const int &ObjVal)
 
static PJsonVal NewObj (const TStr &KeyNm, const double &ObjVal)
 
static PJsonVal NewObj (const TStr &KeyNm, const TStr &ObjVal)
 
static PJsonVal NewObj (const TStr &KeyNm, const bool &ObjVal)
 
static PJsonVal GetValFromLx (TILx &Lx)
 
static PJsonVal GetValFromSIn (const PSIn &SIn)
 
static PJsonVal GetValFromStr (const TStr &JsonStr)
 
static void AddEscapeChAFromStr (const TStr &Str, TChA &ChA)
 
static TStr AddEscapeStrFromStr (const TStr &Str)
 
static void AddQChAFromStr (const TStr &Str, TChA &ChA)
 
static void GetChAFromVal (const PJsonVal &Val, TChA &ChA)
 
static TStr GetStrFromVal (const PJsonVal &Val)
 

Private Member Functions

 UndefCopyAssign (TJsonVal)
 

Private Attributes

TCRef CRef
 
TJsonValType JsonValType
 
TBool Bool
 
TFlt Num
 
TStr Str
 
TJsonValV ValV
 
THash< TStr, PJsonValKeyValH
 

Friends

class TPt< TJsonVal >
 

Detailed Description

Definition at line 9 of file json.h.

Constructor & Destructor Documentation

TJsonVal::TJsonVal ( )
inline

Definition at line 19 of file json.h.

TJsonValType JsonValType
Definition: json.h:11
Definition: json.h:7
TJsonVal::TJsonVal ( TSIn SIn)

Definition at line 3 of file json.cpp.

3  :
4  JsonValType((TJsonValType)(TInt(SIn).Val)), Bool(SIn),
5  Num(SIn), Str(SIn), ValV(SIn), KeyValH(SIn) { }
TStr Str
Definition: json.h:14
THash< TStr, PJsonVal > KeyValH
Definition: json.h:16
TBool Bool
Definition: json.h:12
TJsonValType
Definition: json.h:6
TJsonValType JsonValType
Definition: json.h:11
Definition: dt.h:1044
TJsonValV ValV
Definition: json.h:15
TFlt Num
Definition: json.h:13

Member Function Documentation

void TJsonVal::AddEscapeChAFromStr ( const TStr Str,
TChA ChA 
)
static

Definition at line 188 of file json.cpp.

188  {
189  if (TUnicodeDef::IsDef()) {
190  // parse the UTF8 string
191  TIntV UStr; TUnicodeDef::GetDef()->DecodeUtf8(Str, UStr);
192  // escape the string
193  for (int ChN = 0; ChN < UStr.Len(); ChN++) {
194  const int UCh = UStr[ChN];
195  if (UCh < 0x80) {
196  // 7-bit ascii
197  const char Ch = (char)UCh;
198  switch (Ch) {
199  case '"' : ChA.AddCh('\\'); ChA.AddCh('"'); break;
200  case '\\' : ChA.AddCh('\\'); ChA.AddCh('\\'); break;
201  case '/' : ChA.AddCh('\\'); ChA.AddCh('/'); break;
202  case '\b' : ChA.AddCh('\\'); ChA.AddCh('b'); break;
203  case '\f' : ChA.AddCh('\\'); ChA.AddCh('f'); break;
204  case '\n' : ChA.AddCh('\\'); ChA.AddCh('n'); break;
205  case '\r' : ChA.AddCh('\\'); ChA.AddCh('r'); break;
206  case '\t' : ChA.AddCh('\\'); ChA.AddCh('t'); break;
207  default :
208  ChA.AddCh(Ch);
209  }
210  } else {
211  // escape
212  ChA += "\\u";
213  ChA += TStr::Fmt("%04x", UCh);
214  }
215  }
216  } else {
217  // escape the string
218  for (int ChN = 0; ChN < Str.Len(); ChN++) {
219  const char Ch = Str[ChN];
220  if ((Ch & 0x80) == 0) {
221  // 7-bit ascii
222  switch (Ch) {
223  case '"' : ChA.AddCh('\\'); ChA.AddCh('"'); break;
224  case '\\' : ChA.AddCh('\\'); ChA.AddCh('\\'); break;
225  case '/' : ChA.AddCh('\\'); ChA.AddCh('/'); break;
226  case '\b' : ChA.AddCh('\\'); ChA.AddCh('b'); break;
227  case '\f' : ChA.AddCh('\\'); ChA.AddCh('f'); break;
228  case '\n' : ChA.AddCh('\\'); ChA.AddCh('n'); break;
229  case '\r' : ChA.AddCh('\\'); ChA.AddCh('r'); break;
230  case '\t' : ChA.AddCh('\\'); ChA.AddCh('t'); break;
231  default : ChA.AddCh(Ch);
232  }
233  } else {
234  // escape
235  ChA += "\\u";
236  ChA += TStr::Fmt("%02x", (int)Ch);
237  }
238  }
239  }
240 }
int Len() const
Definition: dt.h:487
void AddCh(const char &Ch, const int &MxLen=-1)
Definition: dt.h:271
TSizeTy Len() const
Returns the number of elements in the vector.
Definition: ds.h:547
static TUnicode * GetDef()
Definition: unicodestring.h:23
int DecodeUtf8(const TIntV &src, TIntV &dest) const
Definition: unicode.h:1787
static TStr Fmt(const char *FmtStr,...)
Definition: dt.cpp:1599
static bool IsDef()
Definition: unicodestring.h:21
static TStr TJsonVal::AddEscapeStrFromStr ( const TStr Str)
inlinestatic

Definition at line 113 of file json.h.

113  {
114  TChA ChA; AddEscapeChAFromStr(Str, ChA); return ChA; }
static void AddEscapeChAFromStr(const TStr &Str, TChA &ChA)
Definition: json.cpp:188
Definition: dt.h:201
void TJsonVal::AddQChAFromStr ( const TStr Str,
TChA ChA 
)
static

Definition at line 242 of file json.cpp.

242  {
243  ChA+="\"";
244  AddEscapeChAFromStr(Str, ChA);
245  ChA+="\"";
246 }
static void AddEscapeChAFromStr(const TStr &Str, TChA &ChA)
Definition: json.cpp:188
void TJsonVal::AddToArr ( const PJsonVal Val)
inline

Definition at line 36 of file json.h.

36  {
TJsonValType JsonValType
Definition: json.h:11
#define EAssert(Cond)
Definition: bd.h:280
TJsonValV ValV
Definition: json.h:15
Definition: json.h:7
TSizeTy Add()
Adds a new element at the end of the vector, after its current last element.
Definition: ds.h:574
void TJsonVal::AddToObj ( const TStr KeyNm,
const PJsonVal Val 
)
inline

Definition at line 39 of file json.h.

39  {
40  EAssert(JsonValType==jvtObj); KeyValH.AddDat(KeyNm, Val);}
Definition: json.h:7
THash< TStr, PJsonVal > KeyValH
Definition: json.h:16
TJsonValType JsonValType
Definition: json.h:11
#define EAssert(Cond)
Definition: bd.h:280
void TJsonVal::AddToObj ( const TStr KeyNm,
const int &  Val 
)
inline

Definition at line 41 of file json.h.

41 { AddToObj(KeyNm, NewNum((double)Val)); }
void AddToObj(const TStr &KeyNm, const PJsonVal &Val)
Definition: json.h:39
static PJsonVal NewNum(const double &Num)
Definition: json.h:52
void TJsonVal::AddToObj ( const TStr KeyNm,
const double &  Val 
)
inline

Definition at line 42 of file json.h.

42 { AddToObj(KeyNm, NewNum(Val)); }
void AddToObj(const TStr &KeyNm, const PJsonVal &Val)
Definition: json.h:39
static PJsonVal NewNum(const double &Num)
Definition: json.h:52
void TJsonVal::AddToObj ( const TStr KeyNm,
const TStr Val 
)
inline

Definition at line 43 of file json.h.

43 { AddToObj(KeyNm, NewStr(Val)); }
static PJsonVal NewStr(const TStr &Str)
Definition: json.h:53
void AddToObj(const TStr &KeyNm, const PJsonVal &Val)
Definition: json.h:39
void TJsonVal::AddToObj ( const TStr KeyNm,
const char *  Val 
)
inline

Definition at line 44 of file json.h.

44 { AddToObj(KeyNm, NewStr(Val)); }
static PJsonVal NewStr(const TStr &Str)
Definition: json.h:53
void AddToObj(const TStr &KeyNm, const PJsonVal &Val)
Definition: json.h:39
void TJsonVal::AddToObj ( const TStr KeyNm,
const bool &  Val 
)
inline

Definition at line 45 of file json.h.

45 { AddToObj(KeyNm, NewBool(Val)); }
static PJsonVal NewBool(const bool &Bool)
Definition: json.h:51
void AddToObj(const TStr &KeyNm, const PJsonVal &Val)
Definition: json.h:39
void TJsonVal::AddToObj ( const TStr KeyNm,
const TJsonValV ValV 
)
inline

Definition at line 46 of file json.h.

46 { AddToObj(KeyNm, NewArr(ValV)); }
void AddToObj(const TStr &KeyNm, const PJsonVal &Val)
Definition: json.h:39
static PJsonVal NewArr()
Definition: json.h:54
void TJsonVal::AddToObj ( const PJsonVal Val)

Definition at line 31 of file json.cpp.

31  {
32  EAssert(Val->IsObj());
33  int KeyId = Val->KeyValH.FFirstKeyId();
34  while (Val->KeyValH.FNextKeyId(KeyId)) {
35  AddToObj(Val->KeyValH.GetKey(KeyId), Val->KeyValH[KeyId]);
36  }
37 }
void AddToObj(const TStr &KeyNm, const PJsonVal &Val)
Definition: json.h:39
#define EAssert(Cond)
Definition: bd.h:280
PJsonVal TJsonVal::GetArrVal ( const int &  ValN) const
inline

Definition at line 87 of file json.h.

87 {return ValV[ValN];}
TJsonValV ValV
Definition: json.h:15
int TJsonVal::GetArrVals ( ) const
inline

Definition at line 86 of file json.h.

86 {EAssert(IsArr()); return ValV.Len();}
TSizeTy Len() const
Returns the number of elements in the vector.
Definition: ds.h:547
bool IsArr() const
Definition: json.h:79
#define EAssert(Cond)
Definition: bd.h:280
TJsonValV ValV
Definition: json.h:15
bool TJsonVal::GetBool ( ) const
inline

Definition at line 83 of file json.h.

83 {EAssert(IsBool()); return Bool;}
TBool Bool
Definition: json.h:12
bool IsBool() const
Definition: json.h:76
#define EAssert(Cond)
Definition: bd.h:280
void TJsonVal::GetChAFromVal ( const PJsonVal Val,
TChA ChA 
)
static

Definition at line 248 of file json.cpp.

248  {
249  switch (Val->GetJsonValType()){
250  case jvtNull:
251  ChA+="null"; break;
252  case jvtBool:
253  if (Val->GetBool()){ChA+="true";} else {ChA+="false";} break;
254  case jvtNum:
255  ChA+=TStr::Fmt("%f", Val->GetNum()); break;
256  case jvtStr:
257  AddQChAFromStr(Val->GetStr(), ChA); break;
258  case jvtArr:
259  ChA+="[";
260  for (int ArrValN=0; ArrValN<Val->GetArrVals(); ArrValN++){
261  if (ArrValN>0){ChA+=", ";}
262  GetChAFromVal(Val->GetArrVal(ArrValN), ChA);
263  }
264  ChA+="]";
265  break;
266  case jvtObj:
267  ChA+="{";
268  for (int ObjKeyN=0; ObjKeyN<Val->GetObjKeys(); ObjKeyN++){
269  if (ObjKeyN>0){ChA+=", ";}
270  TStr ObjKey; PJsonVal ObjVal; Val->GetObjKeyVal(ObjKeyN, ObjKey, ObjVal);
271  AddQChAFromStr(ObjKey, ChA);
272  ChA+=":";
273  GetChAFromVal(ObjVal, ChA);
274  }
275  ChA+="}";
276  break;
277  default: TExcept::Throw("Error parsing json");
278  }
279 }
static void GetChAFromVal(const PJsonVal &Val, TChA &ChA)
Definition: json.cpp:248
Definition: json.h:7
Definition: json.h:7
static void Throw(const TStr &MsgStr)
Definition: ut.h:187
Definition: json.h:7
Definition: json.h:7
Definition: dt.h:412
static TStr Fmt(const char *FmtStr,...)
Definition: dt.cpp:1599
Definition: json.h:7
Definition: json.h:7
Definition: bd.h:196
static void AddQChAFromStr(const TStr &Str, TChA &ChA)
Definition: json.cpp:242
TJsonValType TJsonVal::GetJsonValType ( ) const
inline

Definition at line 73 of file json.h.

73 {return JsonValType;}
TJsonValType JsonValType
Definition: json.h:11
double TJsonVal::GetNum ( ) const
inline

Definition at line 84 of file json.h.

84 {EAssert(IsNum()); return Num;}
bool IsNum() const
Definition: json.h:77
#define EAssert(Cond)
Definition: bd.h:280
TFlt Num
Definition: json.h:13
bool TJsonVal::GetObjBool ( const TStr Key) const
inline

Definition at line 95 of file json.h.

95 { return GetObjKey(Key)->GetBool(); }
PJsonVal GetObjKey(const TStr &Key) const
Definition: json.cpp:78
bool TJsonVal::GetObjBool ( const char *  Key) const
inline

Definition at line 96 of file json.h.

96 { return GetObjKey(Key)->GetBool(); }
PJsonVal GetObjKey(const TStr &Key) const
Definition: json.cpp:78
bool TJsonVal::GetObjBool ( const TStr Key,
const bool &  DefBool 
) const

Definition at line 90 of file json.cpp.

90  {
91  EAssert(IsObj());
92  return (IsObjKey(Key)) ? KeyValH.GetDat(Key)->GetBool() : DefBool;
93 }
THash< TStr, PJsonVal > KeyValH
Definition: json.h:16
#define EAssert(Cond)
Definition: bd.h:280
bool IsObj() const
Definition: json.h:80
bool IsObjKey(const TStr &Key) const
Definition: json.h:91
bool TJsonVal::GetObjBool ( const char *  Key,
const bool &  DefBool 
) const

Definition at line 95 of file json.cpp.

95  {
96  EAssert(IsObj());
97  return (IsObjKey(Key)) ? KeyValH.GetDat(Key)->GetBool() : DefBool;
98 }
THash< TStr, PJsonVal > KeyValH
Definition: json.h:16
#define EAssert(Cond)
Definition: bd.h:280
bool IsObj() const
Definition: json.h:80
bool IsObjKey(const TStr &Key) const
Definition: json.h:91
PJsonVal TJsonVal::GetObjKey ( const TStr Key) const

Definition at line 78 of file json.cpp.

78  {
79  EAssert(IsObj());
80  EAssert(IsObjKey(Key));
81  return KeyValH.GetDat(Key);
82 }
THash< TStr, PJsonVal > KeyValH
Definition: json.h:16
#define EAssert(Cond)
Definition: bd.h:280
bool IsObj() const
Definition: json.h:80
bool IsObjKey(const TStr &Key) const
Definition: json.h:91
PJsonVal TJsonVal::GetObjKey ( const char *  Key) const

Definition at line 84 of file json.cpp.

84  {
85  EAssert(IsObj());
86  EAssert(IsObjKey(Key));
87  return KeyValH.GetDat(Key);
88 }
THash< TStr, PJsonVal > KeyValH
Definition: json.h:16
#define EAssert(Cond)
Definition: bd.h:280
bool IsObj() const
Definition: json.h:80
bool IsObjKey(const TStr &Key) const
Definition: json.h:91
int TJsonVal::GetObjKeys ( ) const
inline

Definition at line 88 of file json.h.

88 {EAssert(IsObj()); return KeyValH.Len();}
THash< TStr, PJsonVal > KeyValH
Definition: json.h:16
#define EAssert(Cond)
Definition: bd.h:280
bool IsObj() const
Definition: json.h:80
void TJsonVal::GetObjKeyVal ( const int &  KeyValN,
TStr Key,
PJsonVal Val 
) const
inline

Definition at line 89 of file json.h.

89  {
90  EAssert(IsObj()); Key=KeyValH.GetKey(KeyValN); Val=KeyValH[KeyValN];}
THash< TStr, PJsonVal > KeyValH
Definition: json.h:16
#define EAssert(Cond)
Definition: bd.h:280
bool IsObj() const
Definition: json.h:80
double TJsonVal::GetObjNum ( const TStr Key) const
inline

Definition at line 97 of file json.h.

97 { return GetObjKey(Key)->GetNum(); }
PJsonVal GetObjKey(const TStr &Key) const
Definition: json.cpp:78
double TJsonVal::GetObjNum ( const char *  Key) const
inline

Definition at line 98 of file json.h.

98 { return GetObjKey(Key)->GetNum(); }
PJsonVal GetObjKey(const TStr &Key) const
Definition: json.cpp:78
double TJsonVal::GetObjNum ( const TStr Key,
const double &  DefNum 
) const

Definition at line 100 of file json.cpp.

100  {
101  EAssert(IsObj());
102  return (IsObjKey(Key)) ? KeyValH.GetDat(Key)->GetNum() : DefNum;
103 }
THash< TStr, PJsonVal > KeyValH
Definition: json.h:16
#define EAssert(Cond)
Definition: bd.h:280
bool IsObj() const
Definition: json.h:80
bool IsObjKey(const TStr &Key) const
Definition: json.h:91
double TJsonVal::GetObjNum ( const char *  Key,
const double &  DefNum 
) const

Definition at line 105 of file json.cpp.

105  {
106  EAssert(IsObj());
107  return (IsObjKey(Key)) ? KeyValH.GetDat(Key)->GetNum() : DefNum;
108 }
THash< TStr, PJsonVal > KeyValH
Definition: json.h:16
#define EAssert(Cond)
Definition: bd.h:280
bool IsObj() const
Definition: json.h:80
bool IsObjKey(const TStr &Key) const
Definition: json.h:91
TStr TJsonVal::GetObjStr ( const TStr Key) const
inline

Definition at line 99 of file json.h.

99 { return GetObjKey(Key)->GetStr(); }
PJsonVal GetObjKey(const TStr &Key) const
Definition: json.cpp:78
TStr TJsonVal::GetObjStr ( const char *  Key) const
inline

Definition at line 100 of file json.h.

100 { return GetObjKey(Key)->GetStr(); }
PJsonVal GetObjKey(const TStr &Key) const
Definition: json.cpp:78
TStr TJsonVal::GetObjStr ( const TStr Key,
const TStr DefStr 
) const

Definition at line 110 of file json.cpp.

110  {
111  EAssert(IsObj());
112  return (IsObjKey(Key)) ? KeyValH.GetDat(Key)->GetStr() : DefStr;
113 }
THash< TStr, PJsonVal > KeyValH
Definition: json.h:16
#define EAssert(Cond)
Definition: bd.h:280
bool IsObj() const
Definition: json.h:80
bool IsObjKey(const TStr &Key) const
Definition: json.h:91
TStr TJsonVal::GetObjStr ( const char *  Key,
const TStr DefStr 
) const

Definition at line 115 of file json.cpp.

115  {
116  EAssert(IsObj());
117  return (IsObjKey(Key)) ? KeyValH.GetDat(Key)->GetStr() : DefStr;
118 }
THash< TStr, PJsonVal > KeyValH
Definition: json.h:16
#define EAssert(Cond)
Definition: bd.h:280
bool IsObj() const
Definition: json.h:80
bool IsObjKey(const TStr &Key) const
Definition: json.h:91
TStr TJsonVal::GetStr ( ) const
inline

Definition at line 85 of file json.h.

85 {EAssert(IsStr()); return Str;}
bool IsStr() const
Definition: json.h:78
TStr Str
Definition: json.h:14
#define EAssert(Cond)
Definition: bd.h:280
TStr TJsonVal::GetStrFromVal ( const PJsonVal Val)
static

Definition at line 281 of file json.cpp.

281  {
282  TChA ChA;
283  GetChAFromVal(Val, ChA);
284  return ChA;
285 }
static void GetChAFromVal(const PJsonVal &Val, TChA &ChA)
Definition: json.cpp:248
Definition: dt.h:201
PJsonVal TJsonVal::GetValFromLx ( TILx Lx)
static

Definition at line 120 of file json.cpp.

120  {
122  PJsonVal Val=TJsonVal::New();
123  if ((Lx.Sym==syIdStr)&&(Lx.Str=="null")){
124  Val->PutNull(); Lx.GetSym();
125  } else if ((Lx.Sym==syIdStr)&&(Lx.Str=="true")){
126  Val->PutBool(true); Lx.GetSym();
127  } else if ((Lx.Sym==syIdStr)&&(Lx.Str=="false")){
128  Val->PutBool(false); Lx.GetSym();
129  } else if (Lx.Sym==syFlt){
130  Val->PutNum(Lx.Flt); Lx.GetSym();
131  } else if (Lx.Sym==syQStr){
132  Val->PutStr(Lx.Str); Lx.GetSym();
133  } else if (Lx.Sym==syLBracket){
134  Val->PutArr(); Lx.GetSym(ValExpect); // added ValExpect to correctyl parse arrays of floats
135  if (Lx.Sym!=syRBracket){
136  forever{
137  PJsonVal SubVal=TJsonVal::GetValFromLx(Lx);
138  Val->AddToArr(SubVal);
139  if (Lx.Sym==syComma){Lx.GetSym(ValExpect);}
140  else if (Lx.Sym==syRBracket){break;}
141  else {TExcept::Throw("JSON Array not properly formed.");}
142  }
143  }
144  Lx.GetSym();
145  } else if (Lx.Sym==syLBrace){
146  Val->PutObj(); Lx.GetSym(TFSet()|syRBrace|syQStr);
147  if (Lx.Sym!=syRBrace){
148  forever{
149  TStr SubKey=Lx.Str;
150  Lx.GetSym(syColon);
151  Lx.GetSym(ValExpect);
152  PJsonVal SubVal=TJsonVal::GetValFromLx(Lx);
153  Val->AddToObj(SubKey, SubVal);
154  if (Lx.Sym==syComma){Lx.GetSym(TFSet()|syQStr);}
155  else if (Lx.Sym==syRBrace){break;}
156  else {TExcept::Throw("JSON Object not properly formed.");}
157  }
158  }
159  Lx.GetSym();
160  } else {
161  TExcept::Throw("Unexpected JSON symbol.");
162  }
163  return Val;
164 }
Definition: lx.h:50
static PJsonVal New()
Definition: json.h:20
Definition: lx.h:50
#define forever
Definition: bd.h:6
Definition: bits.h:119
Definition: lx.h:45
Definition: lx.h:45
static PJsonVal GetValFromLx(TILx &Lx)
Definition: json.cpp:120
TLxSym Sym
Definition: lx.h:149
Definition: lx.h:50
static void Throw(const TStr &MsgStr)
Definition: ut.h:187
Definition: lx.h:50
Definition: lx.h:45
TChA Str
Definition: lx.h:150
Definition: dt.h:412
Definition: lx.h:46
Definition: bd.h:196
Definition: lx.h:46
TLxSym GetSym(const TFSet &Expect)
Definition: lx.cpp:315
double Flt
Definition: lx.h:151
PJsonVal TJsonVal::GetValFromSIn ( const PSIn SIn)
static

Definition at line 166 of file json.cpp.

166  {
168  PJsonVal Val;
169  //bool Ok=true;
170  TStr MsgStr="Ok";
171  try {
172  Lx.GetSym(TFSet()|syLBracket|syLBrace);
173  Val=GetValFromLx(Lx);
174  }
175  catch (PExcept Except){
176  //Ok=false;
177  MsgStr=Except->GetMsgStr();
178  Val=TJsonVal::New();
179  }
180  return Val;
181 }
Definition: lx.h:127
Definition: lx.h:50
static PJsonVal New()
Definition: json.h:20
Definition: bits.h:119
static PJsonVal GetValFromLx(TILx &Lx)
Definition: json.cpp:120
Definition: lx.h:126
Definition: lx.h:126
Definition: lx.h:129
Definition: lx.h:50
Definition: dt.h:412
Definition: bd.h:196
Definition: lx.h:126
PJsonVal TJsonVal::GetValFromStr ( const TStr JsonStr)
static

Definition at line 183 of file json.cpp.

183  {
184  PSIn SIn=TStrIn::New(JsonStr);
185  return GetValFromSIn(SIn);
186 }
static PSIn New(const TStr &Str)
Definition: dt.h:708
static PJsonVal GetValFromSIn(const PSIn &SIn)
Definition: json.cpp:166
bool TJsonVal::IsArr ( ) const
inline

Definition at line 79 of file json.h.

79 {return JsonValType==jvtArr;}
TJsonValType JsonValType
Definition: json.h:11
Definition: json.h:7
bool TJsonVal::IsBool ( ) const
inline

Definition at line 76 of file json.h.

76 {return JsonValType==jvtBool;}
Definition: json.h:7
TJsonValType JsonValType
Definition: json.h:11
bool TJsonVal::IsDef ( ) const
inline

Definition at line 74 of file json.h.

74 {return JsonValType!=jvtUndef;}
TJsonValType JsonValType
Definition: json.h:11
Definition: json.h:7
bool TJsonVal::IsNull ( ) const
inline

Definition at line 75 of file json.h.

75 {return JsonValType==jvtNull;}
TJsonValType JsonValType
Definition: json.h:11
Definition: json.h:7
bool TJsonVal::IsNum ( ) const
inline

Definition at line 77 of file json.h.

77 {return JsonValType==jvtNum;}
TJsonValType JsonValType
Definition: json.h:11
Definition: json.h:7
bool TJsonVal::IsObj ( ) const
inline

Definition at line 80 of file json.h.

80 {return JsonValType==jvtObj;}
Definition: json.h:7
TJsonValType JsonValType
Definition: json.h:11
bool TJsonVal::IsObjKey ( const TStr Key) const
inline

Definition at line 91 of file json.h.

91 {EAssert(IsObj()); return KeyValH.IsKey(Key);}
THash< TStr, PJsonVal > KeyValH
Definition: json.h:16
#define EAssert(Cond)
Definition: bd.h:280
bool IsObj() const
Definition: json.h:80
bool TJsonVal::IsObjKey ( const char *  Key) const
inline

Definition at line 92 of file json.h.

92 {EAssert(IsObj()); return KeyValH.IsKey(Key);}
THash< TStr, PJsonVal > KeyValH
Definition: json.h:16
#define EAssert(Cond)
Definition: bd.h:280
bool IsObj() const
Definition: json.h:80
bool TJsonVal::IsStr ( ) const
inline

Definition at line 78 of file json.h.

78 {return JsonValType==jvtStr;}
TJsonValType JsonValType
Definition: json.h:11
Definition: json.h:7
static PJsonVal TJsonVal::Load ( TSIn SIn)
inlinestatic

Definition at line 23 of file json.h.

23 {return new TJsonVal(SIn);}
TJsonVal()
Definition: json.h:19
static PJsonVal TJsonVal::New ( )
inlinestatic

Definition at line 20 of file json.h.

20  {
21  return new TJsonVal();}
TJsonVal()
Definition: json.h:19
static PJsonVal TJsonVal::NewArr ( )
inlinestatic

Definition at line 54 of file json.h.

54 { PJsonVal Val = TJsonVal::New(); Val->PutArr(); return Val; }
static PJsonVal New()
Definition: json.h:20
Definition: bd.h:196
PJsonVal TJsonVal::NewArr ( const TJsonValV ValV)
static

Definition at line 39 of file json.cpp.

39  {
40  PJsonVal Val = TJsonVal::NewArr();
41  for (int ValN = 0; ValN < ValV.Len(); ValN++) {
42  Val->AddToArr(ValV[ValN]);
43  }
44  return Val;
45 }
TSizeTy Len() const
Returns the number of elements in the vector.
Definition: ds.h:547
Definition: bd.h:196
static PJsonVal NewArr()
Definition: json.h:54
PJsonVal TJsonVal::NewArr ( const TIntV IntV)
static

Definition at line 47 of file json.cpp.

47  {
48  PJsonVal Val = TJsonVal::NewArr();
49  for (int IntN = 0; IntN < IntV.Len(); IntN++) {
50  Val->AddToArr(TJsonVal::NewNum((double)IntV[IntN]));
51  }
52  return Val;
53 }
TSizeTy Len() const
Returns the number of elements in the vector.
Definition: ds.h:547
Definition: bd.h:196
static PJsonVal NewArr()
Definition: json.h:54
static PJsonVal NewNum(const double &Num)
Definition: json.h:52
PJsonVal TJsonVal::NewArr ( const TFltV FltV)
static

Definition at line 55 of file json.cpp.

55  {
56  PJsonVal Val = TJsonVal::NewArr();
57  for (int FltN = 0; FltN < FltV.Len(); FltN++) {
58  Val->AddToArr(TJsonVal::NewNum(FltV[FltN]));
59  }
60  return Val;
61 }
TSizeTy Len() const
Returns the number of elements in the vector.
Definition: ds.h:547
Definition: bd.h:196
static PJsonVal NewArr()
Definition: json.h:54
static PJsonVal NewNum(const double &Num)
Definition: json.h:52
PJsonVal TJsonVal::NewArr ( const TStrV StrV)
static

Definition at line 63 of file json.cpp.

63  {
64  PJsonVal Val = TJsonVal::NewArr();
65  for (int StrN = 0; StrN < StrV.Len(); StrN++) {
66  Val->AddToArr(TJsonVal::NewStr(StrV[StrN]));
67  }
68  return Val;
69 }
TSizeTy Len() const
Returns the number of elements in the vector.
Definition: ds.h:547
static PJsonVal NewStr(const TStr &Str)
Definition: json.h:53
Definition: bd.h:196
static PJsonVal NewArr()
Definition: json.h:54
PJsonVal TJsonVal::NewArr ( const TFltPr FltPr)
static

Definition at line 71 of file json.cpp.

71  {
72  PJsonVal Val = TJsonVal::NewArr();
73  Val->AddToArr(TJsonVal::NewNum(FltPr.Val1));
74  Val->AddToArr(TJsonVal::NewNum(FltPr.Val2));
75  return Val;
76 }
TVal1 Val1
Definition: ds.h:34
TVal2 Val2
Definition: ds.h:35
Definition: bd.h:196
static PJsonVal NewArr()
Definition: json.h:54
static PJsonVal NewNum(const double &Num)
Definition: json.h:52
static PJsonVal TJsonVal::NewBool ( const bool &  Bool)
inlinestatic

Definition at line 51 of file json.h.

51 { PJsonVal Val = TJsonVal::New(); Val->PutBool(Bool); return Val; }
static PJsonVal New()
Definition: json.h:20
TBool Bool
Definition: json.h:12
Definition: bd.h:196
static PJsonVal TJsonVal::NewNull ( )
inlinestatic

Definition at line 50 of file json.h.

50 { PJsonVal Val = TJsonVal::New(); Val->PutNull(); return Val; }
static PJsonVal New()
Definition: json.h:20
Definition: bd.h:196
static PJsonVal TJsonVal::NewNum ( const double &  Num)
inlinestatic

Definition at line 52 of file json.h.

52 { PJsonVal Val = TJsonVal::New(); Val->PutNum(Num); return Val; }
static PJsonVal New()
Definition: json.h:20
Definition: bd.h:196
TFlt Num
Definition: json.h:13
static PJsonVal TJsonVal::NewObj ( )
inlinestatic

Definition at line 60 of file json.h.

60 { PJsonVal Val = TJsonVal::New(); Val->PutObj(); return Val; }
static PJsonVal New()
Definition: json.h:20
Definition: bd.h:196
static PJsonVal TJsonVal::NewObj ( const TStr KeyNm,
const PJsonVal ObjVal 
)
inlinestatic

Definition at line 61 of file json.h.

61  {
62  PJsonVal Val = TJsonVal::New(); Val->PutObj(); Val->AddToObj(KeyNm, ObjVal); return Val; }
static PJsonVal New()
Definition: json.h:20
Definition: bd.h:196
static PJsonVal TJsonVal::NewObj ( const TStr KeyNm,
const int &  ObjVal 
)
inlinestatic

Definition at line 63 of file json.h.

63  {
64  PJsonVal Val = TJsonVal::New(); Val->PutObj(); Val->AddToObj(KeyNm, ObjVal); return Val; }
static PJsonVal New()
Definition: json.h:20
Definition: bd.h:196
static PJsonVal TJsonVal::NewObj ( const TStr KeyNm,
const double &  ObjVal 
)
inlinestatic

Definition at line 65 of file json.h.

65  {
66  PJsonVal Val = TJsonVal::New(); Val->PutObj(); Val->AddToObj(KeyNm, ObjVal); return Val; }
static PJsonVal New()
Definition: json.h:20
Definition: bd.h:196
static PJsonVal TJsonVal::NewObj ( const TStr KeyNm,
const TStr ObjVal 
)
inlinestatic

Definition at line 67 of file json.h.

67  {
68  PJsonVal Val = TJsonVal::New(); Val->PutObj(); Val->AddToObj(KeyNm, ObjVal); return Val; }
static PJsonVal New()
Definition: json.h:20
Definition: bd.h:196
static PJsonVal TJsonVal::NewObj ( const TStr KeyNm,
const bool &  ObjVal 
)
inlinestatic

Definition at line 69 of file json.h.

69  {
70  PJsonVal Val = TJsonVal::New(); Val->PutObj(); Val->AddToObj(KeyNm, ObjVal); return Val; }
static PJsonVal New()
Definition: json.h:20
Definition: bd.h:196
static PJsonVal TJsonVal::NewStr ( const TStr Str)
inlinestatic

Definition at line 53 of file json.h.

53 { PJsonVal Val = TJsonVal::New(); Val->PutStr(Str); return Val; }
static PJsonVal New()
Definition: json.h:20
Definition: bd.h:196
bool TJsonVal::operator!= ( const TJsonVal JsonVal) const

Definition at line 27 of file json.cpp.

27  {
28  return !(*this == JsonVal);
29 }
bool TJsonVal::operator== ( const TJsonVal JsonVal) const

Definition at line 18 of file json.cpp.

18  {
19  return JsonValType == JsonVal.JsonValType &&
20  Bool == JsonVal.Bool &&
21  Num == JsonVal.Num &&
22  Str == JsonVal.Str &&
23  ValV == JsonVal.ValV &&
24  KeyValH == JsonVal.KeyValH;
25 }
TStr Str
Definition: json.h:14
THash< TStr, PJsonVal > KeyValH
Definition: json.h:16
TBool Bool
Definition: json.h:12
TJsonValType JsonValType
Definition: json.h:11
TJsonValV ValV
Definition: json.h:15
TFlt Num
Definition: json.h:13
void TJsonVal::PutArr ( )
inline

Definition at line 35 of file json.h.

TJsonValType JsonValType
Definition: json.h:11
Definition: json.h:7
void TJsonVal::PutBool ( const bool &  BoolVal)
inline

Definition at line 32 of file json.h.

32 {JsonValType=jvtBool; Bool=BoolVal;}
Definition: json.h:7
TBool Bool
Definition: json.h:12
TJsonValType JsonValType
Definition: json.h:11
void TJsonVal::PutNull ( )
inline

Definition at line 31 of file json.h.

TJsonValType JsonValType
Definition: json.h:11
Definition: json.h:7
void TJsonVal::PutNum ( const double &  NumVal)
inline

Definition at line 33 of file json.h.

33 {JsonValType=jvtNum; Num=NumVal;}
TJsonValType JsonValType
Definition: json.h:11
Definition: json.h:7
TFlt Num
Definition: json.h:13
void TJsonVal::PutObj ( )
inline

Definition at line 38 of file json.h.

Definition: json.h:7
TJsonValType JsonValType
Definition: json.h:11
void TJsonVal::PutStr ( const TStr StrVal)
inline

Definition at line 34 of file json.h.

34 {JsonValType=jvtStr; Str=StrVal;}
TStr Str
Definition: json.h:14
TJsonValType JsonValType
Definition: json.h:11
Definition: json.h:7
void TJsonVal::Save ( TSOut SOut) const

Definition at line 7 of file json.cpp.

7  {
8  TInt((int)JsonValType).Save(SOut);
9  Bool.Save(SOut); Num.Save(SOut);
10  Str.Save(SOut); ValV.Save(SOut);
11  KeyValH.Save(SOut);
12 }
void Save(TSOut &SOut) const
Definition: dt.h:1060
void Save(TSOut &SOut) const
Definition: dt.h:902
TStr Str
Definition: json.h:14
THash< TStr, PJsonVal > KeyValH
Definition: json.h:16
void Save(TSOut &SOut) const
Definition: ds.h:903
TBool Bool
Definition: json.h:12
void Save(TSOut &SOut, const bool &IsSmall=false) const
Definition: dt.h:440
TJsonValType JsonValType
Definition: json.h:11
Definition: dt.h:1044
TJsonValV ValV
Definition: json.h:15
TFlt Num
Definition: json.h:13
void Save(TSOut &SOut) const
Definition: dt.h:1309
TStr TJsonVal::SaveStr ( )

Definition at line 14 of file json.cpp.

14  {
15  return GetStrFromVal(this);
16 }
static TStr GetStrFromVal(const PJsonVal &Val)
Definition: json.cpp:281
TJsonVal::UndefCopyAssign ( TJsonVal  )
private

Friends And Related Function Documentation

friend class TPt< TJsonVal >
friend

Definition at line 9 of file json.h.

Member Data Documentation

TBool TJsonVal::Bool
private

Definition at line 12 of file json.h.

TCRef TJsonVal::CRef
private

Definition at line 9 of file json.h.

TJsonValType TJsonVal::JsonValType
private

Definition at line 11 of file json.h.

THash<TStr, PJsonVal> TJsonVal::KeyValH
private

Definition at line 16 of file json.h.

TFlt TJsonVal::Num
private

Definition at line 13 of file json.h.

TStr TJsonVal::Str
private

Definition at line 14 of file json.h.

TJsonValV TJsonVal::ValV
private

Definition at line 15 of file json.h.


The documentation for this class was generated from the following files: