TBTableDriver.h

Go to the documentation of this file.
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 namespace casa {
00039 
00040 //# Forward Declarations
00041 class TableParams;
00042 class TBField;
00043 class TBKeyword;
00044 class TableRecord;
00045 class TBArray;
00046 class TBParser;
00047 class DriverParams;
00048 class ProgressHelper;
00049 class TBData;
00050 class TBArrayData;
00051 class Table;
00052 
00053 // <summary>
00054 // Driver for interacting with the table on disk.
00055 // </summary>
00056 //
00057 // <synopsis>
00058 // TBTableDriver is an abstract superclass that defines how any implementing
00059 // subclass must behave in order to be used by a TBTable.  Any implementing
00060 // subclass should update the table parameters that the driver has references
00061 // to via the TableParams passed into the constructor.
00062 // </synopsis>
00063 
00064 class TBTableDriver {
00065 public:
00066     // Constructor that takes the table and the table parameters.
00067     TBTableDriver(TableParams* tp, TBTable* table);
00068 
00069     virtual ~TBTableDriver();
00070 
00071     
00072     // Sets whether the driver should print debug information or not.
00073     void setPrintDebug(bool pdb);
00074     
00075     
00076     // canRead() must be implemented by any subclass.
00077     // Returns whether or not the underlying table can be read (i.e., the read
00078     // lock is set).  Does not necessary guarantee that the next read operation
00079     // will succeed, but a sufficiently close check before a read should
00080     // suffice in most situations.
00081     virtual bool canRead() = 0;
00082     
00083     // canWrite() must be implemented by any subclass.
00084     // Returns whether or not the underlying table can be written (i.e., the
00085     // write lock is set).  Does not necessary guarantee that the next write
00086     // operation will succeed, but a sufficiently close check before a write
00087     // should suffice in most situations.
00088     virtual bool canWrite() = 0;
00089     
00090     // tryWriteLock() must be implemented by any subclass.
00091     // Tries to reopen the table using a write lock, and returns whether the
00092     // operation succeeded or not.  This MUST be done before any editing
00093     // operations, and the lock should be released afterwards using
00094     // releaseWriteLock().
00095     virtual bool tryWriteLock() = 0;
00096     
00097     // releaseWriteLock() must be implemented by any subclass.
00098     // Releases the write lock if needed.
00099     virtual bool releaseWriteLock() = 0;
00100     
00101     // loadRows() must be implemented by any subclass.
00102     // Loads the given rows into the table.  See TBTable::loadRows();
00103     virtual Result loadRows(int start = 0,
00104                             int num = TBConstants::DEFAULT_SELECT_NUM,
00105                             bool full = false, std::vector<String>* fields = NULL,
00106                             bool parsedata = true,
00107                             ProgressHelper* pp = NULL) = 0;
00108     
00109     // loadArray() must be implemented by any subclass.
00110     // Loads the data into the given array at the given coordinates.
00111     virtual void loadArray(TBArrayData* d, unsigned int row,
00112                            unsigned int col) = 0;
00113 
00114     // dimensionsOf() must be implemented by any subclass.
00115     // Returns the array dimensions of the given field.  See
00116     // TBTable::dimensionsOf().
00117     virtual std::vector<int> dimensionsOf(unsigned int col) = 0;
00118     
00119     // editData() must be implemented by any subclass.
00120     // Updates the cell at the given coordinates to have the given value.
00121     // If the data is an array, the array coordinates are provided in d.
00122     // Returns the result of the operation.
00123     virtual Result editData(unsigned int row, unsigned int col, TBData* newVal,
00124                             std::vector<int>* d = NULL) = 0;
00125                                 
00126     // totalRowsOf() must be implemented by any subclass.
00127     // Returns the total rows of the table at the given location.  See
00128     // TBTable::totalRowsOf().
00129     virtual int totalRowsOf(String location) = 0;
00130 
00131     // insertRows() must be implemented by any subclass.
00132     // Inserts the given number of rows at the end of the table.  See
00133     // TBTable::insertRows().
00134     virtual Result insertRows(int n) = 0;
00135 
00136     // deleteRows() must be implemented by any subclass.
00137     // Deletes the given rows.  See TBTable::deleteRows().
00138     virtual Result deleteRows(std::vector<int> r) = 0;
00139 
00140 protected:
00141     // The location of the table.
00142     String location;
00143     
00144     // Reference to the table's insertRow parameter.
00145     bool& insertRow;
00146     
00147     // Reference to the table's removeRow parameter.
00148     bool& removeRow;
00149     
00150     // Reference to the table's data parameter.    
00151     std::vector<std::vector<TBData*>*>& data;
00152     
00153     // Reference to the table's fields parameter.
00154     std::vector<TBField*>& fields;
00155     
00156     // Reference to the table's keywords parameter.
00157     std::vector<TBKeyword*>& keywords;
00158     
00159     // Reference to the table's subtableRows parameter.
00160     std::vector<int>& subtableRows;
00161     
00162     // Reference to the table's totalRows parameter.
00163     int& totalRows;
00164     
00165     // Reference to the table's loadedRows parameter.
00166     int& loadedRows;
00167     
00168     // Reference to the table's writable parameter.
00169     std::vector<bool>& writable;
00170     
00171     // Reference to the table's taql parameter.
00172     bool& taql;
00173     
00174     // Copy of the table's driver parameters.
00175     DriverParams* dp;
00176     
00177     // Indicates whether the driver should print debug information or not.
00178     bool printdebug;
00179     
00180     // Reference to the table.
00181     TBTable* table;
00182 
00183     
00184     // Sends a direct query through the XMLDriver and returns the Result.
00185     // Result query(String type, String query);
00186 };
00187 
00188 // <summary>
00189 // TBTableDriver implementation that directly accesses the table on disk.
00190 // </summary>
00191 //
00192 // <synopsis>
00193 // TBTableDriverDirect is a table driver that accesses the table on disk via
00194 // the CASA tables code module.  It is therefore faster than the XML driver
00195 // and is the default for the table browser.  See casa::Table.
00196 // </synopsis>
00197 
00198 class TBTableDriverDirect : public TBTableDriver {
00199 public:
00200     // Constructor that takes a table and its parameters.
00201     TBTableDriverDirect(TableParams* tp, TBTable* table);
00202 
00203     virtual ~TBTableDriverDirect();
00204 
00205     
00206     // Implements TBTableDriver::canRead().
00207     bool canRead();
00208     
00209     // Implements TBTableDriver::canWrite().
00210     bool canWrite();
00211     
00212     // Implements TBTableDriver::tryWriteLock().
00213     bool tryWriteLock();
00214 
00215     // Implements TBTableDriver::releaseWriteLock().
00216     bool releaseWriteLock();
00217     
00218     // Implements TBTableDriver::loadRows().
00219     Result loadRows(int start, int num, bool full, std::vector<String>* fields,
00220                     bool parsedata, ProgressHelper* progressPanel);
00221     
00222     // Implements TBTableDriver::loadArray().
00223     void loadArray(TBArrayData* d, unsigned int row, unsigned int col);
00224 
00225     // Implements TBTableDriver::dimensionsOf().
00226     std::vector<int> dimensionsOf(unsigned int col);
00227     
00228     // Implements TBTableDriver::editData().
00229     Result editData(unsigned int row, unsigned int col, TBData* newVal,
00230                     std::vector<int>* d = NULL);
00231                                 
00232     // Implements TBTableDriver::totalRowsOf().
00233     int totalRowsOf(String location);
00234 
00235     // Implements TBTableDriver::insertRows().
00236     Result insertRows(int n);
00237 
00238     // Implements TBTableDriver::deleteRows().
00239     Result deleteRows(std::vector<int> r);
00240 
00241     // Converts keywords in a TableRecord to a vector of TBKeywords.
00242     static std::vector<TBKeyword*>* getKeywords(RecordInterface& kws);
00243     
00244 private:
00245     // Reference to table on disk.
00246     Table m_table;
00247 };
00248 
00249 // NOTE: the TBTableDriverXML has been disabled.  If it is to be used in the
00250 // future, the problems with the new TBData infrastructure must be addressed.
00251 
00252 /*
00253 // <summary>
00254 // TBTableDriver implementation that accesses tables through XML.
00255 // </summary>
00256 //
00257 // <synopsis>
00258 // TBTableDriverXML is a table driver that collects table information into
00259 // a String of information in XML format and then parses the XML.  The XML
00260 // is generated by the TBXMLDriver (which is what was used with the old
00261 // Java table browser) and then parsed by a subclass of TBParser that is
00262 // provided in the TableParams.  This approach has the advantage of
00263 // abstraction and portability; for example, in the future a server/client
00264 // architecture could be implemented to browse remote tables.  However, it
00265 // also as the disadvantage of being slower than the direct approach,
00266 // especially when dealing with large amounts of data such as plotting.
00267 // See TBParser.
00268 // </synopsis>
00269 
00270 class TBTableDriverXML : public TBTableDriver {
00271 public:
00272     // Constructor that takes table parameters.
00273     TBTableDriverXML(TableParams* tp, TBTable* table);
00274 
00275     ~TBTableDriverXML();
00276 
00277     
00278     // Implements TBTableDriver::loadRows().
00279     Result loadRows(int start, int num, bool full, std::vector<String>* fields,
00280                     bool parsedata, ProgressHelper* progressPanel);
00281     
00282     void loadArray(TBArrayData* d, unsigned int row, unsigned int col);
00283 
00284     // Implements TBTableDriver::dimensionsOf().
00285     std::vector<int> dimensionsOf(unsigned int col);
00286     
00287     Result editData(unsigned int row, unsigned int col, TBData* newVal,
00288                         std::vector<int>* d = NULL);
00289                                 
00290     // Implements TBTableDriver::totalRowsOf().
00291     int totalRowsOf(String location);
00292 
00293     // Overrides TBTableDriver::setPrintDebug().
00294     void setPrintDebug(bool pdb);
00295 
00296     // Implements TBTableDriver::insertRows().
00297     Result insertRows(int n);
00298 
00299     // Implements TBTableDriver::deleteRows().
00300     Result deleteRows(std::vector<int> r);
00301     
00302 private:
00303     // XML parser.
00304     TBParser* parser;
00305 };
00306 */
00307 
00308 }
00309 
00310 #endif /* TBTABLEDRIVER_H_ */
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated on 31 Aug 2016 for casa by  doxygen 1.6.1