casacore
Loading...
Searching...
No Matches
BaseTabIter.h
Go to the documentation of this file.
1//# BaseTabIter.h: Base class for table iterator
2//# Copyright (C) 1994,1995,1996,1997,1999
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: casa-feedback@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#ifndef TABLES_BASETABITER_H
27#define TABLES_BASETABITER_H
28
29//# Includes
30#include <casacore/casa/aips.h>
31#include <casacore/tables/Tables/Table.h>
32#include <casacore/casa/Utilities/Compare.h>
33#include <casacore/casa/Containers/Block.h>
34
35namespace casacore { //# NAMESPACE CASACORE - BEGIN
36
37//# Forward Declarations
38class TableColumn;
39class RefTable;
40class String;
41
42
43// <summary>
44// Base class for table iterator
45// </summary>
46
47// <use visibility=local>
48
49// <reviewed reviewer="UNKNOWN" date="before2004/08/25" tests="">
50// </reviewed>
51
52// <prerequisite>
53//# Classes you should understand before using this one.
54// <li> BaseTable
55// <li> TableIterator
56// </prerequisite>
57
58// <etymology>
59// BaseTableIterator is the base class for the classes doing
60// the actual iterating through a table.
61// </etymology>
62
63// <synopsis>
64// BaseTableIterator is the base class for the table iterators.
65// It is a letter class of the envelope TableIterator.
66// Currently there are no classes derived from BaseTableIterator,
67// since it can do all the work itself. However, in the future
68// this need not to be true anymore.
69//
70// BaseTableIterator iterates by sorting the table in the required
71// order and then creating a RefTable for each step containing the
72// rows for that iteration step. Each iteration step assembles the
73// rows with equal key values.
74// </synopsis>
75
76//# <todo asof="$DATE:$">
77//# A List of bugs, limitations, extensions or planned refinements.
78//# </todo>
79
80
82{
83public:
84
85 // Create the table iterator to iterate through the given
86 // columns in the given order. The given compare objects
87 // will be used for the sort and to compare if values are equal.
88 // If a compare object in cmpObjs is null, the default ObjCompare<T>
89 // will be used.
90 // If cacheIterationBoundaries is set to true then the iteration
91 // boundaries computed at construction time while sorting the table
92 // are used when advancing with next(). Otherwise, for each next()
93 // call the comparison functions are reevaluated again to get the
94 // iteration boundary. This improves performance in general but will
95 // break existing applications that change the comparison objects
96 // (cmpObjs) between iterations.
97 BaseTableIterator (const std::shared_ptr<BaseTable>&,
98 const Block<String>& columnNames,
99 const Block<std::shared_ptr<BaseCompare>>& cmpObjs,
100 const Block<Int>& orders,
101 int option,
102 bool cacheIterationBoundaries = false);
103
104 // Clone this iterator.
106
108
109 // Assignment is not needed, because the assignment operator in
110 // the envelope class TableIterator has reference semantics.
112
113 // Reset the iterator (i.e. restart iteration).
114 virtual void reset();
115
116 // Return the next group.
117 virtual std::shared_ptr<BaseTable> next();
118
119 virtual void copyState(const BaseTableIterator &);
120
121 // Report Name of slowest sort column that changed (according to the
122 // comparison function) to terminate the most recent call to next()
123 // Enables clients to sense iteration boundary properties
124 // and organize associated iterations
125 inline const String& keyChangeAtLastNext() const
126 { return keyChangeAtLastNext_p; }
127
128protected:
129 std::shared_ptr<BaseTable> sortTab_p; //# Table sorted in iteration order
130 rownr_t lastRow_p; //# last row used from reftab
131 uInt nrkeys_p; //# nr of columns in group
132 String keyChangeAtLastNext_p; //# name of column that terminated most recent next()
133 PtrBlock<BaseColumn*> colPtr_p; //# pointer to column objects
134 Block<std::shared_ptr<BaseCompare>> cmpObj_p; //# comparison object per column
135
136 // Copy constructor (to be used by clone)
138
139 std::shared_ptr<BaseTable> noCachedIterBoundariesNext();
140
141private:
142 Block<void*> lastVal_p; //# last value per column
143 Block<void*> curVal_p; //# current value per column
144
145 std::shared_ptr<Vector<rownr_t>> sortIterBoundaries_p;
146 std::shared_ptr<Vector<size_t>> sortIterKeyIdxChange_p;
149 RefTable* aRefTable_p; //# RefTable returned in each iteration
150 std::shared_ptr<BaseTable> aBaseTable_p; //# Same as above for automatic deletion
151};
152
153
154
155} //# NAMESPACE CASACORE - END
156
157#endif
const String & keyChangeAtLastNext() const
Report Name of slowest sort column that changed (according to the comparison function) to terminate t...
BaseTableIterator(const std::shared_ptr< BaseTable > &, const Block< String > &columnNames, const Block< std::shared_ptr< BaseCompare > > &cmpObjs, const Block< Int > &orders, int option, bool cacheIterationBoundaries=false)
Create the table iterator to iterate through the given columns in the given order.
std::shared_ptr< BaseTable > aBaseTable_p
BaseTableIterator(const BaseTableIterator &)
Copy constructor (to be used by clone)
virtual std::shared_ptr< BaseTable > next()
Return the next group.
std::shared_ptr< Vector< size_t > > sortIterKeyIdxChange_p
Vector< rownr_t >::iterator sortIterBoundariesIt_p
virtual void copyState(const BaseTableIterator &)
Block< std::shared_ptr< BaseCompare > > cmpObj_p
PtrBlock< BaseColumn * > colPtr_p
BaseTableIterator & operator=(const BaseTableIterator &)=delete
Assignment is not needed, because the assignment operator in the envelope class TableIterator has ref...
Vector< size_t >::iterator sortIterKeyIdxChangeIt_p
std::shared_ptr< Vector< rownr_t > > sortIterBoundaries_p
std::shared_ptr< BaseTable > noCachedIterBoundariesNext()
BaseTableIterator * clone() const
Clone this iterator.
std::shared_ptr< BaseTable > sortTab_p
virtual void reset()
Reset the iterator (i.e.
simple 1-D array
Definition Block.h:198
A drop-in replacement for Block<T*>.
Definition Block.h:812
String: the storage and methods of handling collections of characters.
Definition String.h:223
this file contains all the compiler specific defines
Definition mainpage.dox:28
unsigned int uInt
Definition aipstype.h:49
uInt64 rownr_t
Define the type of a row number in a table.
Definition aipsxtype.h:44