casa
$Rev:20696$
|
Implementation of DParameterChoice to store parameter and associated key. More...
#include <DParameterMapKeyChoice.h>
Public Member Functions | |
DParameterMapKeyChoice (const String name, const String description, const String help, const Vector< String > &options, const Vector< Int > &keys, const String defaultvalue, const String value, const String context="") | |
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. | |
DParameterMapKeyChoice (const DParameterMapKeyChoice &other) | |
(Required) copy constructor. | |
virtual | ~DParameterMapKeyChoice () |
Destructor. | |
DParameterMapKeyChoice & | operator= (const DParameterMapKeyChoice &other) |
(Required) copy assignment. | |
Vector< Int > | keys () const |
Return the list of all keys for this parameter. | |
Int | keyValue () |
Return the current value of this parameter. | |
void | setOptions (const Vector< String > &newOptions) |
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. | |
Protected Member Functions | |
DParameterMapKeyChoice () | |
(Required) default constructor. | |
Private Member Functions | |
Bool | lookUpKey (const String &value) |
Lookup the key based on the string provided. | |
Private Attributes | |
Vector< Int > | itsKeys |
Store for the allowed options for this parameter. | |
Int | itsKeyValue |
String | itsLastString |
Implementation of DParameterChoice to store parameter and associated key.
Public interface
DParameterMapKeyChoice is an implementation of a DisplayParameter providing a choice parameter type. It also maintains a "key". eg it can associate a vector of strings with a vector of integers.
This class is derived from 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.
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();
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.
Definition at line 113 of file DParameterMapKeyChoice.h.
casa::DParameterMapKeyChoice::DParameterMapKeyChoice | ( | const String | name, |
const String | description, | ||
const String | help, | ||
const Vector< String > & | options, | ||
const Vector< Int > & | keys, | ||
const String | defaultvalue, | ||
const String | value, | ||
const String | context = "" |
||
) |
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.
virtual casa::DParameterMapKeyChoice::~DParameterMapKeyChoice | ( | ) | [virtual] |
Destructor.
casa::DParameterMapKeyChoice::DParameterMapKeyChoice | ( | ) | [protected] |
(Required) default constructor.
Vector<Int> casa::DParameterMapKeyChoice::keys | ( | ) | const [inline] |
Return the list of all keys for this parameter.
Definition at line 143 of file DParameterMapKeyChoice.h.
References itsKeys.
Return the current value of this parameter.
Referenced by casa::SkyCatOverlayDD::markerType(), casa::Profile2dDD::profileLineStyle(), and casa::Profile2dDD::regionStatType().
Bool casa::DParameterMapKeyChoice::lookUpKey | ( | const String & | value | ) | [private] |
Lookup the key based on the string provided.
DParameterMapKeyChoice& casa::DParameterMapKeyChoice::operator= | ( | const DParameterMapKeyChoice & | other | ) |
(Required) copy assignment.
void casa::DParameterMapKeyChoice::setKeys | ( | const Vector< Int > & | newKeys | ) |
Set or change the list of allowed options for this parameter.
Bool casa::DParameterMapKeyChoice::setKeyValue | ( | const Int | newValue | ) |
Set the current value, based on a key.
void casa::DParameterMapKeyChoice::setOptions | ( | const Vector< String > & | newOptions | ) | [inline] |
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.
Reimplemented from casa::DParameterChoice.
Definition at line 152 of file DParameterMapKeyChoice.h.
References itsLastString.
Vector<Int> casa::DParameterMapKeyChoice::itsKeys [private] |
Store for the allowed options for this parameter.
Definition at line 173 of file DParameterMapKeyChoice.h.
Referenced by keys().
Int casa::DParameterMapKeyChoice::itsKeyValue [private] |
Definition at line 174 of file DParameterMapKeyChoice.h.
Definition at line 175 of file DParameterMapKeyChoice.h.
Referenced by setOptions().