casa  5.7.0-16
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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>
36 
37 namespace casacore { //# NAMESPACE CASACORE - BEGIN
38 
39 //# Forward Declarations
40 class BaseColumn;
41 class RefRows;
42 template<class T> class Vector;
43 class 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 
83 template<class T>
84 class ScalarColumn : public TableColumn
85 {
86 public:
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.
98  ScalarColumn();
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).
110  ScalarColumn (const ScalarColumn<T>&);
111 
112  ~ScalarColumn();
113 
114  // Clone the object.
115  virtual TableColumn* clone() const;
116 
117  // Assignment uses reference semantics, thus works the same
118  // as function reference.
119  ScalarColumn<T>& operator= (const ScalarColumn<T>&);
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.
126  void reference (const ScalarColumn<T>&);
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 (uInt 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 (uInt rownr) const
148  {
149  T value;
150  get (rownr, value);
151  return value;
152  }
153  T operator() (uInt 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.
168  Vector<T> getColumn() 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  // 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 (uInt 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 (uInt 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 (uInt thisRownr, const ScalarColumn<T>& that, uInt 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 (uInt 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 (uInt thisRownr, const TableColumn& that, uInt 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 
253 private:
254  // Check if the data type matches the column data type.
255  void checkDataType() const;
256 
257 protected:
258  // Keep a switch to determine if an entire column can be accessed.
259  // True = yes; False = no.
261  // Keep a switch to know if access knowledge is permanent or has
262  // to be asked again the next time.
264 };
265 
266 
267 //# Explicitly instantiate these templates in ScalarColumn_tmpl.cc
268  extern template class ScalarColumn<Bool>;
269  extern template class ScalarColumn<Char>;
270  extern template class ScalarColumn<Short>;
271  extern template class ScalarColumn<uShort>;
272  extern template class ScalarColumn<Int>;
273  extern template class ScalarColumn<uInt>;
274  extern template class ScalarColumn<Int64>;
275  extern template class ScalarColumn<Float>;
276  extern template class ScalarColumn<Double>;
277  extern template class ScalarColumn<Complex>;
278  extern template class ScalarColumn<DComplex>;
279  extern template class ScalarColumn<String>;
280 
281 
282 } //# NAMESPACE CASACORE - END
283 
284 
285 //# Make old name ROScalarColumn still available.
286 #define ROScalarColumn ScalarColumn
287 
288 
289 #ifndef CASACORE_NO_AUTO_TEMPLATES
290 #include <casacore/tables/Tables/ScalarColumn.tcc>
291 #endif //# CASACORE_NO_AUTO_TEMPLATES
292 #endif
Int offset(uInt rownr) const
Calculate the offset in the cached data for the given row.
Definition: ColumnCache.h:134
A 1-D Specialization of the Array class.
void fillColumn(const T &value)
Put the same value in all cells of the column.
int Int
Definition: aipstype.h:50
#define TABLECOLUMNCHECKROW(ROWNR)
Definition: TableColumn.h:51
std::vector< double > Vector
Definition: ds9context.h:24
T operator()(uInt rownr) const
Definition: ScalarColumn.h:153
Main interface class to a read/write table.
Definition: Table.h:153
void put(uInt 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
TableColumn()
The default constructor creates a null object, i.e.
BaseColumn * baseColPtr_p
Definition: TableColumn.h:388
virtual TableColumn * clone() const
Clone the object.
void checkDataType() const
Check if the data type matches the column data type.
void checkWritable() const
Check if the column is writable and throw an exception if not.
Definition: TableColumn.h:178
Table table() const
Get the Table object this column belongs to.
void attach(const Table &table, const String &columnName)
Attach a column to the object.
Definition: ScalarColumn.h:131
void reference(const ScalarColumn< T > &)
Change the reference to another column.
void getColumnRange(const Slicer &rowRange, Vector< T > &vec, Bool resize=False) const
Get the vector of a range of values in the column.
Class holding the row numbers in a RefTable.
Definition: RefRows.h:85
const ColumnCache * colCachePtr_p
Definition: TableColumn.h:389
bool Bool
Define the standard types used by Casacore.
Definition: aipstype.h:42
Read/write access to a table column.
Definition: TableColumn.h:98
const Bool False
Definition: aipstype.h:44
Bool canAccessColumn_p
Keep a switch to determine if an entire column can be accessed.
Definition: ScalarColumn.h:260
Specify which elements to extract from an n-dimensional array.
Definition: Slicer.h:289
void put(uInt rownr, const ScalarColumn< T > &that)
Copy the value of a cell of that column to a cell of this column.
Definition: ScalarColumn.h:206
const void * dataPtr() const
Give a pointer to the data.
Definition: ColumnCache.h:140
void putColumn(const Vector< T > &vec)
Put the vector of all values in the column.
virtual void get(uInt rownr, void *dataPtr) const =0
Get the value from a particular cell.
void put(uInt rownr, const T &value)
Put the value in a particular cell (i.e.
Definition: ScalarColumn.h:198
ScalarColumn< T > & operator=(const ScalarColumn< T > &)
Assignment uses reference semantics, thus works the same as function reference.
void putColumnRange(const Slicer &rowRange, const Vector< T > &vec)
Put the vector of a range of values in the column.
String: the storage and methods of handling collections of characters.
Definition: String.h:223
Access to a scalar table column with arbitrary data type.
Definition: MSFitsOutput.h:41
ScalarColumn()
The default constructor creates a null object, i.e.
Vector< T > getColumn() const
Get the vector of all values in the column.
Bool reaskAccessColumn_p
Keep a switch to know if access knowledge is permanent or has to be asked again the next time...
Definition: ScalarColumn.h:263
virtual void put(uInt rownr, const void *dataPtr)=0
Put the value in a particular cell.
LatticeExprNode value(const LatticeExprNode &expr)
This function returns the value of the expression without a mask.
void putColumnCells(const RefRows &rownrs, const Vector< T > &vec)
Put the vector of some values in the column.
unsigned int uInt
Definition: aipstype.h:51
void getColumnCells(const RefRows &rownrs, Vector< T > &vec, Bool resize=False) const
Get the vector of some values in the column.
#define casacore
&lt;X11/Intrinsic.h&gt; #defines true, false, casacore::Bool, and String.
Definition: X11Intrinsic.h:42