tbx  0.7.6
Public Member Functions | Protected Attributes | List of all members
tbx::PropertySet Class Reference

Maintain a simple set of string properties with their values. More...

#include <propertyset.h>

Public Member Functions

bool exists (std::string name) const
 Check if property is a member of this property set. More...
 
void set (std::string name, std::string value)
 Set the value of a string property. More...
 
void set (std::string name, const char *value)
 Set the value of a string property from a C string. More...
 
std::string get (std::string name, const char *def="") const
 Get the value of a property as a string. More...
 
void set (std::string name, int value)
 Set the value of an integer property. More...
 
int get (std::string name, int def) const
 Get the value of an integer property. More...
 
void set (std::string name, bool value)
 Set the value of a boolean property. More...
 
bool get (std::string name, bool def) const
 Get the value of an boolean property. More...
 
bool erase (std::string name)
 Erases a property from the set. More...
 
void set_indexed (std::string name, int index, std::string value)
 Set an indexed string property. More...
 
std::string get_indexed (std::string name, int index, const char *def="") const
 Get the value of an indexed string property. More...
 
void set_indexed (std::string name, int index, int value)
 Set an indexed integer property. More...
 
int get_indexed (std::string name, int index, int def) const
 Get the value of an indexed integer property. More...
 
void set_indexed (std::string name, int index, bool value)
 Set an indexed boolean property. More...
 
bool get_indexed (std::string name, int index, bool def) const
 Get the value of an indexed boolean property. More...
 
bool exists_indexed (std::string name, int index)
 Check if the property set contains the indexed property. More...
 
bool erase_indexed (std::string name, int index)
 Erase an indexed property. More...
 
bool write (std::ostream &os) const
 Writes the property list to a stream. More...
 
bool read (std::istream &is)
 Reads the properties from a stream. More...
 
void clear ()
 Remove all properties from the property set.
 
bool empty ()
 Check if property set is empty.
 
bool save (std::string file_name) const
 Save property set to a file. More...
 
bool load (std::string file_name)
 Load property set from a file. More...
 

Protected Attributes

std::map< std::string, std::string > _properties
 Underlying map to contain the properties.
 

Detailed Description

Maintain a simple set of string properties with their values.

The property names are case sensitive

Member Function Documentation

◆ erase()

bool tbx::PropertySet::erase ( std::string  name)

Erases a property from the set.

Parameters
nameproperty name to erase
Returns
true if property existed in the set

◆ erase_indexed()

bool tbx::PropertySet::erase_indexed ( std::string  name,
int  index 
)

Erase an indexed property.

Parameters
nameproperty name to erased
indexindex to be appended to the property name
Returns
true if indexed property was erased

◆ exists()

bool tbx::PropertySet::exists ( std::string  name) const

Check if property is a member of this property set.

Parameters
namename of property to check
Returns
true if property exists

◆ exists_indexed()

bool tbx::PropertySet::exists_indexed ( std::string  name,
int  index 
)

Check if the property set contains the indexed property.

Parameters
nameproperty name to check
indexindex to be appended to the property name
Returns
true if indexed property exists

◆ get() [1/3]

bool tbx::PropertySet::get ( std::string  name,
bool  def 
) const

Get the value of an boolean property.

Parameters
nameproperty name to get
defdefault value if the property is not in the property set
Returns
value of property or def if not set

◆ get() [2/3]

std::string tbx::PropertySet::get ( std::string  name,
const char *  def = "" 
) const

Get the value of a property as a string.

Parameters
nameproperty name to get
defdefault value if the property is not in the property set
Returns
value of string property returns the default value if property does not exist

◆ get() [3/3]

int tbx::PropertySet::get ( std::string  name,
int  def 
) const

Get the value of an integer property.

Parameters
nameproperty name to get
defdefault value if the property is not in the property set
Returns
value of property or def if not set

◆ get_indexed() [1/3]

bool tbx::PropertySet::get_indexed ( std::string  name,
int  index,
bool  def 
) const

Get the value of an indexed boolean property.

Short cut that just appends the index to the property name before using it in the above routines.

Parameters
nameproperty name to get
indexindex to be appended to the property name
defdefault value if the property is not in the property set
Returns
value of property or def if not set

◆ get_indexed() [2/3]

std::string tbx::PropertySet::get_indexed ( std::string  name,
int  index,
const char *  def = "" 
) const

Get the value of an indexed string property.

Short cut that just appends the index to the property name before using it in the above routines.

Parameters
nameproperty name to get
indexindex to be appended to the property name
defdefault value if the property is not in the property set
Returns
value of property or def if not set

◆ get_indexed() [3/3]

int tbx::PropertySet::get_indexed ( std::string  name,
int  index,
int  def 
) const

Get the value of an indexed integer property.

Short cut that just appends the index to the property name before using it in the above routines.

Parameters
nameproperty name to get
indexindex to be appended to the property name
defdefault value if the property is not in the property set
Returns
value of property or def if not set

◆ load()

bool tbx::PropertySet::load ( std::string  file_name)

Load property set from a file.

Parameters
file_namename of file to load from
Returns
true if successful

◆ read()

bool tbx::PropertySet::read ( std::istream &  is)

Reads the properties from a stream.

Property list is assumed to continue until the end of the stream

Note: Any string property values will have leading and trailing spaces removed.

Parameters
isstream to read properties from
Returns
true if successful

◆ save()

bool tbx::PropertySet::save ( std::string  file_name) const

Save property set to a file.

Parameters
file_namename of file to save to
Returns
true if successful

◆ set() [1/4]

void tbx::PropertySet::set ( std::string  name,
bool  value 
)

Set the value of a boolean property.

Parameters
nameproperty name to set
valuenew value

◆ set() [2/4]

void tbx::PropertySet::set ( std::string  name,
const char *  value 
)

Set the value of a string property from a C string.

Parameters
nameproperty name to set
valuenew value

◆ set() [3/4]

void tbx::PropertySet::set ( std::string  name,
int  value 
)

Set the value of an integer property.

Parameters
nameproperty name to set
valuenew value

◆ set() [4/4]

void tbx::PropertySet::set ( std::string  name,
std::string  value 
)

Set the value of a string property.

Parameters
nameproperty name to set
valuenew value

◆ set_indexed() [1/3]

void tbx::PropertySet::set_indexed ( std::string  name,
int  index,
bool  value 
)

Set an indexed boolean property.

Short cut that just appends the index to the property name before using it in the above routines.

Parameters
nameproperty name to set
indexindex to be appended to the property name
valuenew value

◆ set_indexed() [2/3]

void tbx::PropertySet::set_indexed ( std::string  name,
int  index,
int  value 
)

Set an indexed integer property.

Short cut that just appends the index to the property name before using it in the above routines.

Parameters
nameproperty name to set
indexindex to be appended to the property name
valuenew value

◆ set_indexed() [3/3]

void tbx::PropertySet::set_indexed ( std::string  name,
int  index,
std::string  value 
)

Set an indexed string property.

Short cut that just appends the index to the property name before using it in the above routines.

Parameters
nameproperty name to set
indexindex to be appended to the property name
valuenew value

◆ write()

bool tbx::PropertySet::write ( std::ostream &  os) const

Writes the property list to a stream.

Parameters
osstream to write list to
Returns
true if successful

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