LCOV - code coverage report
Current view: top level - api - ompostlistiterator.cc (source / functions) Hit Total Coverage
Test: Test Coverage for xapian-core r Lines: 41 42 97.6 %
Date: 2011-08-21 Functions: 12 16 75.0 %
Branches: 13 22 59.1 %

           Branch data     Line data    Source code
       1                 :            : /* ompostlistiterator.cc
       2                 :            :  *
       3                 :            :  * Copyright 1999,2000,2001 BrightStation PLC
       4                 :            :  * Copyright 2003,2004,2005,2008,2009 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                 :            : #include <config.h>
      23                 :            : #include <xapian/postingiterator.h>
      24                 :            : #include <xapian/positioniterator.h>
      25                 :            : #include "postlist.h"
      26                 :            : #include "debuglog.h"
      27                 :            : #include "omassert.h"
      28                 :            : 
      29                 :            : using namespace std;
      30                 :            : 
      31                 :     111006 : Xapian::PostingIterator::PostingIterator(Internal *internal_)
      32                 :     111006 :         : internal(internal_)
      33                 :            : {
      34   [ +  +  #  # ]:     111006 :     if (internal.get()) {
      35                 :            :         // A PostList starts before the start, iterators start at the start
      36                 :       5245 :         Internal *p = internal->next();
      37   [ -  +  #  # ]:       5245 :         if (p) internal = p; // handle prune
      38 [ +  + ][ #  # ]:       5245 :         if (internal->at_end()) internal = 0;
      39                 :            :     }
      40                 :     111006 : }
      41                 :            : 
      42                 :       1800 : Xapian::PostingIterator::PostingIterator() : internal(0) {
      43                 :            :     LOGCALL_VOID(API, "Xapian::PostingIterator::PostingIterator", NO_ARGS);
      44                 :       1800 : }
      45                 :            : 
      46                 :     112911 : Xapian::PostingIterator::~PostingIterator() {
      47                 :            :     LOGCALL_VOID(API, "Xapian::PostingIterator::~PostingIterator", NO_ARGS);
      48                 :     112911 : }
      49                 :            : 
      50                 :        105 : Xapian::PostingIterator::PostingIterator(const Xapian::PostingIterator &other)
      51                 :        105 :     : internal(other.internal)
      52                 :            : {
      53                 :            :     LOGCALL_VOID(API, "Xapian::PostingIterator::Xapian::PostingIterator", other);
      54                 :        105 : }
      55                 :            : 
      56                 :            : void
      57                 :        915 : Xapian::PostingIterator::operator=(const Xapian::PostingIterator &other)
      58                 :            : {
      59                 :            :     LOGCALL_VOID(API, "Xapian::PostingIterator::operator=", other);
      60                 :        915 :     internal = other.internal;
      61                 :        915 : }
      62                 :            : 
      63                 :            : Xapian::docid
      64                 :     156364 : Xapian::PostingIterator::operator *() const
      65                 :            : {
      66                 :            :     LOGCALL(API, Xapian::docid, "Xapian::PostingIterator::operator*", NO_ARGS);
      67                 :            :     Assert(internal.get());
      68                 :            :     Assert(!internal->at_end());
      69                 :     156364 :     RETURN(internal->get_docid());
      70                 :            : }
      71                 :            : 
      72                 :            : Xapian::PostingIterator &
      73                 :     120603 : Xapian::PostingIterator::operator++()
      74                 :            : {
      75                 :            :     LOGCALL_VOID(API, "Xapian::PostingIterator::operator++", NO_ARGS);
      76                 :            :     Assert(internal.get());
      77                 :            :     Assert(!internal->at_end());
      78                 :     120603 :     Internal *p = internal->next();
      79         [ -  + ]:     120602 :     if (p) internal = p; // handle prune
      80         [ +  + ]:     120602 :     if (internal->at_end()) internal = 0;
      81                 :     120602 :     return *this;
      82                 :            : }
      83                 :            : 
      84                 :            : // extra method, not required to be an input_iterator
      85                 :            : void
      86                 :        697 : Xapian::PostingIterator::skip_to(Xapian::docid did)
      87                 :            : {
      88                 :            :     LOGCALL_VOID(API, "Xapian::PostingIterator::skip_to", did);
      89                 :            :     Assert(internal.get());
      90                 :            :     Assert(!internal->at_end());
      91                 :        697 :     PostList *p = internal->skip_to(did, 0);
      92         [ -  + ]:        697 :     if (p) internal = p; // handle prune
      93         [ +  + ]:        697 :     if (internal->at_end()) internal = 0;
      94                 :        697 : }    
      95                 :            : 
      96                 :            : Xapian::termcount
      97                 :      34818 : Xapian::PostingIterator::get_doclength() const
      98                 :            : {
      99                 :            :     LOGCALL(API, Xapian::termcount, "Xapian::PostingIterator::get_doclength", NO_ARGS);
     100                 :            :     Assert(internal.get());
     101                 :            :     Assert(!internal->at_end());
     102                 :      34818 :     RETURN(internal->get_doclength());
     103                 :            : }
     104                 :            : 
     105                 :            : Xapian::termcount
     106                 :     155380 : Xapian::PostingIterator::get_wdf() const
     107                 :            : {
     108                 :            :     LOGCALL(API, Xapian::termcount, "Xapian::PostingIterator::get_wdf", NO_ARGS);
     109                 :            :     Assert(internal.get());
     110                 :            :     Assert(!internal->at_end());
     111                 :     155380 :     RETURN(internal->get_wdf());
     112                 :            : }
     113                 :            : 
     114                 :            : Xapian::PositionIterator
     115                 :      34471 : Xapian::PostingIterator::positionlist_begin() const
     116                 :            : {
     117                 :            :     LOGCALL(API, Xapian::PositionIterator, "Xapian::PostingIterator::positionlist_begin", NO_ARGS);
     118                 :            :     Assert(internal.get());
     119                 :            :     Assert(!internal->at_end());
     120                 :      34471 :     RETURN(Xapian::PositionIterator(internal->open_position_list()));
     121                 :            : }
     122                 :            : 
     123                 :            : string
     124                 :         66 : Xapian::PostingIterator::get_description() const
     125                 :            : {
     126                 :         66 :     string desc = "Xapian::PostingIterator(pos=";
     127         [ +  + ]:         66 :     if (internal.get() == 0) {
     128                 :         27 :         desc += "END";
     129                 :            :     } else {
     130                 :         39 :         desc += internal->get_description();
     131                 :            :     }
     132                 :         66 :     desc += ")";
     133                 :          0 :     return desc;
     134                 :            : }

Generated by: LCOV version 1.8