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// <summary>
43// Base class for table iterator
44// </summary>
45
46// <use visibility=local>
47
48// <reviewed reviewer="UNKNOWN" date="before2004/08/25" tests="">
49// </reviewed>
50
51// <prerequisite>
52// # Classes you should understand before using this one.
53// <li> BaseTable
54// <li> TableIterator
55// </prerequisite>
56
57// <etymology>
58// BaseTableIterator is the base class for the classes doing
59// the actual iterating through a table.
60// </etymology>
61
62// <synopsis>
63// BaseTableIterator is the base class for the table iterators.
64// It is a letter class of the envelope TableIterator.
65// Currently there are no classes derived from BaseTableIterator,
66// since it can do all the work itself. However, in the future
67// this need not to be true anymore.
68//
69// BaseTableIterator iterates by sorting the table in the required
70// order and then creating a RefTable for each step containing the
71// rows for that iteration step. Each iteration step assembles the
72// rows with equal key values.
73// </synopsis>
74
75// # <todo asof="$DATE:$">
76// # A List of bugs, limitations, extensions or planned refinements.
77// # </todo>
78
80 public:
81 // Create the table iterator to iterate through the given
82 // columns in the given order. The given compare objects
83 // will be used for the sort and to compare if values are equal.
84 // If a compare object in cmpObjs is null, the default ObjCompare<T>
85 // will be used.
86 // If cacheIterationBoundaries is set to true then the iteration
87 // boundaries computed at construction time while sorting the table
88 // are used when advancing with next(). Otherwise, for each next()
89 // call the comparison functions are reevaluated again to get the
90 // iteration boundary. This improves performance in general but will
91 // break existing applications that change the comparison objects
92 // (cmpObjs) between iterations.
93 BaseTableIterator(const std::shared_ptr<BaseTable>&, const Block<String>& columnNames,
94 const Block<std::shared_ptr<BaseCompare>>& cmpObjs, const Block<Int>& orders,
95 int option, bool cacheIterationBoundaries = false);
96
97 // Clone this iterator.
99
101
102 // Assignment is not needed, because the assignment operator in
103 // the envelope class TableIterator has reference semantics.
105
106 // Reset the iterator (i.e. restart iteration).
107 virtual void reset();
108
109 // Return the next group.
110 virtual std::shared_ptr<BaseTable> next();
111
112 virtual void copyState(const BaseTableIterator&);
113
114 // Report Name of slowest sort column that changed (according to the
115 // comparison function) to terminate the most recent call to next()
116 // Enables clients to sense iteration boundary properties
117 // and organize associated iterations
118 inline const String& keyChangeAtLastNext() const { return keyChangeAtLastNext_p; }
119
120 protected:
121 std::shared_ptr<BaseTable> sortTab_p; // # Table sorted in iteration order
122 rownr_t lastRow_p; // # last row used from reftab
123 uInt nrkeys_p; // # nr of columns in group
124 String keyChangeAtLastNext_p; // # name of column that terminated most recent next()
125 Block<BaseColumn*> colPtr_p; // # pointer to column objects
126 Block<std::shared_ptr<BaseCompare>> cmpObj_p; // # comparison object per column
127
128 // Copy constructor (to be used by clone)
130
131 std::shared_ptr<BaseTable> noCachedIterBoundariesNext();
132
133 private:
134 Block<void*> lastVal_p; // # last value per column
135 Block<void*> curVal_p; // # current value per column
136
137 std::shared_ptr<Vector<rownr_t>> sortIterBoundaries_p;
138 std::shared_ptr<Vector<size_t>> sortIterKeyIdxChange_p;
141 RefTable* aRefTable_p; // # RefTable returned in each iteration
142 std::shared_ptr<BaseTable> aBaseTable_p; // # Same as above for automatic deletion
143};
144
145} // namespace casacore
146
147#endif
IteratorSTL iterator
Definition Array.h:807
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
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
Block< BaseColumn * > colPtr_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.
String: the storage and methods of handling collections of characters.
Definition String.h:355
For temporary backward namespace compatibility, use casa as alias for casacore.
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