blob: e09a7908b69fab193cf3e0dcaf89f49588c95459 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
|
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
/**
* @class document::select::Result
* @ingroup select
*
* @brief Represents a result of matching a document. Can be invalid.
*
* Using a bool to represent match or not proved inferior.
* 'music.artist < 10' should not match any documents as long as music.artist
* is a string field. However, we don't want 'not music.artist < 10' or
* 'music.artist > 10' to match all documents because of that. This type is
* thus used as it has 3 outcomes.. True, false & invalid.
*
* @author H�kon Humberset
*/
#pragma once
#include <vespa/vespalib/util/hdr_abort.h>
#include <vespa/document/util/printable.h>
#include <cstdint>
namespace document::select {
class Result : public Printable {
public:
static Result Invalid;
static Result False;
static Result True;
// Singletons are not copyable
Result(const Result&) = delete;
Result& operator=(const Result&) = delete;
void print(std::ostream& out, bool verbose, const std::string& indent) const override;
bool operator==(const Result& o) const { return (&o == this); }
bool operator!=(const Result& o) const { return (&o != this); }
const Result& operator&&(const Result&) const;
const Result& operator||(const Result&) const;
const Result& operator!() const;
static const Result& get(bool b) { return (b ? True : False); }
static constexpr uint32_t enumRange = 3u;
uint32_t toEnum() const {
if (this == &Result::Invalid)
return 0u;
if (this == &Result::False)
return 1u;
if (this == &Result::True)
return 2u;
HDR_ABORT("should not be reached");
}
static const Result &fromEnum(uint32_t val) {
if (val == 0u)
return Result::Invalid;
if (val == 1u)
return Result::False;
if (val == 2u)
return Result::True;
HDR_ABORT("should not be reached");
}
private:
Result();
};
}
|