LCOV - code coverage report
Current view: top level - include/xapian - postingiterator.h (source / functions) Hit Total Coverage
Test: Test Coverage for xapian-core 4ba52dacf4fb Lines: 25 25 100.0 %
Date: 2019-05-20 14:58:19 Functions: 8 8 100.0 %
Branches: 7 10 70.0 %

           Branch data     Line data    Source code
       1                 :            : /** @file  postingiterator.h
       2                 :            :  *  @brief Class for iterating over a list of document ids
       3                 :            :  */
       4                 :            : /* Copyright (C) 2007,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_POSTINGITERATOR_H
      23                 :            : #define XAPIAN_INCLUDED_POSTINGITERATOR_H
      24                 :            : 
      25                 :            : #if !defined XAPIAN_IN_XAPIAN_H && !defined XAPIAN_LIB_BUILD
      26                 :            : # error "Never use <xapian/postingiterator.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/positioniterator.h>
      35                 :            : #include <xapian/types.h>
      36                 :            : #include <xapian/visibility.h>
      37                 :            : 
      38                 :            : namespace Xapian {
      39                 :            : 
      40                 :            : /// Class for iterating over a list of terms.
      41                 :            : class XAPIAN_VISIBILITY_DEFAULT PostingIterator {
      42                 :            :   public:
      43                 :            :     /// Class representing the PostingIterator internals.
      44                 :            :     class Internal;
      45                 :            :     /// @private @internal Reference counted internals.
      46                 :            :     Internal * internal;
      47                 :            : 
      48                 :            :     /// @private @internal Wrap an existing Internal.
      49                 :            :     XAPIAN_VISIBILITY_INTERNAL
      50                 :            :     explicit PostingIterator(Internal *internal_);
      51                 :            : 
      52                 :            :     /// Copy constructor.
      53                 :            :     PostingIterator(const PostingIterator & o);
      54                 :            : 
      55                 :            :     /// Assignment.
      56                 :            :     PostingIterator & operator=(const PostingIterator & o);
      57                 :            : 
      58                 :            :     /// Move constructor.
      59                 :        225 :     PostingIterator(PostingIterator && o)
      60                 :        225 :         : internal(o.internal) {
      61                 :        225 :         o.internal = nullptr;
      62                 :        225 :     }
      63                 :            : 
      64                 :            :     /// Move assignment operator.
      65                 :       1448 :     PostingIterator & operator=(PostingIterator && o) {
      66         [ +  - ]:       1448 :         if (this != &o) {
      67         [ +  + ]:       1448 :             if (internal) decref();
      68                 :       1448 :             internal = o.internal;
      69                 :       1448 :             o.internal = nullptr;
      70                 :            :         }
      71                 :       1448 :         return *this;
      72                 :            :     }
      73                 :            : 
      74                 :            :     /** Default constructor.
      75                 :            :      *
      76                 :            :      *  Creates an uninitialised iterator, which can't be used before being
      77                 :            :      *  assigned to, but is sometimes syntactically convenient.
      78                 :            :      */
      79                 :      73321 :     XAPIAN_NOTHROW(PostingIterator())
      80                 :      73321 :         : internal(0) { }
      81                 :            : 
      82                 :            :     /// Destructor.
      83                 :      78953 :     ~PostingIterator() {
      84         [ +  + ]:      78953 :         if (internal) decref();
      85                 :      78953 :     }
      86                 :            : 
      87                 :            :     /// Return the document id at the current position.
      88                 :            :     Xapian::docid operator*() const;
      89                 :            : 
      90                 :            :     /// Return the wdf for the document at the current position.
      91                 :            :     Xapian::termcount get_wdf() const;
      92                 :            : 
      93                 :            :     /// Return the length of the document at the current position.
      94                 :            :     Xapian::termcount get_doclength() const;
      95                 :            : 
      96                 :            :     /// Return the number of unique terms in the current document.
      97                 :            :     Xapian::termcount get_unique_terms() const;
      98                 :            : 
      99                 :            : #if 0 // FIXME: TermIterator supports this, so PostingIterator really ought to.
     100                 :            :     /// Return the length of the position list for the current position.
     101                 :            :     Xapian::termcount positionlist_count() const;
     102                 :            : #endif
     103                 :            : 
     104                 :            :     /// Return a PositionIterator for the current document.
     105                 :            :     PositionIterator positionlist_begin() const;
     106                 :            : 
     107                 :            :     /// Return an end PositionIterator for the current document.
     108                 :      24892 :     PositionIterator XAPIAN_NOTHROW(positionlist_end() const) {
     109                 :      24892 :         return PositionIterator();
     110                 :            :     }
     111                 :            : 
     112                 :            :     /// Advance the iterator to the next position.
     113                 :            :     PostingIterator & operator++();
     114                 :            : 
     115                 :            :     /// Advance the iterator to the next position (postfix version).
     116                 :      18408 :     DerefWrapper_<Xapian::docid> operator++(int) {
     117         [ +  - ]:      18408 :         Xapian::docid did(**this);
     118         [ +  - ]:      18408 :         operator++();
     119                 :      18408 :         return DerefWrapper_<Xapian::docid>(did);
     120                 :            :     }
     121                 :            : 
     122                 :            :     /** Advance the iterator to document @a did.
     123                 :            :      *
     124                 :            :      *  @param did      The document id to advance to.  If this document id
     125                 :            :      *                  isn't in the stream being iterated, then the iterator
     126                 :            :      *                  is moved to the next document id after it which is.
     127                 :            :      */
     128                 :            :     void skip_to(Xapian::docid did);
     129                 :            : 
     130                 :            :     /// Return a string describing this object.
     131                 :            :     std::string get_description() const;
     132                 :            : 
     133                 :            :     /** @private @internal PostingIterator is what the C++ STL calls an
     134                 :            :      *  input_iterator.
     135                 :            :      *
     136                 :            :      *  The following typedefs allow std::iterator_traits<> to work so that
     137                 :            :      *  this iterator can be used with the STL.
     138                 :            :      *
     139                 :            :      *  These are deliberately hidden from the Doxygen-generated docs, as the
     140                 :            :      *  machinery here isn't interesting to API users.  They just need to know
     141                 :            :      *  that Xapian iterator classes are compatible with the STL.
     142                 :            :      */
     143                 :            :     // @{
     144                 :            :     /// @private
     145                 :            :     typedef std::input_iterator_tag iterator_category;
     146                 :            :     /// @private
     147                 :            :     typedef Xapian::docid value_type;
     148                 :            :     /// @private
     149                 :            :     typedef Xapian::doccount_diff difference_type;
     150                 :            :     /// @private
     151                 :            :     typedef Xapian::docid * pointer;
     152                 :            :     /// @private
     153                 :            :     typedef Xapian::docid & reference;
     154                 :            :     // @}
     155                 :            : 
     156                 :            :   private:
     157                 :            :     void decref();
     158                 :            : 
     159                 :            :     XAPIAN_VISIBILITY_INTERNAL
     160                 :            :     void post_advance(Internal * res);
     161                 :            : };
     162                 :            : 
     163                 :            : bool
     164                 :            : XAPIAN_NOTHROW(operator==(const PostingIterator &a, const PostingIterator &b));
     165                 :            : 
     166                 :            : /// Equality test for PostingIterator objects.
     167                 :            : inline bool
     168                 :      77573 : operator==(const PostingIterator &a, const PostingIterator &b) XAPIAN_NOEXCEPT
     169                 :            : {
     170                 :            :     // Use a pointer comparison - this ensures both that (a == a) and correct
     171                 :            :     // handling of end iterators (which we ensure have NULL internals).
     172                 :      77573 :     return a.internal == b.internal;
     173                 :            : }
     174                 :            : 
     175                 :            : inline bool
     176                 :            : XAPIAN_NOTHROW(operator!=(const PostingIterator &a, const PostingIterator &b));
     177                 :            : 
     178                 :            : /// Inequality test for PostingIterator objects.
     179                 :            : inline bool
     180                 :      76872 : operator!=(const PostingIterator &a, const PostingIterator &b) XAPIAN_NOEXCEPT
     181                 :            : {
     182                 :      76872 :     return !(a == b);
     183                 :            : }
     184                 :            : 
     185                 :            : }
     186                 :            : 
     187                 :            : #endif // XAPIAN_INCLUDED_POSTINGITERATOR_H

Generated by: LCOV version 1.11