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