casa  5.7.0-16
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
MSMColumn.h
Go to the documentation of this file.
1 //# MSMColumn.h: A column in the MemoryStMan
2 //# Copyright (C) 2003
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_MSMCOLUMN_H
29 #define TABLES_MSMCOLUMN_H
30 
31 
32 //# Includes
33 #include <casacore/casa/aips.h>
40 
41 namespace casacore { //# NAMESPACE CASACORE - BEGIN
42 
43 //# Forward declarations
44 class MSMBase;
45 
46 
47 // <summary>
48 // Column in the Memory table storage manager class
49 // </summary>
50 
51 // <use visibility=local>
52 
53 // <reviewed reviewer="UNKNOWN" date="before2004/08/25" tests="">
54 // </reviewed>
55 
56 // <prerequisite>
57 //# Classes you should understand before using this one.
58 // <li> <linkto class=StManColumn>StManColumn</linkto>
59 // <li> <linkto class=MemoryStMan>MemoryStMan</linkto>
60 // </prerequisite>
61 
62 // <etymology>
63 // MSMColumn handles a column for the memory-based storage manager.
64 // </etymology>
65 
66 // <synopsis>
67 // MSMColumn is used by MemoryStMan to handle the access to
68 // the data in a table column.
69 // It is an storage manager based in memory. Thus the data is lost
70 // when the table is closed.
71 // On reopen it will be initialized to the default column value.
72 // It fully supports addition and removal of rows.
73 //
74 // MSMColumn serves 2 purposes:
75 // <ol>
76 // <li> It handles a column containing scalar values.
77 // <li> It serves as a base class for MSMDirColumn and MSMIndColumn
78 // These classes handle arrays and use MSMColumn to hold a pointer
79 // to the array in each row.
80 // </ol>
81 //
82 // MSMColumn does not hold a column as a consecutive array,
83 // because extending the column (i.e. adding rows) proved be too
84 // expensive due to the repeated copying involved when creating a table
85 // (this method was used by the first version of the table system).
86 // Instead it has a number of data blocks (extensions) indexed to by a
87 // super block. Accessing a row means finding the appropriate extension
88 // via a binary search. Because there is only 1 extension when a table is
89 // read back, the overhead in finding a row is small.
90 // </synopsis>
91 
92 // <motivation>
93 // MSMColumn handles the standard data types. The class
94 // is not templated, but a switch statement is used instead.
95 // Templates would cause too many instantiations.
96 // </motivation>
97 
98 // <todo asof="$DATE:$">
99 //# A List of bugs, limitations, extensions or planned refinements.
100 // <li> StManAipsIO should use this class
101 // </todo>
102 
103 
104 class MSMColumn: public StManColumn
105 {
106 public:
107  // Create a column of the given type.
108  // It will maintain a pointer to its parent storage manager.
109  MSMColumn (MSMBase* smptr, int dataType, Bool byPtr);
110 
111  // Frees up the storage.
112  virtual ~MSMColumn();
113 
114  // Get a scalar value in the given row.
115  // The buffer pointed to by dataPtr has to have the correct length
116  // (which is guaranteed by the Scalar/ArrayColumn get function).
117  // <group>
118  void getBoolV (uInt rownr, Bool* dataPtr);
119  void getuCharV (uInt rownr, uChar* dataPtr);
120  void getShortV (uInt rownr, Short* dataPtr);
121  void getuShortV (uInt rownr, uShort* dataPtr);
122  void getIntV (uInt rownr, Int* dataPtr);
123  void getuIntV (uInt rownr, uInt* dataPtr);
124  void getInt64V (uInt rownr, Int64* dataPtr);
125  void getfloatV (uInt rownr, float* dataPtr);
126  void getdoubleV (uInt rownr, double* dataPtr);
127  void getComplexV (uInt rownr, Complex* dataPtr);
128  void getDComplexV (uInt rownr, DComplex* dataPtr);
129  void getStringV (uInt rownr, String* dataPtr);
130  // </group>
131 
132  // Put a scalar value into the given row.
133  // The buffer pointed to by dataPtr has to have the correct length
134  // (which is guaranteed by the Scalar/ArrayColumn put function).
135  // <group>
136  void putBoolV (uInt rownr, const Bool* dataPtr);
137  void putuCharV (uInt rownr, const uChar* dataPtr);
138  void putShortV (uInt rownr, const Short* dataPtr);
139  void putuShortV (uInt rownr, const uShort* dataPtr);
140  void putIntV (uInt rownr, const Int* dataPtr);
141  void putuIntV (uInt rownr, const uInt* dataPtr);
142  void putInt64V (uInt rownr, const Int64* dataPtr);
143  void putfloatV (uInt rownr, const float* dataPtr);
144  void putdoubleV (uInt rownr, const double* dataPtr);
145  void putComplexV (uInt rownr, const Complex* dataPtr);
146  void putDComplexV (uInt rownr, const DComplex* dataPtr);
147  void putStringV (uInt rownr, const String* dataPtr);
148  // </group>
149 
150  // Get scalars from the given row on with a maximum of nrmax values.
151  // This can be used to get an entire column of scalars or to get
152  // a part of a column (for a cache for example).
153  // The buffer pointed to by dataPtr has to have the correct length
154  // (which is guaranteed by the ScalarColumn get function).
155  // <group>
156  uInt getBlockBoolV (uInt rownr, uInt nrmax, Bool* dataPtr);
157  uInt getBlockuCharV (uInt rownr, uInt nrmax, uChar* dataPtr);
158  uInt getBlockShortV (uInt rownr, uInt nrmax, Short* dataPtr);
159  uInt getBlockuShortV (uInt rownr, uInt nrmax, uShort* dataPtr);
160  uInt getBlockIntV (uInt rownr, uInt nrmax, Int* dataPtr);
161  uInt getBlockuIntV (uInt rownr, uInt nrmax, uInt* dataPtr);
162  uInt getBlockInt64V (uInt rownr, uInt nrmax, Int64* dataPtr);
163  uInt getBlockfloatV (uInt rownr, uInt nrmax, float* dataPtr);
164  uInt getBlockdoubleV (uInt rownr, uInt nrmax, double* dataPtr);
165  uInt getBlockComplexV (uInt rownr, uInt nrmax, Complex* dataPtr);
166  uInt getBlockDComplexV (uInt rownr, uInt nrmax, DComplex* dataPtr);
167  uInt getBlockStringV (uInt rownr, uInt nrmax, String* dataPtr);
168  // </group>
169 
170  // Put nrmax scalars from the given row on.
171  // This can be used to put an entire column of scalars or to put
172  // a part of a column (for a cache for example).
173  // The buffer pointed to by dataPtr has to have the correct length
174  // (which is guaranteed by the ScalarColumn put function).
175  // <group>
176  void putBlockBoolV (uInt rownr, uInt nrmax, const Bool* dataPtr);
177  void putBlockuCharV (uInt rownr, uInt nrmax, const uChar* dataPtr);
178  void putBlockShortV (uInt rownr, uInt nrmax, const Short* dataPtr);
179  void putBlockuShortV (uInt rownr, uInt nrmax, const uShort* dataPtr);
180  void putBlockIntV (uInt rownr, uInt nrmax, const Int* dataPtr);
181  void putBlockuIntV (uInt rownr, uInt nrmax, const uInt* dataPtr);
182  void putBlockInt64V (uInt rownr, uInt nrmax, const Int64* dataPtr);
183  void putBlockfloatV (uInt rownr, uInt nrmax, const float* dataPtr);
184  void putBlockdoubleV (uInt rownr, uInt nrmax, const double* dataPtr);
185  void putBlockComplexV (uInt rownr, uInt nrmax, const Complex* dataPtr);
186  void putBlockDComplexV (uInt rownr, uInt nrmax, const DComplex* dataPtr);
187  void putBlockStringV (uInt rownr, uInt nrmax, const String* dataPtr);
188  // </group>
189 
190  // Get the scalar values in some cells of the column.
191  // The buffer pointed to by dataPtr has to have the correct length.
192  // (which is guaranteed by the ScalarColumn getColumnCells function).
193  // The default implementation loops through all rows.
194  // <group>
195  virtual void getScalarColumnCellsBoolV (const RefRows& rownrs,
196  Vector<Bool>* dataPtr);
197  virtual void getScalarColumnCellsuCharV (const RefRows& rownrs,
198  Vector<uChar>* dataPtr);
199  virtual void getScalarColumnCellsShortV (const RefRows& rownrs,
200  Vector<Short>* dataPtr);
201  virtual void getScalarColumnCellsuShortV (const RefRows& rownrs,
202  Vector<uShort>* dataPtr);
203  virtual void getScalarColumnCellsIntV (const RefRows& rownrs,
204  Vector<Int>* dataPtr);
205  virtual void getScalarColumnCellsuIntV (const RefRows& rownrs,
206  Vector<uInt>* dataPtr);
207  virtual void getScalarColumnCellsInt64V (const RefRows& rownrs,
208  Vector<Int64>* dataPtr);
209  virtual void getScalarColumnCellsfloatV (const RefRows& rownrs,
210  Vector<float>* dataPtr);
211  virtual void getScalarColumnCellsdoubleV (const RefRows& rownrs,
212  Vector<double>* dataPtr);
213  virtual void getScalarColumnCellsComplexV (const RefRows& rownrs,
214  Vector<Complex>* dataPtr);
215  virtual void getScalarColumnCellsDComplexV (const RefRows& rownrs,
216  Vector<DComplex>* dataPtr);
217  virtual void getScalarColumnCellsStringV (const RefRows& rownrs,
218  Vector<String>* dataPtr);
219  // </group>
220 
221  // Add (newNrrow-oldNrrow) rows to the column.
222  virtual void addRow (uInt newNrrow, uInt oldNrrow);
223 
224  // Resize the data blocks.
225  // This adds an extension when needed.
226  void resize (uInt nrval);
227 
228  // Remove the given row.
229  // If no rows remain in the extension, the extension is also removed.
230  virtual void remove (uInt rownr);
231 
232  // Create the number of rows in a new table.
233  // This is used when a table gets created or opened.
234  virtual void doCreate (uInt nrrow);
235 
236  // Check if the class invariants still hold.
237  virtual Bool ok() const;
238 
239 protected:
241  // The data type (for caching purposes).
242  int dtype_p;
243  // The data is indirectly accessed via a pointer (for the derived classes).
245  // The number of allocated rows in the column.
247  // The nr of extensions in use.
249  // The assembly of all extensions (actually Block<T*>).
251  // The cumulative nr of rows in all extensions.
253 
254  // Find the extension in which the row number is.
255  // If the flag is true, it also sets the columnCache object.
256  uInt findExt (uInt rownr, Bool setCache);
257 
258  // Get the next extension.
259  // For the first iteration extnr should be zero.
260  // It returns the number of values in it until the maximum is reached.
261  // Zero means no more extensions.
262  uInt nextExt (void*& ext, uInt& extnr, uInt nrmax) const;
263 
264  // Allocate an extension with the data type of the column.
265  void* allocData (uInt nrval, Bool byPtr);
266 
267  // Delete all extensions.
268  // Possible underlying data (as used by StManArrayColumnMemory)
269  // will not be deleted and should have been deleted beforehand.
270  void deleteAll();
271 
272  // Delete an extension.
273  void deleteData (void* datap, Bool byPtr);
274 
275  // Remove an entry (i.e. a row) from an extension at the given index.
276  // It will do this by shifting the rest (nrvalAfter elements)
277  // one position to the left.
278  void removeData (void* datap, uInt inx, uInt nrvalAfter);
279 
280  // Initialize the data (after an open).
281  void initData (void* datap, uInt nrval);
282 
283  // Get the pointer for the given row.
284  // This is for the derived classes like StManArrayColumnMemory.
285  void* getArrayPtr (uInt rownr);
286 
287  // Put the pointer for the given row.
288  // This is for the derived classes like StManArrayColumnMemory.
289  void putArrayPtr (uInt rownr, void* dataPtr);
290 
291 private:
292  // Forbid copy constructor.
293  MSMColumn (const MSMColumn&);
294 
295  // Forbid assignment.
296  MSMColumn& operator= (const MSMColumn&);
297 };
298 
299 
300 
301 } //# NAMESPACE CASACORE - END
302 
303 #endif
void putArrayPtr(uInt rownr, void *dataPtr)
Put the pointer for the given row.
void putuIntV(uInt rownr, const uInt *dataPtr)
void initData(void *datap, uInt nrval)
Initialize the data (after an open).
void putuShortV(uInt rownr, const uShort *dataPtr)
void putBlockBoolV(uInt rownr, uInt nrmax, const Bool *dataPtr)
Put nrmax scalars from the given row on.
long long Int64
Define the extra non-standard types used by Casacore (like proposed uSize, Size)
Definition: aipsxtype.h:38
int Int
Definition: aipstype.h:50
MSMBase * stmanPtr_p
Definition: MSMColumn.h:240
void getInt64V(uInt rownr, Int64 *dataPtr)
uInt getBlockfloatV(uInt rownr, uInt nrmax, float *dataPtr)
void putBlockComplexV(uInt rownr, uInt nrmax, const Complex *dataPtr)
uInt nralloc_p
The number of allocated rows in the column.
Definition: MSMColumn.h:246
uInt getBlockuShortV(uInt rownr, uInt nrmax, uShort *dataPtr)
void putBlockuIntV(uInt rownr, uInt nrmax, const uInt *dataPtr)
virtual void getScalarColumnCellsuShortV(const RefRows &rownrs, Vector< uShort > *dataPtr)
uInt getBlockBoolV(uInt rownr, uInt nrmax, Bool *dataPtr)
Get scalars from the given row on with a maximum of nrmax values.
void getComplexV(uInt rownr, Complex *dataPtr)
virtual void getScalarColumnCellsInt64V(const RefRows &rownrs, Vector< Int64 > *dataPtr)
void * allocData(uInt nrval, Bool byPtr)
Allocate an extension with the data type of the column.
void getfloatV(uInt rownr, float *dataPtr)
void putShortV(uInt rownr, const Short *dataPtr)
virtual void getScalarColumnCellsIntV(const RefRows &rownrs, Vector< Int > *dataPtr)
unsigned char uChar
Definition: aipstype.h:47
uInt findExt(uInt rownr, Bool setCache)
Find the extension in which the row number is.
uInt getBlockComplexV(uInt rownr, uInt nrmax, Complex *dataPtr)
Base class for memory-based table storage manager class.
Definition: MSMBase.h:67
MSMColumn(MSMBase *smptr, int dataType, Bool byPtr)
Create a column of the given type.
void putBlockfloatV(uInt rownr, uInt nrmax, const float *dataPtr)
virtual void getScalarColumnCellsStringV(const RefRows &rownrs, Vector< String > *dataPtr)
uInt getBlockIntV(uInt rownr, uInt nrmax, Int *dataPtr)
void putBlockdoubleV(uInt rownr, uInt nrmax, const double *dataPtr)
virtual ~MSMColumn()
Frees up the storage.
uInt getBlockStringV(uInt rownr, uInt nrmax, String *dataPtr)
Block< void * > data_p
The assembly of all extensions (actually Block&lt;T*&gt;).
Definition: MSMColumn.h:250
void deleteAll()
Delete all extensions.
uInt getBlockuIntV(uInt rownr, uInt nrmax, uInt *dataPtr)
void getuIntV(uInt rownr, uInt *dataPtr)
void putBlockuCharV(uInt rownr, uInt nrmax, const uChar *dataPtr)
int dataType() const
Return the data type of the column.
short Short
Definition: aipstype.h:48
uInt getBlockInt64V(uInt rownr, uInt nrmax, Int64 *dataPtr)
void putBlockStringV(uInt rownr, uInt nrmax, const String *dataPtr)
uInt getBlockDComplexV(uInt rownr, uInt nrmax, DComplex *dataPtr)
virtual Bool ok() const
Check if the class invariants still hold.
virtual void getScalarColumnCellsuCharV(const RefRows &rownrs, Vector< uChar > *dataPtr)
uInt getBlockdoubleV(uInt rownr, uInt nrmax, double *dataPtr)
void removeData(void *datap, uInt inx, uInt nrvalAfter)
Remove an entry (i.e.
void resize(uInt nrval)
Resize the data blocks.
virtual void getScalarColumnCellsShortV(const RefRows &rownrs, Vector< Short > *dataPtr)
void putBlockuShortV(uInt rownr, uInt nrmax, const uShort *dataPtr)
void getDComplexV(uInt rownr, DComplex *dataPtr)
virtual void getScalarColumnCellsfloatV(const RefRows &rownrs, Vector< float > *dataPtr)
void putBlockDComplexV(uInt rownr, uInt nrmax, const DComplex *dataPtr)
void putfloatV(uInt rownr, const float *dataPtr)
Class holding the row numbers in a RefTable.
Definition: RefRows.h:85
void deleteData(void *datap, Bool byPtr)
Delete an extension.
Block< uInt > ncum_p
The cumulative nr of rows in all extensions.
Definition: MSMColumn.h:252
virtual void doCreate(uInt nrrow)
Create the number of rows in a new table.
void putComplexV(uInt rownr, const Complex *dataPtr)
virtual void getScalarColumnCellsComplexV(const RefRows &rownrs, Vector< Complex > *dataPtr)
virtual void addRow(uInt newNrrow, uInt oldNrrow)
Add (newNrrow-oldNrrow) rows to the column.
void putuCharV(uInt rownr, const uChar *dataPtr)
bool Bool
Define the standard types used by Casacore.
Definition: aipstype.h:42
void getdoubleV(uInt rownr, double *dataPtr)
uInt nrext_p
The nr of extensions in use.
Definition: MSMColumn.h:248
void putBlockInt64V(uInt rownr, uInt nrmax, const Int64 *dataPtr)
Column in the Memory table storage manager class.
Definition: MSMColumn.h:104
void * getArrayPtr(uInt rownr)
Get the pointer for the given row.
virtual void getScalarColumnCellsDComplexV(const RefRows &rownrs, Vector< DComplex > *dataPtr)
MSMColumn & operator=(const MSMColumn &)
Forbid assignment.
void getuCharV(uInt rownr, uChar *dataPtr)
int dtype_p
The data type (for caching purposes).
Definition: MSMColumn.h:242
void putBlockShortV(uInt rownr, uInt nrmax, const Short *dataPtr)
virtual void getScalarColumnCellsBoolV(const RefRows &rownrs, Vector< Bool > *dataPtr)
Get the scalar values in some cells of the column.
void putDComplexV(uInt rownr, const DComplex *dataPtr)
void putIntV(uInt rownr, const Int *dataPtr)
void putInt64V(uInt rownr, const Int64 *dataPtr)
void getStringV(uInt rownr, String *dataPtr)
virtual void getScalarColumnCellsuIntV(const RefRows &rownrs, Vector< uInt > *dataPtr)
uInt getBlockShortV(uInt rownr, uInt nrmax, Short *dataPtr)
void getuShortV(uInt rownr, uShort *dataPtr)
void getIntV(uInt rownr, Int *dataPtr)
String: the storage and methods of handling collections of characters.
Definition: String.h:223
void putBoolV(uInt rownr, const Bool *dataPtr)
Put a scalar value into the given row.
void putStringV(uInt rownr, const String *dataPtr)
uInt getBlockuCharV(uInt rownr, uInt nrmax, uChar *dataPtr)
void putBlockIntV(uInt rownr, uInt nrmax, const Int *dataPtr)
void getShortV(uInt rownr, Short *dataPtr)
void putdoubleV(uInt rownr, const double *dataPtr)
void getBoolV(uInt rownr, Bool *dataPtr)
Get a scalar value in the given row.
virtual void getScalarColumnCellsdoubleV(const RefRows &rownrs, Vector< double > *dataPtr)
Base table column storage manager class.
Definition: StManColumn.h:102
uInt nextExt(void *&ext, uInt &extnr, uInt nrmax) const
Get the next extension.
unsigned int uInt
Definition: aipstype.h:51
unsigned short uShort
Definition: aipstype.h:49
Bool byPtr_p
The data is indirectly accessed via a pointer (for the derived classes).
Definition: MSMColumn.h:244
#define casacore
&lt;X11/Intrinsic.h&gt; #defines true, false, casacore::Bool, and String.
Definition: X11Intrinsic.h:42