casa  $Rev:20696$
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
ColumnCache.h
Go to the documentation of this file.
00001 //# ColumnCache.h: A caching object for a table column
00002 //# Copyright (C) 1997
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: ColumnCache.h 20551 2009-03-25 00:11:33Z Malte.Marquarding $
00027 
00028 #ifndef TABLES_COLUMNCACHE_H
00029 #define TABLES_COLUMNCACHE_H
00030 
00031 
00032 //# Includes
00033 #include <casa/aips.h>
00034 
00035 
00036 namespace casa { //# NAMESPACE CASA - BEGIN
00037 
00038 // <summary>
00039 // A caching object for a table column.
00040 // </summary>
00041 
00042 // <use visibility=local>
00043 
00044 // <reviewed reviewer="UNKNOWN" date="before2004/08/25" tests="">
00045 // </reviewed>
00046 
00047 // <prerequisite>
00048 //# Classes you should understand before using this one.
00049 //   <li> <linkto class=ScalarColumn>ScalarColumn</linkto>
00050 // </prerequisite>
00051 
00052 // <synopsis>
00053 // ColumnCache acts as a cache for a table column.
00054 // It contains a pointer to data and the start and end row number
00055 // for which these data are valid. An increment is part of the object
00056 // and is usually 0 or 1. The value 0 is used for data which is
00057 // valid for multiple rows (as used in
00058 // <linkto class=IncrementalStMan>IncrementalStMan</linkto>).
00059 // The value 1 is used for data stored consecutevily in a buffer for
00060 // each row (as used in <linkto class=StManAipsIO>StManAipsIO</linkto>).
00061 // <p>
00062 // The ColumnCache object is created and updated by the data manager.
00063 // The top level <linkto class=ScalarColumn>ScalarColumn</linkto> object
00064 // contains a pointer to the cache object. In this way the
00065 // <src>ScalarColumn::get</src> can often be executed by a few inlined
00066 // statements which improves performance considerably.
00067 // <p>
00068 // The <src>invalidate</src> function can be used to invalidate the
00069 // cache. This is for instance needed when a table lock is acquired
00070 // or released to be sure that the cache gets refreshed.
00071 // </synopsis> 
00072 
00073 // <motivation>
00074 // This class was developed to improve the performance for getting a scalar.
00075 // </motivation>
00076 
00077 // <todo asof="$DATE:$">
00078 //  <li>For ConcatColumn add the ability to have other ColumnCache objects
00079 //      using this one and invalidate them as well.
00080 // </todo>
00081 
00082 
00083 class ColumnCache
00084 {
00085 public:
00086     // Constructor.
00087     // It sets the increment to 1 and calls invalidate.
00088     ColumnCache();
00089 
00090     // Set the increment to the given value.
00091     void setIncrement (uInt increment);
00092 
00093     // Set the start and end row number for which the given data pointer
00094     // is valid.
00095     void set (uInt startRow, uInt endRow, const void* dataPtr);
00096 
00097     // Invalidate the cache.
00098     // This clears the data pointer and sets startRow>endRow.
00099     void invalidate();
00100 
00101     // Calculate the offset in the cached data for the given row.
00102     // -1 is returned if the row is not within the cached rows.
00103     Int offset (uInt rownr) const;
00104 
00105     // Give a pointer to the data.
00106     // The calling function has to do a proper cast after which the
00107     // calculated offset can be added to get the proper data.
00108     const void* dataPtr() const;
00109 
00110     // Give the start, end (including), and increment row number
00111     // of the cached column values.
00112     uInt start() const {return itsStart;}
00113     uInt end() const {return itsEnd;}
00114     uInt incr() const {return itsIncr;}
00115 
00116 private:
00117     uInt  itsStart;
00118     uInt  itsEnd;
00119     uInt  itsIncr;
00120     const void* itsData;
00121 };
00122 
00123 
00124 inline void ColumnCache::setIncrement (uInt increment)
00125 {
00126     itsIncr = increment;
00127 }
00128 
00129 inline void ColumnCache::invalidate()
00130 {
00131     set (1, 0, 0);
00132 }
00133 
00134 inline Int ColumnCache::offset (uInt rownr) const
00135 {
00136     return rownr<itsStart || rownr>itsEnd  ?  -1 :
00137                                               Int((rownr-itsStart)*itsIncr);
00138 }
00139 
00140 inline const void* ColumnCache::dataPtr() const
00141 {
00142     return itsData;
00143 }
00144 
00145 /*
00146 inline uInt ColumnCache::start() const
00147 {
00148     return itsStart;
00149 }
00150 inline uInt ColumnCache::end() const
00151 {
00152     return itsEnd;
00153 }
00154 inline uInt ColumnCache::incr() const
00155 {
00156     return itsIncr;
00157 }
00158 */
00159 
00160 
00161 } //# NAMESPACE CASA - END
00162 
00163 #endif