casacore
Loading...
Searching...
No Matches
TableVector.h
Go to the documentation of this file.
1//# TableVector.h: Templated read/write table column vectors
2//# Copyright (C) 1994,1995,1996,1999,2000
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: casa-feedback@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#ifndef TABLES_TABLEVECTOR_H
27#define TABLES_TABLEVECTOR_H
28
29//# Includes
30#include <casacore/casa/aips.h>
31#include <casacore/tables/Tables/TVec.h>
32
33namespace casacore { //# NAMESPACE CASACORE - BEGIN
34
35//# Forward Declarations
36class Table;
37class TableColumn;
38template<class T> class TableVectorHelper;
39class String;
40
41
42// <summary>
43// Templated readonly table column vectors
44// </summary>
45
46// <use visibility=export>
47
48// <reviewed reviewer="UNKNOWN" date="before2004/08/25" tests="">
49// </reviewed>
50
51// <prerequisite>
52//# Classes you should understand before using this one.
53// <li> Vector
54// <li> Table
55// </prerequisite>
56
57// <etymology>
58// TableVector allows to operate on a column in a readonly table as a vector.
59// </etymology>
60
61// <synopsis>
62// A TableVector object is a read/write view of data in a Table.
63// This means that the vector data can be changed if the underlying column
64// is writable.
65//
66// Table vectors can be used in the same way as the normal vectors.
67// They allow to handle a column in a table as a vector.
68// Many mathematical and logical operations are defined for them
69// in TabVecMath.h and TabVecLogic.h. In fact, constructors exist
70// to convert a TableColumn or a Vector object to a TableVector,
71// so they can often directly be used in a table vector expression.
72// There are 2 kinds of table vectors:
73// <ul>
74// <li> A table vector representing a scalar column in a table.
75// The data types of the vector and the column must conform.
76// </li> A temporary vector, which is held in memory.
77// These are usually the result of operations on table vectors.
78// </ul>
79//
80// TableVector is implemented by referencing the counted TabVecRep object.
81// A default constructor is defined to allow construction of an array
82// of TableVector objects. However, it constructs an object not
83// referencing anything. Functions like operator() will fail (i.e. result
84// in a segmentation fault) when used on such objects. The functions
85// isNull and throwIfNull can be used to test on this.
86// </synopsis>
87
88// <example>
89// <srcblock>
90// // Create a table vector for column COL1.
91// Table tab ("Table.data");
92// TableVector<Int> tabvec(tab, "COL1");
93// // Multiply it by a constant.
94// // The result has to be stored in a TableVector,
95// // since a TableVector cannot be written.
96// TableVector<Int> temp = 2 * tabvec;
97// </srcblock>
98// </example>
99
100// <motivation>
101// It is very useful to be able to handle a column as a vector.
102// To handle a column in a readonly table, a TableVector class
103// is needed, otherwise output operations could not be forbidden.
104// </motivation>
105
106// <todo asof="$DATE:$">
107//# A List of bugs, limitations, extensions or planned refinements.
108// <li> derive from Lattice one day
109// <li> support slicing
110// <li> support table array columns
111// <li> do we ever need Row vectors?
112// </todo>
113
114
115template<class T>
117{
118public:
119 // The default constructor creates a null table vector.
120 // This does not contain an actual vector and cannot be used until
121 // it references an actual vector (using function reference).
122 // Its sole purpose is to be able to construct an array of TableVectors.
123 // Note that operator(), etc. will cause a segmentation fault
124 // when operating on a null object. It was felt it was too expensive
125 // to test on null over and over again. The user should use the isNull
126 // or throwIfNull function in case of doubt.
128
129 // Create a read/write table vector from the given table column name.
130 // Only scalar columns are supported.
131 TableVector (const Table&, const String& columnName);
132
133 // Create a read/write table vector from the given table column.
134 // Only scalar columns are supported.
135 // This constructor converts a TableColumn to a TableVector and
136 // allows the use of TableColumn objects in table vector expressions.
137 TableVector (const TableColumn& column);
138
139 // Create a table vector from another one (reference semantics)
141
142 // Create a table vector containing the given Vector (reference semantics).
143 // This constructor converts a Vector to a TableVector and
144 // allows the use of Vector objects in table vector expressions.
146
147 // Create a table vector containing a Vector with the given length.
149
150 // Destruct the object.
152
153 // Assign a table vector to another one (copy semantics).
154 // The vectors must have equal length.
156
157 // Test if the table vector is null, i.e. has no actual vector.
158 // This is the case if the default constructor has been used.
159 Bool isNull() const;
160
161 // Throw an exception if the table vector is null, i.e.
162 // if function isNull() is true.
163 void throwIfNull() const;
164
165 // Make a reference to the table vector of the other TableVector.
166 // It will replace an already existing reference.
167 // It handles null objects correctly.
169
170 // Make a (normal) Vector from a TableVector (copy semantics).
172
173 // Get the value of a single pixel.
174 T operator() (rownr_t index) const;
175
176 //# Get a slice.
177//# TableVector<T> operator() (const NSlice&) const;
178
179 // Set all elements to a value.
180 // <group>
181 TableVector<T>& operator= (const T&);
182 void set (const T& value);
183 // </group>
184
185 // Put a value into a single pixel.
186 // <br><src> tabvec(i) = value; </src>
187 void set (rownr_t index, const T& value);
188
189 // Get nr of dimensions (is always 1).
190 uInt ndim() const;
191
192 // Get nr of elements (ie. vector length).
193 rownr_t nelements() const;
194
195 // Test if the shape of the given table vector conforms.
196 Bool conform (const TableVector<T>&) const;
197
198 // Test if the shape of the given vector conforms.
199 Bool conform (const Vector<T>&) const;
200
201 // Test if internal state is correct.
202 Bool ok() const;
203
204protected:
206
207 // Destruct the object. It decreases the reference count in the
208 // underlying object.
209 void destruct();
210
211public:
212 // Return the TabVecRep reference.
214 const TabVecRep<T>& tabVec() const;
215
216 // Create a TableVector from a TabVecRep as result of an operation.
218};
219
220
221template<class T>
223 { return (tabVecPtr_p == 0 ? True : False); }
224
225template<class T>
227 { return tabVecPtr_p->ndim(); }
228
229template<class T>
231 { return tabVecPtr_p->nelements(); }
232
233//# Check if 2 table vectors are conformant.
234template<class T>
236 { return tabVecPtr_p->conform (*vec.tabVecPtr_p); }
237template<class T>
238inline Bool TableVector<T>::conform (const Vector<T>& vec) const
239 { return tabVecPtr_p->conform (vec); }
240
241//# Get the ith pixel.
242template<class T>
244 { return tabVecPtr_p->value (index); }
245
246//# Return the TabVecRep (for TabVecMath and Logic).
247template<class T>
249 { return *tabVecPtr_p; }
250template<class T>
252 { return *tabVecPtr_p; }
253
254
255//# Create a new object as a result of an addition, etc..
256template<class T>
258 { tabVecPtr_p = vec.link(); }
259
260//# Assign a table vector to this one.
261template<class T>
263{
264 tabVecPtr_p->assign (that.tabVec());
265 return *this;
266}
267
268template<class T>
269inline void TableVector<T>::set (rownr_t index, const T& value)
270{
271 tabVecPtr_p->putVal (index, value);
272}
273template<class T>
274inline void TableVector<T>::set (const T& value)
275{
276 tabVecPtr_p->set (value);
277}
278template<class T>
280{
281 tabVecPtr_p->set (value);
282 return *this;
283}
284
285
286} //# NAMESPACE CASACORE - END
287
288
289//# Make old name ROTableVector still available.
290#define ROTableVector TableVector
291
292
293#ifndef CASACORE_NO_AUTO_TEMPLATES
294#include <casacore/tables/Tables/TableVector.tcc>
295#endif //# CASACORE_NO_AUTO_TEMPLATES
296#endif
String: the storage and methods of handling collections of characters.
Definition String.h:223
Templated base class for table vectors.
Definition TVec.h:106
TabVecRep< T > * link()
Increments the reference count.
Definition TVec.h:195
void reference(const TableVector< T > &)
Make a reference to the table vector of the other TableVector.
TableVector(rownr_t leng)
Create a table vector containing a Vector with the given length.
TabVecRep< T > & tabVec()
Return the TabVecRep reference.
void throwIfNull() const
Throw an exception if the table vector is null, i.e.
TableVector(const TableVector< T > &)
Create a table vector from another one (reference semantics)
TableVector(const TableColumn &column)
Create a read/write table vector from the given table column.
T operator()(rownr_t index) const
Get the value of a single pixel.
TableVector()
The default constructor creates a null table vector.
void destruct()
Destruct the object.
uInt ndim() const
Get nr of dimensions (is always 1).
void set(const T &value)
TableVector< T > & operator=(const TableVector< T > &)
Assign a table vector to another one (copy semantics).
Bool isNull() const
Test if the table vector is null, i.e.
Vector< T > makeVector() const
Make a (normal) Vector from a TableVector (copy semantics).
TableVector(const Table &, const String &columnName)
Create a read/write table vector from the given table column name.
TableVector(const Vector< T > &)
Create a table vector containing the given Vector (reference semantics).
TabVecRep< T > * tabVecPtr_p
Bool ok() const
Test if internal state is correct.
~TableVector()
Destruct the object.
Bool conform(const TableVector< T > &) const
Test if the shape of the given table vector conforms.
rownr_t nelements() const
Get nr of elements (ie.
this file contains all the compiler specific defines
Definition mainpage.dox:28
const Bool False
Definition aipstype.h:42
unsigned int uInt
Definition aipstype.h:49
bool Bool
Define the standard types used by Casacore.
Definition aipstype.h:40
LatticeExprNode value(const LatticeExprNode &expr)
This function returns the value of the expression without a mask.
const Bool True
Definition aipstype.h:41
uInt64 rownr_t
Define the type of a row number in a table.
Definition aipsxtype.h:44