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 loadJson (const char *szFilename)
 Load from the specified file in JSON format. (See http://json.org.)
void saveJson (const char *szFilename)
 Saves to a file in JSON format. (See http://json.org.)
void parseJson (GTokenizer &tok)
 Parses JSON format from a tokenizer (which wraps a stream).
void writeJson (std::ostream &stream)
 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)
 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 writeXml (std::ostream &stream)
 Write as XML to the specified stream.
GDomNoderoot ()
 Gets the root document node.
GDomNodesetRoot (GDomNode *pNode)
 Sets the root document node. (Returns the same node that you pass in.)
GDomNodenewObj ()
 Makes a new object node.
GDomNodenewList ()
 Makes a new list node.
GDomNodenewNull ()
 Makes a new node to represent a null value.
GDomNodenewBool (bool b)
 Makes a new boolean node.
GDomNodenewInt (long long n)
 Makes a new integer node.
GDomNodenewDouble (double d)
 Makes a new double node.
GDomNodenewString (const char *szString)
 Makes a new string node from a null-terminated string.
GDomNodenewString (const char *pString, size_t len)
 Makes a new string node from the specified string segment.
GHeapheap ()
 Returns a pointer to the heap used by this doc.

Static Public Member Functions

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

Protected Member Functions

GDomObjField * newField ()
GDomListItem * newItem ()
GDomNodeloadJsonObject (GTokenizer &tok)
GDomNodeloadJsonArray (GTokenizer &tok)
GDomNodeloadJsonNumber (GTokenizer &tok)
GDomNodeloadJsonValue (GTokenizer &tok)

Protected Attributes

GHeap m_heap
GDomNodem_pRoot
int m_line
size_t m_len
const char * m_pDoc

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

GClasses::GDom::GDom ( ) [inline]
GClasses::GDom::~GDom ( ) [inline]

Member Function Documentation

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 ( GTokenizer tok) [protected]
GDomNode* GClasses::GDom::loadJsonNumber ( GTokenizer tok) [protected]
GDomNode* GClasses::GDom::loadJsonObject ( GTokenizer tok) [protected]
GDomNode* GClasses::GDom::loadJsonValue ( GTokenizer tok) [protected]
GDomNode* GClasses::GDom::newBool ( bool  b)

Makes a new boolean node.

GDomNode* GClasses::GDom::newDouble ( double  d)

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]
GDomNode* GClasses::GDom::newList ( )

Makes a new list node.

GDomNode* GClasses::GDom::newNull ( )

Makes a new node to represent a null value.

GDomNode* GClasses::GDom::newObj ( )

Makes a new object node.

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

Makes a new string node from the specified string segment.

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

Makes a new string node from a null-terminated string.

void GClasses::GDom::parseJson ( GTokenizer tok)

Parses JSON format from a tokenizer (which wraps a stream).

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

Gets the root document node.

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

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)

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)

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::writeXml ( std::ostream &  stream)

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]