5#ifndef LIB_TONIC_DART_ARGS_H_
6#define LIB_TONIC_DART_ARGS_H_
13#include "third_party/dart/runtime/include/dart_api.h"
22 : args_(
args), index_(start_index), had_exception_(
false) {}
31 had_exception_ =
true;
51template <
size_t... indices>
54template <
size_t requested_index,
size_t... indices>
61template <
size_t... indices>
69template <
typename ResultType,
typename... ArgTypes>
71 static const size_t count =
sizeof...(ArgTypes);
75template <
typename C,
typename ResultType,
typename... ArgTypes>
77 static const size_t count =
sizeof...(ArgTypes);
81template <
typename C,
typename ResultType,
typename... ArgTypes>
83 static const size_t count =
sizeof...(ArgTypes);
87template <
size_t index,
typename ArgType>
103template <
typename IndicesType,
typename T>
108template <
size_t... indices,
typename... ArgTypes>
125template <
size_t... indices,
typename ResultType,
typename... ArgTypes>
148template <
size_t... indices,
typename C,
typename... ArgTypes>
159 (GetReceiver<C>(it_->
args())->*func)(
166template <
size_t... indices,
169 typename... ArgTypes>
171 ReturnType (
C::*)(ArgTypes...) const>
189template <
size_t... indices,
192 typename... ArgTypes>
209template <
typename Sig>
216 decoder.Dispatch(func);
219template <
typename Sig>
226 decoder.Dispatch(func);
229template <
typename Sig>
239 wrappable = decoder.DispatchCtor(func);
250 wrappable->AssociateWithDartWrapper(wrapper);
263template <
typename C,
typename Signature, Signature function>
269template <
typename Arg,
typename... Args>
273 if constexpr (
sizeof...(Args) > 0) {
282template <
typename Arg,
typename... Args>
286 type>::GetDartRepresentation();
287 if constexpr (
sizeof...(Args) > 0) {
294template <
typename Arg,
typename... Args>
298 if constexpr (
sizeof...(Args) > 0) {
305template <
typename Return,
typename... Args, Return (*
function)(Args...)>
308 static const size_t n_args =
sizeof...(Args);
316 DartConverter<
typename std::remove_const<
typename std::remove_reference<
321 if constexpr (
sizeof...(Args) > 0) {
324 return AllowedInLeafCall<Return>();
336 if constexpr (
sizeof...(Args) > 0) {
342 if constexpr (
sizeof...(Args) > 0) {
352 Return (
C::*method)(Args...)>
355 static const size_t n_args =
sizeof...(Args);
364 DartConverter<
typename std::remove_const<
typename std::remove_reference<
369 if constexpr (
sizeof...(Args) > 0) {
372 return AllowedInLeafCall<Return>();
384 *stream << tonic::DartConverter<C*>::GetFfiRepresentation();
385 if constexpr (
sizeof...(Args) > 0) {
392 *stream << tonic::DartConverter<C*>::GetDartRepresentation();
393 if constexpr (
sizeof...(Args) > 0) {
404 Return (
C::*method)(Args...)
const>
407 static const size_t n_args =
sizeof...(Args);
416 DartConverter<
typename std::remove_const<
typename std::remove_reference<
421 if constexpr (
sizeof...(Args) > 0) {
424 return AllowedInLeafCall<Return>();
436 *stream << tonic::DartConverter<C*>::GetFfiRepresentation();
437 if constexpr (
sizeof...(Args) > 0) {
444 *stream << tonic::DartConverter<C*>::GetDartRepresentation();
445 if constexpr (
sizeof...(Args) > 0) {
454template <
typename... Args, void (*
function)(Args...)>
456 static const size_t n_args =
sizeof...(Args);
464 DartConverter<
typename std::remove_const<
typename std::remove_reference<
469 if constexpr (
sizeof...(Args) > 0) {
484 if constexpr (
sizeof...(Args) > 0) {
490 if constexpr (
sizeof...(Args) > 0) {
498template <
typename C,
typename... Args, void (
C::*method)(Args...)>
500 static const size_t n_args =
sizeof...(Args);
508 (
static_cast<C*
>(receiver)->*method)(
509 DartConverter<
typename std::remove_const<
typename std::remove_reference<
514 if constexpr (
sizeof...(Args) > 0) {
529 *stream << tonic::DartConverter<C*>::GetFfiRepresentation();
530 if constexpr (
sizeof...(Args) > 0) {
537 *stream << tonic::DartConverter<C*>::GetDartRepresentation();
538 if constexpr (
sizeof...(Args) > 0) {
DartArgIterator(Dart_NativeArguments args, int start_index=1)
Dart_NativeArguments args() const
bool had_exception() const
struct _Dart_Handle * Dart_Handle
DART_EXPORT Dart_Handle Dart_GetNativeArgument(Dart_NativeArguments args, int index)
DART_EXPORT Dart_Handle Dart_ThrowException(Dart_Handle exception)
struct _Dart_NativeArguments * Dart_NativeArguments
DART_EXPORT Dart_Handle Dart_GetNativeFieldsOfArgument(Dart_NativeArguments args, int arg_index, int num_fields, intptr_t *field_values)
G_BEGIN_DECLS G_MODULE_EXPORT FlValue * args
Dart_NativeFunction function
static CompileType * ResultType(Definition *call)
void DartCallStatic(Sig func, Dart_NativeArguments args)
void DartCallConstructor(Sig func, Dart_NativeArguments args)
void WriteDartArguments(std::ostringstream *stream)
bool CheckAndHandleError(Dart_Handle handle)
void WriteFfiArguments(std::ostringstream *stream)
void DartReturn(T result, Dart_NativeArguments args)
void DartCall(Sig func, Dart_NativeArguments args)
DartArgHolder(DartArgIterator *it)
typename std::remove_const< typename std::remove_reference< ArgType >::type >::type ValueType
void Dispatch(FunctionPtr func)
ResultType(C::*)(ArgTypes...) FunctionPtr
DartDispatcher(DartArgIterator *it)
ResultType(*)(ArgTypes...) FunctionPtr
ResultType CtorResultType
ResultType DispatchCtor(FunctionPtr func)
DartDispatcher(DartArgIterator *it)
void Dispatch(FunctionPtr func)
ReturnType(C::*)(ArgTypes...) const FunctionPtr
void Dispatch(FunctionPtr func)
DartDispatcher(DartArgIterator *it)
void Dispatch(FunctionPtr func)
void(C::*)(ArgTypes...) FunctionPtr
DartDispatcher(DartArgIterator *it)
DartDispatcher(DartArgIterator *it)
void(*)(ArgTypes...) FunctionPtr
void Dispatch(FunctionPtr func)
static void WriteFfiArguments(std::ostringstream *stream)
typename DartConverter< Return >::FfiType FfiReturn
static bool AllowedAsLeafCall()
static const char * GetReturnDartRepresentation()
static const char * GetReturnFfiRepresentation()
static FfiReturn Call(DartWrappable *receiver, typename DartConverter< typename std::remove_const< typename std::remove_reference< Args >::type >::type >::FfiType... args)
static void WriteDartArguments(std::ostringstream *stream)
static void WriteDartArguments(std::ostringstream *stream)
typename DartConverter< Return >::FfiType FfiReturn
static bool AllowedAsLeafCall()
static FfiReturn Call(DartWrappable *receiver, typename DartConverter< typename std::remove_const< typename std::remove_reference< Args >::type >::type >::FfiType... args)
static const char * GetReturnFfiRepresentation()
static void WriteFfiArguments(std::ostringstream *stream)
static const char * GetReturnDartRepresentation()
static void WriteDartArguments(std::ostringstream *stream)
static void WriteFfiArguments(std::ostringstream *stream)
static const char * GetReturnFfiRepresentation()
static bool AllowedAsLeafCall()
static const char * GetReturnDartRepresentation()
static void Call(DartWrappable *receiver, typename DartConverter< typename std::remove_const< typename std::remove_reference< Args >::type >::type >::FfiType... args)
static const char * GetReturnFfiRepresentation()
static void WriteDartArguments(std::ostringstream *stream)
static const char * GetReturnDartRepresentation()
static bool AllowedAsLeafCall()
typename DartConverter< Return >::FfiType FfiReturn
static void WriteFfiArguments(std::ostringstream *stream)
static FfiReturn Call(typename DartConverter< typename std::remove_const< typename std::remove_reference< Args >::type >::type >::FfiType... args)
static const char * GetReturnDartRepresentation()
static bool AllowedAsLeafCall()
static void WriteDartArguments(std::ostringstream *stream)
static void Call(typename DartConverter< typename std::remove_const< typename std::remove_reference< Args >::type >::type >::FfiType... args)
static void WriteFfiArguments(std::ostringstream *stream)
static const char * GetReturnFfiRepresentation()
typename IndicesGenerator< count >::type type
typename IndicesGenerator< count >::type type
typename IndicesGenerator< count >::type type
typename IndicesGenerator< requested_index - 1, requested_index - 1, indices... >::type type
#define TONIC_CHECK(condition)