Line data Source code
1 : // -*- mode: c++ -*- 2 : //# Copyright (C) 1996,1997,1998,1999,2000,2002,2003,2015 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 : // 27 : // casacore::Data provider mask iterators, based on a flag column. 28 : // 29 : #ifndef MSVIS_STATISTICS_VI2_STATS_FLAGS_ITERATOR_H_ 30 : #define MSVIS_STATISTICS_VI2_STATS_FLAGS_ITERATOR_H_ 31 : 32 : #include <casacore/casa/aips.h> 33 : #include <casacore/casa/Arrays/Array.h> 34 : #include <msvis/MSVis/VisibilityIterator2.h> 35 : #include <msvis/MSVis/VisBuffer2.h> 36 : #include <memory> 37 : #include <iterator> 38 : 39 : namespace casa { 40 : 41 : // Vi2StatsFlagsIterator has the form of a CRTP base class to promote 42 : // efficiency in iterator operations. 43 : // 44 : template <class T> 45 : class Vi2StatsFlagsIterator 46 : : public std::iterator<std::input_iterator_tag,casacore::Bool> { 47 : 48 : public: 49 : Vi2StatsFlagsIterator& operator++(); 50 : 51 : Vi2StatsFlagsIterator operator++(int); 52 : 53 : bool operator==(const Vi2StatsFlagsIterator& rhs); 54 : 55 : bool operator!=(const Vi2StatsFlagsIterator& rhs); 56 : 57 : casacore::Bool operator*(); 58 : 59 : bool atEnd(); 60 : 61 : protected: 62 0 : Vi2StatsFlagsIterator() 63 : : flags_array(&empty_array) 64 : , flags_iter(empty_array.begin()) 65 0 : , end_iter(empty_array.end()) {}; 66 : 67 : const casacore::Array<casacore::Bool>* flags_array; 68 : 69 : casacore::Array<casacore::Bool>::const_iterator flags_iter; 70 : 71 : casacore::Array<casacore::Bool>::const_iterator end_iter; 72 : 73 : static const casacore::Array<casacore::Bool> empty_array; 74 : }; 75 : 76 : template <class T> 77 : const casacore::Array<casacore::Bool> Vi2StatsFlagsIterator<T>::empty_array; 78 : 79 : // Mask iterator over flag cube. If the flag cube column is not present, this 80 : // iterator will provide values as if the flag cube were present by replicating 81 : // flag row values in order to mimic the shape of the flag cube. 82 : class Vi2StatsFlagsCubeIterator final 83 : : public Vi2StatsFlagsIterator<Vi2StatsFlagsCubeIterator> { 84 : public: 85 : Vi2StatsFlagsCubeIterator(vi::VisBuffer2 *vb2); 86 : 87 : Vi2StatsFlagsCubeIterator(); 88 : 89 : Vi2StatsFlagsCubeIterator& operator++(); 90 : 91 : Vi2StatsFlagsCubeIterator operator++(int); 92 : 93 : bool operator==(const Vi2StatsFlagsCubeIterator& rhs); 94 : 95 : bool operator!=(const Vi2StatsFlagsCubeIterator& rhs); 96 : 97 : casacore::Bool operator*(); 98 : 99 : bool atEnd(); 100 : 101 : protected: 102 : casacore::uInt expansion_factor; 103 : 104 : private: 105 : casacore::uInt replicate_count; 106 : }; 107 : 108 : // Mask iterator over row flags. If the row flags column is not present, this 109 : // iterator will provide values as if the row flags column were present by 110 : // reducing the flag cube values to mimic the shape of the flag row column. 111 : class Vi2StatsFlagsRowIterator final 112 : : public Vi2StatsFlagsIterator<Vi2StatsFlagsRowIterator> { 113 : public: 114 : Vi2StatsFlagsRowIterator(vi::VisBuffer2 *vb2); 115 : 116 : Vi2StatsFlagsRowIterator(); 117 : 118 : Vi2StatsFlagsRowIterator& operator++(); 119 : 120 : Vi2StatsFlagsRowIterator operator++(int); 121 : 122 : bool operator==(const Vi2StatsFlagsRowIterator& rhs); 123 : 124 : bool operator!=(const Vi2StatsFlagsRowIterator& rhs); 125 : 126 : casacore::Bool operator*(); 127 : 128 : bool atEnd(); 129 : 130 : protected: 131 : casacore::uInt reduction_factor; 132 : 133 : private: 134 : casacore::Bool rowFlag; 135 : void prepareNextRow(); 136 : }; 137 : 138 : } // namespace casa 139 : 140 : 141 : #endif // MSVIS_STATISTICS_VI2_STATS_FLAGS_ITERATOR_H_