casa  5.7.0-16
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
DParameterChoice.h
Go to the documentation of this file.
1 //# DParameterChoice.h: class to store and retrieve casacore::Choice parameters
2 //# Copyright (C) 2000,2001
3 //# Associated Universities, Inc. Washington DC, USA.
4 //#
5 //# This library is free software; you can redistribute it and/or modify it
6 //# under the terms of the GNU Library General Public License as published by
7 //# the Free Software Foundation; either version 2 of the License, or (at your
8 //# option) any later version.
9 //#
10 //# This library is distributed in the hope that it will be useful, but WITHOUT
11 //# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 //# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
13 //# License for more details.
14 //#
15 //# You should have received a copy of the GNU Library General Public License
16 //# along with this library; if not, write to the Free Software Foundation,
17 //# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA.
18 //#
19 //# Correspondence concerning AIPS++ should be addressed as follows:
20 //# Internet email: aips2-request@nrao.edu.
21 //# Postal address: AIPS++ Project Office
22 //# National Radio Astronomy Observatory
23 //# 520 Edgemont Road
24 //# Charlottesville, VA 22903-2475 USA
25 //#
26 //# $Id$
27 
28 #ifndef TRIALDISPLAY_DPARAMETERCHOICE_H
29 #define TRIALDISPLAY_DPARAMETERCHOICE_H
30 
31 #include <casa/aips.h>
32 #include <casa/Arrays/Vector.h>
35 
36 namespace casa { //# NAMESPACE CASA - BEGIN
37 
38 // <summary>
39 // Implementation of DisplayParameter to store choice parameters.
40 // </summary>
41 
42 // <use visibility=export>
43 
44 // <reviewed reviewer="" date="" test="" demos="">
45 // </reviewed>
46 
47 // <prerequisite>
48 // <li> <linkto class=DisplayParameter>DisplayParameter</linkto>
49 // </prerequisite>
50 
51 // <etymology>
52 // DParameterChoice is an implementation of a DisplayParameter
53 // providing a choice parameter type.
54 // </etymology>
55 
56 // <synopsis>
57 // This class is derived from <linkto
58 // class=DisplayParameter>DisplayParameter</linkto> and provides a
59 // choice-type parameter. casacore::Choice parameters simply have a vector
60 // of possible casacore::String selections, and a default selection. They
61 // cannot be unset.
62 // </synopsis>
63 
64 // <example>
65 
66 // A DParameterChoice can easily be used to store and update any
67 // parameter which can be expressed as a selection from two or more
68 // options. In the following example, a DParameterChoice is
69 // constructed to provide the name of the font to use in axis
70 // labelling:
71 // <srcblock>
72 // casacore::Vector<casacore::String> fonts(4);
73 // fonts(0) = "roman";
74 // // ...
75 // DParameterChoice pchoice("font", "Label font",
76 // "Select the font to use for axis labelling",
77 // fonts, fonts(0), fonts(0));
78 //
79 // // ...
80 //
81 // // update the parameter from some Record
82 // pchoice.fromRecord(rec);
83 //
84 // // examine the value of the parameter
85 // if (pchoice.value() == "italic") {
86 // // ...
87 // }
88 // </srcblock>
89 // </example>
90 
91 // <motivation>
92 // Many parameters are naturally choices, or can be expressed as
93 // choices, hence this class.
94 // </motivation>
95 
96 // <thrown>
97 // <li> None.
98 // </thrown>
99 
100 // <todo asof="2000/01/31">
101 // <li> Nothing known.
102 // </todo>
103 
105 
106  public:
107 
108  // Constructor taking the name of the parameter, a short
109  // description, some help text, a list of allowed options, a default
110  // value, an initial value, the context of the parameter, and a flag
111  // indicating whether the parameter is editable. Obviously the
112  // <src>defaultvalue</src> and <src>value</src> parameters must
113  // exist in the list of allowed options, otherwise an exception
114  // is thrown.
117  const casacore::String defaultvalue, const casacore::String value,
118  const casacore::String context = "", const casacore::Bool editable = false);
119  DParameterChoice(const casacore::String name, const casacore::String description,
120  const casacore::String help, const ColormapDefinition::colormapnamemap &options,
121  const casacore::String defaultvalue, const casacore::String value,
122  const casacore::String context = "", const casacore::Bool editable = false);
123 
124  // (Required) copy constructor.
125  DParameterChoice(const DParameterChoice &other);
126 
127  // Destructor.
128  virtual ~DParameterChoice();
129 
130  // (Required) copy assignment.
132 
133  // Parse <src>record</src>, and update this parameter if a field
134  // exists whose name matches that of this parameter. Return
135  // <src>true</src> if the parameter is changed, otherwise return
136  // <src>false</src>.
137  virtual casacore::Bool fromRecord(const casacore::RecordInterface &record);
138 
139  // Place a record describing this parameter in a sub-field of
140  // <src>record</src> with name matching that of this parameter. If
141  // <src>overwrite</src> is <src>true</src>, then any existing field
142  // with matching name will be overwritten. If <src>fullrecord</src>
143  // is <src>true</src>, then a complete description of the parameter
144  // is given, otherwise just its current value is stored in
145  // <src>record</src>. Presently <src>fullrecord</src> is ignored.
146  virtual void toRecord(casacore::RecordInterface &record, const casacore::Bool fullrecord = true,
147  const casacore::Bool overwrite = false);
148 
149  // Return the list of allowed options for this parameter.
151  return itsOptions;
152  }
153 
154  // Return the default for this parameter.
156  return itsDefaultValue;
157  }
158 
159  // Return the current value of this parameter.
161  return itsValue;
162  }
163 
164  // Set or change if this parameter is editable (determines wether
165  // choice or userchoice is returned in the record
168  }
169 
170  // Set or change the list of allowed options for this parameter.
173  }
174 
175  // Set or change the default value for this parameter.
176  void setDefaultValue(const casacore::String defaultvalue) {
177  itsDefaultValue = defaultvalue;
178  }
179 
180  // Set or change the current value.
181  void setValue(const casacore::String value) {
182  itsValue = value;
183  }
184 
185  // Convenient syntax to set (only) the value.
187  itsValue = value;
188  return value;
189  }
190 
191  // Determine whether this value exists in the list of options.
193 
194  protected:
195 
196  // (Required) default constructor.
198 
199  private:
200 
202  // Store for the allowed options for this parameter.
204 
205  // Store for the default of this parameter.
207 
208  // Store for the value of this parameter.
210 
211  };
212 
213 
214 } //# NAMESPACE CASA - END
215 
216 #endif
casacore::String defaultValue()
Return the default for this parameter.
casacore::String name() const
Return the name of this parameter.
casacore::Bool existsOption(const casacore::String value)
Determine whether this value exists in the list of options.
casacore::String itsValue
Store for the value of this parameter.
void setValue(const casacore::String value)
Set or change the current value.
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...
const casacore::String & operator=(const casacore::String &value)
Convenient syntax to set (only) the value.
std::map< casacore::String, bool > colormapnamemap
Return the names of the built-in colormaps.
casacore::Bool itsEditable
DParameterChoice & operator=(const DParameterChoice &other)
(Required) copy assignment.
void setDefaultValue(const casacore::String defaultvalue)
Set or change the default value for this parameter.
casacore::String help() const
Return the help for this parameter.
casacore::Vector< casacore::String > itsOptions
Store for the allowed options for this parameter.
casacore::String description() const
Return the description of this parameter.
DParameterChoice()
(Required) default constructor.
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 par...
casacore::Bool editable() const
Return whether this parameter is editable.
casacore::String context() const
Return the context of this parameter.
bool Bool
Define the standard types used by Casacore.
Definition: aipstype.h:42
void setEditable(const casacore::Bool editable)
Set or change if this parameter is editable (determines wether choice or userchoice is returned in th...
Implementation of DisplayParameter to store choice parameters.
void setOptions(const casacore::Vector< casacore::String > &options)
Set or change the list of allowed options for this parameter.
casacore::Vector< casacore::String > options() const
Return the list of allowed options for this parameter.
casacore::String value()
Return the current value of this parameter.
String: the storage and methods of handling collections of characters.
Definition: String.h:223
virtual ~DParameterChoice()
Destructor.
Abstract base class for Record classes.
casacore::String itsDefaultValue
Store for the default of this parameter.
Base class for storing and parsing of parameters for display classes.