Website now in git not CVS
[xapian.git] / xapian-core / api / documentvaluelist.cc
blob661d91298ee850e359f80dad93149bdc5d22ee75
1 /** @file documentvaluelist.cc
2 * @brief Iteration over values in a document.
3 */
4 /* Copyright (C) 2008,2009,2011,2013 Olly Betts
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.
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.
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
21 #include <config.h>
23 #include "documentvaluelist.h"
25 #include "backends/document.h"
26 #include "omassert.h"
27 #include "str.h"
28 #include "unicode/description_append.h"
30 #include "xapian/error.h"
32 using namespace std;
34 Xapian::docid
35 DocumentValueList::get_docid() const
37 throw Xapian::InvalidOperationError("get_docid() isn't valid when iterating over values in a document");
40 Xapian::valueno
41 DocumentValueList::get_valueno() const
43 Assert(!at_end());
44 return it->first;
47 string
48 DocumentValueList::get_value() const
50 Assert(!at_end());
51 return it->second;
54 bool
55 DocumentValueList::at_end() const
57 return it == doc->values.end();
60 void
61 DocumentValueList::next()
63 if (it == doc->values.end()) {
64 it = doc->values.begin();
65 } else {
66 ++it;
70 void
71 DocumentValueList::skip_to(Xapian::docid slot)
73 it = doc->values.lower_bound(slot);
76 string
77 DocumentValueList::get_description() const
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)";
89 return desc;