Template Class Parameter

Class Documentation

template<typename T>
class Parameter

General parameter type for member variables of a pre-specified class.

A Parameter is a templatised construct that formally defines an interface to a simple type embedded in a class.

Usage:

Definition:

class A {
    public:
        Parameter<int> counter;
};
and usage (like get/set, but much less verbose):
int main() {
    A a;
    a.counter(1); // <-- Sets the variable.
    a.counter = 1; // <-- This is also ok.
    cout << a.counter(); << endl; // <-- Gets the variable.
}

See also

src/test/core/parameters.cpp, Parameters

Public Functions

inline explicit Parameter()
inline Parameter(const T &value)

Configures the parameter with the type’s default value. Configures the parameter with a specified value.

Parameters:

value – : the value to instantiate the parameter with.

inline virtual ~Parameter()
inline void operator=(const T &value)

Allow assignment from the underlying type.

Note that this does not help with conversions for construction (or in argument passing to functions, because that is construction also).

Parameters:

value – : the value to configure the internal variable with.

inline operator const T&() const

Convenience operator so that it can be treated as a normal variable if you wish (i.e. no () call needed). Note that we do not permit the returned reference to be modified as doing so would mean this class loses control of the variable.

Returns:

T& : a const reference to the parameter’s variable.

inline const T &operator()() const

Formal access to the parameter’s variable. Note that we do not permit the returned reference to be modified as doing so would mean this class loses control of the variable.

Returns:

T& : a reference to the parameter’s variable.

inline void operator()(const T &value)

Formal setting operator for the parameter’s variable. Note that we dont need the reference here since we’re copying into the private variable - you get the same number of constructions either way.

Parameters:

value – : the value to configure the internal variable with.