LTP GCOV extension - code coverage report
Current view: | directory - usr/include/xapian - termiterator.h
Test: | lcov.info
Date: | 2008-08-14 |  | Instrumented lines: | 4
Code covered: | 100.0 % |  | Executed lines: | 4

           1                 : /** \file termiterator.h
           2                 :  * \brief Classes for iterating through term lists
           3                 :  */
           4                 : /* Copyright 1999,2000,2001 BrightStation PLC
           5                 :  * Copyright 2002 Ananova Ltd
           6                 :  * Copyright 2003,2004,2005,2006,2007 Olly Betts
           7                 :  *
           8                 :  * This program is free software; you can redistribute it and/or
           9                 :  * modify it under the terms of the GNU General Public License as
          10                 :  * published by the Free Software Foundation; either version 2 of the
          11                 :  * License, or (at your option) any later version.
          12                 :  *
          13                 :  * This program is distributed in the hope that it will be useful,
          14                 :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
          15                 :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
          16                 :  * GNU General Public License for more details.
          17                 :  *
          18                 :  * You should have received a copy of the GNU General Public License
          19                 :  * along with this program; if not, write to the Free Software
          20                 :  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301
          21                 :  * USA
          22                 :  */
          23                 :
          24                 : #ifndef XAPIAN_INCLUDED_TERMITERATOR_H
          25                 : #define XAPIAN_INCLUDED_TERMITERATOR_H
          26                 :
          27                 : #include <iterator>
          28                 : #include <string>
          29                 :
          30                 : #include <xapian/base.h>
          31                 : #include <xapian/types.h>
          32                 : #include <xapian/positioniterator.h>
          33                 : #include <xapian/visibility.h>
          34                 :
          35                 : namespace Xapian {
          36                 :
          37                 : class Database;
          38                 :
          39                 : /** @internal A wrapper class for a termname which returns the termname if
          40                 :  *  dereferenced with *.  We need this to implement input_iterator semantics.
          41                 :  */
          42                 : class TermNameWrapper {
          43                 :     private:
          44                 :         std::string tname;
          45                 :     public:
          46                 :         explicit TermNameWrapper(const std::string & tname_) : tname(tname_) { }
          47                 :         const std::string & operator*() const { return tname; }
          48                 : };
          49                 :
          50                 : /** An iterator pointing to items in a list of terms.
          51                 :  */
          52                 : class XAPIAN_VISIBILITY_DEFAULT TermIterator {
          53                 :     public:
          54                 :         class Internal;
          55                 :         /// @internal Reference counted internals.
          56                 :         Xapian::Internal::RefCntPtr<Internal> internal;
          57                 :
          58                 :         /// @internal Reference counted internals.
          59                 :         explicit TermIterator(Internal *internal_);
          60                 :
          61                 :         /// Default constructor - for declaring an uninitialised iterator.
          62                 :         TermIterator();
          63                 :
          64                 :         /// Destructor.
          65                 :         ~TermIterator();
          66                 :
          67                 :         /** Copying is allowed.  The internals are reference counted, so
          68                 :          *  copying is also cheap.
          69                 :          */
          70                 :         TermIterator(const TermIterator &other);
          71                 :
          72                 :         /** Assignment is allowed.  The internals are reference counted,
          73                 :          *  so assignment is also cheap.
          74                 :          */
          75                 :         void operator=(const TermIterator &other);
          76                 :
          77                 :         /// Return the current term.
          78                 :         std::string operator *() const;
          79                 :
          80                 :         TermIterator & operator++();
          81                 :
          82                 :         TermNameWrapper operator++(int) {
          83                 :             std::string tmp = **this;
          84                 :             operator++();
          85                 :             return TermNameWrapper(tmp);
          86                 :         }
          87                 :
          88                 :         /** Skip the iterator to term tname, or the first term after tname
          89                 :          *  if tname isn't in the list of terms being iterated.
          90                 :          */
          91                 :         void skip_to(const std::string & tname);
          92                 :
          93                 :         /** Return the wdf of the current term (if meaningful).
          94                 :          *
          95                 :          *  The wdf (within document frequency) is the number of occurences
          96                 :          *  of a term in a particular document.
          97                 :          */
          98                 :         Xapian::termcount get_wdf() const;
          99                 :
         100                 :         /** Return the term frequency of the current term (if meaningful).
         101                 :          *
         102                 :          *  The term frequency is the number of documents which a term indexes.
         103                 :          */
         104                 :         Xapian::doccount get_termfreq() const;
         105                 :
         106                 :         /** Return length of positionlist for current term.
         107                 :          */
         108                 :         Xapian::termcount positionlist_count() const;
         109                 :
         110                 :         /** Return PositionIterator pointing to start of positionlist for
         111                 :          *  current term.
         112                 :          */
         113                 :         PositionIterator positionlist_begin() const;
         114                 :
         115                 :         /** Return PositionIterator pointing to end of positionlist for
         116                 :          *  current term.
         117                 :          */
         118                 :         PositionIterator positionlist_end() const {
         119                 :             return PositionIterator(NULL);
         120                 :         }
         121                 :
         122                 :         /// Return a string describing this object.
         123                 :         std::string get_description() const;
         124                 :
         125                 :         /// Allow use as an STL iterator
         126                 :         //@{
         127                 :         typedef std::input_iterator_tag iterator_category;
         128                 :         typedef std::string value_type;
         129                 :         typedef Xapian::termcount_diff difference_type;
         130                 :         typedef std::string * pointer;
         131                 :         typedef std::string & reference;
         132                 :         //@}
         133                 : };
         134                 :
         135                 : inline bool
         136               5 : operator==(const TermIterator &a, const TermIterator &b)
         137                 : {
         138               5 :     return (a.internal.get() == b.internal.get());
         139                 : }
         140                 :
         141                 : inline bool
         142               5 : operator!=(const TermIterator &a, const TermIterator &b)
         143                 : {
         144               5 :     return !(a == b);
         145                 : }
         146                 :
         147                 : }
         148                 :
         149                 : #endif /* XAPIAN_INCLUDED_TERMITERATOR_H */

Generated by: LTP GCOV extension version 1.6