| 1 |
// Copyright (c) the JPEG XL Project Authors. All rights reserved. |
| 2 |
// |
| 3 |
// Use of this source code is governed by a BSD-style |
| 4 |
// license that can be found in the LICENSE file. |
| 5 |
|
| 6 |
#ifndef LIB_JXL_BASE_C_CALLBACK_SUPPORT_H_ |
| 7 |
#define LIB_JXL_BASE_C_CALLBACK_SUPPORT_H_ |
| 8 |
|
| 9 |
#include <utility> |
| 10 |
|
| 11 |
namespace jxl { |
| 12 |
namespace detail { |
| 13 |
|
| 14 |
template <typename T> |
| 15 |
struct MethodToCCallbackHelper {}; |
| 16 |
|
| 17 |
template <typename T, typename R, typename... Args> |
| 18 |
struct MethodToCCallbackHelper<R (T::*)(Args...)> { |
| 19 |
template <R (T::*method)(Args...)> |
| 20 |
static R Call(void *opaque, Args... args) { |
| 21 |
return (reinterpret_cast<T *>(opaque)->*method)( |
| 22 |
std::forward<Args>(args)...); |
| 23 |
} |
| 24 |
}; |
| 25 |
|
| 26 |
} // namespace detail |
| 27 |
} // namespace jxl |
| 28 |
|
| 29 |
#define METHOD_TO_C_CALLBACK(method) \ |
| 30 |
::jxl::detail::MethodToCCallbackHelper<decltype(method)>::Call<method> |
| 31 |
|
| 32 |
#endif // LIB_JXL_BASE_C_CALLBACK_SUPPORT_H_ |