aboutsummaryrefslogtreecommitdiffstats
path: root/eval/src/vespa/eval/eval/lazy_params.h
blob: 06165b6b5ee50452c539a861fb59e3d8f5b3d6dc (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
60
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.

#pragma once

#include <vector>
#include "value.h"

namespace vespalib {

class Stash;

namespace eval {

/**
 * Interface used to lazy-resolve parameters.
 **/
struct LazyParams {
    // used by compiled code to resolve lazy double-only parameters
    using resolve_function = double (*)(void *ctx, size_t idx);

    virtual const Value &resolve(size_t idx, Stash &stash) const = 0;
    virtual ~LazyParams();
};

/**
 * Simple wrapper for object parameters that are known up
 * front. Intended for convenience (testing), not performance.
 **/
struct SimpleObjectParams : LazyParams {
    std::vector<Value::CREF> params;
    explicit SimpleObjectParams(const std::vector<Value::CREF> &params_in)
        : params(params_in) {}
    ~SimpleObjectParams();
    const Value &resolve(size_t idx, Stash &stash) const override;
};

/**
 * Simple wrapper for number-only parameters that are known up
 * front. Intended for convenience (testing), not performance.
 **/
struct SimpleParams : LazyParams {
    std::vector<double> params;
    explicit SimpleParams(const std::vector<double> &params_in)
        : params(params_in) {}
    ~SimpleParams();
    const Value &resolve(size_t idx, Stash &stash) const override;
};

/**
 * Simple wrapper for cases where you have no parameters.
 **/
struct NoParams : LazyParams {
    static NoParams params;
    const Value &resolve(size_t, Stash &) const override {
        abort();
    }
};

} // namespace vespalib::eval
} // namespace vespalib