Rudiments
Public Member Functions | Protected Member Functions | List of all members
propdom Class Reference

Inherits propsax, and dom.

Public Member Functions

 propdom ()
 
 propdom (bool stringcacheenabled)
 
virtual ~propdom ()
 
virtual const char * getType ()
 
bool parse (input *in)
 
bool parseFile (const char *filename)
 
bool parseString (const char *string)
 
void createRootNode ()
 
- Public Member Functions inherited from propsax
 propsax ()
 
virtual ~propsax ()
 
- Public Member Functions inherited from sax
 sax ()
 
virtual ~sax ()
 
void setIgnoreHeaderLines (uint64_t lines)
 
uint64_t getIgnoreHeaderLines ()
 
void setIgnoreFooterLines (uint64_t lines)
 
uint64_t getIgnoreFooterLines ()
 
const char * getError ()
 
- Public Member Functions inherited from object
virtual ~object ()
 
- Public Member Functions inherited from dom
 dom ()
 
 dom (bool stringcacheenabled)
 
virtual ~dom ()
 
virtual domnodegetRootNode ()
 
virtual domnodegetNullNode ()
 
virtual ssize_t writeFile (const char *filename, mode_t perms)
 
virtual ssize_t writeFile (const char *filename, mode_t perms, bool indent)
 
virtual ssize_t write ()
 
virtual ssize_t write (bool indent)
 
virtual ssize_t write (output *out)
 
virtual ssize_t write (output *out, bool indent)
 
virtual ssize_t writeXml ()
 
virtual ssize_t writeXml (bool indent)
 
virtual ssize_t writeXml (output *out)
 
virtual ssize_t writeXml (output *out, bool indent)
 
bool getStringCacheEnabled ()
 
- Public Member Functions inherited from collection
 collection ()
 
 collection (collection &c)
 
collectionoperator= (collection &c)
 
virtual ~collection ()
 
virtual uint64_t getCount ()=0
 
comparatorgetComparator ()
 
void setComparator (comparator *newcomp)
 
virtual bool isReadOnly ()
 
virtual bool isBlockBased ()
 
virtual uint64_t getBlockSize ()
 
virtual bool isSequentialAccess ()
 
virtual void setManageValues (bool manage)
 
virtual bool getManageValues ()
 
virtual void setManageArrayValues (bool manage)
 
virtual bool getManageArrayValues ()
 
virtual void setManageKeys (bool manage)
 
virtual bool getManageKeys ()
 
virtual void setManageArrayKeys (bool manage)
 
virtual bool getManageArrayKeys ()
 
virtual bool clear ()=0
 
virtual ssize_t writeJson ()=0
 
virtual ssize_t writeJson (bool indent)=0
 
virtual ssize_t writeJson (output *out)=0
 
virtual ssize_t writeJson (output *out, bool indent)=0
 

Protected Member Functions

virtual bool whitespaceStart ()
 
virtual bool whitespace (const char *w)
 
virtual bool whitespaceEnd ()
 
virtual bool exclamationCommentStart ()
 
virtual bool exclamationComment (const char *c)
 
virtual bool exclamationCommentEnd ()
 
virtual bool poundCommentStart ()
 
virtual bool poundComment (const char *c)
 
virtual bool poundCommentEnd ()
 
virtual bool keyStart ()
 
virtual bool key (const char *k)
 
virtual bool keyEnd ()
 
virtual bool equals (const char *e)
 
virtual bool valueStart ()
 
virtual bool value (const char *v)
 
virtual bool valueEnd ()
 

Detailed Description

The propdom class implements a minimal DOM parser for a JAVA-style properties file.

It parses a file or string of property-file-formatted data and produces a dom tree representing the data. It creates "k" elements for each key, "p" elements for each pound-delimited comment, and "c" elements for each exclamation-delimited comment. It adds a "v" attribute to each element, containing the value. For each "k" element, it also adds a "k" attribute, containing the name of the key. Text dom nodes (nodes of type TEXT_DOMNODETYPE) are used to preserve whitespace.

For example, the following property file:

#pound comment !exclamation comment key1=value1 key2=value2

key 3=value 3 key 4=value 4

would produce the following dom tree:

<e v="exclamation comment"> <k k="key1" v="value1"> <k k="key2" v="value2">

<k k="key 3" v="value 3"> <k k="key 4" v="value 4">

(Note the blank line of text between key2 and key 3. This is the text domnode, used to preserve the whitespace.) The propdom class implements a minimal properties file DOM parser.

Constructor & Destructor Documentation

◆ propdom() [1/2]

propdom::propdom ( )

Creates a new instance of the propdom class.

◆ propdom() [2/2]

propdom::propdom ( bool  stringcacheenabled)

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

By default, as each domnode is added to the propdom 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. If the data is 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.

◆ ~propdom()

virtual propdom::~propdom ( )
virtual

Deletes this instance of the propdom class.

Member Function Documentation

◆ createRootNode()

void propdom::createRootNode ( )
virtual

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

Reimplemented from dom.

◆ equals()

virtual bool propdom::equals ( const char *  e)
protectedvirtual

Gets called when the equality delimiter between a key and value is parsed.

Reimplemented from propsax.

◆ exclamationComment()

virtual bool propdom::exclamationComment ( const char *  c)
protectedvirtual

Gets called when an exclamation-delimited comment is parsed.

Reimplemented from propsax.

◆ exclamationCommentEnd()

virtual bool propdom::exclamationCommentEnd ( )
protectedvirtual

Gets called when the end of an exclamation-delimited comment is encountered.

Reimplemented from propsax.

◆ exclamationCommentStart()

virtual bool propdom::exclamationCommentStart ( )
protectedvirtual

Gets called when the start of an exclamation-delimited comment is encountered.

Reimplemented from propsax.

◆ getType()

virtual const char* propdom::getType ( )
virtual

Returns "propdom".

Reimplemented from dom.

◆ key()

virtual bool propdom::key ( const char *  k)
protectedvirtual

Gets called when a key name is parsed.

Reimplemented from propsax.

◆ keyEnd()

virtual bool propdom::keyEnd ( )
protectedvirtual

Gets called when the end of a key is encountered.

Reimplemented from propsax.

◆ keyStart()

virtual bool propdom::keyStart ( )
protectedvirtual

Gets called when the start of a key is encountered.

Reimplemented from propsax.

◆ parse()

bool propdom::parse ( input in)
virtual

Parses generic input "in" and generates a DOM tree.

Implements dom.

◆ parseFile()

bool propdom::parseFile ( const char *  filename)
virtual

Parses file "filename" and generates a DOM tree.

Implements dom.

◆ parseString()

bool propdom::parseString ( const char *  string)
virtual

Parses string "string" and generates a DOM tree.

Implements dom.

◆ poundComment()

virtual bool propdom::poundComment ( const char *  c)
protectedvirtual

Gets called when a pound-delimited comment is parsed.

Reimplemented from propsax.

◆ poundCommentEnd()

virtual bool propdom::poundCommentEnd ( )
protectedvirtual

Gets called when the end of a pound-delimited comment is encountered.

Reimplemented from propsax.

◆ poundCommentStart()

virtual bool propdom::poundCommentStart ( )
protectedvirtual

Gets called when the start of a pound-delimited comment is encountered.

Reimplemented from propsax.

◆ value()

virtual bool propdom::value ( const char *  v)
protectedvirtual

Gets called when a value name is parsed.

Reimplemented from propsax.

◆ valueEnd()

virtual bool propdom::valueEnd ( )
protectedvirtual

Gets called when the end of a value is encountered.

Reimplemented from propsax.

◆ valueStart()

virtual bool propdom::valueStart ( )
protectedvirtual

Gets called when the start of a value is encountered.

Reimplemented from propsax.

◆ whitespace()

virtual bool propdom::whitespace ( const char *  w)
protectedvirtual

Gets called when whitespace (outside of a comment, section name, key, or value) is parsed.

Reimplemented from propsax.

◆ whitespaceEnd()

virtual bool propdom::whitespaceEnd ( )
protectedvirtual

Gets called when the end of whitespace (outside of a comment, section name, key, or value) is encountered.

Reimplemented from propsax.

◆ whitespaceStart()

virtual bool propdom::whitespaceStart ( )
protectedvirtual

Gets called when the start of whitespace (outside of a comment, section name, key, or value) is encountered.

Reimplemented from propsax.