casa
$Rev:20696$
|
00001 //# TBTableDriver.h: Driver for interacting with the table on disk. 00002 //# Copyright (C) 2007-2008 00003 //# Associated Universities, Inc. Washington DC, USA. 00004 //# 00005 //# This library is free software; you can redistribute it and/or modify it 00006 //# under the terms of the GNU Library General Public License as published by 00007 //# the Free Software Foundation; either version 2 of the License, or (at your 00008 //# option) any later version. 00009 //# 00010 //# This library is distributed in the hope that it will be useful, but WITHOUT 00011 //# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 00012 //# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public 00013 //# License for more details. 00014 //# 00015 //# You should have received a copy of the GNU Library General Public License 00016 //# along with this library; if not, write to the Free Software Foundation, 00017 //# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA. 00018 //# 00019 //# Correspondence concerning AIPS++ should be addressed as follows: 00020 //# Internet email: aips2-request@nrao.edu. 00021 //# Postal address: AIPS++ Project Office 00022 //# National Radio Astronomy Observatory 00023 //# 520 Edgemont Road 00024 //# Charlottesville, VA 22903-2475 USA 00025 //# 00026 //# $Id: $ 00027 #ifndef TBTABLEDRIVER_H_ 00028 #define TBTABLEDRIVER_H_ 00029 00030 #include <casaqt/QtBrowser/TBConstants.h> 00031 #include <casaqt/QtBrowser/TBTable.h> 00032 00033 #include <casa/BasicSL/String.h> 00034 #include <tables/Tables/Table.h> 00035 00036 #include <vector> 00037 00038 #include <casa/namespace.h> 00039 using namespace std; 00040 00041 namespace casa { 00042 00043 //# Forward Declarations 00044 class TableParams; 00045 class TBField; 00046 class TBKeyword; 00047 class TableRecord; 00048 class TBArray; 00049 class TBParser; 00050 class DriverParams; 00051 class ProgressHelper; 00052 class TBData; 00053 class TBArrayData; 00054 class Table; 00055 00056 // <summary> 00057 // Driver for interacting with the table on disk. 00058 // </summary> 00059 // 00060 // <synopsis> 00061 // TBTableDriver is an abstract superclass that defines how any implementing 00062 // subclass must behave in order to be used by a TBTable. Any implementing 00063 // subclass should update the table parameters that the driver has references 00064 // to via the TableParams passed into the constructor. 00065 // </synopsis> 00066 00067 class TBTableDriver { 00068 public: 00069 // Constructor that takes the table and the table parameters. 00070 TBTableDriver(TableParams* tp, TBTable* table); 00071 00072 virtual ~TBTableDriver(); 00073 00074 00075 // Sets whether the driver should print debug information or not. 00076 void setPrintDebug(bool pdb); 00077 00078 00079 // canRead() must be implemented by any subclass. 00080 // Returns whether or not the underlying table can be read (i.e., the read 00081 // lock is set). Does not necessary guarantee that the next read operation 00082 // will succeed, but a sufficiently close check before a read should 00083 // suffice in most situations. 00084 virtual bool canRead() = 0; 00085 00086 // canWrite() must be implemented by any subclass. 00087 // Returns whether or not the underlying table can be written (i.e., the 00088 // write lock is set). Does not necessary guarantee that the next write 00089 // operation will succeed, but a sufficiently close check before a write 00090 // should suffice in most situations. 00091 virtual bool canWrite() = 0; 00092 00093 // tryWriteLock() must be implemented by any subclass. 00094 // Tries to reopen the table using a write lock, and returns whether the 00095 // operation succeeded or not. This MUST be done before any editing 00096 // operations, and the lock should be released afterwards using 00097 // releaseWriteLock(). 00098 virtual bool tryWriteLock() = 0; 00099 00100 // releaseWriteLock() must be implemented by any subclass. 00101 // Releases the write lock if needed. 00102 virtual bool releaseWriteLock() = 0; 00103 00104 // loadRows() must be implemented by any subclass. 00105 // Loads the given rows into the table. See TBTable::loadRows(); 00106 virtual Result loadRows(int start = 0, 00107 int num = TBConstants::DEFAULT_SELECT_NUM, 00108 bool full = false, vector<String>* fields = NULL, 00109 bool parsedata = true, 00110 ProgressHelper* pp = NULL) = 0; 00111 00112 // loadArray() must be implemented by any subclass. 00113 // Loads the data into the given array at the given coordinates. 00114 virtual void loadArray(TBArrayData* d, unsigned int row, 00115 unsigned int col) = 0; 00116 00117 // dimensionsOf() must be implemented by any subclass. 00118 // Returns the array dimensions of the given field. See 00119 // TBTable::dimensionsOf(). 00120 virtual vector<int> dimensionsOf(unsigned int col) = 0; 00121 00122 // editData() must be implemented by any subclass. 00123 // Updates the cell at the given coordinates to have the given value. 00124 // If the data is an array, the array coordinates are provided in d. 00125 // Returns the result of the operation. 00126 virtual Result editData(unsigned int row, unsigned int col, TBData* newVal, 00127 vector<int>* d = NULL) = 0; 00128 00129 // totalRowsOf() must be implemented by any subclass. 00130 // Returns the total rows of the table at the given location. See 00131 // TBTable::totalRowsOf(). 00132 virtual int totalRowsOf(String location) = 0; 00133 00134 // insertRows() must be implemented by any subclass. 00135 // Inserts the given number of rows at the end of the table. See 00136 // TBTable::insertRows(). 00137 virtual Result insertRows(int n) = 0; 00138 00139 // deleteRows() must be implemented by any subclass. 00140 // Deletes the given rows. See TBTable::deleteRows(). 00141 virtual Result deleteRows(vector<int> r) = 0; 00142 00143 protected: 00144 // The location of the table. 00145 String location; 00146 00147 // Reference to the table's insertRow parameter. 00148 bool& insertRow; 00149 00150 // Reference to the table's removeRow parameter. 00151 bool& removeRow; 00152 00153 // Reference to the table's data parameter. 00154 vector<vector<TBData*>*>& data; 00155 00156 // Reference to the table's fields parameter. 00157 vector<TBField*>& fields; 00158 00159 // Reference to the table's keywords parameter. 00160 vector<TBKeyword*>& keywords; 00161 00162 // Reference to the table's subtableRows parameter. 00163 vector<int>& subtableRows; 00164 00165 // Reference to the table's totalRows parameter. 00166 int& totalRows; 00167 00168 // Reference to the table's loadedRows parameter. 00169 int& loadedRows; 00170 00171 // Reference to the table's writable parameter. 00172 vector<bool>& writable; 00173 00174 // Reference to the table's taql parameter. 00175 bool& taql; 00176 00177 // Copy of the table's driver parameters. 00178 DriverParams* dp; 00179 00180 // Indicates whether the driver should print debug information or not. 00181 bool printdebug; 00182 00183 // Reference to the table. 00184 TBTable* table; 00185 00186 00187 // Sends a direct query through the XMLDriver and returns the Result. 00188 // Result query(String type, String query); 00189 }; 00190 00191 // <summary> 00192 // TBTableDriver implementation that directly accesses the table on disk. 00193 // </summary> 00194 // 00195 // <synopsis> 00196 // TBTableDriverDirect is a table driver that accesses the table on disk via 00197 // the CASA tables code module. It is therefore faster than the XML driver 00198 // and is the default for the table browser. See casa::Table. 00199 // </synopsis> 00200 00201 class TBTableDriverDirect : public TBTableDriver { 00202 public: 00203 // Constructor that takes a table and its parameters. 00204 TBTableDriverDirect(TableParams* tp, TBTable* table); 00205 00206 virtual ~TBTableDriverDirect(); 00207 00208 00209 // Implements TBTableDriver::canRead(). 00210 bool canRead(); 00211 00212 // Implements TBTableDriver::canWrite(). 00213 bool canWrite(); 00214 00215 // Implements TBTableDriver::tryWriteLock(). 00216 bool tryWriteLock(); 00217 00218 // Implements TBTableDriver::releaseWriteLock(). 00219 bool releaseWriteLock(); 00220 00221 // Implements TBTableDriver::loadRows(). 00222 Result loadRows(int start, int num, bool full, vector<String>* fields, 00223 bool parsedata, ProgressHelper* progressPanel); 00224 00225 // Implements TBTableDriver::loadArray(). 00226 void loadArray(TBArrayData* d, unsigned int row, unsigned int col); 00227 00228 // Implements TBTableDriver::dimensionsOf(). 00229 vector<int> dimensionsOf(unsigned int col); 00230 00231 // Implements TBTableDriver::editData(). 00232 Result editData(unsigned int row, unsigned int col, TBData* newVal, 00233 vector<int>* d = NULL); 00234 00235 // Implements TBTableDriver::totalRowsOf(). 00236 int totalRowsOf(String location); 00237 00238 // Implements TBTableDriver::insertRows(). 00239 Result insertRows(int n); 00240 00241 // Implements TBTableDriver::deleteRows(). 00242 Result deleteRows(vector<int> r); 00243 00244 // Converts keywords in a TableRecord to a vector of TBKeywords. 00245 static vector<TBKeyword*>* getKeywords(RecordInterface& kws); 00246 00247 private: 00248 // Reference to table on disk. 00249 Table m_table; 00250 }; 00251 00252 // NOTE: the TBTableDriverXML has been disabled. If it is to be used in the 00253 // future, the problems with the new TBData infrastructure must be addressed. 00254 00255 /* 00256 // <summary> 00257 // TBTableDriver implementation that accesses tables through XML. 00258 // </summary> 00259 // 00260 // <synopsis> 00261 // TBTableDriverXML is a table driver that collects table information into 00262 // a String of information in XML format and then parses the XML. The XML 00263 // is generated by the TBXMLDriver (which is what was used with the old 00264 // Java table browser) and then parsed by a subclass of TBParser that is 00265 // provided in the TableParams. This approach has the advantage of 00266 // abstraction and portability; for example, in the future a server/client 00267 // architecture could be implemented to browse remote tables. However, it 00268 // also as the disadvantage of being slower than the direct approach, 00269 // especially when dealing with large amounts of data such as plotting. 00270 // See TBParser. 00271 // </synopsis> 00272 00273 class TBTableDriverXML : public TBTableDriver { 00274 public: 00275 // Constructor that takes table parameters. 00276 TBTableDriverXML(TableParams* tp, TBTable* table); 00277 00278 ~TBTableDriverXML(); 00279 00280 00281 // Implements TBTableDriver::loadRows(). 00282 Result loadRows(int start, int num, bool full, vector<String>* fields, 00283 bool parsedata, ProgressHelper* progressPanel); 00284 00285 void loadArray(TBArrayData* d, unsigned int row, unsigned int col); 00286 00287 // Implements TBTableDriver::dimensionsOf(). 00288 vector<int> dimensionsOf(unsigned int col); 00289 00290 Result editData(unsigned int row, unsigned int col, TBData* newVal, 00291 vector<int>* d = NULL); 00292 00293 // Implements TBTableDriver::totalRowsOf(). 00294 int totalRowsOf(String location); 00295 00296 // Overrides TBTableDriver::setPrintDebug(). 00297 void setPrintDebug(bool pdb); 00298 00299 // Implements TBTableDriver::insertRows(). 00300 Result insertRows(int n); 00301 00302 // Implements TBTableDriver::deleteRows(). 00303 Result deleteRows(vector<int> r); 00304 00305 private: 00306 // XML parser. 00307 TBParser* parser; 00308 }; 00309 */ 00310 00311 } 00312 00313 #endif /* TBTABLEDRIVER_H_ */