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 4915 2021-12-01 18:26:55Z 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 
72 struct JVal
73 {
74 #ifdef __cplusplus
75 
77  JVType getType();
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 
313 typedef struct JVal JVal;
314 
315 #ifdef __cplusplus
316 extern "C" {
317 #endif
318 #define JVal_getType(o) (o)->type
319 BA_API JVal* JVal_vget(JVal* o,JErr* err,const char** fmt, va_list* argList);
320 BA_API JVal* JVal_get(JVal* o, JErr* err, const char* fmt, ...);
321 BA_API S32 JVal_getInt(JVal* o, JErr* e);
322 BA_API S64 JVal_getLong(JVal* o, JErr* e);
323 BA_API double JVal_getDouble(JVal* o, JErr* e);
324 BA_API BaBool JVal_getBoolean(JVal* o, JErr* e);
325 BA_API const char* JVal_getString(JVal* o, JErr* e);
326 BA_API char* JVal_manageString(JVal* o, JErr* e);
327 BA_API const char* JVal_getName(JVal* o);
328 BA_API char* JVal_manageName(JVal* o);
329 #define JVal_getNextElem(o) (o)->next
330 BA_API JVal* JVal_getObject(JVal* o, JErr* e);
331 BA_API JVal* JVal_getArray(JVal* o, JErr* e);
332 BA_API JVal* JVal_getJ(JVal* o, JErr* e);
333 BA_API JVal* JVal_manageJ(JVal* o, JErr* e);
334 BA_API S32 JVal_getLength(struct JVal* o, JErr* e);
335 #define JVal_isObjectMember(o) ((o)->memberName != 0)
336 BA_API int JVal_unlink(JVal* o, JVal* child);
337 BA_API int JVal_addMember(JVal* o, JErr* e, const char* memberName,
338  JVal* child, AllocatorIntf* dAlloc);
339 BA_API int JVal_add(JVal* o, JErr* e, JVal* child);
340 BA_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)
348 BA_API void JVal_setX(JVal* o, JErr* e, JVType t, void* v);
349 #ifdef __cplusplus
350 }
352  return JVal_getType(this); }
353 inline JVal* JVal::vget(JErr* err,const char** fmt, va_list* argList){
354  return JVal_vget(this,err,fmt, argList); }
355 inline 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 }
362 inline S32 JVal::getInt(JErr* e){
363  return JVal_getInt(this, e); }
364 inline S64 JVal::getLong(JErr* e){
365  return JVal_getLong(this, e); }
366 inline double JVal::getDouble(JErr* e){
367  return JVal_getDouble(this, e); }
368 inline BaBool JVal::getBoolean(JErr* e){
369  return JVal_getBoolean(this, e); }
370 inline const char* JVal::getString(JErr* e){
371  return JVal_getString(this, e); }
372 inline char* JVal::manageString(JErr* e){
373  return JVal_manageString(this, e); }
374 inline const char* JVal::getName(){
375  return JVal_getName(this); }
376 inline 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); }
384 inline JVal* JVal::getJ(JErr* e){
385  return JVal_getJ(this, e); }
386 inline JVal* JVal::manageJ(JErr* e){
387  return JVal_manageJ(this, e); }
388 inline S32 JVal::getLength(JErr* e){
389  return JVal_getLength(this, e); }
390 
391 inline void JVal::setInt(JErr* e,S32 v) {
392  JVal_setInt(this, e, v); }
393 inline void JVal::setLong(JErr* e,S64 v) {
394  JVal_setLong(this, e, v); }
395 inline void JVal::setDouble(JErr* e,double v) {
396  JVal_setDouble(this, e, v); }
397 inline void JVal::setBoolean(JErr* e,BaBool v) {
398  JVal_setBoolean(this, e, v); }
399 inline void JVal::setNull(JErr* e) {
400  JVal_setNull(this, e); }
401 inline void JVal::setString(JErr* e, char* v) {
402  JVal_setString(this, e, v); }
403 inline bool JVal::isObjectMember(){
404  return JVal_isObjectMember(this) ? true : false; }
405 inline int JVal::unlink(JVal* child){
406  return JVal_unlink(this, child); }
407 inline int JVal::addMember(JErr* e, const char* memberName,
408  JVal* child, AllocatorIntf* dAlloc) {
409  return JVal_addMember(this, e, memberName, child, dAlloc); }
410 inline int JVal::add(JErr* e, JVal* child) {
411  return JVal_add(this, e, child); }
412 inline void JVal::terminate(AllocatorIntf* vAlloc, AllocatorIntf* dAlloc){
413  JVal_terminate(this, vAlloc, dAlloc); }
414 #endif
415  /* end of JSONRef */
417 
422 typedef enum
423 {
424  JParserValFactStat_OK=0,
425  JParserValFactStat_DMemErr,
426  JParserValFactStat_VMemErr,
427  JParserValFactStat_MaxNodes
428 } JParserValFactStat;
429 
445 #ifdef __cplusplus
446 typedef struct JParserValFact : public JParserIntf
447 {
453  JParserValFact(AllocatorIntf* vAlloc, AllocatorIntf* dAlloc);
454 
457  ~JParserValFact();
458 
461  JVal* getFirstVal();
462 
466  JVal* manageFirstVal();
467 
472  void termFirstVal();
473 #else
474 typedef 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
487 extern "C" {
488 #endif
489 BA_API void JParserValFact_constructor(
490  JParserValFact* o, AllocatorIntf* vAlloc, AllocatorIntf* dAlloc);
491 #define JParserValFact_getFirstVal(o) \
492  ((o)->vStack && *(o)->vStack ? *(o)->vStack : 0)
493 BA_API JVal* JParserValFact_manageFirstVal(JParserValFact* o);
494 BA_API void JParserValFact_termFirstVal(JParserValFact* o);
495 BA_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 
522 typedef struct JValFact
523 {
524 #ifdef __cplusplus
525 
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
568 extern "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)
578 BA_API void JValFact_constructor(
579  JValFact* o, AllocatorIntf* vAlloc, AllocatorIntf* dAlloc);
580 BA_API JVal* JValFact_mkVal(JValFact* o, JVType t, const void* uv);
581 #ifdef __cplusplus
582 }
584  JValFact_constructor(this,vAlloc, dAlloc); }
585 inline JVal* JValFact::mkString(const char* v) {
586  return JValFact_mkString(this, v); }
587 inline JVal* JValFact::mkDouble(double v) {
588  return JValFact_mkDouble(this, v); }
589 inline JVal* JValFact::mkInt(S32 v) {
590  return JValFact_mkInt(this, v); }
591 inline JVal* JValFact::mkLong(S64 v) {
592  return JValFact_mkLong(this, v); }
593 inline 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
JVal::setBoolean
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
JValFact::mkObject
JVal * mkObject()
Make a JSON object.
Definition: JVal.h:598
JVal::vget
JVal * vget(JErr *err, const char **fmt, va_list *argList)
Equivalent to get with variable argument list replaced by argList.
Definition: JVal.h:353
AllocatorIntf
Memory allocation and deallocation Interface class.
Definition: AllocatorIntf.h:83
JVal::getLong
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
JVal::getName
const char * getName()
Returns the member name if this value is part of a JSON object.
Definition: JVal.h:374
JVal::addMember
int addMember(JErr *e, const char *memberName, JVal *child, AllocatorIntf *dAlloc)
Add a child to an object.
Definition: JVal.h:407
JVal::isObjectMember
bool isObjectMember()
Returns true if this is a child element in an object.
Definition: JVal.h:403
JVal::terminate
void terminate(AllocatorIntf *vAlloc, AllocatorIntf *dAlloc)
Terminate the node and all sub nodes.
Definition: JVal.h:412
JValFact::JValFact
JValFact(AllocatorIntf *vAlloc, AllocatorIntf *dAlloc)
create a JValFact JVal factory instance.
Definition: JVal.h:583
JVal::manageJ
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
JParserValFact::termFirstVal
void termFirstVal()
Terminate the syntax tree such that the JParserValFact instance can be reused when the JParser instan...
Definition: JVal.h:505
JParserIntf
The JParserIntf interface class is the interface between the parser and an object that implements the...
Definition: JParser.h:65
JVal::get
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::setDouble
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
JVal::setLong
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
JVal represents a value in a JSON tree.
Definition: JVal.h:73
JValFact::mkLong
JVal * mkLong(S64 v)
Make a long integer.
Definition: JVal.h:591
JParserValFact::~JParserValFact
~JParserValFact()
The destructor terminates all nodes not managed.
Definition: JVal.h:507
JValFact::mkArray
JVal * mkArray()
Make a JSON array.
Definition: JVal.h:600
JParserValFact::getFirstVal
JVal * getFirstVal()
Returns the root of the JVal syntax tree.
Definition: JVal.h:501
JValFact
The JValFact enables one to manually create a JVal syntax tree or add nodes to an existing syntax tre...
Definition: JVal.h:523
JVal::getType
JVType getType()
Returns the JSON type.
Definition: JVal.h:351
JParserValFact::JParserValFact
JParserValFact(AllocatorIntf *vAlloc, AllocatorIntf *dAlloc)
create a JParserValFact JVal factory instance.
Definition: JVal.h:498
JVal::getBoolean
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::getDouble
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
JValFact::mkString
JVal * mkString(const char *v)
Make a string.
Definition: JVal.h:585
JVal::getString
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
JVal::add
int add(JErr *e, JVal *child)
Add a child to an array.
Definition: JVal.h:410
JValFact::mkBoolean
JVal * mkBoolean(bool v)
Make a boolean.
Definition: JVal.h:593
JVal::getObject
JVal * getObject(JErr *e)
Returns the first child if an object.
Definition: JVal.h:380
JParserValFact::manageFirstVal
JVal * manageFirstVal()
Similar to getFirstVal, but you must manage the JVal tree as the value is detached from the JParserVa...
Definition: JVal.h:503
JVal::getArray
JVal * getArray(JErr *e)
Returns the first child if an array.
Definition: JVal.h:382
JVal::manageName
char * manageName()
Similar to getName, but you must manage the value as the value is detached from the tree.
Definition: JVal.h:376
JValFact
struct JValFact JValFact
The JValFact enables one to manually create a JVal syntax tree or add nodes to an existing syntax tre...
JVal::getNextElem
JVal * getNextElem()
Returns the next element if the parent is an object or an array.
Definition: JVal.h:378
JErr
The JSON error container object.
Definition: JParser.h:155
JVal::setNull
void setNull(JErr *e)
Changes the JSON type if not NULL.
Definition: JVal.h:399
JVal::getLength
S32 getLength(JErr *e)
Returns the elements left in the list.
Definition: JVal.h:388
JVal::setInt
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
JValFact::mkInt
JVal * mkInt(S32 v)
Make an integer.
Definition: JVal.h:589
JVType
JVType
The JSON types.
Definition: JParser.h:103
JValFact::mkDouble
JVal * mkDouble(double v)
Make a float.
Definition: JVal.h:587
JVal::setString
void setString(JErr *e, char *v)
Sets a string value and changes the JSON type if needed.
Definition: JVal.h:401
JVal::manageString
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
JValFact::mkNull
JVal * mkNull()
Make a null value.
Definition: JVal.h:596
JVal::getInt
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
JVal::unlink
int unlink(JVal *child)
Remove a child.
Definition: JVal.h:405
JVal::getJ
JVal * getJ(JErr *e)
Returns the first child if an array or object.
Definition: JVal.h:384
JParserValFact
JParserValFact is the JVal JSON parser factory class.
Definition: JVal.h:447