gatb.core-API-1.4.2
Properties Class Reference

Implementation of IProperties interface. More...

#include <Property.hpp>

Inheritance diagram for Properties:
Inheritance graph

Public Member Functions

 Properties (const std::string &rootname="")
 
 Properties (const Properties &p)
 
virtual ~Properties ()
 
Propertiesoperator= (const Properties &p)
 
void accept (IPropertiesVisitor *visitor)
 
IPropertyadd (size_t depth, const std::string &aKey, const char *format=0,...)
 
IPropertyadd (size_t depth, const std::string &aKey, const std::string &aValue)
 
void add (size_t depth, IProperties *prop)
 
void add (size_t depth, const IProperties &prop)
 
void merge (IProperties *prop)
 
IPropertyoperator[] (const std::string &key)
 
IPropertyget (const std::string &key) const
 
std::string getStr (const std::string &key) const
 
int64_t getInt (const std::string &key) const
 
double getDouble (const std::string &key) const
 
void setStr (const std::string &key, const std::string &value)
 
void setInt (const std::string &key, const int64_t &value)
 
void setDouble (const std::string &key, const double &value)
 
IPropertiesclone ()
 
std::list< IProperties * > map (const char *separator)
 
std::set< std::string > getKeys ()
 
void setToFront (const std::string &key)
 
void readXML (std::istream &stream)
 
void readXML (const std::string &xmlString)
 
std::string getXML ()
 
void readFile (const std::string &file)
 
- Public Member Functions inherited from SmartPointer
void use ()
 
void forget ()
 
- Public Member Functions inherited from ISmartPointer
virtual ~ISmartPointer ()
 

Additional Inherited Members

- Protected Member Functions inherited from SmartPointer
 SmartPointer ()
 
virtual ~SmartPointer ()
 

Detailed Description

Implementation of IProperties interface.

This class provides a constructor that can read a file holding properties as [key,value] entries (one per line). This is useful for instance for managing a configuration file.

Sample of use:

void sample ()
{
// we create a IProperties instance.
IProperties* props = new Properties ();
// we add some entries. Note the different depth used: we have a root property having 3 children properties.
props->add (0, "root", "");
props->add (1, "loud", "len=%d", 3);
props->add (1, "louder", "great");
props->add (1, "stop", "[x,y]=[%f,%f]", 3.14, 2.71);
// we create some visitor for dumping the props into a XML file
IPropertiesVisitor* v = new XmlDumpPropertiesVisitor ("/tmp/test.xml");
// we accept the visitor; after that, the output file should have been created.
props->accept (v);
}

Constructor & Destructor Documentation

Properties ( const std::string &  rootname = "")

Constructor. If a file path is provided, it tries to read [key,value] entries from this file.

Parameters
[in]rootname: the file (if any) to be read
Properties ( const Properties p)

Copy constructor.

~Properties ( )
virtual

Destructor.

Member Function Documentation

void accept ( IPropertiesVisitor visitor)
virtual

Accept a visitor (should loop over all IProperty instances).

Parameters
[in]visitor: visitor to be accepted

Implements IProperties.

IProperty * add ( size_t  depth,
const std::string &  aKey,
const char *  format = 0,
  ... 
)
virtual

Add a IProperty instance given a depth, a key and a value provided in a printf way.

Parameters
[in]depth: depth of the property to be added
[in]aKey: key of the property to be added
[in]format: define the format of the value of the property, the actual value being defined by the ellipsis
Returns
a IProperty instance is created and returned as result of the method.

Implements IProperties.

IProperty * add ( size_t  depth,
const std::string &  aKey,
const std::string &  aValue 
)
virtual

Add a IProperty instance given a depth, a key and a value.

Parameters
[in]depth: depth of the property to be added
[in]aKey: key of the property to be added
[in]aValue: value (as a string) of the property to be added
Returns
a IProperty instance is created and returned as result of the method.

Implements IProperties.

void add ( size_t  depth,
IProperties prop 
)
virtual

Add all the IProperty instances contained in the provided IProperties instance. Note that a depth is provided and is added to the depth of each added IProperty instance.

Parameters
[in]depth: depth to be added to each depth of added instances.
[in]prop: instance holding IProperty instances to be added

Implements IProperties.

void add ( size_t  depth,
const IProperties prop 
)
virtual

Add all the IProperty instances contained in the provided IProperties instance. Note that a depth is provided and is added to the depth of each added IProperty instance.

Parameters
[in]depth: depth to be added to each depth of added instances.
[in]prop: instance holding IProperty instances to be added

Implements IProperties.

IProperties * clone ( )
virtual

Clone the instance

Returns
the cloned instance.

Implements IProperties.

IProperty * get ( const std::string &  key) const
virtual

Returns the IProperty instance given a key.

Parameters
[in]key: the key
Returns
the IProperty instance if found, 0 otherwise.

Implements IProperties.

double getDouble ( const std::string &  key) const
virtual

Get the value of a property given its key.

Parameters
[in]key: the key of the property
Returns
the value of the key as a double.

Implements IProperties.

int64_t getInt ( const std::string &  key) const
virtual

Get the value of a property given its key.

Parameters
[in]key: the key of the property
Returns
the value of the key as an integer

Implements IProperties.

set< string > getKeys ( )
virtual

Get the known keys.

Returns
the set of keys

Implements IProperties.

std::string getStr ( const std::string &  key) const
virtual

Get the value of a property given its key.

Parameters
[in]key: the key of the property
Returns
the value of the key as a string.

Implements IProperties.

string getXML ( )
virtual

Get the properties as an XML string

Returns
the XML string.

Implements IProperties.

std::list< IProperties * > map ( const char *  separator)
virtual

Distribute arguments that are comma separated list.

Returns
the list of distributed IProperties instances.

Implements IProperties.

void merge ( IProperties prop)
virtual

Merge the IProperty instances contained in the provided IProperties instance.

Parameters
[in]prop: instance holding IProperty instances to be added

Implements IProperties.

Properties & operator= ( const Properties p)

Affectation operator.

IProperty * operator[] ( const std::string &  key)
virtual

Returns the IProperty instance given a key.

Parameters
[in]key: the key
Returns
the IProperty instance if found, 0 otherwise.

Implements IProperties.

void readFile ( const std::string &  file)

Read a file holding [key,value] entries and add them through 'add' method.

Parameters
[in]file: the file to be read
void readXML ( std::istream &  stream)
virtual

Fill a Properties instance from an XML stream.

Parameters
[in]streamthe stream to be read (file, string...)

Implements IProperties.

void readXML ( const std::string &  xmlString)
inline

Fill a Properties instance from an XML string.

Parameters
[in]xmlStringthe XML string to be read (file, string...)
void setDouble ( const std::string &  key,
const double &  value 
)
virtual

Set the value of a property given its key.

Parameters
[in]key: the key of the property
[in]value: value to be set.

Implements IProperties.

void setInt ( const std::string &  key,
const int64_t &  value 
)
virtual

Set the value of a property given its key.

Parameters
[in]key: the key of the property
[in]value: value to be set.

Implements IProperties.

void setStr ( const std::string &  key,
const std::string &  value 
)
virtual

Set the value of a property given its key.

Parameters
[in]key: the key of the property
[in]value: value to be set.

Implements IProperties.

void setToFront ( const std::string &  key)
virtual

Move the item (given its key) to the front of the container.

Parameters
[in]key: the key of the item to be moved.

Implements IProperties.


The documentation for this class was generated from the following files: