Audio Processing Framework (APF)  version 0.3.0
Public Member Functions | List of all members
apf::parameter_map Struct Reference

A "dictionary" for parameters. More...

#include <apf/parameter_map.h>

Inherits std::map< K, T >.

Inherited by apf::MimoProcessor< Derived, interface_policy, thread_policy, query_policy >::Xput::Params.

Public Member Functions

template<typename... Args>
 parameter_map (Args &&...args)
 Constructor. More...
 
const std::string & operator[] (const std::string &k) const
 "Getter". More...
 
std::string & operator[] (const std::string &k)
 "Setter". More...
 
template<typename T >
get (const std::string &k, const T &def) const
 Get value converted to given type. More...
 
template<typename char_T >
std::basic_string< char_T > get (const std::string &k, const char_T *const def) const
 Overloaded function for character array (aka C-string). More...
 
template<typename T >
get (const std::string &k) const
 Throwing getter. More...
 
template<typename T >
const std::string & set (const std::string &k, const T &v)
 Set value. More...
 
bool has_key (const std::string &k) const
 Check if a given parameter is available. More...
 

Detailed Description

A "dictionary" for parameters.

All values are saved as std::string's.

Usage examples:

params.set("one", "first value");
params.set("two", 2);
params.set("three", 3.1415);
std::string val1, val5;
int val2, val3, val4;
val1 = params["one"];
val2 = params.get<int>("two");
val3 = params.get<int>("one"); // throws std::invalid_argument exception!
val4 = params.get("one", 42); // default value 42 if conversion fails
// template argument is deduced from 2nd arg
if (params.has_key("four"))
{
// this is not done because there is no key named "four":
do_something();
}
params["four"] = "42"; // throws std::out_of_range exception!
val5 = params["four"]; // throws std::out_of_range exception!
Examples:
audiofile_simpleprocessor.cpp, dummy_example.cpp, flext_simpleprocessor.cpp, jack_simpleprocessor.cpp, mex_simpleprocessor.cpp, and simpleprocessor.h.

Definition at line 65 of file parameter_map.h.

Constructor & Destructor Documentation

template<typename... Args>
apf::parameter_map::parameter_map ( Args &&...  args)
inlineexplicit

Constructor.

All parameters are forwarded to the std::map constructor.

Definition at line 71 of file parameter_map.h.

Member Function Documentation

const std::string& apf::parameter_map::operator[] ( const std::string &  k) const
inline

"Getter".

Parameters
kName of the parameter which should be retrieved.
Returns
const reference to the value referenced by k.
Exceptions
std::out_of_rangeif the key k doesn't exist. You should've checked beforehand with has_key() ...
See also
has_key(), get()

Definition at line 82 of file parameter_map.h.

Referenced by get().

std::string& apf::parameter_map::operator[] ( const std::string &  k)
inline

"Setter".

Well, not really. It just gives you a reference where you can assign stuff to.

Parameters
kName of the parameter which should be set. The parameter has to be in the map already, if not, an exception is thrown! If you want to add a new value, use set().
Returns
non-const reference to the value referenced by k. You can assign a std::string to actually set a new value.
Exceptions
std::out_of_rangeif the key k doesn't exist yet.
See also
has_key(), set()

Definition at line 104 of file parameter_map.h.

template<typename T >
T apf::parameter_map::get ( const std::string &  k,
const T &  def 
) const
inline

Get value converted to given type.

Template Parameters
TThe desired type. Can be omitted if def is specified.
Parameters
kName of the parameter which should be retrieved.
defDefault value for cases where conversion fails.
Returns
Value referenced by k, converted to type T. If the key k isn't available, or if the conversion failed, def is returned.
Warning
If the result is equal to the default value def, there is no way to know ...
  • if the key was available
  • if the conversion was successful
To check the former, you can use has_key(), for the latter you have to get the value as string (with operator[]()) and convert it yourself (e.g. with apf::str::S2A()). Or you can use the throwing version of get<T>().
Examples:
simpleprocessor.h.

Definition at line 133 of file parameter_map.h.

Referenced by apf::jack_policy::jack_policy().

template<typename char_T >
std::basic_string<char_T> apf::parameter_map::get ( const std::string &  k,
const char_T *const  def 
) const
inline

Overloaded function for character array (aka C-string).

This is mainly used to specify a string literal as default value, which wouldn't work with the other get() version, e.g.

params.set("id", "item42");
std::string id1, id2, name1, name2;
id1 = params.get("id" , "no_id_available"); // id1 = "item42";
id2 = params.get("id" , "item42"); // id2 = "item42";
name1 = params.get("name", "Default Name"); // name1 = "Default Name";
name2 = params.get("name", ""); // name2 = "";
Template Parameters
TThe given character type. Can be omitted if def is specified (which is normally the case!).
Parameters
kName of the parameter which should be retrieved.
defDefault value for cases where conversion fails.
Returns
Value referenced by k, converted to a std::basic_string<char_T>. If the key k isn't available, or if the conversion failed, def is returned.
Warning
Same warning as for the other get() version with default value.

Definition at line 172 of file parameter_map.h.

template<typename T >
T apf::parameter_map::get ( const std::string &  k) const
inline

Throwing getter.

Template Parameters
TDesired output type
Parameters
kName of the parameter which should be retrieved.
Exceptions
std::out_of_rangeif the key k is not available
std::invalid_argumentif the content cannot be converted to T

Definition at line 184 of file parameter_map.h.

References operator[]().

template<typename T >
const std::string& apf::parameter_map::set ( const std::string &  k,
const T &  v 
)
inline

Set value.

Template Parameters
TInput type
Parameters
kName of parameter to be set
vValue. Will be converted to std::string.
Returns
const reference to the std::string representation of v. If "" is returned, the conversion failed (or v was "" originally).
Examples:
audiofile_simpleprocessor.cpp, flext_simpleprocessor.cpp, and jack_simpleprocessor.cpp.

Definition at line 207 of file parameter_map.h.

References apf::str::A2S().

bool apf::parameter_map::has_key ( const std::string &  k) const
inline

Check if a given parameter is available.

Parameters
kThe parameter name
Returns
true if k is available

Definition at line 216 of file parameter_map.h.

Referenced by apf::jack_policy::jack_policy().


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