casa  5.7.0-16
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
DParameterMapKeyChoice.h
Go to the documentation of this file.
1 //# DParameterMapKeyChoice.h: class to store/retrieve a parameter and its key
2 //# Copyright (C) 2000,2001,2002
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_DPARAMETERMAPKEYCHOICE_H
29 #define TRIALDISPLAY_DPARAMETERMAPKEYCHOICE_H
30 
31 #include <casa/aips.h>
32 #include <casa/Arrays/Vector.h>
34 
35 namespace casa { //# NAMESPACE CASA - BEGIN
36 
37 // <summary>
38 // Implementation of DParameterChoice to store parameter and
39 // associated key
40 // </summary>
41 
42 // <use visibility=export>
43 
44 // <reviewed reviewer="" date="" test="" demos="">
45 // </reviewed>
46 
47 // <prerequisite>
48 // <li> <linkto class=DParameterChoice>DParameterChoice</linkto>
49 // </prerequisite>
50 
51 // <etymology>
52 // DParameterMapKeyChoice is an implementation of a DisplayParameter
53 // providing a choice parameter type. It also maintains a "key". eg it
54 // can associate a vector of strings with a vector of integers.
55 // </etymology>
56 
57 // <synopsis>
58 // This class is derived from <linkto
59 // class=DParameterChoice>DParameterChoice</linkto> and provides a
60 // choice-type parameter. The string selection correspond to a "key"
61 // selection. It is desgined for use with, for example, an enum. In such a
62 // case, each string value can have an associated integer value which
63 // can be cast to / from a enum.
64 // </synopsis>
65 // <example>
66 
67 // A DParameterMapKeyChoice can easily be used to store and update any
68 // parameter which can be expressed as a selection from two or more
69 // options.
70 // <srcblock>
71 // casacore::Vector<casacore::String> myStrings(2);
72 // myStrings(0) = "Ten";
73 // myStrings(1) = "Twenty";
74 // casacore::Vector<casacore::Int> myInts(2);
75 // myInts(0) = 10;
76 // myInts(1) = 20;
77 //
78 // // ...
79 // DParameterMapKeyChoice mchoice("number", "Choose a number of ...",
80 // "Select the number of ... to use for ...",
81 // myStrings, myInts,
82 // myStrings(0), myStrings(0));
83 //
84 // // ...
85 //
86 // // update the parameter from some casacore::Record (casacore::String representation);
87 // mchoice.fromRecord(rec);
88 //
89 // // examine the value of the parameter
90 // cerr << "You have selected " << mchoice.value() << " things." << endl;
91 // // ...
92 // itsNumberThings = mchoice.keyValue();
93 // </srcblock>
94 // </example>
95 
96 // <motivation>
97 // Often at C++ level, parameters will be described by enums etc.
98 // At glish level however, it is often required for these parameters
99 // to be displayed as text options. This class is designed to make that
100 // process easier. It can also be used more generally to associate any key
101 // with a text option.
102 // </motivation>
103 
104 // <thrown>
105 // <li> Throws AipsErrors if number of keys do not match number of options
106 // or if there is a problem looking up a key.
107 // </thrown>
108 
109 // <todo asof="2002/05/08">
110 // <li> casacore::Template the class so a "key" can be anything.
111 // </todo>
112 
114 
115  public:
116 
117  // Constructor taking the name of the parameter, a short
118  // description, some help text, the enum which is to form
119  // the basis of the options (must have an overloaded ostream <<
120  // operator), a vector of integers corresponding to the options
121  // within that enum, a default value, an initial value, and the
122  // context of the parameter. Obviously the
123  // <src>defaultvalue</src> and <src>value</src> parameters must
124  // exist in the list of allowed options, otherwise an exception
125  // is thrown.
129  const casacore::String defaultvalue, const casacore::String value,
130  const casacore::String context = "");
131 
132 
133  // (Required) copy constructor.
135 
136  // Destructor.
137  virtual ~DParameterMapKeyChoice();
138 
139  // (Required) copy assignment.
141 
142  // Return the list of all keys for this parameter.
144  return itsKeys;
145  }
146 
147  // Return the current value of this parameter.
149 
150  // Thise function has very little implementation, it is here so if
151  // a user changes the list of options, we can ensure we do not make a
152  // mistake when looking up its corresponding key
154  itsLastString = "";
155  DParameterChoice::setOptions(newOptions);
156  }
157 
158  // Set the current value, based on a key.
159  casacore::Bool setKeyValue(const casacore::Int newValue);
160 
161  // Set or change the list of allowed options for this parameter.
162  void setKeys (const casacore::Vector<casacore::Int>& newKeys);
163 
164  protected:
165 
166  // (Required) default constructor.
168 
169  private:
170  // Lookup the key based on the string provided
172 
173  // Store for the allowed options for this parameter.
177  };
178 
179 
180 } //# NAMESPACE CASA - END
181 
182 #endif
virtual ~DParameterMapKeyChoice()
Destructor.
DParameterMapKeyChoice & operator=(const DParameterMapKeyChoice &other)
(Required) copy assignment.
int Int
Definition: aipstype.h:50
casacore::String name() const
Return the name of this parameter.
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...
casacore::Bool lookUpKey(const casacore::String &value)
Lookup the key based on the string provided.
casacore::String help() const
Return the help for this parameter.
void setKeys(const casacore::Vector< casacore::Int > &newKeys)
Set or change the list of allowed options for this parameter.
casacore::Bool setKeyValue(const casacore::Int newValue)
Set the current value, based on a key.
casacore::String description() const
Return the description of this parameter.
casacore::Vector< casacore::Int > itsKeys
Store for the allowed options for this parameter.
DParameterMapKeyChoice()
(Required) default constructor.
casacore::String context() const
Return the context of this parameter.
casacore::Vector< casacore::Int > keys() const
Return the list of all keys for this parameter.
bool Bool
Define the standard types used by Casacore.
Definition: aipstype.h:42
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.
Implementation of DParameterChoice to store parameter and associated key.
casacore::Int keyValue()
Return the current value of 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