File: registered_method_dispatcher.h

package info (click to toggle)
intel-compute-runtime 25.35.35096.9-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 79,324 kB
  • sloc: cpp: 926,243; lisp: 3,433; sh: 715; makefile: 162; python: 21
file content (50 lines) | stat: -rw-r--r-- 1,186 bytes parent folder | download | duplicates (3)
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
/*
 * Copyright (C) 2019-2021 Intel Corporation
 *
 * SPDX-License-Identifier: MIT
 *
 */

#pragma once

#include <cstddef>
#include <cstdint>
#include <functional>

namespace NEO {

template <typename MethodArgsT, typename EstimateMethodArgsT>
class RegisteredMethodDispatcher {
  public:
    using CommandsSizeEstimationMethodT = std::function<EstimateMethodArgsT>;
    using RegisteredMethodT = std::function<MethodArgsT>;

    void registerMethod(RegisteredMethodT method) {
        this->method = method;
    }

    void registerCommandsSizeEstimationMethod(CommandsSizeEstimationMethodT method) {
        this->commandsEstimationMethod = method;
    }

    template <typename... Args>
    void operator()(Args &&...args) const {
        if (method) {
            method(std::forward<Args>(args)...);
        }
    }

    template <typename... Args>
    size_t estimateCommandsSize(Args &&...args) const {
        if (commandsEstimationMethod) {
            return commandsEstimationMethod(std::forward<Args>(args)...);
        }
        return 0;
    }

  protected:
    CommandsSizeEstimationMethodT commandsEstimationMethod;
    RegisteredMethodT method;
};

} // namespace NEO