LCOV - code coverage report
Current view: top level - matcher - valuestreamdocument.h (source / functions) Hit Total Coverage
Test: Test Coverage for xapian-core c2b6f1024d3a Lines: 17 17 100.0 %
Date: 2019-05-16 09:13:18 Functions: 5 5 100.0 %
Branches: 9 12 75.0 %

           Branch data     Line data    Source code
       1                 :            : /** @file valuestreamdocument.h
       2                 :            :  * @brief A document which gets its values from a ValueStreamManager.
       3                 :            :  */
       4                 :            : /* Copyright (C) 2009,2011,2014,2017 Olly Betts
       5                 :            :  *
       6                 :            :  * This program is free software; you can redistribute it and/or modify
       7                 :            :  * it under the terms of the GNU General Public License as published by
       8                 :            :  * the Free Software Foundation; either version 2 of the License, or
       9                 :            :  * (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 USA
      19                 :            :  */
      20                 :            : 
      21                 :            : #ifndef XAPIAN_INCLUDED_VALUESTREAMDOCUMENT_H
      22                 :            : #define XAPIAN_INCLUDED_VALUESTREAMDOCUMENT_H
      23                 :            : 
      24                 :            : #include "backends/documentinternal.h"
      25                 :            : #include "backends/multi.h"
      26                 :            : #include "backends/multi/multi_database.h"
      27                 :            : #include "backends/valuelist.h"
      28                 :            : #include "omassert.h"
      29                 :            : #include "xapian/database.h"
      30                 :            : #include "xapian/types.h"
      31                 :            : 
      32                 :            : #include <map>
      33                 :            : 
      34                 :            : /// A document which gets its values from a ValueStreamManager.
      35                 :            : class ValueStreamDocument : public Xapian::Document::Internal {
      36                 :            :     /// Don't allow assignment.
      37                 :            :     void operator=(const ValueStreamDocument &);
      38                 :            : 
      39                 :            :     /// Don't allow copying.
      40                 :            :     ValueStreamDocument(const ValueStreamDocument &);
      41                 :            : 
      42                 :            :     mutable std::map<Xapian::valueno, ValueList *> valuelists;
      43                 :            : 
      44                 :            :     Xapian::Database db;
      45                 :            : 
      46                 :            :     size_t current = 0;
      47                 :            : 
      48                 :            :     size_t n_shards;
      49                 :            : 
      50                 :            :     mutable Xapian::Document::Internal * doc = NULL;
      51                 :            : 
      52                 :            :     /** Private constructor.
      53                 :            :      *
      54                 :            :      *  This is an implementation detail - the public constructor forwards to
      55                 :            :      *  this constructor so we can use n_shards_ to init our parent class.
      56                 :            :      */
      57                 :     149736 :     ValueStreamDocument(const Xapian::Database& db_, size_t n_shards_)
      58                 :            :         : Internal(n_shards_ == 1 ?
      59                 :     121216 :                    db_.internal.get() :
      60                 :      28520 :                    static_cast<MultiDatabase*>(db_.internal.get())->shards[0],
      61                 :            :                    0),
      62                 :            :           db(db_),
      63 [ +  + ][ +  - ]:     178256 :           n_shards(n_shards_) {}
         [ +  - ][ +  - ]
      64                 :            : 
      65                 :            :   public:
      66                 :     149736 :     explicit ValueStreamDocument(const Xapian::Database& db_)
      67                 :     149736 :         : ValueStreamDocument(db_, db_.internal->size()) {}
      68                 :            : 
      69                 :            :     void new_shard(size_t n);
      70                 :            : 
      71                 :            :     ~ValueStreamDocument();
      72                 :            : 
      73                 :   34353342 :     void set_shard_document(Xapian::docid shard_did) {
      74         [ +  + ]:   34353342 :         if (did != shard_did) {
      75                 :   34353195 :             did = shard_did;
      76         [ +  + ]:   34353195 :             delete doc;
      77                 :   34353195 :             doc = NULL;
      78                 :            :         }
      79                 :   34353342 :     }
      80                 :            : 
      81                 :   34347408 :     void set_document(Xapian::docid did_) {
      82                 :            :         AssertEq(current, shard_number(did_, n_shards));
      83                 :   34347408 :         set_shard_document(shard_docid(did_, n_shards));
      84                 :   34347408 :     }
      85                 :            : 
      86                 :            :     // Optimise away the virtual call when the matcher wants to know a value.
      87                 :      26012 :     std::string get_value(Xapian::valueno slot) const {
      88                 :      26012 :         return ValueStreamDocument::fetch_value(slot);
      89                 :            :     }
      90                 :            : 
      91                 :            :   protected:
      92                 :            :     /** Implementation of virtual methods @{ */
      93                 :            :     std::string fetch_value(Xapian::valueno slot) const;
      94                 :            :     void fetch_all_values(std::map<Xapian::valueno, std::string> & values_) const;
      95                 :            :     std::string fetch_data() const;
      96                 :            :     /** @} */
      97                 :            : };
      98                 :            : 
      99                 :            : #endif // XAPIAN_INCLUDED_VALUESTREAMDOCUMENT_H

Generated by: LCOV version 1.11