casacore
Loading...
Searching...
No Matches
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: casa-feedback@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#ifndef IMAGES_RFREADERWRITER_H
27#define IMAGES_RFREADERWRITER_H
28
29// # Includes
30#include <casacore/casa/aips.h>
31#include <casacore/casa/Logging/LogIO.h>
32#include <casacore/casa/Containers/Record.h>
33#include <casacore/coordinates/Coordinates/CoordinateSystem.h>
34
35namespace casacore { // # NAMESPACE CASACORE - BEGIN
36
37// # Forward declarations
38class RFReader;
39class RFWriter;
40
41// <summary>
42// Convenience class for a String/bool pair.
43// </summary>
44//
45// <use visibility=export>
46//
47// <reviewed reviewer="" date="" tests="">
48// </reviewed>
49//
50// <prerequisite>
51// </prerequisite>
52//
53// <synopsis>
54// </synopsis>
55//
56// <example>
57// <srcblock>
58// </srcblock>
59// </example>
60//
61// # <todo asof="2009/03/10">
62// # <li>
63// # </todo>
64
65class RFError {
66 public:
67 // Constructor, blank error.
69
70 // Constructor, error with the given text and isFatal flag.
71 RFError(const String& error, bool isFatal = false);
72
73 // Destructor.
75
76 // Returns whether this error was fatal or not.
77 bool isFatal() const;
78
79 // Returns this error's text.
80 const String& error() const;
81
82 // Sets the error.
83 void set(const String& error, bool isFatal = false);
84
85 private:
87 bool fatal_p;
88};
89
90// <summary>
91// Superclass for readers and writers containing common definitions and
92// operations.
93// </summary>
94//
95// <use visibility=export>
96//
97// <reviewed reviewer="" date="" tests="">
98// </reviewed>
99//
100// <prerequisite>
101// </prerequisite>
102//
103// <synopsis>
104// </synopsis>
105//
106// <example>
107// <srcblock>
108// </srcblock>
109// </example>
110//
111// # <todo asof="2009/03/10">
112// # <li>
113// # </todo>
114
116 public:
117 // An enum of all known subclasses/formats supported.
119
120 // Converts between enum and String for SupportedType.
121 // <group>
124 // </group>
125
126 // Returns the file extension for the given SupportedType.
128
129 // Returns all known SupportedTypes.
130 // <group>
133 // </group>
134
135 // Returns an appropriate child RFReader class for the given
136 // SupportedType, or NULL for an error (shouldn't happen).
138
139 // Returns an new appropriate child RfWriter class for the given
140 // SupportedType, or NULL for an error (shouldn't happen).
142
143 // Returns an new appropriate options widget for the given SupportedType,
144 // or NULL for an error (shouldn't happen).
146
147 // Constructor.
149
150 // Destructor.
151 virtual ~RFReaderWriter() {}
152
153 // Sets the file to be read/written to the given.
154 virtual void setFile(const String& filename);
155
156 // Sets the region name associated withe the file to be read or written.
157 virtual void setName(const String& regionName);
158
159 // Returns the last error set during read/write.
160 virtual const RFError& lastError() const;
161
162 protected:
163 // Filename to be read/written.
165
166 // Name to be assigned to the region
168
169 // Last error seen during read/write.
171
172 // Record containg plotting options for the regions
174
175 // Convenience method for setting last error during read/write.
176 virtual void setError(const String& error, bool fatal = false) const;
177};
178
179// <summary>
180// Abstract superclass for any class that reads a format that produces
181// Regions from a file.
182// </summary>
183//
184// <use visibility=export>
185//
186// <reviewed reviewer="" date="" tests="">
187// </reviewed>
188//
189// <prerequisite>
190// </prerequisite>
191//
192// <synopsis>
193// Provide a well defined set of operations for reading
194// region files, regardless of the data format.
195//
196// Note that some file formats allow for plotting options
197// to be defined as well as the regions. These options are
198// read and stored in a record of ... , the contents
199// of this record is ill-defined (ie. there is no standard).
200//
201// There may come a time where a standard is necessary.
202// </synopsis>
203//
204// <example>
205// <srcblock>
206// </srcblock>
207// </example>
208//
209// # <todo asof="2009/03/10">
210// # <li>
211// # </todo>
212
213class RFReader : public virtual RFReaderWriter {
214 public:
215 // Constructor.
217
218 // Destructor.
219 virtual ~RFReader() {}
220
221 // Provides access to the plotting options that
222 // were found in the region file.
223 virtual Record* options() { return &options_p; };
224
225 // reported, false otherwise. If false is returned, the details can be
226 // found using lastError(). Any valid Regions that were read from the
227 // file are placed in the given vector (which is cleared first).
228 virtual bool read(Record& region) = 0;
229
230 // Calls setFile() then read().
231 virtual bool readFile(const String& file, Record& region) {
232 setFile(file);
233 return read(region);
234 }
235};
236
237// <summary>
238// Abstract superclass for any class that writes Regions to a region
239// file format.
240// </summary>
241//
242// <use visibility=export>
243//
244// <reviewed reviewer="" date="" tests="">
245// </reviewed>
246//
247// <prerequisite>
248// </prerequisite>
249//
250// <synopsis>
251// Provide a well defined set of operations that all
252// region file writers must contain regardless of the
253// file format of the file being saved. .
254//
255// Note that some file formats allow for plotting options
256// to be stored with the region information. The setOptions
257// method allows the user to supply this information.
258// </synopsis>
259//
260// <example>
261// <srcblock>
262// </srcblock>
263// </example>
264//
265// # <todo asof="2009/03/10">
266// # <li>
267// # </todo>
268
269class RFWriter : public virtual RFReaderWriter {
270 public:
271 // Constructor.
273
274 // Destructor.
275 virtual ~RFWriter() {}
276
277 // Sets the optional to the values. These values are related to
278 // the drawing of regions and not defining the regions themselves.
279 // For example, the colour to draw the region as.
280 virtual void setOptions(const Record* options) {
281 options_p.defineRecord("regionoptions", *options);
282 };
283
284 // Write the given regions to the filename set with setFile and returns
285 // true if no errors were reported, false otherwise. If false is returned,
286 // the details can be found using lastError().
287 virtual bool write(const Record& region) const = 0;
288
289 // Calls setFile then write.
290 virtual bool writeFile(const String& filename, const Record& regions) {
291 setFile(filename);
292 return write(regions);
293 }
294};
295
296} // namespace casacore
297
298#endif
bool isFatal() const
Returns whether this error was fatal or not.
void set(const String &error, bool isFatal=false)
Sets the error.
const String & error() const
Returns this error's text.
~RFError()
Destructor.
RFError()
Constructor, blank error.
RFError(const String &error, bool isFatal=false)
Constructor, error with the given text and isFatal flag.
virtual void setFile(const String &filename)
Sets the file to be read/written to the given.
SupportedType
An enum of all known subclasses/formats supported.
Record options_p
Record containg plotting options for the regions.
virtual void setName(const String &regionName)
Sets the region name associated withe the file to be read or written.
static String supportedTypes(SupportedType type)
static Vector< SupportedType > supportedTypes()
Returns all known SupportedTypes.
virtual const RFError & lastError() const
Returns the last error set during read/write.
virtual ~RFReaderWriter()
Destructor.
static RFWriter * writerForType(SupportedType type)
Returns an new appropriate child RfWriter class for the given SupportedType, or NULL for an error (sh...
static Record * optionsWidgetForType(SupportedType type)
Returns an new appropriate options widget for the given SupportedType, or NULL for an error (shouldn'...
static SupportedType supportedTypes(String type)
Converts between enum and String for SupportedType.
String * pFilename_p
Filename to be read/written.
static String extensionForType(SupportedType type)
Returns the file extension for the given SupportedType.
static Vector< String > supportedTypeStrings()
String * pRegionName_p
Name to be assigned to the region.
static RFReader * readerForType(SupportedType type)
Returns an appropriate child RFReader class for the given SupportedType, or NULL for an error (should...
virtual void setError(const String &error, bool fatal=false) const
Convenience method for setting last error during read/write.
RFError lastError_p
Last error seen during read/write.
Abstract superclass for any class that reads a format that produces Regions from a file.
virtual bool readFile(const String &file, Record &region)
Calls setFile() then read().
virtual Record * options()
Provides access to the plotting options that were found in the region file.
virtual ~RFReader()
Destructor.
virtual bool read(Record &region)=0
reported, false otherwise.
RFReader()
Constructor.
Abstract superclass for any class that writes Regions to a region file format.
virtual bool writeFile(const String &filename, const Record &regions)
Calls setFile then write.
virtual ~RFWriter()
Destructor.
RFWriter()
Constructor.
virtual void setOptions(const Record *options)
Sets the optional to the values.
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,...
String: the storage and methods of handling collections of characters.
Definition String.h:355
For temporary backward namespace compatibility, use casa as alias for casacore.
Definition mainpage.dox:28
virtual int read()
The read()' and write()' functions control reading and writing data from the external FITS I/O medium...