36#define DECLARE_JVALUE_HELPERS(decl) \
37 decl void ida_export jvalue_t_clear(jvalue_t *); \
38 decl void ida_export jvalue_t_copy(jvalue_t *, const jvalue_t &);
48 jvalue_t(
const jvalue_t &o) : _type(
JT_UNKNOWN) { jvalue_t_copy(
this, o); }
49 ~jvalue_t() { clear(); }
51 void clear() { jvalue_t_clear(
this); }
53 jvalue_t &operator=(
const jvalue_t &o) { jvalue_t_copy(
this, o);
return *
this; }
56 int64 num()
const { QASSERT(1277, _type ==
JT_NUM);
return _num; }
57 const char *str()
const { QASSERT(1278, _type ==
JT_STR);
return _str->c_str(); }
58 const qstring &qstr()
const { QASSERT(1623, _type ==
JT_STR);
return *_str; }
59 const jobj_t &obj()
const { QASSERT(1279, _type ==
JT_OBJ);
return *_obj; }
60 const jarr_t &arr()
const { QASSERT(1280, _type ==
JT_ARR);
return *_arr; }
61 bool vbool()
const { QASSERT(1281, _type ==
JT_BOOL);
return _bool; }
62 double vdouble()
const { QASSERT(2928, _type ==
JT_DBL);
return _double; }
63 jobj_t &obj() { QASSERT(1282, _type ==
JT_OBJ);
return *_obj; }
64 jarr_t &arr() { QASSERT(1283, _type ==
JT_ARR);
return *_arr; }
66 bool is_null()
const { QASSERT(2929, _type ==
JT_NULL);
return true; }
72 void set_double(
double dbl) {
if ( _type !=
JT_UNKNOWN ) clear(); _type =
JT_DBL; _double = dbl; }
73 void set_str(
const char *s) { set_str(
new qstring(s)); }
77 void set_bool(
bool b) {
if ( _type !=
JT_UNKNOWN ) clear(); _type =
JT_BOOL; _bool = b; }
83 void swap(jvalue_t &r)
85 qswap(_type, r._type);
121 jvalue_t *v =
nullptr;
122 for (
size_t i = 0, _n =
size(); i < _n; ++i )
124 if (
at(i).key == k )
136 return ((
jobj_t *)
this)->get_value(k,
t);
142 QASSERT(1289, v !=
nullptr);
160 for (
size_t i = 0, _n =
size(); i < _n; ++i )
162 if (
at(i).key == k )
178#define DEFINE_FLAG_GETTER(Type, JType, GetExpr) \
179 bool get(Type *out, const char *k) const \
181 const jvalue_t *v = get_value(k, JType); \
182 bool ok = v != nullptr; \
187#define DEFINE_DFLT_GETTER(Type, JType, GetExpr) \
188 Type get(const char *k, Type dflt) const \
190 const jvalue_t *v = get_value(k, JType); \
191 return v != nullptr ? GetExpr : dflt; \
193#define DEFINE_SETTER(Type, SetExpr) \
194 void put(const char *key, Type value) \
196 jvalue_t *v = get_value_or_new(key); \
199#define DEFINE_ACCESSORS(Type, ConstType, JType, GetExpr, SetExpr) \
200 DEFINE_FLAG_GETTER(ConstType, JType, GetExpr) \
201 DEFINE_DFLT_GETTER(ConstType, JType, GetExpr) \
202 DEFINE_SETTER(Type, SetExpr)
213#undef DEFINE_ACCESSORS
215#undef DEFINE_DFLT_GETTER
216#undef DEFINE_FLAG_GETTER
221 bool ok = v !=
nullptr;
230 return v !=
nullptr ? v->qstr() : dflt;
236 v->set_str(
new qstring(value));
242 v->set_obj(
new jobj_t(value));
255 for (
size_t i = 0,
n =
values.size(); i <
n; ++i )
275#define SJF_PRETTY 0x1
276#define SJF_SORTED_KEYS 0x2
Reimplementation of vector class from STL.
Definition pro.h:2250
iterator erase(iterator it)
Definition pro.h:2678
const kvp_t & at(size_t _idx) const
Definition pro.h:2427
qvector(void)
Definition pro.h:2328
iterator begin(void)
Definition pro.h:2609
void push_back(kvp_t &&x)
Definition pro.h:2361
size_t size(void) const
Definition pro.h:2423
idaman size_t n
Definition pro.h:997
const tinfo_t & type
Definition hexrays.hpp:7301
bool ok
Definition kernwin.hpp:7006
ssize_t rc
Definition kernwin.hpp:7101
Tools for parsing C-like input.
qstack< token_t > tokenstack_t
see get_token(), unget_token()
Definition lex.hpp:329
__int64 int64
Definition llong.hpp:14
jtype_t
Definition parsejson.hpp:21
@ JT_NUM
Definition parsejson.hpp:23
@ JT_DBL
Definition parsejson.hpp:29
@ JT_OBJ
Definition parsejson.hpp:25
@ JT_NULL
Definition parsejson.hpp:28
@ JT_BOOL
Definition parsejson.hpp:27
@ JT_ARR
Definition parsejson.hpp:26
@ JT_UNKNOWN
Definition parsejson.hpp:22
@ JT_STR
Definition parsejson.hpp:24
idaman THREAD_SAFE error_t ida_export parse_json_string(jvalue_t *out, const char *s, qstring *errbuf=nullptr, const char *file_path=nullptr)
idaman THREAD_SAFE bool ida_export serialize_json(qstring *out, const jvalue_t &v, uint32 flags=0)
idaman THREAD_SAFE error_t ida_export parse_json(jvalue_t *out, lexer_t *lx, tokenstack_t *ungot_tokens=nullptr)
DECLARE_TYPE_AS_MOVABLE(jvalue_t)
idaman THREAD_SAFE error_t ida_export parse_json_file(jvalue_t *out, const char *path, qstring *errbuf=nullptr)
qvector< jvalue_t > jvalues_t
Definition parsejson.hpp:105
DECLARE_JVALUE_HELPERS(idaman) struct jvalue_t
Definition parsejson.hpp:42
idaman size_t const char time_t t
Definition pro.h:602
THREAD_SAFE void * extract_obj(T &v, void *destbuf, size_t destsize)
Definition pro.h:1996
unsigned int uint32
unsigned 32 bit value
Definition pro.h:348
THREAD_SAFE void qswap(T &a, T &b)
Swap 2 objects of the same type using memory copies.
Definition pro.h:1715
int error_t
Error code (errno)
Definition pro.h:458
_qstring< char > qstring
regular string
Definition pro.h:3694
Definition parsejson.hpp:249
bool is_homogeneous(jtype_t t) const
Definition parsejson.hpp:261
size_t count_items_with_type(jtype_t t) const
Definition parsejson.hpp:252
jvalues_t values
Definition parsejson.hpp:250
Definition parsejson.hpp:117
DEFINE_ACCESSORS(double, double, JT_DBL, v->vdouble(), v->set_double(value))
DEFINE_ACCESSORS(bool, bool, JT_BOOL, v->vbool(), v->set_bool(value))
jvalue_t * get_value(const char *k, jtype_t t=JT_UNKNOWN)
Definition parsejson.hpp:119
const jarr_t & get_arr(const char *k) const
Definition parsejson.hpp:176
const jvalue_t * get_value_or_fail(const char *k, jtype_t t=JT_UNKNOWN) const
Definition parsejson.hpp:139
const qstring & get(const char *k, const qstring &dflt) const
Definition parsejson.hpp:227
int64 get_num(const char *k) const
Definition parsejson.hpp:171
DEFINE_ACCESSORS(jarr_t *, const jarr_t *, JT_ARR, &v->arr(), v->set_arr(value))
DEFINE_ACCESSORS(jobj_t *, const jobj_t *, JT_OBJ, &v->obj(), v->set_obj(value))
void put(const char *key, const qstring &value)
Definition parsejson.hpp:233
DEFINE_ACCESSORS(int, int, JT_NUM, v->num(), v->set_num(value))
bool del_value(const char *k)
Definition parsejson.hpp:158
DEFINE_ACCESSORS(const char *, const char *, JT_STR, v->str(), v->set_str(new qstring(value)))
double get_double(const char *k) const
Definition parsejson.hpp:173
jvalue_t * get_value_or_new(const char *key)
Definition parsejson.hpp:146
bool get(qstring *out, const char *k) const
Definition parsejson.hpp:218
bool has_value(const char *k) const
Definition parsejson.hpp:118
void put(const char *key, const jobj_t &value)
Definition parsejson.hpp:239
const jobj_t & get_obj(const char *k) const
Definition parsejson.hpp:175
const char * get_str(const char *k) const
Definition parsejson.hpp:174
bool get_bool(const char *k) const
Definition parsejson.hpp:172
const jvalue_t * get_value(const char *k, jtype_t t=JT_UNKNOWN) const
Definition parsejson.hpp:134
DEFINE_ACCESSORS(int64, int64, JT_NUM, v->num(), v->set_num(value))
Definition parsejson.hpp:109
qstring key
Definition parsejson.hpp:110
jvalue_t value
Definition parsejson.hpp:111