summaryrefslogtreecommitdiff
path: root/src/db.cc
blob: b1efc216d73d1af0ad7dbf22800e3d9ce79143f2 (plain)
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
#include "common.hh"

#include "db.hh"

namespace stuff {

DB::Value::Value(const std::string& value)
    : type_(DB::Type::STRING), string_(value) {
}

DB::Value::Value(int32_t value)
    : type_(DB::Type::INT32) {
    data_.i32 = value;
}

DB::Value::Value(int64_t value)
    : type_(DB::Type::INT64) {
    data_.i64 = value;
}

DB::Value::Value(bool value)
    : type_(DB::Type::BOOL) {
    data_.b = value;
}

DB::Value::Value(double value)
    : type_(DB::Type::DOUBLE) {
    data_.d = value;
}

DB::Value::Value(std::nullptr_t)
    : type_(DB::Type::RAW) {
}

const std::string& DB::Value::string() const {
    assert(type_ == DB::Type::STRING);
    return string_;
}

int32_t DB::Value::i32() const {
    assert(type_ == DB::Type::INT32);
    return data_.i32;
}

int64_t DB::Value::i64() const {
    assert(type_ == DB::Type::INT64);
    return data_.i64;
}

bool DB::Value::b() const {
    assert(type_ == DB::Type::BOOL);
    return data_.b;
}

double DB::Value::d() const {
    assert(type_ == DB::Type::DOUBLE);
    return data_.d;
}

}  // namespace stuff