blob: a25f5c259e49794ca101f33c92e4bf5595b90708 (
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
|
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#include "routingspec.h"
#include <vespa/vespalib/util/stringfmt.h>
using vespalib::make_string;
namespace mbus {
RoutingSpec::RoutingSpec() noexcept = default;
RoutingSpec::RoutingSpec(const RoutingSpec &) = default;
RoutingSpec::RoutingSpec(RoutingSpec &&) noexcept = default;
RoutingSpec & RoutingSpec::operator=(RoutingSpec &&) noexcept = default;
RoutingSpec::~RoutingSpec() = default;
RoutingSpec &
RoutingSpec::addTable(RoutingTableSpec && table) & {
_tables.emplace_back(std::move(table));
return *this;
}
RoutingSpec &&
RoutingSpec::addTable(RoutingTableSpec && table) && {
_tables.emplace_back(std::move(table));
return std::move(*this);
}
string
RoutingSpec::toConfigString(const string &input)
{
string ret;
ret.append("\"");
for (char i : input) {
if (i == '\\') {
ret.append("\\\\");
} else if (i == '"') {
ret.append("\\\"");
} else if (i == '\n') {
ret.append("\\n");
} else if (i == 0) {
ret.append("\\x00");
} else {
ret += i;
}
}
ret.append("\"");
return ret;
}
void
RoutingSpec::toConfig(string &cfg, const string &prefix) const
{
uint32_t numTables = _tables.size();
if (numTables > 0) {
cfg.append(prefix).append("routingtable[").append(make_string("%d", numTables)).append("]\n");
for (uint32_t i = 0; i < numTables; ++i) {
_tables[i].toConfig(cfg, make_string("%sroutingtable[%d].", prefix.c_str(), i));
}
}
}
string
RoutingSpec::toString() const
{
string ret = "";
toConfig(ret, "");
return ret;
}
bool
RoutingSpec::operator==(const RoutingSpec &rhs) const
{
if (_tables.size() != rhs._tables.size()) {
return false;
}
for (uint32_t i = 0, len = _tables.size(); i < len; ++i) {
if (_tables[i] != rhs._tables[i]) {
return false;
}
}
return true;
}
} // namespace mbus
|