5#ifndef LIB_CONVERTER_TONIC_DART_CONVERTER_H_
6#define LIB_CONVERTER_TONIC_DART_CONVERTER_H_
12#include "third_party/dart/runtime/include/dart_api.h"
20template <
typename T,
typename Enable =
void>
42 static constexpr const char* kFfiRepresentation =
"Void";
43 static constexpr const char* kDartRepresentation =
"void";
44 static constexpr bool kAllowedInLeafCall =
true;
57 static constexpr const char* kFfiRepresentation =
"Bool";
58 static constexpr const char* kDartRepresentation =
"bool";
59 static constexpr bool kAllowedInLeafCall =
true;
121 if (
sizeof(
T) == 4) {
122 if (std::is_signed<T>()) {
128 if (std::is_signed<T>()) {
155 static constexpr const char* kFfiRepresentation =
"Uint64";
156 static constexpr const char* kDartRepresentation =
"int";
157 static constexpr bool kAllowedInLeafCall =
true;
172 unsigned long long val) {
210 static constexpr const char* kFfiRepresentation =
"Double";
211 static constexpr const char* kDartRepresentation =
"double";
212 static constexpr bool kAllowedInLeafCall =
true;
248 static constexpr const char* kFfiRepresentation =
"Int32";
249 static constexpr const char* kDartRepresentation =
"int";
250 static constexpr bool kAllowedInLeafCall =
true;
289 static constexpr const char* kFfiRepresentation =
"Handle";
290 static constexpr const char* kDartRepresentation =
"String";
291 static constexpr bool kAllowedInLeafCall =
false;
304 return std::string();
306 uint8_t*
data =
nullptr;
309 return std::string();
310 return std::string(
reinterpret_cast<char*
>(
data),
length);
330 static constexpr const char* kFfiRepresentation =
"Handle";
331 static constexpr const char* kDartRepresentation =
"String";
332 static constexpr bool kAllowedInLeafCall =
false;
336 reinterpret_cast<const uint16_t*
>(val.data()), val.length());
345 return std::u16string();
351 return std::u16string(
reinterpret_cast<char16_t*
>(
data.data()),
length);
381 const char*
result =
nullptr;
397 const std::string& type_name) {
448template <
typename T,
typename Enable =
void>
451 bool is_nullable =
false;
454 return is_nullable_handle;
461 auto sentinel = CreateZeroInitializedDartObject<T>(type_handle);
476 static constexpr const char* kFfiRepresentation =
"Handle";
477 static constexpr const char* kDartRepresentation =
"List";
478 static constexpr bool kAllowedInLeafCall =
false;
485 ToDartTypeHandle<ValueType>(), val.size());
488 for (
size_t i = 0;
i < val.size();
i++) {
498 const std::vector<ValueType>& val) {
503 std::vector<ValueType>
result;
516 std::vector<Dart_Handle> items(
length);
548 static constexpr const char* kFfiRepresentation =
"Handle";
549 static constexpr const char* kDartRepresentation =
"Object";
550 static constexpr bool kAllowedInLeafCall =
false;
DART_EXPORT Dart_Handle Dart_StringToUTF16(Dart_Handle str, uint16_t *utf16_array, intptr_t *length)
DART_EXPORT Dart_Handle Dart_StringLength(Dart_Handle str, intptr_t *length)
DART_EXPORT Dart_Handle Dart_NewDouble(double value)
DART_EXPORT void Dart_SetIntegerReturnValue(Dart_NativeArguments args, int64_t retval)
DART_EXPORT Dart_Handle Dart_GetNonNullableType(Dart_Handle library, Dart_Handle class_name, intptr_t number_of_type_arguments, Dart_Handle *type_arguments)
DART_EXPORT Dart_Handle Dart_IsNullableType(Dart_Handle type, bool *result)
DART_EXPORT Dart_Handle Dart_ListGetRange(Dart_Handle list, intptr_t offset, intptr_t length, Dart_Handle *result)
DART_EXPORT Dart_Handle Dart_NewStringFromUTF8(const uint8_t *utf8_array, intptr_t length)
DART_EXPORT Dart_Handle Dart_IntegerToInt64(Dart_Handle integer, int64_t *value)
DART_EXPORT Dart_Handle Dart_NewListOfTypeFilled(Dart_Handle element_type, Dart_Handle fill_object, intptr_t length)
struct _Dart_Handle * Dart_Handle
DART_EXPORT void Dart_SetDoubleReturnValue(Dart_NativeArguments args, double retval)
DART_EXPORT Dart_Handle Dart_GetNativeArgument(Dart_NativeArguments args, int index)
DART_EXPORT Dart_Handle Dart_EmptyString(void)
DART_EXPORT Dart_Handle Dart_NewIntegerFromUint64(uint64_t value)
DART_EXPORT Dart_Handle Dart_LookupLibrary(Dart_Handle url)
struct _Dart_NativeArguments * Dart_NativeArguments
DART_EXPORT DART_WARN_UNUSED_RESULT Dart_Handle Dart_New(Dart_Handle type, Dart_Handle constructor_name, int number_of_arguments, Dart_Handle *arguments)
DART_EXPORT Dart_Handle Dart_GetNativeIntegerArgument(Dart_NativeArguments args, int index, int64_t *value)
DART_EXPORT Dart_Handle Dart_Null(void)
DART_EXPORT void Dart_SetReturnValue(Dart_NativeArguments args, Dart_Handle retval)
DART_EXPORT Dart_Handle Dart_StringToUTF8(Dart_Handle str, uint8_t **utf8_array, intptr_t *length)
DART_EXPORT Dart_Handle Dart_ListLength(Dart_Handle list, intptr_t *length)
DART_EXPORT bool Dart_IsNull(Dart_Handle object)
DART_EXPORT Dart_Handle Dart_StringToCString(Dart_Handle str, const char **cstr)
DART_EXPORT Dart_Handle Dart_NewStringFromCString(const char *str)
DART_EXPORT Dart_Handle Dart_NewInteger(int64_t value)
DART_EXPORT Dart_Handle Dart_DoubleValue(Dart_Handle double_obj, double *value)
DART_EXPORT Dart_Handle Dart_NewBoolean(bool value)
DART_EXPORT void Dart_SetBooleanReturnValue(Dart_NativeArguments args, bool retval)
DART_EXPORT bool Dart_IsError(Dart_Handle handle)
DART_EXPORT Dart_Handle Dart_NewStringFromUTF16(const uint16_t *utf16_array, intptr_t length)
DART_EXPORT Dart_Handle Dart_NewListOfType(Dart_Handle element_type, intptr_t length)
DART_EXPORT Dart_Handle Dart_BooleanValue(Dart_Handle boolean_obj, bool *value)
DART_EXPORT bool Dart_IsList(Dart_Handle object)
DART_EXPORT Dart_Handle Dart_GetNativeDoubleArgument(Dart_NativeArguments args, int index, double *value)
DART_EXPORT Dart_Handle Dart_ListSetAt(Dart_Handle list, intptr_t index, Dart_Handle value)
DART_EXPORT Dart_Handle Dart_GetNativeBooleanArgument(Dart_NativeArguments args, int index, bool *value)
G_BEGIN_DECLS G_MODULE_EXPORT FlValue * args
Dart_Handle LookupNonNullableType(const std::string &library_name, const std::string &type_name)
Dart_Handle StdStringToDart(const std::string &val)
Dart_Handle ToDartTypeHandle()
Dart_Handle ToDart(const T &object)
Dart_Handle ToDart(const char *val)
bool CheckAndHandleError(Dart_Handle handle)
std::string StdStringFromDart(Dart_Handle handle)
Dart_Handle CreateZeroInitializedDartObject(Dart_Handle type_handle_or_null=::Dart_Null())
static Dart_Handle ToDart(T val)
static const char * GetFfiRepresentation()
static constexpr const char * kDartRepresentation
static void SetReturnValue(Dart_NativeArguments args, T val)
static T FromFfi(FfiType val)
static const char * GetDartRepresentation()
static constexpr bool kAllowedInLeafCall
static T FromDart(Dart_Handle handle)
static FfiType ToFfi(T val)
static bool AllowedInLeafCall()
static T FromArguments(Dart_NativeArguments args, int index, Dart_Handle &exception)
static NativeType FromFfi(FfiType val)
static FfiType ToFfi(NativeType val)
static Dart_Handle ToDart(NativeType val)
static bool AllowedInLeafCall()
static const char * GetDartRepresentation()
static const char * GetFfiRepresentation()
static NativeType FromArguments(Dart_NativeArguments args, int index, Dart_Handle &exception)
static NativeType FromDart(Dart_Handle handle)
static void SetReturnValue(Dart_NativeArguments args, Dart_Handle val)
static const char * GetFfiRepresentation()
static T FromDart(Dart_Handle handle)
static Dart_Handle ToDart(T val)
static void SetReturnValue(Dart_NativeArguments args, T val)
static bool AllowedInLeafCall()
static T FromFfi(FfiType val)
static T FromArguments(Dart_NativeArguments args, int index, Dart_Handle &exception)
static const char * GetDartRepresentation()
static void SetReturnValue(Dart_NativeArguments args, bool val)
static bool AllowedInLeafCall()
static FfiType ToFfi(NativeType val)
static Dart_Handle ToDart(NativeType val)
static const char * GetFfiRepresentation()
static const char * GetDartRepresentation()
static NativeType FromDart(Dart_Handle handle)
static NativeType FromFfi(FfiType val)
static NativeType FromArguments(Dart_NativeArguments args, int index, Dart_Handle &exception)
static const char * FromDart(Dart_Handle handle)
static void SetReturnValue(Dart_NativeArguments args, const char *val)
static const char * FromArguments(Dart_NativeArguments args, int index, Dart_Handle &exception)
static Dart_Handle ToDart(const char *val)
static FfiType ToFfi(double val)
static void SetReturnValue(Dart_NativeArguments args, double val)
static bool AllowedInLeafCall()
static double FromArguments(Dart_NativeArguments args, int index, Dart_Handle &exception)
static const char * GetFfiRepresentation()
static Dart_Handle ToDart(double val)
static double FromFfi(FfiType val)
static double FromDart(Dart_Handle handle)
static const char * GetDartRepresentation()
static FfiType ToFfi(NativeType val)
static const char * GetDartRepresentation()
static const char * GetFfiRepresentation()
static Dart_Handle ToDart(const NativeType &val)
static bool AllowedInLeafCall()
static NativeType FromDart(Dart_Handle handle)
static NativeType FromArguments(Dart_NativeArguments args, int index, Dart_Handle &exception)
static NativeType FromFfi(FfiType val)
static void SetReturnValue(Dart_NativeArguments args, const NativeType &val)
std::u16string NativeType
static NativeType FromArguments(Dart_NativeArguments args, int index, Dart_Handle &exception)
static const char * GetDartRepresentation()
static NativeType FromFfi(FfiType val)
static const char * GetFfiRepresentation()
static void SetReturnValue(Dart_NativeArguments args, const NativeType &val)
static NativeType FromDart(Dart_Handle handle)
static FfiType ToFfi(NativeType val)
static bool AllowedInLeafCall()
static Dart_Handle ToDart(const NativeType &val)
static bool AllowedInLeafCall()
typename DartConverterTypes< T >::ValueType ValueType
static Dart_Handle ToDart(const std::vector< ValueType > &val)
static std::vector< ValueType > FromDart(Dart_Handle handle)
static const char * GetDartRepresentation()
static const char * GetFfiRepresentation()
static FfiType ToFfi(std::vector< ValueType > val)
static void SetReturnValue(Dart_NativeArguments args, const std::vector< ValueType > &val)
typename DartConverterTypes< T >::ConverterType ConverterType
static std::vector< ValueType > FromFfi(FfiType val)
static std::vector< ValueType > FromArguments(Dart_NativeArguments args, int index, Dart_Handle &exception)
static bool AllowedInLeafCall()
static void SetReturnValue(Dart_NativeArguments args, unsigned long long val)
static Dart_Handle ToDart(unsigned long long val)
static const char * GetDartRepresentation()
static unsigned long long FromDart(Dart_Handle handle)
unsigned long long FfiType
static unsigned long long FromArguments(Dart_NativeArguments args, int index, Dart_Handle &exception)
static FfiType FromFfi(FfiType val)
static FfiType ToFfi(FfiType val)
static const char * GetFfiRepresentation()
static bool AllowedInLeafCall()
static const char * GetDartRepresentation()
static const char * GetFfiRepresentation()
static Dart_Handle NewList(Dart_Handle type_handle, intptr_t length)
std::shared_ptr< const fml::Mapping > data