GClasses
GClasses::GDom Class Reference

A Document Object Model. This represents a document as a hierarchy of objects. The DOM can be loaded-from or saved-to a file in JSON (JavaScript Object Notation) format. (See http://json.org.) In the future, support for XML and/or other formats may be added. More...

#include <GDom.h>

List of all members.

Public Member Functions

 GDom ()
 ~GDom ()
void clear ()
 Clears the DOM.
GHeapheap ()
 Returns a pointer to the heap used by this doc.
void loadJson (const char *szFilename)
 Load from the specified file in JSON format. (See http://json.org.)
GDomNodenewBool (bool b)
 Makes a new boolean node.
GDomNodenewDouble (double d)
 Makes a new double node.
GDomNodenewInt (long long n)
 Makes a new integer node.
GDomNodenewList ()
 Makes a new list node.
GDomNodenewNull ()
 Makes a new node to represent a null value.
GDomNodenewObj ()
 Makes a new object node.
GDomNodenewString (const char *szString)
 Makes a new string node from a null-terminated string. (If you want to parse a JSON string, call parseJson instead. This method just wraps the string in a node.)
GDomNodenewString (const char *pString, size_t len)
 Makes a new string node from the specified string segment.
void parseJson (const char *pJsonString, size_t len)
 Parses a JSON string. The resulting DOM can be retrieved by calling root().
GDomNoderoot () const
 Gets the root document node.
void saveJson (const char *szFilename) const
 Saves to a file in JSON format. (See http://json.org.)
GDomNodesetRoot (GDomNode *pNode)
 Sets the root document node. (Returns the same node that you pass in.)
void writeJson (std::ostream &stream) const
 Writes this doc to the specified stream in JSON format. (See http://json.org.) (If you want to write to a memory buffer, you can use open_memstream.)
void writeJsonCpp (std::ostream &stream) const
 Writes this doc to the specified stream as an inlined C++ string in JSON format. (This method would be useful for hard-coding a serialized object in a C++ program.)
void writeJsonPretty (std::ostream &stream) const
 Writes this doc to the specified stream in JSON format with indentation to make it human-readable. (If you want to write to a memory buffer, you can use open_memstream.)
void writeXml (std::ostream &stream) const
 Write as XML to the specified stream.

Static Public Member Functions

static void test ()
 Performs unit tests for this class. Throws an exception if there is a failure.

Protected Member Functions

GDomNodeloadJsonArray (GJsonTokenizer &tok)
GDomNodeloadJsonNumber (GJsonTokenizer &tok)
GDomNodeloadJsonObject (GJsonTokenizer &tok)
char * loadJsonString (GJsonTokenizer &tok)
GDomNodeloadJsonValue (GJsonTokenizer &tok)
GDomObjField * newField ()
GDomListItem * newItem ()

Protected Attributes

GHeap m_heap
size_t m_len
int m_line
const char * m_pDoc
GDomNodem_pRoot

Friends

class GDomNode

Detailed Description

A Document Object Model. This represents a document as a hierarchy of objects. The DOM can be loaded-from or saved-to a file in JSON (JavaScript Object Notation) format. (See http://json.org.) In the future, support for XML and/or other formats may be added.


Constructor & Destructor Documentation


Member Function Documentation

Clears the DOM.

GHeap* GClasses::GDom::heap ( ) [inline]

Returns a pointer to the heap used by this doc.

void GClasses::GDom::loadJson ( const char *  szFilename)

Load from the specified file in JSON format. (See http://json.org.)

GDomNode* GClasses::GDom::loadJsonArray ( GJsonTokenizer &  tok) [protected]
GDomNode* GClasses::GDom::loadJsonNumber ( GJsonTokenizer &  tok) [protected]
GDomNode* GClasses::GDom::loadJsonObject ( GJsonTokenizer &  tok) [protected]
char* GClasses::GDom::loadJsonString ( GJsonTokenizer &  tok) [protected]
GDomNode* GClasses::GDom::loadJsonValue ( GJsonTokenizer &  tok) [protected]

Makes a new boolean node.

Makes a new double node.

GDomObjField* GClasses::GDom::newField ( ) [protected]
GDomNode* GClasses::GDom::newInt ( long long  n)

Makes a new integer node.

GDomListItem* GClasses::GDom::newItem ( ) [protected]

Makes a new list node.

Makes a new node to represent a null value.

Makes a new object node.

GDomNode* GClasses::GDom::newString ( const char *  szString)

Makes a new string node from a null-terminated string. (If you want to parse a JSON string, call parseJson instead. This method just wraps the string in a node.)

GDomNode* GClasses::GDom::newString ( const char *  pString,
size_t  len 
)

Makes a new string node from the specified string segment.

void GClasses::GDom::parseJson ( const char *  pJsonString,
size_t  len 
)

Parses a JSON string. The resulting DOM can be retrieved by calling root().

GDomNode* GClasses::GDom::root ( ) const [inline]

Gets the root document node.

void GClasses::GDom::saveJson ( const char *  szFilename) const

Saves to a file in JSON format. (See http://json.org.)

GDomNode* GClasses::GDom::setRoot ( GDomNode pNode) [inline]

Sets the root document node. (Returns the same node that you pass in.)

static void GClasses::GDom::test ( ) [static]

Performs unit tests for this class. Throws an exception if there is a failure.

void GClasses::GDom::writeJson ( std::ostream &  stream) const

Writes this doc to the specified stream in JSON format. (See http://json.org.) (If you want to write to a memory buffer, you can use open_memstream.)

void GClasses::GDom::writeJsonCpp ( std::ostream &  stream) const

Writes this doc to the specified stream as an inlined C++ string in JSON format. (This method would be useful for hard-coding a serialized object in a C++ program.)

void GClasses::GDom::writeJsonPretty ( std::ostream &  stream) const

Writes this doc to the specified stream in JSON format with indentation to make it human-readable. (If you want to write to a memory buffer, you can use open_memstream.)

void GClasses::GDom::writeXml ( std::ostream &  stream) const

Write as XML to the specified stream.


Friends And Related Function Documentation

friend class GDomNode [friend]

Member Data Documentation

size_t GClasses::GDom::m_len [protected]
int GClasses::GDom::m_line [protected]
const char* GClasses::GDom::m_pDoc [protected]