Barracuda Application Server C/C++ Reference
NO
JVal.h
1/*
2 * ____ _________ __ _
3 * / __ \___ ____ _/ /_ __(_)___ ___ ___ / / ____ ____ _(_)____
4 * / /_/ / _ \/ __ `/ / / / / / __ `__ \/ _ \/ / / __ \/ __ `/ / ___/
5 * / _, _/ __/ /_/ / / / / / / / / / / / __/ /___/ /_/ / /_/ / / /__
6 * /_/ |_|\___/\__,_/_/ /_/ /_/_/ /_/ /_/\___/_____/\____/\__, /_/\___/
7 * /____/
8 *
9 * Barracuda Application Server
10 *
11 ****************************************************************************
12 * HEADER
13 *
14 * $Id: JVal.h 5380 2023-02-16 15:40:23Z wini $
15 *
16 * COPYRIGHT: Real Time Logic LLC, 2006-2014
17 *
18 * This software is copyrighted by and is the sole property of Real
19 * Time Logic LLC. All rights, title, ownership, or other interests in
20 * the software remain the property of Real Time Logic LLC. This
21 * software may only be used in accordance with the terms and
22 * conditions stipulated in the corresponding license agreement under
23 * which the software has been supplied. Any unauthorized use,
24 * duplication, transmission, distribution, or disclosure of this
25 * software is expressly forbidden.
26 *
27 * This Copyright notice may not be removed or modified without prior
28 * written consent of Real Time Logic LLC.
29 *
30 * Real Time Logic LLC. reserves the right to modify this software
31 * without notice.
32 *
33 * http://www.realtimelogic.com
34 ****************************************************************************
35 *
36 */
37
38#ifndef __JVal_h
39#define __JVal_h
40
41#include <JParser.h>
42#include <stdarg.h>
43
72struct JVal
73{
74#ifdef __cplusplus
78
81 JVal* vget(JErr* err,const char** fmt, va_list* argList);
82
155 JVal* get(JErr* err, const char* fmt, ...);
156
161 S32 getInt(JErr* e);
162
166 void setInt(JErr* e,S32 v);
167
172 S64 getLong(JErr* e);
173
177 void setLong(JErr* e,S64 v);
178
183 double getDouble(JErr* e);
184
188 void setDouble(JErr* e,double v);
189
193 BaBool getBoolean(JErr* e);
194
198 void setBoolean(JErr* e,BaBool v);
199
202 void setNull(JErr* e);
203
207 const char* getString(JErr* e);
208
215 void setString(JErr* e, char* v);
216
220 char* manageString(JErr* e);
221
224 const char* getName();
225
229 char* manageName();
230
233 JVal* getNextElem();
234
238 JVal* getObject(JErr* e);
239
242 JVal* getArray(JErr* e);
243
247 JVal* getJ(JErr* e);
248
252 JVal* manageJ(JErr* e);
253
258 S32 getLength(JErr* e);
259
263 bool isObjectMember();
264
268 int unlink(JVal* child);
269
276 int addMember(JErr* e, const char* memberName,
277 JVal* child, AllocatorIntf* dAlloc);
278
283 int add(JErr* e, JVal* child);
284
294 void terminate(AllocatorIntf* vAlloc, AllocatorIntf* dAlloc);
295#endif
296 union
297 {
298 struct JVal* firstChild; /* If object or array */
299 U8* s; /* If string */
300#ifndef NO_DOUBLE
301 double f; /* If floating point */
302#endif
303 S32 d; /* If integer */
304 S64 l; /* If long integer */
305 BaBool b; /* If true or false */
306 } v;
307
308 char* memberName;
309 struct JVal* next;
310 JVType type;
311};
312
313typedef struct JVal JVal;
314
315#ifdef __cplusplus
316extern "C" {
317#endif
318#define JVal_getType(o) (o)->type
319BA_API JVal* JVal_vget(JVal* o,JErr* err,const char** fmt, va_list* argList);
320BA_API JVal* JVal_get(JVal* o, JErr* err, const char* fmt, ...);
321BA_API S32 JVal_getInt(JVal* o, JErr* e);
322BA_API S64 JVal_getLong(JVal* o, JErr* e);
323BA_API double JVal_getDouble(JVal* o, JErr* e);
324BA_API BaBool JVal_getBoolean(JVal* o, JErr* e);
325BA_API const char* JVal_getString(JVal* o, JErr* e);
326BA_API char* JVal_manageString(JVal* o, JErr* e);
327BA_API const char* JVal_getName(JVal* o);
328BA_API char* JVal_manageName(JVal* o);
329#define JVal_getNextElem(o) (o)->next
330BA_API JVal* JVal_getObject(JVal* o, JErr* e);
331BA_API JVal* JVal_getArray(JVal* o, JErr* e);
332BA_API JVal* JVal_getJ(JVal* o, JErr* e);
333BA_API JVal* JVal_manageJ(JVal* o, JErr* e);
334BA_API S32 JVal_getLength(struct JVal* o, JErr* e);
335#define JVal_isObjectMember(o) ((o)->memberName != 0)
336BA_API int JVal_unlink(JVal* o, JVal* child);
337BA_API int JVal_addMember(JVal* o, JErr* e, const char* memberName,
338 JVal* child, AllocatorIntf* dAlloc);
339BA_API int JVal_add(JVal* o, JErr* e, JVal* child);
340BA_API void JVal_terminate(JVal* o, AllocatorIntf* vAlloc,
341 AllocatorIntf* dAlloc);
342#define JVal_setInt(o, e, v) JVal_setX(o, e, JVType_Int, &v)
343#define JVal_setLong(o, e, v) JVal_setX(o, e, JVType_Long, &v)
344#define JVal_setDouble(o, e, v) JVal_setX(o, e, JVType_Double, &v)
345#define JVal_setBoolean(o, e, v) JVal_setX(o, e, JVType_Boolean, &v)
346#define JVal_setNull(o, e) JVal_setX(o, e, JVType_Null, 0)
347#define JVal_setString(o, e, v) JVal_setX(o, e, JVType_String, v)
348BA_API void JVal_setX(JVal* o, JErr* e, JVType t, void* v);
349#ifdef __cplusplus
350}
352 return JVal_getType(this); }
353inline JVal* JVal::vget(JErr* err,const char** fmt, va_list* argList){
354 return JVal_vget(this,err,fmt, argList); }
355inline JVal* JVal::get( JErr* err, const char* fmt, ...){
356 JVal* retv; va_list argList;
357 va_start(argList, fmt);
358 retv = JVal_vget(this,err,&fmt,&argList);
359 va_end(argList);
360 return retv;
361}
362inline S32 JVal::getInt(JErr* e){
363 return JVal_getInt(this, e); }
364inline S64 JVal::getLong(JErr* e){
365 return JVal_getLong(this, e); }
366inline double JVal::getDouble(JErr* e){
367 return JVal_getDouble(this, e); }
368inline BaBool JVal::getBoolean(JErr* e){
369 return JVal_getBoolean(this, e); }
370inline const char* JVal::getString(JErr* e){
371 return JVal_getString(this, e); }
372inline char* JVal::manageString(JErr* e){
373 return JVal_manageString(this, e); }
374inline const char* JVal::getName(){
375 return JVal_getName(this); }
376inline char* JVal::manageName(){
377 return JVal_manageName(this); }
379 return JVal_getNextElem(this); }
381 return JVal_getObject(this, e); }
383 return JVal_getArray(this, e); }
384inline JVal* JVal::getJ(JErr* e){
385 return JVal_getJ(this, e); }
387 return JVal_manageJ(this, e); }
388inline S32 JVal::getLength(JErr* e){
389 return JVal_getLength(this, e); }
390
391inline void JVal::setInt(JErr* e,S32 val) {
392 JVal_setInt(this, e, val); }
393inline void JVal::setLong(JErr* e,S64 val) {
394 JVal_setLong(this, e, val); }
395inline void JVal::setDouble(JErr* e,double val) {
396 JVal_setDouble(this, e, val); }
397inline void JVal::setBoolean(JErr* e,BaBool val) {
398 JVal_setBoolean(this, e, val); }
399inline void JVal::setNull(JErr* e) {
400 JVal_setNull(this, e); }
401inline void JVal::setString(JErr* e, char* val) {
402 JVal_setString(this, e, val); }
404 return JVal_isObjectMember(this) ? true : false; }
405inline int JVal::unlink(JVal* child){
406 return JVal_unlink(this, child); }
407inline int JVal::addMember(JErr* e, const char* name,
408 JVal* child, AllocatorIntf* dAlloc) {
409 return JVal_addMember(this, e, name, child, dAlloc); }
410inline int JVal::add(JErr* e, JVal* child) {
411 return JVal_add(this, e, child); }
412inline void JVal::terminate(AllocatorIntf* vAlloc, AllocatorIntf* dAlloc){
413 JVal_terminate(this, vAlloc, dAlloc); }
414#endif
415 /* end of JSONRef */
417
422typedef enum
423{
424 JParserValFactStat_OK=0,
425 JParserValFactStat_DMemErr,
426 JParserValFactStat_VMemErr,
427 JParserValFactStat_MaxNodes
428} JParserValFactStat;
429
445#ifdef __cplusplus
446typedef struct JParserValFact : public JParserIntf
447{
454
458
461 JVal* getFirstVal();
462
467
472 void termFirstVal();
473#else
474typedef struct JParserValFact
475{
476 JParserIntf super; /*Inherits from JParserIntf*/
477#endif
478 AllocatorIntf* dAlloc;
479 AllocatorIntf* vAlloc;
480 JVal** vStack;
481 int vStackSize;
482 U32 nodeCounter;
483 U32 maxNodes;
484 JParserValFactStat status;
486#ifdef __cplusplus
487extern "C" {
488#endif
489BA_API void JParserValFact_constructor(
490 JParserValFact* o, AllocatorIntf* vAlloc, AllocatorIntf* dAlloc);
491#define JParserValFact_getFirstVal(o) \
492 ((o)->vStack && *(o)->vStack ? *(o)->vStack : 0)
493BA_API JVal* JParserValFact_manageFirstVal(JParserValFact* o);
494BA_API void JParserValFact_termFirstVal(JParserValFact* o);
495BA_API void JParserValFact_destructor(JParserValFact* o);
496#ifdef __cplusplus
497}
499 AllocatorIntf* vAlloc, AllocatorIntf* dAlloc){
500 JParserValFact_constructor(this, vAlloc, dAlloc);}
502 return JParserValFact_getFirstVal(this); }
504 return JParserValFact_manageFirstVal(this); }
506 JParserValFact_termFirstVal(this); }
508 JParserValFact_destructor(this); }
509#endif
510 /* end of JSONCB */
512
522typedef struct JValFact
523{
524#ifdef __cplusplus
530 JValFact(AllocatorIntf* vAlloc, AllocatorIntf* dAlloc);
531
534 JVal* mkString(const char* v);
535
538 JVal* mkDouble(double v);
539
542 JVal* mkInt(S32 v);
543
546 JVal* mkLong(S64 v);
547
550 JVal* mkBoolean(bool v);
551
554 JVal* mkNull();
555
558 JVal* mkObject();
559
562 JVal* mkArray();
563#endif
564 AllocatorIntf* dAlloc;
565 AllocatorIntf* vAlloc;
567#ifdef __cplusplus
568extern "C" {
569#endif
570#define JValFact_mkString(o, v) JValFact_mkVal(o, JVType_String, v)
571#define JValFact_mkDouble(o, v) JValFact_mkVal(o, JVType_Double, &v)
572#define JValFact_mkInt(o, v) JValFact_mkVal(o, JVType_Int, &v)
573#define JValFact_mkLong(o, v) JValFact_mkVal(o, JVType_Long, &v)
574#define JValFact_mkBoolean(o, v) JValFact_mkVal(o, JVType_Boolean, &v)
575#define JValFact_mkNull(o) JValFact_mkVal(o, JVType_Null, 0)
576#define JValFact_mkObject(o) JValFact_mkVal(o, JVType_Object, 0)
577#define JValFact_mkArray(o) JValFact_mkVal(o, JVType_Array, 0)
578BA_API void JValFact_constructor(
579 JValFact* o, AllocatorIntf* vAlloc, AllocatorIntf* dAlloc);
580BA_API JVal* JValFact_mkVal(JValFact* o, JVType t, const void* uv);
581#ifdef __cplusplus
582}
584 JValFact_constructor(this,vAlloc, dAlloc); }
585inline JVal* JValFact::mkString(const char* v) {
586 return JValFact_mkString(this, v); }
587inline JVal* JValFact::mkDouble(double v) {
588 return JValFact_mkDouble(this, v); }
589inline JVal* JValFact::mkInt(S32 v) {
590 return JValFact_mkInt(this, v); }
591inline JVal* JValFact::mkLong(S64 v) {
592 return JValFact_mkLong(this, v); }
593inline JVal* JValFact::mkBoolean(bool v) {
594 BaBool b = v ? TRUE : FALSE;
595 return JValFact_mkBoolean(this, b); }
597 return JValFact_mkNull(this); }
599 return JValFact_mkObject(this); }
601 return JValFact_mkArray(this); }
602#endif
603 /* end of JSONRef */
605
606#endif
JParserValFact(AllocatorIntf *vAlloc, AllocatorIntf *dAlloc)
create a JParserValFact JVal factory instance.
Definition: JVal.h:498
JVal * manageFirstVal()
Similar to getFirstVal, but you must manage the JVal tree as the value is detached from the JParserVa...
Definition: JVal.h:503
~JParserValFact()
The destructor terminates all nodes not managed.
Definition: JVal.h:507
void termFirstVal()
Terminate the syntax tree such that the JParserValFact instance can be reused when the JParser instan...
Definition: JVal.h:505
JVal * getFirstVal()
Returns the root of the JVal syntax tree.
Definition: JVal.h:501
const char * getName()
Returns the member name if this value is part of a JSON object.
Definition: JVal.h:374
void setLong(JErr *e, S64 v)
Sets a new integer value or changes the JSON type and sets the integer value.
Definition: JVal.h:393
JVal * mkDouble(double v)
Make a float.
Definition: JVal.h:587
char * manageString(JErr *e)
Similar to getString, but you must manage the value as the value is detached from the tree.
Definition: JVal.h:372
JVal * mkLong(S64 v)
Make a long integer.
Definition: JVal.h:591
JVal * mkInt(S32 v)
Make an integer.
Definition: JVal.h:589
JVal * mkBoolean(bool v)
Make a boolean.
Definition: JVal.h:593
int addMember(JErr *e, const char *memberName, JVal *child, AllocatorIntf *dAlloc)
Add a child to an object.
Definition: JVal.h:407
void setString(JErr *e, char *v)
Sets a string value and changes the JSON type if needed.
Definition: JVal.h:401
void terminate(AllocatorIntf *vAlloc, AllocatorIntf *dAlloc)
Terminate the node and all sub nodes.
Definition: JVal.h:412
S64 getLong(JErr *e)
Returns the integer as a long value for an integer JVal type or attempts to convert the value to a lo...
Definition: JVal.h:364
bool isObjectMember()
Returns true if this is a child element in an object.
Definition: JVal.h:403
JVal * getArray(JErr *e)
Returns the first child if an array.
Definition: JVal.h:382
JVal * getNextElem()
Returns the next element if the parent is an object or an array.
Definition: JVal.h:378
JVType
The JSON types.
Definition: JParser.h:103
JVal * mkNull()
Make a null value.
Definition: JVal.h:596
struct JValFact JValFact
The JValFact enables one to manually create a JVal syntax tree or add nodes to an existing syntax tre...
JVal * manageJ(JErr *e)
Similar to getJ, but you must manage the JVal as the value is detached from the tree.
Definition: JVal.h:386
JVal * getObject(JErr *e)
Returns the first child if an object.
Definition: JVal.h:380
JVal * getJ(JErr *e)
Returns the first child if an array or object.
Definition: JVal.h:384
double getDouble(JErr *e)
Returns the double value for a JVal float or attempts to convert the value to a float.
Definition: JVal.h:366
BaBool getBoolean(JErr *e)
Returns the boolean value for a boolean JVal type or false if the JVal is JVType_Null.
Definition: JVal.h:368
JVal * mkString(const char *v)
Make a string.
Definition: JVal.h:585
JVal * get(JErr *err, const char *fmt,...)
Get any type of value(s) from a JVal node or JVal tree.
Definition: JVal.h:355
JVal * mkArray()
Make a JSON array.
Definition: JVal.h:600
S32 getInt(JErr *e)
Returns the integer value for an integer JVal type or attempts to convert the value to an integer.
Definition: JVal.h:362
JVType getType()
Returns the JSON type.
Definition: JVal.h:351
JVal * mkObject()
Make a JSON object.
Definition: JVal.h:598
JVal * vget(JErr *err, const char **fmt, va_list *argList)
Equivalent to get with variable argument list replaced by argList.
Definition: JVal.h:353
char * manageName()
Similar to getName, but you must manage the value as the value is detached from the tree.
Definition: JVal.h:376
int add(JErr *e, JVal *child)
Add a child to an array.
Definition: JVal.h:410
S32 getLength(JErr *e)
Returns the elements left in the list.
Definition: JVal.h:388
void setBoolean(JErr *e, BaBool v)
Sets a new boolean value or changes the JSON type and sets the boolean value.
Definition: JVal.h:397
void setDouble(JErr *e, double v)
Sets a new float value or changes the JSON type to float and sets the float value.
Definition: JVal.h:395
int unlink(JVal *child)
Remove a child.
Definition: JVal.h:405
void setNull(JErr *e)
Changes the JSON type if not NULL.
Definition: JVal.h:399
const char * getString(JErr *e)
Returns the string as a const or returns NULL if the JVAL is a NULL type.
Definition: JVal.h:370
JValFact(AllocatorIntf *vAlloc, AllocatorIntf *dAlloc)
create a JValFact JVal factory instance.
Definition: JVal.h:583
void setInt(JErr *e, S32 v)
Sets a new integer value or changes the JSON type and sets the integer value.
Definition: JVal.h:391
Memory allocation and deallocation Interface class.
Definition: AllocatorIntf.h:83
The JSON error container object.
Definition: JParser.h:155
The JParserIntf interface class is the interface between the parser and an object that implements the...
Definition: JParser.h:65
JParserValFact is the JVal JSON parser factory class.
Definition: JVal.h:447
The JValFact enables one to manually create a JVal syntax tree or add nodes to an existing syntax tre...
Definition: JVal.h:523
JVal represents a value in a JSON tree.
Definition: JVal.h:73