LCOV - code coverage report
Current view: top level - msvis/MSVis/statistics - Vi2StatsDataIterator.h (source / functions) Hit Total Coverage
Test: ctest_coverage.info Lines: 5 5 100.0 %
Date: 2023-11-06 10:06:49 Functions: 8 8 100.0 %

          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             : // Data iterators for Vi2ChunkDataProvider
      28             : //
      29             : #ifndef MSVIS_STATISTICS_VI2_STATS_DATA_ITERATOR_H_
      30             : #define MSVIS_STATISTICS_VI2_STATS_DATA_ITERATOR_H_
      31             : 
      32             : #include <casacore/casa/aips.h>
      33             : #include <casacore/casa/Arrays/Array.h>
      34             : #include <iterator>
      35             : 
      36             : 
      37             : namespace casa {
      38             : 
      39             : //
      40             : // Vi2StatsDataIterator is designed to support an on-the-fly application of a
      41             : // transformation between the values in the source array and the values provided
      42             : // by the iterator. This feature allows a Vi2ChunkDataProvider to provide, for
      43             : // example, visibility amplitudes during iteration over visibilities.
      44             : //
      45             : template<class Transformed, class Data>
      46             : class Vi2StatsDataIterator
      47             :         : public std::iterator<std::input_iterator_tag,Transformed> {
      48             : 
      49             : public:
      50             :         typedef Transformed AccumType;
      51             :         typedef Data DataType;
      52             : 
      53       81786 :         Vi2StatsDataIterator(const casacore::Array<Data>& a)
      54             :                 : array(&a)
      55       81786 :                 , array_iter(array->begin())
      56       81786 :                 , end_iter(array->end()) {}
      57             : 
      58             :         Vi2StatsDataIterator()
      59             :                 : Vi2StatsDataIterator(empty_array) {}
      60             : 
      61             :         Vi2StatsDataIterator& operator++() {
      62             :                 ++array_iter;
      63             :                 return *this;
      64             :         }
      65             : 
      66             :         Vi2StatsDataIterator operator++(int) {
      67             :                 Vi2StatsDataIterator tmp(*this);
      68             :                 operator++();
      69             :                 return tmp;
      70             :         }
      71             : 
      72             :         bool operator==(const Vi2StatsDataIterator& rhs) {
      73             :                 return array_iter == rhs.array_iter;
      74             :         }
      75             : 
      76             :         bool operator!=(const Vi2StatsDataIterator& rhs) {
      77             :                 return array_iter != rhs.array_iter;
      78             :         }
      79             : 
      80             :         Transformed operator*();
      81             : 
      82             :         bool atEnd() {
      83             :                 return array_iter == end_iter;
      84             :         }
      85             : 
      86       81786 :         casacore::uInt64 getCount() {
      87       81786 :                 return array->size();
      88             :         }
      89             : 
      90             : protected:
      91             : 
      92             :         const casacore::Array<Data>* array;
      93             : 
      94             :         typename casacore::Array<Data>::const_iterator array_iter;
      95             : 
      96             :         typename casacore::Array<Data>::const_iterator end_iter;
      97             : 
      98             :         static const casacore::Array<Data> empty_array;
      99             : 
     100             : };
     101             : 
     102             : 
     103             : template<class Transformed, class Data>
     104             : const casacore::Array<Data> Vi2StatsDataIterator<Transformed,Data>::empty_array;
     105             : 
     106             : // Simple non-transforming (widening excepted) data iterator types.
     107             : //
     108             : template <class T>
     109             : class DataIteratorMixin : public T {
     110             : 
     111             : public:
     112             :         using T::T;
     113             : 
     114             :         typename T::AccumType operator*() {
     115             :                 return *T::array_iter;
     116             :         }
     117             : };
     118             : 
     119             : typedef DataIteratorMixin< Vi2StatsDataIterator<casacore::Double,casacore::Float> >
     120             : Vi2StatsFloatIterator;
     121             : 
     122             : typedef DataIteratorMixin< Vi2StatsDataIterator<casacore::Double,casacore::Double> >
     123             : Vi2StatsDoubleIterator;
     124             : 
     125             : typedef DataIteratorMixin< Vi2StatsDataIterator<casacore::Double,casacore::Int> >
     126             : Vi2StatsIntIterator;
     127             : 
     128             : }
     129             : 
     130             : 
     131             : #endif // MSVIS_STATISTICS_VI2_STATS_DATA_ITERATOR_H_

Generated by: LCOV version 1.16