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
|