1 | #ifndef _ASAP_INDEX_ITERATOR_H_
|
---|
2 | #define _ASAP_INDEX_ITERATOR_H_
|
---|
3 |
|
---|
4 | #include <vector>
|
---|
5 | #include <casa/Containers/Block.h>
|
---|
6 | #include <casa/Arrays/Vector.h>
|
---|
7 | #include <casa/Arrays/Matrix.h>
|
---|
8 | #include <casa/Arrays/IPosition.h>
|
---|
9 |
|
---|
10 | #include "Scantable.h"
|
---|
11 |
|
---|
12 | using namespace std ;
|
---|
13 | using namespace casa ;
|
---|
14 |
|
---|
15 | namespace asap {
|
---|
16 | class IndexIterator
|
---|
17 | {
|
---|
18 | public:
|
---|
19 | IndexIterator( IPosition &shape ) ;
|
---|
20 | Block<uInt> current() { return idx_m ; } ;
|
---|
21 | Bool pastEnd() ;
|
---|
22 | void next() ;
|
---|
23 | private:
|
---|
24 | uInt nfield_m ;
|
---|
25 | Block<uInt> prod_m ;
|
---|
26 | Block<uInt> idx_m ;
|
---|
27 | uInt niter_m ;
|
---|
28 | uInt maxiter_m ;
|
---|
29 | } ;
|
---|
30 |
|
---|
31 | class ArrayIndexIterator
|
---|
32 | {
|
---|
33 | public:
|
---|
34 | ArrayIndexIterator( Matrix<uInt> &arr,
|
---|
35 | vector< vector<uInt> > idlist=vector< vector<uInt> >() ) ;
|
---|
36 | virtual ~ArrayIndexIterator() ;
|
---|
37 | Vector<uInt> current() ;
|
---|
38 | Bool pastEnd() ;
|
---|
39 | virtual void next() = 0 ;
|
---|
40 | virtual Vector<uInt> getRows( StorageInitPolicy policy=COPY ) = 0 ;
|
---|
41 | protected:
|
---|
42 | IndexIterator *iter_m ;
|
---|
43 | uInt nrow_m ;
|
---|
44 | uInt ncol_m ;
|
---|
45 | Block<uInt> storage_m ;
|
---|
46 | Matrix<uInt> arr_m ;
|
---|
47 | IPosition pos_m ;
|
---|
48 | Vector<uInt> current_m ;
|
---|
49 | vector< vector<uInt> > idxlist_m ;
|
---|
50 | } ;
|
---|
51 |
|
---|
52 | class ArrayIndexIteratorNormal : public ArrayIndexIterator
|
---|
53 | {
|
---|
54 | public:
|
---|
55 | ArrayIndexIteratorNormal( Matrix<uInt> &arr,
|
---|
56 | vector< vector<uInt> > idlist=vector< vector<uInt> >() ) ;
|
---|
57 | void next() ;
|
---|
58 | Vector<uInt> getRows( StorageInitPolicy policy=COPY ) ;
|
---|
59 | } ;
|
---|
60 |
|
---|
61 | class ArrayIndexIteratorAcc : public ArrayIndexIterator
|
---|
62 | {
|
---|
63 | public:
|
---|
64 | ArrayIndexIteratorAcc( Matrix<uInt> &arr,
|
---|
65 | vector< vector<uInt> > idlist=vector< vector<uInt> >() ) ;
|
---|
66 | void next() ;
|
---|
67 | Vector<uInt> getRows( StorageInitPolicy policy=COPY ) ;
|
---|
68 | private:
|
---|
69 | Int isChanged( Block<uInt> &idx ) ;
|
---|
70 | uInt *updateStorage( Int &icol, uInt *base, uInt &v ) ;
|
---|
71 |
|
---|
72 | Block<uInt> prev_m ;
|
---|
73 | Block<uInt> len_m ;
|
---|
74 | Block<Bool> skip_m ;
|
---|
75 | } ;
|
---|
76 |
|
---|
77 | class STIdxIter
|
---|
78 | {
|
---|
79 | public:
|
---|
80 | STIdxIter() ;
|
---|
81 | STIdxIter( const string &name,
|
---|
82 | const vector<string> &cols ) ;
|
---|
83 | STIdxIter( const CountedPtr<Scantable> &s,
|
---|
84 | const vector<string> &cols ) ;
|
---|
85 | virtual ~STIdxIter() ;
|
---|
86 | vector<uInt> currentSTL() { return tovector( iter_m->current() ) ; } ;
|
---|
87 | Vector<uInt> current() { return iter_m->current() ; } ;
|
---|
88 | Bool pastEnd() { return iter_m->pastEnd() ; } ;
|
---|
89 | void next() { iter_m->next() ; } ;
|
---|
90 | vector<uInt> getRowsSTL() { return tovector( iter_m->getRows() ) ; } ;
|
---|
91 | // !!!you should not use policy=TAKE_OVER since it causes problem!!!
|
---|
92 | Vector<uInt> getRows( StorageInitPolicy policy=COPY ) ;
|
---|
93 | protected:
|
---|
94 | ArrayIndexIterator *iter_m ;
|
---|
95 | virtual void init( Table &t,
|
---|
96 | const vector<string> &cols ) = 0 ;
|
---|
97 | private:
|
---|
98 | vector<uInt> tovector( Vector<uInt> v ) ;
|
---|
99 | } ;
|
---|
100 |
|
---|
101 | class STIdxIterNormal : public STIdxIter
|
---|
102 | {
|
---|
103 | public:
|
---|
104 | STIdxIterNormal() ;
|
---|
105 | STIdxIterNormal( const string &name,
|
---|
106 | const vector<string> &cols ) ;
|
---|
107 | STIdxIterNormal( const CountedPtr<Scantable> &s,
|
---|
108 | const vector<string> &cols ) ;
|
---|
109 | ~STIdxIterNormal() ;
|
---|
110 | protected:
|
---|
111 | void init( Table &t,
|
---|
112 | const vector<string> &cols ) ;
|
---|
113 | } ;
|
---|
114 |
|
---|
115 | class STIdxIterAcc : public STIdxIter
|
---|
116 | {
|
---|
117 | public:
|
---|
118 | STIdxIterAcc() ;
|
---|
119 | STIdxIterAcc( const string &name,
|
---|
120 | const vector<string> &cols ) ;
|
---|
121 | STIdxIterAcc( const CountedPtr<Scantable> &s,
|
---|
122 | const vector<string> &cols ) ;
|
---|
123 | ~STIdxIterAcc() ;
|
---|
124 | protected:
|
---|
125 | virtual void init( Table &t,
|
---|
126 | const vector<string> &cols ) ;
|
---|
127 | } ;
|
---|
128 |
|
---|
129 | // class STIdxIterExAcc : public STIdxIterAcc
|
---|
130 | // {
|
---|
131 | // STIdxIterExAcc() ;
|
---|
132 | // STIdxIterExAcc( const string &name,
|
---|
133 | // const vector<string> &cols ) ;
|
---|
134 | // STIdxIterExAcc( const CountedPtr<Scantable> &s,
|
---|
135 | // const vector<string> &cols ) ;
|
---|
136 | // ~STIdxIterExAcc() ;
|
---|
137 | // protected:
|
---|
138 | // virtual void init( Table &t,
|
---|
139 | // const vector<string> &cols ) ;
|
---|
140 | // } ;
|
---|
141 |
|
---|
142 | } // namespace
|
---|
143 | #endif /* _ASAP_INDEX_ITERATOR_H_ */
|
---|