|
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.
#include <GDom.h>
Public Member Functions | |
| GDom () | |
| ~GDom () | |
| void | clear () |
| Clears the DOM. More... | |
| GHeap * | heap () |
| Returns a pointer to the heap used by this doc. More... | |
| void | loadJson (const char *szFilename) |
| Load from the specified file in JSON format. (See http://json.org.) More... | |
| GDomNode * | newBool (bool b) |
| Makes a new boolean node. More... | |
| GDomNode * | newDouble (double d) |
| Makes a new double node. More... | |
| GDomNode * | newInt (long long n) |
| Makes a new integer node. More... | |
| GDomNode * | newList () |
| Makes a new list node. More... | |
| GDomNode * | newNull () |
| Makes a new node to represent a null value. More... | |
| GDomNode * | newObj () |
| Makes a new object node. More... | |
| GDomNode * | 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.) More... | |
| GDomNode * | newString (const char *pString, size_t len) |
| Makes a new string node from the specified string segment. More... | |
| void | parseJson (const char *pJsonString, size_t len) |
| Parses a JSON string. The resulting DOM can be retrieved by calling root(). More... | |
| const GDomNode * | root () const |
| Gets the root document node. More... | |
| void | saveJson (const char *szFilename) const |
| Saves to a file in JSON format. (See http://json.org.) More... | |
| const GDomNode * | setRoot (const GDomNode *pNode) |
| Sets the root document node. (Returns the same node that you pass in.) More... | |
| 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.) More... | |
| 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.) More... | |
| 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.) More... | |
| void | writeXml (std::ostream &stream) const |
| Write as XML to the specified stream. More... | |
Static Public Member Functions | |
| static void | test () |
| Performs unit tests for this class. Throws an exception if there is a failure. More... | |
Protected Member Functions | |
| GDomNode * | loadJsonArray (GJsonTokenizer &tok) |
| GDomNode * | loadJsonNumber (GJsonTokenizer &tok) |
| GDomNode * | loadJsonObject (GJsonTokenizer &tok) |
| char * | loadJsonString (GJsonTokenizer &tok) |
| GDomNode * | loadJsonValue (GJsonTokenizer &tok) |
| GDomObjField * | newField () |
| GDomListItem * | newItem () |
Protected Attributes | |
| GHeap | m_heap |
| size_t | m_len |
| int | m_line |
| const char * | m_pDoc |
| const GDomNode * | m_pRoot |
Friends | |
| class | GDomNode |
| GClasses::GDom::GDom | ( | ) |
| GClasses::GDom::~GDom | ( | ) |
| void GClasses::GDom::clear | ( | ) |
Clears the DOM.
|
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.)
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
| GDomNode* GClasses::GDom::newBool | ( | bool | b | ) |
Makes a new boolean node.
| GDomNode* GClasses::GDom::newDouble | ( | double | d | ) |
Makes a new double node.
|
protected |
| GDomNode* GClasses::GDom::newInt | ( | long long | n | ) |
Makes a new integer node.
|
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 * | 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().
|
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.)
Sets the root document node. (Returns the same node that you pass in.)
|
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.
|
friend |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |