LCOV - code coverage report
Current view: top level - include/basebmp - compositeiterator.hxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 67 70 95.7 %
Date: 2015-06-13 12:38:46 Functions: 146 677 21.6 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : 
      20             : #ifndef INCLUDED_BASEBMP_COMPOSITEITERATOR_HXX
      21             : #define INCLUDED_BASEBMP_COMPOSITEITERATOR_HXX
      22             : 
      23             : #include <sal/types.h>
      24             : #include <osl/diagnose.h>
      25             : 
      26             : #include <basebmp/nonstandarditerator.hxx>
      27             : #include <vigra/tuple.hxx>
      28             : #include <vigra/iteratortraits.hxx>
      29             : 
      30             : 
      31             : namespace basebmp
      32             : {
      33             : 
      34             : namespace detail
      35             : {
      36             :     template< typename T1, typename T2 > class ArithmeticProxy
      37             :     {
      38             :     public:
      39     1108904 :         ArithmeticProxy(T1& val1, T2& val2) :
      40             :             mpVal1( &val1 ),
      41     1108904 :             mpVal2( &val2 )
      42     1108904 :         {}
      43             : 
      44     5862373 :         void operator++() { ++(*mpVal1); ++(*mpVal2); }
      45             :         void operator++(int) { (*mpVal1)++; (*mpVal2)++; }
      46             :         void operator--() { --(*mpVal1); --(*mpVal2); }
      47             :         void operator--(int) { (*mpVal1)--; (*mpVal2)--; }
      48       21019 :         void operator+=(int d) {*mpVal1+=d; *mpVal2+=d; }
      49             :         void operator-=(int d) {*mpVal1-=d; *mpVal2-=d; }
      50             : 
      51             :         bool operator==(ArithmeticProxy const & rhs) const
      52             :         { return *mpVal1==*rhs.mpVal1 && *mpVal2==*rhs.mpVal2; }
      53             : 
      54             :         bool operator!=(ArithmeticProxy const & rhs) const
      55             :         { return *mpVal1!=*rhs.mpVal1 || *mpVal2!=*rhs.mpVal2; }
      56             : 
      57      620511 :         bool operator<(ArithmeticProxy const & rhs) const
      58      620511 :         { return *mpVal1<*rhs.mpVal1 && *mpVal2<*rhs.mpVal2; }
      59             : 
      60             :         bool operator<=(ArithmeticProxy const & rhs) const
      61             :         { return *mpVal1<=*rhs.mpVal1 && *mpVal2<=*rhs.mpVal2; }
      62             : 
      63             :         bool operator>(ArithmeticProxy const & rhs) const
      64             :         { return *mpVal1>*rhs.mpVal1 && *mpVal2>*rhs.mpVal2; }
      65             : 
      66             :         bool operator>=(ArithmeticProxy const & rhs) const
      67             :         { return *mpVal1>=*rhs.mpVal1 && *mpVal2>=*rhs.mpVal2; }
      68             : 
      69       38450 :         int operator-(ArithmeticProxy const & rhs) const
      70       38450 :         { return *mpVal1 - *rhs.mpVal1; }
      71             : 
      72             :     private:
      73             :         T1* mpVal1;
      74             :         T2* mpVal2;
      75             :     };
      76             : 
      77             :     template< typename Iterator1,
      78             :               typename Iterator2,
      79             :               typename ValueType,
      80             :               typename DifferenceType,
      81             :               typename IteratorCategory,
      82             :               class Derived >
      83             :     class CompositeIteratorBase : public NonStandardIterator
      84             :     {
      85             :     public:
      86             :         typedef Iterator1        iterator1_type;
      87             :         typedef Iterator2        iterator2_type;
      88             :         typedef ValueType        value_type;
      89             :         typedef DifferenceType   difference_type;
      90             :         typedef IteratorCategory iterator_category;
      91             : 
      92           0 :         struct Impl
      93             :         {
      94             :             iterator1_type maIter1;
      95             :             iterator2_type maIter2;
      96             :             Impl()
      97             :                 : maIter1()
      98             :                 , maIter2()
      99             :             {
     100             :             }
     101  1190814442 :             Impl(const iterator1_type& rIter1, const iterator2_type& rIter2)
     102             :                 : maIter1(rIter1)
     103  1190814442 :                 , maIter2(rIter2)
     104             :             {
     105  1190814442 :             }
     106             :         };
     107             : 
     108             :     protected:
     109             :         Impl* pImpl;
     110             : 
     111             :     private:
     112  1243453174 :         bool equal(CompositeIteratorBase const & rhs) const
     113             :         {
     114  1243453174 :             return (pImpl->maIter1 == rhs.pImpl->maIter1) && (pImpl->maIter2 == rhs.pImpl->maIter2);
     115             :         }
     116             : 
     117             :     public:
     118             :         CompositeIteratorBase()
     119             :         {
     120             :             pImpl = new Impl();
     121             :         }
     122             : 
     123     6714238 :         CompositeIteratorBase(const iterator1_type& rIter1, const iterator2_type& rIter2)
     124     6714238 :         {
     125     6714238 :             pImpl = new Impl(rIter1, rIter2);
     126     6714238 :         }
     127             : 
     128  1184100204 :         CompositeIteratorBase(const CompositeIteratorBase& rOther)
     129  1184100204 :         {
     130  1184100204 :             pImpl = new Impl(rOther.pImpl->maIter1, rOther.pImpl->maIter2);
     131  1184100204 :         }
     132             : 
     133  1190814442 :         ~CompositeIteratorBase()
     134             :         {
     135  1190814442 :             delete pImpl;
     136  1190814442 :         }
     137             : 
     138           0 :         bool operator==(Derived const & rhs) const
     139             :         {
     140           0 :             return equal(rhs);
     141             :         }
     142             : 
     143  1243453174 :         bool operator!=(Derived const & rhs) const
     144             :         {
     145  1243453174 :             return !equal(rhs);
     146             :         }
     147             : 
     148        4296 :         difference_type operator-(Derived const & rhs) const
     149             :         {
     150             :             OSL_ASSERT(pImpl->maIter1 - rhs.pImpl->maIter1 == pImpl->maIter2 - rhs.pImpl->maIter2);
     151        4296 :             return pImpl->maIter1 - rhs.pImpl->maIter1;
     152             :         }
     153             : 
     154    27218706 :         Derived & operator+=(difference_type const & s)
     155             :         {
     156    27218706 :             pImpl->maIter1 += s;
     157    27218706 :             pImpl->maIter2 += s;
     158    27218706 :             return static_cast<Derived&>(*this);
     159             :         }
     160             : 
     161             :         Derived & operator-=(difference_type const & s)
     162             :         {
     163             :             pImpl->maIter1 -= s;
     164             :             pImpl->maIter2 -= s;
     165             :             return static_cast<Derived&>(*this);
     166             :         }
     167             : 
     168    11242261 :         Derived operator+(difference_type const & s) const
     169             :         {
     170    11242261 :             Derived ret(static_cast<Derived const&>(*this));
     171    11242261 :             ret += s;
     172    11242261 :             return ret;
     173             :         }
     174             : 
     175             :         Derived operator-(difference_type const & s) const
     176             :         {
     177             :             Derived ret(static_cast<Derived const&>(*this));
     178             :             ret -= s;
     179             :             return ret;
     180             :         }
     181             : 
     182    72161388 :         Derived& operator++()
     183             :         {
     184    72161388 :             ++pImpl->maIter1;
     185    72161388 :             ++pImpl->maIter2;
     186    72161388 :             return static_cast<Derived&>(*this);
     187             :         }
     188             : 
     189             :         Derived& operator--()
     190             :         {
     191             :             --pImpl->maIter1;
     192             :             --pImpl->maIter2;
     193             :             return static_cast<Derived&>(*this);
     194             :         }
     195             : 
     196  1172622454 :         Derived operator++(int)
     197             :         {
     198  1172622454 :             Derived ret(static_cast<Derived const&>(*this));
     199  1172622454 :             ++pImpl->maIter1;
     200  1172622454 :             ++pImpl->maIter2;
     201  1172622454 :             return ret;
     202             :         }
     203             : 
     204             :         Derived operator--(int)
     205             :         {
     206             :             Derived ret(static_cast<Derived const&>(*this));
     207             :             --pImpl->maIter1;
     208             :             --pImpl->maIter2;
     209             :             return ret;
     210             :         }
     211             : 
     212             :         value_type get() const
     213             :         {
     214             :             return value_type(pImpl->maIter1.get(),
     215             :                               pImpl->maIter2.get());
     216             :         }
     217             : 
     218             :         value_type get(difference_type const & d) const
     219             :         {
     220             :             return value_type(pImpl->maIter1.get(d),
     221             :                               pImpl->maIter2.get(d));
     222             :         }
     223             : 
     224             :         void set( value_type v ) const
     225             :         {
     226             :             pImpl->maIter1.set(v);
     227             :             pImpl->maIter2.set(v);
     228             :         }
     229             : 
     230             :         void set( value_type v, difference_type const & d ) const
     231             :         {
     232             :             pImpl->maIter1.set(v,d);
     233             :             pImpl->maIter2.set(v,d);
     234             :         }
     235             : 
     236       21019 :         CompositeIteratorBase& operator=(const CompositeIteratorBase& rNew)
     237             :         {
     238       21019 :             this->pImpl->maIter1 = rNew.pImpl->maIter1;
     239       21019 :             this->pImpl->maIter2 = rNew.pImpl->maIter2;
     240       21019 :             return *this;
     241             :         }
     242             : 
     243  2457029629 :         const iterator1_type& first() const { return pImpl->maIter1; }
     244             :         iterator1_type& first() { return pImpl->maIter1; }
     245             : 
     246  1260951600 :         const iterator2_type& second() const { return pImpl->maIter2; }
     247             :         iterator2_type& second() { return pImpl->maIter2; }
     248             :     };
     249             : }
     250             : 
     251             : /** Provide the composition of two 1D image iterators
     252             : 
     253             :     Use this template to compose two iterators into one (e.g. image
     254             :     and mask). Operations are transitive, e.g. operator== only returns
     255             :     true, if both wrapped iterator operator== have yielded true.
     256             : 
     257             :     Note that both iterators must have compatible difference types. To
     258             :     avoid funny effects, iterator ranges given by a CompositeIterator
     259             :     should consist of wrapped iterators of similar range
     260             :  */
     261             : template< typename Iterator1,
     262             :           typename Iterator2,
     263             :           typename ValueType,
     264             :           typename DifferenceType,
     265             :           typename IteratorCategory >
     266  2373995379 : class CompositeIterator1D :
     267             :     public detail::CompositeIteratorBase< Iterator1,
     268             :                                           Iterator2,
     269             :                                           ValueType,
     270             :                                           DifferenceType,
     271             :                                           IteratorCategory,
     272             :                                           CompositeIterator1D<Iterator1,
     273             :                                                               Iterator2,
     274             :                                                               ValueType,
     275             :                                                               DifferenceType,
     276             :                                                               IteratorCategory> >
     277             : {
     278             :     typedef detail::CompositeIteratorBase< Iterator1,
     279             :                                            Iterator2,
     280             :                                            ValueType,
     281             :                                            DifferenceType,
     282             :                                            IteratorCategory,
     283             :                                            CompositeIterator1D<Iterator1,
     284             :                                                                Iterator2,
     285             :                                                                ValueType,
     286             :                                                                DifferenceType,
     287             :                                                                IteratorCategory> > base_type;
     288             : public:
     289             :     CompositeIterator1D() :
     290             :         base_type()
     291             :     {}
     292             : 
     293     6545620 :     CompositeIterator1D( const Iterator1& rIter1,
     294             :                          const Iterator2& rIter2 ) :
     295     6545620 :         base_type( rIter1, rIter2 )
     296     6545620 :     {}
     297             : };
     298             : 
     299             : /** Provide the composition of two 2D image iterators
     300             : 
     301             :     Use this template to compose two iterators into one (e.g. image
     302             :     and mask). Operations are transitive, e.g. operator== only returns
     303             :     true, if both wrapped iterator operator== have yielded true.
     304             : 
     305             :     Note that both iterators must have compatible difference types. To
     306             :     avoid funny effects, iterator ranges given by a CompositeIterator
     307             :     should consist of wrapped iterators of similar range
     308             :  */
     309      554452 : template< typename Iterator1, typename Iterator2 > class CompositeIterator2D :
     310             :     public detail::CompositeIteratorBase< Iterator1,
     311             :                                           Iterator2,
     312             :                                           std::pair<
     313             :                                                 typename vigra::IteratorTraits<Iterator1>::value_type,
     314             :                                                 typename vigra::IteratorTraits<Iterator2>::value_type >,
     315             :                                           typename vigra::IteratorTraits<Iterator1>::difference_type,
     316             :                                           typename vigra::IteratorTraits<Iterator1>::iterator_category,
     317             :                                           CompositeIterator2D<Iterator1, Iterator2> >
     318             : {
     319             :     typedef detail::CompositeIteratorBase< Iterator1,
     320             :                                            Iterator2,
     321             :                                            std::pair<
     322             :                                                 typename vigra::IteratorTraits<Iterator1>::value_type,
     323             :                                                 typename vigra::IteratorTraits<Iterator2>::value_type >,
     324             :                                            typename vigra::IteratorTraits<Iterator1>::difference_type,
     325             :                                            typename vigra::IteratorTraits<Iterator1>::iterator_category,
     326             :                                            CompositeIterator2D<Iterator1, Iterator2> > base_type;
     327             : public:
     328             :     typedef CompositeIterator1D< typename Iterator1::row_iterator,
     329             :                                  typename Iterator2::row_iterator,
     330             :                                  typename base_type::value_type,
     331             :                                  int,
     332             :                                  typename base_type::iterator_category >  row_iterator;
     333             :     typedef CompositeIterator1D< typename Iterator1::column_iterator,
     334             :                                  typename Iterator2::column_iterator,
     335             :                                  typename base_type::value_type,
     336             :                                  int,
     337             :                                  typename base_type::iterator_category >  column_iterator;
     338             : 
     339             :     typedef detail::ArithmeticProxy< typename Iterator1::MoveX,
     340             :                                      typename Iterator2::MoveX >            MoveX;
     341             :     typedef detail::ArithmeticProxy< typename Iterator1::MoveY,
     342             :                                      typename Iterator2::MoveY >            MoveY;
     343             : 
     344             :     MoveX x;
     345             :     MoveY y;
     346             : 
     347             :     CompositeIterator2D() :
     348             :         base_type(),
     349             :         x(this->pImpl->maIter1.x,this->pImpl->maIter2.x),
     350             :         y(this->pImpl->maIter1.y,this->pImpl->maIter2.y)
     351             :     {}
     352             : 
     353      168618 :     CompositeIterator2D( const Iterator1& rIter1, const Iterator2& rIter2 ) :
     354             :         base_type( rIter1, rIter2 ),
     355             :         x(this->pImpl->maIter1.x,this->pImpl->maIter2.x),
     356      168618 :         y(this->pImpl->maIter1.y,this->pImpl->maIter2.y)
     357      168618 :     {}
     358             : 
     359      385834 :     CompositeIterator2D( const CompositeIterator2D& rOld ) :
     360             :         base_type(rOld),
     361             :         x(this->pImpl->maIter1.x,this->pImpl->maIter2.x),
     362      385834 :         y(this->pImpl->maIter1.y,this->pImpl->maIter2.y)
     363      385834 :     {}
     364             : 
     365             :     CompositeIterator2D& operator=( const CompositeIterator2D& rNew )
     366             :     {
     367             :         this->pImpl->maIter1 = rNew.pImpl->maIter1;
     368             :         this->pImpl->maIter2 = rNew.pImpl->maIter2;
     369             : 
     370             :         x = MoveX(this->pImpl->maIter1.x,
     371             :                   this->pImpl->maIter2.x);
     372             :         y = MoveY(this->pImpl->maIter1.y,
     373             :                   this->pImpl->maIter2.y);
     374             : 
     375             :         return *this;
     376             :     }
     377             : 
     378     6495382 :     row_iterator rowIterator() const
     379             :     {
     380             :         return row_iterator(this->pImpl->maIter1.rowIterator(),
     381     6495382 :                             this->pImpl->maIter2.rowIterator());
     382             :     }
     383             : 
     384       50238 :     column_iterator columnIterator() const
     385             :     {
     386             :         return column_iterator(this->pImpl->maIter1.columnIterator(),
     387       50238 :                                this->pImpl->maIter2.columnIterator());
     388             :     }
     389             : };
     390             : 
     391             : } // namespace basebmp
     392             : 
     393             : #endif /* INCLUDED_BASEBMP_COMPOSITEITERATOR_HXX */
     394             : 
     395             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11