DParameterChoice and provides a
choice-type parameter. The string selection correspond to a "key"
selection. It is desgined for use with, for example, an enum. In such a
case, each string value can have an associated integer value which
can be cast to / from a enum.
Example
A DParameterMapKeyChoice can easily be used to store and update any
parameter which can be expressed as a selection from two or more
options.
Vector<String> myStrings(2);
myStrings(0) = "Ten";
myStrings(1) = "Twenty";
Vector<Int> myInts(2);
myInts(0) = 10;
myInts(1) = 20;
// ...
DParameterMapKeyChoice mchoice("number", "Choose a number of ...",
"Select the number of ... to use for ...",
myStrings, myInts,
myStrings(0), myStrings(0));
// ...
// update the parameter from some Record (String representation);
mchoice.fromRecord(rec);
// examine the value of the parameter
cerr << "You have selected " << mchoice.value() << " things." << endl;
// ...
itsNumberThings = mchoice.keyValue();
Motivation
Often at C++ level, parameters will be described by enums etc.
At glish level however, it is often required for these parameters
to be displayed as text options. This class is designed to make that
process easier. It can also be used more generally to associate any key
with a text option.
Thrown Exceptions
- Throws AipsErrors if number of keys do not match number of options
or if there is a problem looking up a key.
To Do
- Template the class so a "key" can be anything.
Member Description
Constructor taking the name of the parameter, a short
description, some help text, the enum which is to form
the basis of the options (must have an overloaded ostream <<
operator), a vector of integers corresponding to the options
within that enum, a default value, an initial value, and the
context of the parameter. Obviously the
defaultvalue and value parameters must
exist in the list of allowed options, otherwise an exception
is thrown.
(Required) copy constructor.
Destructor.
DParameterMapKeyChoice &operator=(const DParameterMapKeyChoice &other)
(Required) copy assignment.
Return the list of all keys for this parameter.
Return the current value of this parameter.
Thise function has very little implementation, it is here so if
a user changes the list of options, we can ensure we do not make a
mistake when looking up its corresponding key
Bool setKeyValue(const Int newValue)
Set the current value, based on a key.
void setKeys (const Vector<Int>& newKeys)
Set or change the list of allowed options for this parameter.
(Required) default constructor.
Lookup the key based on the string provided