casa  $Rev:20696$
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
Public Member Functions | Protected Member Functions | Private Member Functions | Private Attributes
casa::DParameterMapKeyChoice Class Reference

Implementation of DParameterChoice to store parameter and associated key. More...

#include <DParameterMapKeyChoice.h>

Inheritance diagram for casa::DParameterMapKeyChoice:
casa::DParameterChoice casa::DisplayParameter

List of all members.

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.
DParameterMapKeyChoiceoperator= (const DParameterMapKeyChoice &other)
 (Required) copy assignment.
Vector< Intkeys () 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< IntitsKeys
 Store for the allowed options for this parameter.
Int itsKeyValue
String itsLastString

Detailed Description

Implementation of DParameterChoice to store parameter and associated key.

Intended use:

Public interface

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

Definition at line 113 of file DParameterMapKeyChoice.h.


Constructor & Destructor Documentation

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.

Destructor.

(Required) default constructor.


Member Function Documentation

Return the list of all keys for this parameter.

Definition at line 143 of file DParameterMapKeyChoice.h.

References itsKeys.

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.

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.


Member Data Documentation

Store for the allowed options for this parameter.

Definition at line 173 of file DParameterMapKeyChoice.h.

Referenced by keys().

Definition at line 174 of file DParameterMapKeyChoice.h.

Definition at line 175 of file DParameterMapKeyChoice.h.

Referenced by setOptions().


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