GClasses
|
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>
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. | |
GDomNode * | root () |
Gets the root document node. | |
GDomNode * | setRoot (GDomNode *pNode) |
Sets the root document node. (Returns the same node that you pass in.) | |
GDomNode * | newObj () |
Makes a new object node. | |
GDomNode * | newList () |
Makes a new list node. | |
GDomNode * | newNull () |
Makes a new node to represent a null value. | |
GDomNode * | newBool (bool b) |
Makes a new boolean node. | |
GDomNode * | newInt (long long n) |
Makes a new integer node. | |
GDomNode * | newDouble (double d) |
Makes a new double node. | |
GDomNode * | newString (const char *szString) |
Makes a new string node from a null-terminated string. | |
GDomNode * | newString (const char *pString, size_t len) |
Makes a new string node from the specified string segment. | |
GHeap * | heap () |
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 () |
GDomNode * | loadJsonObject (GTokenizer &tok) |
GDomNode * | loadJsonArray (GTokenizer &tok) |
GDomNode * | loadJsonNumber (GTokenizer &tok) |
GDomNode * | loadJsonValue (GTokenizer &tok) |
Protected Attributes | |
GHeap | m_heap |
GDomNode * | m_pRoot |
int | m_line |
size_t | m_len |
const char * | m_pDoc |
Friends | |
class | GDomNode |
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.
GClasses::GDom::GDom | ( | ) | [inline] |
GClasses::GDom::~GDom | ( | ) | [inline] |
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.)
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.
friend class GDomNode [friend] |
GHeap GClasses::GDom::m_heap [protected] |
size_t GClasses::GDom::m_len [protected] |
int GClasses::GDom::m_line [protected] |
const char* GClasses::GDom::m_pDoc [protected] |
GDomNode* GClasses::GDom::m_pRoot [protected] |