casa  5.7.0-16
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
TBTableDriver.h
Go to the documentation of this file.
1 //# TBTableDriver.h: Driver for interacting with the table on disk.
2 //# Copyright (C) 2007-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 TBTABLEDRIVER_H_
28 #define TBTABLEDRIVER_H_
29 
32 
33 #include <casa/BasicSL/String.h>
34 #include <tables/Tables/Table.h>
35 
36 #include <vector>
37 
38 namespace casacore{
39 
40 class TableRecord;
41 class Table;
42 }
43 
44 namespace casa {
45 
46 //# Forward Declarations
47 class TableParams;
48 class TBField;
49 class TBKeyword;
50 class TBArray;
51 class TBParser;
52 class DriverParams;
53 class ProgressHelper;
54 class TBData;
55 class TBArrayData;
56 
57 // <summary>
58 // Driver for interacting with the table on disk.
59 // </summary>
60 //
61 // <synopsis>
62 // TBTableDriver is an abstract superclass that defines how any implementing
63 // subclass must behave in order to be used by a TBTable. Any implementing
64 // subclass should update the table parameters that the driver has references
65 // to via the TableParams passed into the constructor.
66 // </synopsis>
67 
69 public:
70  // Constructor that takes the table and the table parameters.
72 
73  virtual ~TBTableDriver();
74 
75 
76  // Sets whether the driver should print debug information or not.
77  void setPrintDebug(bool pdb);
78 
79 
80  // canRead() must be implemented by any subclass.
81  // Returns whether or not the underlying table can be read (i.e., the read
82  // lock is set). Does not necessary guarantee that the next read operation
83  // will succeed, but a sufficiently close check before a read should
84  // suffice in most situations.
85  virtual bool canRead() = 0;
86 
87  // canWrite() must be implemented by any subclass.
88  // Returns whether or not the underlying table can be written (i.e., the
89  // write lock is set). Does not necessary guarantee that the next write
90  // operation will succeed, but a sufficiently close check before a write
91  // should suffice in most situations.
92  virtual bool canWrite() = 0;
93 
94  // tryWriteLock() must be implemented by any subclass.
95  // Tries to reopen the table using a write lock, and returns whether the
96  // operation succeeded or not. This MUST be done before any editing
97  // operations, and the lock should be released afterwards using
98  // releaseWriteLock().
99  virtual bool tryWriteLock() = 0;
100 
101  // releaseWriteLock() must be implemented by any subclass.
102  // Releases the write lock if needed.
103  virtual bool releaseWriteLock() = 0;
104 
105  // loadRows() must be implemented by any subclass.
106  // Loads the given rows into the table. See TBTable::loadRows();
107  virtual Result loadRows(int start = 0,
109  bool full = false, std::vector<casacore::String>* fields = NULL,
110  bool parsedata = true,
111  ProgressHelper* pp = NULL) = 0;
112 
113  // loadArray() must be implemented by any subclass.
114  // Loads the data into the given array at the given coordinates.
115  virtual void loadArray(TBArrayData* d, unsigned int row,
116  unsigned int col) = 0;
117 
118  // dimensionsOf() must be implemented by any subclass.
119  // Returns the array dimensions of the given field. See
120  // TBTable::dimensionsOf().
121  virtual std::vector<int> dimensionsOf(unsigned int col) = 0;
122 
123  // editData() must be implemented by any subclass.
124  // Updates the cell at the given coordinates to have the given value.
125  // If the data is an array, the array coordinates are provided in d.
126  // Returns the result of the operation.
127  virtual Result editData(unsigned int row, unsigned int col, TBData* newVal,
128  std::vector<int>* d = NULL) = 0;
129 
130  // totalRowsOf() must be implemented by any subclass.
131  // Returns the total rows of the table at the given location. See
132  // TBTable::totalRowsOf().
133  virtual int totalRowsOf(casacore::String location) = 0;
134 
135  // insertRows() must be implemented by any subclass.
136  // Inserts the given number of rows at the end of the table. See
137  // TBTable::insertRows().
138  virtual Result insertRows(int n) = 0;
139 
140  // deleteRows() must be implemented by any subclass.
141  // Deletes the given rows. See TBTable::deleteRows().
142  virtual Result deleteRows(std::vector<int> r) = 0;
143 
144 protected:
145  // The location of the table.
147 
148  // Reference to the table's insertRow parameter.
149  bool& insertRow;
150 
151  // Reference to the table's removeRow parameter.
152  bool& removeRow;
153 
154  // Reference to the table's data parameter.
155  std::vector<std::vector<TBData*>*>& data;
156 
157  // Reference to the table's fields parameter.
158  std::vector<TBField*>& fields;
159 
160  // Reference to the table's keywords parameter.
161  std::vector<TBKeyword*>& keywords;
162 
163  // Reference to the table's subtableRows parameter.
164  std::vector<int>& subtableRows;
165 
166  // Reference to the table's totalRows parameter.
167  int& totalRows;
168 
169  // Reference to the table's loadedRows parameter.
171 
172  // Reference to the table's writable parameter.
173  std::vector<bool>& writable;
174 
175  // Reference to the table's taql parameter.
176  bool& taql;
177 
178  // Copy of the table's driver parameters.
180 
181  // Indicates whether the driver should print debug information or not.
183 
184  // Reference to the table.
186 
187 
188  // Sends a direct query through the XMLDriver and returns the Result.
189  // Result query(casacore::String type, casacore::String query);
190 };
191 
192 // <summary>
193 // TBTableDriver implementation that directly accesses the table on disk.
194 // </summary>
195 //
196 // <synopsis>
197 // TBTableDriverDirect is a table driver that accesses the table on disk via
198 // the CASA tables code module. It is therefore faster than the XML driver
199 // and is the default for the table browser. See casa::Table.
200 // </synopsis>
201 
203 public:
204  // Constructor that takes a table and its parameters.
206 
207  virtual ~TBTableDriverDirect();
208 
209 
210  // Implements TBTableDriver::canRead().
211  bool canRead();
212 
213  // Implements TBTableDriver::canWrite().
214  bool canWrite();
215 
216  // Implements TBTableDriver::tryWriteLock().
217  bool tryWriteLock();
218 
219  // Implements TBTableDriver::releaseWriteLock().
220  bool releaseWriteLock();
221 
222  // Implements TBTableDriver::loadRows().
223  Result loadRows(int start, int num, bool full, std::vector<casacore::String>* fields,
224  bool parsedata, ProgressHelper* progressPanel);
225 
226  // Implements TBTableDriver::loadArray().
227  void loadArray(TBArrayData* d, unsigned int row, unsigned int col);
228 
229  // Implements TBTableDriver::dimensionsOf().
230  std::vector<int> dimensionsOf(unsigned int col);
231 
232  // Implements TBTableDriver::editData().
233  Result editData(unsigned int row, unsigned int col, TBData* newVal,
234  std::vector<int>* d = NULL);
235 
236  // Implements TBTableDriver::totalRowsOf().
238 
239  // Implements TBTableDriver::insertRows().
240  Result insertRows(int n);
241 
242  // Implements TBTableDriver::deleteRows().
243  Result deleteRows(std::vector<int> r);
244 
245  // Converts keywords in a casacore::TableRecord to a vector of TBKeywords.
246  static std::vector<TBKeyword*>* getKeywords(casacore::RecordInterface& kws);
247 
248 private:
249  // Reference to table on disk.
251 };
252 
253 // NOTE: the TBTableDriverXML has been disabled. If it is to be used in the
254 // future, the problems with the new TBData infrastructure must be addressed.
255 
256 /*
257 // <summary>
258 // TBTableDriver implementation that accesses tables through XML.
259 // </summary>
260 //
261 // <synopsis>
262 // TBTableDriverXML is a table driver that collects table information into
263 // a casacore::String of information in XML format and then parses the XML. The XML
264 // is generated by the TBXMLDriver (which is what was used with the old
265 // Java table browser) and then parsed by a subclass of TBParser that is
266 // provided in the TableParams. This approach has the advantage of
267 // abstraction and portability; for example, in the future a server/client
268 // architecture could be implemented to browse remote tables. However, it
269 // also as the disadvantage of being slower than the direct approach,
270 // especially when dealing with large amounts of data such as plotting.
271 // See TBParser.
272 // </synopsis>
273 
274 class TBTableDriverXML : public TBTableDriver {
275 public:
276  // Constructor that takes table parameters.
277  TBTableDriverXML(TableParams* tp, TBTable* table);
278 
279  ~TBTableDriverXML();
280 
281 
282  // Implements TBTableDriver::loadRows().
283  Result loadRows(int start, int num, bool full, std::vector<casacore::String>* fields,
284  bool parsedata, ProgressHelper* progressPanel);
285 
286  void loadArray(TBArrayData* d, unsigned int row, unsigned int col);
287 
288  // Implements TBTableDriver::dimensionsOf().
289  std::vector<int> dimensionsOf(unsigned int col);
290 
291  Result editData(unsigned int row, unsigned int col, TBData* newVal,
292  std::vector<int>* d = NULL);
293 
294  // Implements TBTableDriver::totalRowsOf().
295  int totalRowsOf(casacore::String location);
296 
297  // Overrides TBTableDriver::setPrintDebug().
298  void setPrintDebug(bool pdb);
299 
300  // Implements TBTableDriver::insertRows().
301  Result insertRows(int n);
302 
303  // Implements TBTableDriver::deleteRows().
304  Result deleteRows(std::vector<int> r);
305 
306 private:
307  // XML parser.
308  TBParser* parser;
309 };
310 */
311 
312 }
313 
314 #endif /* TBTABLEDRIVER_H_ */
static const unsigned int DEFAULT_SELECT_NUM
The default number of rows to load from the table at a time.
Definition: TBConstants.h:168
bool releaseWriteLock()
Implements TBTableDriver::releaseWriteLock().
int totalRowsOf(casacore::String location)
Implements TBTableDriver::totalRowsOf().
virtual bool releaseWriteLock()=0
releaseWriteLock() must be implemented by any subclass.
Main interface class to a read/write table.
Definition: Table.h:153
Convenience class for a casacore::String/bool tuple.
Definition: TBConstants.h:93
std::vector< int > & subtableRows
Reference to the table&#39;s subtableRows parameter.
casacore::Data types used for loaded data.
Definition: TBData.h:51
static std::vector< TBKeyword * > * getKeywords(casacore::RecordInterface &kws)
Converts keywords in a casacore::TableRecord to a vector of TBKeywords.
TBTableDriver implementation that directly accesses the table on disk.
int & totalRows
Reference to the table&#39;s totalRows parameter.
std::vector< TBField * > & fields
Reference to the table&#39;s fields parameter.
Driver for interacting with the table on disk.
Definition: TBTableDriver.h:68
virtual void loadArray(TBArrayData *d, unsigned int row, unsigned int col)=0
loadArray() must be implemented by any subclass.
virtual Result deleteRows(std::vector< int > r)=0
deleteRows() must be implemented by any subclass.
void loadArray(TBArrayData *d, unsigned int row, unsigned int col)
Implements TBTableDriver::loadArray().
casacore::Data type that holds an array.
Definition: TBData.h:983
Wrapper around a QProgressPanel or other QLabel/QProgressBar pairing.
Parameters that define all table data and meta-deta.
Definition: TBTable.h:90
virtual bool tryWriteLock()=0
tryWriteLock() must be implemented by any subclass.
bool tryWriteLock()
Implements TBTableDriver::tryWriteLock().
Primary interface for the rest of the browser to a table.
Definition: TBTable.h:152
virtual bool canRead()=0
canRead() must be implemented by any subclass.
std::vector< bool > & writable
Reference to the table&#39;s writable parameter.
void setPrintDebug(bool pdb)
Sets whether the driver should print debug information or not.
bool & insertRow
Reference to the table&#39;s insertRow parameter.
virtual Result insertRows(int n)=0
insertRows() must be implemented by any subclass.
bool & removeRow
Reference to the table&#39;s removeRow parameter.
Result deleteRows(std::vector< int > r)
Implements TBTableDriver::deleteRows().
virtual int totalRowsOf(casacore::String location)=0
totalRowsOf() must be implemented by any subclass.
virtual Result editData(unsigned int row, unsigned int col, TBData *newVal, std::vector< int > *d=NULL)=0
editData() must be implemented by any subclass.
virtual bool canWrite()=0
canWrite() must be implemented by any subclass.
bool & taql
Reference to the table&#39;s taql parameter.
std::vector< std::vector< TBData * > * > & data
Reference to the table&#39;s data parameter.
Result editData(unsigned int row, unsigned int col, TBData *newVal, std::vector< int > *d=NULL)
Implements TBTableDriver::editData().
bool canRead()
Implements TBTableDriver::canRead().
TBTable * table
Reference to the table.
casacore::Table m_table
Reference to table on disk.
virtual Result loadRows(int start=0, int num=TBConstants::DEFAULT_SELECT_NUM, bool full=false, std::vector< casacore::String > *fields=NULL, bool parsedata=true, ProgressHelper *pp=NULL)=0
loadRows() must be implemented by any subclass.
Result insertRows(int n)
Implements TBTableDriver::insertRows().
std::vector< TBKeyword * > & keywords
Reference to the table&#39;s keywords parameter.
casacore::String location
The location of the table.
Result loadRows(int start, int num, bool full, std::vector< casacore::String > *fields, bool parsedata, ProgressHelper *progressPanel)
Implements TBTableDriver::loadRows().
int & loadedRows
Reference to the table&#39;s loadedRows parameter.
String: the storage and methods of handling collections of characters.
Definition: String.h:223
virtual std::vector< int > dimensionsOf(unsigned int col)=0
dimensionsOf() must be implemented by any subclass.
virtual ~TBTableDriver()
Abstract base class for Record classes.
TBTableDriver(TableParams *tp, TBTable *table)
Constructor that takes the table and the table parameters.
Parameters to indicate what driver should be used for the table backend.
Definition: TBTable.h:62
TBTableDriverDirect(TableParams *tp, TBTable *table)
Constructor that takes a table and its parameters.
bool printdebug
Indicates whether the driver should print debug information or not.
std::vector< int > dimensionsOf(unsigned int col)
Implements TBTableDriver::dimensionsOf().
DriverParams * dp
Copy of the table&#39;s driver parameters.
bool canWrite()
Implements TBTableDriver::canWrite().
#define casacore
&lt;X11/Intrinsic.h&gt; #defines true, false, casacore::Bool, and String.
Definition: X11Intrinsic.h:42