LCOV - code coverage report
Current view: top level - include/xapian - positioniterator.h (source / functions) Hit Total Coverage
Test: Test Coverage for xapian-core 7822d31adece Lines: 23 23 100.0 %
Date: 2019-05-23 11:15:29 Functions: 7 7 100.0 %
Branches: 7 10 70.0 %

           Branch data     Line data    Source code
       1                 :            : /** @file  positioniterator.h
       2                 :            :  *  @brief Class for iterating over term positions.
       3                 :            :  */
       4                 :            : /* Copyright (C) 2008,2009,2010,2011,2012,2013,2014,2015 Olly Betts
       5                 :            :  *
       6                 :            :  * This program is free software; you can redistribute it and/or
       7                 :            :  * modify it under the terms of the GNU General Public License as
       8                 :            :  * published by the Free Software Foundation; either version 2 of the
       9                 :            :  * License, or (at your option) any later version.
      10                 :            :  *
      11                 :            :  * This program is distributed in the hope that it will be useful,
      12                 :            :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      13                 :            :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      14                 :            :  * GNU General Public License for more details.
      15                 :            :  *
      16                 :            :  * You should have received a copy of the GNU General Public License
      17                 :            :  * along with this program; if not, write to the Free Software
      18                 :            :  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301
      19                 :            :  * USA
      20                 :            :  */
      21                 :            : 
      22                 :            : #ifndef XAPIAN_INCLUDED_POSITIONITERATOR_H
      23                 :            : #define XAPIAN_INCLUDED_POSITIONITERATOR_H
      24                 :            : 
      25                 :            : #if !defined XAPIAN_IN_XAPIAN_H && !defined XAPIAN_LIB_BUILD
      26                 :            : # error "Never use <xapian/positioniterator.h> directly; include <xapian.h> instead."
      27                 :            : #endif
      28                 :            : 
      29                 :            : #include <iterator>
      30                 :            : #include <string>
      31                 :            : 
      32                 :            : #include <xapian/attributes.h>
      33                 :            : #include <xapian/derefwrapper.h>
      34                 :            : #include <xapian/types.h>
      35                 :            : #include <xapian/visibility.h>
      36                 :            : 
      37                 :            : namespace Xapian {
      38                 :            : 
      39                 :            : /// Class for iterating over term positions.
      40                 :            : class XAPIAN_VISIBILITY_DEFAULT PositionIterator {
      41                 :            :     void decref();
      42                 :            : 
      43                 :            :   public:
      44                 :            :     /// Class representing the PositionIterator internals.
      45                 :            :     class Internal;
      46                 :            :     /// @private @internal Reference counted internals.
      47                 :            :     Internal * internal;
      48                 :            : 
      49                 :            :     /// @private @internal Wrap an existing Internal.
      50                 :            :     XAPIAN_VISIBILITY_INTERNAL
      51                 :            :     explicit PositionIterator(Internal *internal_);
      52                 :            : 
      53                 :            :     /// Copy constructor.
      54                 :            :     PositionIterator(const PositionIterator & o);
      55                 :            : 
      56                 :            :     /// Assignment.
      57                 :            :     PositionIterator & operator=(const PositionIterator & o);
      58                 :            : 
      59                 :            :     /// Move constructor.
      60                 :          1 :     PositionIterator(PositionIterator && o)
      61                 :          1 :         : internal(o.internal) {
      62                 :          1 :         o.internal = nullptr;
      63                 :          1 :     }
      64                 :            : 
      65                 :            :     /// Move assignment operator.
      66                 :     522070 :     PositionIterator & operator=(PositionIterator && o) {
      67         [ +  - ]:     522070 :         if (this != &o) {
      68         [ +  + ]:     522070 :             if (internal) decref();
      69                 :     522070 :             internal = o.internal;
      70                 :     522070 :             o.internal = nullptr;
      71                 :            :         }
      72                 :     522070 :         return *this;
      73                 :            :     }
      74                 :            : 
      75                 :            :     /** Default constructor.
      76                 :            :      *
      77                 :            :      *  Creates an uninitialised iterator, which can't be used before being
      78                 :            :      *  assigned to, but is sometimes syntactically convenient.
      79                 :            :      */
      80                 :    5162462 :     XAPIAN_NOTHROW(PositionIterator())
      81                 :    5162462 :         : internal(0) { }
      82                 :            : 
      83                 :            :     /// Destructor.
      84                 :    6846397 :     ~PositionIterator() {
      85         [ +  + ]:    6846397 :         if (internal) decref();
      86                 :    6846397 :     }
      87                 :            : 
      88                 :            :     /// Return the term position at the current iterator position.
      89                 :            :     Xapian::termpos operator*() const;
      90                 :            : 
      91                 :            :     /// Advance the iterator to the next position.
      92                 :            :     PositionIterator & operator++();
      93                 :            : 
      94                 :            :     /// Advance the iterator to the next position (postfix version).
      95                 :         90 :     DerefWrapper_<Xapian::termpos> operator++(int) {
      96         [ +  - ]:         90 :         Xapian::termpos pos(**this);
      97         [ +  - ]:         90 :         operator++();
      98                 :         90 :         return DerefWrapper_<Xapian::termpos>(pos);
      99                 :            :     }
     100                 :            : 
     101                 :            :     /** Advance the iterator to term position @a termpos.
     102                 :            :      *
     103                 :            :      *  @param termpos  The position to advance to.  If this position isn't in
     104                 :            :      *                  the stream being iterated, then the iterator is moved
     105                 :            :      *                  to the next term position after it which is.
     106                 :            :      */
     107                 :            :     void skip_to(Xapian::termpos termpos);
     108                 :            : 
     109                 :            :     /// Return a string describing this object.
     110                 :            :     std::string get_description() const;
     111                 :            : 
     112                 :            :     /** @private @internal PositionIterator is what the C++ STL calls an
     113                 :            :      *  input_iterator.
     114                 :            :      *
     115                 :            :      *  The following typedefs allow std::iterator_traits<> to work so that
     116                 :            :      *  this iterator can be used with the STL.
     117                 :            :      *
     118                 :            :      *  These are deliberately hidden from the Doxygen-generated docs, as the
     119                 :            :      *  machinery here isn't interesting to API users.  They just need to know
     120                 :            :      *  that Xapian iterator classes are compatible with the STL.
     121                 :            :      */
     122                 :            :     // @{
     123                 :            :     /// @private
     124                 :            :     typedef std::input_iterator_tag iterator_category;
     125                 :            :     /// @private
     126                 :            :     typedef Xapian::termpos value_type;
     127                 :            :     /// @private
     128                 :            :     typedef Xapian::termpos_diff difference_type;
     129                 :            :     /// @private
     130                 :            :     typedef Xapian::termpos * pointer;
     131                 :            :     /// @private
     132                 :            :     typedef Xapian::termpos & reference;
     133                 :            :     // @}
     134                 :            : };
     135                 :            : 
     136                 :            : bool
     137                 :            : XAPIAN_NOTHROW(operator==(const PositionIterator &a, const PositionIterator &b));
     138                 :            : 
     139                 :            : /// Equality test for PositionIterator objects.
     140                 :            : inline bool
     141                 :    4715480 : operator==(const PositionIterator &a, const PositionIterator &b) XAPIAN_NOEXCEPT
     142                 :            : {
     143                 :            :     // Use a pointer comparison - this ensures both that (a == a) and correct
     144                 :            :     // handling of end iterators (which we ensure have NULL internals).
     145                 :    4715480 :     return a.internal == b.internal;
     146                 :            : }
     147                 :            : 
     148                 :            : bool
     149                 :            : XAPIAN_NOTHROW(operator!=(const PositionIterator &a, const PositionIterator &b));
     150                 :            : 
     151                 :            : /// Inequality test for PositionIterator objects.
     152                 :            : inline bool
     153                 :    3630959 : operator!=(const PositionIterator &a, const PositionIterator &b) XAPIAN_NOEXCEPT
     154                 :            : {
     155                 :    3630959 :     return !(a == b);
     156                 :            : }
     157                 :            : 
     158                 :            : }
     159                 :            : 
     160                 :            : #endif // XAPIAN_INCLUDED_POSITIONITERATOR_H

Generated by: LCOV version 1.11