casa  5.7.0-16
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
RFReaderWriter.h
Go to the documentation of this file.
1 //# RegionFileReaderWriter.h: Interfaces for classes that read/write image regions.
2 //# Copyright (C) 2009
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 IMAGES_RFREADERWRITER_H
29 #define IMAGES_RFREADERWRITER_H
30 
31 //# Includes
32 #include <casacore/casa/aips.h>
36 
37 namespace casacore {//# NAMESPACE CASACORE - BEGIN
38 
39 //# Forward declarations
40 class RFReader;
41 class RFWriter;
42 
43 // <summary>
44 // Convenience class for a String/bool pair.
45 // </summary>
46 //
47 // <use visibility=export>
48 //
49 // <reviewed reviewer="" date="" tests="">
50 // </reviewed>
51 //
52 // <prerequisite>
53 // </prerequisite>
54 //
55 // <synopsis>
56 // </synopsis>
57 //
58 // <example>
59 // <srcblock>
60 // </srcblock>
61 // </example>
62 //
63 //# <todo asof="2009/03/10">
64 //# <li>
65 //# </todo>
66 
67 class RFError
68 {
69 public:
70  // Constructor, blank error.
71  RFError();
72 
73  // Constructor, error with the given text and isFatal flag.
74  RFError(const String& error, bool isFatal = false);
75 
76  // Destructor.
77  ~RFError();
78 
79  // Returns whether this error was fatal or not.
80  bool isFatal() const;
81 
82  // Returns this error's text.
83  const String& error() const;
84 
85  // Sets the error.
86  void set(const String& error, bool isFatal = false);
87 
88 private:
90  bool fatal_p;
91 };
92 
93 
94 // <summary>
95 // Superclass for readers and writers containing common definitions and
96 // operations.
97 // </summary>
98 //
99 // <use visibility=export>
100 //
101 // <reviewed reviewer="" date="" tests="">
102 // </reviewed>
103 //
104 // <prerequisite>
105 // </prerequisite>
106 //
107 // <synopsis>
108 // </synopsis>
109 //
110 // <example>
111 // <srcblock>
112 // </srcblock>
113 // </example>
114 //
115 //# <todo asof="2009/03/10">
116 //# <li>
117 //# </todo>
118 
120 {
121 public:
122  // An enum of all known subclasses/formats supported.
125  };
126 
127  // Converts between enum and String for SupportedType.
128  // <group>
131  // </group>
132 
133  // Returns the file extension for the given SupportedType.
135 
136  // Returns all known SupportedTypes.
137  // <group>
140  // </group>
141 
142  // Returns an appropriate child RFReader class for the given
143  // SupportedType, or NULL for an error (shouldn't happen).
145 
146  // Returns an new appropriate child RfWriter class for the given
147  // SupportedType, or NULL for an error (shouldn't happen).
149 
150  // Returns an new appropriate options widget for the given SupportedType,
151  // or NULL for an error (shouldn't happen).
153 
154 
155  // Constructor.
157 
158  // Destructor.
159  virtual ~RFReaderWriter() { }
160 
161  // Sets the file to be read/written to the given.
162  virtual void setFile(const String& filename);
163 
164  // Sets the region name associated withe the file to be read or written.
165  virtual void setName(const String& regionName);
166 
167  // Returns the last error set during read/write.
168  virtual const RFError& lastError() const;
169 
170 protected:
171  // Filename to be read/written.
173 
174  // Name to be assigned to the region
176 
177  // Last error seen during read/write.
179 
180  // Record containg plotting options for the regions
182 
183  // Convenience method for setting last error during read/write.
184  virtual void setError(const String& error, bool fatal = false) const;
185 };
186 
187 
188 // <summary>
189 // Abstract superclass for any class that reads a format that produces
190 // Regions from a file.
191 // </summary>
192 //
193 // <use visibility=export>
194 //
195 // <reviewed reviewer="" date="" tests="">
196 // </reviewed>
197 //
198 // <prerequisite>
199 // </prerequisite>
200 //
201 // <synopsis>
202 // Provide a well defined set of operations for reading
203 // region files, regardless of the data format.
204 //
205 // Note that some file formats allow for plotting options
206 // to be defined as well as the regions. These options are
207 // read and stored in a record of ... , the contents
208 // of this record is ill-defined (ie. there is no standard).
209 //
210 // There may come a time where a standard is necessary.
211 // </synopsis>
212 //
213 // <example>
214 // <srcblock>
215 // </srcblock>
216 // </example>
217 //
218 //# <todo asof="2009/03/10">
219 //# <li>
220 //# </todo>
221 
222 class RFReader : public virtual RFReaderWriter
223 {
224 public:
225  // Constructor.
226  RFReader() { }
227 
228  // Destructor.
229  virtual ~RFReader() { }
230 
231  // Provides access to the plotting options that
232  // were found in the region file.
233  virtual Record* options() {
234  return &options_p;
235  };
236 
237  // reported, false otherwise. If false is returned, the details can be
238  // found using lastError(). Any valid Regions that were read from the
239  // file are placed in the given vector (which is cleared first).
240  virtual bool read(Record& region) = 0;
241 
242 
243  // Calls setFile() then read().
244  virtual bool readFile(const String& file, Record& region) {
245  setFile(file);
246  return read(region);
247  }
248 };
249 
250 
251 // <summary>
252 // Abstract superclass for any class that writes Regions to a region
253 // file format.
254 // </summary>
255 //
256 // <use visibility=export>
257 //
258 // <reviewed reviewer="" date="" tests="">
259 // </reviewed>
260 //
261 // <prerequisite>
262 // </prerequisite>
263 //
264 // <synopsis>
265 // Provide a well defined set of operations that all
266 // region file writers must contain regardless of the
267 // file format of the file being saved. .
268 //
269 // Note that some file formats allow for plotting options
270 // to be stored with the region information. The setOptions
271 // method allows the user to supply this information.
272 // </synopsis>
273 //
274 // <example>
275 // <srcblock>
276 // </srcblock>
277 // </example>
278 //
279 //# <todo asof="2009/03/10">
280 //# <li>
281 //# </todo>
282 
283 class RFWriter : public virtual RFReaderWriter
284 {
285 public:
286  // Constructor.
287  RFWriter() { }
288 
289  // Destructor.
290  virtual ~RFWriter() { }
291 
292  // Sets the optional to the values. These values are related to
293  // the drawing of regions and not defining the regions themselves.
294  // For example, the colour to draw the region as.
295  virtual void setOptions(const Record* options) {
296  options_p.defineRecord( "regionoptions", *options );
297  };
298 
299 
300  // Write the given regions to the filename set with setFile and returns
301  // true if no errors were reported, false otherwise. If false is returned,
302  // the details can be found using lastError().
303  virtual bool write(const Record& region) const = 0;
304 
305  // Calls setFile then write.
306  virtual bool writeFile(const String& filename,
307  const Record& regions) {
308  setFile(filename);
309  return write(regions);
310  }
311 };
312 
313 } //# end namespace
314 
315 #endif
virtual bool writeFile(const String &filename, const Record &regions)
Calls setFile then write.
bool isFatal() const
Returns whether this error was fatal or not.
A 1-D Specialization of the Array class.
RFWriter()
Constructor.
Abstract superclass for any class that reads a format that produces Regions from a file...
void defineRecord(const RecordFieldId &, const Record &value, RecordType type=Variable)
Define a value for the given field containing a subrecord.
RFError()
Constructor, blank error.
virtual ~RFReader()
Destructor.
virtual ~RFReaderWriter()
Destructor.
virtual const RFError & lastError() const
Returns the last error set during read/write.
void set(const String &error, bool isFatal=false)
Sets the error.
Abstract superclass for any class that writes Regions to a region file format.
RFError lastError_p
Last error seen during read/write.
static RFWriter * writerForType(SupportedType type)
Returns an new appropriate child RfWriter class for the given SupportedType, or NULL for an error (sh...
static Vector< SupportedType > supportedTypes()
Returns all known SupportedTypes.
RFReaderWriter()
Constructor.
virtual void setOptions(const Record *options)
Sets the optional to the values.
virtual casacore::String type() const
Implements RegionShape::type.
Definition: RegionShapes.h:548
static String extensionForType(SupportedType type)
Returns the file extension for the given SupportedType.
const String & error() const
Returns this error&#39;s text.
virtual void setName(const String &regionName)
Sets the region name associated withe the file to be read or written.
String * pFilename_p
Filename to be read/written.
static RFReader * readerForType(SupportedType type)
Returns an appropriate child RFReader class for the given SupportedType, or NULL for an error (should...
Convenience class for a String/bool pair.
virtual bool write(const Record &region) const =0
Write the given regions to the filename set with setFile and returns true if no errors were reported...
Options options
RFReader()
Constructor.
virtual void setError(const String &error, bool fatal=false) const
Convenience method for setting last error during read/write.
A hierarchical collection of named fields of various types.
Definition: Record.h:180
virtual bool readFile(const String &file, Record &region)
Calls setFile() then read().
String * pRegionName_p
Name to be assigned to the region.
virtual ~RFWriter()
Destructor.
static Vector< String > supportedTypeStrings()
virtual Record * options()
Provides access to the plotting options that were found in the region file.
static Record * optionsWidgetForType(SupportedType type)
Returns an new appropriate options widget for the given SupportedType, or NULL for an error (shouldn&#39;...
Superclass for readers and writers containing common definitions and operations.
virtual bool read(Record &region)=0
reported, false otherwise.
~RFError()
Destructor.
String: the storage and methods of handling collections of characters.
Definition: String.h:223
SupportedType
An enum of all known subclasses/formats supported.
virtual void setFile(const String &filename)
Sets the file to be read/written to the given.
Record options_p
Record containg plotting options for the regions.
Defines nreal time structures used by the VLA table filler.
Definition: nreal.h:100
#define casacore
&lt;X11/Intrinsic.h&gt; #defines true, false, casacore::Bool, and String.
Definition: X11Intrinsic.h:42