CGRA-ME
Public Types | Public Member Functions | Private Member Functions | Private Attributes | Friends | List of all members
ConfigStore Class Reference

#include <ConfigStore.h>

Public Types

using BackingStore = std::map< std::string, std::string >
 

Public Member Functions

 ConfigStore ()=default
 
 ConfigStore (BackingStore src)
 
 ConfigStore (std::initializer_list< std::pair< std::string, ImplicitlyToString >> ilist)
 Flexible constructor that converts everything value it is given to a string. More...
 
 ConfigStore (const ConfigStore &)=default
 
ConfigStoreoperator= (const ConfigStore &)=default
 
 ConfigStore (ConfigStore &&)=default
 
ConfigStoreoperator= (ConfigStore &&)=default
 
bool addString (std::string key, std::string value)
 
bool addInt (std::string key, long long value)
 
bool addReal (std::string key, double value)
 
bool addBool (std::string key, bool value)
 
void setString (std::string key, std::string value)
 
void setInt (std::string key, long long value)
 
void setReal (std::string key, double value)
 
void setBool (std::string key, bool value)
 
const std::string & getString (const std::string &key) const
 
long long getInt (const std::string &key) const
 
double getReal (const std::string &key) const
 
bool getBool (const std::string &key) const
 
const std::string & getStringOr (const std::string &key, const std::string &otherwise) const
 
std::string getStringOr (const std::string &key, std::string &&otherwise) const
 
long long getIntOr (const std::string &key, long long otherwise) const
 
double getRealOr (const std::string &key, double otherwise) const
 
bool getBoolOr (const std::string &key, bool otherwise) const
 
bool hasKey (const std::string &key) const
 
auto begin () const
 
auto end () const
 
bool empty () const
 
bool operator== (const ConfigStore &rhs) const
 
bool operator!= (const ConfigStore &rhs) const
 

Private Member Functions

std::invalid_argument makeIncompleteConversionException (const std::string &key, const std::string &value) const
 

Private Attributes

BackingStore backing_store = {}
 

Friends

std::ostream & operator<< (std::ostream &os, const ConfigStore &cs)
 

Detailed Description

A class that helps with storing things like INI settings or other simple key-value data. Provides convenience conversions from the stored string data and supports in-code defaults.

Definition at line 76 of file ConfigStore.h.

Member Typedef Documentation

◆ BackingStore

using ConfigStore::BackingStore = std::map<std::string, std::string>

Definition at line 78 of file ConfigStore.h.

Constructor & Destructor Documentation

◆ ConfigStore() [1/5]

ConfigStore::ConfigStore ( )
default

◆ ConfigStore() [2/5]

ConfigStore::ConfigStore ( BackingStore  src)
inline

Definition at line 82 of file ConfigStore.h.

◆ ConfigStore() [3/5]

ConfigStore::ConfigStore ( std::initializer_list< std::pair< std::string, ImplicitlyToString >>  ilist)
inline

Flexible constructor that converts everything value it is given to a string.

Keys must be string due to ambiguity (eg. what is a canonical conversion for bools?), and not having a clear use-case.

Ex.:

{"0", false},
{"1", "1"},
{"two", 2},
{"3", std::string("3")},
{"4", returnsBool(arg4)},
{"five", returnsInt(arg5)},
};

Definition at line 104 of file ConfigStore.h.

◆ ConfigStore() [4/5]

ConfigStore::ConfigStore ( const ConfigStore )
default

◆ ConfigStore() [5/5]

ConfigStore::ConfigStore ( ConfigStore &&  )
default

Member Function Documentation

◆ addBool()

bool ConfigStore::addBool ( std::string  key,
bool  value 
)
inline

Definition at line 123 of file ConfigStore.h.

◆ addInt()

bool ConfigStore::addInt ( std::string  key,
long long  value 
)
inline

Definition at line 121 of file ConfigStore.h.

◆ addReal()

bool ConfigStore::addReal ( std::string  key,
double  value 
)
inline

Definition at line 122 of file ConfigStore.h.

◆ addString()

bool ConfigStore::addString ( std::string  key,
std::string  value 
)
inline

Inserts value under the key key. Does not overwrite.

Definition at line 120 of file ConfigStore.h.

◆ begin()

auto ConfigStore::begin ( ) const
inline

Definition at line 213 of file ConfigStore.h.

◆ empty()

bool ConfigStore::empty ( ) const
inline

Definition at line 215 of file ConfigStore.h.

◆ end()

auto ConfigStore::end ( ) const
inline

Definition at line 214 of file ConfigStore.h.

◆ getBool()

bool ConfigStore::getBool ( const std::string &  key) const
inline

Definition at line 166 of file ConfigStore.h.

◆ getBoolOr()

bool ConfigStore::getBoolOr ( const std::string &  key,
bool  otherwise 
) const
inline

Definition at line 201 of file ConfigStore.h.

◆ getInt()

long long ConfigStore::getInt ( const std::string &  key) const
inline

Definition at line 146 of file ConfigStore.h.

◆ getIntOr()

long long ConfigStore::getIntOr ( const std::string &  key,
long long  otherwise 
) const
inline

Definition at line 191 of file ConfigStore.h.

◆ getReal()

double ConfigStore::getReal ( const std::string &  key) const
inline

Definition at line 156 of file ConfigStore.h.

◆ getRealOr()

double ConfigStore::getRealOr ( const std::string &  key,
double  otherwise 
) const
inline

Definition at line 196 of file ConfigStore.h.

◆ getString()

const std::string& ConfigStore::getString ( const std::string &  key) const
inline

The simple getters. Throw exceptions if the key is not found.

Definition at line 136 of file ConfigStore.h.

◆ getStringOr() [1/2]

const std::string& ConfigStore::getStringOr ( const std::string &  key,
const std::string &  otherwise 
) const
inline

The defaulted getters. Return the second argument if the key has no value.

Definition at line 181 of file ConfigStore.h.

◆ getStringOr() [2/2]

std::string ConfigStore::getStringOr ( const std::string &  key,
std::string &&  otherwise 
) const
inline

Definition at line 186 of file ConfigStore.h.

◆ hasKey()

bool ConfigStore::hasKey ( const std::string &  key) const
inline

Returns true iff key has a value

Definition at line 209 of file ConfigStore.h.

◆ makeIncompleteConversionException()

std::invalid_argument ConfigStore::makeIncompleteConversionException ( const std::string &  key,
const std::string &  value 
) const
inlineprivate

Definition at line 240 of file ConfigStore.h.

◆ operator!=()

bool ConfigStore::operator!= ( const ConfigStore rhs) const
inline

Definition at line 220 of file ConfigStore.h.

◆ operator=() [1/2]

ConfigStore& ConfigStore::operator= ( ConfigStore &&  )
default

◆ operator=() [2/2]

ConfigStore& ConfigStore::operator= ( const ConfigStore )
default

◆ operator==()

bool ConfigStore::operator== ( const ConfigStore rhs) const
inline

Definition at line 217 of file ConfigStore.h.

◆ setBool()

void ConfigStore::setBool ( std::string  key,
bool  value 
)
inline

Definition at line 131 of file ConfigStore.h.

◆ setInt()

void ConfigStore::setInt ( std::string  key,
long long  value 
)
inline

Definition at line 129 of file ConfigStore.h.

◆ setReal()

void ConfigStore::setReal ( std::string  key,
double  value 
)
inline

Definition at line 130 of file ConfigStore.h.

◆ setString()

void ConfigStore::setString ( std::string  key,
std::string  value 
)
inline

Sets key to have the value value. Will overwrite.

Definition at line 128 of file ConfigStore.h.

Friends And Related Function Documentation

◆ operator<<

std::ostream& operator<< ( std::ostream &  os,
const ConfigStore cs 
)
friend

Print out the contents in a neat way.

Definition at line 225 of file ConfigStore.h.

Member Data Documentation

◆ backing_store

BackingStore ConfigStore::backing_store = {}
private

Definition at line 244 of file ConfigStore.h.


The documentation for this class was generated from the following file:
ConfigStore
Definition: ConfigStore.h:76