tue_config
Public Member Functions | Private Member Functions | Private Attributes | Friends | List of all members
tue::config::ReaderWriter Class Reference

#include <reader_writer.h>

Public Member Functions

bool addArrayItem ()
 addArrayItem create a new item in the array More...
 
void addError (const std::string &msg)
 
DataPointer data () const
 data get the data from the current reading/writing point More...
 
bool endArray ()
 endArray go to parrent of current array, wrapping end() for readibility More...
 
bool endArrayItem ()
 endArrayItem go back to the array level More...
 
bool endGroup ()
 endGroup go to the parrent of current group, wrapping end() for readbility More...
 
const std::stringerror () const
 
bool hasArray (const std::string &name)
 hasArray check if current node has a child, which is an array, with the key 'name' More...
 
bool hasError () const
 
bool hasGroup (const std::string &name)
 hasGroup check if current node has a child, which is a group, with the key 'name' More...
 
ReaderWriter limitScope () const
 limitScope Limit the data to the current position. All parents and siblings incl. their child aren't accesible anymore. More...
 
bool loadFromSDFFile (const std::string &filename)
 loadFromSDFFile loads a sdf file into a ReaderWriter class More...
 
bool loadFromXMLFile (const std::string &filename)
 loadFromXMLFile loads a xml file into a ReaderWriter class More...
 
bool loadFromYAMLFile (const std::string &filename, const ResolveConfig &resolve_config=ResolveConfig::defaultConfig())
 loadFromYAMLFile loads a yaml file into a ReaderWriter class More...
 
bool nextArrayItem ()
 nextArrayItem go to the next item in the array, wrapping next() for readbility More...
 
bool readArray (const std::string &name, const RequiredOrOptional opt=OPTIONAL)
 readArray read the child with key 'name', which should be an array More...
 
 ReaderWriter ()
 
 ReaderWriter (DataPointer &cfg)
 
bool readGroup (const std::string &name, const RequiredOrOptional opt=OPTIONAL)
 readGroup read the child with key 'name', which should be a group More...
 
void setErrorContext (const std::string &context)
 setErrorContext More...
 
void setShortErrorContext (const std::string &context)
 setShortErrorContext More...
 
void setSource (const std::string &source)
 setSource set the source file of the data in this object More...
 
template<typename T >
void setValue (const std::string &name, const T &value)
 setValue set child value with key 'name' and value 'value' More...
 
void setValue (const std::string &name, std::string value)
 setValue<string> set child value with key 'name' and value 'value', value is stripped from leading and trailing whitespace More...
 
const std::stringsource () const
 source get the source file of the data in this object More...
 
bool sync ()
 sync re-read the source file if the file has changed since last reading time. More...
 
std::string toYAMLString () const
 toYAMLString convert data (from current reading/writing point) to yaml string More...
 
template<typename T >
bool value (const std::string &name, T &value, RequiredOrOptional opt=REQUIRED)
 value read value of child with key 'name' More...
 
bool writeArray (const std::string &name)
 writeArray starts writing an array. Or start extending it, if it already exists. More...
 
bool writeGroup (const std::string &name)
 writeGroup starts writing a group. Or start extending it, if it already exists. More...
 
virtual ~ReaderWriter ()
 

Private Member Functions

bool end ()
 end go to parent node. More...
 
bool hasChild (const std::string &name, NodeType type) const
 hasChild check if node has a child with key 'name' and type ARRAY or MAP More...
 
bool next ()
 next go to next item in an array More...
 
bool read (const std::string &name, const NodeType type, RequiredOrOptional opt=OPTIONAL)
 read read child with key 'name' of type ARRAY or MAP More...
 

Private Attributes

boost::shared_ptr< Datacfg_
 
boost::shared_ptr< Errorerror_
 
boost::shared_ptr< std::stringerror_context_
 
std::string filename_
 
NodeIdx idx_
 
ResolveConfig resolve_config_
 
NodeIdx scope_
 
std::time_t source_last_write_time_
 

Friends

std::ostreamoperator<< (std::ostream &out, const ReaderWriter &rw)
 operator << stream operator More...
 

Detailed Description

Definition at line 26 of file reader_writer.h.

Constructor & Destructor Documentation

◆ ReaderWriter() [1/2]

tue::config::ReaderWriter::ReaderWriter ( )

Definition at line 33 of file reader_writer.cpp.

◆ ReaderWriter() [2/2]

tue::config::ReaderWriter::ReaderWriter ( DataPointer cfg)

Definition at line 39 of file reader_writer.cpp.

◆ ~ReaderWriter()

tue::config::ReaderWriter::~ReaderWriter ( )
virtual

Definition at line 50 of file reader_writer.cpp.

Member Function Documentation

◆ addArrayItem()

bool tue::config::ReaderWriter::addArrayItem ( )

addArrayItem create a new item in the array

Returns
indicates succes, can fail if current node isn't in an array

Definition at line 223 of file reader_writer.cpp.

◆ addError()

void tue::config::ReaderWriter::addError ( const std::string msg)

Definition at line 136 of file reader_writer.cpp.

◆ data()

DataPointer tue::config::ReaderWriter::data ( ) const
inline

data get the data from the current reading/writing point

Returns
DataPointer

Definition at line 249 of file reader_writer.h.

◆ end()

bool tue::config::ReaderWriter::end ( )
private

end go to parent node.

Returns
indicates succes, can fail if current node is the scope or if node doesn't have a parent

Definition at line 78 of file reader_writer.cpp.

◆ endArray()

bool tue::config::ReaderWriter::endArray ( )
inline

endArray go to parrent of current array, wrapping end() for readibility

Returns
indicates succes, see end() for more information

Definition at line 98 of file reader_writer.h.

◆ endArrayItem()

bool tue::config::ReaderWriter::endArrayItem ( )

endArrayItem go back to the array level

Returns
indicates succes, can fail if current node ins't an array item

Definition at line 245 of file reader_writer.cpp.

◆ endGroup()

bool tue::config::ReaderWriter::endGroup ( )
inline

endGroup go to the parrent of current group, wrapping end() for readbility

Returns
indicates succes, see end() for more information

Definition at line 104 of file reader_writer.h.

◆ error()

const std::string& tue::config::ReaderWriter::error ( ) const
inline

Definition at line 208 of file reader_writer.h.

◆ hasArray()

bool tue::config::ReaderWriter::hasArray ( const std::string name)
inline

hasArray check if current node has a child, which is an array, with the key 'name'

Parameters
namekey of the possible child array
Returns
indicates succes, can fail if key isn't avalaible or child is an array instead of a group

Definition at line 117 of file reader_writer.h.

◆ hasChild()

bool tue::config::ReaderWriter::hasChild ( const std::string name,
NodeType  type 
) const
private

hasChild check if node has a child with key 'name' and type ARRAY or MAP

Parameters
namekey of the child
typenode type of the child, ARRAY or MAP
Returns
indicates succes, can fail if key isn't avalaible or child is a group instead of an array

Definition at line 122 of file reader_writer.cpp.

◆ hasError()

bool tue::config::ReaderWriter::hasError ( ) const
inline

Definition at line 206 of file reader_writer.h.

◆ hasGroup()

bool tue::config::ReaderWriter::hasGroup ( const std::string name)
inline

hasGroup check if current node has a child, which is a group, with the key 'name'

Parameters
namekey of the possible child group
Returns
indicates succes, can fail if key isn't avalaible or child is a group instead of an array

Definition at line 124 of file reader_writer.h.

◆ limitScope()

ReaderWriter tue::config::ReaderWriter::limitScope ( ) const

limitScope Limit the data to the current position. All parents and siblings incl. their child aren't accesible anymore.

Returns
ReaderWriter with data limited to current position

Definition at line 113 of file reader_writer.cpp.

◆ loadFromSDFFile()

bool tue::config::ReaderWriter::loadFromSDFFile ( const std::string filename)

loadFromSDFFile loads a sdf file into a ReaderWriter class

Parameters
filenameinput file
Returns
indicates success

Definition at line 267 of file reader_writer.cpp.

◆ loadFromXMLFile()

bool tue::config::ReaderWriter::loadFromXMLFile ( const std::string filename)

loadFromXMLFile loads a xml file into a ReaderWriter class

Parameters
filenameinput file
Returns
indicates success

Definition at line 286 of file reader_writer.cpp.

◆ loadFromYAMLFile()

bool tue::config::ReaderWriter::loadFromYAMLFile ( const std::string filename,
const ResolveConfig resolve_config = ResolveConfig::defaultConfig() 
)

loadFromYAMLFile loads a yaml file into a ReaderWriter class

Parameters
filenameinput file
Returns
indicates success

Definition at line 305 of file reader_writer.cpp.

◆ next()

bool tue::config::ReaderWriter::next ( )
private

next go to next item in an array

Returns
indicates succes, can fail if current node isn't in an array or if it is the last item in the array

Definition at line 98 of file reader_writer.cpp.

◆ nextArrayItem()

bool tue::config::ReaderWriter::nextArrayItem ( )
inline

nextArrayItem go to the next item in the array, wrapping next() for readbility

Returns
indicates succes, can fail if current node isn't in an array or if it is the last item in the array

Definition at line 110 of file reader_writer.h.

◆ read()

bool tue::config::ReaderWriter::read ( const std::string name,
const NodeType  type,
RequiredOrOptional  opt = OPTIONAL 
)
private

read read child with key 'name' of type ARRAY or MAP

Parameters
namekey of the child
typenode type of the child, ARRAY or MAP
optRequiredOrOptional
Returns
indicates succes, can fail if key isn't avalaible or child is of incorrect type

Definition at line 56 of file reader_writer.cpp.

◆ readArray()

bool tue::config::ReaderWriter::readArray ( const std::string name,
const RequiredOrOptional  opt = OPTIONAL 
)
inline

readArray read the child with key 'name', which should be an array

Parameters
namekey of the array
optRequiredOrOptional
Returns
indicates succes, can fail if key isn't available or child is a group instead of an array

Definition at line 84 of file reader_writer.h.

◆ readGroup()

bool tue::config::ReaderWriter::readGroup ( const std::string name,
const RequiredOrOptional  opt = OPTIONAL 
)
inline

readGroup read the child with key 'name', which should be a group

Parameters
namekey of the group
optRequiredOrOptional
Returns
indicates succes, can fail if key isn't avalaible or child is an array instead of a group

Definition at line 92 of file reader_writer.h.

◆ setErrorContext()

void tue::config::ReaderWriter::setErrorContext ( const std::string context)
inline

setErrorContext

Parameters
contextcontext string

Definition at line 255 of file reader_writer.h.

◆ setShortErrorContext()

void tue::config::ReaderWriter::setShortErrorContext ( const std::string context)
inline

setShortErrorContext

Parameters
contextcontext string

Definition at line 261 of file reader_writer.h.

◆ setSource()

void tue::config::ReaderWriter::setSource ( const std::string source)
inline

setSource set the source file of the data in this object

Parameters
sourcestring of the source file

Definition at line 193 of file reader_writer.h.

◆ setValue() [1/2]

template<typename T >
void tue::config::ReaderWriter::setValue ( const std::string name,
const T &  value 
)
inline

setValue set child value with key 'name' and value 'value'

Parameters
namename of the key
valuevalue of the value

Definition at line 155 of file reader_writer.h.

◆ setValue() [2/2]

void tue::config::ReaderWriter::setValue ( const std::string name,
std::string  value 
)
inline

setValue<string> set child value with key 'name' and value 'value', value is stripped from leading and trailing whitespace

Parameters
namename of the key
valuevalue of the value

Definition at line 168 of file reader_writer.h.

◆ source()

const std::string& tue::config::ReaderWriter::source ( ) const
inline

source get the source file of the data in this object

Returns
string of the source file

Definition at line 130 of file reader_writer.h.

◆ sync()

bool tue::config::ReaderWriter::sync ( )

sync re-read the source file if the file has changed since last reading time.

Returns
indicates succes, can fail if last changed time is incorrect or unsupported extension is used.

Definition at line 325 of file reader_writer.cpp.

◆ toYAMLString()

std::string tue::config::ReaderWriter::toYAMLString ( ) const

toYAMLString convert data (from current reading/writing point) to yaml string

Returns
yaml string

Definition at line 257 of file reader_writer.cpp.

◆ value()

template<typename T >
bool tue::config::ReaderWriter::value ( const std::string name,
T &  value,
RequiredOrOptional  opt = REQUIRED 
)
inline

value read value of child with key 'name'

Parameters
namename of the key
valueobject to write the value to
optRequiredOrOptional
Returns
indicates succes, can fail if key not available or variable type isn't matching

Definition at line 47 of file reader_writer.h.

◆ writeArray()

bool tue::config::ReaderWriter::writeArray ( const std::string name)

writeArray starts writing an array. Or start extending it, if it already exists.

Parameters
nameof the array
Returns
indicates succes

Definition at line 202 of file reader_writer.cpp.

◆ writeGroup()

bool tue::config::ReaderWriter::writeGroup ( const std::string name)

writeGroup starts writing a group. Or start extending it, if it already exists.

Parameters
nameof the group
Returns
indicates succes

Definition at line 181 of file reader_writer.cpp.

Friends And Related Function Documentation

◆ operator<<

std::ostream& operator<< ( std::ostream out,
const ReaderWriter rw 
)
friend

operator << stream operator

Parameters
out
rwReaderWriter object
Returns

Definition at line 361 of file reader_writer.cpp.

Member Data Documentation

◆ cfg_

boost::shared_ptr<Data> tue::config::ReaderWriter::cfg_
private

Definition at line 301 of file reader_writer.h.

◆ error_

boost::shared_ptr<Error> tue::config::ReaderWriter::error_
private

Definition at line 303 of file reader_writer.h.

◆ error_context_

boost::shared_ptr<std::string> tue::config::ReaderWriter::error_context_
private

Definition at line 305 of file reader_writer.h.

◆ filename_

std::string tue::config::ReaderWriter::filename_
private

Definition at line 310 of file reader_writer.h.

◆ idx_

NodeIdx tue::config::ReaderWriter::idx_
private

Definition at line 297 of file reader_writer.h.

◆ resolve_config_

ResolveConfig tue::config::ReaderWriter::resolve_config_
private

Definition at line 314 of file reader_writer.h.

◆ scope_

NodeIdx tue::config::ReaderWriter::scope_
private

Definition at line 299 of file reader_writer.h.

◆ source_last_write_time_

std::time_t tue::config::ReaderWriter::source_last_write_time_
private

Definition at line 312 of file reader_writer.h.


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