aboutsummaryrefslogtreecommitdiffstats
path: root/searchcore/src/vespa/searchcore/proton/common/selectcontext.cpp
blob: 726feb5949f181e5643bd792fccc789ada1be3eb (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
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.

#include "selectcontext.h"
#include "cachedselect.h"
#include <vespa/document/select/value.h>
#include <vespa/searchlib/attribute/attribute_read_guard.h>
#include <vespa/searchlib/attribute/readable_attribute_vector.h>
#include <cassert>

namespace proton {

using document::select::Value;
using document::select::Context;
using search::AttributeVector;
using search::attribute::AttributeReadGuard;

namespace select {
struct Guards : public std::vector<std::unique_ptr<AttributeReadGuard>> {
    using Parent = std::vector<std::unique_ptr<AttributeReadGuard>>;
    using Parent::Parent;
};
}

SelectContext::SelectContext(const CachedSelect &cachedSelect)
    : Context(),
      _docId(0u),
      _guards(std::make_unique<select::Guards>(cachedSelect.attributes().size())),
      _cachedSelect(cachedSelect)
{ }

SelectContext::~SelectContext() = default;

void
SelectContext::getAttributeGuards()
{
    _guards->clear();
    _guards->reserve(_cachedSelect.attributes().size());
    for (const auto& attr : _cachedSelect.attributes()) {
        _guards->emplace_back(attr->makeReadGuard(false));
    }
}

void
SelectContext::dropAttributeGuards()
{
    _guards->clear();
}

const search::attribute::IAttributeVector&
SelectContext::guarded_attribute_at_index(uint32_t index) const noexcept
{
    assert(index < _guards->size());
    assert((*_guards)[index].get() != nullptr);
    return *((*_guards)[index])->attribute();
}

}