aboutsummaryrefslogtreecommitdiffstats
path: root/searchlib/src/vespa/searchcommon/attribute/iattributecontext.h
blob: cf7b1d2f9593b30b0bc6d771544e0dde8938d5b6 (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
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.

#pragma once

#include "i_attribute_functor.h"
#include "iattributevector.h"

namespace search::attribute {

/**
 * This is an interface used to access all registered attribute vectors.
 **/
class IAttributeContext : public IAttributeExecutor {
public:
    using string = vespalib::string;
    /** Convenience typedefs **/
    using UP = std::unique_ptr<IAttributeContext>;

    /**
     * Returns the attribute vector with the given name.
     *
     * @param name the name of the attribute vector.
     * @return const view of the attribute vector or NULL if the attribute vector does not exists.
     **/
    virtual const IAttributeVector * getAttribute(const string & name) const = 0;

    /**
     * Returns the attribute vector with the given name.
     * Makes sure that the underlying enum values are stable during the use of this attribute.
     *
     * @param name the name of the attribute vector
     * @return const view of the attribute vector or NULL if the attribute vector does not exists.
     **/
    virtual const IAttributeVector * getAttributeStableEnum(const string & name) const = 0;

    /**
     * Fill the given list with all attribute vectors registered.
     *
     * @param list the list to fill in attribute vectors.
     **/
    virtual void getAttributeList(std::vector<const IAttributeVector *> & list) const = 0;

    /**
     * Releases all cached attribute guards.
     **/
    virtual void releaseEnumGuards() {}

    /**
     * Must be called before multiple threads will access the context.
     */
    virtual void enableMultiThreadSafe() {}

    /**
     * Virtual destructor to allow safe subclassing.
     **/
    virtual ~IAttributeContext() = default;
};

}