//# TableVector.h: Templated read/write table column vectors //# Copyright (C) 1994,1995,1996,1999,2000 //# Associated Universities, Inc. Washington DC, USA. //# //# This library is free software; you can redistribute it and/or modify it //# under the terms of the GNU Library General Public License as published by //# the Free Software Foundation; either version 2 of the License, or (at your //# option) any later version. //# //# This library is distributed in the hope that it will be useful, but WITHOUT //# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or //# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public //# License for more details. //# //# You should have received a copy of the GNU Library General Public License //# along with this library; if not, write to the Free Software Foundation, //# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA. //# //# Correspondence concerning AIPS++ should be addressed as follows: //# Internet email: aips2-request@nrao.edu. //# Postal address: AIPS++ Project Office //# National Radio Astronomy Observatory //# 520 Edgemont Road //# Charlottesville, VA 22903-2475 USA //# //# $Id$ #ifndef TABLES_TABLEVECTOR_H #define TABLES_TABLEVECTOR_H //# Includes #include #include namespace casacore { //# NAMESPACE CASACORE - BEGIN //# Forward Declarations class Table; class TableColumn; template class TableVectorHelper; class String; // // Templated readonly table column vectors // // // // // //# Classes you should understand before using this one. //
  • Vector //
  • Table // // // TableVector allows to operate on a column in a readonly table as a vector. // // // A TableVector object is a read/write view of data in a Table. // This means that the vector data can be changed if the underlying column // is writable. // // Table vectors can be used in the same way as the normal vectors. // They allow to handle a column in a table as a vector. // Many mathematical and logical operations are defined for them // in TabVecMath.h and TabVecLogic.h. In fact, constructors exist // to convert a TableColumn or a Vector object to a TableVector, // so they can often directly be used in a table vector expression. // There are 2 kinds of table vectors: //
      //
    • A table vector representing a scalar column in a table. // The data types of the vector and the column must conform. //
    • A temporary vector, which is held in memory. // These are usually the result of operations on table vectors. //
    // // TableVector is implemented by referencing the counted TabVecRep object. // A default constructor is defined to allow construction of an array // of TableVector objects. However, it constructs an object not // referencing anything. Functions like operator() will fail (i.e. result // in a segmentation fault) when used on such objects. The functions // isNull and throwIfNull can be used to test on this. //
    // // // // Create a table vector for column COL1. // Table tab ("Table.data"); // TableVector tabvec(tab, "COL1"); // // Multiply it by a constant. // // The result has to be stored in a TableVector, // // since a TableVector cannot be written. // TableVector temp = 2 * tabvec; // // // // It is very useful to be able to handle a column as a vector. // To handle a column in a readonly table, a TableVector class // is needed, otherwise output operations could not be forbidden. // // //# A List of bugs, limitations, extensions or planned refinements. //
  • derive from Lattice one day //
  • support slicing //
  • support table array columns //
  • do we ever need Row vectors? // template class TableVector { public: // The default constructor creates a null table vector. // This does not contain an actual vector and cannot be used until // it references an actual vector (using function reference). // Its sole purpose is to be able to construct an array of TableVectors. // Note that operator(), etc. will cause a segmentation fault // when operating on a null object. It was felt it was too expensive // to test on null over and over again. The user should use the isNull // or throwIfNull function in case of doubt. TableVector(); // Create a read/write table vector from the given table column name. // Only scalar columns are supported. TableVector (const Table&, const String& columnName); // Create a read/write table vector from the given table column. // Only scalar columns are supported. // This constructor converts a TableColumn to a TableVector and // allows the use of TableColumn objects in table vector expressions. TableVector (const TableColumn& column); // Create a table vector from another one (reference semantics) TableVector (const TableVector&); // Create a table vector containing the given Vector (reference semantics). // This constructor converts a Vector to a TableVector and // allows the use of Vector objects in table vector expressions. TableVector (const Vector&); // Create a table vector containing a Vector with the given length. TableVector (rownr_t leng); // Destruct the object. ~TableVector(); // Assign a table vector to another one (copy semantics). // The vectors must have equal length. TableVector& operator= (const TableVector&); // Test if the table vector is null, i.e. has no actual vector. // This is the case if the default constructor has been used. Bool isNull() const; // Throw an exception if the table vector is null, i.e. // if function isNull() is true. void throwIfNull() const; // Make a reference to the table vector of the other TableVector. // It will replace an already existing reference. // It handles null objects correctly. void reference (const TableVector&); // Make a (normal) Vector from a TableVector (copy semantics). Vector makeVector() const; // Get the value of a single pixel. T operator() (rownr_t index) const; //# Get a slice. //# TableVector operator() (const NSlice&) const; // Set all elements to a value. // TableVector& operator= (const T&); void set (const T& value); // // Put a value into a single pixel. //
    tabvec(i) = value; void set (rownr_t index, const T& value); // Get nr of dimensions (is always 1). uInt ndim() const; // Get nr of elements (ie. vector length). rownr_t nelements() const; // Test if the shape of the given table vector conforms. Bool conform (const TableVector&) const; // Test if the shape of the given vector conforms. Bool conform (const Vector&) const; // Test if internal state is correct. Bool ok() const; protected: TabVecRep* tabVecPtr_p; // Destruct the object. It decreases the reference count in the // underlying object. void destruct(); public: // Return the TabVecRep reference. TabVecRep& tabVec(); const TabVecRep& tabVec() const; // Create a TableVector from a TabVecRep as result of an operation. TableVector (TabVecRep&); }; template inline Bool TableVector::isNull() const { return (tabVecPtr_p == 0 ? True : False); } template inline uInt TableVector::ndim () const { return tabVecPtr_p->ndim(); } template inline rownr_t TableVector::nelements() const { return tabVecPtr_p->nelements(); } //# Check if 2 table vectors are conformant. template inline Bool TableVector::conform (const TableVector& vec) const { return tabVecPtr_p->conform (*vec.tabVecPtr_p); } template inline Bool TableVector::conform (const Vector& vec) const { return tabVecPtr_p->conform (vec); } //# Get the ith pixel. template inline T TableVector::operator() (rownr_t index) const { return tabVecPtr_p->value (index); } //# Return the TabVecRep (for TabVecMath and Logic). template inline const TabVecRep& TableVector::tabVec() const { return *tabVecPtr_p; } template inline TabVecRep& TableVector::tabVec() { return *tabVecPtr_p; } //# Create a new object as a result of an addition, etc.. template inline TableVector::TableVector (TabVecRep& vec) { tabVecPtr_p = vec.link(); } //# Assign a table vector to this one. template inline TableVector& TableVector::operator= (const TableVector& that) { tabVecPtr_p->assign (that.tabVec()); return *this; } template inline void TableVector::set (rownr_t index, const T& value) { tabVecPtr_p->putVal (index, value); } template inline void TableVector::set (const T& value) { tabVecPtr_p->set (value); } template inline TableVector& TableVector::operator= (const T& value) { tabVecPtr_p->set (value); return *this; } } //# NAMESPACE CASACORE - END //# Make old name ROTableVector still available. #define ROTableVector TableVector #ifndef CASACORE_NO_AUTO_TEMPLATES #include #endif //# CASACORE_NO_AUTO_TEMPLATES #endif