/home/runner/work/HiCR/HiCR/include/hicr/frontends/tasking/callbackMap.hpp Source File

HiCR: /home/runner/work/HiCR/HiCR/include/hicr/frontends/tasking/callbackMap.hpp Source File
HiCR
callbackMap.hpp
Go to the documentation of this file.
1/*
2 * Copyright 2025 Huawei Technologies Co., Ltd.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
24#pragma once
25
26#include <map>
27#include <hicr/core/definitions.hpp>
28#include "./common.hpp"
29
30namespace HiCR::tasking
31{
32
38template <class T, class E>
40{
41 public:
42
46 __INLINE__ void clear() { _callbackMap.clear(); }
47
53 __INLINE__ void removeCallback(const E callback) { _callbackMap.erase(callback); }
54
61 __INLINE__ void setCallback(const E callback, callbackFc_t<T> fc) { _callbackMap[callback] = fc; }
62
69 __INLINE__ void trigger(T arg, const E callback) const
70 {
71 if (_callbackMap.contains(callback)) _callbackMap.at(callback)(arg);
72 }
73
80 __INLINE__ bool isCallbackSet(const E callback) const { return _callbackMap.contains(callback); }
81
82 private:
83
87 std::map<E, callbackFc_t<T>> _callbackMap;
88};
89
90} // namespace HiCR::tasking
Definition callbackMap.hpp:40
__INLINE__ void trigger(T arg, const E callback) const
Definition callbackMap.hpp:69
__INLINE__ void clear()
Definition callbackMap.hpp:46
__INLINE__ void removeCallback(const E callback)
Definition callbackMap.hpp:53
__INLINE__ void setCallback(const E callback, callbackFc_t< T > fc)
Definition callbackMap.hpp:61
__INLINE__ bool isCallbackSet(const E callback) const
Definition callbackMap.hpp:80
This file implements variables shared among mutiple code files.
std::function< void(T)> callbackFc_t
Definition common.hpp:41