Rudiments
Public Member Functions | Protected Member Functions | List of all members
jsondom Class Reference

#include <jsondom.h>

Inherits jsonsax, and dom.

Public Member Functions

 jsondom ()
 
 jsondom (bool stringcacheenabled)
 
virtual ~jsondom ()
 
virtual const chargetType ()
 
bool parse (input *in)
 
bool parseFile (const char *filename)
 
bool parseString (const char *string)
 
void createRootNode ()
 
- Public Member Functions inherited from jsonsax
 jsonsax ()
 
virtual ~jsonsax ()
 
- Public Member Functions inherited from sax
 sax ()
 
virtual ~sax ()
 
void setIgnoreHeaderLines (uint64_t lines)
 
uint64_t getIgnoreHeaderLines ()
 
void setIgnoreFooterLines (uint64_t lines)
 
uint64_t getIgnoreFooterLines ()
 
const chargetError ()
 
- Public Member Functions inherited from object
virtual ~object ()
 
- Public Member Functions inherited from dom
 dom ()
 
 dom (bool stringcacheenabled)
 
virtual ~dom ()
 
virtual domnodegetRootNode ()
 
virtual domnodegetNullNode ()
 
virtual ssize_t writeFile (const char *filename, mode_t perms)
 
virtual ssize_t writeFile (const char *filename, mode_t perms, bool indent)
 
virtual ssize_t write ()
 
virtual ssize_t write (bool indent)
 
virtual ssize_t write (output *out)
 
virtual ssize_t write (output *out, bool indent)
 
virtual ssize_t writeXml ()
 
virtual ssize_t writeXml (bool indent)
 
virtual ssize_t writeXml (output *out)
 
virtual ssize_t writeXml (output *out, bool indent)
 
bool getStringCacheEnabled ()
 
- Public Member Functions inherited from collection
 collection ()
 
 collection (collection &c)
 
collectionoperator= (collection &c)
 
virtual ~collection ()
 
virtual uint64_t getCount ()=0
 
comparatorgetComparator ()
 
void setComparator (comparator *newcomp)
 
virtual bool isReadOnly ()
 
virtual bool isBlockBased ()
 
virtual uint64_t getBlockSize ()
 
virtual bool isSequentialAccess ()
 
virtual void setManageValues (bool manage)
 
virtual bool getManageValues ()
 
virtual void setManageArrayValues (bool manage)
 
virtual bool getManageArrayValues ()
 
virtual void setManageKeys (bool manage)
 
virtual bool getManageKeys ()
 
virtual void setManageArrayKeys (bool manage)
 
virtual bool getManageArrayKeys ()
 
virtual bool clear ()=0
 
virtual ssize_t writeJson ()=0
 
virtual ssize_t writeJson (bool indent)=0
 
virtual ssize_t writeJson (output *out)=0
 
virtual ssize_t writeJson (output *out, bool indent)=0
 

Protected Member Functions

virtual bool objectStart ()
 
virtual bool memberStart ()
 
virtual bool memberName (const char *name)
 
virtual bool valueStart ()
 
virtual bool stringValue (const char *value)
 
virtual bool numberValue (const char *value)
 
virtual bool trueValue ()
 
virtual bool falseValue ()
 
virtual bool nullValue ()
 
virtual bool arrayStart ()
 
virtual bool arrayEnd ()
 
virtual bool valueEnd ()
 
virtual bool memberEnd ()
 
virtual bool objectEnd ()
 

Detailed Description

The jsondom class implements a minimal JSON DOM parser.

It parses a file or string of JSON-formatted data and produces a dom tree representing the data. It creates an "r" element for the root, named elements for each object or array, and "v" elements for each array value. It adds a "t" attribute to each object, indicating the type: "o" for standard object, "a" for array, "s" for string, "n" for number, "t" for true, "f" for false, and "u" for null. It also adds a "v" attribute to each string or number object, containing the value.

For example, the following JSON:

{ string_object: "string value 1", number_object: 10, true_object: true, false_object: false, null_object: null, composite_object: { string_member: "string value", number_member: 10, true_member: true, false_member: false, null_member: null nested_composite_object: { string_member: "string value", number_member: 10, true_member: true, false_member: false, null_member: null } }, array_object: ["string value", 10, true, false, null] }

would produce the following dom tree:

<r t="o"> <string_object t="s" v="string value 1"> <number_object t="n" v="10"> <true_object t="t"> <false_object t="f"> <null_object t="u"> <composite_object t="o"> <string_member t="s" v="string value"> <number_member t="n" v="10"> <true_member t="t"> <false_member t="f"> <null_member t="u"> <nested_composite_object t="o"> <string_member t="s" v="string value"> <number_member t="n" v="10"> <true_member t="t"> <false_member t="f"> <null_member t="u"> <array_object t="a"> <v t="s" v="string value"> <v t="n" v="10"> <v t="t"> <v t="f"> <v t="u"> </array_object> </nested_composite_object> </composite_object> </r>

Constructor & Destructor Documentation

◆ jsondom() [1/2]

jsondom::jsondom ( )

Creates a new instance of the jsondom class.

◆ jsondom() [2/2]

jsondom::jsondom ( bool stringcacheenabled)

Creates a new instance of the jsondom class, allowing the user to enable or disable the "string cache" for this instance.

By default, as each domnode is added to the jsondom tree, tag and attribute names and values are stored in a string cache and pointers into the cache are assigned to each node. Reference counters are kept and the string is removed from the cache when no more nodes are using it. If the data is highly repetitive this conserves memory at the cost of speed.

If the string cache is disabled then memory is allocated in each domnode for names and values and freed when the domnode is freed. This is faster but uses much more memory.

◆ ~jsondom()

virtual jsondom::~jsondom ( )
virtual

Deletes this instance of the jsondom class.

Member Function Documentation

◆ arrayEnd()

virtual bool jsondom::arrayEnd ( )
protectedvirtual

Gets called when an array end is parsed.

Reimplemented from jsonsax.

◆ arrayStart()

virtual bool jsondom::arrayStart ( )
protectedvirtual

Gets called when an array start is parsed.

Reimplemented from jsonsax.

◆ createRootNode()

void jsondom::createRootNode ( )
virtual

Creates a new root node. This is useful for building a tree from scratch.

Reimplemented from dom.

◆ falseValue()

virtual bool jsondom::falseValue ( )
protectedvirtual

Gets called when a false value is parsed.

Reimplemented from jsonsax.

◆ getType()

virtual const char * jsondom::getType ( )
virtual

Returns "jsondom".

Reimplemented from dom.

◆ memberEnd()

virtual bool jsondom::memberEnd ( )
protectedvirtual

Gets called when a member end is parsed.

Reimplemented from jsonsax.

◆ memberName()

virtual bool jsondom::memberName ( const char * name)
protectedvirtual

Gets called when a member name is parsed.

Reimplemented from jsonsax.

◆ memberStart()

virtual bool jsondom::memberStart ( )
protectedvirtual

Gets called when a member start is parsed.

Reimplemented from jsonsax.

◆ nullValue()

virtual bool jsondom::nullValue ( )
protectedvirtual

Gets called when a null value is parsed.

Reimplemented from jsonsax.

◆ numberValue()

virtual bool jsondom::numberValue ( const char * value)
protectedvirtual

Gets called when a number value is parsed.

Reimplemented from jsonsax.

◆ objectEnd()

virtual bool jsondom::objectEnd ( )
protectedvirtual

Gets called when an object end is parsed.

Reimplemented from jsonsax.

◆ objectStart()

virtual bool jsondom::objectStart ( )
protectedvirtual

Gets called when an object start is parsed.

Reimplemented from jsonsax.

◆ parse()

bool jsondom::parse ( input * in)
virtual

Parses generic input "in" and generates a DOM tree.

Reimplemented from sax.

◆ parseFile()

bool jsondom::parseFile ( const char * filename)
virtual

Parses file "filename" and generates a DOM tree.

Reimplemented from sax.

◆ parseString()

bool jsondom::parseString ( const char * string)
virtual

Parses string "string" and generates a DOM tree.

Reimplemented from sax.

◆ stringValue()

virtual bool jsondom::stringValue ( const char * value)
protectedvirtual

Gets called when a string value is parsed.

Reimplemented from jsonsax.

◆ trueValue()

virtual bool jsondom::trueValue ( )
protectedvirtual

Gets called when a true value is parsed.

Reimplemented from jsonsax.

◆ valueEnd()

virtual bool jsondom::valueEnd ( )
protectedvirtual

Gets called when an value end is parsed.

Reimplemented from jsonsax.

◆ valueStart()

virtual bool jsondom::valueStart ( )
protectedvirtual

Gets called when a value start is parsed.

Reimplemented from jsonsax.