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