xapian-core  2.0.0
inmemory_document.cc
Go to the documentation of this file.
1 
4 /* Copyright (C) 2008,2009,2016 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, see
18  * <https://www.gnu.org/licenses/>.
19  */
20 
21 #include <config.h>
22 
23 #include "inmemory_document.h"
24 
25 #include "inmemory_database.h"
26 
27 #include "debuglog.h"
28 
29 using namespace std;
30 
31 string
33 {
34  LOGCALL(DB, string, "InMemoryDocument::fetch_value", slot);
35  const InMemoryDatabase * db;
36  db = static_cast<const InMemoryDatabase*>(database.get());
37  if (rare(did > db->valuelists.size()))
38  RETURN(string());
39  const auto& values_ = db->valuelists[did - 1];
40  auto i = values_.find(slot);
41  if (i == values_.end())
42  RETURN(string());
43  RETURN(i->second);
44 }
45 
46 void
47 InMemoryDocument::fetch_all_values(map<Xapian::valueno, string> &values_) const
48 {
49  LOGCALL_VOID(DB, "InMemoryDocument::fetch_all_values", values_);
50  const InMemoryDatabase * db;
51  db = static_cast<const InMemoryDatabase*>(database.get());
53  if (rare(did > db->valuelists.size())) {
54  values_.clear();
55  return;
56  }
57  values_ = db->valuelists[did - 1];
58 }
59 
60 string
62 {
63  LOGCALL(DB, string, "InMemoryDocument::fetch_data", NO_ARGS);
64  const InMemoryDatabase * db;
65  db = static_cast<const InMemoryDatabase*>(database.get());
67  if (rare(did > db->valuelists.size()))
68  RETURN(string());
69  RETURN(db->doclists[did - 1]);
70 }
A database held entirely in memory.
static void throw_database_closed()
std::vector< std::string > doclists
std::vector< std::map< Xapian::valueno, std::string > > valuelists
std::string fetch_value(Xapian::valueno slot) const
Implementation of virtual methods.
void fetch_all_values(std::map< Xapian::valueno, std::string > &values_) const
Implementation of virtual methods.
std::string fetch_data() const
Implementation of virtual methods.
#define rare(COND)
Definition: config.h:607
Debug logging macros.
#define RETURN(...)
Definition: debuglog.h:484
#define LOGCALL(CATEGORY, TYPE, FUNC, PARAMS)
Definition: debuglog.h:478
#define LOGCALL_VOID(CATEGORY, FUNC, PARAMS)
Definition: debuglog.h:479
C++ class definition for inmemory database access.
A document read from a InMemoryDatabase.
unsigned valueno
The number for a value slot in a document.
Definition: types.h:90