LCOV - code coverage report
Current view: top level - backends/flint - flint_metadata.cc (source / functions) Hit Total Coverage
Test: Test Coverage for xapian-core r Lines: 21 25 84.0 %
Date: 2011-08-21 Functions: 6 11 54.5 %
Branches: 15 26 57.7 %

           Branch data     Line data    Source code
       1                 :            : /** @file flint_metadata.cc
       2                 :            :  * @brief Access to metadata for a flint database.
       3                 :            :  */
       4                 :            : /* Copyright (C) 2004,2005,2006,2007,2008 Olly Betts
       5                 :            :  * Copyright (C) 2008 Lemur Consulting Ltd
       6                 :            :  *
       7                 :            :  * This program is free software; you can redistribute it and/or modify
       8                 :            :  * it under the terms of the GNU General Public License as published by
       9                 :            :  * the Free Software Foundation; either version 2 of the License, or
      10                 :            :  * (at your option) any later version.
      11                 :            :  *
      12                 :            :  * This program is distributed in the hope that it will be useful,
      13                 :            :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      14                 :            :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      15                 :            :  * GNU General Public License for more details.
      16                 :            :  *
      17                 :            :  * You should have received a copy of the GNU General Public License
      18                 :            :  * along with this program; if not, write to the Free Software
      19                 :            :  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
      20                 :            :  */
      21                 :            : 
      22                 :            : #include <config.h>
      23                 :            : #include "flint_metadata.h"
      24                 :            : 
      25                 :            : #include "database.h"
      26                 :            : #include "debuglog.h"
      27                 :            : #include "omassert.h"
      28                 :            : #include "stringutils.h"
      29                 :            : 
      30                 :            : using namespace std;
      31                 :            : 
      32                 :         24 : FlintMetadataTermList::FlintMetadataTermList(
      33                 :            :         Xapian::Internal::RefCntPtr<const Xapian::Database::Internal> database_,
      34                 :            :         FlintCursor * cursor_,
      35                 :            :         const string &prefix_)
      36                 :         24 :         : database(database_), cursor(cursor_), prefix(string("\x00\xc0", 2) + prefix_)
      37                 :            : {
      38                 :            :     LOGCALL_CTOR(DB, "FlintMetadataTermList", database_ | cursor_ | prefix_);
      39                 :            :     Assert(cursor);
      40                 :            :     // Seek to the first key before the first metadata key.
      41                 :         24 :     cursor->find_entry_lt(prefix);
      42                 :         24 : }
      43                 :            : 
      44                 :         24 : FlintMetadataTermList::~FlintMetadataTermList()
      45                 :            : {
      46                 :            :     LOGCALL_DTOR(DB, "FlintMetadataTermList");
      47 [ +  - ][ #  # ]:         24 :     delete cursor;
                 [ #  # ]
      48 [ +  - ][ #  # ]:         24 : }
                 [ #  # ]
      49                 :            : 
      50                 :            : string
      51                 :         50 : FlintMetadataTermList::get_termname() const
      52                 :            : {
      53                 :            :     LOGCALL(DB, string, "FlintMetadataTermList::get_termname", NO_ARGS);
      54                 :            :     Assert(!at_end());
      55                 :            :     Assert(!cursor->current_key.empty());
      56                 :            :     Assert(startswith(cursor->current_key, prefix));
      57                 :         50 :     RETURN(cursor->current_key.substr(2));
      58                 :            : }
      59                 :            : 
      60                 :            : Xapian::doccount
      61                 :          0 : FlintMetadataTermList::get_termfreq() const
      62                 :            : {
      63                 :          0 :     throw Xapian::InvalidOperationError("FlintMetadataTermList::get_termfreq() not meaningful");
      64                 :            : }
      65                 :            : 
      66                 :            : Xapian::termcount
      67                 :          0 : FlintMetadataTermList::get_collection_freq() const
      68                 :            : {
      69                 :          0 :     throw Xapian::InvalidOperationError("FlintMetadataTermList::get_collection_freq() not meaningful");
      70                 :            : }
      71                 :            : 
      72                 :            : TermList *
      73                 :         68 : FlintMetadataTermList::next()
      74                 :            : {
      75                 :            :     LOGCALL(DB, TermList *, "FlintMetadataTermList::next", NO_ARGS);
      76                 :            :     Assert(!at_end());
      77                 :            : 
      78                 :         68 :     cursor->next();
      79   [ +  +  +  + ]:         68 :     if (!cursor->after_end() && !startswith(cursor->current_key, prefix)) {
                 [ +  + ]
      80                 :            :         // We've reached the end of the end of the prefixed terms.
      81                 :         17 :         cursor->to_end();
      82                 :            :     }
      83                 :            : 
      84                 :         68 :     RETURN(NULL);
      85                 :            : }
      86                 :            : 
      87                 :            : TermList *
      88                 :          6 : FlintMetadataTermList::skip_to(const string &key)
      89                 :            : {
      90                 :            :     LOGCALL(DB, TermList *, "FlintMetadataTermList::skip_to", key);
      91                 :            :     Assert(!at_end());
      92                 :            : 
      93         [ +  + ]:          6 :     if (!cursor->find_entry_ge(string("\x00\xc0", 2) + key)) {
      94                 :            :         // The exact term we asked for isn't there, so check if the next
      95                 :            :         // term after it also has the right prefix.
      96 [ +  - ][ +  + ]:          2 :         if (!cursor->after_end() && !startswith(cursor->current_key, prefix)) {
                 [ +  + ]
      97                 :            :             // We've reached the end of the prefixed terms.
      98                 :          1 :             cursor->to_end();
      99                 :            :         }
     100                 :            :     }
     101                 :          6 :     RETURN(NULL);
     102                 :            : }
     103                 :            : 
     104                 :            : bool
     105                 :         74 : FlintMetadataTermList::at_end() const
     106                 :            : {
     107                 :            :     LOGCALL(DB, bool, "FlintMetadataTermList::at_end", NO_ARGS);
     108                 :         74 :     RETURN(cursor->after_end());
     109                 :            : }

Generated by: LCOV version 1.8