blob: 90b4b1711f16ce96cf5e297a4474aa9168b03170 (
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
|
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#include "boolfieldvalue.h"
#include <vespa/document/datatype/datatype.h>
#include <vespa/vespalib/util/xmlstream.h>
#include <ostream>
using namespace vespalib::xml;
namespace document {
BoolFieldValue::BoolFieldValue(bool value)
: FieldValue(Type::BOOL), _value(value) {
}
BoolFieldValue::~BoolFieldValue() = default;
FieldValue &
BoolFieldValue::assign(const FieldValue &rhs) {
if (rhs.isA(Type::BOOL)) {
operator=(static_cast<const BoolFieldValue &>(rhs));
return *this;
} else {
return FieldValue::assign(rhs);
}
}
int
BoolFieldValue::compare(const FieldValue&rhs) const {
int diff = FieldValue::compare(rhs);
if (diff != 0) return diff;
const BoolFieldValue &o = static_cast<const BoolFieldValue &>(rhs);
return (_value == o._value) ? 0 : _value ? 1 : -1;
}
void
BoolFieldValue::printXml(XmlOutputStream& out) const {
out << XmlContent(getAsString());
}
void
BoolFieldValue::print(std::ostream& out, bool, const std::string&) const {
out << (_value ? "true" : "false") << "\n";
}
const DataType *
BoolFieldValue::getDataType() const {
return DataType::BOOL;
}
FieldValue *
BoolFieldValue::clone() const {
return new BoolFieldValue(*this);
}
char
BoolFieldValue::getAsByte() const {
return _value ? 1 : 0;
}
int32_t
BoolFieldValue::getAsInt() const {
return _value ? 1 : 0;
}
int64_t
BoolFieldValue::getAsLong() const {
return _value ? 1 : 0;
}
float
BoolFieldValue::getAsFloat() const {
return _value ? 1 : 0;
}
double
BoolFieldValue::getAsDouble() const {
return _value ? 1 : 0;
}
vespalib::string
BoolFieldValue::getAsString() const {
return _value ? "true" : "false";
}
BoolFieldValue&
BoolFieldValue::operator=(vespalib::stringref v) {
_value = (v == "true");
return *this;
}
} // namespace document
|