casacore
 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: MSMColumn.h 20551 2009-03-25 00:11:33Z Malte.Marquarding $
27 
28 #ifndef TABLES_MSMCOLUMN_H
29 #define TABLES_MSMCOLUMN_H
30 
31 
32 //# Includes
33 #include <casacore/casa/aips.h>
39 
40 namespace casacore { //# NAMESPACE CASACORE - BEGIN
41 
42 //# Forward declarations
43 class MSMBase;
44 
45 
46 // <summary>
47 // Column in the Memory table storage manager class
48 // </summary>
49 
50 // <use visibility=local>
51 
52 // <reviewed reviewer="UNKNOWN" date="before2004/08/25" tests="">
53 // </reviewed>
54 
55 // <prerequisite>
56 //# Classes you should understand before using this one.
57 // <li> <linkto class=StManColumn>StManColumn</linkto>
58 // <li> <linkto class=MemoryStMan>MemoryStMan</linkto>
59 // </prerequisite>
60 
61 // <etymology>
62 // MSMColumn handles a column for the memory-based storage manager.
63 // </etymology>
64 
65 // <synopsis>
66 // MSMColumn is used by MemoryStMan to handle the access to
67 // the data in a table column.
68 // It is an storage manager based in memory. Thus the data is lost
69 // when the table is closed.
70 // On reopen it will be initialized to the default column value.
71 // It fully supports addition and removal of rows.
72 //
73 // MSMColumn serves 2 purposes:
74 // <ol>
75 // <li> It handles a column containing scalar values.
76 // <li> It serves as a base class for MSMDirColumn and MSMIndColumn
77 // These classes handle arrays and use MSMColumn to hold a pointer
78 // to the array in each row.
79 // </ol>
80 //
81 // MSMColumn does not hold a column as a consecutive array,
82 // because extending the column (i.e. adding rows) proved be too
83 // expensive due to the repeated copying involved when creating a table
84 // (this method was used by the first version of the table system).
85 // Instead it has a number of data blocks (extensions) indexed to by a
86 // super block. Accessing a row means finding the appropriate extension
87 // via a binary search. Because there is only 1 extension when a table is
88 // read back, the overhead in finding a row is small.
89 // </synopsis>
90 
91 // <motivation>
92 // MSMColumn handles the standard data types. The class
93 // is not templated, but a switch statement is used instead.
94 // Templates would cause too many instantiations.
95 // </motivation>
96 
97 // <todo asof="$DATE:$">
98 //# A List of bugs, limitations, extensions or planned refinements.
99 // <li> StManAipsIO should use this class
100 // </todo>
101 
102 
104 {
105 public:
106  // Create a column of the given type.
107  // It will maintain a pointer to its parent storage manager.
108  MSMColumn (MSMBase* smptr, int dataType, Bool byPtr);
109 
110  // Frees up the storage.
111  virtual ~MSMColumn();
112 
113  // Get a scalar value in the given row.
114  // The buffer pointed to by dataPtr has to have the correct length
115  // (which is guaranteed by the Scalar/ArrayColumn get function).
116  // <group>
117  virtual void getBool (rownr_t rownr, Bool* dataPtr);
118  virtual void getuChar (rownr_t rownr, uChar* dataPtr);
119  virtual void getShort (rownr_t rownr, Short* dataPtr);
120  virtual void getuShort (rownr_t rownr, uShort* dataPtr);
121  virtual void getInt (rownr_t rownr, Int* dataPtr);
122  virtual void getuInt (rownr_t rownr, uInt* dataPtr);
123  virtual void getInt64 (rownr_t rownr, Int64* dataPtr);
124  virtual void getfloat (rownr_t rownr, float* dataPtr);
125  virtual void getdouble (rownr_t rownr, double* dataPtr);
126  virtual void getComplex (rownr_t rownr, Complex* dataPtr);
127  virtual void getDComplex (rownr_t rownr, DComplex* dataPtr);
128  virtual void getString (rownr_t rownr, String* dataPtr);
129  // </group>
130 
131  // Put a scalar value into the given row.
132  // The buffer pointed to by dataPtr has to have the correct length
133  // (which is guaranteed by the Scalar/ArrayColumn put function).
134  // <group>
135  virtual void putBool (rownr_t rownr, const Bool* dataPtr);
136  virtual void putuChar (rownr_t rownr, const uChar* dataPtr);
137  virtual void putShort (rownr_t rownr, const Short* dataPtr);
138  virtual void putuShort (rownr_t rownr, const uShort* dataPtr);
139  virtual void putInt (rownr_t rownr, const Int* dataPtr);
140  virtual void putuInt (rownr_t rownr, const uInt* dataPtr);
141  virtual void putInt64 (rownr_t rownr, const Int64* dataPtr);
142  virtual void putfloat (rownr_t rownr, const float* dataPtr);
143  virtual void putdouble (rownr_t rownr, const double* dataPtr);
144  virtual void putComplex (rownr_t rownr, const Complex* dataPtr);
145  virtual void putDComplex (rownr_t rownr, const DComplex* dataPtr);
146  virtual void putString (rownr_t rownr, const String* dataPtr);
147  // </group>
148 
149  // Get all scalar values in the column.
150  // The vector given in <src>data</src> has to have the correct length
151  // (which is guaranteed by the ScalarColumn getColumn function).
152  virtual void getScalarColumnV (ArrayBase& data);
153 
154  // Put all scalar values in the column.
155  // The vector given in <src>data</src> has to have the correct length
156  // (which is guaranteed by the ScalarColumn putColumn function).
157  virtual void putScalarColumnV (const ArrayBase& data);
158 
159  // Add (newNrrow-oldNrrow) rows to the column.
160  virtual void addRow (rownr_t newNrrow, rownr_t oldNrrow);
161 
162  // Resize the data blocks.
163  // This adds an extension when needed.
164  void resize (rownr_t nrval);
165 
166  // Remove the given row.
167  // If no rows remain in the extension, the extension is also removed.
168  virtual void remove (rownr_t rownr);
169 
170  // Create the number of rows in a new table.
171  // This is used when a table gets created or opened.
172  virtual void doCreate (rownr_t nrrow);
173 
174  // Make it possible to write the column data.
175  // It is only used by derived classes.
176  virtual void putFile (rownr_t nrval, AipsIO&);
177 
178  // Make it possible to read the column data.
179  // It is only used by derived classes.
180  virtual void getFile (rownr_t nrval, AipsIO&);
181 
182  // Reopen the storage manager files for read/write.
183  virtual void reopenRW();
184 
185  // Check if the class invariants still hold.
186  virtual Bool ok() const;
187 
188 protected:
190  // The data is indirectly accessed via a pointer (for the derived classes).
192  // The number of allocated rows in the column.
194  // The nr of extensions in use.
196  // The assembly of all extensions (actually Block<T*>).
198  // The cumulative nr of rows in all extensions.
200 
201  // Find the extension in which the row number is.
202  // If the flag is true, it also sets the columnCache object.
203  uInt findExt (rownr_t rownr, Bool setCache);
204 
205  // Allocate an extension with the data type of the column.
206  void* allocData (rownr_t nrval, Bool byPtr);
207 
208  // Delete all extensions.
209  // Possible underlying data (as used by StManArrayColumnMemory)
210  // will not be deleted and should have been deleted beforehand.
211  void deleteAll();
212 
213  // Delete an extension.
214  void deleteData (void* datap, Bool byPtr);
215 
216  // Remove an entry (i.e. a row) from an extension at the given index.
217  // It will do this by shifting the rest (nrvalAfter elements)
218  // one position to the left.
219  void removeData (void* datap, rownr_t inx, rownr_t nrvalAfter);
220 
221  // Initialize the data (after an open).
222  virtual void initData (void* datap, rownr_t nrval);
223 
224  // Get the pointer for the given row.
225  // This is for the derived classes like StManArrayColumnMemory.
226  void* getArrayPtr (rownr_t rownr);
227 
228  // Put the pointer for the given row.
229  // This is for the derived classes like StManArrayColumnMemory.
230  void putArrayPtr (rownr_t rownr, void* dataPtr);
231 
232 private:
233  // Forbid copy constructor.
234  MSMColumn (const MSMColumn&);
235 
236  // Forbid assignment.
237  MSMColumn& operator= (const MSMColumn&);
238 };
239 
240 
241 
242 } //# NAMESPACE CASACORE - END
243 
244 #endif
long long Int64
Define the extra non-standard types used by Casacore (like proposed uSize, Size)
Definition: aipsxtype.h:38
virtual void putuShort(rownr_t rownr, const uShort *dataPtr)
int Int
Definition: aipstype.h:50
MSMBase * stmanPtr_p
Definition: MSMColumn.h:189
virtual void putInt(rownr_t rownr, const Int *dataPtr)
Non-templated base class for templated Array class.
Definition: ArrayBase.h:72
virtual void getdouble(rownr_t rownr, double *dataPtr)
virtual void getString(rownr_t rownr, String *dataPtr)
virtual void putuInt(rownr_t rownr, const uInt *dataPtr)
AipsIO is the object persistency mechanism of Casacore.
Definition: AipsIO.h:168
virtual void getBool(rownr_t rownr, Bool *dataPtr)
Get a scalar value in the given row.
virtual void getuShort(rownr_t rownr, uShort *dataPtr)
virtual void putString(rownr_t rownr, const String *dataPtr)
unsigned char uChar
Definition: aipstype.h:47
virtual void getShort(rownr_t rownr, Short *dataPtr)
virtual void addRow(rownr_t newNrrow, rownr_t oldNrrow)
Add (newNrrow-oldNrrow) rows to the column.
Base class for memory-based table storage manager class.
Definition: MSMBase.h:67
virtual void getComplex(rownr_t rownr, Complex *dataPtr)
Block< rownr_t > ncum_p
The cumulative nr of rows in all extensions.
Definition: MSMColumn.h:199
MSMColumn(MSMBase *smptr, int dataType, Bool byPtr)
Create a column of the given type.
Base table column storage manager class.
virtual void putDComplex(rownr_t rownr, const DComplex *dataPtr)
virtual ~MSMColumn()
Frees up the storage.
Block< void * > data_p
The assembly of all extensions (actually Block&lt;T*&gt;).
Definition: MSMColumn.h:197
void deleteAll()
Delete all extensions.
void * allocData(rownr_t nrval, Bool byPtr)
Allocate an extension with the data type of the column.
short Short
Definition: aipstype.h:48
rownr_t nralloc_p
The number of allocated rows in the column.
Definition: MSMColumn.h:193
virtual Bool ok() const
Check if the class invariants still hold.
virtual void reopenRW()
Reopen the storage manager files for read/write.
virtual void putComplex(rownr_t rownr, const Complex *dataPtr)
virtual void getFile(rownr_t nrval, AipsIO &)
Make it possible to read the column data.
virtual void initData(void *datap, rownr_t nrval)
Initialize the data (after an open).
void deleteData(void *datap, Bool byPtr)
Delete an extension.
virtual void putFile(rownr_t nrval, AipsIO &)
Make it possible to write the column data.
virtual void putBool(rownr_t rownr, const Bool *dataPtr)
Put a scalar value into the given row.
virtual int dataType() const
Return the data type of the column.
virtual void getInt(rownr_t rownr, Int *dataPtr)
void putArrayPtr(rownr_t rownr, void *dataPtr)
Put the pointer for the given row.
virtual void putfloat(rownr_t rownr, const float *dataPtr)
bool Bool
Define the standard types used by Casacore.
Definition: aipstype.h:42
virtual void getfloat(rownr_t rownr, float *dataPtr)
uInt nrext_p
The nr of extensions in use.
Definition: MSMColumn.h:195
virtual void getScalarColumnV(ArrayBase &data)
Get all scalar values in the column.
Column in the Memory table storage manager class.
Definition: MSMColumn.h:103
virtual void getInt64(rownr_t rownr, Int64 *dataPtr)
MSMColumn & operator=(const MSMColumn &)
Forbid assignment.
uInt findExt(rownr_t rownr, Bool setCache)
Find the extension in which the row number is.
void * getArrayPtr(rownr_t rownr)
Get the pointer for the given row.
uInt64 rownr_t
Define the type of a row number in a table.
Definition: aipsxtype.h:46
virtual void putdouble(rownr_t rownr, const double *dataPtr)
virtual void getuChar(rownr_t rownr, uChar *dataPtr)
String: the storage and methods of handling collections of characters.
Definition: String.h:225
void resize(rownr_t nrval)
Resize the data blocks.
virtual void doCreate(rownr_t nrrow)
Create the number of rows in a new table.
virtual void getDComplex(rownr_t rownr, DComplex *dataPtr)
virtual void putuChar(rownr_t rownr, const uChar *dataPtr)
virtual void putShort(rownr_t rownr, const Short *dataPtr)
virtual void putScalarColumnV(const ArrayBase &data)
Put all scalar values in the column.
void removeData(void *datap, rownr_t inx, rownr_t nrvalAfter)
Remove an entry (i.e.
virtual void getuInt(rownr_t rownr, uInt *dataPtr)
virtual void putInt64(rownr_t rownr, const Int64 *dataPtr)
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:191