xapian-core  2.0.0
rset.cc
Go to the documentation of this file.
1 
4 /* Copyright (C) 2017 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  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, see
16  * <https://www.gnu.org/licenses/>.
17  */
18 
19 #include <config.h>
20 
21 #include <xapian/rset.h>
22 
23 #include "rsetinternal.h"
24 #include "str.h"
25 
26 #include <string>
27 
28 using namespace std;
29 
30 namespace Xapian {
31 
32 RSet::RSet(const RSet&) = default;
33 
34 RSet&
35 RSet::operator=(const RSet&) = default;
36 
37 RSet::RSet(RSet &&) = default;
38 
39 RSet&
40 RSet::operator=(RSet &&) = default;
41 
42 RSet::RSet() {}
43 
44 RSet::RSet(Internal* internal_) : internal(internal_) {}
45 
47 
49 RSet::size() const
50 {
51  return internal ? internal->docs.size() : 0;
52 }
53 
54 void
56 {
57  if (rare(did == 0))
58  throw Xapian::InvalidArgumentError("Docid 0 not valid in an RSet");
59  if (!internal)
60  internal = new RSet::Internal;
61  internal->docs.insert(did);
62 }
63 
64 void
66 {
67  if (rare(did == 0))
68  throw Xapian::InvalidArgumentError("Docid 0 not valid in an RSet");
69  if (internal)
70  internal->docs.erase(did);
71 }
72 
73 bool
75 {
76  return internal && internal->docs.find(did) != internal->docs.end();
77 }
78 
79 string
81 {
82  string desc = "RSet(";
83  if (!internal || internal->docs.empty()) {
84  desc += ')';
85  } else {
86  for (auto&& did : internal->docs) {
87  desc += str(did);
88  desc += ',';
89  }
90  desc.back() = ')';
91  }
92  return desc;
93 }
94 
95 }
InvalidArgumentError indicates an invalid parameter value was passed to the API.
Definition: error.h:229
std::set< Xapian::docid > docs
Definition: rsetinternal.h:36
Xapian::Internal::intrusive_ptr< Internal > internal
Definition: rset.h:42
void add_document(Xapian::docid did)
Mark a document as relevant.
Definition: rset.cc:55
~RSet()
Destructor.
Definition: rset.cc:46
void remove_document(Xapian::docid did)
Unmark a document as relevant.
Definition: rset.cc:65
Xapian::doccount size() const
Return number of documents in this RSet object.
Definition: rset.cc:49
bool contains(Xapian::docid did) const
Check if a document is marked as relevant.
Definition: rset.cc:74
std::string get_description() const
Return a string describing this object.
Definition: rset.cc:80
#define rare(COND)
Definition: config.h:607
string str(int value)
Convert int to std::string.
Definition: str.cc:91
The Xapian namespace contains public interfaces for the Xapian library.
Definition: compactor.cc:82
unsigned XAPIAN_DOCID_BASE_TYPE doccount
A count of documents.
Definition: types.h:37
unsigned XAPIAN_DOCID_BASE_TYPE docid
A unique identifier for a document.
Definition: types.h:51
Set of documents judged as relevant.
Set of documents judged as relevant.
Convert types to std::string.