ChimeraTK-DeviceAccess 03.25.00
Loading...
Searching...
No Matches
VirtualFunctionTemplate.h
Go to the documentation of this file.
1// SPDX-FileCopyrightText: Deutsches Elektronen-Synchrotron DESY, MSK, ChimeraTK Project <chimeratk-support@desy.de>
2// SPDX-License-Identifier: LGPL-3.0-or-later
3#pragma once
4
5#include <boost/bind/bind.hpp>
6#include <boost/function.hpp>
7#include <boost/fusion/include/at_key.hpp>
8#include <boost/fusion/include/for_each.hpp>
9
36#define DEFINE_VIRTUAL_FUNCTION_TEMPLATE_VTABLE(functionName, ...) \
37 template<typename T> \
38 class functionName##_functionSignature : public boost::function<__VA_ARGS__> { \
39 public: \
40 functionName##_functionSignature& operator=(const boost::function<__VA_ARGS__>& rhs) { \
41 boost::function<__VA_ARGS__>::operator=(rhs); \
42 return *this; \
43 } \
44 }; \
45 TemplateUserTypeMap<functionName##_functionSignature> functionName##_vtable
46
52#define DEFINE_VIRTUAL_FUNCTION_OVERRIDE_VTABLE(BaseClass, functionName, ...) \
53 DEFINE_VIRTUAL_FUNCTION_TEMPLATE_VTABLE(BaseClass##functionName, __VA_ARGS__)
54
64#define CALL_VIRTUAL_FUNCTION_TEMPLATE(functionName, templateArgument, ...) \
65 boost::fusion::at_key<templateArgument>(functionName##_vtable.table)(__VA_ARGS__)
66
72#define CALL_BASE_FUNCTION_TEMPLATE(BaseClass, functionName, templateArgument, ...) \
73 boost::fusion::at_key<templateArgument>(BaseClass##functionName##_vtable.table)(__VA_ARGS__)
74
78#define FILL_VIRTUAL_FUNCTION_TEMPLATE_VTABLE(functionName) \
79 ChimeraTK::for_each(this->functionName##_vtable.table, [this](auto& pair) { \
80 typedef typename std::remove_reference<decltype(pair)>::type::first_type VTableFillerUserType; \
81 pair.second = [this](auto... args) { return this->functionName<VTableFillerUserType>(args...); }; \
82 })
83
87#define OVERRIDE_VIRTUAL_FUNCTION_TEMPLATE(BaseClass, functionName) \
88 do { \
89 /* Copy the old vtable into _base before filling it with the new implementation */ \
90 ChimeraTK::for_each(BaseClass##functionName##_vtable.table, [&](auto& pair) { \
91 typedef typename std::remove_reference<decltype(pair)>::type::first_type VTableFillerUserType; \
92 pair.second = (boost::fusion::at_key<VTableFillerUserType>(functionName##_vtable.table)); \
93 }); \
94 FILL_VIRTUAL_FUNCTION_TEMPLATE_VTABLE(functionName); \
95 } while(false)
96
98#define FILL_VIRTUAL_FUNCTION_TEMPLATE_VTABLE_STANDALONE(functionName, numberOfArguments) \
99 FILL_VIRTUAL_FUNCTION_TEMPLATE_VTABLE(functionName)
100
102#define DEFINE_VIRTUAL_FUNCTION_TEMPLATE_VTABLE_FILLER(className, functionName, numberOfArguments) \
103 class UslessVTableFillerClass##functionName {}