casa  5.7.0-16
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
DisplayParameter.h
Go to the documentation of this file.
1 //# DisplayParameter.h: base class for storing and parsing 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_DISPLAYPARAMETER_H
29 #define TRIALDISPLAY_DISPLAYPARAMETER_H
30 
31 #include <casa/aips.h>
32 #include <casa/Containers/Record.h>
34 
35 namespace casa { //# NAMESPACE CASA - BEGIN
36 
37 // <summary>
38 // Base class for storing and parsing of parameters for display classes.
39 // </summary>
40 
41 // <use visibility=local>
42 
43 // <reviewed reviewer="" date="" test="" demos="">
44 // </reviewed>
45 
46 // <prerequisite>
47 // <li> <linkto class=DisplayOptions>DisplayOptions</linkto>
48 // </prerequisite>
49 
50 // <etymology>
51 // DisplayParameter is a base class which provides services for
52 // conveniently storing and parsing parameters relevant to the display
53 // classes.
54 // </etymology>
55 
56 // <synopsis>
57 // DisplayParameter defines a relatively simple interface for writing
58 // small containers for the various types of parameters used
59 // throughout the display classes. The required interface consists of
60 // methods to update the parameter value from an incoming
61 // <src>casacore::RecordInterface</src>-type object, and to add the description
62 // of the parameter to a provided <src>casacore::RecordInterface</src> object.
63 //
64 // Other than this, all parameters share these common elements:
65 //
66 // <li> <src>name</src>, a short <src>casacore::String</src> uniquely
67 // identifiying the parameter.
68 //
69 // <li> <src>description</src>, a slightly longer <src>casacore::String</src>
70 // which offers a description of the parameter, suitably short for
71 // display in a graphical user interface, for example.
72 //
73 // <li> <src>help</src>, an even longer <src>casacore::String</src> (!) which
74 // should be filled in with text describing the option in more detail
75 // than can be given in <src>description</src>
76 //
77 // <li> <src>context</src>, which if provided (ie. <src>context !=
78 // casacore::String("")</src>) gives a category name for this parameter, and is
79 // used, for example, by the autogui to place the parameter in an
80 // appropriately named roll-up.
81 //
82 // <li> <src>allowunset</src>, which indicates whether this parameter
83 // can be "unset" or not. An "unset" parameter is one for which a
84 // sensible (perhaps context sensitive) default can be determined and
85 // used. Derived classes need not provide this option in their
86 // constructor.
87 //
88 // <li> <src>editable</src>, which indicates whether this parameter is
89 // allowed to be modified by the user.
90 //
91 // DisplayParameter makes use of the <linkto
92 // class=DisplayOptions>DisplayOptions</linkto> class to parse Records
93 // containing parameter descriptions. Derived classes must implement
94 // the two virtual methods <src>toRecord</src> and
95 // <src>fromRecord</src>, which respectively store a description of
96 // the DisplayParameter in a sub-field of the provided
97 // casacore::RecordInterface, and extract the value of the DisplayParameter from
98 // a sub-field in the provided record. The sub-field is identified by
99 // the <src>name</src> of the DisplayParameter.
100 //
101 // Derived classes should also add utility functions which return the
102 // various aspects of the DisplayParameter to the programmer. Most
103 // importantly, a <src>value()</src> function should be provided to
104 // enable the user to easily retrieve the current value of the
105 // parameter.
106 // </synopsis>
107 
108 // <motivation>
109 // To avoid littering many of the display classes with code fragments
110 // for constructing and parsing Records.
111 // </motivation>
112 
113 // <thrown>
114 // <li> None.
115 // </thrown>
116 
117 // <todo asof="2000/01/28">
118 // <li> Provide base class support for unset values.
119 // </todo>
120 
122 
123  public:
124 
125  // Destructor.
126  virtual ~DisplayParameter();
127 
128  // Parse <src>record</src>, and update this parameter if a field
129  // exists whose name matches that of this parameter. Return
130  // <src>true</src> if the parameter is changed, otherwise return
131  // <src>false</src>.
132  virtual casacore::Bool fromRecord(const casacore::RecordInterface &record) = 0;
133 
134  // Place a record describing this parameter in a sub-field of
135  // <src>record</src> with name matching that of this parameter. If
136  // <src>overwrite</src> is <src>true</src>, then any existing field
137  // with matching name will be overwritten. If <src>fullrecord</src>
138  // is <src>true</src>, then a complete description of the parameter
139  // is given, otherwise just its current value is stored in
140  // <src>record</src>.
141  virtual void toRecord(casacore::RecordInterface &record, const casacore::Bool fullrecord = true,
142  const casacore::Bool overwrite = false) = 0;
143 
144  // Return the name of this parameter.
146  return itsName;
147  }
148 
149  // Return the description of this parameter.
151  return itsDescription;
152  }
153 
154  // Return the help for this parameter.
156  return itsHelp;
157  }
158 
159  // Return the context of this parameter.
161  return itsContext;
162  }
163 
164  // Return whether this parameter can be unset.
166  return itsAllowUnset;
167  }
168 
169  // Return whether this parameter is editable.
171  return itsEditable;
172  }
173 
174  // Set or change the name of this parameter to that specified.
176  itsName = name;
177  }
178 
179  // Set or change the description of this parameter to what is
180  // specified.
183  }
184 
185  // Set or change the help for this parameter to what is specified.
187  itsHelp = help;
188  }
189 
190  // Set or change the context of this parameter to what is specified.
193  }
194 
195  // Set or change whether this parameter may be unset, according to
196  // the function argument value.
197  void setAllowUnset(const casacore::Bool allowunset) {
198  itsAllowUnset = allowunset;
199  }
200 
201  // Set or change whether this parameter is editable according to
202  // the function argument.
205  }
206 
207  protected:
208 
209  // Constructor taking the name of the parameter, a short
210  // description, some help text, and flags indicating whether the
211  // parameter can be unset and is editable.
213  const casacore::String help, const casacore::String context = "",
214  const casacore::Bool allowunset = false,
215  const casacore::Bool editable = true);
216 
217  // Copy constructor using copy semantics.
218  DisplayParameter(const DisplayParameter &other);
219 
220  // Default constructor yielding a useless DisplayParameter.
222 
223  // Copy assignment.
225 
226  // Return a basic description of this parameter; used by virtual
227  // implementations of <src>toRecord</src> method to fill out
228  // a casacore::Record describing this DisplayParameter.
230 
231  // Return the DisplayOptions to use for parsing Records.
233  return itsDisplayOptions;
234  }
235 
236  private:
237 
238  // Store for the name of this parameter.
240 
241  // Store for the description of this parameter.
243 
244  // Store for the help for this parameter.
246 
247  // Store for the context of this parameter.
249 
250  // Store for whether this parameter can be unset.
252 
253  // Store for whether this parameter is editable.
255 
256  // Store for a DisplayOptions object for parsing Records.
258 
259  };
260 
261 
262 } //# NAMESPACE CASA - END
263 
264 #endif
DisplayParameter()
Default constructor yielding a useless DisplayParameter.
Class to provide option parsing routines for display classes.
casacore::String itsContext
Store for the context of this parameter.
casacore::String name() const
Return the name of this parameter.
const DisplayOptions & displayOptions() const
Return the DisplayOptions to use for parsing Records.
casacore::String itsDescription
Store for the description of this parameter.
casacore::Record baseDescription()
Return a basic description of this parameter; used by virtual implementations of toRecord method to f...
casacore::String itsHelp
Store for the help for this parameter.
casacore::String help() const
Return the help for this parameter.
DisplayParameter & operator=(const DisplayParameter &other)
Copy assignment.
void setName(const casacore::String name)
Set or change the name of this parameter to that specified.
casacore::String description() const
Return the description of this parameter.
void setAllowUnset(const casacore::Bool allowunset)
Set or change whether this parameter may be unset, according to the function argument value...
virtual ~DisplayParameter()
Destructor.
DisplayOptions itsDisplayOptions
Store for a DisplayOptions object for parsing Records.
void setDescription(const casacore::String description)
Set or change the description of this parameter to what is specified.
casacore::Bool editable() const
Return whether this parameter is editable.
casacore::String context() const
Return the context of this parameter.
A hierarchical collection of named fields of various types.
Definition: Record.h:180
bool Bool
Define the standard types used by Casacore.
Definition: aipstype.h:42
casacore::Bool itsEditable
Store for whether this parameter is editable.
casacore::Bool allowUnset() const
Return whether this parameter can be unset.
virtual casacore::Bool fromRecord(const casacore::RecordInterface &record)=0
Parse record, and update this parameter if a field exists whose name matches that of this parameter...
void setHelp(const casacore::String help)
Set or change the help for this parameter to what is specified.
String: the storage and methods of handling collections of characters.
Definition: String.h:223
virtual void toRecord(casacore::RecordInterface &record, const casacore::Bool fullrecord=true, const casacore::Bool overwrite=false)=0
Place a record describing this parameter in a sub-field of record with name matching that of this par...
void setContext(const casacore::String context)
Set or change the context of this parameter to what is specified.
Abstract base class for Record classes.
void setEditable(const casacore::Bool editable)
Set or change whether this parameter is editable according to the function argument.
casacore::String itsName
Store for the name of this parameter.
casacore::Bool itsAllowUnset
Store for whether this parameter can be unset.
Base class for storing and parsing of parameters for display classes.