LCOV - code coverage report
Current view: top level - include/xapian - termiterator.h (source / functions) Hit Total Coverage
Test: Test Coverage for xapian-core 954b5873a738 Lines: 25 25 100.0 %
Date: 2019-06-30 05:20:33 Functions: 8 8 100.0 %
Branches: 7 10 70.0 %

           Branch data     Line data    Source code
       1                 :            : /** @file  termiterator.h
       2                 :            :  *  @brief Class for iterating over a list of terms
       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_TERMITERATOR_H
      23                 :            : #define XAPIAN_INCLUDED_TERMITERATOR_H
      24                 :            : 
      25                 :            : #if !defined XAPIAN_IN_XAPIAN_H && !defined XAPIAN_LIB_BUILD
      26                 :            : # error "Never use <xapian/termiterator.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 TermIterator {
      42                 :            :   public:
      43                 :            :     /// Class representing the TermIterator 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 TermIterator(Internal *internal_);
      51                 :            : 
      52                 :            :     /// Copy constructor.
      53                 :            :     TermIterator(const TermIterator & o);
      54                 :            : 
      55                 :            :     /// Assignment.
      56                 :            :     TermIterator & operator=(const TermIterator & o);
      57                 :            : 
      58                 :            :     /// Move constructor.
      59                 :          1 :     TermIterator(TermIterator && o)
      60                 :          1 :         : internal(o.internal) {
      61                 :          1 :         o.internal = nullptr;
      62                 :          1 :     }
      63                 :            : 
      64                 :            :     /// Move assignment operator.
      65                 :     162041 :     TermIterator & operator=(TermIterator && o) {
      66         [ +  - ]:     162041 :         if (this != &o) {
      67         [ +  + ]:     162041 :             if (internal) decref();
      68                 :     162041 :             internal = o.internal;
      69                 :     162041 :             o.internal = nullptr;
      70                 :            :         }
      71                 :     162041 :         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                 :    7449219 :     XAPIAN_NOTHROW(TermIterator())
      80                 :    7449219 :         : internal(0) { }
      81                 :            : 
      82                 :            :     /// Destructor.
      83                 :    8344701 :     ~TermIterator() {
      84         [ +  + ]:    8344701 :         if (internal) decref();
      85                 :    8344701 :     }
      86                 :            : 
      87                 :            :     /// Return the term at the current position.
      88                 :            :     std::string operator*() const;
      89                 :            : 
      90                 :            :     /// Return the wdf for the term at the current position.
      91                 :            :     Xapian::termcount get_wdf() const;
      92                 :            : 
      93                 :            :     /// Return the term frequency for the term at the current position.
      94                 :            :     Xapian::doccount get_termfreq() const;
      95                 :            : 
      96                 :            :     /// Return the length of the position list for the current position.
      97                 :            :     Xapian::termcount positionlist_count() const;
      98                 :            : 
      99                 :            :     /// Return a PositionIterator for the current term.
     100                 :            :     PositionIterator positionlist_begin() const;
     101                 :            : 
     102                 :            :     /// Return an end PositionIterator for the current term.
     103                 :    4635174 :     PositionIterator XAPIAN_NOTHROW(positionlist_end() const) {
     104                 :    4635174 :         return PositionIterator();
     105                 :            :     }
     106                 :            : 
     107                 :            :     /// Advance the iterator to the next position.
     108                 :            :     TermIterator & operator++();
     109                 :            : 
     110                 :            :     /// Advance the iterator to the next position (postfix version).
     111                 :        404 :     DerefWrapper_<std::string> operator++(int) {
     112                 :        404 :         const std::string & term(**this);
     113         [ +  - ]:        404 :         operator++();
     114         [ +  - ]:        404 :         return DerefWrapper_<std::string>(term);
     115                 :            :     }
     116                 :            : 
     117                 :            :     /** Advance the iterator to term @a term.
     118                 :            :      *
     119                 :            :      *  If the iteration is over an unsorted list of terms, then this method
     120                 :            :      *  will throw Xapian::InvalidOperationError.
     121                 :            :      *
     122                 :            :      *  @param term     The term to advance to.  If this term isn't in
     123                 :            :      *                  the stream being iterated, then the iterator is moved
     124                 :            :      *                  to the next term after it which is.
     125                 :            :      */
     126                 :            :     void skip_to(const std::string &term);
     127                 :            : 
     128                 :            :     /// Return a string describing this object.
     129                 :            :     std::string get_description() const;
     130                 :            : 
     131                 :            :     /** @private @internal TermIterator is what the C++ STL calls an
     132                 :            :      *  input_iterator.
     133                 :            :      *
     134                 :            :      *  The following typedefs allow std::iterator_traits<> to work so that
     135                 :            :      *  this iterator can be used with the STL.
     136                 :            :      *
     137                 :            :      *  These are deliberately hidden from the Doxygen-generated docs, as the
     138                 :            :      *  machinery here isn't interesting to API users.  They just need to know
     139                 :            :      *  that Xapian iterator classes are compatible with the STL.
     140                 :            :      */
     141                 :            :     // @{
     142                 :            :     /// @private
     143                 :            :     typedef std::input_iterator_tag iterator_category;
     144                 :            :     /// @private
     145                 :            :     typedef std::string value_type;
     146                 :            :     /// @private
     147                 :            :     typedef Xapian::termcount_diff difference_type;
     148                 :            :     /// @private
     149                 :            :     typedef std::string * pointer;
     150                 :            :     /// @private
     151                 :            :     typedef std::string & reference;
     152                 :            :     // @}
     153                 :            : 
     154                 :            :   private:
     155                 :            :     void decref();
     156                 :            : 
     157                 :            :     XAPIAN_VISIBILITY_INTERNAL
     158                 :            :     void post_advance(Internal * res);
     159                 :            : };
     160                 :            : 
     161                 :            : bool
     162                 :            : XAPIAN_NOTHROW(operator==(const TermIterator &a, const TermIterator &b));
     163                 :            : 
     164                 :            : /// Equality test for TermIterator objects.
     165                 :            : inline bool
     166                 :    7242573 : operator==(const TermIterator &a, const TermIterator &b) XAPIAN_NOEXCEPT
     167                 :            : {
     168                 :            :     // Use a pointer comparison - this ensures both that (a == a) and correct
     169                 :            :     // handling of end iterators (which we ensure have NULL internals).
     170                 :    7242573 :     return a.internal == b.internal;
     171                 :            : }
     172                 :            : 
     173                 :            : bool
     174                 :            : XAPIAN_NOTHROW(operator!=(const TermIterator &a, const TermIterator &b));
     175                 :            : 
     176                 :            : /// Inequality test for TermIterator objects.
     177                 :            : inline bool
     178                 :    6928808 : operator!=(const TermIterator &a, const TermIterator &b) XAPIAN_NOEXCEPT
     179                 :            : {
     180                 :    6928808 :     return !(a == b);
     181                 :            : }
     182                 :            : 
     183                 :            : }
     184                 :            : 
     185                 :            : #endif // XAPIAN_INCLUDED_TERMITERATOR_H

Generated by: LCOV version 1.11