STAPL API Reference          
Overview   Containers   Algorithms   Views   Skeletons   Run-Time System
Modules     Classes    
List of all members | Public Member Functions | Public Types | Friends

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 >
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.
 

Detailed Description

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:

option opts = option("key1", int(2)) & option("key2", "object");

You can also pass the argc and argv from main() using the following:

option opts = option(argc, argv) & option("key2", "object");

Constructor & Destructor Documentation

◆ option() [1/2]

stapl::option::option ( key_type const &  key,
const char *  s 
)

Creates a new option object with the string associated with the key.

Parameters
keyKey to add to the map of options.
sString to associate with the key.

◆ option() [2/2]

template<typename T >
stapl::option::option ( key_type const &  key,
T &&  t 
)

Creates a new option object with the object associated with the key.

Parameters
keyKey to add to the map of options.
tObject to associate with the key.

Member Function Documentation

◆ try_get_noenv()

template<typename T >
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.

Template Parameters
TType of the object associated with the key.

This function will not attempt return an option from the environment.

Parameters
keyKey of the required option.
tSpace to save the object that is associated with the key.
Returns
true if the key exists in the map and the object saved to t, otherwise false.

◆ try_get()

template<typename T >
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.

Template Parameters
TType of the object associated with the key.

This function will attempt to return an option from the environment.

Parameters
keyKey of the required option.
tSpace to save the object that is associated with the key.
Returns
true if the key exists in the map and the object saved to t, otherwise false.

◆ get() [1/2]

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.

Parameters
keyKey of the required option.
default_valueString to return if the key is not in the options map or the environment.
Returns
The string associated with the key.

◆ get() [2/2]

template<typename T >
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.

Template Parameters
TType of the object associated with the key.

This function will attempt to return an option from the environment.

Parameters
keyKey of the required option.
default_valueObject to return if the key is not in the options map or the environment.
Returns
The object associated with the key.

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