Barracuda Application Server C/C++ Reference
Native APIs, integration guides, and platform interfaces
JVal.h
Go to the documentation of this file.
1/*
2 * ____ _________ __ _
3 * / __ \___ ____ _/ /_ __(_)___ ___ ___ / / ____ ____ _(_)____
4 * / /_/ / _ \/ __ `/ / / / / / __ `__ \/ _ \/ / / __ \/ __ `/ / ___/
5 * / _, _/ __/ /_/ / / / / / / / / / / / __/ /___/ /_/ / /_/ / / /__
6 * /_/ |_|\___/\__,_/_/ /_/ /_/_/ /_/ /_/\___/_____/\____/\__, /_/\___/
7 * /____/
8 *
9 * Barracuda Application Server
10 *
11 ****************************************************************************
12 * HEADER
13 *
14 * $Id: JVal.h 5978 2026-09-11 16:13:48Z wini $
15 *
16 * COPYRIGHT: Real Time Logic LLC, 2006-2026
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
40#ifndef __JVal_h
41#define __JVal_h
42
43#include <JParser.h>
44#include <stdarg.h>
45
77struct JVal
78{
79#ifdef __cplusplus
83
90 JVal* vget(JErr* err,const char** fmt, va_list* argList);
91
174 JVal* get(JErr* err, const char* fmt, ...);
175
183 S32 getInt(JErr* e);
184
192 void setInt(JErr* e,S32 v);
193
201 S64 getLong(JErr* e);
202
210 void setLong(JErr* e,S64 v);
211
218 double getDouble(JErr* e);
219
227 void setDouble(JErr* e,double v);
228
235
243 void setBoolean(JErr* e,BaBool v);
244
250 void setNull(JErr* e);
251
258 const char* getString(JErr* e);
259
263 size_t getStringLen();
264
273 void setString(JErr* e, char* v);
274
281 char* manageString(JErr* e);
282
286 const char* getName();
287
291 size_t getNameLen();
292
298 char* manageName();
299
303 JVal* getNextElem();
304
310 JVal* getObject(JErr* e);
311
317 JVal* getArray(JErr* e);
318
324 JVal* getJ(JErr* e);
325
332 JVal* manageJ(JErr* e);
333
339 S32 getLength(JErr* e);
340
344 bool isObjectMember();
345
351 int unlink(JVal* child);
352
364 int addMember(JErr* e, const char* memberName,
365 JVal* child, AllocatorIntf* dAlloc);
366
374 int add(JErr* e, JVal* child);
375
383 void terminate(AllocatorIntf* vAlloc, AllocatorIntf* dAlloc);
384#endif
385 union
386 {
387 struct JVal* firstChild; /* If object or array */
388 U8* s; /* If string */
389#ifndef NO_DOUBLE
390 double f; /* If floating point */
391#endif
392 S32 d; /* If integer */
393 S64 l; /* If long integer */
394 BaBool b; /* If true or false */
395 } v;
396
397 char* memberName;
398 struct JVal* next;
399 size_t stringLen;
400 size_t memberNameLen;
401 JVType type;
402};
403
404typedef struct JVal JVal;
405
406#ifdef __cplusplus
407extern "C" {
408#endif
412#define JVal_getType(o) (o)->type
416BA_API JVal* JVal_vget(JVal* o,JErr* err,const char** fmt, va_list* argList);
420BA_API JVal* JVal_get(JVal* o, JErr* err, const char* fmt, ...);
424BA_API S32 JVal_getInt(JVal* o, JErr* e);
428BA_API S64 JVal_getLong(JVal* o, JErr* e);
432BA_API double JVal_getDouble(JVal* o, JErr* e);
440BA_API const char* JVal_getString(JVal* o, JErr* e);
444#define JVal_getStringLen(o) (o)->stringLen
448BA_API char* JVal_manageString(JVal* o, JErr* e);
452BA_API const char* JVal_getName(JVal* o);
456#define JVal_getNameLen(o) (o)->memberNameLen
460BA_API char* JVal_manageName(JVal* o);
464#define JVal_getNextElem(o) (o)->next
468BA_API JVal* JVal_getObject(JVal* o, JErr* e);
472BA_API JVal* JVal_getArray(JVal* o, JErr* e);
476BA_API JVal* JVal_getJ(JVal* o, JErr* e);
480BA_API JVal* JVal_manageJ(JVal* o, JErr* e);
484BA_API S32 JVal_getLength(struct JVal* o, JErr* e);
488#define JVal_isObjectMember(o) ((o)->memberName != 0)
492BA_API int JVal_unlink(JVal* o, JVal* child);
496BA_API int JVal_addMember(JVal* o, JErr* e, const char* memberName,
497 JVal* child, AllocatorIntf* dAlloc);
501BA_API int JVal_add(JVal* o, JErr* e, JVal* child);
505BA_API void JVal_terminate(JVal* o, AllocatorIntf* vAlloc,
506 AllocatorIntf* dAlloc);
511#define JVal_setInt(o, e, v) JVal_setX(o, e, JVType_Int, &v)
516#define JVal_setLong(o, e, v) JVal_setX(o, e, JVType_Long, &v)
521#define JVal_setDouble(o, e, v) JVal_setX(o, e, JVType_Double, &v)
526#define JVal_setBoolean(o, e, v) JVal_setX(o, e, JVType_Boolean, &v)
530#define JVal_setNull(o, e) JVal_setX(o, e, JVType_Null, 0)
534#define JVal_setString(o, e, v) JVal_setX(o, e, JVType_String, v)
544BA_API void JVal_setX(JVal* o, JErr* e, JVType t, void* v);
545#ifdef __cplusplus
546}
548 return JVal_getType(this); }
549inline JVal* JVal::vget(JErr* err,const char** fmt, va_list* argList){
550 return JVal_vget(this,err,fmt, argList); }
551inline JVal* JVal::get( JErr* err, const char* fmt, ...){
552 JVal* retv; va_list argList;
553 va_start(argList, fmt);
554 retv = JVal_vget(this,err,&fmt,&argList);
555 va_end(argList);
556 return retv;
557}
559 return JVal_getInt(this, e); }
561 return JVal_getLong(this, e); }
562inline double JVal::getDouble(JErr* e){
563 return JVal_getDouble(this, e); }
565 return JVal_getBoolean(this, e); }
566inline const char* JVal::getString(JErr* e){
567 return JVal_getString(this, e); }
568inline size_t JVal::getStringLen(){
569 return JVal_getStringLen(this); }
570inline char* JVal::manageString(JErr* e){
571 return JVal_manageString(this, e); }
572inline const char* JVal::getName(){
573 return JVal_getName(this); }
574inline size_t JVal::getNameLen(){
575 return JVal_getNameLen(this); }
576inline char* JVal::manageName(){
577 return JVal_manageName(this); }
579 return JVal_getNextElem(this); }
581 return JVal_getObject(this, e); }
583 return JVal_getArray(this, e); }
584inline JVal* JVal::getJ(JErr* e){
585 return JVal_getJ(this, e); }
587 return JVal_manageJ(this, e); }
589 return JVal_getLength(this, e); }
590
591inline void JVal::setInt(JErr* e,S32 val) {
592 JVal_setInt(this, e, val); }
593inline void JVal::setLong(JErr* e,S64 val) {
594 JVal_setLong(this, e, val); }
595inline void JVal::setDouble(JErr* e,double val) {
596 JVal_setDouble(this, e, val); }
597inline void JVal::setBoolean(JErr* e,BaBool val) {
598 JVal_setBoolean(this, e, val); }
599inline void JVal::setNull(JErr* e) {
600 JVal_setNull(this, e); }
601inline void JVal::setString(JErr* e, char* val) {
602 JVal_setString(this, e, val); }
604 return JVal_isObjectMember(this) ? true : false; }
605inline int JVal::unlink(JVal* child){
606 return JVal_unlink(this, child); }
607inline int JVal::addMember(JErr* e, const char* name,
608 JVal* child, AllocatorIntf* dAlloc) {
609 return JVal_addMember(this, e, name, child, dAlloc); }
610inline int JVal::add(JErr* e, JVal* child) {
611 return JVal_add(this, e, child); }
612inline void JVal::terminate(AllocatorIntf* vAlloc, AllocatorIntf* dAlloc){
613 JVal_terminate(this, vAlloc, dAlloc); }
614#endif
615 /* end of JSONRef */
617
622typedef enum
623{
624 JParserValFactStat_OK=0,
625 JParserValFactStat_DMemErr,
626 JParserValFactStat_VMemErr,
627 JParserValFactStat_MaxNodes
628} JParserValFactStat;
629
645#ifdef __cplusplus
646typedef struct JParserValFact : public JParserIntf
647{
655
660
664 JVal* getFirstVal();
665
671
676 void termFirstVal();
677#else
678typedef struct JParserValFact
679{
680 JParserIntf super; /*Inherits from JParserIntf*/
681#endif
682 AllocatorIntf* dAlloc;
683 AllocatorIntf* vAlloc;
684 JVal** vStack;
685 int vStackSize;
686 U32 nodeCounter;
692 JParserValFactStat status;
694#ifdef __cplusplus
695extern "C" {
696#endif
701 JParserValFact* o, AllocatorIntf* vAlloc, AllocatorIntf* dAlloc);
705#define JParserValFact_getFirstVal(o) \
706 ((o)->vStack && *(o)->vStack ? *(o)->vStack : 0)
719#ifdef __cplusplus
720}
722 AllocatorIntf* vAlloc, AllocatorIntf* dAlloc){
723 JParserValFact_constructor(this, vAlloc, dAlloc);}
725 return JParserValFact_getFirstVal(this); }
727 return JParserValFact_manageFirstVal(this); }
732#endif
733 /* end of JSONCB */
735
745typedef struct JValFact
746{
747#ifdef __cplusplus
754 JValFact(AllocatorIntf* vAlloc, AllocatorIntf* dAlloc);
755
761 JVal* mkString(const char* v);
762
768 JVal* mkDouble(double v);
769
775 JVal* mkInt(S32 v);
776
782 JVal* mkLong(S64 v);
783
789 JVal* mkBoolean(bool v);
790
795 JVal* mkNull();
796
801 JVal* mkObject();
802
807 JVal* mkArray();
808#endif
809 AllocatorIntf* dAlloc;
810 AllocatorIntf* vAlloc;
812#ifdef __cplusplus
813extern "C" {
814#endif
818#define JValFact_mkString(o, v) JValFact_mkVal(o, JVType_String, v)
823#define JValFact_mkDouble(o, v) JValFact_mkVal(o, JVType_Double, &v)
828#define JValFact_mkInt(o, v) JValFact_mkVal(o, JVType_Int, &v)
833#define JValFact_mkLong(o, v) JValFact_mkVal(o, JVType_Long, &v)
838#define JValFact_mkBoolean(o, v) JValFact_mkVal(o, JVType_Boolean, &v)
842#define JValFact_mkNull(o) JValFact_mkVal(o, JVType_Null, 0)
846#define JValFact_mkObject(o) JValFact_mkVal(o, JVType_Object, 0)
850#define JValFact_mkArray(o) JValFact_mkVal(o, JVType_Array, 0)
855 JValFact* o, AllocatorIntf* vAlloc, AllocatorIntf* dAlloc);
865BA_API JVal* JValFact_mkVal(JValFact* o, JVType t, const void* uv);
866#ifdef __cplusplus
867}
869 JValFact_constructor(this,vAlloc, dAlloc); }
870inline JVal* JValFact::mkString(const char* v) {
871 return JValFact_mkString(this, v); }
872inline JVal* JValFact::mkDouble(double v) {
873 return JValFact_mkDouble(this, v); }
875 return JValFact_mkInt(this, v); }
877 return JValFact_mkLong(this, v); }
878inline JVal* JValFact::mkBoolean(bool v) {
879 BaBool b = v ? TRUE : FALSE;
880 return JValFact_mkBoolean(this, b); }
882 return JValFact_mkNull(this); }
884 return JValFact_mkObject(this); }
886 return JValFact_mkArray(this); }
887#endif
888 /* end of JSONRef */
890
891#endif
JParserValFact(AllocatorIntf *vAlloc, AllocatorIntf *dAlloc)
Initialize a factory without allocating a tree.
Definition: JVal.h:721
JVal * manageFirstVal()
Detach the current root and reset the node counter when a root exists.
Definition: JVal.h:726
BA_API JVal * JParserValFact_manageFirstVal(JParserValFact *o)
Detach the current root and reset the node counter when a root exists.
~JParserValFact()
Free the attached root and all factory stack storage.
Definition: JVal.h:730
void termFirstVal()
Free the attached tree and factory stack, preparing for another document.
Definition: JVal.h:728
BA_API void JParserValFact_constructor(JParserValFact *o, AllocatorIntf *vAlloc, AllocatorIntf *dAlloc)
Initialize a factory without allocating a tree.
JVal * getFirstVal()
Definition: JVal.h:724
BA_API void JParserValFact_termFirstVal(JParserValFact *o)
Free the attached tree and factory stack, preparing for another document.
#define JParserValFact_getFirstVal(o)
Definition: JVal.h:705
BA_API void JParserValFact_destructor(JParserValFact *o)
Free the attached root and all factory stack storage.
const char * getName()
Definition: JVal.h:572
void setLong(JErr *e, S64 v)
Replace a scalar value and set its type.
Definition: JVal.h:593
#define JVal_setDouble(o, e, v)
Replace a scalar value and set its type.
Definition: JVal.h:521
#define JValFact_mkArray(o)
Create a detached array node.
Definition: JVal.h:850
JVal * mkDouble(double v)
Create a detached double node.
Definition: JVal.h:872
char * manageString(JErr *e)
Detach a string's storage, leaving a String node with NULL data and zero length.
Definition: JVal.h:570
JVal * mkLong(S64 v)
Create a detached long node.
Definition: JVal.h:876
JVal * mkInt(S32 v)
Create a detached int node.
Definition: JVal.h:874
BA_API int JVal_add(JVal *o, JErr *e, JVal *child)
Prepend a child to an array.
BA_API JVal * JValFact_mkVal(JValFact *o, JVType t, const void *uv)
Allocate a detached typed value.
BA_API S32 JVal_getInt(JVal *o, JErr *e)
Convert a numeric, boolean, or null node to S32.
JVal * mkBoolean(bool v)
Create a detached boolean node.
Definition: JVal.h:878
BA_API S64 JVal_getLong(JVal *o, JErr *e)
Convert a numeric, boolean, or null node to S64.
BA_API JVal * JVal_getJ(JVal *o, JErr *e)
Access the first child of an object or array node.
BA_API JVal * JVal_getObject(JVal *o, JErr *e)
Access the first child of an object node.
#define JValFact_mkDouble(o, v)
Create a detached double node.
Definition: JVal.h:823
BA_API int JVal_addMember(JVal *o, JErr *e, const char *memberName, JVal *child, AllocatorIntf *dAlloc)
Prepend a child to an object.
int addMember(JErr *e, const char *memberName, JVal *child, AllocatorIntf *dAlloc)
Prepend a child to an object.
Definition: JVal.h:607
BA_API void JVal_setX(JVal *o, JErr *e, JVType t, void *v)
Low-level scalar replacement used by the typed setter macros.
BA_API JVal * JVal_getArray(JVal *o, JErr *e)
Access the first child of an array node.
void setString(JErr *e, char *v)
Store a string pointer without copying it and set the node's type.
Definition: JVal.h:601
#define JVal_getStringLen(o)
Definition: JVal.h:444
void terminate(AllocatorIntf *vAlloc, AllocatorIntf *dAlloc)
Free this node, all descendants, and all following siblings recursively.
Definition: JVal.h:612
#define JVal_setBoolean(o, e, v)
Replace a scalar value and set its type.
Definition: JVal.h:526
BA_API S32 JVal_getLength(struct JVal *o, JErr *e)
Count immediate children of this object/array.
BA_API JVal * JVal_get(JVal *o, JErr *err, const char *fmt,...)
Get any type of value(s) from a JVal node or JVal tree.
S64 getLong(JErr *e)
Convert a numeric, boolean, or null node to S64.
Definition: JVal.h:560
#define JValFact_mkLong(o, v)
Create a detached long node.
Definition: JVal.h:833
bool isObjectMember()
Definition: JVal.h:603
JVal * getArray(JErr *e)
Access the first child of an array node.
Definition: JVal.h:582
JVal * getNextElem()
Definition: JVal.h:578
JVType
The JSON types.
Definition: JParser.h:121
JVal * mkNull()
Create a detached null node.
Definition: JVal.h:881
BA_API JVal * JVal_manageJ(JVal *o, JErr *e)
Detach all children from an object/array, leaving the container empty.
#define JVal_setNull(o, e)
Replace a scalar value with JSON null.
Definition: JVal.h:530
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)
Detach all children from an object/array, leaving the container empty.
Definition: JVal.h:586
JVal * getObject(JErr *e)
Access the first child of an object node.
Definition: JVal.h:580
JVal * getJ(JErr *e)
Access the first child of an object or array node.
Definition: JVal.h:584
BA_API char * JVal_manageName(JVal *o)
Detach the member name and clear its pointer/length in the node.
#define JValFact_mkObject(o)
Create a detached object node.
Definition: JVal.h:846
BA_API char * JVal_manageString(JVal *o, JErr *e)
Detach a string's storage, leaving a String node with NULL data and zero length.
size_t getNameLen()
Definition: JVal.h:574
#define JVal_getNextElem(o)
Definition: JVal.h:464
double getDouble(JErr *e)
Convert a numeric, boolean, or null node to double.
Definition: JVal.h:562
#define JVal_getType(o)
Definition: JVal.h:412
BA_API int JVal_unlink(JVal *o, JVal *child)
Remove one immediate child without destroying it.
BA_API BaBool JVal_getBoolean(JVal *o, JErr *e)
Read a boolean or null node.
BA_API const char * JVal_getString(JVal *o, JErr *e)
Access a string without transferring ownership.
#define JVal_isObjectMember(o)
Definition: JVal.h:488
BaBool getBoolean(JErr *e)
Read a boolean or null node.
Definition: JVal.h:564
#define JVal_setLong(o, e, v)
Replace a scalar value and set its type.
Definition: JVal.h:516
JVal * mkString(const char *v)
Create a detached string node.
Definition: JVal.h:870
#define JValFact_mkBoolean(o, v)
Create a detached boolean node.
Definition: JVal.h:838
JVal * get(JErr *err, const char *fmt,...)
Get any type of value(s) from a JVal node or JVal tree.
Definition: JVal.h:551
BA_API void JVal_terminate(JVal *o, AllocatorIntf *vAlloc, AllocatorIntf *dAlloc)
Free this node, all descendants, and all following siblings recursively.
JVal * mkArray()
Create a detached array node.
Definition: JVal.h:885
S32 getInt(JErr *e)
Convert a numeric, boolean, or null node to S32.
Definition: JVal.h:558
JVType getType()
Definition: JVal.h:547
JVal * mkObject()
Create a detached object node.
Definition: JVal.h:883
BA_API double JVal_getDouble(JVal *o, JErr *e)
Convert a numeric, boolean, or null node to double.
JVal * vget(JErr *err, const char **fmt, va_list *argList)
Extract values as for get(), using mutable format and argument cursors.
Definition: JVal.h:549
size_t getStringLen()
Definition: JVal.h:568
char * manageName()
Detach the member name and clear its pointer/length in the node.
Definition: JVal.h:576
#define JValFact_mkInt(o, v)
Create a detached int node.
Definition: JVal.h:828
#define JValFact_mkNull(o)
Create a detached null node.
Definition: JVal.h:842
int add(JErr *e, JVal *child)
Prepend a child to an array.
Definition: JVal.h:610
BA_API void JValFact_constructor(JValFact *o, AllocatorIntf *vAlloc, AllocatorIntf *dAlloc)
Initialize a factory without allocating a tree.
BA_API JVal * JVal_vget(JVal *o, JErr *err, const char **fmt, va_list *argList)
Extract values as for get(), using mutable format and argument cursors.
S32 getLength(JErr *e)
Count immediate children of this object/array.
Definition: JVal.h:588
void setBoolean(JErr *e, BaBool v)
Replace a scalar value and set its type.
Definition: JVal.h:597
void setDouble(JErr *e, double v)
Replace a scalar value and set its type.
Definition: JVal.h:595
int unlink(JVal *child)
Remove one immediate child without destroying it.
Definition: JVal.h:605
#define JVal_getNameLen(o)
Definition: JVal.h:456
void setNull(JErr *e)
Replace a scalar value with JSON null.
Definition: JVal.h:599
const char * getString(JErr *e)
Access a string without transferring ownership.
Definition: JVal.h:566
#define JVal_setString(o, e, v)
Store a string pointer without copying it and set the node's type.
Definition: JVal.h:534
JValFact(AllocatorIntf *vAlloc, AllocatorIntf *dAlloc)
Initialize a factory without allocating a tree.
Definition: JVal.h:868
#define JValFact_mkString(o, v)
Create a detached string node.
Definition: JVal.h:818
BA_API const char * JVal_getName(JVal *o)
void setInt(JErr *e, S32 v)
Replace a scalar value and set its type.
Definition: JVal.h:591
#define JVal_setInt(o, e, v)
Replace a scalar value and set its type.
Definition: JVal.h:511
int64_t S64
Signed 64-bit integer.
Definition: GenPrimT.h:87
int32_t S32
Signed 32-bit integer.
Definition: GenPrimT.h:85
uint32_t U32
Unsigned 32-bit integer.
Definition: GenPrimT.h:93
uint8_t U8
Unsigned 8-bit integer.
Definition: GenPrimT.h:89
U8 BaBool
Boolean stored in an unsigned byte; FALSE is zero and TRUE is one.
Definition: GenPrimT.h:118
Memory allocation and deallocation Interface class.
Definition: AllocatorIntf.h:98
The JSON error container object.
Definition: JParser.h:173
The JParserIntf interface class is the interface between the parser and an object that implements the...
Definition: JParser.h:72
JParserValFact is the JVal JSON parser factory class.
Definition: JVal.h:647
JParserValFactStat status
Factory status, initially OK; parse failures may set it.
Definition: JVal.h:692
U32 maxNodes
Node-count threshold, initially U32 maximum.
Definition: JVal.h:689
The JValFact enables one to manually create a JVal syntax tree or add nodes to an existing syntax tre...
Definition: JVal.h:746
JVal represents a value in a JSON tree.
Definition: JVal.h:78