casacore
MemoryTable.h
Go to the documentation of this file.
1 //# MemoryTable.h: Class for a table held in memory
2 //# Copyright (C) 2003
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 
28 #ifndef TABLES_MEMORYTABLE_H
29 #define TABLES_MEMORYTABLE_H
30 
31 
32 //# Includes
33 #include <casacore/casa/aips.h>
34 #include <casacore/tables/Tables/BaseTable.h>
35 #include <casacore/casa/BasicSL/String.h>
36 #include <casacore/casa/Arrays/Vector.h>
37 
38 namespace casacore { //# NAMESPACE CASACORE - BEGIN
39 
40 //# Forward Declarations
41 class SetupNewTable;
42 class ColumnSet;
43 class TableLockData;
44 
45 
46 // <summary>
47 // Class for a table held in memory
48 // </summary>
49 
50 // <use visibility=local>
51 
52 // <reviewed reviewer="UNKNOWN" date="before2004/08/25" tests="">
53 // </reviewed>
54 
55 // <prerequisite>
56 //# Classes you should understand before using this one.
57 // <li> BaseTable
58 // </prerequisite>
59 
60 // <synopsis>
61 // MemoryTable holds all its data in memory.
62 // It means that the data is not persistent. However, it can be copied to
63 // another table to make the data persistent.
64 // Furthermore it is a table as all other tables, so all table functions
65 // can be applied to it. Some functions (e.g. lock) won't do anything.
66 // Also all table operations like sorting, selecting, and iterating can
67 // be used.
68 //
69 // The constructor accepts a SetupNewTable object which can contain
70 // bindings of columns to any data manager. All bindings to storage
71 // managers will be replaced by a binding to the memory based storage
72 // manager <linkto class=MemoryStMan>MemoryStMan</linkto>. Also all
73 // unbound columns will be bound to MemoryStMan.
74 // Thus it is still possible that a column is bound to a virtual column
75 // engine like <linkto class=CompressComplex>CompressComplex</linkto>.
76 // </synopsis>
77 
78 //# <todo asof="$DATE:$">
79 //# </todo>
80 
81 
82 class MemoryTable : public BaseTable
83 {
84 public:
85 
86  // Create the table in memory using the definitions in the
87  // SetupNewTable object.
88  MemoryTable (SetupNewTable&, rownr_t nrrow, Bool initialize);
89 
90  // The destructor deletes all data.
91  virtual ~MemoryTable();
92 
93  // Try to reopen the table (the underlying one) for read/write access.
94  // It does nothing.
95  virtual void reopenRW();
96 
97  // Is the table stored in big or little endian format?
98  // It returns the endian format of the machine.
99  virtual Bool asBigEndian() const;
100 
101  // Get the storage option used for the table.
102  virtual const StorageOption& storageOption() const;
103 
104  // Is the table in use (i.e. open) in another process?
105  // It always returns False.
106  virtual Bool isMultiUsed (Bool checkSubTable) const;
107 
108  // Get the locking info.
109  // It returns PermanentLocking.
110  virtual const TableLock& lockOptions() const;
111 
112  // Merge the given lock info with the existing one.
113  // It does nothing.
114  virtual void mergeLock (const TableLock& lockOptions);
115 
116  // Has this process the read or write lock, thus can the table
117  // be read or written safely?
118  // It always returns True.
120 
121  // Locking the table is a no-op.
122  virtual Bool lock (FileLocker::LockType, uInt nattempts);
123 
124  // Unlocking the table is a no-op.
125  virtual void unlock();
126 
127  // Flushing the table is a no-op.
128  virtual void flush (Bool fsync, Bool recursive);
129 
130  // Resyncing the Table is a no-op.
131  virtual void resync();
132 
133  // Get the modify counter. It always returns 0.
134  virtual uInt getModifyCounter() const;
135 
136  // Test if the table is opened as writable. It always returns True.
137  virtual Bool isWritable() const;
138 
139  // Copy the table and all its subtables.
140  // It copies the contents of each row to get a real copy.
141  // <group>
142  virtual void copy (const String& newName, int tableOption) const;
143  virtual void deepCopy (const String& newName,
144  const Record& dataManagerInfo,
145  const StorageOption&,
146  int tableOption, Bool, int endianFormat,
147  Bool noRows) const;
148  // </group>
149 
150  // Rename the table. The tableOption is ignored.
151  virtual void rename (const String& newName, int tableOption);
152 
153  // Get the table type (Table::Memory).
154  virtual int tableType() const;
155 
156  // Get the actual table description.
157  virtual TableDesc actualTableDesc() const;
158 
159  // Get the data manager info.
160  virtual Record dataManagerInfo() const;
161 
162  // Get readonly access to the table keyword set.
164 
165  // Get read/write access to the table keyword set.
167 
168  // Write the TableInfo object. It does not do anything.
169  virtual void flushTableInfo();
170 
171  // Get a column object using its index.
172  virtual BaseColumn* getColumn (uInt columnIndex) const;
173 
174  // Get a column object using its name.
175  virtual BaseColumn* getColumn (const String& columnName) const;
176 
177  // Test if it is possible to add a row to this table (yes).
178  virtual Bool canAddRow() const;
179 
180  // Add one or more rows and possibly initialize them.
181  // This will fail for tables not supporting addition of rows.
182  virtual void addRow (rownr_t nrrow = 1, Bool initialize = True);
183 
184  // Test if it is possible to remove a row from this table (yes).
185  virtual Bool canRemoveRow() const;
186 
187  // Remove the given row.
188  virtual void removeRow (rownr_t rownr);
189 
190  // Add a column to the table.
191  // If the DataManager is not a virtual engine, MemoryStMan will be used.
192  // The last Bool argument is not used in MemoryTable, but can be used in
193  // other classes derived from BaseTable.
194  // <group>
195  virtual void addColumn (const ColumnDesc& columnDesc, Bool addToParent);
196  virtual void addColumn (const ColumnDesc& columnDesc,
197  const String& dataManager, Bool byName,
198  Bool addToParent);
199  virtual void addColumn (const ColumnDesc& columnDesc,
200  const DataManager& dataManager, Bool addToParent);
201  virtual void addColumn (const TableDesc& tableDesc,
202  const DataManager& dataManager, Bool addToParent);
203  // </group>
204 
205  // Test if columns can be removed (yes).
206  virtual Bool canRemoveColumn (const Vector<String>& columnNames) const;
207 
208  // Remove columns.
209  virtual void removeColumn (const Vector<String>& columnNames);
210 
211  // Test if a column can be renamed (yes).
212  virtual Bool canRenameColumn (const String& columnName) const;
213 
214  // Rename a column.
215  virtual void renameColumn (const String& newName, const String& oldName);
216 
217  // Rename a hypercolumn.
218  virtual void renameHypercolumn (const String& newName,
219  const String& oldName);
220 
221  // Find the data manager with the given name or for the given column.
222  // There is only one storage manager (MemoryStMan) with name MSM.
223  virtual DataManager* findDataManager (const String& name,
224  Bool byColumn) const;
225 
226 
227 private:
228  CountedPtr<ColumnSet> colSetPtr_p; //# pointer to set of columns
229  TableLockData* lockPtr_p; //# pointer to lock object
230 
231  // Copy constructor is forbidden, because copying a table requires
232  // some more knowledge (like table name of result).
233  // Declaring it private, makes it unusable.
235 
236  // Assignment is forbidden, because copying a table requires
237  // some more knowledge (like table name of result).
238  // Declaring it private, makes it unusable.
240 
241  // Setup the main parts of the object.
242  // <br>Create the initial name map from the table description.
243  // This map maps a name to the name in the original table.
244  // A rename might change the map.
245  // <br>Create the RefColumn objects.
246  // <br>Create the initial TableInfo as a copy of the original BaseTable.
247  void setup (BaseTable* btp);
248 };
249 
250 
251 
252 } //# NAMESPACE CASACORE - END
253 
254 #endif
const TableDesc & tableDesc() const
Get the table description.
Definition: BaseTable.h:272
int tableOption() const
Get the table option.
Definition: BaseTable.h:253
Referenced counted pointer for constant data.
Definition: CountedPtr.h:81
Abstract base class for a data manager.
Definition: DataManager.h:221
LockType
Define the possible lock types.
Definition: FileLocker.h:95
CountedPtr< ColumnSet > colSetPtr_p
Definition: MemoryTable.h:228
virtual void flushTableInfo()
Write the TableInfo object.
virtual TableRecord & rwKeywordSet()
Get read/write access to the table keyword set.
virtual Bool canAddRow() const
Test if it is possible to add a row to this table (yes).
virtual Record dataManagerInfo() const
Get the data manager info.
virtual const StorageOption & storageOption() const
Get the storage option used for the table.
virtual void copy(const String &newName, int tableOption) const
Copy the table and all its subtables.
virtual void mergeLock(const TableLock &lockOptions)
Merge the given lock info with the existing one.
virtual void flush(Bool fsync, Bool recursive)
Flushing the table is a no-op.
virtual void renameHypercolumn(const String &newName, const String &oldName)
Rename a hypercolumn.
virtual void addColumn(const ColumnDesc &columnDesc, const DataManager &dataManager, Bool addToParent)
virtual Bool isMultiUsed(Bool checkSubTable) const
Is the table in use (i.e.
virtual void addColumn(const ColumnDesc &columnDesc, Bool addToParent)
Add a column to the table.
virtual void deepCopy(const String &newName, const Record &dataManagerInfo, const StorageOption &, int tableOption, Bool, int endianFormat, Bool noRows) const
virtual void removeColumn(const Vector< String > &columnNames)
Remove columns.
virtual Bool hasLock(FileLocker::LockType) const
Has this process the read or write lock, thus can the table be read or written safely?...
MemoryTable(const MemoryTable &)
Copy constructor is forbidden, because copying a table requires some more knowledge (like table name ...
virtual void removeRow(rownr_t rownr)
Remove the given row.
MemoryTable(SetupNewTable &, rownr_t nrrow, Bool initialize)
Create the table in memory using the definitions in the SetupNewTable object.
virtual uInt getModifyCounter() const
Get the modify counter.
virtual void resync()
Resyncing the Table is a no-op.
virtual void addColumn(const TableDesc &tableDesc, const DataManager &dataManager, Bool addToParent)
TableLockData * lockPtr_p
Definition: MemoryTable.h:229
virtual Bool canRenameColumn(const String &columnName) const
Test if a column can be renamed (yes).
virtual const TableLock & lockOptions() const
Get the locking info.
virtual DataManager * findDataManager(const String &name, Bool byColumn) const
Find the data manager with the given name or for the given column.
virtual Bool asBigEndian() const
Is the table stored in big or little endian format? It returns the endian format of the machine.
void setup(BaseTable *btp)
Setup the main parts of the object.
virtual void unlock()
Unlocking the table is a no-op.
virtual void renameColumn(const String &newName, const String &oldName)
Rename a column.
virtual int tableType() const
Get the table type (Table::Memory).
virtual BaseColumn * getColumn(uInt columnIndex) const
Get a column object using its index.
virtual ~MemoryTable()
The destructor deletes all data.
virtual Bool lock(FileLocker::LockType, uInt nattempts)
Locking the table is a no-op.
virtual Bool canRemoveRow() const
Test if it is possible to remove a row from this table (yes).
virtual Bool isWritable() const
Test if the table is opened as writable.
virtual TableRecord & keywordSet()
Get readonly access to the table keyword set.
virtual void addColumn(const ColumnDesc &columnDesc, const String &dataManager, Bool byName, Bool addToParent)
virtual void rename(const String &newName, int tableOption)
Rename the table.
virtual void addRow(rownr_t nrrow=1, Bool initialize=True)
Add one or more rows and possibly initialize them.
MemoryTable & operator=(const MemoryTable &)
Assignment is forbidden, because copying a table requires some more knowledge (like table name of res...
virtual void reopenRW()
Try to reopen the table (the underlying one) for read/write access.
virtual BaseColumn * getColumn(const String &columnName) const
Get a column object using its name.
virtual Bool canRemoveColumn(const Vector< String > &columnNames) const
Test if columns can be removed (yes).
virtual TableDesc actualTableDesc() const
Get the actual table description.
Create a new table - define shapes, data managers, etc.
Definition: SetupNewTab.h:341
String: the storage and methods of handling collections of characters.
Definition: String.h:225
this file contains all the compiler specific defines
Definition: mainpage.dox:28
unsigned int uInt
Definition: aipstype.h:51
bool Bool
Define the standard types used by Casacore.
Definition: aipstype.h:42
const Bool True
Definition: aipstype.h:43
uInt64 rownr_t
Define the type of a row number in a table.
Definition: aipsxtype.h:46