00001 //# MemoryTable.h: Class for a table held in memory 00002 //# Copyright (C) 2003 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 00028 #ifndef TABLES_MEMORYTABLE_H 00029 #define TABLES_MEMORYTABLE_H 00030 00031 00032 //# Includes 00033 #include <casacore/casa/aips.h> 00034 #include <casacore/tables/Tables/BaseTable.h> 00035 #include <casacore/casa/BasicSL/String.h> 00036 #include <casacore/casa/Arrays/Vector.h> 00037 00038 namespace casacore { //# NAMESPACE CASACORE - BEGIN 00039 00040 //# Forward Declarations 00041 class SetupNewTable; 00042 class ColumnSet; 00043 class TableLockData; 00044 00045 00046 // <summary> 00047 // Class for a table held in memory 00048 // </summary> 00049 00050 // <use visibility=local> 00051 00052 // <reviewed reviewer="UNKNOWN" date="before2004/08/25" tests=""> 00053 // </reviewed> 00054 00055 // <prerequisite> 00056 //# Classes you should understand before using this one. 00057 // <li> BaseTable 00058 // </prerequisite> 00059 00060 // <synopsis> 00061 // MemoryTable holds all its data in memory. 00062 // It means that the data is not persistent. However, it can be copied to 00063 // another table to make the data persistent. 00064 // Furthermore it is a table as all other tables, so all table functions 00065 // can be applied to it. Some functions (e.g. lock) won't do anything. 00066 // Also all table operations like sorting, selecting, and iterating can 00067 // be used. 00068 // 00069 // The constructor accepts a SetupNewTable object which can contain 00070 // bindings of columns to any data manager. All bindings to storage 00071 // managers will be replaced by a binding to the memory based storage 00072 // manager <linkto class=MemoryStMan>MemoryStMan</linkto>. Also all 00073 // unbound columns will be bound to MemoryStMan. 00074 // Thus it is still possible that a column is bound to a virtual column 00075 // engine like <linkto class=CompressComplex>CompressComplex</linkto>. 00076 // </synopsis> 00077 00078 //# <todo asof="$DATE:$"> 00079 //# </todo> 00080 00081 00082 class MemoryTable : public BaseTable 00083 { 00084 public: 00085 00086 // Create the table in memory using the definitions in the 00087 // SetupNewTable object. 00088 MemoryTable (SetupNewTable&, uInt nrrow, Bool initialize); 00089 00090 // The destructor deletes all data. 00091 virtual ~MemoryTable(); 00092 00093 // Try to reopen the table (the underlying one) for read/write access. 00094 // It does nothing. 00095 virtual void reopenRW(); 00096 00097 // Is the table stored in big or little endian format? 00098 // It returns the endian format of the machine. 00099 virtual Bool asBigEndian() const; 00100 00101 // Get the storage option used for the table. 00102 virtual const StorageOption& storageOption() const; 00103 00104 // Is the table in use (i.e. open) in another process? 00105 // It always returns False. 00106 virtual Bool isMultiUsed (Bool checkSubTable) const; 00107 00108 // Get the locking info. 00109 // It returns PermanentLocking. 00110 virtual const TableLock& lockOptions() const; 00111 00112 // Merge the given lock info with the existing one. 00113 // It does nothing. 00114 virtual void mergeLock (const TableLock& lockOptions); 00115 00116 // Has this process the read or write lock, thus can the table 00117 // be read or written safely? 00118 // It always returns True. 00119 virtual Bool hasLock (FileLocker::LockType) const; 00120 00121 // Locking the table is a no-op. 00122 virtual Bool lock (FileLocker::LockType, uInt nattempts); 00123 00124 // Unlocking the table is a no-op. 00125 virtual void unlock(); 00126 00127 // Flushing the table is a no-op. 00128 virtual void flush (Bool fsync, Bool recursive); 00129 00130 // Resyncing the Table is a no-op. 00131 virtual void resync(); 00132 00133 // Get the modify counter. It always returns 0. 00134 virtual uInt getModifyCounter() const; 00135 00136 // Test if the table is opened as writable. It always returns True. 00137 virtual Bool isWritable() const; 00138 00139 // Copy the table and all its subtables. 00140 // It copies the contents of each row to get a real copy. 00141 // <group> 00142 virtual void copy (const String& newName, int tableOption) const; 00143 virtual void deepCopy (const String& newName, 00144 const Record& dataManagerInfo, 00145 const StorageOption&, 00146 int tableOption, Bool, int endianFormat, 00147 Bool noRows) const; 00148 // </group> 00149 00150 // Rename the table. The tableOption is ignored. 00151 virtual void rename (const String& newName, int tableOption); 00152 00153 // Get the table type (Table::Memory). 00154 virtual int tableType() const; 00155 00156 // Get the actual table description. 00157 virtual TableDesc actualTableDesc() const; 00158 00159 // Get the data manager info. 00160 virtual Record dataManagerInfo() const; 00161 00162 // Get readonly access to the table keyword set. 00163 virtual TableRecord& keywordSet(); 00164 00165 // Get read/write access to the table keyword set. 00166 virtual TableRecord& rwKeywordSet(); 00167 00168 // Write the TableInfo object. It does not do anything. 00169 virtual void flushTableInfo(); 00170 00171 // Get a column object using its index. 00172 virtual BaseColumn* getColumn (uInt columnIndex) const; 00173 00174 // Get a column object using its name. 00175 virtual BaseColumn* getColumn (const String& columnName) const; 00176 00177 // Test if it is possible to add a row to this table (yes). 00178 virtual Bool canAddRow() const; 00179 00180 // Add one or more rows and possibly initialize them. 00181 // This will fail for tables not supporting addition of rows. 00182 virtual void addRow (uInt nrrow = 1, Bool initialize = True); 00183 00184 // Test if it is possible to remove a row from this table (yes). 00185 virtual Bool canRemoveRow() const; 00186 00187 // Remove the given row. 00188 virtual void removeRow (uInt rownr); 00189 00190 // Add a column to the table. 00191 // If the DataManager is not a virtual engine, MemoryStMan will be used. 00192 // The last Bool argument is not used in MemoryTable, but can be used in 00193 // other classes derived from BaseTable. 00194 // <group> 00195 virtual void addColumn (const ColumnDesc& columnDesc, Bool addToParent); 00196 virtual void addColumn (const ColumnDesc& columnDesc, 00197 const String& dataManager, Bool byName, 00198 Bool addToParent); 00199 virtual void addColumn (const ColumnDesc& columnDesc, 00200 const DataManager& dataManager, Bool addToParent); 00201 virtual void addColumn (const TableDesc& tableDesc, 00202 const DataManager& dataManager, Bool addToParent); 00203 // </group> 00204 00205 // Test if columns can be removed (yes). 00206 virtual Bool canRemoveColumn (const Vector<String>& columnNames) const; 00207 00208 // Remove columns. 00209 virtual void removeColumn (const Vector<String>& columnNames); 00210 00211 // Test if a column can be renamed (yes). 00212 virtual Bool canRenameColumn (const String& columnName) const; 00213 00214 // Rename a column. 00215 virtual void renameColumn (const String& newName, const String& oldName); 00216 00217 // Rename a hypercolumn. 00218 virtual void renameHypercolumn (const String& newName, 00219 const String& oldName); 00220 00221 // Find the data manager with the given name or for the given column. 00222 // There is only one storage manager (MemoryStMan) with name MSM. 00223 virtual DataManager* findDataManager (const String& name, 00224 Bool byColumn) const; 00225 00226 00227 private: 00228 ColumnSet* colSetPtr_p; //# pointer to set of columns 00229 TableLockData* lockPtr_p; //# pointer to lock object 00230 00231 // Copy constructor is forbidden, because copying a table requires 00232 // some more knowledge (like table name of result). 00233 // Declaring it private, makes it unusable. 00234 MemoryTable (const MemoryTable&); 00235 00236 // Assignment is forbidden, because copying a table requires 00237 // some more knowledge (like table name of result). 00238 // Declaring it private, makes it unusable. 00239 MemoryTable& operator= (const MemoryTable&); 00240 00241 // Setup the main parts of the object. 00242 // <br>Create the initial name map from the table description. 00243 // This map maps a name to the name in the original table. 00244 // A rename might change the map. 00245 // <br>Create the RefColumn objects. 00246 // <br>Create the initial TableInfo as a copy of the original BaseTable. 00247 void setup (BaseTable* btp); 00248 }; 00249 00250 00251 00252 } //# NAMESPACE CASACORE - END 00253 00254 #endif