Files
2025-10-24 12:31:06 +02:00

75 lines
1.9 KiB
C++
Generated

///
/// JFunc_void.hpp
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
/// https://github.com/mrousavy/nitro
/// Copyright © 2025 Marc Rousavy @ Margelo
///
#pragma once
#include <fbjni/fbjni.h>
#include <functional>
#include <functional>
namespace margelo::nitro::video {
using namespace facebook;
/**
* Represents the Java/Kotlin callback `() -> Unit`.
* This can be passed around between C++ and Java/Kotlin.
*/
struct JFunc_void: public jni::JavaClass<JFunc_void> {
public:
static auto constexpr kJavaDescriptor = "Lcom/margelo/nitro/video/Func_void;";
public:
/**
* Invokes the function this `JFunc_void` instance holds through JNI.
*/
void invoke() const {
static const auto method = javaClassStatic()->getMethod<void()>("invoke");
method(self());
}
};
/**
* An implementation of Func_void that is backed by a C++ implementation (using `std::function<...>`)
*/
struct JFunc_void_cxx final: public jni::HybridClass<JFunc_void_cxx, JFunc_void> {
public:
static jni::local_ref<JFunc_void::javaobject> fromCpp(const std::function<void()>& func) {
return JFunc_void_cxx::newObjectCxxArgs(func);
}
public:
/**
* Invokes the C++ `std::function<...>` this `JFunc_void_cxx` instance holds.
*/
void invoke_cxx() {
_func();
}
public:
[[nodiscard]]
inline const std::function<void()>& getFunction() const {
return _func;
}
public:
static auto constexpr kJavaDescriptor = "Lcom/margelo/nitro/video/Func_void_cxx;";
static void registerNatives() {
registerHybrid({makeNativeMethod("invoke_cxx", JFunc_void_cxx::invoke_cxx)});
}
private:
explicit JFunc_void_cxx(const std::function<void()>& func): _func(func) { }
private:
friend HybridBase;
std::function<void()> _func;
};
} // namespace margelo::nitro::video