A key-value pair that can be saved to a file on the disk. More...
#include <Preference.h>
Public Types | |
| enum class | Type { Bool , String , Int , UInt , Double , Float } |
| The type of the value in the key-value pair. More... | |
Public Member Functions | |
| Preference (const std::string &key, Type type) | |
| Constructor. More... | |
| template<typename T > | |
| Preference (const std::string &key, Type type, T value, const std::string &description="") | |
| Constructor. More... | |
| template<typename T > | |
| void | setValue (T value) |
| Set the value of the preference. More... | |
| bool | hasValue () const |
| Check if the preference has a value or not. More... | |
| template<typename T > | |
| T | getValue () const |
| Get the value of the preference. More... | |
| Type | getType () const |
| Get the type of the preference. More... | |
| const std::string & | getKey () const |
| Get the key/name of the preference. More... | |
| void | setDescription (const std::string &description) |
| Set the text to be displayed above the key-value pair. More... | |
| const std::string & | getDescription () const |
| Get the preference description. More... | |
A key-value pair that can be saved to a file on the disk.
A Preference is very similar to a Property. What sets them apart is that a Preference can only store objects whose type are known to it whereas a Property can store objects of any type. In addition, the contents of a Preference can be saved to a file on the disk
Definition at line 43 of file Preference.h.
|
strong |
The type of the value in the key-value pair.
| Enumerator | |
|---|---|
| Bool | bool |
| String | std::string type (NOT "const char*") |
| Int | int |
| UInt | unsigned int |
| Double | double |
| Float | float |
Definition at line 48 of file Preference.h.
| ime::Preference::Preference | ( | const std::string & | key, |
| Type | type | ||
| ) |
Constructor.
| key | The unique identifier of the preference |
| type | The type of the value in the key-value pair |
Note that once set, the key and type of the preference cannot be changed later
| ime::Preference::Preference | ( | const std::string & | key, |
| Type | type, | ||
| T | value, | ||
| const std::string & | description = "" |
||
| ) |
Constructor.
| key | The unique identifier of the preference |
| type | The type of the value in the key-value pair |
| value | The value of the preference |
| description | An optional message describing the key-value pair |
| InvalidArgumentException | If the type of the value argument does not correspond to the type specified by type argument |
Note that once set, the key and type cannot be changed later.
A description is an optional short message describing what the preference is. When saved to the disk, it will be preceded by a hashtag sign (#), indicating that it is a comment
| const std::string & ime::Preference::getDescription | ( | ) | const |
Get the preference description.
| const std::string & ime::Preference::getKey | ( | ) | const |
Get the key/name of the preference.
| Type ime::Preference::getType | ( | ) | const |
Get the type of the preference.
| T ime::Preference::getValue | ( | ) | const |
Get the value of the preference.
| InvalidArgumentException | if T is not the same as the ime::Preference::Type given in the constructor or the preference does not have a value |
| bool ime::Preference::hasValue | ( | ) | const |
Check if the preference has a value or not.
| void ime::Preference::setDescription | ( | const std::string & | description | ) |
Set the text to be displayed above the key-value pair.
| description | The description to be set |
A description is an optional short message describing what the preference is. When saved to the disk, it will be preceded by a hashtag sign (#), indicating that it is a comment
By default, the description is an empty string
| void ime::Preference::setValue | ( | T | value | ) |
Set the value of the preference.
| value | The value to be set |
| InvalidArgumentException | if the type of value does not correspond to the ime::Preference::Type given in the constructor |