![]() |
IOFormat 1.12.0
|
A map of heterogeneous options. More...
#include <ioformat/OptionMap.h>
Inherited by ioformat::GeneralOptions.
Classes | |
| class | iterator |
| An iterator on OptionMap keys. More... | |
Public Member Functions | |
| OptionMap (const OptionMap &other) | |
| OptionMap & | operator= (const OptionMap &other) |
| OptionMap (OptionMap &&other) noexcept | |
| OptionMap & | operator= (OptionMap &&other) noexcept |
| size_t | size () const |
| Get the number of element in the option map. | |
| bool | empty () const |
| Check if the option map is empty. | |
| bool | has (const std::string &key) const |
| Check if a key is present. | |
| iolink::DataType | dtype (const std::string &key) const |
| Get the option data type. | |
| size_t | count (const std::string &key) const |
| Get the number of values associated with a key. | |
| void | remove (const std::string &key) |
| Remove a key from the option map. | |
| std::string | toString () const |
| Get a string representation of the option map. | |
| bool | getBool (const std::string &key) const |
| Get a boolean value. | |
| const std::string & | getString (const std::string &key) const |
| Get a string value. | |
| const int64_t * | getIntPtr (const std::string &key) const |
| Get a pointer to the integer array first value. | |
| int64_t | getInt (const std::string &key, size_t index) const |
| Get the integer value at a given index. | |
| int64_t | getInt (const std::string &key) const |
| Get an integer value. | |
| const double * | getFloatPtr (const std::string &key) const |
| Get a pointer to the float array first value. | |
| double | getFloat (const std::string &key, size_t index) const |
| Get the float value at the given index. | |
| double | getFloat (const std::string &key) const |
| Get a float value. | |
| void | setBool (const std::string &key, bool value) |
| Associate a boolean value with a specific key. | |
| void | setString (const std::string &key, const std::string &value) |
| Associate a string value with a specific key. | |
| void | setInt (const std::string &key, const int64_t *values, size_t count) |
| Associate an integer array with a specific key. | |
| void | setInt (const std::string &key, int64_t value) |
| Associate an integer value with a specific key. | |
| void | setFloat (const std::string &key, const double *values, size_t count) |
| Associate a float array with a specific key. | |
| void | setFloat (const std::string &key, double value) |
| Associate a float value with a specific key. | |
| iterator | begin () const |
| Get an iterator on the beginning of the option map. | |
| iterator | end () const |
| Get an iterator on the end of the option map. | |
A map of heterogeneous options.
This container stores a map of options values that can handle a variety of types:
The numeric types can handle multiple values per key, while the others only handle one.
When getting a value, the type is checked and an error is thrown if the wrong method is used. For exemple using OptionMap::GetString on an integer value.
When setting a value, if the key already exists it will be erased and replaced by the new value. No check is done on the type of the previous value.
| size_t ioformat::OptionMap::count | ( | const std::string & | key | ) | const |
Get the number of values associated with a key.
Boolean and string values will always return one, while numeric values will return the number of elements in the array.
| key | The key to fetch. |
| InvalidArgument | if the key is not present. |
| iolink::DataType ioformat::OptionMap::dtype | ( | const std::string & | key | ) | const |
Get the option data type.
| key | The key to fetch. |
| InvalidArgument | if the key is not present. |
| bool ioformat::OptionMap::getBool | ( | const std::string & | key | ) | const |
Get a boolean value.
| key | The key to fetch. |
| InvalidArgument | if the key is not present. |
| Error | if the value is not a boolean. |
| double ioformat::OptionMap::getFloat | ( | const std::string & | key | ) | const |
Get a float value.
This shortcut method return the first element of the array.
| key | The key to fetch. |
| InvalidArgument | if the key is not present. |
| Error | if the value is not a float. |
| double ioformat::OptionMap::getFloat | ( | const std::string & | key, |
| size_t | index | ||
| ) | const |
Get the float value at the given index.
| key | The key to fetch. |
| index | The index of the value in the array. |
| InvalidArgument | if the key is not present. |
| InvalidArgument | if the index is out of bounds. |
| Error | if the value is not a float. |
| const double * ioformat::OptionMap::getFloatPtr | ( | const std::string & | key | ) | const |
Get a pointer to the float array first value.
| key | The key to fetch. |
| InvalidArgument | if the key is not present. |
| Error | if the value is not a float. |
| int64_t ioformat::OptionMap::getInt | ( | const std::string & | key | ) | const |
Get an integer value.
This shortcut method return the first element of the array.
| key | The key to fetch. |
| InvalidArgument | if the key is not present. |
| Error | if the value is not an integer. |
| int64_t ioformat::OptionMap::getInt | ( | const std::string & | key, |
| size_t | index | ||
| ) | const |
Get the integer value at a given index.
| key | The key to fetch. |
| index | The index of the value in the array. |
| InvalidArgument | if the key is not present. |
| InvalidArgument | if the index is out of bounds. |
| Error | if the value is not an integer. |
| const int64_t * ioformat::OptionMap::getIntPtr | ( | const std::string & | key | ) | const |
Get a pointer to the integer array first value.
| key | The key to fetch. |
| InvalidArgument | if the key is not present. |
| Error | if the value is not an integer. |
| const std::string & ioformat::OptionMap::getString | ( | const std::string & | key | ) | const |
Get a string value.
| key | The key to fetch. |
| InvalidArgument | if the key is not present. |
| Error | if the value is not a string. |
| bool ioformat::OptionMap::has | ( | const std::string & | key | ) | const |
Check if a key is present.
| key | The key to check |
| void ioformat::OptionMap::remove | ( | const std::string & | key | ) |
Remove a key from the option map.
| key | The key to remove. |
| InvalidArgument | if the key is not present. |
| void ioformat::OptionMap::setBool | ( | const std::string & | key, |
| bool | value | ||
| ) |
Associate a boolean value with a specific key.
| key | The key to set. |
| value | The value to set. |
| void ioformat::OptionMap::setFloat | ( | const std::string & | key, |
| const double * | values, | ||
| size_t | count | ||
| ) |
Associate a float array with a specific key.
| key | The key to set. |
| values | The values to set. |
| count | The number of values to set. |
| void ioformat::OptionMap::setFloat | ( | const std::string & | key, |
| double | value | ||
| ) |
Associate a float value with a specific key.
This shortcut method set a single value.
| key | The key to set. |
| value | The value to set. |
| void ioformat::OptionMap::setInt | ( | const std::string & | key, |
| const int64_t * | values, | ||
| size_t | count | ||
| ) |
Associate an integer array with a specific key.
| key | The key to set. |
| values | The values to set. |
| count | The number of values to set. |
| void ioformat::OptionMap::setInt | ( | const std::string & | key, |
| int64_t | value | ||
| ) |
Associate an integer value with a specific key.
This shortcut method set a single value.
| key | The key to set. |
| value | The value to set. |
| void ioformat::OptionMap::setString | ( | const std::string & | key, |
| const std::string & | value | ||
| ) |
Associate a string value with a specific key.
| key | The key to set. |
| value | The value to set. |