xapian-core  1.4.27
valuestreamdocument.cc
Go to the documentation of this file.
1 
4 /* Copyright (C) 2009,2011,2014 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 #include <config.h>
22 
23 #include "valuestreamdocument.h"
24 #include "omassert.h"
25 
26 using namespace std;
27 
28 static void
29 clear_valuelists(map<Xapian::valueno, ValueList *> & valuelists)
30 {
31  map<Xapian::valueno, ValueList *>::const_iterator i;
32  for (i = valuelists.begin(); i != valuelists.end(); ++i) {
33  delete i->second;
34  }
35  valuelists.clear();
36 }
37 
39 {
40  delete doc;
41  clear_valuelists(valuelists);
42 }
43 
44 void
46 {
47  AssertRel(n,>,0);
48  AssertRel(size_t(n),<,db.internal.size());
49  current = unsigned(n);
50  database = db.internal[n];
51  clear_valuelists(valuelists);
52 }
53 
54 string
56 {
57 #ifdef XAPIAN_ASSERTIONS_PARANOID
58  if (!doc) {
59  doc = database->open_document(did, true);
60  }
61 #endif
62 
63  pair<map<Xapian::valueno, ValueList *>::iterator, bool> ret;
64  ret = valuelists.insert(make_pair(slot, static_cast<ValueList*>(NULL)));
65  ValueList * vl;
66  if (ret.second) {
67  // Entry didn't already exist, so open a value list for slot.
68  vl = database->open_value_list(slot);
69  ret.first->second = vl;
70  } else {
71  vl = ret.first->second;
72  if (!vl) {
73  AssertEqParanoid(string(), doc->get_value(slot));
74  return string();
75  }
76  }
77 
78  if (vl->check(did)) {
79  if (vl->at_end()) {
80  delete vl;
81  ret.first->second = NULL;
82  } else if (vl->get_docid() == did) {
83  Assert(vl);
84  string v = vl->get_value();
85  AssertEq(v, doc->get_value(slot));
86  return v;
87  }
88  }
89  AssertEqParanoid(string(), doc->get_value(slot));
90  return string();
91 }
92 
93 void
94 ValueStreamDocument::do_get_all_values(map<Xapian::valueno, string> & v) const
95 {
96  if (!doc) {
97  doc = database->open_document(did, true);
98  }
99  doc->do_get_all_values(v);
100 }
101 
102 string
104 {
105  if (!doc) {
106  doc = database->open_document(did, true);
107  }
108  return doc->do_get_data();
109 }
#define Assert(COND)
Definition: omassert.h:122
#define AssertEq(A, B)
Definition: omassert.h:124
virtual bool at_end() const =0
Return true if the current position is past the last entry in this list.
#define AssertRel(A, REL, B)
Definition: omassert.h:123
STL namespace.
static void clear_valuelists(map< Xapian::valueno, ValueList *> &valuelists)
std::string do_get_value(Xapian::valueno slot) const
Implementation of virtual methods.
virtual Xapian::docid get_docid() const =0
Return the docid at the current position.
A document which gets its values from a ValueStreamManager.
Abstract base class for value streams.
Definition: valuelist.h:31
#define AssertEqParanoid(A, B)
Definition: omassert.h:131
std::string do_get_data() const
Implementation of virtual methods.
virtual std::string get_value() const =0
Return the value at the current position.
unsigned valueno
The number for a value slot in a document.
Definition: types.h:108
virtual bool check(Xapian::docid did)
Check if the specified docid occurs in this valuestream.
Definition: valuelist.cc:30
Various assertion macros.
void do_get_all_values(std::map< Xapian::valueno, std::string > &values_) const
Implementation of virtual methods.