00001 // -*- mode: c++ -*- 00002 //# Copyright (C) 1996,1997,1998,1999,2000,2002,2003,2015 00003 //# Associated Universities, Inc. Washington DC, USA. 00004 //# 00005 //# This library is free software; you can redistribute it and/or modify it 00006 //# under the terms of the GNU Library General Public License as published by 00007 //# the Free Software Foundation; either version 2 of the License, or (at your 00008 //# option) any later version. 00009 //# 00010 //# This library is distributed in the hope that it will be useful, but WITHOUT 00011 //# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 00012 //# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public 00013 //# License for more details. 00014 //# 00015 //# You should have received a copy of the GNU Library General Public License 00016 //# along with this library; if not, write to the Free Software Foundation, 00017 //# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA. 00018 //# 00019 //# Correspondence concerning AIPS++ should be addressed as follows: 00020 //# Internet email: aips2-request@nrao.edu. 00021 //# Postal address: AIPS++ Project Office 00022 //# National Radio Astronomy Observatory 00023 //# 520 Edgemont Road 00024 //# Charlottesville, VA 22903-2475 USA 00025 //# 00026 // 00027 // Data iterators for Vi2ChunkDataProvider 00028 // 00029 #ifndef MSVIS_STATISTICS_VI2_STATS_DATA_ITERATOR_H_ 00030 #define MSVIS_STATISTICS_VI2_STATS_DATA_ITERATOR_H_ 00031 00032 #include <casacore/casa/aips.h> 00033 #include <casacore/casa/Arrays/Array.h> 00034 #include <iterator> 00035 00036 namespace casa { 00037 00038 // 00039 // Vi2StatsDataIterator is designed to support an on-the-fly application of a 00040 // transformation between the values in the source array and the values provided 00041 // by the iterator. This feature allows a Vi2ChunkDataProvider to provide, for 00042 // example, visibility amplitudes during iteration over visibilities. 00043 // 00044 template<class Transformed, class Data> 00045 class Vi2StatsDataIterator 00046 : public std::iterator<std::input_iterator_tag,Transformed> { 00047 00048 public: 00049 typedef Transformed AccumType; 00050 typedef Data DataType; 00051 00052 Vi2StatsDataIterator(const Array<Data>& a) 00053 : array(&a) 00054 , array_iter(array->begin()) 00055 , end_iter(array->end()) {} 00056 00057 Vi2StatsDataIterator() 00058 : Vi2StatsDataIterator(empty_array) {} 00059 00060 Vi2StatsDataIterator& operator++() { 00061 ++array_iter; 00062 return *this; 00063 } 00064 00065 Vi2StatsDataIterator operator++(int) { 00066 Vi2StatsDataIterator tmp(*this); 00067 operator++(); 00068 return tmp; 00069 } 00070 00071 bool operator==(const Vi2StatsDataIterator& rhs) { 00072 return array_iter == rhs.array_iter; 00073 } 00074 00075 bool operator!=(const Vi2StatsDataIterator& rhs) { 00076 return array_iter != rhs.array_iter; 00077 } 00078 00079 Transformed operator*(); 00080 00081 bool atEnd() { 00082 return array_iter == end_iter; 00083 } 00084 00085 uInt64 getCount() { 00086 return array->size(); 00087 }; 00088 00089 protected: 00090 00091 const Array<Data>* array; 00092 00093 typename Array<Data>::const_iterator array_iter; 00094 00095 typename Array<Data>::const_iterator end_iter; 00096 00097 static const Array<Data> empty_array; 00098 00099 }; 00100 00101 00102 template<class Transformed, class Data> 00103 const Array<Data> Vi2StatsDataIterator<Transformed,Data>::empty_array; 00104 00105 // Simple non-transforming (widening excepted) data iterator types. 00106 // 00107 template <class T> 00108 class DataIteratorMixin : public T { 00109 00110 public: 00111 using T::T; 00112 00113 typename T::AccumType operator*() { 00114 return *T::array_iter; 00115 } 00116 }; 00117 00118 typedef DataIteratorMixin< Vi2StatsDataIterator<Double,Float> > 00119 Vi2StatsFloatIterator; 00120 00121 typedef DataIteratorMixin< Vi2StatsDataIterator<Double,Double> > 00122 Vi2StatsDoubleIterator; 00123 00124 typedef DataIteratorMixin< Vi2StatsDataIterator<Double,Int> > 00125 Vi2StatsIntIterator; 00126 00127 } // namespace casa 00128 00129 #endif // MSVIS_STATISTICS_VI2_STATS_DATA_ITERATOR_H_