Registry

class Registry_Exception : public std::logic_error
#include <registry.h>

The base exception class thrown by the registry.

It is derived from the STL logic_error exception.

Subclassed by Registry_Key_not_found_Exception

Public Functions

inline explicit Registry_Exception(const std::string &err_msg)

Construct exception with error message.

Parameters:

err_msg – The error message.

class Registry_Key_not_found_Exception : public Registry_Exception
#include <registry.h>

The exception when the desired key is not found.

Subclassed by Registry_Block_Data_not_found_Exception, Registry_Block_not_found_Exception, Registry_cfgfile_not_found_Exception

Public Functions

inline explicit Registry_Key_not_found_Exception(const std::string &err_msg)

The Exception when a requested key is not found.

Parameters:

err_msg – The error message of which key is not found.

class Registry_Block_Data_not_found_Exception : public Registry_Key_not_found_Exception
#include <registry.h>

The exception when the requested data in a block is not present.

Public Functions

inline explicit Registry_Block_Data_not_found_Exception(const std::string &key_value)

Construct an exception when the data was not found.

Parameters:

key_value – which key was not found.

inline ~Registry_Block_Data_not_found_Exception()

Public Members

const std::string block_key

to denote the block where no data was found

class Registry_Block_not_found_Exception : public Registry_Key_not_found_Exception
#include <registry.h>

The exception when the requested block is not present.

Public Functions

inline explicit Registry_Block_not_found_Exception(const std::string &key_value)

Construct an exception where a block was not found.

Parameters:

key_value – the block which has not been found.

inline ~Registry_Block_not_found_Exception()

Public Members

const std::string block

which block has not been found.

class Registry_cfgfile_not_found_Exception : public Registry_Key_not_found_Exception
#include <registry.h>

The exception when the requested config file could not be found.

Public Functions

inline explicit Registry_cfgfile_not_found_Exception(const std::string &key_value)

Construct the respective exception when a file was not found.

Parameters:

key_value – Which config file could not be found.

inline ~Registry_cfgfile_not_found_Exception()

Public Members

const std::string cfgfile

which config file was not found.

class Block
#include <registry.h>

This class contains the contents of a [BLOCK] structure in a config file.

In Config Files those [BLOCK] thingies.

Public Functions

inline Block()

Create an empty block.

Block(std::string blockname, const std::vector<std::string> &block)

Create a block from a vector of strings.

Parameters:
  • blockname – The name of the block.

  • block – a vector of strings.

inline unsigned int size(void) const

Get the number of keys that we store.

Returns:

the number of keys that we store.

inline const std::vector<std::string> GetKeys() const

Get the list of keys that we store.

Returns:

The list of keys that we store.

inline std::string &operator[](const std::string &key)

Get access to the contents of a block.

This distinguishes itself from find() by doing no checks.

Parameters:

key – the key for which to look.

Returns:

the value of the key.

inline std::string &find(const std::string &key)

Get access to the contents of a block.

non-const version. In contrast to operator[] this perform checking.

Parameters:

key – the key for which to look.

Throws:

Registry_Block_Data_not_found_Exception – If the key was not found

Returns:

the value of the key.

inline const std::string &find(const std::string &key) const

Get access to the contents of a block.

constified version. In contrast to operator[] this perform checking.

Parameters:

key – the key for which to look.

Throws:

Registry_Block_Data_not_found_Exception – If the key was not found

Returns:

the value of the key.

inline ~Block()

Clean up a block.

Private Functions

void push_back_Key(std::string arg)

Add a key-value pair.

Parameters:

arg – Add this key-value pair.

Private Members

std::map<std::string, std::string> Block_Data

A map between the keys and their values.

std::string BlockName

The name of the block.

std::vector<std::string> Keys

all keys that have been found.

std::map<std::string, std::string>::size_type NrOfKeys

the number of key-value pairs that we have.

class cfile
#include <registry.h>

This class contains the contents of a single config file.

Public Functions

inline cfile()

Default constructor.

inline Block &operator[](std::string a)

Get access to the contents of a file.

This distinguishes itself from find() by doing no checks.

Parameters:

a – the block for which to look.

Returns:

A block that can be queried further.

inline Block &find(const std::string &key)

Get access to the contents of a file.

non-const version. In contrast to operator[] this perform checking.

Parameters:

key – the file for which to look.

Returns:

the blocks of the file.

inline const Block &find(const std::string &key) const

Get access to the contents of a file.

const version. In contrast to operator[] this perform checking.

Parameters:

key – the file for which to look.

Returns:

the blocks of the file.

cfile(std::string &file)

Constructor that initializes this with the contents of a config-file.

Parameters:

file – The file that we should parse.

Private Members

std::string filename

the filename

std::map<std::string, Block> cfgfile

The map between files and their internal blocks.

class RegistryDB
#include <registry.h>

This holds together all the contents of the configuration directory and provides access via the Get() template.

Public Functions

int init(const std::string &cfgDir, const std::string pat = "")

Initialize registry.

This initializes the registry via a separate function call.

Parameters:
  • cfgDir – the directory that contains all the files the registry should contain

  • pat – a suffix to select only certain files, e.g. : .ini

RegistryDB(const std::string &arg, const std::string pat = "")

construct the registry.

This is the constructor for the registry.

Parameters:
  • arg – the directory that contains all the files the registry should contain

  • pat – a suffix to select only certain files, e.g. : .ini

inline RegistryDB()

Empty default constructor.

inline ~RegistryDB()

Tidy up everything.

inline Block GetBlock(std::string file, std::string bloc)

Get a particular block in a file of the Registry.

Parameters:
  • file – the file in which to look.

  • bloc – the bloc we require.

Returns:

the requested block.

template<typename T>
inline T Get(const std::string &file, const std::string &block, const std::string &key) const

Function to get a value from the registry.

The template parameter determines to which type to convert the key.

Template Parameters:

T – to which type do we convert.

Parameters:
  • file – the file in which to look

  • block – under which block is the value

  • key – for which key to look

Returns:

the requested key

template<typename T>
inline T set(const std::string &file, const std::string &block, const std::string &key, T val)

A function for setting values in the registry.

Private Members

std::map<std::string, cfile> Reg

The map containing all config files.

template<typename A>
struct GetTrait
#include <registry.h>

The helper template for performing string -> type conversions.

The basic template for doing the conversion between strings and the requested type. We use the C++ stringstreams thus we benefit from all overloads that are already provided by C++.

Template Parameters:

A – to which type do we want to convert.

Public Static Functions

static inline A Convert(std::string arg)

Helper function to convert from a string to the requested type.

Parameters:

arg – a string that should represent something.

Returns:

Hopefully, the successfully converted object.

template<>
struct GetTrait<bool>
#include <registry.h>

The helper template for performing string -> bool conversion.

Specialization for boolean(true, false) like strings

Public Static Functions

static inline bool Convert(std::string arg)

Helper function to convert from a string to a boolean value.

Every occurence of uppercase/lowercase mixing of TRUE is interpreted as true, everything else is false.

Returns:

boolean true, if the string was [Tt][Rr][Uu][Ee]

template<typename A>
struct SetTrait
#include <registry.h>

A helper template to set values in the registry.

Template Parameters:

A – the type of the value.

Public Static Functions

static inline std::string convert(A arg)

Convert a type to its textual representation.

Parameters:

arg – The value we want to write.

Returns:

a textual representation of arg.

template<typename T>
struct GetTrait<std::vector<T>>
#include <registry.h>

A helper trait for reading vectors of values with a predefined separator.

The predefined separator is currently hard-coded to “;” or “,”.

Template Parameters:

T – the type of the elements in the vector.

Public Static Functions

static inline std::vector<T> Convert(std::string &arg)

Implementation function for the conversion.

Parameters:

arg – the string that we intend to break up.

Returns:

the converted values stored in a C++ std::vector .

template<>
struct GetTrait<std::vector<std::string>>
#include <registry.h>

A helper trait for reading vectors of strings with a predefined separator.

The predefined separator is currently hard-coded to “;” or “,”.

Template Parameters:

T – the type of the elements in the vector.

Public Static Functions

static inline std::vector<std::string> Convert(std::string arg)

Implementation function for the conversion.

Parameters:

arg – the string that we intend to break up.

Returns:

the strings stored in a C++ std::vector .