CAVAPA-GUI  30.5.2014
 All Classes Namespaces Functions Variables Typedefs Enumerations Pages
Public Types | Public Member Functions | Protected Attributes | List of all members
cavapa_gui::KeyValueCollection Class Reference

Represents a collection of key-value pairs. More...

#include <keyvaluecollection.h>

Inheritance diagram for cavapa_gui::KeyValueCollection:
cavapa_gui::Metadata cavapa_gui::Settings cavapa_gui::GeneralSettings cavapa_gui::SourceSettings

Public Types

using const_iterator = std::map< std::string, std::string >::const_iterator
 Provides a bidirectional iterator that can read a const element in the collection.
 

Public Member Functions

const_iterator begin () const
 Returns a const iterator to the beginning of the collection. More...
 
const_iterator end () const
 Returns a const iterator to the end of the collection. More...
 
std::string get (const std::string &name) const
 Gets the value of the specified key as a string. More...
 
bool getBool (const std::string &name) const
 Gets the value of the specified key as a bool. More...
 
QColor getColor (const std::string &name) const
 Gets the value of the specified key as a QColor. More...
 
QString getQString (const std::string &name) const
 Gets the value of the specified key as a QString. More...
 
double getDouble (const std::string &name) const
 Gets the value of the specified key as a double. More...
 
int getInt (const std::string &name) const
 Gets the value of the specified key as an integer. More...
 
template<typename ValueType , int N>
std::array< ValueType, N > getValues (const std::string &name) const
 Gets an array of values from the specified key. More...
 
void set (const std::string &name, const std::string &value)
 Sets the value of the specified key. More...
 
void setBool (const std::string &name, bool value)
 Sets the value of the specified key as a bool. More...
 
void setColor (const std::string &name, const QColor &value)
 Sets the value of the specified key as a QColor. More...
 
void setInt (const std::string &name, int value)
 Sets the value of the specified key as an int. More...
 
template<typename... T>
void setValues (const std::string &name, T...values)
 Sets the value of the specified key as an array. More...
 
void setQString (const std::string &name, const QString &value)
 Sets the value of the specified key as a QString. More...
 
bool trySet (const std::string &name, const std::string &value)
 Attempts to set the value of the specified key. More...
 

Protected Attributes

std::map< std::string,
std::string > 
keyValueMap
 Contains the key-value mappings in an std::map.
 

Detailed Description

Represents a collection of key-value pairs.

Author
Mika Lehtinen

Member Function Documentation

KeyValueCollection::const_iterator cavapa_gui::KeyValueCollection::begin ( ) const

Returns a const iterator to the beginning of the collection.

Returns
The const iterator.
KeyValueCollection::const_iterator cavapa_gui::KeyValueCollection::end ( ) const

Returns a const iterator to the end of the collection.

Returns
The const iterator.
std::string cavapa_gui::KeyValueCollection::get ( const std::string &  name) const

Gets the value of the specified key as a string.

Parameters
nameThe name of the key to be retrieved.
Returns
The value of the key as a string.
bool cavapa_gui::KeyValueCollection::getBool ( const std::string &  name) const

Gets the value of the specified key as a bool.

Parameters
nameThe name of the key to be retrieved.
Returns
The value of the key as a bool.
QColor cavapa_gui::KeyValueCollection::getColor ( const std::string &  name) const

Gets the value of the specified key as a QColor.

Parameters
nameThe name of the key to be retrieved.
Returns
The value of the key as a QColor.
double cavapa_gui::KeyValueCollection::getDouble ( const std::string &  name) const

Gets the value of the specified key as a double.

Parameters
nameThe name of the key to be retrieved.
Returns
The value of the key.
int cavapa_gui::KeyValueCollection::getInt ( const std::string &  name) const

Gets the value of the specified key as an integer.

Parameters
nameThe name of the key to be retrieved.
Returns
The value of the key.
QString cavapa_gui::KeyValueCollection::getQString ( const std::string &  name) const

Gets the value of the specified key as a QString.

Parameters
nameThe name of the key to be retrieved.
Returns
The value of the key.
template<typename ValueType , int N>
std::array<ValueType, N> cavapa_gui::KeyValueCollection::getValues ( const std::string &  name) const
inline

Gets an array of values from the specified key.

Parameters
nameThe name of the key to be retrieved.
Template Parameters
ValueTypeThe type of the values, either double or int.
NThe size of the array.
Returns
The values of the key as an array.
void cavapa_gui::KeyValueCollection::set ( const std::string &  name,
const std::string &  value 
)

Sets the value of the specified key.

Parameters
nameThe name of the key to be set.
valueThe value of the key.
void cavapa_gui::KeyValueCollection::setBool ( const std::string &  name,
bool  value 
)

Sets the value of the specified key as a bool.

Parameters
nameThe name of the key to be set.
valueThe value of the key as a bool.
void cavapa_gui::KeyValueCollection::setColor ( const std::string &  name,
const QColor &  value 
)

Sets the value of the specified key as a QColor.

Parameters
nameThe name of the key to be set.
valueThe value of the key as a QColor.
void cavapa_gui::KeyValueCollection::setInt ( const std::string &  name,
int  value 
)

Sets the value of the specified key as an int.

Parameters
nameThe name of the key to be set.
valueThe value of the key as an int.
void cavapa_gui::KeyValueCollection::setQString ( const std::string &  name,
const QString &  value 
)

Sets the value of the specified key as a QString.

Parameters
nameThe name of the key to be set.
valueThe value of the key as a QString.
template<typename... T>
void cavapa_gui::KeyValueCollection::setValues ( const std::string &  name,
T...  values 
)
inline

Sets the value of the specified key as an array.

Parameters
nameThe name of the key to be set.
valuesThe values.
Template Parameters
TThe type of the values, usually deduced automatically by the compiler.
bool cavapa_gui::KeyValueCollection::trySet ( const std::string &  name,
const std::string &  value 
)

Attempts to set the value of the specified key.

Parameters
nameThe name of the key to be set.
valueThe value of the key.
Returns
True if the value was successfully set, false otherwise.

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