[python3] Simplify generated wrapper post-processing
[xapian.git] / xapian-core / api / document.cc
blobce14b3b17c9d14495f26d9bf1eed32b848156873
1 /** @file document.cc
2 * @brief Class representing a document
3 */
4 /* Copyright 2008,2017 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 "xapian/document.h"
25 #include <string>
27 #include "backends/documentinternal.h"
28 #include "net/serialise.h"
29 #include "str.h"
31 #include "xapian/error.h"
33 using namespace std;
35 [[noreturn]]
36 static void
37 throw_invalid_arg_empty_term()
39 throw Xapian::InvalidArgumentError("Empty termnames are invalid");
42 namespace Xapian {
44 Document::Document(Document::Internal* internal_)
45 : internal(internal_)
49 Document::Document(const Document& o)
50 : internal(o.internal)
54 Document&
55 Document::operator=(const Document& o)
57 internal = o.internal;
58 return *this;
61 Document::Document() : internal(new Xapian::Document::Internal)
65 Document::~Document()
69 Xapian::docid
70 Document::get_docid() const
72 return internal->get_docid();
75 string
76 Document::get_data() const
78 return internal->get_data();
81 void
82 Document::set_data(const string& data)
84 internal->set_data(data);
87 void
88 Document::add_term(const string& term, Xapian::termcount wdf_inc)
90 if (term.empty()) {
91 throw_invalid_arg_empty_term();
93 internal->add_term(term, wdf_inc);
96 void
97 Document::remove_term(const string& term)
99 if (term.empty()) {
100 throw_invalid_arg_empty_term();
102 if (!internal->remove_term(term)) {
103 string m;
104 m = "Document::remove_term() failed - term '";
105 m += term;
106 m + "' not present";
107 throw Xapian::InvalidArgumentError(m);
111 void
112 Document::add_posting(const string& term,
113 Xapian::termpos term_pos,
114 Xapian::termcount wdf_inc)
116 if (term.empty()) {
117 throw_invalid_arg_empty_term();
119 internal->add_posting(term, term_pos, wdf_inc);
122 void
123 Document::remove_posting(const string& term,
124 Xapian::termpos term_pos,
125 Xapian::termcount wdf_dec)
127 if (term.empty()) {
128 throw_invalid_arg_empty_term();
130 auto res = internal->remove_posting(term, term_pos, wdf_dec);
131 if (res != Document::Internal::OK) {
132 string m = "Document::remove_posting() failed - term '";
133 m += term;
134 if (res == Document::Internal::NO_TERM) {
135 m += "' not present";
136 } else {
137 m += "' not present at position ";
138 m += str(term_pos);
140 throw Xapian::InvalidArgumentError(m);
144 void
145 Document::clear_terms()
147 internal->clear_terms();
150 Xapian::termcount
151 Document::termlist_count() const {
152 return internal->termlist_count();
155 TermIterator
156 Document::termlist_begin() const
158 return TermIterator(internal->open_term_list());
161 string
162 Document::get_value(Xapian::valueno slot) const
164 return internal->get_value(slot);
167 void
168 Document::add_value(Xapian::valueno slot, const string& value)
170 internal->add_value(slot, value);
173 void
174 Document::clear_values()
176 internal->clear_values();
179 Xapian::termcount
180 Document::values_count() const {
181 return internal->values_count();
184 ValueIterator
185 Document::values_begin() const
187 return internal->values_begin();
190 string
191 Document::serialise() const
193 return serialise_document(*this);
196 Document
197 Document::unserialise(const string& serialised)
199 return unserialise_document(serialised);
202 string
203 Document::get_description() const
205 return internal->get_description();