blob: 5ce2bb21530c32e0d0bd4dbcea4f2d752e688695 (
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
|
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#include "parameterdescriptions.h"
#include <cassert>
namespace search {
namespace fef {
ParameterDescriptions::Description::Description(size_t tag) :
_tag(tag),
_params(),
_repeat(0)
{ }
ParameterDescriptions::Description::~Description() { }
ParameterDescriptions::Description &
ParameterDescriptions::Description::addParameter(const ParamDescItem ¶m) {
_params.push_back(param);
return *this;
}
ParamDescItem
ParameterDescriptions::Description::getParam(size_t i) const
{
if (i < _params.size()) {
return _params[i];
}
size_t offset = (i - _params.size()) % _repeat;
size_t realIndex = _params.size() - _repeat + offset;
return _params[realIndex];
}
ParameterDescriptions::ParameterDescriptions() :
_descriptions(),
_nextTag(0)
{ }
ParameterDescriptions::~ParameterDescriptions() { }
ParameterDescriptions &
ParameterDescriptions::desc() {
_descriptions.push_back(Description(_nextTag++));
return *this;
}
ParameterDescriptions &
ParameterDescriptions::desc(size_t tag) {
_descriptions.push_back(Description(tag));
_nextTag = tag + 1;
return *this;
}
void
ParameterDescriptions::addParameter(const ParamDescItem ¶m) {
assert(!_descriptions.empty());
assert(!getCurrent().hasRepeat());
getCurrent().addParameter(param);
}
ParameterDescriptions &
ParameterDescriptions::repeat(size_t n) {
assert(!_descriptions.empty());
assert(getCurrent().getParams().size() >= n);
getCurrent().setRepeat(n);
return *this;
}
} // namespace fef
} // namespace search
|