Inkscape
Vector Graphics Editor
Loading...
Searching...
No Matches
callback-converter.h
Go to the documentation of this file.
1// SPDX-License-Identifier: GPL-2.0-or-later
5/*
6 * Author: PBS <pbs3141@gmail.com>
7 * Copyright (C) 2022 Authors
8 * Released under GNU GPL v2+, read the file 'COPYING' for more information.
9 */
10#ifndef INKSCAPE_UTIL_CALLBACK_CONVERTER_H
11#define INKSCAPE_UTIL_CALLBACK_CONVERTER_H
12
13#include <utility>
14
15namespace Inkscape::Util {
16namespace detail {
17
18template <auto Fp>
20{
21 template <typename T>
22 struct Helper;
23
24 template <typename Ret, typename Obj, typename... Args>
25 struct Helper<Ret(Obj::*)(Args...)>
26 {
27 // Unary plus converts lambda to function pointer.
28 static constexpr auto result = +[] (Args... args, void *data) -> Ret {
29 return (reinterpret_cast<Obj*>(data)->*Fp)(std::forward<Args>(args)...);
30 };
31 };
32
33 static constexpr auto result = Helper<decltype(Fp)>::result;
34};
35
36} // namespace detail
37
57template <auto Fp>
59
64template <auto Fp>
65inline auto make_g_callback = reinterpret_cast<void(*)()>(make_c_callback<Fp>); // inline instead of constexpr due to reinterpret_cast
66
67} // namespace Inkscape::Util
68
69#endif // INKSCAPE_UTIL_CALLBACK_CONVERTER_H
Miscellaneous supporting code.
Definition document.h:93
constexpr auto make_c_callback
Given a member function, make_c_callback produces a pure function with an extra void* argument at the...
auto make_g_callback
A worse version of make_c_callback that also casts the result to a GCallback, losing even more type-s...
static const Point data[]