BaseTable.h

Classes

BaseTable -- Abstract base class for tables (full description)

class BaseTable

Interface

Public Members
BaseTable (const String& tableName, int tableOption, uInt nrrow)
virtual ~BaseTable()
void link()
static void unlink (BaseTable*)
virtual Bool isNull() const
virtual void reopenRW() = 0
virtual Bool asBigEndian() const = 0
virtual Bool isMultiUsed(Bool checkSubTables) const = 0
virtual const TableLock& lockOptions() const = 0
virtual void mergeLock (const TableLock& lockOptions) = 0
virtual Bool hasLock (FileLocker::LockType) const = 0
virtual Bool lock (FileLocker::LockType, uInt nattempts) = 0
virtual void unlock() = 0
virtual void flush (Bool fsync, Bool recursive) = 0
virtual void resync() = 0
virtual uInt getModifyCounter() const = 0
virtual void setTableChanged()
void doNotWrite()
virtual Bool isWritable() const = 0
Bool isColumnWritable (const String& columnName) const
Bool isColumnWritable (uInt columnIndex) const
Bool isColumnStored (const String& columnName) const
Bool isColumnStored (uInt columnIndex) const
const String& tableName() const
virtual void rename (const String& newName, int tableOption)
virtual void copy (const String& newName, int tableOption) const
virtual void deepCopy (const String& newName, const Record& dataManagerInfo, int tableOption, Bool valueCopy, int endianFormat, Bool noRows) const
virtual int tableType() const
int tableOption() const
void markForDelete (Bool callback, const String& oldName)
void unmarkForDelete (Bool callback, const String& oldName)
Bool isMarkedForDelete() const
const TableDesc& tableDesc() const
virtual TableDesc actualTableDesc() const = 0
virtual Record dataManagerInfo() const = 0
virtual TableRecord& keywordSet() = 0
virtual TableRecord& rwKeywordSet() = 0
TableInfo& tableInfo()
static TableInfo tableInfo (const String& tableName)
virtual void flushTableInfo()
uInt nrow() const
virtual BaseColumn* getColumn (uInt columnIndex) const = 0
virtual BaseColumn* getColumn (const String& columnName) const = 0
virtual Bool canAddRow() const
virtual void addRow (uInt nrrow = 1, Bool initialize = True)
virtual Bool canRemoveRow() const
virtual void removeRow (uInt rownr)
void removeRow (const Vector<uInt>& rownrs)
virtual DataManager* findDataManager (const String& dataManagerName) const = 0
BaseTable* select (const TableExprNode&, uInt maxRow)
BaseTable* select (const Vector<uInt>& rownrs)
BaseTable* select (const Block<Bool>& mask)
BaseTable* project (const Block<String>& columnNames)
BaseTable* tabAnd (BaseTable*)
BaseTable* tabOr (BaseTable*)
BaseTable* tabSub (BaseTable*)
BaseTable* tabXor (BaseTable*)
BaseTable* tabNot ()
BaseTable* sort (const Block<String>& columnNames, const PtrBlock<ObjCompareFunc*>& compareFunctionPointers, const Block<Int>& sortOrder, int sortOption)
BaseTableIterator* makeIterator (const Block<String>& columnNames, const PtrBlock<ObjCompareFunc*>&, const Block<Int>& orders, int option)
virtual void addColumn (const ColumnDesc& columnDesc)
virtual void addColumn (const ColumnDesc& columnDesc, const String& dataManager, Bool byName)
virtual void addColumn (const ColumnDesc& columnDesc, const DataManager& dataManager)
virtual void addColumn (const TableDesc& tableDesc, const DataManager& dataManager)
void addColumns (const TableDesc& tableDesc, const Record& dmInfo)
virtual Bool canRemoveColumn (const Vector<String>& columnNames) const = 0
virtual void removeColumn (const Vector<String>& columnNames) = 0
Bool checkRemoveColumn (const Vector<String>& columnNames, Bool throwException) const
virtual Bool canRenameColumn (const String& columnName) const = 0
virtual void renameColumn (const String& newName, const String& oldName) = 0
virtual Vector<uInt> rowNumbers() const
virtual BaseTable* root()
virtual Bool rowOrder() const
virtual Vector<uInt>* rowStorage()
virtual Bool adjustRownrs (uInt nrrow, Vector<uInt>& rownrs, Bool determineOrder) const
virtual BaseTable* doSort (PtrBlock<BaseColumn*>&, const PtrBlock<ObjCompareFunc*>&, const Block<Int>& sortOrder, int sortOption)
RefTable* makeRefTable (Bool rowOrder, uInt initialNrrow)
void checkRowNumber (uInt rownr) const
Protected Members
void scratchCallback (Bool isScratch, const String& oldName) const
Bool makeTableDir()
void trueDeepCopy (const String& newName, const Record& dataManagerInfo, int tableOption, int endianFormat, Bool noRows) const
void prepareCopyRename (const String& newName, int tableOption) const
virtual void renameSubTables (const String& newName, const String& oldName)
void throwIfTableExists()
Bool openedForWrite() const
void writeStart (AipsIO&, Bool bigEndian)
void writeEnd (AipsIO&)
Bool shouldNotWrite() const
void getTableInfo()
Private Members
BaseTable (const BaseTable&)
BaseTable& operator= (const BaseTable&)
void checkRowNumberThrow (uInt rownr) const
void logicCheck (BaseTable* that)
uInt logicRows (uInt*& rownrs, Bool& allocated)
const TableDesc& makeTableDesc() const

Description

Review Status

Reviewed By:
UNKNOWN
Date Reviewed:
before2004/08/25

Prerequisite

Etymology

BaseTable is the (abstract) base class for different kind of tables.

Synopsis

BaseTables defines many virtual functions, which are actually implemented in the underlying table classes like PlainTable and RefTable. Other functions like sort and select are implemented in BaseTable itself.

The functions in BaseTable and its derived classes can only be used by the table system classes. All user access is via the envelope class Table, which references (counted) BaseTable.

To Do

Member Description

BaseTable (const String& tableName, int tableOption, uInt nrrow)

Initialize the object.

virtual ~BaseTable()

void link()

Link to this BaseTable object (i.e. increase reference count).

static void unlink (BaseTable*)

Unlink from a BaseTable. Delete it if no more references.

virtual Bool isNull() const

Is the table a null table? By default it is not.

virtual void reopenRW() = 0

Reopen the table for read/write.

virtual Bool asBigEndian() const = 0

Is the table stored in big or little endian format?

virtual Bool isMultiUsed(Bool checkSubTables) const = 0

Is the table in use (i.e. open) in another process? If checkSubTables is set, it is also checked if a subtable is used in another process.

virtual const TableLock& lockOptions() const = 0

Get the locking info.

virtual void mergeLock (const TableLock& lockOptions) = 0

Merge the given lock info with the existing one.

virtual Bool hasLock (FileLocker::LockType) const = 0

Has this process the read or write lock, thus can the table be read or written safely?

virtual Bool lock (FileLocker::LockType, uInt nattempts) = 0

Try to lock the table for read or write access.

virtual void unlock() = 0

Unlock the table. This will also synchronize the table data, thus force the data to be written to disk.

virtual void flush (Bool fsync, Bool recursive) = 0

Flush the table, i.e. write it to disk.

virtual void resync() = 0

Resync the Table object with the table file.

virtual uInt getModifyCounter() const = 0

Get the modify counter.

virtual void setTableChanged()

Set the table to being changed. By default it does nothing.

void doNotWrite()

Do not write the table (used in in case of exceptions).

virtual Bool isWritable() const = 0

Test if this table is writable. This tells if values can be put into a column.

Bool isColumnWritable (const String& columnName) const
Bool isColumnWritable (uInt columnIndex) const

Test if the given column is writable.

Bool isColumnStored (const String& columnName) const
Bool isColumnStored (uInt columnIndex) const

Test if the given column is stored (otherwise it is virtual).

const String& tableName() const

Get the table name.

virtual void rename (const String& newName, int tableOption)

Rename the table. The following options can be given:

Table::Update
A table with this name must already exists, which will be overwritten. When succesfully renamed, the table is unmarked for delete (if necessary).
Table::New
When a table with this name exists, it will be overwritten. When succesfully renamed, the table is unmarked for delete (if necessary).
Table::NewNoReplace
When a table with this name already exists, an exception is thrown. When succesfully renamed, the table is unmarked for delete (if necessary).
Table::Scratch
Same as Table::New, but followed by markForDelete().
The rename function in this base class renames the table file. In a derived class (e.g. PlainTable) the function should also be implemented to rename subtables in its keywords.

virtual void copy (const String& newName, int tableOption) const
virtual void deepCopy (const String& newName, const Record& dataManagerInfo, int tableOption, Bool valueCopy, int endianFormat, Bool noRows) const

Copy the table and all its subtables. The default implementation of deepCopy is to call copy. The following options can be given:

Table::New
When a table with this name exists, it will be overwritten.
Table::NewNoReplace
When a table with this name already exists, an exception is thrown.
Table::Scratch
Same as Table::New, but followed by markForDelete().

virtual int tableType() const

Get the table type. By default it returns Table::Plain.

int tableOption() const

Get the table option.

void markForDelete (Bool callback, const String& oldName)

Mark the table for delete. This means that the underlying table gets deleted when it is actually destructed. The scratchCallback function is called when needed.

void unmarkForDelete (Bool callback, const String& oldName)

Unmark the table for delete. This means the underlying table does not get deleted when destructed. The scratchCallback function is called when needed.

Bool isMarkedForDelete() const

Test if the table is marked for delete.

const TableDesc& tableDesc() const

Get the table description.

virtual TableDesc actualTableDesc() const = 0

Get the actual table description.

virtual Record dataManagerInfo() const = 0

Get the data manager info.

virtual TableRecord& keywordSet() = 0

Get readonly access to the table keyword set.

virtual TableRecord& rwKeywordSet() = 0

Get read/write access to the table keyword set. This requires that the table is locked (or it gets locked when using AutoLocking mode).

TableInfo& tableInfo()

Get access to the TableInfo object.

static TableInfo tableInfo (const String& tableName)

Get the table info of the table with the given name. An empty object is returned when the table is unknown.

virtual void flushTableInfo()

Write the TableInfo object.

uInt nrow() const

Get number of rows.

virtual BaseColumn* getColumn (uInt columnIndex) const = 0

Get a column object using its index.

virtual BaseColumn* getColumn (const String& columnName) const = 0

Get a column object using its name.

virtual Bool canAddRow() const

Test if it is possible to add a row to this table.

virtual void addRow (uInt nrrow = 1, Bool initialize = True)

Add one or more rows and possibly initialize them. This will fail for tables not supporting addition of rows.

virtual Bool canRemoveRow() const

Test if it is possible to remove a row from this table.

virtual void removeRow (uInt rownr)
void removeRow (const Vector<uInt>& rownrs)

Remove rows. This will fail for tables not supporting removal of rows.

Tip The following code fragments do NOT have the same result:
       tab.removeRow (10);      // remove row 10
       tab.removeRow (20);      // remove row 20, which was 21
    </em></blockquote>
       Vector<uInt> vec(2);
       vec(0) = 10;
       vec(1) = 20;
       tab.removeRow (vec);     // remove row 10 and 20
    
because in the first fragment removing row 10 turns the former row 21 into row 20.

virtual DataManager* findDataManager (const String& dataManagerName) const = 0

Find the data manager with the given name.

BaseTable* select (const TableExprNode&, uInt maxRow)

Select rows using the given expression.

BaseTable* select (const Vector<uInt>& rownrs)

Select rows using a vector of row numbers.

BaseTable* select (const Block<Bool>& mask)

Select rows using a mask block. The length of the block must match the number of rows in the table. If True, the corresponding row will be selected.

BaseTable* project (const Block<String>& columnNames)

Project the given columns (i.e. select the columns).

BaseTable* tabAnd (BaseTable*)

Do logical operations on a table.

intersection with another table

BaseTable* tabOr (BaseTable*)

Do logical operations on a table.

union with another table

BaseTable* tabSub (BaseTable*)

Do logical operations on a table.

subtract another table

BaseTable* tabXor (BaseTable*)

Do logical operations on a table.

xor with another table

BaseTable* tabNot ()

Do logical operations on a table.

take complement

BaseTable* sort (const Block<String>& columnNames, const PtrBlock<ObjCompareFunc*>& compareFunctionPointers, const Block<Int>& sortOrder, int sortOption)

Sort a table on one or more columns of scalars.

BaseTableIterator* makeIterator (const Block<String>& columnNames, const PtrBlock<ObjCompareFunc*>&, const Block<Int>& orders, int option)

Create an iterator.

virtual void addColumn (const ColumnDesc& columnDesc)
virtual void addColumn (const ColumnDesc& columnDesc, const String& dataManager, Bool byName)
virtual void addColumn (const ColumnDesc& columnDesc, const DataManager& dataManager)
virtual void addColumn (const TableDesc& tableDesc, const DataManager& dataManager)

Add one or more columns to the table. The default implementation throws an "invalid operation" exception.

void addColumns (const TableDesc& tableDesc, const Record& dmInfo)

Add one or more columns to the table. The data manager to use is described in the record.

virtual Bool canRemoveColumn (const Vector<String>& columnNames) const = 0

Test if columns can be removed.

virtual void removeColumn (const Vector<String>& columnNames) = 0

Remove columns.

Bool checkRemoveColumn (const Vector<String>& columnNames, Bool throwException) const

Check if the set of columns can be removed. It checks if columns have not been specified twice and it checks if they exist. If the flag is set an exception is thrown if errors are found.

virtual Bool canRenameColumn (const String& columnName) const = 0

Test if a column can be renamed.

virtual void renameColumn (const String& newName, const String& oldName) = 0

Rename a column.

virtual Vector<uInt> rowNumbers() const

Get a vector of row numbers. By default it returns the row numbers 0..nrrow()-1. It needs to be implemented for RefTable only.

virtual BaseTable* root()

Get pointer to root table (i.e. parent of a RefTable). Default it is this table. It is meant for the reference tables after a select or sort which can then still name their parent as the root.

virtual Bool rowOrder() const

Tell if the table is in row order. By default it is, since normally a table is always in row order. It is meant for RefTable-s, where the rows can be in another (sorted) order.

virtual Vector<uInt>* rowStorage()

By the default the table cannot return the storage of rownrs. That can only be done by a RefTable, where it is implemented.

virtual Bool adjustRownrs (uInt nrrow, Vector<uInt>& rownrs, Bool determineOrder) const

Adjust the row numbers to be the actual row numbers in the root table. This is, for instance, used when a RefTable is sorted. Optionally it also determines if the resulting rows are in order.

virtual BaseTable* doSort (PtrBlock<BaseColumn*>&, const PtrBlock<ObjCompareFunc*>&, const Block<Int>& sortOrder, int sortOption)

Do the actual sort. The default implementation is suitable for almost all cases. Only in RefTable a smarter implementation is provided.

RefTable* makeRefTable (Bool rowOrder, uInt initialNrrow)

Create a RefTable object.

void checkRowNumber (uInt rownr) const

Check if the row number is valid. It throws an exception if out of range.

void scratchCallback (Bool isScratch, const String& oldName) const

Do the callback for scratch tables (if callback is set).

Bool makeTableDir()

Create the table directory when needed (and possible). When the file already exists, check if it is a directory. It returns True when it actually created the directory.

void trueDeepCopy (const String& newName, const Record& dataManagerInfo, int tableOption, int endianFormat, Bool noRows) const

Make a true deep copy of the table.

void prepareCopyRename (const String& newName, int tableOption) const

Prepare for copying or renaming a table. It checks if the target table already exists and removes it when necessary.

virtual void renameSubTables (const String& newName, const String& oldName)

Rename the subtables (used by rename function).

void throwIfTableExists()

Check if the table already exists. Throw an exception if so.

Bool openedForWrite() const

Test if the table is opened for write.

void writeStart (AipsIO&, Bool bigEndian)

Start writing a table. It does a putstart and writes nrrow_p. It should be ended by calling writeEnd.

void writeEnd (AipsIO&)

End writing a table.

Bool shouldNotWrite() const

Should the table be written. This flag is False if an exception was thrown.

void getTableInfo()

Read the TableInfo object.

BaseTable (const BaseTable&)

Copy constructor is forbidden, because copying a table requires some more knowledge (like table name of result). Declaring it private, makes it unusable.

BaseTable& operator= (const BaseTable&)

Assignment is forbidden, because copying a table requires some more knowledge (like table name of result). Declaring it private, makes it unusable.

void checkRowNumberThrow (uInt rownr) const

Throw an exception for checkRowNumber.

void logicCheck (BaseTable* that)

Check if the tables combined in a logical operation have the same root.

uInt logicRows (uInt*& rownrs, Bool& allocated)

Get the rownrs of the table in ascending order to be used in the logical operation on the table.

const TableDesc& makeTableDesc() const

Make an empty table description. This is used if one asks for the description of a NullTable. Creating an empty TableDesc in the NullTable takes too much time. Furthermore it causes static initialization order problems.