casa  5.7.0-16
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Public Member Functions | Protected Member Functions | Private Member Functions | Private Attributes | List of all members
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

Public Member Functions

 DParameterMapKeyChoice (const casacore::String name, const casacore::String description, const casacore::String help, const casacore::Vector< casacore::String > &options, const casacore::Vector< casacore::Int > &keys, const casacore::String defaultvalue, const casacore::String value, const casacore::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. More...
 
 DParameterMapKeyChoice (const DParameterMapKeyChoice &other)
 (Required) copy constructor. More...
 
virtual ~DParameterMapKeyChoice ()
 Destructor. More...
 
DParameterMapKeyChoiceoperator= (const DParameterMapKeyChoice &other)
 (Required) copy assignment. More...
 
casacore::Vector< casacore::Intkeys () const
 Return the list of all keys for this parameter. More...
 
casacore::Int keyValue ()
 Return the current value of this parameter. More...
 
void setOptions (const casacore::Vector< casacore::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. More...
 
casacore::Bool setKeyValue (const casacore::Int newValue)
 Set the current value, based on a key. More...
 
void setKeys (const casacore::Vector< casacore::Int > &newKeys)
 Set or change the list of allowed options for this parameter. More...
 
- Public Member Functions inherited from casa::DParameterChoice
 DParameterChoice (const casacore::String name, const casacore::String description, const casacore::String help, const casacore::Vector< casacore::String > &options, const casacore::String defaultvalue, const casacore::String value, const casacore::String context="", const casacore::Bool editable=false)
 Constructor taking the name of the parameter, a short description, some help text, a list of allowed options, a default value, an initial value, the context of the parameter, and a flag indicating whether the parameter is editable. More...
 
 DParameterChoice (const casacore::String name, const casacore::String description, const casacore::String help, const ColormapDefinition::colormapnamemap &options, const casacore::String defaultvalue, const casacore::String value, const casacore::String context="", const casacore::Bool editable=false)
 
 DParameterChoice (const DParameterChoice &other)
 (Required) copy constructor. More...
 
virtual ~DParameterChoice ()
 Destructor. More...
 
DParameterChoiceoperator= (const DParameterChoice &other)
 (Required) copy assignment. More...
 
virtual casacore::Bool fromRecord (const casacore::RecordInterface &record)
 Parse record, and update this parameter if a field exists whose name matches that of this parameter. More...
 
virtual void toRecord (casacore::RecordInterface &record, const casacore::Bool fullrecord=true, const casacore::Bool overwrite=false)
 Place a record describing this parameter in a sub-field of record with name matching that of this parameter. More...
 
casacore::Vector
< casacore::String
options () const
 Return the list of allowed options for this parameter. More...
 
casacore::String defaultValue ()
 Return the default for this parameter. More...
 
casacore::String value ()
 Return the current value of this parameter. More...
 
void setEditable (const casacore::Bool editable)
 Set or change if this parameter is editable (determines wether choice or userchoice is returned in the record. More...
 
void setOptions (const casacore::Vector< casacore::String > &options)
 Set or change the list of allowed options for this parameter. More...
 
void setDefaultValue (const casacore::String defaultvalue)
 Set or change the default value for this parameter. More...
 
void setValue (const casacore::String value)
 Set or change the current value. More...
 
const casacore::Stringoperator= (const casacore::String &value)
 Convenient syntax to set (only) the value. More...
 
casacore::Bool existsOption (const casacore::String value)
 Determine whether this value exists in the list of options. More...
 
- Public Member Functions inherited from casa::DisplayParameter
virtual ~DisplayParameter ()
 Destructor. More...
 
casacore::String name () const
 Return the name of this parameter. More...
 
casacore::String description () const
 Return the description of this parameter. More...
 
casacore::String help () const
 Return the help for this parameter. More...
 
casacore::String context () const
 Return the context of this parameter. More...
 
casacore::Bool allowUnset () const
 Return whether this parameter can be unset. More...
 
casacore::Bool editable () const
 Return whether this parameter is editable. More...
 
void setName (const casacore::String name)
 Set or change the name of this parameter to that specified. More...
 
void setDescription (const casacore::String description)
 Set or change the description of this parameter to what is specified. More...
 
void setHelp (const casacore::String help)
 Set or change the help for this parameter to what is specified. More...
 
void setContext (const casacore::String context)
 Set or change the context of this parameter to what is specified. More...
 
void setAllowUnset (const casacore::Bool allowunset)
 Set or change whether this parameter may be unset, according to the function argument value. More...
 
void setEditable (const casacore::Bool editable)
 Set or change whether this parameter is editable according to the function argument. More...
 

Protected Member Functions

 DParameterMapKeyChoice ()
 (Required) default constructor. More...
 
- Protected Member Functions inherited from casa::DParameterChoice
 DParameterChoice ()
 (Required) default constructor. More...
 
- Protected Member Functions inherited from casa::DisplayParameter
 DisplayParameter (const casacore::String name, const casacore::String description, const casacore::String help, const casacore::String context="", const casacore::Bool allowunset=false, const casacore::Bool editable=true)
 Constructor taking the name of the parameter, a short description, some help text, and flags indicating whether the parameter can be unset and is editable. More...
 
 DisplayParameter (const DisplayParameter &other)
 Copy constructor using copy semantics. More...
 
 DisplayParameter ()
 Default constructor yielding a useless DisplayParameter. More...
 
DisplayParameteroperator= (const DisplayParameter &other)
 Copy assignment. More...
 
casacore::Record baseDescription ()
 Return a basic description of this parameter; used by virtual implementations of toRecord method to fill out a casacore::Record describing this DisplayParameter. More...
 
const DisplayOptionsdisplayOptions () const
 Return the DisplayOptions to use for parsing Records. More...
 

Private Member Functions

casacore::Bool lookUpKey (const casacore::String &value)
 Lookup the key based on the string provided. More...
 

Private Attributes

casacore::Vector< casacore::IntitsKeys
 Store for the allowed options for this parameter. More...
 
casacore::Int itsKeyValue
 
casacore::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.

myStrings(0) = "Ten";
myStrings(1) = "Twenty";
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 casacore::Record (casacore::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 casacore::String  name,
const casacore::String  description,
const casacore::String  help,
const casacore::Vector< casacore::String > &  options,
const casacore::Vector< casacore::Int > &  keys,
const casacore::String  defaultvalue,
const casacore::String  value,
const casacore::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.

casa::DParameterMapKeyChoice::DParameterMapKeyChoice ( const DParameterMapKeyChoice other)

(Required) copy constructor.

virtual casa::DParameterMapKeyChoice::~DParameterMapKeyChoice ( )
virtual

Destructor.

casa::DParameterMapKeyChoice::DParameterMapKeyChoice ( )
protected

(Required) default constructor.

Member Function Documentation

casacore::Vector<casacore::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.

casacore::Int casa::DParameterMapKeyChoice::keyValue ( )
casacore::Bool casa::DParameterMapKeyChoice::lookUpKey ( const casacore::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 casacore::Vector< casacore::Int > &  newKeys)

Set or change the list of allowed options for this parameter.

casacore::Bool casa::DParameterMapKeyChoice::setKeyValue ( const casacore::Int  newValue)

Set the current value, based on a key.

void casa::DParameterMapKeyChoice::setOptions ( const casacore::Vector< casacore::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.

Definition at line 153 of file DParameterMapKeyChoice.h.

References itsLastString, and casa::DParameterChoice::setOptions().

Member Data Documentation

casacore::Vector<casacore::Int> casa::DParameterMapKeyChoice::itsKeys
private

Store for the allowed options for this parameter.

Definition at line 174 of file DParameterMapKeyChoice.h.

Referenced by keys().

casacore::Int casa::DParameterMapKeyChoice::itsKeyValue
private

Definition at line 175 of file DParameterMapKeyChoice.h.

casacore::String casa::DParameterMapKeyChoice::itsLastString
private

Definition at line 176 of file DParameterMapKeyChoice.h.

Referenced by setOptions().


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