casa  5.7.0-16
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
RSFileReaderWriter.h
Go to the documentation of this file.
1 //# RSFileReaderWriter.h: Interfaces for classes that read/write shape files.
2 //# Copyright (C) 2008
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 #ifndef RSFILEREADERWRITER_H_
28 #define RSFILEREADERWRITER_H_
29 
31 #include <casa/Containers/Record.h>
34 
35 #include <utility>
36 
37 #include <casa/namespace.h>
38 using namespace std;
39 
40 class QWidget;
41 
42 namespace casa {
43 
44  class RSFileReader;
45  class RSFileWriter;
46 
47 class RFError {
48 
49 // Convenience class for a casacore::String/bool pair.
50  public:
51  // Constructor, blank error.
52  RFError();
53 
54  // Constructor, error with the given text and isFatal flag.
55  RFError(const casacore::String& error, bool isFatal = false);
56 
57  // Destructor.
58  ~RFError();
59 
60 
61  // Returns whether this error was fatal or not.
62  bool isFatal() const;
63 
64  // Returns this error's text.
65  const casacore::String& error() const;
66 
67  // Sets the error.
68  void set(const casacore::String& error, bool isFatal = false);
69 
70  private:
72  bool m_fatal;
73  };
74 
75 
76 // Superclass for readers and writers containing common definitions and
77 // operations.
79  public:
80  // Public Static Methods //
81 
82  // An enum of all known subclasses/formats supported.
84  DS9, CASA_XML
85  };
86 
87  // Converts between enum and casacore::String for SupportedType.
88  // <group>
89  static SupportedType supportedType(casacore::String type);
90  static casacore::String supportedType(SupportedType type);
91  // </group>
92 
93  // Returns the file extension for the given SupportedType.
94  static casacore::String extensionForType(SupportedType type);
95 
96  // Returns all known SupportedTypes.
97  // <group>
98  static std::vector<SupportedType> supportedTypes();
99  static std::vector<casacore::String> supportedTypesStrings();
100  // </group>
101 
102  // Returns an appropriate child RegionFileReader class for the given
103  // SupportedType, or NULL for an error (shouldn't happen).
104  static RSFileReader* readerForType(SupportedType type);
105 
106  // Returns an new appropriate child RegionFileWriter class for the given
107  // SupportedType, or NULL for an error (shouldn't happen).
108  static RSFileWriter* writerForType(SupportedType type);
109 
110  // Returns an new appropriate options widget for the given SupportedType,
111  // or NULL for an error (shouldn't happen).
112  static QWidget* optionsWidgetForType(SupportedType type);
113 
114 
115  // Non-Static Members //
116 
117  // Constructor.
119 
120  // Destructor.
121  virtual ~RSFileReaderWriter() { }
122 
123  // Sets the file to be read/written to the given.
124  virtual void setFile(const casacore::String& filename);
125 
126  // Returns the last error set during read/write.
127  virtual const RFError& lastError() const;
128 
129  protected:
130  // Filename to be read/written.
132 
133  // Last error seen during read/write.
135 
136  // Convenience method for setting last error during read/write.
137  virtual void setError(const casacore::String& error, bool isFatal = false) const;
138  };
139 
140 
141 // Abstract superclass for any class that reads a format that produces
142 // RegionShapes from a file.
143  class RSFileReader : public virtual RSFileReaderWriter {
144  public:
145  // Constructor.
147 
148  // Destructor.
149  virtual ~RSFileReader() { }
150 
151  // Read the filename set with setFile and returns true if no errors were
152  // reported, false otherwise. If false is returned, the details can be
153  // found using lastError(). Any valid RegionShapes that were read from the
154  // file are placed in the given vector (which is cleared first).
155  virtual bool read(std::vector<RegionShape*>& readShapes) = 0;
156 
157  // Calls setFile() then read().
158  virtual bool readFile(const casacore::String& file, std::vector<RegionShape*>& shapes) {
159  setFile(file);
160  return read(shapes);
161  }
162  };
163 
164 
165 // Abstract superclass for any class that writes RegionShapes to a region
166 // file format.
167  class RSFileWriter : public virtual RSFileReaderWriter {
168  public:
169  // Constructor.
171 
172  // Destructor.
173  virtual ~RSFileWriter() { }
174 
175  // Provides a custom widget that can be used to get/set options specific
176  // to each format type.
177  virtual QWidget* optionsWidget() const = 0;
178 
179  // Sets the options to the values given in the widget. May ignore invalid
180  // widgets (i.e., widgets different from the kind provided by
181  // optionsWidget()).
182  virtual void setOptions(const QWidget* widget) = 0;
183 
184  // Write the given regions to the filename set with setFile and returns
185  // true if no errors were reported, false otherwise. If false is returned,
186  // the details can be found using lastError().
187  virtual bool write(const std::vector<RegionShape*>& shapes) const = 0;
188 
189  // Calls setFile then write.
190  virtual bool writeFile(const casacore::String& filename,
191  const std::vector<RegionShape*>& shapes) {
192  setFile(filename);
193  return write(shapes);
194  }
195  };
196 
197 }
198 
199 #endif /*RSFILEREADERWRITER_H_*/
RSFileWriter()
Constructor.
virtual bool readFile(const casacore::String &file, std::vector< RegionShape * > &shapes)
Calls setFile() then read().
virtual ~RSFileWriter()
Destructor.
Abstract superclass for any class that reads a format that produces RegionShapes from a file...
virtual casacore::String type() const
Implements RegionShape::type.
Definition: RegionShapes.h:548
virtual ~RSFileReaderWriter()
Destructor.
RFError m_lastError
Last error seen during read/write.
Abstract superclass for any class that writes RegionShapes to a region file format.
bool write(const std::vector< RegionShape * > &shapes) const
Implements RegionFileWriter::write.
virtual ~RSFileReader()
Destructor.
RSFileReaderWriter()
Non-Static Members //.
Superclass for readers and writers containing common definitions and operations.
casacore::String m_filename
Filename to be read/written.
virtual bool writeFile(const casacore::String &filename, const std::vector< RegionShape * > &shapes)
Calls setFile then write.
void setOptions(const QWidget *widget)
Implements RegionFileWriter::setOptions.
QWidget * optionsWidget() const
Implements RegionFileWriter::optionsWidget.
casacore::String m_error
SupportedType
Public Static Methods //.
String: the storage and methods of handling collections of characters.
Definition: String.h:223
RSFileReader()
Constructor.
Defines nreal time structures used by the VLA table filler.
Definition: nreal.h:100