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>
40class String;
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
114template <class T>
116 public:
117 // The default constructor creates a null table vector.
118 // This does not contain an actual vector and cannot be used until
119 // it references an actual vector (using function reference).
120 // Its sole purpose is to be able to construct an array of TableVectors.
121 // Note that operator(), etc. will cause a segmentation fault
122 // when operating on a null object. It was felt it was too expensive
123 // to test on null over and over again. The user should use the isNull
124 // or throwIfNull function in case of doubt.
126
127 // Create a read/write table vector from the given table column name.
128 // Only scalar columns are supported.
129 TableVector(const Table&, const String& columnName);
130
131 // Create a read/write table vector from the given table column.
132 // Only scalar columns are supported.
133 // This constructor converts a TableColumn to a TableVector and
134 // allows the use of TableColumn objects in table vector expressions.
135 TableVector(const TableColumn& column);
136
137 // Create a table vector from another one (reference semantics)
139
140 // Create a table vector containing the given Vector (reference semantics).
141 // This constructor converts a Vector to a TableVector and
142 // allows the use of Vector objects in table vector expressions.
144
145 // Create a table vector containing a Vector with the given length.
147
148 // Destruct the object.
150
151 // Assign a table vector to another one (copy semantics).
152 // The vectors must have equal length.
154
155 // Test if the table vector is null, i.e. has no actual vector.
156 // This is the case if the default constructor has been used.
157 Bool isNull() const;
158
159 // Throw an exception if the table vector is null, i.e.
160 // if function isNull() is true.
161 void throwIfNull() const;
162
163 // Make a reference to the table vector of the other TableVector.
164 // It will replace an already existing reference.
165 // It handles null objects correctly.
167
168 // Make a (normal) Vector from a TableVector (copy semantics).
170
171 // Get the value of a single pixel.
172 T operator()(rownr_t index) const;
173
174 // # Get a slice.
175 // # TableVector<T> operator() (const NSlice&) const;
176
177 // Set all elements to a value.
178 // <group>
179 TableVector<T>& operator=(const T&);
180 void set(const T& value);
181 // </group>
182
183 // Put a value into a single pixel.
184 // <br><src> tabvec(i) = value; </src>
185 void set(rownr_t index, const T& value);
186
187 // Get nr of dimensions (is always 1).
188 uInt ndim() const;
189
190 // Get nr of elements (ie. vector length).
191 rownr_t nelements() const;
192
193 // Test if the shape of the given table vector conforms.
194 Bool conform(const TableVector<T>&) const;
195
196 // Test if the shape of the given vector conforms.
197 Bool conform(const Vector<T>&) const;
198
199 // Test if internal state is correct.
200 Bool ok() const;
201
202 protected:
204
205 // Destruct the object. It decreases the reference count in the
206 // underlying object.
207 void destruct();
208
209 public:
210 // Return the TabVecRep reference.
212 const TabVecRep<T>& tabVec() const;
213
214 // Create a TableVector from a TabVecRep as result of an operation.
216};
217
218template <class T>
220 return (tabVecPtr_p == 0 ? True : False);
221}
222
223template <class T>
225 return tabVecPtr_p->ndim();
226}
227
228template <class T>
230 return tabVecPtr_p->nelements();
231}
232
233// # Check if 2 table vectors are conformant.
234template <class T>
236 return tabVecPtr_p->conform(*vec.tabVecPtr_p);
237}
238template <class T>
239inline Bool TableVector<T>::conform(const Vector<T>& vec) const {
240 return tabVecPtr_p->conform(vec);
241}
242
243// # Get the ith pixel.
244template <class T>
245inline T TableVector<T>::operator()(rownr_t index) const {
246 return tabVecPtr_p->value(index);
247}
248
249// # Return the TabVecRep (for TabVecMath and Logic).
250template <class T>
252 return *tabVecPtr_p;
253}
254template <class T>
256 return *tabVecPtr_p;
257}
258
259// # Create a new object as a result of an addition, etc..
260template <class T>
264
265// # Assign a table vector to this one.
266template <class T>
268 tabVecPtr_p->assign(that.tabVec());
269 return *this;
270}
271
272template <class T>
273inline void TableVector<T>::set(rownr_t index, const T& value) {
274 tabVecPtr_p->putVal(index, value);
275}
276template <class T>
277inline void TableVector<T>::set(const T& value) {
278 tabVecPtr_p->set(value);
279}
280template <class T>
282 tabVecPtr_p->set(value);
283 return *this;
284}
285
286} // namespace casacore
287
288// # Make old name ROTableVector still available.
289#define ROTableVector TableVector
290
291#ifndef CASACORE_NO_AUTO_TEMPLATES
292#include <casacore/tables/Tables/TableVector.tcc>
293#endif // # CASACORE_NO_AUTO_TEMPLATES
294#endif
String: the storage and methods of handling collections of characters.
Definition String.h:355
Templated base class for table vectors.
Definition TVec.h:101
TabVecRep< T > * link()
Increments the reference count.
Definition TVec.h:191
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.
For temporary backward namespace compatibility, use casa as alias for casacore.
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
const Bool True
Definition aipstype.h:41
NewDelAllocator< T > NewDelAllocator< T >::value
Definition Allocator.h:360
uInt64 rownr_t
Define the type of a row number in a table.
Definition aipsxtype.h:44