casacore
ScalarColumn.h
Go to the documentation of this file.
1//# SclarColumn.h: access to a scalar table column with arbitrary data type
2//# Copyright (C) 1994,1995,1996,1997,1998
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: aips2-request@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//# $Id$
27
28#ifndef TABLES_SCALARCOLUMN_H
29#define TABLES_SCALARCOLUMN_H
30
31
32//# Includes
33#include <casacore/casa/aips.h>
34#include <casacore/casa/Arrays/ArrayFwd.h>
35#include <casacore/tables/Tables/TableColumn.h>
36#include <casacore/tables/Tables/ColumnCache.h>
37
38namespace casacore { //# NAMESPACE CASACORE - BEGIN
39
40//# Forward Declarations
41class BaseColumn;
42class RefRows;
43class String;
44
45
46// <summary>
47// Access to a scalar table column with arbitrary data type
48// </summary>
49
50// <use visibility=export>
51
52// <reviewed reviewer="dschieb" date="1994/08/10" tests="none">
53// </reviewed>
54
55// <prerequisite>
56// <li> Table
57// <li> TableColumn
58// </prerequisite>
59
60// <etymology>
61// ScalarColumn<T> gives read and write access to a column in a table
62// containing a scalar with data type T.
63// </etymology>
64
65// <synopsis>
66// The class ScalarColumn allows read and write access to a column
67// containing scalar values with an arbitrary data type.
68// It is possible to get the data in an individual cell (i.e. table row)
69// and to get the column as a whole.
70//
71// A default constructor is defined to allow construction of an array
72// of ScalarColumn objects. However, this constructs an object not
73// referencing a column. Functions like get, etc. will fail (i.e. result
74// in a segmentation fault) when used on such objects. The functions
75// isNull and throwIfNull can be used to test on this.
76// The functions attach and reference can fill in the object.
77// </synopsis>
78
79// <example>
80// See module <linkto module="Tables#open">Tables</linkto>.
81// </example>
82
83template<class T>
85{
86public:
87
88 // The default constructor creates a null object, i.e. it
89 // does not reference a table column.
90 // The sole purpose of this constructor is to allow construction
91 // of an array of ScalarColumn objects.
92 // The functions reference and attach can be used to make a null object
93 // reference a column.
94 // Note that get functions, etc. will cause a segmentation fault
95 // when operating on a null object. It was felt it was too expensive
96 // to test on null over and over again. The user should use the isNull
97 // or throwIfNull function in case of doubt.
99
100 // Construct for the given column in the given table.
101 ScalarColumn (const Table&, const String& columnName);
102
103 // Construct from the given table column.
104 // This constructor is useful if first a table column was constructed,
105 // its type is determined and thereafter used to construct the
106 // correct column object.
107 explicit ScalarColumn (const TableColumn&);
108
109 // Copy constructor (reference semantics).
111
113
114 // Clone the object.
115 virtual TableColumn* clone() const;
116
117 // Assignment uses reference semantics, thus works the same
118 // as function reference.
120
121 // Change the reference to another column.
122 // This is in fact an assignment operator with reference semantics.
123 // It removes the reference to the current column and creates
124 // a reference to the column referenced in the other object.
125 // It will handle null objects correctly.
127
128 // Attach a column to the object.
129 // This is in fact only a shorthand for
130 // <br><src> reference (ScalarColumn<T> (table, columnName)); </src>
131 void attach (const Table& table, const String& columnName)
132 { reference (ScalarColumn<T> (table, columnName)); }
133
134 // Get the data from a particular cell (i.e. table row).
135 // The row numbers count from 0 until #rows-1.
136 // <group>
137 void get (rownr_t rownr, T& value) const
138 {
139 TABLECOLUMNCHECKROW(rownr);
140 Int off = colCachePtr_p->offset(rownr);
141 if (off >= 0) {
142 value = ((T*)(colCachePtr_p->dataPtr()))[off];
143 }else{
144 baseColPtr_p->get (rownr, &value);
145 }
146 }
147 T get (rownr_t rownr) const
148 {
149 T value;
150 get (rownr, value);
151 return value;
152 }
153 T operator() (rownr_t rownr) const
154 {
155 T value;
156 get (rownr, value);
157 return value;
158 }
159 // </group>
160
161 // Get the vector of all values in the column.
162 // According to the assignment rules of class Array, the destination
163 // vector must be empty or its length must be the number of cells
164 // in the column (i.e. the number of rows in the table).
165 void getColumn (Vector<T>& vec, Bool resize = False) const;
166
167 // Get the vector of all values in the column.
169
170 // Get the vector of a range of values in the column.
171 // The Slicer object can be used to specify start, end (or length),
172 // and stride of the rows to get.
173 // According to the assignment rules of class Array, the destination
174 // vector must be empty or its length must be the number of cells
175 // in the column (i.e. the number of rows in the slicer).
176 void getColumnRange (const Slicer& rowRange, Vector<T>& vec,
177 Bool resize = False) const;
178
179 // Get the vector of a range of values in the column.
180 // The Slicer object can be used to specify start, end (or length),
181 // and stride of the rows to get..
182 Vector<T> getColumnRange (const Slicer& rowRange) const;
183
184 // Get the vector of some values in the column.
185 // The Slicer object can be used to specify start, end (or length),
186 // and stride of the rows to get.
187 // According to the assignment rules of class Array, the destination
188 // vector must be empty or its length must be the number of cells
189 // in the column (i.e. the number of rows in the RefRows object).
190 void getColumnCells (const RefRows& rownrs, Vector<T>& vec,
191 Bool resize = False) const;
192
193 // Get the vector of some values in the column.
194 Vector<T> getColumnCells (const RefRows& rownrs) const;
195
196 // Put the value in a particular cell (i.e. table row).
197 // The row numbers count from 0 until #rows-1.
198 void put (rownr_t rownr, const T& value)
200 baseColPtr_p->put (rownr, &value); }
201
202 // Copy the value of a cell of that column to a cell of this column.
203 // The data types of both columns must be the same.
204 // <group>
205 // Use the same row numbers for both cells.
206 void put (rownr_t rownr, const ScalarColumn<T>& that)
207 { put (rownr, that, rownr); }
208 // Use possibly different row numbers for that (i.e. input) and
209 // and this (i.e. output) cell.
210 void put (rownr_t thisRownr, const ScalarColumn<T>& that, rownr_t thatRownr);
211 // </group>
212
213 // Copy the value of a cell of that column to a cell of this column.
214 // This function uses a generic TableColumn object as input.
215 // If possible the data will be promoted to the data type of this column.
216 // Otherwise an exception is thrown.
217 // <group>
218 // Use the same row numbers for both cells.
219 void put (rownr_t rownr, const TableColumn& that, Bool=False)
220 { put (rownr, that, rownr); }
221 // Use possibly different row numbers for that (i.e. input) and
222 // and this (i.e. output) cell.
223 void put (rownr_t thisRownr, const TableColumn& that, rownr_t thatRownr,
224 Bool=False);
225 // </group>
226
227 // Put the vector of all values in the column.
228 // The length of the vector must be the number of cells in the column
229 // (i.e. the number of rows in the table).
230 void putColumn (const Vector<T>& vec);
231
232 // Put the vector of a range of values in the column.
233 // The Slicer object can be used to specify start, end (or length),
234 // and stride of the rows to put.
235 // The length of the vector must be the number of cells in the slice.
236 void putColumnRange (const Slicer& rowRange, const Vector<T>& vec);
237
238 // Put the vector of some values in the column.
239 // The length of the vector must be the number of cells in the RefRows
240 // object.
241 void putColumnCells (const RefRows& rownrs, const Vector<T>& vec);
242
243 // Put the same value in all cells of the column.
244 void fillColumn (const T& value);
245
246 // Put the contents of a column with the same data type into this column.
247 // To put the contents of a column with a different data type into
248 // this column, the function TableColumn::putColumn can be used
249 // (provided the data type promotion is possible).
250 // In fact, this function is an assignment operator with copy semantics.
251 void putColumn (const ScalarColumn<T>& that);
252
253private:
254 // Check if the data type matches the column data type.
255 void checkDataType() const;
256};
257
258
259//# Explicitly instantiate these templates in ScalarColumn_tmpl.cc
260 extern template class ScalarColumn<Bool>;
261 extern template class ScalarColumn<Char>;
262 extern template class ScalarColumn<Short>;
263 extern template class ScalarColumn<uShort>;
264 extern template class ScalarColumn<Int>;
265 extern template class ScalarColumn<uInt>;
266 extern template class ScalarColumn<Int64>;
267 extern template class ScalarColumn<Float>;
268 extern template class ScalarColumn<Double>;
269 extern template class ScalarColumn<Complex>;
270 extern template class ScalarColumn<DComplex>;
271 extern template class ScalarColumn<String>;
272
273
274} //# NAMESPACE CASACORE - END
275
276
277//# Make old name ROScalarColumn still available.
278#define ROScalarColumn ScalarColumn
279
280
281#ifndef CASACORE_NO_AUTO_TEMPLATES
282#include <casacore/tables/Tables/ScalarColumn.tcc>
283#endif //# CASACORE_NO_AUTO_TEMPLATES
284#endif
#define TABLECOLUMNCHECKROW(ROWNR)
Definition: TableColumn.h:51
virtual void get(rownr_t rownr, void *dataPtr) const
Get a scalar value from a particular cell.
virtual void put(rownr_t rownr, const void *dataPtr)
Put the scalar value in a particular cell.
Int64 offset(rownr_t rownr) const
Calculate the offset in the cached data for the given row.
Definition: ColumnCache.h:140
const void * dataPtr() const
Give a pointer to the data.
Definition: ColumnCache.h:150
void put(rownr_t thisRownr, const TableColumn &that, rownr_t thatRownr, Bool=False)
Use possibly different row numbers for that (i.e.
ScalarColumn< T > & operator=(const ScalarColumn< T > &)
Assignment uses reference semantics, thus works the same as function reference.
ScalarColumn()
The default constructor creates a null object, i.e.
Vector< T > getColumn() const
Get the vector of all values in the column.
void put(rownr_t rownr, const T &value)
Put the value in a particular cell (i.e.
Definition: ScalarColumn.h:198
ScalarColumn(const ScalarColumn< T > &)
Copy constructor (reference semantics).
void put(rownr_t rownr, const ScalarColumn< T > &that)
Copy the value of a cell of that column to a cell of this column.
Definition: ScalarColumn.h:206
void get(rownr_t rownr, T &value) const
Get the data from a particular cell (i.e.
Definition: ScalarColumn.h:137
void checkDataType() const
Check if the data type matches the column data type.
void fillColumn(const T &value)
Put the same value in all cells of the column.
void putColumnCells(const RefRows &rownrs, const Vector< T > &vec)
Put the vector of some values in the column.
virtual TableColumn * clone() const
Clone the object.
void put(rownr_t rownr, const TableColumn &that, Bool=False)
Copy the value of a cell of that column to a cell of this column.
Definition: ScalarColumn.h:219
ScalarColumn(const Table &, const String &columnName)
Construct for the given column in the given table.
Vector< T > getColumnCells(const RefRows &rownrs) const
Get the vector of some values in the column.
T get(rownr_t rownr) const
Definition: ScalarColumn.h:147
void putColumnRange(const Slicer &rowRange, const Vector< T > &vec)
Put the vector of a range of values in the column.
void getColumnRange(const Slicer &rowRange, Vector< T > &vec, Bool resize=False) const
Get the vector of a range of values in the column.
void attach(const Table &table, const String &columnName)
Attach a column to the object.
Definition: ScalarColumn.h:131
void putColumn(const Vector< T > &vec)
Put the vector of all values in the column.
void put(rownr_t thisRownr, const ScalarColumn< T > &that, rownr_t thatRownr)
Use possibly different row numbers for that (i.e.
void getColumn(Vector< T > &vec, Bool resize=False) const
Get the vector of all values in the column.
ScalarColumn(const TableColumn &)
Construct from the given table column.
void putColumn(const ScalarColumn< T > &that)
Put the contents of a column with the same data type into this column.
void reference(const ScalarColumn< T > &)
Change the reference to another column.
T operator()(rownr_t rownr) const
Definition: ScalarColumn.h:153
void getColumnCells(const RefRows &rownrs, Vector< T > &vec, Bool resize=False) const
Get the vector of some values in the column.
Vector< T > getColumnRange(const Slicer &rowRange) const
Get the vector of a range of values in the column.
String: the storage and methods of handling collections of characters.
Definition: String.h:225
const ColumnCache * colCachePtr_p
Definition: TableColumn.h:389
void checkWritable() const
Check if the column is writable and throw an exception if not.
Definition: TableColumn.h:178
BaseColumn * baseColPtr_p
Definition: TableColumn.h:388
Table table() const
Get the Table object this column belongs to.
this file contains all the compiler specific defines
Definition: mainpage.dox:28
const Bool False
Definition: aipstype.h:44
int Int
Definition: aipstype.h:50
bool Bool
Define the standard types used by Casacore.
Definition: aipstype.h:42
LatticeExprNode value(const LatticeExprNode &expr)
This function returns the value of the expression without a mask.
uInt64 rownr_t
Define the type of a row number in a table.
Definition: aipsxtype.h:46