EpcTools
An event based multi-threaded C++ development framework.
Classes | Public Types | Public Member Functions | List of all members
EJsonBuilder Class Reference

A class used to build JSON strings. It maintains a stack of JSON objects which allows you to build a hierarchy of items. New objects are added to the scope of the current object (i.e. the top of the stack). It provides methods to push and pop objects from the stack and helper classes to automatically manage the stack. More...

#include <ejsonbuilder.h>

Classes

class  StackContainer
 A helper class which pushes/pops items on the builder's object stack based on its lifetime. More...
 
class  StackValue
 A helper class which pushes/pops items on the builder's object stack based on its lifetime. More...
 

Public Types

enum  ContainerType { ContainerType::Array, ContainerType::Object }
 Enumeration for JSON containers types. More...
 
using StackString = StackValue< EString >
 
using StackUInt = StackValue< UInt >
 
using StackBool = StackValue< Bool >
 
using StackArray = StackContainer< ContainerType::Array >
 
using StackObject = StackContainer< ContainerType::Object >
 

Public Member Functions

 EJsonBuilder ()
 Constructor. Initializes the document object used to contain all appended JSON objects. More...
 
 ~EJsonBuilder ()
 Destructor. More...
 
Void push (ContainerType type)
 Pushes a container type object onto the stack. More...
 
Void push (const EString &value)
 Pushes a string object onto the stack. More...
 
Void push (const UInt value)
 Pushes an unsigned integer value onto the stack. More...
 
Void pop (const EString &name="")
 Pops the top object off the stack. More...
 
cpStr toString (Bool pretty=false)
 Returns a string representation of the json objects. More...
 

Detailed Description

A class used to build JSON strings. It maintains a stack of JSON objects which allows you to build a hierarchy of items. New objects are added to the scope of the current object (i.e. the top of the stack). It provides methods to push and pop objects from the stack and helper classes to automatically manage the stack.

Member Typedef Documentation

Member Enumeration Documentation

Enumeration for JSON containers types.

Enumerator
Array 

an array type []

Object 

an object type with name/values {}

Constructor & Destructor Documentation

EJsonBuilder::EJsonBuilder ( )

Constructor. Initializes the document object used to contain all appended JSON objects.

EJsonBuilder::~EJsonBuilder ( )
default

Destructor.

Member Function Documentation

Void EJsonBuilder::pop ( const EString name = "")

Pops the top object off the stack.

Parameters
namethe name to use when adding this object to a container object on the stack. If the current container object is an array, then the name shall be empty, otherwise, it is required to be non-empty.
Exceptions
EJsonBuilder_EmptyStack
EJsonBuilder_NonEmptyName
EJsonBuilder_EmptyName
Void EJsonBuilder::push ( ContainerType  type)

Pushes a container type object onto the stack.

Parameters
typethe type of container object to push
Exceptions
EJsonBuilder_UnrecognizedType
Void EJsonBuilder::push ( const EString value)

Pushes a string object onto the stack.

Parameters
valuethe value of the string object
Void EJsonBuilder::push ( const UInt  value)

Pushes an unsigned integer value onto the stack.

Parameters
valuethe value of the unsigned integer object
cpStr EJsonBuilder::toString ( Bool  pretty = false)

Returns a string representation of the json objects.

Parameters
prettycontrols whether pretty printing is used
Returns
a constant pointer to the character buffer held by this object
Exceptions
EJsonBuilder_NonEmptyStack

The documentation for this class was generated from the following files: