DParameterMapKeyChoice.h

Classes

DParameterMapKeyChoice -- Implementation of DParameterChoice to store parameter and associated key (full description)

class DParameterMapKeyChoice : public DParameterChoice

Interface

Public Members
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 = "")
DParameterMapKeyChoice(const DParameterMapKeyChoice &other)
virtual ~DParameterMapKeyChoice()
DParameterMapKeyChoice &operator=(const DParameterMapKeyChoice &other)
Vector<Int> keys() const
Int keyValue()
void setOptions(const Vector<String>& newOptions)
Bool setKeyValue(const Int newValue)
void setKeys (const Vector<Int>& newKeys)
Protected Members
DParameterMapKeyChoice()
Private Members
Bool lookUpKey(const String& value)

Description

Prerequisite

Etymology

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.

Synopsis

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.

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

To Do

Member Description

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.

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.

DParameterMapKeyChoice()

(Required) default constructor.

Bool lookUpKey(const String& value)

Lookup the key based on the string provided