DP3
Public Types | Public Member Functions | List of all members
dp3::common::ParameterSetImpl Class Reference

Implements a map of Key-Value pairs. Description of class. The ParameterSetImpl class is a key-value implementation of the type map<string, string, KeyCompare>. This means that values are stored as a string which allows easy merging and splitting of ParameterSetImpls because no conversions have to be done. A couple of getXxx routines are provided to convert the strings to the desired type. More...

#include <ParameterSetImpl.h>

Inheritance diagram for dp3::common::ParameterSetImpl:

Public Types

typedef KVMap::const_iterator const_iterator
 
typedef KVMap::iterator iterator
 

Public Member Functions

std::vector< std::string > unusedKeys () const
 Get all unused parameter names. More...
 
Construction and Destruction

A ParameterSetImpl can be constructed as empty collection, can be read from a file or copied from another collection.

 ParameterSetImpl (KeyCompare::Mode mode)
 
 ~ParameterSetImpl ()
 Destroy the contents. More...
 
 ParameterSetImpl (const std::string &theFilename, KeyCompare::Mode mode)
 
const ParameterValueget (const std::string &aKey) const
 
KeyCompare::Mode keyCompareMode () const
 Return the key comparison mode. More...
 
Merging or appending collections

An existing collection can be extended/merged with another collection.

void adoptFile (const std::string &theFilename, const std::string &thePrefix="")
 
void adoptBuffer (const std::string &theBuffer, const std::string &thePrefix="")
 
void adoptCollection (const ParameterSetImpl &theCollection, const std::string &thePrefix="")
 
void adoptArguments (const std::vector< std::string > &arguments)
 
Saving the collection

The map of key-value pair can be saved in a file or a string.

void writeFile (const std::string &theFilename, bool append=false) const
 Writes the Key-Values pair from the current ParCollection to the file. More...
 
void writeBuffer (std::string &theBuffer) const
 
void writeStream (std::ostream &os) const
 
Handle subsets

A subset from the current collection can be made based on the prefix of the keys in the collection.

std::shared_ptr< ParameterSetImplmakeSubset (const std::string &baseKey, const std::string &prefix="") const
 
void subtractSubset (const std::string &fullPrefix)
 
Handling single key-value pairs

Single key-value pairs can ofcourse be added, replaced or removed from a collection.

void add (const std::string &aKey, const ParameterValue &aValue)
 
void replace (const std::string &aKey, const ParameterValue &aValue)
 
void remove (const std::string &aKey)
 Removes the pair with the given key. Removing a non-existing key is ok. More...
 
Searching and retrieving

The following functions support searching the collection for existance of given keys an the retrieval of the corresponding value. In the getXxx retrieve functions the stored string-value is converted to the wanted type.

bool isDefined (const std::string &searchKey) const
 Checks if the given Key is defined in the ParameterSetImpl. More...
 
std::string locateModule (const std::string &shortName) const
 
std::string fullModuleName (const std::string &shortName) const
 
bool getBool (const std::string &aKey) const
 
bool getBool (const std::string &aKey, bool aValue) const
 
int getInt (const std::string &aKey) const
 
int getInt (const std::string &aKey, int aValue) const
 
unsigned int getUint (const std::string &aKey) const
 
unsigned int getUint (const std::string &aKey, unsigned int aValue) const
 
int16_t getInt16 (const std::string &aKey) const
 
int16_t getInt16 (const std::string &aKey, int16_t aValue) const
 
uint16_t getUint16 (const std::string &aKey) const
 
uint16_t getUint16 (const std::string &aKey, uint16_t aValue) const
 
int32_t getInt32 (const std::string &aKey) const
 
int32_t getInt32 (const std::string &aKey, int32_t aValue) const
 
uint32_t getUint32 (const std::string &aKey) const
 
uint32_t getUint32 (const std::string &aKey, uint32_t aValue) const
 
int64_t getInt64 (const std::string &aKey) const
 
int64_t getInt64 (const std::string &aKey, int64_t aValue) const
 
uint64_t getUint64 (const std::string &aKey) const
 
uint64_t getUint64 (const std::string &aKey, uint64_t aValue) const
 
float getFloat (const std::string &aKey) const
 
float getFloat (const std::string &aKey, float aValue) const
 
double getDouble (const std::string &aKey) const
 
double getDouble (const std::string &aKey, double aValue) const
 
std::string getString (const std::string &aKey) const
 
std::string getString (const std::string &aKey, const std::string &aValue) const
 
time_t getTime (const std::string &aKey) const
 
time_t getTime (const std::string &aKey, const time_t &aValue) const
 
std::vector< bool > getBoolVector (const std::string &aKey, bool expandable) const
 
std::vector< bool > getBoolVector (const std::string &aKey, const std::vector< bool > &aValue, bool expandable) const
 
std::vector< int > getIntVector (const std::string &aKey, bool expandable) const
 
std::vector< int > getIntVector (const std::string &aKey, const std::vector< int > &aValue, bool expandable) const
 
std::vector< unsigned int > getUintVector (const std::string &aKey, bool expandable) const
 
std::vector< unsigned int > getUintVector (const std::string &aKey, const std::vector< unsigned int > &aValue, bool expandable) const
 
std::vector< int16_t > getInt16Vector (const std::string &aKey, bool expandable) const
 
std::vector< int16_t > getInt16Vector (const std::string &aKey, const std::vector< int16_t > &aValue, bool expandable) const
 
std::vector< uint16_t > getUint16Vector (const std::string &aKey, bool expandable) const
 
std::vector< uint16_t > getUint16Vector (const std::string &aKey, const std::vector< uint16_t > &aValue, bool expandable) const
 
std::vector< int32_t > getInt32Vector (const std::string &aKey, bool expandable) const
 
std::vector< int32_t > getInt32Vector (const std::string &aKey, const std::vector< int32_t > &aValue, bool expandable) const
 
std::vector< uint32_t > getUint32Vector (const std::string &aKey, bool expandable) const
 
std::vector< uint32_t > getUint32Vector (const std::string &aKey, const std::vector< uint32_t > &aValue, bool expandable) const
 
std::vector< int64_t > getInt64Vector (const std::string &aKey, bool expandable) const
 
std::vector< int64_t > getInt64Vector (const std::string &aKey, const std::vector< int64_t > &aValue, bool expandable) const
 
std::vector< uint64_t > getUint64Vector (const std::string &aKey, bool expandable) const
 
std::vector< uint64_t > getUint64Vector (const std::string &aKey, const std::vector< uint64_t > &aValue, bool expandable) const
 
std::vector< float > getFloatVector (const std::string &aKey, bool expandable) const
 
std::vector< float > getFloatVector (const std::string &aKey, const std::vector< float > &aValue, bool expandable) const
 
std::vector< double > getDoubleVector (const std::string &aKey, bool expandable) const
 
std::vector< double > getDoubleVector (const std::string &aKey, const std::vector< double > &aValue, bool expandable) const
 
std::vector< std::string > getStringVector (const std::string &aKey, bool expandable) const
 
std::vector< std::string > getStringVector (const std::string &aKey, const std::vector< std::string > &aValue, bool expandable) const
 
std::vector< time_t > getTimeVector (const std::string &aKey, bool expandable) const
 
std::vector< time_t > getTimeVector (const std::string &aKey, const std::vector< time_t > &aValue, bool expandable) const
 

Friends

Printing

Mostly for debug purposes the collection can be printed.

std::ostream & operator<< (std::ostream &os, const ParameterSetImpl &thePS)
 

Detailed Description

Implements a map of Key-Value pairs. Description of class. The ParameterSetImpl class is a key-value implementation of the type map<string, string, KeyCompare>. This means that values are stored as a string which allows easy merging and splitting of ParameterSetImpls because no conversions have to be done. A couple of getXxx routines are provided to convert the strings to the desired type.

It keeps track of the keys being asked for. Unused keys might mean that their names were misspelled. The class is fully thread-safe.

Member Typedef Documentation

◆ const_iterator

typedef KVMap::const_iterator dp3::common::ParameterSetImpl::const_iterator

◆ iterator

typedef KVMap::iterator dp3::common::ParameterSetImpl::iterator

Constructor & Destructor Documentation

◆ ParameterSetImpl() [1/2]

dp3::common::ParameterSetImpl::ParameterSetImpl ( KeyCompare::Mode  mode)
explicit

Create an empty collection. The argument mode determines how keys should be compared.

◆ ~ParameterSetImpl()

dp3::common::ParameterSetImpl::~ParameterSetImpl ( )

Destroy the contents.

◆ ParameterSetImpl() [2/2]

dp3::common::ParameterSetImpl::ParameterSetImpl ( const std::string &  theFilename,
KeyCompare::Mode  mode 
)
explicit

Construct a ParameterSet from the contents of theFilename. The argument mode determines how keys should be compared.

Member Function Documentation

◆ add()

void dp3::common::ParameterSetImpl::add ( const std::string &  aKey,
const ParameterValue aValue 
)

Add the given pair to the collection. When the aKey already exist in the collection an exception is thrown.

◆ adoptArguments()

void dp3::common::ParameterSetImpl::adoptArguments ( const std::vector< std::string > &  arguments)

Adds the Key-Values pairs in the argument list. It ignores arguments not having the Key=Value syntax.

◆ adoptBuffer()

void dp3::common::ParameterSetImpl::adoptBuffer ( const std::string &  theBuffer,
const std::string &  thePrefix = "" 
)

Adds the Key-Values pair in the given buffer to the current collection. Each key will be prefixed with the optional argument thePrefix.

◆ adoptCollection()

void dp3::common::ParameterSetImpl::adoptCollection ( const ParameterSetImpl theCollection,
const std::string &  thePrefix = "" 
)

Adds the Key-Values pair in the given collection to the current collection. Each key will be prefixed with the optional argument thePrefix.

◆ adoptFile()

void dp3::common::ParameterSetImpl::adoptFile ( const std::string &  theFilename,
const std::string &  thePrefix = "" 
)

Adds the Key-Values pair in the given file to the current collection. Each key will be prefixed with the optional argument thePrefix.

◆ fullModuleName()

std::string dp3::common::ParameterSetImpl::fullModuleName ( const std::string &  shortName) const

Searches the module name or module hierarchy and returns its fullposition. e.g: a.b.c.d.param=xxxx --> fullModuleName(d)-->a.b.c.d e.g: a.b.c.d.param=xxxx --> fullModuleName(b.c)-->a.b.c

◆ get()

const ParameterValue & dp3::common::ParameterSetImpl::get ( const std::string &  aKey) const
inline

Get the ParameterValue.

◆ getBool() [1/2]

bool dp3::common::ParameterSetImpl::getBool ( const std::string &  aKey) const
inline

Return scalar value.

◆ getBool() [2/2]

bool dp3::common::ParameterSetImpl::getBool ( const std::string &  aKey,
bool  aValue 
) const
inline

◆ getBoolVector() [1/2]

std::vector<bool> dp3::common::ParameterSetImpl::getBoolVector ( const std::string &  aKey,
bool  expandable 
) const

Return vector of values.

◆ getBoolVector() [2/2]

std::vector<bool> dp3::common::ParameterSetImpl::getBoolVector ( const std::string &  aKey,
const std::vector< bool > &  aValue,
bool  expandable 
) const

◆ getDouble() [1/2]

double dp3::common::ParameterSetImpl::getDouble ( const std::string &  aKey) const
inline

◆ getDouble() [2/2]

double dp3::common::ParameterSetImpl::getDouble ( const std::string &  aKey,
double  aValue 
) const
inline

◆ getDoubleVector() [1/2]

std::vector<double> dp3::common::ParameterSetImpl::getDoubleVector ( const std::string &  aKey,
bool  expandable 
) const

◆ getDoubleVector() [2/2]

std::vector<double> dp3::common::ParameterSetImpl::getDoubleVector ( const std::string &  aKey,
const std::vector< double > &  aValue,
bool  expandable 
) const

◆ getFloat() [1/2]

float dp3::common::ParameterSetImpl::getFloat ( const std::string &  aKey) const
inline

◆ getFloat() [2/2]

float dp3::common::ParameterSetImpl::getFloat ( const std::string &  aKey,
float  aValue 
) const
inline

◆ getFloatVector() [1/2]

std::vector<float> dp3::common::ParameterSetImpl::getFloatVector ( const std::string &  aKey,
bool  expandable 
) const

◆ getFloatVector() [2/2]

std::vector<float> dp3::common::ParameterSetImpl::getFloatVector ( const std::string &  aKey,
const std::vector< float > &  aValue,
bool  expandable 
) const

◆ getInt() [1/2]

int dp3::common::ParameterSetImpl::getInt ( const std::string &  aKey) const
inline

◆ getInt() [2/2]

int dp3::common::ParameterSetImpl::getInt ( const std::string &  aKey,
int  aValue 
) const
inline

◆ getInt16() [1/2]

int16_t dp3::common::ParameterSetImpl::getInt16 ( const std::string &  aKey) const
inline

◆ getInt16() [2/2]

int16_t dp3::common::ParameterSetImpl::getInt16 ( const std::string &  aKey,
int16_t  aValue 
) const
inline

◆ getInt16Vector() [1/2]

std::vector<int16_t> dp3::common::ParameterSetImpl::getInt16Vector ( const std::string &  aKey,
bool  expandable 
) const

◆ getInt16Vector() [2/2]

std::vector<int16_t> dp3::common::ParameterSetImpl::getInt16Vector ( const std::string &  aKey,
const std::vector< int16_t > &  aValue,
bool  expandable 
) const

◆ getInt32() [1/2]

int32_t dp3::common::ParameterSetImpl::getInt32 ( const std::string &  aKey) const
inline

◆ getInt32() [2/2]

int32_t dp3::common::ParameterSetImpl::getInt32 ( const std::string &  aKey,
int32_t  aValue 
) const
inline

◆ getInt32Vector() [1/2]

std::vector<int32_t> dp3::common::ParameterSetImpl::getInt32Vector ( const std::string &  aKey,
bool  expandable 
) const

◆ getInt32Vector() [2/2]

std::vector<int32_t> dp3::common::ParameterSetImpl::getInt32Vector ( const std::string &  aKey,
const std::vector< int32_t > &  aValue,
bool  expandable 
) const

◆ getInt64() [1/2]

int64_t dp3::common::ParameterSetImpl::getInt64 ( const std::string &  aKey) const
inline

◆ getInt64() [2/2]

int64_t dp3::common::ParameterSetImpl::getInt64 ( const std::string &  aKey,
int64_t  aValue 
) const
inline

◆ getInt64Vector() [1/2]

std::vector<int64_t> dp3::common::ParameterSetImpl::getInt64Vector ( const std::string &  aKey,
bool  expandable 
) const

◆ getInt64Vector() [2/2]

std::vector<int64_t> dp3::common::ParameterSetImpl::getInt64Vector ( const std::string &  aKey,
const std::vector< int64_t > &  aValue,
bool  expandable 
) const

◆ getIntVector() [1/2]

std::vector<int> dp3::common::ParameterSetImpl::getIntVector ( const std::string &  aKey,
bool  expandable 
) const

◆ getIntVector() [2/2]

std::vector<int> dp3::common::ParameterSetImpl::getIntVector ( const std::string &  aKey,
const std::vector< int > &  aValue,
bool  expandable 
) const

◆ getString() [1/2]

std::string dp3::common::ParameterSetImpl::getString ( const std::string &  aKey) const
inline

◆ getString() [2/2]

std::string dp3::common::ParameterSetImpl::getString ( const std::string &  aKey,
const std::string &  aValue 
) const
inline

◆ getStringVector() [1/2]

std::vector<std::string> dp3::common::ParameterSetImpl::getStringVector ( const std::string &  aKey,
bool  expandable 
) const

◆ getStringVector() [2/2]

std::vector<std::string> dp3::common::ParameterSetImpl::getStringVector ( const std::string &  aKey,
const std::vector< std::string > &  aValue,
bool  expandable 
) const

◆ getTime() [1/2]

time_t dp3::common::ParameterSetImpl::getTime ( const std::string &  aKey) const
inline

Returns the value as a time value (seconds since 1970).

◆ getTime() [2/2]

time_t dp3::common::ParameterSetImpl::getTime ( const std::string &  aKey,
const time_t &  aValue 
) const
inline

◆ getTimeVector() [1/2]

std::vector<time_t> dp3::common::ParameterSetImpl::getTimeVector ( const std::string &  aKey,
bool  expandable 
) const

◆ getTimeVector() [2/2]

std::vector<time_t> dp3::common::ParameterSetImpl::getTimeVector ( const std::string &  aKey,
const std::vector< time_t > &  aValue,
bool  expandable 
) const

◆ getUint() [1/2]

unsigned int dp3::common::ParameterSetImpl::getUint ( const std::string &  aKey) const
inline

◆ getUint() [2/2]

unsigned int dp3::common::ParameterSetImpl::getUint ( const std::string &  aKey,
unsigned int  aValue 
) const
inline

◆ getUint16() [1/2]

uint16_t dp3::common::ParameterSetImpl::getUint16 ( const std::string &  aKey) const
inline

◆ getUint16() [2/2]

uint16_t dp3::common::ParameterSetImpl::getUint16 ( const std::string &  aKey,
uint16_t  aValue 
) const
inline

◆ getUint16Vector() [1/2]

std::vector<uint16_t> dp3::common::ParameterSetImpl::getUint16Vector ( const std::string &  aKey,
bool  expandable 
) const

◆ getUint16Vector() [2/2]

std::vector<uint16_t> dp3::common::ParameterSetImpl::getUint16Vector ( const std::string &  aKey,
const std::vector< uint16_t > &  aValue,
bool  expandable 
) const

◆ getUint32() [1/2]

uint32_t dp3::common::ParameterSetImpl::getUint32 ( const std::string &  aKey) const
inline

◆ getUint32() [2/2]

uint32_t dp3::common::ParameterSetImpl::getUint32 ( const std::string &  aKey,
uint32_t  aValue 
) const
inline

◆ getUint32Vector() [1/2]

std::vector<uint32_t> dp3::common::ParameterSetImpl::getUint32Vector ( const std::string &  aKey,
bool  expandable 
) const

◆ getUint32Vector() [2/2]

std::vector<uint32_t> dp3::common::ParameterSetImpl::getUint32Vector ( const std::string &  aKey,
const std::vector< uint32_t > &  aValue,
bool  expandable 
) const

◆ getUint64() [1/2]

uint64_t dp3::common::ParameterSetImpl::getUint64 ( const std::string &  aKey) const
inline

◆ getUint64() [2/2]

uint64_t dp3::common::ParameterSetImpl::getUint64 ( const std::string &  aKey,
uint64_t  aValue 
) const
inline

◆ getUint64Vector() [1/2]

std::vector<uint64_t> dp3::common::ParameterSetImpl::getUint64Vector ( const std::string &  aKey,
bool  expandable 
) const

◆ getUint64Vector() [2/2]

std::vector<uint64_t> dp3::common::ParameterSetImpl::getUint64Vector ( const std::string &  aKey,
const std::vector< uint64_t > &  aValue,
bool  expandable 
) const

◆ getUintVector() [1/2]

std::vector<unsigned int> dp3::common::ParameterSetImpl::getUintVector ( const std::string &  aKey,
bool  expandable 
) const

◆ getUintVector() [2/2]

std::vector<unsigned int> dp3::common::ParameterSetImpl::getUintVector ( const std::string &  aKey,
const std::vector< unsigned int > &  aValue,
bool  expandable 
) const

◆ isDefined()

bool dp3::common::ParameterSetImpl::isDefined ( const std::string &  searchKey) const
inline

Checks if the given Key is defined in the ParameterSetImpl.

◆ keyCompareMode()

KeyCompare::Mode dp3::common::ParameterSetImpl::keyCompareMode ( ) const
inline

Return the key comparison mode.

◆ locateModule()

std::string dp3::common::ParameterSetImpl::locateModule ( const std::string &  shortName) const

Searches for a module whose name end in the given modulename. e.g: a.b.c.d.param=xxx ; locateModule('d') --> 'a.b.c.'

◆ makeSubset()

std::shared_ptr<ParameterSetImpl> dp3::common::ParameterSetImpl::makeSubset ( const std::string &  baseKey,
const std::string &  prefix = "" 
) const

Creates a subset from the current ParameterSetImpl containing all parameters starting with the given baseKey. The baseKey is cut off from the Keynames in the created subset, the optional prefix is put before all keys in the subset.

◆ remove()

void dp3::common::ParameterSetImpl::remove ( const std::string &  aKey)

Removes the pair with the given key. Removing a non-existing key is ok.

◆ replace()

void dp3::common::ParameterSetImpl::replace ( const std::string &  aKey,
const ParameterValue aValue 
)

Replaces the given pair in the collection. If aKey does not exist in the collection the pair is just added to the collection.

◆ subtractSubset()

void dp3::common::ParameterSetImpl::subtractSubset ( const std::string &  fullPrefix)

Subtract a subset from the current ParameterSet. Every parameter whose key starts with the given name will be removed from the ParameterSet.

◆ unusedKeys()

std::vector<std::string> dp3::common::ParameterSetImpl::unusedKeys ( ) const

Get all unused parameter names.

◆ writeBuffer()

void dp3::common::ParameterSetImpl::writeBuffer ( std::string &  theBuffer) const

Writes the Key-Values pair from the current ParCollection to the string buffer.

◆ writeFile()

void dp3::common::ParameterSetImpl::writeFile ( const std::string &  theFilename,
bool  append = false 
) const

Writes the Key-Values pair from the current ParCollection to the file.

◆ writeStream()

void dp3::common::ParameterSetImpl::writeStream ( std::ostream &  os) const

Write the Key-Value pairs from the current ParCollection to the output stream.

Friends And Related Function Documentation

◆ operator<<

std::ostream& operator<< ( std::ostream &  os,
const ParameterSetImpl thePS 
)
friend

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