xapian-core  1.4.25
documentvaluelist.cc
Go to the documentation of this file.
1 
4 /* Copyright (C) 2008,2009,2011,2013 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, 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 "documentvaluelist.h"
24 
25 #include "backends/document.h"
26 #include "omassert.h"
27 #include "str.h"
29 
30 #include "xapian/error.h"
31 
32 using namespace std;
33 
36 {
37  throw Xapian::InvalidOperationError("get_docid() isn't valid when iterating over values in a document");
38 }
39 
42 {
43  Assert(!at_end());
44  return it->first;
45 }
46 
47 string
49 {
50  Assert(!at_end());
51  return it->second;
52 }
53 
54 bool
56 {
57  return it == doc->values.end();
58 }
59 
60 void
62 {
63  if (it == doc->values.end()) {
64  it = doc->values.begin();
65  } else {
66  ++it;
67  }
68 }
69 
70 void
72 {
73  it = doc->values.lower_bound(slot);
74 }
75 
76 string
78 {
79  string desc = "DocumentValueList(";
80  if (!at_end()) {
81  desc += "slot=";
82  desc += str(get_valueno());
83  desc += ", value=\"";
84  description_append(desc, get_value());
85  desc += "\")";
86  } else {
87  desc += "atend)";
88  }
89  return desc;
90 }
#define Assert(COND)
Definition: omassert.h:122
Xapian::docid get_docid() const
Return the docid at the current position.
bool at_end() const
Return true if the current position is past the last entry in this list.
InvalidOperationError indicates the API was used in an invalid way.
Definition: error.h:283
void next()
Advance the current position to the next document in the value stream.
STL namespace.
Convert types to std::string.
std::string get_value() const
Return the value at the current position.
Xapian::valueno get_valueno() const
Return the value slot for the current position/this iterator.
Hierarchy of classes which Xapian can throw as exceptions.
void skip_to(Xapian::docid slot)
The parameter is actually a Xapian::valueno for this subclass.
void description_append(std::string &desc, const std::string &s)
Definition: unittest.cc:102
Iteration over values in a document.
string str(int value)
Convert int to std::string.
Definition: str.cc:90
std::string get_description() const
Return a string description of this object.
Append a string to an object description, escaping invalid UTF-8.
unsigned valueno
The number for a value slot in a document.
Definition: types.h:108
Various assertion macros.
unsigned XAPIAN_DOCID_BASE_TYPE docid
A unique identifier for a document.
Definition: types.h:52