votca 2024-dev
Loading...
Searching...
No Matches
Public Types | Public Member Functions | Static Public Member Functions | Private Attributes | Static Private Attributes | Friends | List of all members
votca::tools::Property Class Reference

class to manage program options with xml serialization functionality More...

#include <property.h>

Collaboration diagram for votca::tools::Property:
Collaboration graph
[legend]

Public Types

using iterator = std::vector< Property >::iterator
 iterator to iterate over properties
 
using const_iterator = std::vector< Property >::const_iterator
 
typedef std::map< std::string, std::string >::iterator AttributeIterator
 
typedef std::map< std::string, std::string >::const_iterator const_AttributeIterator
 

Public Member Functions

 Property ()=default
 
 Property (const std::string &name, const std::string &value, const std::string &path)
 
Propertyadd (const std::string &key, const std::string &value)
 add a new property to structure
 
Propertyadd (const Property &other)
 add a copy of an existing property to a property
 
PropertyaddTree (const std::string &key, const std::string &value)
 add a new property tree to structure
 
PropertyaddTree (const std::vector< std::string > &key, const std::string &value)
 
Propertyset (const std::string &key, const std::string &value)
 set value of existing property
 
Propertyget (const std::string &key)
 get existing property
 
const Propertyget (const std::string &key) const
 
PropertygetOradd (const std::string &key)
 adds new or gets existing property
 
bool exists (const std::string &key) const
 check whether property exists
 
template<typename T >
ifExistsReturnElseReturnDefault (const std::string &key, T defaultvalue) const
 
std::vector< Property * > Select (const std::string &filter)
 select property based on a filter
 
std::vector< const Property * > Select (const std::string &filter) const
 
std::string & value ()
 reference to value of property
 
const std::string & value () const
 
std::string & name ()
 name of property
 
const std::string & name () const
 
std::string & path ()
 full path of property (including parents)
 
const std::string & path () const
 
template<typename T >
as () const
 return value as type
 
bool HasChildren () const
 does the property have children?
 
iterator begin ()
 iterator to first child property
 
const_iterator begin () const
 
iterator end ()
 end iterator for child properties
 
const_iterator end () const
 
Index size () const
 number of child properties
 
template<class cond >
void deleteChildren (cond condition)
 deletes all children that fulfill a condition
 
template<typename T >
getAttribute (const std::string &attribute) const
 return attribute as type
 
template<typename T >
void setAttribute (const std::string &attribute, const T &value)
 set an attribute
 
void deleteAttribute (const std::string &attribute)
 deletes an attribute
 
bool hasAttributes () const
 return true if a node has attributes
 
bool hasAttribute (const std::string &attribute) const
 return true if an attribute exists
 
AttributeIterator findAttribute (const std::string &attribute)
 returns an iterator to an attribute
 
const_AttributeIterator findAttribute (const std::string &attribute) const
 
AttributeIterator firstAttribute ()
 returns an iterator to the first attribute
 
const_AttributeIterator firstAttribute () const
 
AttributeIterator lastAttribute ()
 returns an iterator to the last attribute
 
const_AttributeIterator lastAttribute () const
 
template<typename T >
getAttribute (AttributeIterator it)
 return attribute as type
 
template<typename T >
getAttribute (const_AttributeIterator it) const
 
void LoadFromXML (std::string filename)
 
template<typename T >
getAttribute (std::map< std::string, std::string >::const_iterator it) const
 
template<>
std::string ifExistsReturnElseReturnDefault (const std::string &key, std::string defaultvalue) const
 

Static Public Member Functions

static Index getIOindex ()
 

Private Attributes

std::map< std::string, std::vector< Index > > map_
 
std::map< std::string, std::string > attributes_
 
std::vector< Propertyproperties_
 
std::string name_ = ""
 
std::string value_ = ""
 
std::string path_ = ""
 

Static Private Attributes

static const Index IOindex = std::ios_base::xalloc()
 

Friends

std::ostream & operator<< (std::ostream &out, const Property &p)
 outputs the property to the ostream
 

Detailed Description

class to manage program options with xml serialization functionality

This class stores tags and content in a hierarchical (tree) structure similar to the one used in the XML format. The structure can be either filled manually or read in from an XML file using load_property_from_xml. The supported XML constructs are TAGS, ATTRIBUTES, and CONTENT. The property object can be output to an ostream using format modifiers: cout << XML << property; Supported formats are XML, TXT, HLP

Definition at line 55 of file property.h.

Member Typedef Documentation

◆ AttributeIterator

typedef std::map<std::string,std::string>::iterator votca::tools::Property::AttributeIterator

for iterator-based access of Attributes

Definition at line 232 of file property.h.

◆ const_AttributeIterator

typedef std::map<std::string,std::string>::const_iterator votca::tools::Property::const_AttributeIterator

Definition at line 234 of file property.h.

◆ const_iterator

using votca::tools::Property::const_iterator = std::vector<Property>::const_iterator

Definition at line 186 of file property.h.

◆ iterator

using votca::tools::Property::iterator = std::vector<Property>::iterator

iterator to iterate over properties

Definition at line 185 of file property.h.

Constructor & Destructor Documentation

◆ Property() [1/2]

votca::tools::Property::Property ( )
default

◆ Property() [2/2]

votca::tools::Property::Property ( const std::string &  name,
const std::string &  value,
const std::string &  path 
)
inline

Definition at line 62 of file property.h.

Member Function Documentation

◆ add() [1/2]

Property & votca::tools::Property::add ( const Property other)

add a copy of an existing property to a property

Parameters
otherother property

Definition at line 142 of file property.cc.

◆ add() [2/2]

Property & votca::tools::Property::add ( const std::string &  key,
const std::string &  value 
)

add a new property to structure

Parameters
keyidentifier
valuevalue
Returns
reference to the created Property object

Definition at line 108 of file property.cc.

◆ addTree() [1/2]

Property & votca::tools::Property::addTree ( const std::string &  key,
const std::string &  value 
)

add a new property tree to structure

Parameters
keyidentifier
valuevalue
Returns
reference to the created Property object This function adds a property specified by key separated by "." to step down hierarchy. If the intermediate properties are not found they are also created.

Definition at line 89 of file property.cc.

◆ addTree() [2/2]

Property & votca::tools::Property::addTree ( const std::vector< std::string > &  key,
const std::string &  value 
)

Definition at line 93 of file property.cc.

◆ as()

template<typename T >
T votca::tools::Property::as
inline

return value as type

returns the value after type conversion, e.g. p.as<Index>() returns an integer

Definition at line 283 of file property.h.

◆ begin() [1/2]

iterator votca::tools::Property::begin ( )
inline

iterator to first child property

Definition at line 188 of file property.h.

◆ begin() [2/2]

const_iterator votca::tools::Property::begin ( ) const
inline

Definition at line 189 of file property.h.

◆ deleteAttribute()

void votca::tools::Property::deleteAttribute ( const std::string &  attribute)

deletes an attribute

Definition at line 206 of file property.cc.

◆ deleteChildren()

template<class cond >
void votca::tools::Property::deleteChildren ( cond  condition)

deletes all children that fulfill a condition

Parameters
conditionunary function which takes a const reference to a property and returns a bool

Definition at line 348 of file property.h.

◆ end() [1/2]

iterator votca::tools::Property::end ( )
inline

end iterator for child properties

Definition at line 191 of file property.h.

◆ end() [2/2]

const_iterator votca::tools::Property::end ( ) const
inline

Definition at line 192 of file property.h.

◆ exists()

bool votca::tools::Property::exists ( const std::string &  key) const

check whether property exists

Parameters
keyidentifier
Returns
true or false

Definition at line 122 of file property.cc.

◆ findAttribute() [1/2]

AttributeIterator votca::tools::Property::findAttribute ( const std::string &  attribute)
inline

returns an iterator to an attribute

Definition at line 238 of file property.h.

◆ findAttribute() [2/2]

const_AttributeIterator votca::tools::Property::findAttribute ( const std::string &  attribute) const
inline

Definition at line 241 of file property.h.

◆ firstAttribute() [1/2]

AttributeIterator votca::tools::Property::firstAttribute ( )
inline

returns an iterator to the first attribute

Definition at line 247 of file property.h.

◆ firstAttribute() [2/2]

const_AttributeIterator votca::tools::Property::firstAttribute ( ) const
inline

Definition at line 248 of file property.h.

◆ get() [1/2]

Property & votca::tools::Property::get ( const std::string &  key)

get existing property

Parameters
keyidentifier
Returns
Reference to property object

This function tries to find a property specified by key separated by "." to step down hierarchy. If the property is not found a runtime_exception is thrown. If more than property with this name exists, return the last added one.

Definition at line 79 of file property.cc.

◆ get() [2/2]

const Property & votca::tools::Property::get ( const std::string &  key) const

Definition at line 48 of file property.cc.

◆ getAttribute() [1/4]

template<typename T >
T votca::tools::Property::getAttribute ( AttributeIterator  it)

return attribute as type

returns an attribute after type conversion, e.g. p.getAttribute<Index>() returns an integer

◆ getAttribute() [2/4]

template<typename T >
T votca::tools::Property::getAttribute ( const std::string &  attribute) const
inline

return attribute as type

returns an attribute after type conversion, e.g. p.getAttribute<Index>() returns an integer

Definition at line 308 of file property.h.

◆ getAttribute() [3/4]

template<typename T >
T votca::tools::Property::getAttribute ( const_AttributeIterator  it) const

◆ getAttribute() [4/4]

template<typename T >
T votca::tools::Property::getAttribute ( std::map< std::string, std::string >::const_iterator  it) const
inline

Definition at line 295 of file property.h.

◆ getIOindex()

static Index votca::tools::Property::getIOindex ( )
inlinestatic

Definition at line 268 of file property.h.

◆ getOradd()

Property & votca::tools::Property::getOradd ( const std::string &  key)

adds new or gets existing property

Parameters
keyidentifier
Returns
Reference to property object

This function tries to find a property specified by key separated by "." to step down hierarchy. If the property is not found a property with that name is added and returned. If more than property with this name exists, return the last added one.

Definition at line 156 of file property.cc.

◆ hasAttribute()

bool votca::tools::Property::hasAttribute ( const std::string &  attribute) const

return true if an attribute exists

Definition at line 118 of file property.cc.

◆ hasAttributes()

bool votca::tools::Property::hasAttributes ( ) const
inline

return true if a node has attributes

Definition at line 226 of file property.h.

◆ HasChildren()

bool votca::tools::Property::HasChildren ( ) const
inline

does the property have children?

Returns
true or false

Definition at line 182 of file property.h.

◆ ifExistsReturnElseReturnDefault() [1/2]

template<>
std::string votca::tools::Property::ifExistsReturnElseReturnDefault ( const std::string &  key,
std::string  defaultvalue 
) const
inline

Definition at line 333 of file property.h.

◆ ifExistsReturnElseReturnDefault() [2/2]

template<typename T >
T votca::tools::Property::ifExistsReturnElseReturnDefault ( const std::string &  key,
defaultvalue 
) const
inline

Definition at line 321 of file property.h.

◆ lastAttribute() [1/2]

AttributeIterator votca::tools::Property::lastAttribute ( )
inline

returns an iterator to the last attribute

Definition at line 252 of file property.h.

◆ lastAttribute() [2/2]

const_AttributeIterator votca::tools::Property::lastAttribute ( ) const
inline

Definition at line 253 of file property.h.

◆ LoadFromXML()

void votca::tools::Property::LoadFromXML ( std::string  filename)

Definition at line 238 of file property.cc.

◆ name() [1/2]

std::string & votca::tools::Property::name ( )
inline

name of property

Returns
name

Definition at line 159 of file property.h.

◆ name() [2/2]

const std::string & votca::tools::Property::name ( ) const
inline

Definition at line 160 of file property.h.

◆ path() [1/2]

std::string & votca::tools::Property::path ( )
inline

full path of property (including parents)

Returns
path

e.g. cg.inverse.value

Definition at line 167 of file property.h.

◆ path() [2/2]

const std::string & votca::tools::Property::path ( ) const
inline

Definition at line 168 of file property.h.

◆ Select() [1/2]

std::vector< Property * > votca::tools::Property::Select ( const std::string &  filter)

select property based on a filter

Parameters
filter
Returns
list of pointers to property objects

returns a list of properties that match the key criteria including wildcard "*". Example: "base.item*.value"

Definition at line 185 of file property.cc.

◆ Select() [2/2]

std::vector< const Property * > votca::tools::Property::Select ( const std::string &  filter) const

Definition at line 164 of file property.cc.

◆ set()

Property & votca::tools::Property::set ( const std::string &  key,
const std::string &  value 
)

set value of existing property

Parameters
keyidentifier
valuevalue
Returns
reference to the created Property object If more than property with this name exists, return the last added one.

Definition at line 83 of file property.cc.

◆ setAttribute()

template<typename T >
void votca::tools::Property::setAttribute ( const std::string &  attribute,
const T &  value 
)
inline

set an attribute

Definition at line 314 of file property.h.

◆ size()

Index votca::tools::Property::size ( ) const
inline

number of child properties

Definition at line 194 of file property.h.

◆ value() [1/2]

std::string & votca::tools::Property::value ( )
inline

reference to value of property

Returns
std::string content

Definition at line 153 of file property.h.

◆ value() [2/2]

const std::string & votca::tools::Property::value ( ) const
inline

Definition at line 154 of file property.h.

Friends And Related Symbol Documentation

◆ operator<<

std::ostream & operator<< ( std::ostream &  out,
const Property p 
)
friend

outputs the property to the ostream

Definition at line 440 of file property.cc.

Member Data Documentation

◆ attributes_

std::map<std::string, std::string> votca::tools::Property::attributes_
private

Definition at line 272 of file property.h.

◆ IOindex

const Index votca::tools::Property::IOindex = std::ios_base::xalloc()
staticprivate

Definition at line 279 of file property.h.

◆ map_

std::map<std::string, std::vector<Index> > votca::tools::Property::map_
private

Definition at line 271 of file property.h.

◆ name_

std::string votca::tools::Property::name_ = ""
private

Definition at line 275 of file property.h.

◆ path_

std::string votca::tools::Property::path_ = ""
private

Definition at line 277 of file property.h.

◆ properties_

std::vector<Property> votca::tools::Property::properties_
private

Definition at line 273 of file property.h.

◆ value_

std::string votca::tools::Property::value_ = ""
private

Definition at line 276 of file property.h.


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