LCOV - code coverage report
Current view: top level - backends/brass - brass_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 brass_metadata.cc
       2                 :            :  * @brief Access to metadata for a brass database.
       3                 :            :  */
       4                 :            : /* Copyright (C) 2004,2005,2006,2007,2008,2009,2010 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                 :            : 
      24                 :            : #include "brass_metadata.h"
      25                 :            : 
      26                 :            : #include "brass_cursor.h"
      27                 :            : 
      28                 :            : #include "database.h"
      29                 :            : #include "debuglog.h"
      30                 :            : #include "omassert.h"
      31                 :            : #include "stringutils.h"
      32                 :            : 
      33                 :            : #include "xapian/error.h"
      34                 :            : 
      35                 :            : using namespace std;
      36                 :            : 
      37                 :         24 : BrassMetadataTermList::BrassMetadataTermList(
      38                 :            :         Xapian::Internal::RefCntPtr<const Xapian::Database::Internal> database_,
      39                 :            :         BrassCursor * cursor_,
      40                 :            :         const string &prefix_)
      41                 :         24 :         : database(database_), cursor(cursor_), prefix(string("\x00\xc0", 2) + prefix_)
      42                 :            : {
      43                 :            :     LOGCALL_CTOR(DB, "BrassMetadataTermList", database_ | cursor_ | prefix_);
      44                 :            :     Assert(cursor);
      45                 :            :     // Seek to the first key before the first metadata key.
      46                 :         24 :     cursor->find_entry_lt(prefix);
      47                 :         24 : }
      48                 :            : 
      49                 :         24 : BrassMetadataTermList::~BrassMetadataTermList()
      50                 :            : {
      51                 :            :     LOGCALL_DTOR(DB, "BrassMetadataTermList");
      52 [ +  - ][ #  # ]:         24 :     delete cursor;
                 [ #  # ]
      53 [ +  - ][ #  # ]:         24 : }
                 [ #  # ]
      54                 :            : 
      55                 :            : string
      56                 :         50 : BrassMetadataTermList::get_termname() const
      57                 :            : {
      58                 :            :     LOGCALL(DB, string, "BrassMetadataTermList::get_termname", NO_ARGS);
      59                 :            :     Assert(!at_end());
      60                 :            :     Assert(!cursor->current_key.empty());
      61                 :            :     Assert(startswith(cursor->current_key, prefix));
      62                 :         50 :     RETURN(cursor->current_key.substr(2));
      63                 :            : }
      64                 :            : 
      65                 :            : Xapian::doccount
      66                 :          0 : BrassMetadataTermList::get_termfreq() const
      67                 :            : {
      68                 :          0 :     throw Xapian::InvalidOperationError("BrassMetadataTermList::get_termfreq() not meaningful");
      69                 :            : }
      70                 :            : 
      71                 :            : Xapian::termcount
      72                 :          0 : BrassMetadataTermList::get_collection_freq() const
      73                 :            : {
      74                 :          0 :     throw Xapian::InvalidOperationError("BrassMetadataTermList::get_collection_freq() not meaningful");
      75                 :            : }
      76                 :            : 
      77                 :            : TermList *
      78                 :         68 : BrassMetadataTermList::next()
      79                 :            : {
      80                 :            :     LOGCALL(DB, TermList *, "BrassMetadataTermList::next", NO_ARGS);
      81                 :            :     Assert(!at_end());
      82                 :            : 
      83                 :         68 :     cursor->next();
      84   [ +  +  +  + ]:         68 :     if (!cursor->after_end() && !startswith(cursor->current_key, prefix)) {
                 [ +  + ]
      85                 :            :         // We've reached the end of the end of the prefixed terms.
      86                 :         17 :         cursor->to_end();
      87                 :            :     }
      88                 :            : 
      89                 :         68 :     RETURN(NULL);
      90                 :            : }
      91                 :            : 
      92                 :            : TermList *
      93                 :          6 : BrassMetadataTermList::skip_to(const string &key)
      94                 :            : {
      95                 :            :     LOGCALL(DB, TermList *, "BrassMetadataTermList::skip_to", key);
      96                 :            :     Assert(!at_end());
      97                 :            : 
      98         [ +  + ]:          6 :     if (!cursor->find_entry_ge(string("\x00\xc0", 2) + key)) {
      99                 :            :         // The exact term we asked for isn't there, so check if the next
     100                 :            :         // term after it also has the right prefix.
     101 [ +  - ][ +  + ]:          2 :         if (!cursor->after_end() && !startswith(cursor->current_key, prefix)) {
                 [ +  + ]
     102                 :            :             // We've reached the end of the prefixed terms.
     103                 :          1 :             cursor->to_end();
     104                 :            :         }
     105                 :            :     }
     106                 :          6 :     RETURN(NULL);
     107                 :            : }
     108                 :            : 
     109                 :            : bool
     110                 :         74 : BrassMetadataTermList::at_end() const
     111                 :            : {
     112                 :            :     LOGCALL(DB, bool, "BrassMetadataTermList::at_end", NO_ARGS);
     113                 :         74 :     RETURN(cursor->after_end());
     114                 :            : }

Generated by: LCOV version 1.8