aboutsummaryrefslogtreecommitdiffstats
path: root/searchlib/src/vespa/searchlib/index/postinglistparams.cpp
blob: 27f2d60d4201ed26b8b6b4f9cd8de5f75f2ab54f (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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.

#include "postinglistparams.h"
#include <sstream>

namespace {

vespalib::string empty;

}

namespace search::index {

bool
PostingListParams::isSet(const vespalib::string &key) const
{
    auto it = _map.find(key);
    if (it != _map.end()) {
        return true;
    }
    return false;
}

void
PostingListParams::setStr(const vespalib::string &key,
                          const vespalib::string &val)
{
    _map[key] = val;
}

const vespalib::string &
PostingListParams::getStr(const vespalib::string &key) const
{
    auto it = _map.find(key);
    if (it != _map.end()) {
        return it->second;
    }
    return empty;
}

void
PostingListParams::clear()
{
    _map.clear();
}

void
PostingListParams::add(const PostingListParams & toAdd)
{
    _map.insert(toAdd._map.begin(), toAdd._map.end());
}

void
PostingListParams::erase(const vespalib::string &key)
{
    _map.erase(key);
}

bool
PostingListParams::operator!=(const PostingListParams &rhs) const
{
    return _map != rhs._map;
}

template <typename TYPE>
void
PostingListParams::set(const vespalib::string &key, const TYPE &val)
{
    std::ostringstream os;

    os << val;
    _map[key] = os.str();
}

template <typename TYPE>
void
PostingListParams::get(const vespalib::string &key, TYPE &val) const
{
    std::istringstream is;
    auto it = _map.find(key);
    if (it != _map.end()) {
        is.str(it->second);
        is >> val;
    }
}

template void
PostingListParams::set<bool>(const vespalib::string &key, const bool &val);

template void
PostingListParams::get<bool>(const vespalib::string &key, bool &val) const;

template void
PostingListParams::set<int32_t>(const vespalib::string &key, const int32_t &val);

template void
PostingListParams::get<int32_t>(const vespalib::string &key, int32_t &val) const;

template void
PostingListParams::set<uint32_t>(const vespalib::string &key, const uint32_t &val);

template void
PostingListParams::get<uint32_t>(const vespalib::string &key, uint32_t &val) const;

template void
PostingListParams::set<uint64_t>(const vespalib::string &key, const uint64_t &val);

template void
PostingListParams::get<uint64_t>(const vespalib::string &key, uint64_t &val) const;

}