Used to create a list of options. More...
Public Member Functions | |
option (int &argc, char **&argv) | |
Creates a new option object with the argc and argv from a main() function. | |
option (key_type const &key, const char *s) | |
Creates a new option object with the string associated with the key. More... | |
template<typename T > | |
option (key_type const &key, T &&t) | |
Creates a new option object with the object associated with the key. More... | |
bool | has_argv (void) const noexcept |
int & | get_argc (void) const noexcept |
char **& | get_argv (void) const noexcept |
size_type | count (key_type const &key) const noexcept |
size_type | count (const char *key) const noexcept |
template<typename T > | |
bool | try_get_noenv (key_type const &key, T &t) const |
Returns the value associated with the key if it is in the options map. More... | |
template<typename T > | |
bool | try_get (key_type const &key, T &t) const |
Returns the object associated with the key if it is in the options map. More... | |
const char * | get (key_type const &key, const char *default_value) const |
Returns the C string associated with the key if it is in the options map or the default value if it is not. More... | |
template<typename T > | |
T | get (key_type const &key, T const &default_value) const |
Returns the object associated with the key if it is in the options map or the default value if it is not. More... | |
void | merge (option const &other) |
Merges *this with other , to create a bigger option map. | |
Public Types | |
typedef map_type::key_type | key_type |
typedef map_type::size_type | size_type |
Friends | |
option | operator & (option const &x, option y) |
Merges x with y , to create a bigger option map. | |
Used to create a list of options.
The option object is a map of keys and objects. The objects can be retrieved with the key, but they have to be cast to the right type. Depending on the function, if the object does not exist, a default value can be returned or a value from the environment.
You can create a list of options by combining multiple option objects:
You can also pass the argc
and argv
from main()
using the following:
stapl::option::option | ( | key_type const & | key, |
const char * | s | ||
) |
Creates a new option object with the string associated with the key.
key | Key to add to the map of options. |
s | String to associate with the key . |
stapl::option::option | ( | key_type const & | key, |
T && | t | ||
) |
Creates a new option object with the object associated with the key.
key | Key to add to the map of options. |
t | Object to associate with the key . |
bool stapl::option::try_get_noenv | ( | key_type const & | key, |
T & | t | ||
) | const |
Returns the value associated with the key if it is in the options map.
T | Type of the object associated with the key. |
This function will not attempt return an option from the environment.
key | Key of the required option. |
t | Space to save the object that is associated with the key. |
true
if the key exists in the map and the object saved to t
, otherwise false
. bool stapl::option::try_get | ( | key_type const & | key, |
T & | t | ||
) | const |
Returns the object associated with the key if it is in the options map.
T | Type of the object associated with the key. |
This function will attempt to return an option from the environment.
key | Key of the required option. |
t | Space to save the object that is associated with the key. |
true
if the key exists in the map and the object saved to t
, otherwise false
. const char* stapl::option::get | ( | key_type const & | key, |
const char * | default_value | ||
) | const |
Returns the C string associated with the key if it is in the options map or the default value if it is not.
This function will attempt to return an option from the environment.
key | Key of the required option. |
default_value | String to return if the key is not in the options map or the environment. |
T stapl::option::get | ( | key_type const & | key, |
T const & | default_value | ||
) | const |
Returns the object associated with the key if it is in the options map or the default value if it is not.
T | Type of the object associated with the key. |
This function will attempt to return an option from the environment.
key | Key of the required option. |
default_value | Object to return if the key is not in the options map or the environment. |