casa  5.7.0-16
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ColumnCache.h
Go to the documentation of this file.
1 //# ColumnCache.h: A caching object for a table column
2 //# Copyright (C) 1997
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_COLUMNCACHE_H
29 #define TABLES_COLUMNCACHE_H
30 
31 
32 //# Includes
33 #include <casacore/casa/aips.h>
34 
35 
36 namespace casacore { //# NAMESPACE CASACORE - BEGIN
37 
38 // <summary>
39 // A caching object for a table column.
40 // </summary>
41 
42 // <use visibility=local>
43 
44 // <reviewed reviewer="UNKNOWN" date="before2004/08/25" tests="">
45 // </reviewed>
46 
47 // <prerequisite>
48 //# Classes you should understand before using this one.
49 // <li> <linkto class=ScalarColumn>ScalarColumn</linkto>
50 // </prerequisite>
51 
52 // <synopsis>
53 // ColumnCache acts as a cache for a table column.
54 // It contains a pointer to data and the start and end row number
55 // for which these data are valid. An increment is part of the object
56 // and is usually 0 or 1. The value 0 is used for data which is
57 // valid for multiple rows (as used in
58 // <linkto class=IncrementalStMan>IncrementalStMan</linkto>).
59 // The value 1 is used for data stored consecutevily in a buffer for
60 // each row (as used in <linkto class=StManAipsIO>StManAipsIO</linkto>).
61 // <p>
62 // The ColumnCache object is created and updated by the data manager.
63 // The top level <linkto class=ScalarColumn>ScalarColumn</linkto> object
64 // contains a pointer to the cache object. In this way the
65 // <src>ScalarColumn::get</src> can often be executed by a few inlined
66 // statements which improves performance considerably.
67 // <p>
68 // The <src>invalidate</src> function can be used to invalidate the
69 // cache. This is for instance needed when a table lock is acquired
70 // or released to be sure that the cache gets refreshed.
71 // </synopsis>
72 
73 // <motivation>
74 // This class was developed to improve the performance for getting a scalar.
75 // </motivation>
76 
77 // <todo asof="$DATE:$">
78 // <li>For ConcatColumn add the ability to have other ColumnCache objects
79 // using this one and invalidate them as well.
80 // </todo>
81 
82 
84 {
85 public:
86  // Constructor.
87  // It sets the increment to 1 and calls invalidate.
88  ColumnCache();
89 
90  // Set the increment to the given value.
91  void setIncrement (uInt increment);
92 
93  // Set the start and end row number for which the given data pointer
94  // is valid.
95  void set (uInt startRow, uInt endRow, const void* dataPtr);
96 
97  // Invalidate the cache.
98  // This clears the data pointer and sets startRow>endRow.
99  void invalidate();
100 
101  // Calculate the offset in the cached data for the given row.
102  // -1 is returned if the row is not within the cached rows.
103  Int offset (uInt rownr) const;
104 
105  // Give a pointer to the data.
106  // The calling function has to do a proper cast after which the
107  // calculated offset can be added to get the proper data.
108  const void* dataPtr() const;
109 
110  // Give the start, end (including), and increment row number
111  // of the cached column values.
112  uInt start() const {return itsStart;}
113  uInt end() const {return itsEnd;}
114  uInt incr() const {return itsIncr;}
115 
116 private:
120  const void* itsData;
121 };
122 
123 
124 inline void ColumnCache::setIncrement (uInt increment)
125 {
126  itsIncr = increment;
127 }
128 
130 {
131  set (1, 0, 0);
132 }
133 
134 inline Int ColumnCache::offset (uInt rownr) const
135 {
136  return rownr<itsStart || rownr>itsEnd ? -1 :
137  Int((rownr-itsStart)*itsIncr);
138 }
139 
140 inline const void* ColumnCache::dataPtr() const
141 {
142  return itsData;
143 }
144 
145 /*
146 inline uInt ColumnCache::start() const
147 {
148  return itsStart;
149 }
150 inline uInt ColumnCache::end() const
151 {
152  return itsEnd;
153 }
154 inline uInt ColumnCache::incr() const
155 {
156  return itsIncr;
157 }
158 */
159 
160 
161 } //# NAMESPACE CASACORE - END
162 
163 #endif
Int offset(uInt rownr) const
Calculate the offset in the cached data for the given row.
Definition: ColumnCache.h:134
int Int
Definition: aipstype.h:50
ColumnCache()
Constructor.
uInt incr() const
Definition: ColumnCache.h:114
void setIncrement(uInt increment)
Set the increment to the given value.
Definition: ColumnCache.h:124
uInt end() const
Definition: ColumnCache.h:113
A caching object for a table column.
Definition: ColumnCache.h:83
void set(uInt startRow, uInt endRow, const void *dataPtr)
Set the start and end row number for which the given data pointer is valid.
const void * dataPtr() const
Give a pointer to the data.
Definition: ColumnCache.h:140
const void * itsData
Definition: ColumnCache.h:120
void invalidate()
Invalidate the cache.
Definition: ColumnCache.h:129
uInt start() const
Give the start, end (including), and increment row number of the cached column values.
Definition: ColumnCache.h:112
unsigned int uInt
Definition: aipstype.h:51
#define casacore
&lt;X11/Intrinsic.h&gt; #defines true, false, casacore::Bool, and String.
Definition: X11Intrinsic.h:42