Home C-Bits Package Documentation Project Page

Main Page   Namespace List   Compound List   File List   Compound Members  

cbits::PropertyList Class Reference

An application 'property set'. More...

#include <PropertyList.h>

List of all members.

Public Methods

void setProperty (const std::string &property_name, const std::string &property_value)
 Set a property. More...

const char * getProperty (const std::string &property_name)
 Retrieve the value (if any) for the specified property. More...

const bool isSet (const char *name)
 Test if a specific property is set in this PropertyList instance. More...

const int getNumProperties () const
 Count number of propety entires in this property set. More...

std::vector< std::string > & getValues (void)
 Retrieve the list of the property values stored in this PropertyList instance. More...

std::vector< std::string > & getKeys (void)
 Retrieve the names of the properties stored in this PropertyList instance. More...

void removeProperties ()
 Remove all properties from this instance. More...

const bool readPropertyList (std::istream &prop_stream, const bool override=true, const char nv_delim='=', const char cmt_delim='#')
 Read properties from a stream, and add them to this instance. More...

const bool readFile (const char *const path, const bool override=true, const char nv_delim='=', const char cmt_delim='#')
 Read a property file, adding contents to this propertyList instance. More...

const bool writePropertyList (std::ostream &os, const char delim='=') const
 Write properties to a stream. More...

const int readCommandLine (const int argc, const char *const *argv, const bool override=true, const char delim='=')
 Read command line, adding any properties to this property set. More...


Static Public Methods

PropertyList & getPropertyList (const std::string &name)
 Get a new or existing PropertyList. More...

void removePropertyList (const std::string &name)
 Remove a property list from memory. More...

void removeAll ()
 Remove all property lists from memory. More...

int getNumPropertyLists ()
 Count number of property lists in memory. More...

const bool exists (const std::string &name)
 Test if a property set exists. More...

std::string trim (const std::string &line)
 Trim whitespace from both ends of a line. More...


Protected Methods

 PropertyList ()
 Default constructor. More...


Static Protected Methods

std::map< std::string, PropertyList * > & getSets ()
 Access the property sets. More...


Private Types

typedef std::map< std::string,
std::string >::const_iterator 
PITERATOR
 Properties iterator. More...


Private Methods

 PropertyList (const PropertyList &)
 Prevent copy construction. More...

PropertyList & operator= (const PropertyList &)
 Prevent assignment. More...


Private Attributes

std::map< std::string, std::string > _properties
 The properties for this PropertyList instance. More...

std::vector< std::string > _values
 Cache for the values stored in this PropertyList instance. More...

std::vector< std::string > _keys
 Cache for the property names stored in this PropertyList instance. More...


Static Private Attributes

std::map< std::string, PropertyList * > _sets
 Map that holds the property sets. More...


Detailed Description

An application 'property set'.

Can be used to

FIXME PropertyList.h this class isn't thread safe.


Member Typedef Documentation

typedef std::map<std::string,std::string>::const_iterator cbits::PropertyList::PITERATOR [private]
 

Properties iterator.


Constructor & Destructor Documentation

PropertyList::PropertyList   [protected]
 

Default constructor.

cbits::PropertyList::PropertyList const PropertyList &    [private]
 

Prevent copy construction.


Member Function Documentation

const bool PropertyList::exists const std::string &    name [static]
 

Test if a property set exists.

Returns:
true if the property set exists; otherwise, false. The property set is NOT created if it doesn't exist.
Parameters:
name  The name of the property set.

std::vector< std::string > & PropertyList::getKeys void   
 

Retrieve the names of the properties stored in this PropertyList instance.

Returns:
reference to a vector of strings. If this PropertyList instance has no properties set, the vector will have no elements.

const int PropertyList::getNumProperties   const
 

Count number of propety entires in this property set.

Returns:
number of entries in property set.

int PropertyList::getNumPropertyLists   [static]
 

Count number of property lists in memory.

const char * PropertyList::getProperty const std::string &    property_name
 

Retrieve the value (if any) for the specified property.

Returns:
pointer to a constant character string value, or 0 if the property has not been set.
Parameters:
property_name  The name of the property.

PropertyList & PropertyList::getPropertyList const std::string &    name [static]
 

Get a new or existing PropertyList.

Returns:
a reference to a PropertyList instance
Parameters:
name  The name of the property list to fetch. If it doesn't exist, a new one will be created.

std::map< std::string, PropertyList * > & PropertyList::getSets   [static, protected]
 

Access the property sets.

std::vector< std::string > & PropertyList::getValues void   
 

Retrieve the list of the property values stored in this PropertyList instance.

Returns:
reference to a vector of strings. If this PropertyList instance has no properties set, the vector will have no elements.

const bool PropertyList::isSet const char *    name
 

Test if a specific property is set in this PropertyList instance.

Returns:
true if the property is set; otherwise, false;
Parameters:
name  The name of the property to test.

PropertyList& cbits::PropertyList::operator= const PropertyList &    [private]
 

Prevent assignment.

const int PropertyList::readCommandLine const int    argc,
const char *const *    argv,
const bool    override = true,
const char    delim = '='
 

Read command line, adding any properties to this property set.

Returns:
number of properties accepted from the command line.
Parameters:
argc  Number of command line arguments
argv  The command line arguments
override  If true, existing property settings will be overridden.
nv_delim  The character used to delimit the name-value pair.

const bool PropertyList::readFile const char *const    path,
const bool    override = true,
const char    nv_delim = '=',
const char    cmt_delim = '#'
 

Read a property file, adding contents to this propertyList instance.

The properties must be 'name <delim> value' pairs, one pair per line, with each line terminated by a '
' (NEWLINE). <delim> is a single character used to delimit property names from value (see 'nv_delim' argument).

Whitespace between 'name' and the <delim> character, or between <delim> and 'value' is ignored.

Returns:
true if the property file was successfully read; otherwise, false.
Parameters:
path  The path to the file to read.
override  If true, existing property settings will be overridden by settings in the property file being read.
nv_delim  The character used to delimit the name-value pair.
cmnt_delim  The character used to designate a comment line.

const bool PropertyList::readPropertyList std::istream &    prop_stream,
const bool    override = true,
const char    nv_delim = '=',
const char    cmt_delim = '#'
 

Read properties from a stream, and add them to this instance.

The properties must be 'name <delim> value' pairs separated by '
' (NEWLINE) characters. <delim> is a single character used to delimit property names from value (see 'nv_delim' argument).

Whitespace between 'name' and the <delim> character, or between <delim> and 'value' is ignored.

Returns:
true if the stream was successfully read; otherwise, false.
Parameters:
props  The stream to read from.
override  If true, existing property settings will be overridden by settings in the property file being read.
nv_delim  The character used to delimit the name-value pair.
cmnt_delim  The character used to designate a comment line.

void PropertyList::removeAll   [static]
 

Remove all property lists from memory.

void PropertyList::removeProperties  
 

Remove all properties from this instance.

void PropertyList::removePropertyList const std::string &    name [static]
 

Remove a property list from memory.

Parameters:
name  The name of the property list to remove. If it doesn't exist, it is ignored.

void PropertyList::setProperty const std::string &    property_name,
const std::string &    property_value
 

Set a property.

Define the method used to set a property.

Parameters:
property_name  The name of the property.
property_value  The value to associate with the given property.

std::string PropertyList::trim const std::string &    line [static]
 

Trim whitespace from both ends of a line.

Returns:
a copy of the line with whitespace removed from both ends.
Parameters:
s  The line to trim.

const bool PropertyList::writePropertyList std::ostream &    os,
const char    delim = '='
const
 

Write properties to a stream.

Returns:
true if properties were successfully written; otherwise, false.
Parameters:
os  The stream to write to.
delim  Character used to delimit names from values.


Member Data Documentation

std::vector< std::string > cbits::PropertyList::_keys [private]
 

Cache for the property names stored in this PropertyList instance.

std::map< std::string, std::string > cbits::PropertyList::_properties [private]
 

The properties for this PropertyList instance.

std::map< std::string, PropertyList * > PropertyList::_sets [static, private]
 

Map that holds the property sets.

std::vector< std::string > cbits::PropertyList::_values [private]
 

Cache for the values stored in this PropertyList instance.


The documentation for this class was generated from the following files:
Generated by
doxygen
Hosted by
SourceForge