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

#include <vespa/searchcommon/attribute/iattributecontext.h>
#include <memory>
#include <map>

#pragma once

namespace search::fef::test {

class AttributeMap;

/**
 * Simple IAttributeContext implementation which forwards all attribute lookups
 * to a referenced AttributeMap.
 *
 * Note that the attribute mapping does not use any kind of snapshot visibility;
 * changes to the associated AttributeMap after the context has been created will
 * be reflected in subsequent calls to the attribute context.
 */
class MockAttributeContext : public attribute::IAttributeContext {
    const AttributeMap& _attributes;
public:
    using IAttributeVector = attribute::IAttributeVector;

    explicit MockAttributeContext(const AttributeMap& attributes)
        : _attributes(attributes)
    {
    }

    const IAttributeVector * getAttribute(const string & name) const override;
    const IAttributeVector * getAttributeStableEnum(const string & name) const override;
    void getAttributeList(std::vector<const IAttributeVector *> & list) const override;

    void
    asyncForAttribute(const vespalib::string &name, std::unique_ptr<attribute::IAttributeFunctor> func) const override;
};

}