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
66{
67public:
68 // Constructor, blank error.
70
71 // Constructor, error with the given text and isFatal flag.
72 RFError(const String& error, bool isFatal = false);
73
74 // Destructor.
76
77 // Returns whether this error was fatal or not.
78 bool isFatal() const;
79
80 // Returns this error's text.
81 const String& error() const;
82
83 // Sets the error.
84 void set(const String& error, bool isFatal = false);
85
86private:
88 bool fatal_p;
89};
90
91
92// <summary>
93// Superclass for readers and writers containing common definitions and
94// operations.
95// </summary>
96//
97// <use visibility=export>
98//
99// <reviewed reviewer="" date="" tests="">
100// </reviewed>
101//
102// <prerequisite>
103// </prerequisite>
104//
105// <synopsis>
106// </synopsis>
107//
108// <example>
109// <srcblock>
110// </srcblock>
111// </example>
112//
113//# <todo asof="2009/03/10">
114//# <li>
115//# </todo>
116
118{
119public:
120 // An enum of all known subclasses/formats supported.
124
125 // Converts between enum and String for SupportedType.
126 // <group>
129 // </group>
130
131 // Returns the file extension for the given SupportedType.
133
134 // Returns all known SupportedTypes.
135 // <group>
138 // </group>
139
140 // Returns an appropriate child RFReader class for the given
141 // SupportedType, or NULL for an error (shouldn't happen).
143
144 // Returns an new appropriate child RfWriter class for the given
145 // SupportedType, or NULL for an error (shouldn't happen).
147
148 // Returns an new appropriate options widget for the given SupportedType,
149 // or NULL for an error (shouldn't happen).
151
152
153 // Constructor.
155
156 // Destructor.
157 virtual ~RFReaderWriter() { }
158
159 // Sets the file to be read/written to the given.
160 virtual void setFile(const String& filename);
161
162 // Sets the region name associated withe the file to be read or written.
163 virtual void setName(const String& regionName);
164
165 // Returns the last error set during read/write.
166 virtual const RFError& lastError() const;
167
168protected:
169 // Filename to be read/written.
171
172 // Name to be assigned to the region
174
175 // Last error seen during read/write.
177
178 // Record containg plotting options for the regions
180
181 // Convenience method for setting last error during read/write.
182 virtual void setError(const String& error, bool fatal = false) const;
183};
184
185
186// <summary>
187// Abstract superclass for any class that reads a format that produces
188// Regions from a file.
189// </summary>
190//
191// <use visibility=export>
192//
193// <reviewed reviewer="" date="" tests="">
194// </reviewed>
195//
196// <prerequisite>
197// </prerequisite>
198//
199// <synopsis>
200// Provide a well defined set of operations for reading
201// region files, regardless of the data format.
202//
203// Note that some file formats allow for plotting options
204// to be defined as well as the regions. These options are
205// read and stored in a record of ... , the contents
206// of this record is ill-defined (ie. there is no standard).
207//
208// There may come a time where a standard is necessary.
209// </synopsis>
210//
211// <example>
212// <srcblock>
213// </srcblock>
214// </example>
215//
216//# <todo asof="2009/03/10">
217//# <li>
218//# </todo>
219
220class RFReader : public virtual RFReaderWriter
221{
222public:
223 // Constructor.
225
226 // Destructor.
227 virtual ~RFReader() { }
228
229 // Provides access to the plotting options that
230 // were found in the region file.
231 virtual Record* options() {
232 return &options_p;
233 };
234
235 // reported, false otherwise. If false is returned, the details can be
236 // found using lastError(). Any valid Regions that were read from the
237 // file are placed in the given vector (which is cleared first).
238 virtual bool read(Record& region) = 0;
239
240
241 // Calls setFile() then read().
242 virtual bool readFile(const String& file, Record& region) {
243 setFile(file);
244 return read(region);
245 }
246};
247
248
249// <summary>
250// Abstract superclass for any class that writes Regions to a region
251// file format.
252// </summary>
253//
254// <use visibility=export>
255//
256// <reviewed reviewer="" date="" tests="">
257// </reviewed>
258//
259// <prerequisite>
260// </prerequisite>
261//
262// <synopsis>
263// Provide a well defined set of operations that all
264// region file writers must contain regardless of the
265// file format of the file being saved. .
266//
267// Note that some file formats allow for plotting options
268// to be stored with the region information. The setOptions
269// method allows the user to supply this information.
270// </synopsis>
271//
272// <example>
273// <srcblock>
274// </srcblock>
275// </example>
276//
277//# <todo asof="2009/03/10">
278//# <li>
279//# </todo>
280
281class RFWriter : public virtual RFReaderWriter
282{
283public:
284 // Constructor.
286
287 // Destructor.
288 virtual ~RFWriter() { }
289
290 // Sets the optional to the values. These values are related to
291 // the drawing of regions and not defining the regions themselves.
292 // For example, the colour to draw the region as.
293 virtual void setOptions(const Record* options) {
294 options_p.defineRecord( "regionoptions", *options );
295 };
296
297
298 // Write the given regions to the filename set with setFile and returns
299 // true if no errors were reported, false otherwise. If false is returned,
300 // the details can be found using lastError().
301 virtual bool write(const Record& region) const = 0;
302
303 // Calls setFile then write.
304 virtual bool writeFile(const String& filename,
305 const Record& regions) {
306 setFile(filename);
307 return write(regions);
308 }
309};
310
311} //# end namespace
312
313#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.
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:223
this file contains all the compiler specific defines
Definition mainpage.dox:28