DParameterChoice.h

Classes

DParameterChoice -- Implementation of DisplayParameter to store choice parameters. (full description)

class DParameterChoice : public DisplayParameter

Interface

Public Members
DParameterChoice(const String name, const String description, const String help, const Vector<String> &options, const String defaultvalue, const String value, const String context = "", const Bool editable = False)
DParameterChoice(const DParameterChoice &other)
virtual ~DParameterChoice()
DParameterChoice &operator=(const DParameterChoice &other)
virtual Bool fromRecord(const RecordInterface &record)
virtual void toRecord(RecordInterface &record, const Bool fullrecord = True, const Bool overwrite = False)
Vector<String> options() const
String defaultValue()
String value()
void setEditable(const Bool editable)
void setOptions(const Vector<String> &options)
void setDefaultValue(const String defaultvalue)
void setValue(const String value)
const String& operator=(const String &value)
Bool existsOption(const String value)
Protected Members
DParameterChoice()

Description

Prerequisite

Etymology

DParameterChoice is an implementation of a DisplayParameter providing a choice parameter type.

Synopsis

This class is derived from DisplayParameter and provides a choice-type parameter. Choice parameters simply have a vector of possible String selections, and a default selection. They cannot be unset.

Example

A DParameterChoice can easily be used to store and update any parameter which can be expressed as a selection from two or more options. In the following example, a DParameterChoice is constructed to provide the name of the font to use in axis labelling:

    Vector<String> fonts(4);
    fonts(0) = "roman";
    // ...
    DParameterChoice pchoice("font", "Label font", 
                             "Select the font to use for axis labelling",
                             fonts, fonts(0), fonts(0));
    
    // ...
    
    // update the parameter from some Record
    pchoice.fromRecord(rec);
    
    // examine the value of the parameter
    if (pchoice.value() == "italic") {
    // ...
    }
    

Motivation

Many parameters are naturally choices, or can be expressed as choices, hence this class.

Thrown Exceptions

To Do

Member Description

DParameterChoice(const String name, const String description, const String help, const Vector<String> &options, const String defaultvalue, const String value, const String context = "", const 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. Obviously the defaultvalue and value parameters must exist in the list of allowed options, otherwise an exception is thrown.

DParameterChoice(const DParameterChoice &other)

(Required) copy constructor.

virtual ~DParameterChoice()

Destructor.

DParameterChoice &operator=(const DParameterChoice &other)

(Required) copy assignment.

virtual Bool fromRecord(const RecordInterface &record)

Parse record, and update this parameter if a field exists whose name matches that of this parameter. Return True if the parameter is changed, otherwise return False.

virtual void toRecord(RecordInterface &record, const Bool fullrecord = True, const Bool overwrite = False)

Place a record describing this parameter in a sub-field of record with name matching that of this parameter. If overwrite is True, then any existing field with matching name will be overwritten. If fullrecord is True, then a complete description of the parameter is given, otherwise just its current value is stored in record. Presently fullrecord is ignored.

Vector<String> options() const

Return the list of allowed options for this parameter.

String defaultValue()

Return the default for this parameter.

String value()

Return the current value of this parameter.

void setEditable(const Bool editable)

Set or change if this parameter is editable (determines wether choice or userchoice is returned in the record

void setOptions(const Vector<String> &options)

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

void setDefaultValue(const String defaultvalue)

Set or change the default value for this parameter.

void setValue(const String value)

Set or change the current value.

const String& operator=(const String &value)

Convenient syntax to set (only) the value.

Bool existsOption(const String value)

Determine whether this value exists in the list of options.

DParameterChoice()

(Required) default constructor.