OpenDaVINCI  4.15.3
odcore::base::KeyValueConfiguration Class Reference

#include <KeyValueConfiguration.h>

Inheritance diagram for odcore::base::KeyValueConfiguration:
Inheritance graph

Public Member Functions

 KeyValueConfiguration ()
 
 KeyValueConfiguration (const KeyValueConfiguration &obj)
 
virtual ~KeyValueConfiguration ()
 
KeyValueConfigurationoperator= (const KeyValueConfiguration &obj)
 
virtual int32_t getID () const
 
virtual const string getShortName () const
 
virtual const string getLongName () const
 
virtual const string toString () const
 
virtual ostream & operator<< (ostream &out) const
 
virtual istream & operator>> (istream &in)
 
ostream & writeTo (ostream &out) const
 
istream & readFrom (istream &in)
 
template<class T >
getValue (const string &key) const throw (exceptions::ValueForKeyNotFoundException)
 
template<class T >
getOptionalValue (const string &key, bool &isFound) const
 
KeyValueConfiguration getSubsetForSectionRemoveLeadingSectionName (const string &section) const
 
KeyValueConfiguration getSubsetForSection (const string &section) const
 
const vector< string > getListOfKeys () const
 

Detailed Description

This class is the key/value-based configuration. It reads configuration data using istream:

istream i = ...;
kvc.readFrom(i);

Format for the configuration data:

Comment

key=value #key=value Disabled key. anotherKey=anotherValue # Commented key-value-pair.

Constructor & Destructor Documentation

odcore::base::KeyValueConfiguration::KeyValueConfiguration ( )
odcore::base::KeyValueConfiguration::KeyValueConfiguration ( const KeyValueConfiguration obj)

Copy constructor.

Parameters
objReference to an object of this class.
odcore::base::KeyValueConfiguration::~KeyValueConfiguration ( )
virtual

Member Function Documentation

int32_t odcore::base::KeyValueConfiguration::getID ( ) const
virtual

This method returns the message ID.

Returns
Message identifier.

Implements odcore::data::SerializableData.

const vector< string > odcore::base::KeyValueConfiguration::getListOfKeys ( ) const

This method returns a vector of keys.

Returns
Vector of contained keys.

Referenced by odcontext::base::SuperComponent::getConfiguration().

const string odcore::base::KeyValueConfiguration::getLongName ( ) const
virtual

This method returns the message name including namespace.

Returns
Message name including namespace.

Implements odcore::data::SerializableData.

template<class T >
T odcore::base::KeyValueConfiguration::getOptionalValue ( const string &  key,
bool &  isFound 
) const
inline

This method returns an optional configuration value

...
T t = kvc.getOptionalValue<T>(key, isFound);
Parameters
keyKey for retrieving the value.
isFoundFlag set to true if the parameter is found, false otherwise.
Returns
Value if the parameter is found, undefined otherwise.
const string odcore::base::KeyValueConfiguration::getShortName ( ) const
virtual

This method returns the message name.

Returns
Message name.

Implements odcore::data::SerializableData.

KeyValueConfiguration odcore::base::KeyValueConfiguration::getSubsetForSection ( const string &  section) const

This method returns a subset of this key/value-configuration, i.e. all key/value-pairs starting with "section".

Parameters
sectionBuild subset key/value-configuration for this section.
Returns
(Empty) subset key/value-configuration.

References readFrom().

Referenced by odcontext::base::SuperComponent::getConfiguration().

KeyValueConfiguration odcore::base::KeyValueConfiguration::getSubsetForSectionRemoveLeadingSectionName ( const string &  section) const

This method returns a subset of this key/value-configuration, i.e. all key/value-pairs starting with "section" and removes the leading "section" from the resulting subset.

Parameters
sectionBuild subset key/value-configuration for this section without "section".
Returns
(Empty) subset key/value-configuration.

References readFrom().

template<class T >
T odcore::base::KeyValueConfiguration::getValue ( const string &  key) const
throw (exceptions::ValueForKeyNotFoundException
)
inline

This method returns a configuration value

...
T t = kvc.getValue<T>(key);
Parameters
keyKey for retrieving the value.
Returns
Value.
Exceptions
ValueForKeyNotFoundExceptionis the value for the given key does not exist.

References OPENDAVINCI_CORE_THROW_EXCEPTION.

Referenced by odcontext::base::SuperComponent::getConfiguration().

ostream & odcore::base::KeyValueConfiguration::operator<< ( ostream &  out) const
virtual

This method needs to be used to serialize data.

Parameters
outostream to serialize data to.
Returns
The ostream.

Implements odcore::serialization::Serializable.

References odcore::serialization::SerializationFactory::getInstance(), odcore::serialization::SerializationFactory::getSerializer(), and writeTo().

KeyValueConfiguration & odcore::base::KeyValueConfiguration::operator= ( const KeyValueConfiguration obj)

Assignment operator.

Parameters
objReference to an object of this class.
Returns
Reference to this instance.
istream & odcore::base::KeyValueConfiguration::operator>> ( istream &  in)
virtual

This method needs to be used to deserialize data.

Parameters
inistream to deserialize data from.
Returns
The istream.

Implements odcore::serialization::Serializable.

References odcore::serialization::SerializationFactory::getDeserializer(), odcore::serialization::SerializationFactory::getInstance(), and readFrom().

istream & odcore::base::KeyValueConfiguration::readFrom ( istream &  in)

This method is used to read configuration data using iostreams. It is necessary to allow human readable data on disks.

Parameters
inStream from which the configuration data will be read.
Returns
Stream.

References odcore::strings::StringToolbox::trim().

Referenced by odcontext::base::DirectInterface::DirectInterface(), odcontext::base::SuperComponent::getConfiguration(), getSubsetForSection(), getSubsetForSectionRemoveLeadingSectionName(), operator>>(), and odcontext::base::CommandLineInterface::parse().

const string odcore::base::KeyValueConfiguration::toString ( ) const
virtual

This method returns a human readable format of the contained data.

Returns
Human readable representation.

Implements odcore::data::SerializableData.

References writeTo().

ostream & odcore::base::KeyValueConfiguration::writeTo ( ostream &  out) const

This method is used to write configuration data using iostreams. It is necessary to allow human readable data on disks.

Parameters
outStream to which the configuration data will be written.
Returns
Stream.

Referenced by odcontext::base::SuperComponent::getConfiguration(), operator<<(), and toString().