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

#pragma once

#include "currentindex.h"
#include <vespa/vespalib/stllike/string.h>
#include <vespa/vespalib/stllike/hash_map.h>
#include <vespa/vespalib/stllike/hash_set.h>
#include <utility>

namespace search::expression {

class CurrentIndexSetup {
public:
    class Usage {
    private:
        friend class CurrentIndexSetup;
        vespalib::hash_set<vespalib::string> _unbound;
        void notify_unbound_struct_usage(vespalib::stringref name);
    public:
        Usage();
        ~Usage();
        [[nodiscard]] bool has_single_unbound_struct() const noexcept {
            return (_unbound.size() == 1);
        }
        vespalib::stringref get_unbound_struct_name() const;
        class Bind {
        private:
            CurrentIndexSetup &_setup;
        public:
            Bind(CurrentIndexSetup &setup, Usage &usage) noexcept;
            ~Bind();
        };
    };
private:
    vespalib::hash_map<vespalib::string, const CurrentIndex *> _bound;
    Usage *_usage;
    [[nodiscard]] Usage *capture(Usage *usage) noexcept {
        return std::exchange(_usage, usage);
    }
public:
    CurrentIndexSetup();
    ~CurrentIndexSetup();
    [[nodiscard]] const CurrentIndex *resolve(vespalib::stringref field_name) const;    
    void bind(vespalib::stringref struct_name, const CurrentIndex &index);
};

}