BaseMappedArrayEngine.h
Classes
- BaseMappedArrayEngine -- Templated virtual column engine for an table array of any type. (full description)
Interface
- Public Members
- virtual Bool canAddRow() const
- virtual Bool canRemoveRow() const
- const String& sourceName() const
- Protected Members
- BaseMappedArrayEngine (const String& sourceColumnName, const String& targetColumnName)
- ~BaseMappedArrayEngine()
- BaseMappedArrayEngine()
- BaseMappedArrayEngine (const BaseMappedArrayEngine<SourceType, TargetType>&)
- void setNames (const String& sourceName, const String& targetName)
- const String& targetName() const
- inline ROArrayColumn<TargetType>& roColumn()
- inline ArrayColumn<TargetType>& rwColumn()
- virtual Bool isWritable() const
- virtual DataManagerColumn* makeIndArrColumn (const String& columnName, int dataType, const String& dataTypeId)
- virtual void create (uInt initialNrrow)
- virtual void prepare()
- void prepare1()
- void prepare2()
- virtual void reopenRW()
- virtual void addRow (uInt nrrow)
- virtual void addRowInit (uInt startRow, uInt nrrow)
- virtual void removeRow (uInt rownr)
- virtual void setShapeColumn (const IPosition& shape)
- virtual void setShape (uInt rownr, const IPosition& shape)
- virtual Bool isShapeDefined (uInt rownr)
- virtual uInt ndim (uInt rownr)
- virtual IPosition shape (uInt rownr)
- virtual Bool canChangeShape() const
- TableColumn makeTableColumn (const String& columnName)
- Private Members
- BaseMappedArrayEngine<SourceType, TargetType>& operator= (const BaseMappedArrayEngine<SourceType, TargetType>&)
Prerequisite
Etymology
BaseMappedArrayEngine contains for the 1-1 mapping of a source
column to a target column (both containing arrays).
Synopsis
BaseMappedArrayEngine is an abstract base class for virtual column engines
which map data from the arrays in the source column to
the arrays in the target column.
Examples of classes using this base class are
ScaledArrayEngine and
RetypedArrayEngine.
The source column has to be bound to the virtual column engine used
for it. The target column will usually be bound to a storage manager,
but any other suitable data manager is possible. E.g. it is
possible to use MappedArrayEngine<StokesVector,float>
to map a StokesVector to a float column, which in its turn uses
ScaledArrayEngine<float,Int> to store it as integers.
Note that the names of the source and target column have to be different,
otherwise the table system cannot distinguish them.
This base class does several tasks for the derived classes.
The main one is to keep and handle the information about the source
and target column. The name of the target column is written as a keyword
in the source column. In this way the target column is known when
a table is read back. It also creates (RO)ArrayColumn<T>
objects to access the target column. The function roColumn gives
read access, while rwColumn gives write access.
An engine object should be used for one column only, because the target
column name is part of the engine. If it would be used for more than
one column, they would all share the same target column.
When the engine is bound to a column, it is checked if the name
of that column matches the given source column name.
The engine can be used for a column containing any kind of array
(thus direct or indirect, fixed or variable shaped)) as long as the
source array can be stored in the target array. Thus a fixed shaped
source can use a variable shaped target, but not vice versa.
A fixed shape indirect source can use a target with direct arrays.
The DataManager framework contains various virtual functions.
This class implements several, but not all of them. Furthermore
some implementations may not be optimal or correct for derived classes.
Hereafter follows a list of functions which may need implementation
in derived classes. The classes mentioned in the examples below show
implementations of these functions.
-
The following (virtual) functions have to be implemented:
-
~... (the destructor)
-
DataManager* clone() const;
-
String dataManagerType() const;
-
static void registerClass();
-
static DataManager* makeObject (const String& dataManagerType);
-
void getArray (uInt rownr, Array<T>& data);
-
void putArray (uInt rownr, const Array<T>& data);
-
For efficiency reasons it could be better to implement the following
functions:
-
void getSlice (uInt rownr, const Slicer& slicer, Array<T>& data);
-
void putSlice (uInt rownr, const Slicer& slicer,
const Array<T>& data);
-
void getArrayColumn (Array<T>& data);
-
void putArrayColumn (const Array<T>& data);
-
void getColumnSlice (const Slicer& slicer, Array<T>& data);
-
void putColumnSlice (const Slicer& slicer, const Array<T>& data);
-
The following functions have to be implemented when the shapes
of the source and target arrays are not the same.
-
void setShapeColumn (const IPosition& shape);
-
void setShape (uInt rownr, const IPosition& shape);
-
uInt ndim (uInt rownr);
-
IPosition shape (uInt rownr);
-
The following functions deal with the initialization and persistence
of engine specific variables. When the class has variables of its
own, these functions may need to be implemented. Implementations of
create and prepare have to call the similar functions in this base class.
-
void close (AipsIO& ios);
-
void create (uInt nrrow);
-
void open (uInt nrrow, AipsIO& ios);
-
void prepare();
-
The following functions do not need to be declared and implemented
in derived classes unless it is a very special case.
-
String dataManagerName() const;
-
Bool canAddRow() const;
-
Bool canRemoveRow() const;
-
void addRow (uInt nrrow);
-
void removeRow (uInt rownr);
-
DataManagerColumn* makeDirArrColumn (const String& columnName,
int dataType,
const String& dataTypeId);
-
DataManagerColumn* makeIndArrColumn (const String& columnName,
int dataType,
const String& dataTypeId);
-
Bool isWritable() const;
-
Bool isShapeDefined (uInt rownr);
Example
The derived classes
ScaledArrayEngine and
RetypedArrayEngine
are two examples of how to derive a class from this base class.
Note that ScaledArrayEngine does not need to implement functions
dealing with shapes, because it can use them from this base class.
On the other hand they need to be implemented in RetypedArrayEngine.
Motivation
This base class implements several functions making the implementation
of derived classes simpler. Many details are implemented here, so often
only the basic mapping functions (get, put) need to be implemented
in a derived class.
Template Type Argument Requirements (SourceType)
- default constructor
- copy constructor
- assignment operator
- static String dataTypeId(); // unique name of the class
Template Type Argument Requirements (TargetType)
- Default constructor
- Copy constructor
- Assignment operator
Member Description
virtual Bool canAddRow() const
Adding rows is possible for this engine.
Deleting rows is possible for this engine.
Give the source name.
Construct an engine to convert the source column to the target column.
TargetColumnName is the name of the column where the converted
data will be put and must have data type TargetType.
The source column using this engine must have data type SourceType.
Destructor is mandatory.
The default constructor is required for reconstruction of the
engine when a table is read back.
BaseMappedArrayEngine (const BaseMappedArrayEngine<SourceType, TargetType>&)
Copy constructor is only used by copy constructor of derived classes.
(so it is made protected).
void setNames (const String& sourceName, const String& targetName)
Set the source and target column name.
Get the target name.
Give readonly access to the target column.
This can be used by the derived classes to get data.
Give read/write access to the target column.
This can be used by the derived classes to put data.
virtual Bool isWritable() const
The column is writable if the underlying target column is writable.
Create the column object for the array column in this engine.
It will check if the given column name matches the source
column name. This assures that the engine is bound to the
correct column.
virtual void create (uInt initialNrrow)
Initialize the object for a new table.
It defines a source column keyword telling the target column name.
Initially the table has the given number of rows.
A derived class can have its own create function, but that should
always call this create function.
virtual void prepare()
Preparing consists of setting the writable switch and
adding the initial number of rows in case of create.
It reads the target column name from the source column keywords.
A derived class can have its own prepare function, but that should
always call this prepare function.
Do the 2 stages of the prepare (define columns and adding rows).
Reopen the engine for read/write access.
It makes the column writable if the underlying column is writable.
virtual void addRow (uInt nrrow)
virtual void addRowInit (uInt startRow, uInt nrrow)
Rows are added to the end of the table.
If the source column has FixedShape arrays and the target not,
the shape in each target row will be set.
This assures that the arrays are properly defined in each row,
so putSlice can be used without problems.
The second version is used by prepare2, because in case a column is
added to an already existing table, table.nrow() gives the existing
number of columns instead of 0.
virtual void removeRow (uInt rownr)
Deleting rows is possible and is a no-op for this engine.
Set the shape of the FixedShape arrays in the column.
This function only gets called if the column has FixedShape arrays.
The shape gets saved and used to set the shape of the arrays
in the target in case the target has non-FixedShape arrays.
This implementation assumes the shape of source and target arrays
are the same. If not, it has to be overidden in a derived class.
virtual void setShape (uInt rownr, const IPosition& shape)
Define the shape of the array in the given row.
It will define the shape of the (underlying) array.
This implementation assumes the shape of source and target arrays
are the same. If not, it has to be overidden in a derived class.
Test if the (underlying) array is defined in the given row.
virtual uInt ndim (uInt rownr)
Get the dimensionality of the (underlying) array in the given row.
This implementation assumes the dimensionality of source and
target arrays are the same. If not, it has to be overidden in a
derived class.
Get the shape of the (underlying) array in the given row.
This implementation assumes the shape of source and target arrays
are the same. If not, it has to be overidden in a derived class.
The data manager can handle changing the shape of an existing array
when the underlying target column can do it.
Make a table column object for the given column.
This has to be used in the create function, otherwise it could not
create a TableColumn object to store data in the column keywords.
BaseMappedArrayEngine<SourceType, TargetType>& operator= (const BaseMappedArrayEngine<SourceType, TargetType>&)
Assignment is not needed and therefore forbidden
(so it is made private and not implemented).