casa  $Rev:20696$
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
MSMIndColumn.h
Go to the documentation of this file.
00001 //# MSMIndColumn.h: Memory storage manager for variable shaped table arrays
00002 //# Copyright (C) 2003
00003 //# Associated Universities, Inc. Washington DC, USA.
00004 //#
00005 //# This library is free software; you can redistribute it and/or modify it
00006 //# under the terms of the GNU Library General Public License as published by
00007 //# the Free Software Foundation; either version 2 of the License, or (at your
00008 //# option) any later version.
00009 //#
00010 //# This library is distributed in the hope that it will be useful, but WITHOUT
00011 //# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00012 //# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Library General Public
00013 //# License for more details.
00014 //#
00015 //# You should have received a copy of the GNU Library General Public License
00016 //# along with this library; if not, write to the Free Software Foundation,
00017 //# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA.
00018 //#
00019 //# Correspondence concerning AIPS++ should be addressed as follows:
00020 //#        Internet email: aips2-request@nrao.edu.
00021 //#        Postal address: AIPS++ Project Office
00022 //#                        National Radio Astronomy Observatory
00023 //#                        520 Edgemont Road
00024 //#                        Charlottesville, VA 22903-2475 USA
00025 //#
00026 //# $Id: MSMIndColumn.h 20551 2009-03-25 00:11:33Z Malte.Marquarding $
00027 
00028 #ifndef TABLES_MSMINDCOLUMN_H
00029 #define TABLES_MSMINDCOLUMN_H
00030 
00031 
00032 //# Includes
00033 #include <casa/aips.h>
00034 #include <tables/Tables/MSMColumn.h>
00035 #include <tables/Tables/MSMBase.h>
00036 #include <casa/Arrays/IPosition.h>
00037 
00038 
00039 namespace casa { //# NAMESPACE CASA - BEGIN
00040 
00041 // <summary>
00042 // Mmeory storage manager for variable shaped table arrays
00043 // </summary>
00044 
00045 // <use visibility=local>
00046 
00047 // <reviewed reviewer="UNKNOWN" date="before2004/08/25" tests="">
00048 // </reviewed>
00049 
00050 // <prerequisite>
00051 //# Classes you should understand before using this one.
00052 //   <li> MSMBase
00053 //   <li> MSMColumn
00054 // </prerequisite>
00055 
00056 // <synopsis> 
00057 // StManColumnArrayAipsIO handles indirect arrays in a table column.
00058 //
00059 // An array (or section of an array) is only read when needed.
00060 // It, however, caches the array shape using the helper class
00061 // StIndArray. Pointers to these objects
00062 // are maintained using the standard StManColumnAipsIO facilities.
00063 // When the column gets written, the offsets in the StManArrayFile file
00064 // get written. Those will be read back when the column is read in.
00065 //
00066 // When a row gets deleted or when the array gets bigger, the file space
00067 // is lost. This storage manager is a simple one and no attempts
00068 // are done to make it smart.
00069 // </synopsis> 
00070 
00071 //# <todo asof="$DATE:$">
00072 //# A List of bugs, limitations, extensions or planned refinements.
00073 //# </todo>
00074 
00075 
00076 class MSMIndColumn : public MSMColumn
00077 {
00078 public:
00079 
00080   // Create a column of the given type.
00081   MSMIndColumn (MSMBase*, int dataType);
00082 
00083   // Frees up the storage.
00084   ~MSMIndColumn();
00085 
00086   // It can handle access to a slice in a cell.
00087   Bool canAccessSlice (Bool& reask) const;
00088 
00089   // Set the (fixed) shape of the arrays in the entire column.
00090   void setShapeColumn (const IPosition& shape);
00091 
00092   // Get the column shape.
00093   const IPosition& columnShape() const
00094     { return fixedShape_p; }
00095 
00096   // Set the shape of the array in the given row and allocate the array
00097   // in the file.
00098   void setShape (uInt rownr, const IPosition& shape);
00099 
00100   // Is the shape defined (i.e. is there an array) in this row?
00101   Bool isShapeDefined (uInt rownr);
00102 
00103   // Get the dimensionality of the item in the given row.
00104   // 0 is returned if there is no array.
00105   uInt ndim (uInt rownr);
00106 
00107   // Get the shape of the array in the given row.
00108   // An zero-length IPosition is returned if there is no array.
00109   IPosition shape (uInt rownr);
00110 
00111   // This storage manager can handle changing array shapes.
00112   Bool canChangeShape() const;
00113 
00114   // Get an array value in the given row.
00115   // The buffer pointed to by dataPtr has to have the correct length
00116   // (which is guaranteed by the ArrayColumn get function).
00117   // <group>
00118   void getArrayBoolV     (uInt rownr, Array<Bool>* dataPtr);
00119   void getArrayuCharV    (uInt rownr, Array<uChar>* dataPtr);
00120   void getArrayShortV    (uInt rownr, Array<Short>* dataPtr);
00121   void getArrayuShortV   (uInt rownr, Array<uShort>* dataPtr);
00122   void getArrayIntV      (uInt rownr, Array<Int>* dataPtr);
00123   void getArrayuIntV     (uInt rownr, Array<uInt>* dataPtr);
00124   void getArrayfloatV    (uInt rownr, Array<float>* dataPtr);
00125   void getArraydoubleV   (uInt rownr, Array<double>* dataPtr);
00126   void getArrayComplexV  (uInt rownr, Array<Complex>* dataPtr);
00127   void getArrayDComplexV (uInt rownr, Array<DComplex>* dataPtr);
00128   void getArrayStringV   (uInt rownr, Array<String>* dataPtr);
00129   // </group>
00130 
00131   // Put an array value into the given row.
00132   // The buffer pointed to by dataPtr has to have the correct length
00133   // (which is guaranteed by the ArrayColumn put function).
00134   // <group>
00135   void putArrayBoolV     (uInt rownr, const Array<Bool>* dataPtr);
00136   void putArrayuCharV    (uInt rownr, const Array<uChar>* dataPtr);
00137   void putArrayShortV    (uInt rownr, const Array<Short>* dataPtr);
00138   void putArrayuShortV   (uInt rownr, const Array<uShort>* dataPtr);
00139   void putArrayIntV      (uInt rownr, const Array<Int>* dataPtr);
00140   void putArrayuIntV     (uInt rownr, const Array<uInt>* dataPtr);
00141   void putArrayfloatV    (uInt rownr, const Array<float>* dataPtr);
00142   void putArraydoubleV   (uInt rownr, const Array<double>* dataPtr);
00143   void putArrayComplexV  (uInt rownr, const Array<Complex>* dataPtr);
00144   void putArrayDComplexV (uInt rownr, const Array<DComplex>* dataPtr);
00145   void putArrayStringV   (uInt rownr, const Array<String>* dataPtr);
00146   // </group>
00147 
00148   // Get a section of the array in the given row.
00149   // The buffer pointed to by dataPtr has to have the correct length
00150   // (which is guaranteed by the ArrayColumn getSlice function).
00151   // <group>
00152   void getSliceBoolV     (uInt rownr, const Slicer&, Array<Bool>* dataPtr);
00153   void getSliceuCharV    (uInt rownr, const Slicer&, Array<uChar>* dataPtr);
00154   void getSliceShortV    (uInt rownr, const Slicer&, Array<Short>* dataPtr);
00155   void getSliceuShortV   (uInt rownr, const Slicer&, Array<uShort>* dataPtr);
00156   void getSliceIntV      (uInt rownr, const Slicer&, Array<Int>* dataPtr);
00157   void getSliceuIntV     (uInt rownr, const Slicer&, Array<uInt>* dataPtr);
00158   void getSlicefloatV    (uInt rownr, const Slicer&, Array<float>* dataPtr);
00159   void getSlicedoubleV   (uInt rownr, const Slicer&, Array<double>* dataPtr);
00160   void getSliceComplexV  (uInt rownr, const Slicer&, Array<Complex>* dataPtr);
00161   void getSliceDComplexV (uInt rownr, const Slicer&, Array<DComplex>* dataPtr);
00162   void getSliceStringV   (uInt rownr, const Slicer&, Array<String>* dataPtr);
00163   // </group>
00164 
00165   // Put into a section of the array in the given row.
00166   // The buffer pointed to by dataPtr has to have the correct length
00167   // (which is guaranteed by the ArrayColumn putSlice function).
00168   // <group>
00169   void putSliceBoolV     (uInt rownr, const Slicer&,
00170                           const Array<Bool>* dataPtr);
00171   void putSliceuCharV    (uInt rownr, const Slicer&,
00172                           const Array<uChar>* dataPtr);
00173   void putSliceShortV    (uInt rownr, const Slicer&,
00174                           const Array<Short>* dataPtr);
00175   void putSliceuShortV   (uInt rownr, const Slicer&,
00176                           const Array<uShort>* dataPtr);
00177   void putSliceIntV      (uInt rownr, const Slicer&,
00178                           const Array<Int>* dataPtr);
00179   void putSliceuIntV     (uInt rownr, const Slicer&,
00180                           const Array<uInt>* dataPtr);
00181   void putSlicefloatV    (uInt rownr, const Slicer&,
00182                           const Array<float>* dataPtr);
00183   void putSlicedoubleV   (uInt rownr, const Slicer&,
00184                           const Array<double>* dataPtr);
00185   void putSliceComplexV  (uInt rownr, const Slicer&,
00186                           const Array<Complex>* dataPtr);
00187   void putSliceDComplexV (uInt rownr, const Slicer&,
00188                           const Array<DComplex>* dataPtr);
00189   void putSliceStringV   (uInt rownr, const Slicer&,
00190                           const Array<String>* dataPtr);
00191   // </group>
00192 
00193   // Remove the value in the given row.
00194   // This will result in lost file space.
00195   void remove (uInt rownr);
00196 
00197 
00198 private:
00199   class Data {
00200   public:
00201     Data (const IPosition& shape, int dtype);
00202     ~Data();
00203     void clear (int dtype);
00204     const IPosition& shape() const {return shape_p;}
00205     void* data() {return data_p;}
00206   private:
00207     Data (const Data&);
00208     Data& operator= (const Data&);
00209     IPosition shape_p;
00210     void* data_p;
00211   };
00212   // The shape of all arrays in case it is fixed.
00213   IPosition fixedShape_p;
00214   // The size of an array element.
00215   uInt elemSize_p;
00216   // The size at the start of the data (for the IPosition).
00217   uInt startSize_p;
00218 
00219 
00220   // Delete the array in the given row.
00221   void deleteArray (uInt rownr);
00222 
00223   // Read the shape at the given row.
00224   // It throws an exception if undefined.
00225   Data* getShape (uInt rownr);
00226 
00227   // Get a pointer to the data array.
00228   void* getDataPtr (uInt rownr)
00229     { return (char*)(getShape(rownr)) + startSize_p; }
00230 
00231   // Forbid copy constructor.
00232   MSMIndColumn (const MSMIndColumn&);
00233 
00234   // Forbid assignment.
00235   MSMIndColumn& operator= (const MSMIndColumn&);
00236 };
00237 
00238 
00239 
00240 } //# NAMESPACE CASA - END
00241 
00242 #endif