IOFormat 1.12.0
Loading...
Searching...
No Matches
ioformat::OptionMap Class Reference

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)
 
OptionMapoperator= (const OptionMap &other)
 
 OptionMap (OptionMap &&other) noexcept
 
OptionMapoperator= (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.
 

Detailed Description

A map of heterogeneous options.

This container stores a map of options values that can handle a variety of types:

  • Booleans
  • Character strings
  • Integers
  • Floating point numbers

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.

Member Function Documentation

◆ count()

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.

Parameters
keyThe key to fetch.
Exceptions
InvalidArgumentif the key is not present.

◆ dtype()

iolink::DataType ioformat::OptionMap::dtype ( const std::string &  key) const

Get the option data type.

Parameters
keyThe key to fetch.
Exceptions
InvalidArgumentif the key is not present.

◆ getBool()

bool ioformat::OptionMap::getBool ( const std::string &  key) const

Get a boolean value.

Parameters
keyThe key to fetch.
Exceptions
InvalidArgumentif the key is not present.
Errorif the value is not a boolean.

◆ getFloat() [1/2]

double ioformat::OptionMap::getFloat ( const std::string &  key) const

Get a float value.

This shortcut method return the first element of the array.

Parameters
keyThe key to fetch.
Exceptions
InvalidArgumentif the key is not present.
Errorif the value is not a float.

◆ getFloat() [2/2]

double ioformat::OptionMap::getFloat ( const std::string &  key,
size_t  index 
) const

Get the float value at the given index.

Parameters
keyThe key to fetch.
indexThe index of the value in the array.
Exceptions
InvalidArgumentif the key is not present.
InvalidArgumentif the index is out of bounds.
Errorif the value is not a float.

◆ getFloatPtr()

const double * ioformat::OptionMap::getFloatPtr ( const std::string &  key) const

Get a pointer to the float array first value.

Parameters
keyThe key to fetch.
Exceptions
InvalidArgumentif the key is not present.
Errorif the value is not a float.

◆ getInt() [1/2]

int64_t ioformat::OptionMap::getInt ( const std::string &  key) const

Get an integer value.

This shortcut method return the first element of the array.

Parameters
keyThe key to fetch.
Exceptions
InvalidArgumentif the key is not present.
Errorif the value is not an integer.

◆ getInt() [2/2]

int64_t ioformat::OptionMap::getInt ( const std::string &  key,
size_t  index 
) const

Get the integer value at a given index.

Parameters
keyThe key to fetch.
indexThe index of the value in the array.
Exceptions
InvalidArgumentif the key is not present.
InvalidArgumentif the index is out of bounds.
Errorif the value is not an integer.

◆ getIntPtr()

const int64_t * ioformat::OptionMap::getIntPtr ( const std::string &  key) const

Get a pointer to the integer array first value.

Parameters
keyThe key to fetch.
Exceptions
InvalidArgumentif the key is not present.
Errorif the value is not an integer.

◆ getString()

const std::string & ioformat::OptionMap::getString ( const std::string &  key) const

Get a string value.

Parameters
keyThe key to fetch.
Exceptions
InvalidArgumentif the key is not present.
Errorif the value is not a string.

◆ has()

bool ioformat::OptionMap::has ( const std::string &  key) const

Check if a key is present.

Parameters
keyThe key to check

◆ remove()

void ioformat::OptionMap::remove ( const std::string &  key)

Remove a key from the option map.

Parameters
keyThe key to remove.
Exceptions
InvalidArgumentif the key is not present.

◆ setBool()

void ioformat::OptionMap::setBool ( const std::string &  key,
bool  value 
)

Associate a boolean value with a specific key.

Parameters
keyThe key to set.
valueThe value to set.

◆ setFloat() [1/2]

void ioformat::OptionMap::setFloat ( const std::string &  key,
const double *  values,
size_t  count 
)

Associate a float array with a specific key.

Parameters
keyThe key to set.
valuesThe values to set.
countThe number of values to set.

◆ setFloat() [2/2]

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.

Parameters
keyThe key to set.
valueThe value to set.

◆ setInt() [1/2]

void ioformat::OptionMap::setInt ( const std::string &  key,
const int64_t *  values,
size_t  count 
)

Associate an integer array with a specific key.

Parameters
keyThe key to set.
valuesThe values to set.
countThe number of values to set.

◆ setInt() [2/2]

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.

Parameters
keyThe key to set.
valueThe value to set.

◆ setString()

void ioformat::OptionMap::setString ( const std::string &  key,
const std::string &  value 
)

Associate a string value with a specific key.

Parameters
keyThe key to set.
valueThe value to set.

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