LCOV - code coverage report
Current view: top level - api - maptermlist.h (source / functions) Hit Total Coverage
Test: Test Coverage for xapian-core r Lines: 21 28 75.0 %
Date: 2011-08-21 Functions: 9 12 75.0 %
Branches: 3 12 25.0 %

           Branch data     Line data    Source code
       1                 :            : /* maptermlist.h
       2                 :            :  *
       3                 :            :  * Copyright 1999,2000,2001 BrightStation PLC
       4                 :            :  * Copyright 2002,2003,2004,2005,2006,2007,2008,2010 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 OM_HGUARD_MAPTERMLIST_H
      23                 :            : #define OM_HGUARD_MAPTERMLIST_H
      24                 :            : 
      25                 :            : #include "termlist.h"
      26                 :            : 
      27                 :            : #include "inmemory_positionlist.h"
      28                 :            : #include "document.h"
      29                 :            : 
      30                 :            : #include "omassert.h"
      31                 :            : 
      32                 :            : using namespace std;
      33                 :            : 
      34 [ +  - ][ #  # ]:     345898 : class MapTermList : public TermList {
      35                 :            :     private:
      36                 :            :         Xapian::Document::Internal::document_terms::const_iterator it;
      37                 :            :         Xapian::Document::Internal::document_terms::const_iterator it_end;
      38                 :            :         bool started;
      39                 :            : 
      40                 :            :     public:
      41                 :     345898 :         MapTermList(const Xapian::Document::Internal::document_terms::const_iterator &it_,
      42                 :            :                     const Xapian::Document::Internal::document_terms::const_iterator &it_end_)
      43                 :     345898 :                 : it(it_), it_end(it_end_), started(false)
      44                 :     345898 :         { }
      45                 :            : 
      46                 :            :         // Gets size of termlist
      47                 :          0 :         Xapian::termcount get_approx_size() const {
      48                 :            :             // This method shouldn't get called on a MapTermList.
      49                 :            :             Assert(false);
      50                 :          0 :             return 0;
      51                 :            :         }
      52                 :            : 
      53                 :            :         // Gets current termname
      54                 :   12957930 :         string get_termname() const {
      55                 :            :             Assert(started);
      56                 :            :             Assert(!at_end());
      57                 :   12957930 :             return it->first;
      58                 :            :         }
      59                 :            : 
      60                 :            :         // Get wdf of current term
      61                 :    9423700 :         Xapian::termcount get_wdf() const {
      62                 :            :             Assert(started);
      63                 :            :             Assert(!at_end());
      64                 :    9423700 :             return it->second.wdf;
      65                 :            :         }
      66                 :            : 
      67                 :            :         // Get num of docs indexed by term
      68                 :         18 :         Xapian::doccount get_termfreq() const {
      69                 :         18 :             throw Xapian::InvalidOperationError("Can't get term frequency from a document termlist which is not associated with a database.");
      70                 :            :         }
      71                 :            : 
      72                 :    4435711 :         Xapian::PositionIterator positionlist_begin() const {
      73                 :    4435711 :             return Xapian::PositionIterator(new InMemoryPositionList(it->second.positions));
      74                 :            :         }
      75                 :            : 
      76                 :    1308657 :         Xapian::termcount positionlist_count() const {
      77                 :    1308657 :             return it->second.positions.size();
      78                 :            :         }
      79                 :            : 
      80                 :    7113540 :         TermList * next() {
      81         [ +  + ]:    7113540 :             if (!started) {
      82                 :     345898 :                 started = true;
      83                 :            :             } else {
      84                 :            :                 Assert(!at_end());
      85                 :    6767642 :                 it++;
      86                 :            :             }
      87                 :    7113540 :             return NULL;
      88                 :            :         }
      89                 :            : 
      90                 :          0 :         TermList * skip_to(const std::string & term) {
      91 [ #  # ][ #  # ]:          0 :             while (it != it_end && it->first < term) {
                 [ #  # ]
      92                 :          0 :                 ++it;
      93                 :            :             }
      94                 :          0 :             started = true;
      95                 :          0 :             return NULL;
      96                 :            :         }
      97                 :            : 
      98                 :            :         // True if we're off the end of the list
      99                 :    7113540 :         bool at_end() const {
     100                 :            :             Assert(started);
     101                 :    7113540 :             return it == it_end;
     102                 :            :         }
     103                 :            : };
     104                 :            : 
     105                 :            : #endif /* OM_HGUARD_MAPTERMLIST_H */

Generated by: LCOV version 1.8