casacore
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>
33#include <casacore/casa/Logging/LogIO.h>
34#include <casacore/casa/Containers/Record.h>
35#include <casacore/coordinates/Coordinates/CoordinateSystem.h>
36
37namespace casacore {//# NAMESPACE CASACORE - BEGIN
38
39//# Forward declarations
40class RFReader;
41class 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
68{
69public:
70 // Constructor, blank error.
72
73 // Constructor, error with the given text and isFatal flag.
74 RFError(const String& error, bool isFatal = false);
75
76 // Destructor.
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
88private:
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{
121public:
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
170protected:
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
222class RFReader : public virtual RFReaderWriter
223{
224public:
225 // Constructor.
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
283class RFWriter : public virtual RFReaderWriter
284{
285public:
286 // Constructor.
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
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.
Superclass for readers and writers containing common definitions and operations.
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.
RFReaderWriter()
Constructor.
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,...
void defineRecord(const RecordFieldId &, const Record &value, RecordType type=Variable)
Define a value for the given field containing a subrecord.
String: the storage and methods of handling collections of characters.
Definition: String.h:225
this file contains all the compiler specific defines
Definition: mainpage.dox:28