aboutsummaryrefslogtreecommitdiffstats
path: root/searchlib/src/vespa/searchlib/test/mock_attribute_context.cpp
blob: ccf44e49cdefbe0abb2c8682e926389a25ad3fe1 (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
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.

#include "mock_attribute_context.h"

namespace search::attribute::test {

const IAttributeVector *
MockAttributeContext::get(const string &name) const {
    if (_vectors.find(name) == _vectors.end()) {
        return 0;
    }
    return _vectors.find(name)->second;
}
const IAttributeVector *
MockAttributeContext::getAttribute(const string &name) const {
    return get(name);
}
const IAttributeVector *
MockAttributeContext::getAttributeStableEnum(const string &name) const {
    return get(name);
}
void
MockAttributeContext::getAttributeList(std::vector<const IAttributeVector *> & list) const {
    for (const auto& elem : _vectors) {
        list.push_back(elem.second);
    }
}
MockAttributeContext::~MockAttributeContext() {
    for (auto& elem : _vectors) {
        delete elem.second;
    }
}

void
MockAttributeContext::add(IAttributeVector *attr) {
    _vectors[attr->getName()] = attr;
}

void
MockAttributeContext::asyncForAttribute(const vespalib::string &, std::unique_ptr<IAttributeFunctor>) const {
    throw std::runtime_error("MockAttributeContext::asyncForAttribute is not implemented and should not be reached");
}

}