Rudiments
Public Member Functions | List of all members
dom Class Referenceabstract

Inherited by csvdom, jsondom, and xmldom.

Public Member Functions

 dom ()
 
 dom (bool stringcacheenabled)
 
virtual ~dom ()
 
virtual bool parseFile (const char *filename)=0
 
virtual bool parseString (const char *string)=0
 
virtual domnodegetRootNode () const
 
virtual domnodegetNullNode () const
 
virtual void createRootNode ()
 
virtual bool writeFile (const char *filename, mode_t perms) const
 
virtual bool write (output *out) const
 
virtual bool write (output *out, bool indent) const
 
bool stringCacheEnabled ()
 

Detailed Description

The dom class implements a minimal DOM-style parser.

Constructor & Destructor Documentation

◆ dom() [1/2]

dom::dom ( )

Creates a new instance of the dom class.

◆ dom() [2/2]

dom::dom ( bool  stringcacheenabled)

Creates a new instance of the dom class, allowing the user to enable or disable the "string cache" for this instance.

By default, as each domnode is added to the dom tree, tag and attribute names and values are stored in a string cache and pointers into the cache are assigned to each node. Reference counters are kept and the string is removed from the cache when no more nodes are using it. As some formats tend to be highly repetitive this conserves memory at the cost of speed.

If the string cache is disabled then memory is allocated in each domnode for names and values and freed when the domnode is freed. This is faster but uses much more memory.

◆ ~dom()

virtual dom::~dom ( )
virtual

Deletes this instance of the dom class.

Member Function Documentation

◆ createRootNode()

virtual void dom::createRootNode ( )
virtual

Creates a new root node. This is useful for building a tree from scratch.

Reimplemented in csvdom, jsondom, and xmldom.

◆ getNullNode()

virtual domnode* dom::getNullNode ( ) const
virtual

Returns the null node of the DOM tree.

◆ getRootNode()

virtual domnode* dom::getRootNode ( ) const
virtual

Returns the root node of the DOM tree.

◆ parseFile()

virtual bool dom::parseFile ( const char *  filename)
pure virtual

Parses file "filename" and generates a DOM tree.

Implemented in csvdom, jsondom, and xmldom.

◆ parseString()

virtual bool dom::parseString ( const char *  string)
pure virtual

Parses string "string" and generates a DOM tree.

Implemented in csvdom, jsondom, and xmldom.

◆ stringCacheEnabled()

bool dom::stringCacheEnabled ( )

Returns true if the string cache is enabled and false if it is disabled.

◆ write() [1/2]

virtual bool dom::write ( output out) const
virtual

Writes the current DOM tree to "out".

Reimplemented in jsondom.

◆ write() [2/2]

virtual bool dom::write ( output out,
bool  indent 
) const
virtual

Writes the current DOM tree to "out".

If "indent" is true, then the output is automatically indented. If "indent" is false, then the tree is output as-is.

Reimplemented in csvdom.

◆ writeFile()

virtual bool dom::writeFile ( const char *  filename,
mode_t  perms 
) const
virtual

Writes the current DOM tree to "filename" and sets permissions of the file to "perms".