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