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 5839 2026-07-29 13:27:22Z 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
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
210 size_t getStringLen();
211
218 void setString(JErr* e, char* v);
219
223 char* manageString(JErr* e);
224
227 const char* getName();
228
230 size_t getNameLen();
231
235 char* manageName();
236
239 JVal* getNextElem();
240
244 JVal* getObject(JErr* e);
245
248 JVal* getArray(JErr* e);
249
253 JVal* getJ(JErr* e);
254
258 JVal* manageJ(JErr* e);
259
264 S32 getLength(JErr* e);
265
269 bool isObjectMember();
270
274 int unlink(JVal* child);
275
282 int addMember(JErr* e, const char* memberName,
283 JVal* child, AllocatorIntf* dAlloc);
284
289 int add(JErr* e, JVal* child);
290
300 void terminate(AllocatorIntf* vAlloc, AllocatorIntf* dAlloc);
301#endif
302 union
303 {
304 struct JVal* firstChild; /* If object or array */
305 U8* s; /* If string */
306#ifndef NO_DOUBLE
307 double f; /* If floating point */
308#endif
309 S32 d; /* If integer */
310 S64 l; /* If long integer */
311 BaBool b; /* If true or false */
312 } v;
313
314 char* memberName;
315 struct JVal* next;
316 size_t stringLen;
317 size_t memberNameLen;
318 JVType type;
319};
320
321typedef struct JVal JVal;
322
323#ifdef __cplusplus
324extern "C" {
325#endif
326#define JVal_getType(o) (o)->type
327BA_API JVal* JVal_vget(JVal* o,JErr* err,const char** fmt, va_list* argList);
328BA_API JVal* JVal_get(JVal* o, JErr* err, const char* fmt, ...);
329BA_API S32 JVal_getInt(JVal* o, JErr* e);
330BA_API S64 JVal_getLong(JVal* o, JErr* e);
331BA_API double JVal_getDouble(JVal* o, JErr* e);
332BA_API BaBool JVal_getBoolean(JVal* o, JErr* e);
333BA_API const char* JVal_getString(JVal* o, JErr* e);
334#define JVal_getStringLen(o) (o)->stringLen
335BA_API char* JVal_manageString(JVal* o, JErr* e);
336BA_API const char* JVal_getName(JVal* o);
337#define JVal_getNameLen(o) (o)->memberNameLen
338BA_API char* JVal_manageName(JVal* o);
339#define JVal_getNextElem(o) (o)->next
340BA_API JVal* JVal_getObject(JVal* o, JErr* e);
341BA_API JVal* JVal_getArray(JVal* o, JErr* e);
342BA_API JVal* JVal_getJ(JVal* o, JErr* e);
343BA_API JVal* JVal_manageJ(JVal* o, JErr* e);
344BA_API S32 JVal_getLength(struct JVal* o, JErr* e);
345#define JVal_isObjectMember(o) ((o)->memberName != 0)
346BA_API int JVal_unlink(JVal* o, JVal* child);
347BA_API int JVal_addMember(JVal* o, JErr* e, const char* memberName,
348 JVal* child, AllocatorIntf* dAlloc);
349BA_API int JVal_add(JVal* o, JErr* e, JVal* child);
350BA_API void JVal_terminate(JVal* o, AllocatorIntf* vAlloc,
351 AllocatorIntf* dAlloc);
352#define JVal_setInt(o, e, v) JVal_setX(o, e, JVType_Int, &v)
353#define JVal_setLong(o, e, v) JVal_setX(o, e, JVType_Long, &v)
354#define JVal_setDouble(o, e, v) JVal_setX(o, e, JVType_Double, &v)
355#define JVal_setBoolean(o, e, v) JVal_setX(o, e, JVType_Boolean, &v)
356#define JVal_setNull(o, e) JVal_setX(o, e, JVType_Null, 0)
357#define JVal_setString(o, e, v) JVal_setX(o, e, JVType_String, v)
358BA_API void JVal_setX(JVal* o, JErr* e, JVType t, void* v);
359#ifdef __cplusplus
360}
362 return JVal_getType(this); }
363inline JVal* JVal::vget(JErr* err,const char** fmt, va_list* argList){
364 return JVal_vget(this,err,fmt, argList); }
365inline JVal* JVal::get( JErr* err, const char* fmt, ...){
366 JVal* retv; va_list argList;
367 va_start(argList, fmt);
368 retv = JVal_vget(this,err,&fmt,&argList);
369 va_end(argList);
370 return retv;
371}
372inline S32 JVal::getInt(JErr* e){
373 return JVal_getInt(this, e); }
374inline S64 JVal::getLong(JErr* e){
375 return JVal_getLong(this, e); }
376inline double JVal::getDouble(JErr* e){
377 return JVal_getDouble(this, e); }
378inline BaBool JVal::getBoolean(JErr* e){
379 return JVal_getBoolean(this, e); }
380inline const char* JVal::getString(JErr* e){
381 return JVal_getString(this, e); }
382inline size_t JVal::getStringLen(){
383 return JVal_getStringLen(this); }
384inline char* JVal::manageString(JErr* e){
385 return JVal_manageString(this, e); }
386inline const char* JVal::getName(){
387 return JVal_getName(this); }
388inline size_t JVal::getNameLen(){
389 return JVal_getNameLen(this); }
390inline char* JVal::manageName(){
391 return JVal_manageName(this); }
393 return JVal_getNextElem(this); }
395 return JVal_getObject(this, e); }
397 return JVal_getArray(this, e); }
398inline JVal* JVal::getJ(JErr* e){
399 return JVal_getJ(this, e); }
401 return JVal_manageJ(this, e); }
402inline S32 JVal::getLength(JErr* e){
403 return JVal_getLength(this, e); }
404
405inline void JVal::setInt(JErr* e,S32 val) {
406 JVal_setInt(this, e, val); }
407inline void JVal::setLong(JErr* e,S64 val) {
408 JVal_setLong(this, e, val); }
409inline void JVal::setDouble(JErr* e,double val) {
410 JVal_setDouble(this, e, val); }
411inline void JVal::setBoolean(JErr* e,BaBool val) {
412 JVal_setBoolean(this, e, val); }
413inline void JVal::setNull(JErr* e) {
414 JVal_setNull(this, e); }
415inline void JVal::setString(JErr* e, char* val) {
416 JVal_setString(this, e, val); }
418 return JVal_isObjectMember(this) ? true : false; }
419inline int JVal::unlink(JVal* child){
420 return JVal_unlink(this, child); }
421inline int JVal::addMember(JErr* e, const char* name,
422 JVal* child, AllocatorIntf* dAlloc) {
423 return JVal_addMember(this, e, name, child, dAlloc); }
424inline int JVal::add(JErr* e, JVal* child) {
425 return JVal_add(this, e, child); }
426inline void JVal::terminate(AllocatorIntf* vAlloc, AllocatorIntf* dAlloc){
427 JVal_terminate(this, vAlloc, dAlloc); }
428#endif
429 /* end of JSONRef */
431
436typedef enum
437{
438 JParserValFactStat_OK=0,
439 JParserValFactStat_DMemErr,
440 JParserValFactStat_VMemErr,
441 JParserValFactStat_MaxNodes
442} JParserValFactStat;
443
459#ifdef __cplusplus
460typedef struct JParserValFact : public JParserIntf
461{
468
472
475 JVal* getFirstVal();
476
481
486 void termFirstVal();
487#else
488typedef struct JParserValFact
489{
490 JParserIntf super; /*Inherits from JParserIntf*/
491#endif
492 AllocatorIntf* dAlloc;
493 AllocatorIntf* vAlloc;
494 JVal** vStack;
495 int vStackSize;
496 U32 nodeCounter;
497 U32 maxNodes;
498 JParserValFactStat status;
500#ifdef __cplusplus
501extern "C" {
502#endif
503BA_API void JParserValFact_constructor(
504 JParserValFact* o, AllocatorIntf* vAlloc, AllocatorIntf* dAlloc);
505#define JParserValFact_getFirstVal(o) \
506 ((o)->vStack && *(o)->vStack ? *(o)->vStack : 0)
507BA_API JVal* JParserValFact_manageFirstVal(JParserValFact* o);
508BA_API void JParserValFact_termFirstVal(JParserValFact* o);
509BA_API void JParserValFact_destructor(JParserValFact* o);
510#ifdef __cplusplus
511}
513 AllocatorIntf* vAlloc, AllocatorIntf* dAlloc){
514 JParserValFact_constructor(this, vAlloc, dAlloc);}
516 return JParserValFact_getFirstVal(this); }
518 return JParserValFact_manageFirstVal(this); }
520 JParserValFact_termFirstVal(this); }
522 JParserValFact_destructor(this); }
523#endif
524 /* end of JSONCB */
526
536typedef struct JValFact
537{
538#ifdef __cplusplus
544 JValFact(AllocatorIntf* vAlloc, AllocatorIntf* dAlloc);
545
548 JVal* mkString(const char* v);
549
552 JVal* mkDouble(double v);
553
556 JVal* mkInt(S32 v);
557
560 JVal* mkLong(S64 v);
561
564 JVal* mkBoolean(bool v);
565
568 JVal* mkNull();
569
572 JVal* mkObject();
573
576 JVal* mkArray();
577#endif
578 AllocatorIntf* dAlloc;
579 AllocatorIntf* vAlloc;
581#ifdef __cplusplus
582extern "C" {
583#endif
584#define JValFact_mkString(o, v) JValFact_mkVal(o, JVType_String, v)
585#define JValFact_mkDouble(o, v) JValFact_mkVal(o, JVType_Double, &v)
586#define JValFact_mkInt(o, v) JValFact_mkVal(o, JVType_Int, &v)
587#define JValFact_mkLong(o, v) JValFact_mkVal(o, JVType_Long, &v)
588#define JValFact_mkBoolean(o, v) JValFact_mkVal(o, JVType_Boolean, &v)
589#define JValFact_mkNull(o) JValFact_mkVal(o, JVType_Null, 0)
590#define JValFact_mkObject(o) JValFact_mkVal(o, JVType_Object, 0)
591#define JValFact_mkArray(o) JValFact_mkVal(o, JVType_Array, 0)
592BA_API void JValFact_constructor(
593 JValFact* o, AllocatorIntf* vAlloc, AllocatorIntf* dAlloc);
594BA_API JVal* JValFact_mkVal(JValFact* o, JVType t, const void* uv);
595#ifdef __cplusplus
596}
598 JValFact_constructor(this,vAlloc, dAlloc); }
599inline JVal* JValFact::mkString(const char* v) {
600 return JValFact_mkString(this, v); }
601inline JVal* JValFact::mkDouble(double v) {
602 return JValFact_mkDouble(this, v); }
603inline JVal* JValFact::mkInt(S32 v) {
604 return JValFact_mkInt(this, v); }
605inline JVal* JValFact::mkLong(S64 v) {
606 return JValFact_mkLong(this, v); }
607inline JVal* JValFact::mkBoolean(bool v) {
608 BaBool b = v ? TRUE : FALSE;
609 return JValFact_mkBoolean(this, b); }
611 return JValFact_mkNull(this); }
613 return JValFact_mkObject(this); }
615 return JValFact_mkArray(this); }
616#endif
617 /* end of JSONRef */
619
620#endif
JParserValFact(AllocatorIntf *vAlloc, AllocatorIntf *dAlloc)
create a JParserValFact JVal factory instance.
Definition: JVal.h:512
JVal * manageFirstVal()
Similar to getFirstVal, but you must manage the JVal tree as the value is detached from the JParserVa...
Definition: JVal.h:517
~JParserValFact()
The destructor terminates all nodes not managed.
Definition: JVal.h:521
void termFirstVal()
Terminate the syntax tree such that the JParserValFact instance can be reused when the JParser instan...
Definition: JVal.h:519
JVal * getFirstVal()
Returns the root of the JVal syntax tree.
Definition: JVal.h:515
const char * getName()
Returns the member name if this value is part of a JSON object.
Definition: JVal.h:386
void setLong(JErr *e, S64 v)
Sets a new integer value or changes the JSON type and sets the integer value.
Definition: JVal.h:407
JVal * mkDouble(double v)
Make a float.
Definition: JVal.h:601
char * manageString(JErr *e)
Similar to getString, but you must manage the value as the value is detached from the tree.
Definition: JVal.h:384
JVal * mkLong(S64 v)
Make a long integer.
Definition: JVal.h:605
JVal * mkInt(S32 v)
Make an integer.
Definition: JVal.h:603
JVal * mkBoolean(bool v)
Make a boolean.
Definition: JVal.h:607
int addMember(JErr *e, const char *memberName, JVal *child, AllocatorIntf *dAlloc)
Add a child to an object.
Definition: JVal.h:421
void setString(JErr *e, char *v)
Sets a string value and changes the JSON type if needed.
Definition: JVal.h:415
void terminate(AllocatorIntf *vAlloc, AllocatorIntf *dAlloc)
Terminate the node and all sub nodes.
Definition: JVal.h:426
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:374
bool isObjectMember()
Returns true if this is a child element in an object.
Definition: JVal.h:417
JVal * getArray(JErr *e)
Returns the first child if an array.
Definition: JVal.h:396
JVal * getNextElem()
Returns the next element if the parent is an object or an array.
Definition: JVal.h:392
JVType
The JSON types.
Definition: JParser.h:103
JVal * mkNull()
Make a null value.
Definition: JVal.h:610
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:400
JVal * getObject(JErr *e)
Returns the first child if an object.
Definition: JVal.h:394
JVal * getJ(JErr *e)
Returns the first child if an array or object.
Definition: JVal.h:398
size_t getNameLen()
Returns the member-name length.
Definition: JVal.h:388
double getDouble(JErr *e)
Returns the double value for a JVal float or attempts to convert the value to a float.
Definition: JVal.h:376
BaBool getBoolean(JErr *e)
Returns the boolean value for a boolean JVal type or false if the JVal is JVType_Null.
Definition: JVal.h:378
JVal * mkString(const char *v)
Make a string.
Definition: JVal.h:599
JVal * get(JErr *err, const char *fmt,...)
Get any type of value(s) from a JVal node or JVal tree.
Definition: JVal.h:365
JVal * mkArray()
Make a JSON array.
Definition: JVal.h:614
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:372
JVType getType()
Returns the JSON type.
Definition: JVal.h:361
JVal * mkObject()
Make a JSON object.
Definition: JVal.h:612
JVal * vget(JErr *err, const char **fmt, va_list *argList)
Equivalent to get with variable argument list replaced by argList.
Definition: JVal.h:363
size_t getStringLen()
Returns the string length.
Definition: JVal.h:382
char * manageName()
Similar to getName, but you must manage the value as the value is detached from the tree.
Definition: JVal.h:390
int add(JErr *e, JVal *child)
Add a child to an array.
Definition: JVal.h:424
S32 getLength(JErr *e)
Returns the elements left in the list.
Definition: JVal.h:402
void setBoolean(JErr *e, BaBool v)
Sets a new boolean value or changes the JSON type and sets the boolean value.
Definition: JVal.h:411
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:409
int unlink(JVal *child)
Remove a child.
Definition: JVal.h:419
void setNull(JErr *e)
Changes the JSON type if not NULL.
Definition: JVal.h:413
const char * getString(JErr *e)
Returns the string as a const or returns NULL if the JVAL is a NULL type.
Definition: JVal.h:380
JValFact(AllocatorIntf *vAlloc, AllocatorIntf *dAlloc)
create a JValFact JVal factory instance.
Definition: JVal.h:597
void setInt(JErr *e, S32 v)
Sets a new integer value or changes the JSON type and sets the integer value.
Definition: JVal.h:405
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:461
The JValFact enables one to manually create a JVal syntax tree or add nodes to an existing syntax tre...
Definition: JVal.h:537
JVal represents a value in a JSON tree.
Definition: JVal.h:73