diff --git a/CronosPlayUnreal.uplugin b/CronosPlayUnreal.uplugin index c8c3eab0..b69508c9 100644 --- a/CronosPlayUnreal.uplugin +++ b/CronosPlayUnreal.uplugin @@ -2,8 +2,8 @@ "FileVersion": 3, "FriendlyName": "Cronos Play for Unreal Engine", "Version": 1, - "VersionName": "v0.0.17-alpha", - "EngineVersion": "5.2.0", + "VersionName": "v0.0.18-alpha", + "EngineVersion": "5.3.0", "Description": "Cronos labs", "Category": "Programming", "CreatedBy": "Cronos labs", diff --git a/Makefile b/Makefile index 4f58d3c8..ce856f35 100644 --- a/Makefile +++ b/Makefile @@ -2,7 +2,7 @@ UNAME := $(shell uname) PWD = $(shell pwd) # Set the play cpp sdk version -PLAYCPPSDK=v0.0.23-alpha +PLAYCPPSDK=v0.0.24-alpha # Set the play-cpp-sdk cache path PLAYCPPSDK_CACHE_DIR=./install/$(PLAYCPPSDK) # Set the play-cpp-sdk target path diff --git a/Source/CronosPlayUnreal/CronosPlayUnreal.Build.cs b/Source/CronosPlayUnreal/CronosPlayUnreal.Build.cs index 925dee20..6ef85f93 100644 --- a/Source/CronosPlayUnreal/CronosPlayUnreal.Build.cs +++ b/Source/CronosPlayUnreal/CronosPlayUnreal.Build.cs @@ -40,5 +40,13 @@ public CronosPlayUnreal(ReadOnlyTargetRules Target) : base(Target) { "AndroidPlugin", System.IO.Path.Combine(PluginPath, "Android.xml")); } + if (Target.Platform == UnrealTargetPlatform.Mac) { + // Add frameworks for macOS + PublicFrameworks.AddRange(new string[] { + "Security", + "CoreFoundation", + "SystemConfiguration" + }); + } } } diff --git a/Source/CronosPlayUnreal/Private/PlayCppSdkActor.cpp b/Source/CronosPlayUnreal/Private/PlayCppSdkActor.cpp index 41bc4f03..bdafe122 100644 --- a/Source/CronosPlayUnreal/Private/PlayCppSdkActor.cpp +++ b/Source/CronosPlayUnreal/Private/PlayCppSdkActor.cpp @@ -660,9 +660,10 @@ void APlayCppSdkActor::SendEip155Transaction( ::std::array<::std::uint8_t, 20> dstaddress; for (int i = 0; i < address.Num(); i++) { dstaddress[i] = address[i]; - } + } WalletConnectTxEip155 myinfo; + myinfo.from= TCHAR_TO_UTF8(*info.from); myinfo.to = TCHAR_TO_UTF8(*info.to); myinfo.common.gas_limit = TCHAR_TO_UTF8(*info.gas); myinfo.common.gas_price = TCHAR_TO_UTF8(*info.gas_price); diff --git a/Source/CronosPlayUnreal/Public/PlayCppSdkActor.h b/Source/CronosPlayUnreal/Public/PlayCppSdkActor.h index 1438cedd..0c881ef0 100644 --- a/Source/CronosPlayUnreal/Public/PlayCppSdkActor.h +++ b/Source/CronosPlayUnreal/Public/PlayCppSdkActor.h @@ -183,6 +183,9 @@ struct FWalletConnectTxEip155 { GENERATED_USTRUCT_BODY() /** hexstring, "0x..." */ UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "PlayCppSdk") + FString from; + /** hexstring, "0x..." */ + UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "PlayCppSdk") FString to; /** gas limit in decimal string */ UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "PlayCppSdk") diff --git a/Source/ThirdParty/PlayCppSdkLibrary/Include/android.cc b/Source/ThirdParty/PlayCppSdkLibrary/Include/android.cc index 673adae7..c44ffbd3 100644 --- a/Source/ThirdParty/PlayCppSdkLibrary/Include/android.cc +++ b/Source/ThirdParty/PlayCppSdkLibrary/Include/android.cc @@ -12,77 +12,76 @@ namespace org { namespace defi_wallet_core { int secureStorageSetJavaEnv(JNIEnv *userenv) { - g_env = userenv; - return 1; + g_env = userenv; + return 1; } jclass getSecureStorageClass(JNIEnv *env) { - string secureStorageClass = SECURE_STORAGE_CLASS; - jclass kotlinClass = env->FindClass(secureStorageClass.c_str()); - return kotlinClass; + string secureStorageClass = SECURE_STORAGE_CLASS; + jclass kotlinClass = env->FindClass(secureStorageClass.c_str()); + return kotlinClass; } jobject getContext(JNIEnv *env) { - jclass activityThreadClass = env->FindClass("android/app/ActivityThread"); - jmethodID currentActivityThreadMethod = - env->GetStaticMethodID(activityThreadClass, "currentActivityThread", - "()Landroid/app/ActivityThread;"); - jobject activityThread = env->CallStaticObjectMethod( - activityThreadClass, currentActivityThreadMethod); - jmethodID getApplicationMethod = env->GetMethodID( - activityThreadClass, "getApplication", "()Landroid/app/Application;"); - jobject context = - env->CallObjectMethod(activityThread, getApplicationMethod); - return context; + jclass activityThreadClass = env->FindClass("android/app/ActivityThread"); + jmethodID currentActivityThreadMethod = + env->GetStaticMethodID(activityThreadClass, "currentActivityThread", + "()Landroid/app/ActivityThread;"); + jobject activityThread = env->CallStaticObjectMethod( + activityThreadClass, currentActivityThreadMethod); + jmethodID getApplicationMethod = env->GetMethodID( + activityThreadClass, "getApplication", "()Landroid/app/Application;"); + jobject context = env->CallObjectMethod(activityThread, getApplicationMethod); + return context; } int secureStorageWriteBasic(JNIEnv *env, string userkey, string uservalue) { - jobject context = getContext(env); - jclass secureStorageClass = getSecureStorageClass(env); - jmethodID functionMethod = env->GetStaticMethodID( - secureStorageClass, "writeSecureStorage", - "(Landroid/content/Context;Ljava/lang/String;Ljava/lang/String;)I"); - jstring key = env->NewStringUTF(userkey.c_str()); - jstring value = env->NewStringUTF(uservalue.c_str()); - jint ret = env->CallStaticIntMethod(secureStorageClass, functionMethod, - context, key, value); + jobject context = getContext(env); + jclass secureStorageClass = getSecureStorageClass(env); + jmethodID functionMethod = env->GetStaticMethodID( + secureStorageClass, "writeSecureStorage", + "(Landroid/content/Context;Ljava/lang/String;Ljava/lang/String;)I"); + jstring key = env->NewStringUTF(userkey.c_str()); + jstring value = env->NewStringUTF(uservalue.c_str()); + jint ret = env->CallStaticIntMethod(secureStorageClass, functionMethod, + context, key, value); - return (int)ret; + return (int)ret; } string secureStorageReadBasic(JNIEnv *env, string userkey) { - jobject context = getContext(env); - jclass secureStorageClass = getSecureStorageClass(env); - jmethodID functionMethod = env->GetStaticMethodID( - secureStorageClass, "readSecureStorage", - "(Landroid/content/Context;Ljava/lang/String;)Ljava/lang/String;"); - jstring userkeyarg = env->NewStringUTF(userkey.c_str()); - jobject ret = env->CallStaticObjectMethod( - secureStorageClass, functionMethod, context, userkeyarg); - string retstring = string(env->GetStringUTFChars((jstring)ret, 0)); + jobject context = getContext(env); + jclass secureStorageClass = getSecureStorageClass(env); + jmethodID functionMethod = env->GetStaticMethodID( + secureStorageClass, "readSecureStorage", + "(Landroid/content/Context;Ljava/lang/String;)Ljava/lang/String;"); + jstring userkeyarg = env->NewStringUTF(userkey.c_str()); + jobject ret = env->CallStaticObjectMethod(secureStorageClass, functionMethod, + context, userkeyarg); + string retstring = string(env->GetStringUTFChars((jstring)ret, 0)); - return retstring; + return retstring; } int secureStorageWrite(rust::String userkey, rust::String uservalue) { - try { - JNIEnv *env = g_env; - string userkeystring = userkey.c_str(); - string uservaluestring = uservalue.c_str(); - int ret = secureStorageWriteBasic(env, userkeystring, uservaluestring); - return ret; - } catch (exception &e) { - return 0; // fail - } + try { + JNIEnv *env = g_env; + string userkeystring = userkey.c_str(); + string uservaluestring = uservalue.c_str(); + int ret = secureStorageWriteBasic(env, userkeystring, uservaluestring); + return ret; + } catch (exception &e) { + return 0; // fail + } } rust::String secureStorageRead(rust::String userkey) { - try { - JNIEnv *env = g_env; - string ret = secureStorageReadBasic(env, userkey.c_str()); - return rust::String(ret.c_str()); - } catch (exception &e) { - return rust::String(""); // fail - } + try { + JNIEnv *env = g_env; + string ret = secureStorageReadBasic(env, userkey.c_str()); + return rust::String(ret.c_str()); + } catch (exception &e) { + return rust::String(""); // fail + } } } // namespace defi_wallet_core diff --git a/Source/ThirdParty/PlayCppSdkLibrary/Include/defi-wallet-core-cpp/src/contract.rs.cc b/Source/ThirdParty/PlayCppSdkLibrary/Include/defi-wallet-core-cpp/src/contract.rs.cc index f96b90f7..c8e81999 100644 --- a/Source/ThirdParty/PlayCppSdkLibrary/Include/defi-wallet-core-cpp/src/contract.rs.cc +++ b/Source/ThirdParty/PlayCppSdkLibrary/Include/defi-wallet-core-cpp/src/contract.rs.cc @@ -20,575 +20,621 @@ inline namespace cxxbridge1 { #ifndef CXXBRIDGE1_PANIC #define CXXBRIDGE1_PANIC -template void panic [[noreturn]] (const char *msg); +template +void panic [[noreturn]] (const char *msg); #endif // CXXBRIDGE1_PANIC struct unsafe_bitcopy_t; namespace { -template class impl; +template +class impl; } // namespace class Opaque; -template ::std::size_t size_of(); -template ::std::size_t align_of(); +template +::std::size_t size_of(); +template +::std::size_t align_of(); #ifndef CXXBRIDGE1_RUST_STRING #define CXXBRIDGE1_RUST_STRING class String final { - public: - String() noexcept; - String(const String &) noexcept; - String(String &&) noexcept; - ~String() noexcept; - - String(const std::string &); - String(const char *); - String(const char *, std::size_t); - String(const char16_t *); - String(const char16_t *, std::size_t); - - static String lossy(const std::string &) noexcept; - static String lossy(const char *) noexcept; - static String lossy(const char *, std::size_t) noexcept; - static String lossy(const char16_t *) noexcept; - static String lossy(const char16_t *, std::size_t) noexcept; - - String &operator=(const String &) &noexcept; - String &operator=(String &&) &noexcept; - - explicit operator std::string() const; - - const char *data() const noexcept; - std::size_t size() const noexcept; - std::size_t length() const noexcept; - bool empty() const noexcept; - - const char *c_str() noexcept; - - std::size_t capacity() const noexcept; - void reserve(size_t new_cap) noexcept; - - using iterator = char *; - iterator begin() noexcept; - iterator end() noexcept; - - using const_iterator = const char *; - const_iterator begin() const noexcept; - const_iterator end() const noexcept; - const_iterator cbegin() const noexcept; - const_iterator cend() const noexcept; - - bool operator==(const String &) const noexcept; - bool operator!=(const String &) const noexcept; - bool operator<(const String &) const noexcept; - bool operator<=(const String &) const noexcept; - bool operator>(const String &) const noexcept; - bool operator>=(const String &) const noexcept; - - void swap(String &) noexcept; - - String(unsafe_bitcopy_t, const String &) noexcept; - - private: - struct lossy_t; - String(lossy_t, const char *, std::size_t) noexcept; - String(lossy_t, const char16_t *, std::size_t) noexcept; - friend void swap(String &lhs, String &rhs) noexcept { lhs.swap(rhs); } - - std::array repr; +public: + String() noexcept; + String(const String &) noexcept; + String(String &&) noexcept; + ~String() noexcept; + + String(const std::string &); + String(const char *); + String(const char *, std::size_t); + String(const char16_t *); + String(const char16_t *, std::size_t); + + static String lossy(const std::string &) noexcept; + static String lossy(const char *) noexcept; + static String lossy(const char *, std::size_t) noexcept; + static String lossy(const char16_t *) noexcept; + static String lossy(const char16_t *, std::size_t) noexcept; + + String &operator=(const String &) &noexcept; + String &operator=(String &&) &noexcept; + + explicit operator std::string() const; + + const char *data() const noexcept; + std::size_t size() const noexcept; + std::size_t length() const noexcept; + bool empty() const noexcept; + + const char *c_str() noexcept; + + std::size_t capacity() const noexcept; + void reserve(size_t new_cap) noexcept; + + using iterator = char *; + iterator begin() noexcept; + iterator end() noexcept; + + using const_iterator = const char *; + const_iterator begin() const noexcept; + const_iterator end() const noexcept; + const_iterator cbegin() const noexcept; + const_iterator cend() const noexcept; + + bool operator==(const String &) const noexcept; + bool operator!=(const String &) const noexcept; + bool operator<(const String &) const noexcept; + bool operator<=(const String &) const noexcept; + bool operator>(const String &) const noexcept; + bool operator>=(const String &) const noexcept; + + void swap(String &) noexcept; + + String(unsafe_bitcopy_t, const String &) noexcept; + +private: + struct lossy_t; + String(lossy_t, const char *, std::size_t) noexcept; + String(lossy_t, const char16_t *, std::size_t) noexcept; + friend void swap(String &lhs, String &rhs) noexcept { lhs.swap(rhs); } + + std::array repr; }; #endif // CXXBRIDGE1_RUST_STRING #ifndef CXXBRIDGE1_RUST_SLICE #define CXXBRIDGE1_RUST_SLICE namespace detail { -template struct copy_assignable_if {}; - -template <> struct copy_assignable_if { - copy_assignable_if() noexcept = default; - copy_assignable_if(const copy_assignable_if &) noexcept = default; - copy_assignable_if & - operator=(const copy_assignable_if &) &noexcept = delete; - copy_assignable_if &operator=(copy_assignable_if &&) &noexcept = default; +template +struct copy_assignable_if {}; + +template <> +struct copy_assignable_if { + copy_assignable_if() noexcept = default; + copy_assignable_if(const copy_assignable_if &) noexcept = default; + copy_assignable_if &operator=(const copy_assignable_if &) &noexcept = delete; + copy_assignable_if &operator=(copy_assignable_if &&) &noexcept = default; }; } // namespace detail template class Slice final : private detail::copy_assignable_if::value> { - public: - using value_type = T; +public: + using value_type = T; - Slice() noexcept; - Slice(T *, std::size_t count) noexcept; + Slice() noexcept; + Slice(T *, std::size_t count) noexcept; - Slice &operator=(const Slice &) &noexcept = default; - Slice &operator=(Slice &&) &noexcept = default; + Slice &operator=(const Slice &) &noexcept = default; + Slice &operator=(Slice &&) &noexcept = default; - T *data() const noexcept; - std::size_t size() const noexcept; - std::size_t length() const noexcept; - bool empty() const noexcept; + T *data() const noexcept; + std::size_t size() const noexcept; + std::size_t length() const noexcept; + bool empty() const noexcept; - T &operator[](std::size_t n) const noexcept; - T &at(std::size_t n) const; - T &front() const noexcept; - T &back() const noexcept; + T &operator[](std::size_t n) const noexcept; + T &at(std::size_t n) const; + T &front() const noexcept; + T &back() const noexcept; - Slice(const Slice &) noexcept = default; - ~Slice() noexcept = default; + Slice(const Slice &) noexcept = default; + ~Slice() noexcept = default; - class iterator; - iterator begin() const noexcept; - iterator end() const noexcept; + class iterator; + iterator begin() const noexcept; + iterator end() const noexcept; - void swap(Slice &) noexcept; + void swap(Slice &) noexcept; - private: - class uninit; - Slice(uninit) noexcept; - friend impl; - friend void sliceInit(void *, const void *, std::size_t) noexcept; - friend void *slicePtr(const void *) noexcept; - friend std::size_t sliceLen(const void *) noexcept; +private: + class uninit; + Slice(uninit) noexcept; + friend impl; + friend void sliceInit(void *, const void *, std::size_t) noexcept; + friend void *slicePtr(const void *) noexcept; + friend std::size_t sliceLen(const void *) noexcept; - std::array repr; + std::array repr; }; -template class Slice::iterator final { - public: - using iterator_category = std::random_access_iterator_tag; - using value_type = T; - using difference_type = std::ptrdiff_t; - using pointer = typename std::add_pointer::type; - using reference = typename std::add_lvalue_reference::type; - - reference operator*() const noexcept; - pointer operator->() const noexcept; - reference operator[](difference_type) const noexcept; - - iterator &operator++() noexcept; - iterator operator++(int) noexcept; - iterator &operator--() noexcept; - iterator operator--(int) noexcept; - - iterator &operator+=(difference_type) noexcept; - iterator &operator-=(difference_type) noexcept; - iterator operator+(difference_type) const noexcept; - iterator operator-(difference_type) const noexcept; - difference_type operator-(const iterator &) const noexcept; - - bool operator==(const iterator &) const noexcept; - bool operator!=(const iterator &) const noexcept; - bool operator<(const iterator &) const noexcept; - bool operator<=(const iterator &) const noexcept; - bool operator>(const iterator &) const noexcept; - bool operator>=(const iterator &) const noexcept; - - private: - friend class Slice; - void *pos; - std::size_t stride; +template +class Slice::iterator final { +public: + using iterator_category = std::random_access_iterator_tag; + using value_type = T; + using difference_type = std::ptrdiff_t; + using pointer = typename std::add_pointer::type; + using reference = typename std::add_lvalue_reference::type; + + reference operator*() const noexcept; + pointer operator->() const noexcept; + reference operator[](difference_type) const noexcept; + + iterator &operator++() noexcept; + iterator operator++(int) noexcept; + iterator &operator--() noexcept; + iterator operator--(int) noexcept; + + iterator &operator+=(difference_type) noexcept; + iterator &operator-=(difference_type) noexcept; + iterator operator+(difference_type) const noexcept; + iterator operator-(difference_type) const noexcept; + difference_type operator-(const iterator &) const noexcept; + + bool operator==(const iterator &) const noexcept; + bool operator!=(const iterator &) const noexcept; + bool operator<(const iterator &) const noexcept; + bool operator<=(const iterator &) const noexcept; + bool operator>(const iterator &) const noexcept; + bool operator>=(const iterator &) const noexcept; + +private: + friend class Slice; + void *pos; + std::size_t stride; }; -template Slice::Slice() noexcept { - sliceInit(this, reinterpret_cast(align_of()), 0); +template +Slice::Slice() noexcept { + sliceInit(this, reinterpret_cast(align_of()), 0); } -template Slice::Slice(T *s, std::size_t count) noexcept { - assert(s != nullptr || count == 0); - sliceInit(this, - s == nullptr && count == 0 - ? reinterpret_cast(align_of()) - : const_cast::type *>(s), - count); +template +Slice::Slice(T *s, std::size_t count) noexcept { + assert(s != nullptr || count == 0); + sliceInit(this, + s == nullptr && count == 0 + ? reinterpret_cast(align_of()) + : const_cast::type *>(s), + count); } -template T *Slice::data() const noexcept { - return reinterpret_cast(slicePtr(this)); +template +T *Slice::data() const noexcept { + return reinterpret_cast(slicePtr(this)); } -template std::size_t Slice::size() const noexcept { - return sliceLen(this); +template +std::size_t Slice::size() const noexcept { + return sliceLen(this); } -template std::size_t Slice::length() const noexcept { - return this->size(); +template +std::size_t Slice::length() const noexcept { + return this->size(); } -template bool Slice::empty() const noexcept { - return this->size() == 0; +template +bool Slice::empty() const noexcept { + return this->size() == 0; } -template T &Slice::operator[](std::size_t n) const noexcept { - assert(n < this->size()); - auto ptr = static_cast(slicePtr(this)) + size_of() * n; - return *reinterpret_cast(ptr); +template +T &Slice::operator[](std::size_t n) const noexcept { + assert(n < this->size()); + auto ptr = static_cast(slicePtr(this)) + size_of() * n; + return *reinterpret_cast(ptr); } -template T &Slice::at(std::size_t n) const { - if (n >= this->size()) { - panic("rust::Slice index out of range"); - } - return (*this)[n]; +template +T &Slice::at(std::size_t n) const { + if (n >= this->size()) { + panic("rust::Slice index out of range"); + } + return (*this)[n]; } -template T &Slice::front() const noexcept { - assert(!this->empty()); - return (*this)[0]; +template +T &Slice::front() const noexcept { + assert(!this->empty()); + return (*this)[0]; } -template T &Slice::back() const noexcept { - assert(!this->empty()); - return (*this)[this->size() - 1]; +template +T &Slice::back() const noexcept { + assert(!this->empty()); + return (*this)[this->size() - 1]; } template typename Slice::iterator::reference Slice::iterator::operator*() const noexcept { - return *static_cast(this->pos); + return *static_cast(this->pos); } template typename Slice::iterator::pointer Slice::iterator::operator->() const noexcept { - return static_cast(this->pos); + return static_cast(this->pos); } template typename Slice::iterator::reference Slice::iterator::operator[]( typename Slice::iterator::difference_type n) const noexcept { - auto ptr = static_cast(this->pos) + this->stride * n; - return *reinterpret_cast(ptr); + auto ptr = static_cast(this->pos) + this->stride * n; + return *reinterpret_cast(ptr); } template typename Slice::iterator &Slice::iterator::operator++() noexcept { - this->pos = static_cast(this->pos) + this->stride; - return *this; + this->pos = static_cast(this->pos) + this->stride; + return *this; } template typename Slice::iterator Slice::iterator::operator++(int) noexcept { - auto ret = iterator(*this); - this->pos = static_cast(this->pos) + this->stride; - return ret; + auto ret = iterator(*this); + this->pos = static_cast(this->pos) + this->stride; + return ret; } template typename Slice::iterator &Slice::iterator::operator--() noexcept { - this->pos = static_cast(this->pos) - this->stride; - return *this; + this->pos = static_cast(this->pos) - this->stride; + return *this; } template typename Slice::iterator Slice::iterator::operator--(int) noexcept { - auto ret = iterator(*this); - this->pos = static_cast(this->pos) - this->stride; - return ret; + auto ret = iterator(*this); + this->pos = static_cast(this->pos) - this->stride; + return ret; } template typename Slice::iterator &Slice::iterator::operator+=( typename Slice::iterator::difference_type n) noexcept { - this->pos = static_cast(this->pos) + this->stride * n; - return *this; + this->pos = static_cast(this->pos) + this->stride * n; + return *this; } template typename Slice::iterator &Slice::iterator::operator-=( typename Slice::iterator::difference_type n) noexcept { - this->pos = static_cast(this->pos) - this->stride * n; - return *this; + this->pos = static_cast(this->pos) - this->stride * n; + return *this; } template typename Slice::iterator Slice::iterator::operator+( typename Slice::iterator::difference_type n) const noexcept { - auto ret = iterator(*this); - ret.pos = static_cast(this->pos) + this->stride * n; - return ret; + auto ret = iterator(*this); + ret.pos = static_cast(this->pos) + this->stride * n; + return ret; } template typename Slice::iterator Slice::iterator::operator-( typename Slice::iterator::difference_type n) const noexcept { - auto ret = iterator(*this); - ret.pos = static_cast(this->pos) - this->stride * n; - return ret; + auto ret = iterator(*this); + ret.pos = static_cast(this->pos) - this->stride * n; + return ret; } template typename Slice::iterator::difference_type Slice::iterator::operator-(const iterator &other) const noexcept { - auto diff = std::distance(static_cast(other.pos), - static_cast(this->pos)); - return diff / this->stride; + auto diff = std::distance(static_cast(other.pos), + static_cast(this->pos)); + return diff / static_cast::iterator::difference_type>( + this->stride); } template bool Slice::iterator::operator==(const iterator &other) const noexcept { - return this->pos == other.pos; + return this->pos == other.pos; } template bool Slice::iterator::operator!=(const iterator &other) const noexcept { - return this->pos != other.pos; + return this->pos != other.pos; } template bool Slice::iterator::operator<(const iterator &other) const noexcept { - return this->pos < other.pos; + return this->pos < other.pos; } template bool Slice::iterator::operator<=(const iterator &other) const noexcept { - return this->pos <= other.pos; + return this->pos <= other.pos; } template bool Slice::iterator::operator>(const iterator &other) const noexcept { - return this->pos > other.pos; + return this->pos > other.pos; } template bool Slice::iterator::operator>=(const iterator &other) const noexcept { - return this->pos >= other.pos; + return this->pos >= other.pos; } template typename Slice::iterator Slice::begin() const noexcept { - iterator it; - it.pos = slicePtr(this); - it.stride = size_of(); - return it; + iterator it; + it.pos = slicePtr(this); + it.stride = size_of(); + return it; } template typename Slice::iterator Slice::end() const noexcept { - iterator it = this->begin(); - it.pos = static_cast(it.pos) + it.stride * this->size(); - return it; + iterator it = this->begin(); + it.pos = static_cast(it.pos) + it.stride * this->size(); + return it; } -template void Slice::swap(Slice &rhs) noexcept { - std::swap(*this, rhs); +template +void Slice::swap(Slice &rhs) noexcept { + std::swap(*this, rhs); } #endif // CXXBRIDGE1_RUST_SLICE #ifndef CXXBRIDGE1_RUST_BITCOPY_T #define CXXBRIDGE1_RUST_BITCOPY_T struct unsafe_bitcopy_t final { - explicit unsafe_bitcopy_t() = default; + explicit unsafe_bitcopy_t() = default; }; #endif // CXXBRIDGE1_RUST_BITCOPY_T #ifndef CXXBRIDGE1_RUST_VEC #define CXXBRIDGE1_RUST_VEC -template class Vec final { - public: - using value_type = T; - - Vec() noexcept; - Vec(std::initializer_list); - Vec(const Vec &); - Vec(Vec &&) noexcept; - ~Vec() noexcept; - - Vec &operator=(Vec &&) &noexcept; - Vec &operator=(const Vec &) &; - - std::size_t size() const noexcept; - bool empty() const noexcept; - const T *data() const noexcept; - T *data() noexcept; - std::size_t capacity() const noexcept; - - const T &operator[](std::size_t n) const noexcept; - const T &at(std::size_t n) const; - const T &front() const noexcept; - const T &back() const noexcept; - - T &operator[](std::size_t n) noexcept; - T &at(std::size_t n); - T &front() noexcept; - T &back() noexcept; - - void reserve(std::size_t new_cap); - void push_back(const T &value); - void push_back(T &&value); - template void emplace_back(Args &&...args); - void truncate(std::size_t len); - void clear(); - - using iterator = typename Slice::iterator; - iterator begin() noexcept; - iterator end() noexcept; - - using const_iterator = typename Slice::iterator; - const_iterator begin() const noexcept; - const_iterator end() const noexcept; - const_iterator cbegin() const noexcept; - const_iterator cend() const noexcept; - - void swap(Vec &) noexcept; - - Vec(unsafe_bitcopy_t, const Vec &) noexcept; - - private: - void reserve_total(std::size_t new_cap) noexcept; - void set_len(std::size_t len) noexcept; - void drop() noexcept; - - friend void swap(Vec &lhs, Vec &rhs) noexcept { lhs.swap(rhs); } - - std::array repr; +template +class Vec final { +public: + using value_type = T; + + Vec() noexcept; + Vec(std::initializer_list); + Vec(const Vec &); + Vec(Vec &&) noexcept; + ~Vec() noexcept; + + Vec &operator=(Vec &&) &noexcept; + Vec &operator=(const Vec &) &; + + std::size_t size() const noexcept; + bool empty() const noexcept; + const T *data() const noexcept; + T *data() noexcept; + std::size_t capacity() const noexcept; + + const T &operator[](std::size_t n) const noexcept; + const T &at(std::size_t n) const; + const T &front() const noexcept; + const T &back() const noexcept; + + T &operator[](std::size_t n) noexcept; + T &at(std::size_t n); + T &front() noexcept; + T &back() noexcept; + + void reserve(std::size_t new_cap); + void push_back(const T &value); + void push_back(T &&value); + template + void emplace_back(Args &&...args); + void truncate(std::size_t len); + void clear(); + + using iterator = typename Slice::iterator; + iterator begin() noexcept; + iterator end() noexcept; + + using const_iterator = typename Slice::iterator; + const_iterator begin() const noexcept; + const_iterator end() const noexcept; + const_iterator cbegin() const noexcept; + const_iterator cend() const noexcept; + + void swap(Vec &) noexcept; + + Vec(unsafe_bitcopy_t, const Vec &) noexcept; + +private: + void reserve_total(std::size_t new_cap) noexcept; + void set_len(std::size_t len) noexcept; + void drop() noexcept; + + friend void swap(Vec &lhs, Vec &rhs) noexcept { lhs.swap(rhs); } + + std::array repr; }; -template Vec::Vec(std::initializer_list init) : Vec{} { - this->reserve_total(init.size()); - std::move(init.begin(), init.end(), std::back_inserter(*this)); +template +Vec::Vec(std::initializer_list init) : Vec{} { + this->reserve_total(init.size()); + std::move(init.begin(), init.end(), std::back_inserter(*this)); } -template Vec::Vec(const Vec &other) : Vec() { - this->reserve_total(other.size()); - std::copy(other.begin(), other.end(), std::back_inserter(*this)); +template +Vec::Vec(const Vec &other) : Vec() { + this->reserve_total(other.size()); + std::copy(other.begin(), other.end(), std::back_inserter(*this)); } -template Vec::Vec(Vec &&other) noexcept : repr(other.repr) { - new (&other) Vec(); +template +Vec::Vec(Vec &&other) noexcept : repr(other.repr) { + new (&other) Vec(); } -template Vec::~Vec() noexcept { this->drop(); } +template +Vec::~Vec() noexcept { + this->drop(); +} -template Vec &Vec::operator=(Vec &&other) &noexcept { - this->drop(); - this->repr = other.repr; - new (&other) Vec(); - return *this; +template +Vec &Vec::operator=(Vec &&other) &noexcept { + this->drop(); + this->repr = other.repr; + new (&other) Vec(); + return *this; } -template Vec &Vec::operator=(const Vec &other) & { - if (this != &other) { - this->drop(); - new (this) Vec(other); - } - return *this; +template +Vec &Vec::operator=(const Vec &other) & { + if (this != &other) { + this->drop(); + new (this) Vec(other); + } + return *this; } -template bool Vec::empty() const noexcept { - return this->size() == 0; +template +bool Vec::empty() const noexcept { + return this->size() == 0; } -template T *Vec::data() noexcept { - return const_cast(const_cast *>(this)->data()); +template +T *Vec::data() noexcept { + return const_cast(const_cast *>(this)->data()); } template const T &Vec::operator[](std::size_t n) const noexcept { - assert(n < this->size()); - auto data = reinterpret_cast(this->data()); - return *reinterpret_cast(data + n * size_of()); + assert(n < this->size()); + auto data = reinterpret_cast(this->data()); + return *reinterpret_cast(data + n * size_of()); } -template const T &Vec::at(std::size_t n) const { - if (n >= this->size()) { - panic("rust::Vec index out of range"); - } - return (*this)[n]; +template +const T &Vec::at(std::size_t n) const { + if (n >= this->size()) { + panic("rust::Vec index out of range"); + } + return (*this)[n]; } -template const T &Vec::front() const noexcept { - assert(!this->empty()); - return (*this)[0]; +template +const T &Vec::front() const noexcept { + assert(!this->empty()); + return (*this)[0]; } -template const T &Vec::back() const noexcept { - assert(!this->empty()); - return (*this)[this->size() - 1]; +template +const T &Vec::back() const noexcept { + assert(!this->empty()); + return (*this)[this->size() - 1]; } -template T &Vec::operator[](std::size_t n) noexcept { - assert(n < this->size()); - auto data = reinterpret_cast(this->data()); - return *reinterpret_cast(data + n * size_of()); +template +T &Vec::operator[](std::size_t n) noexcept { + assert(n < this->size()); + auto data = reinterpret_cast(this->data()); + return *reinterpret_cast(data + n * size_of()); } -template T &Vec::at(std::size_t n) { - if (n >= this->size()) { - panic("rust::Vec index out of range"); - } - return (*this)[n]; +template +T &Vec::at(std::size_t n) { + if (n >= this->size()) { + panic("rust::Vec index out of range"); + } + return (*this)[n]; } -template T &Vec::front() noexcept { - assert(!this->empty()); - return (*this)[0]; +template +T &Vec::front() noexcept { + assert(!this->empty()); + return (*this)[0]; } -template T &Vec::back() noexcept { - assert(!this->empty()); - return (*this)[this->size() - 1]; +template +T &Vec::back() noexcept { + assert(!this->empty()); + return (*this)[this->size() - 1]; } -template void Vec::reserve(std::size_t new_cap) { - this->reserve_total(new_cap); +template +void Vec::reserve(std::size_t new_cap) { + this->reserve_total(new_cap); } -template void Vec::push_back(const T &value) { - this->emplace_back(value); +template +void Vec::push_back(const T &value) { + this->emplace_back(value); } -template void Vec::push_back(T &&value) { - this->emplace_back(std::move(value)); +template +void Vec::push_back(T &&value) { + this->emplace_back(std::move(value)); } template template void Vec::emplace_back(Args &&...args) { - auto size = this->size(); - this->reserve_total(size + 1); - ::new (reinterpret_cast(reinterpret_cast(this->data()) + - size * size_of())) - T(std::forward(args)...); - this->set_len(size + 1); + auto size = this->size(); + this->reserve_total(size + 1); + ::new (reinterpret_cast(reinterpret_cast(this->data()) + + size * size_of())) + T(std::forward(args)...); + this->set_len(size + 1); } -template void Vec::clear() { this->truncate(0); } +template +void Vec::clear() { + this->truncate(0); +} -template typename Vec::iterator Vec::begin() noexcept { - return Slice(this->data(), this->size()).begin(); +template +typename Vec::iterator Vec::begin() noexcept { + return Slice(this->data(), this->size()).begin(); } -template typename Vec::iterator Vec::end() noexcept { - return Slice(this->data(), this->size()).end(); +template +typename Vec::iterator Vec::end() noexcept { + return Slice(this->data(), this->size()).end(); } template typename Vec::const_iterator Vec::begin() const noexcept { - return this->cbegin(); + return this->cbegin(); } template typename Vec::const_iterator Vec::end() const noexcept { - return this->cend(); + return this->cend(); } template typename Vec::const_iterator Vec::cbegin() const noexcept { - return Slice(this->data(), this->size()).begin(); + return Slice(this->data(), this->size()).begin(); } template typename Vec::const_iterator Vec::cend() const noexcept { - return Slice(this->data(), this->size()).end(); + return Slice(this->data(), this->size()).end(); } -template void Vec::swap(Vec &rhs) noexcept { - using std::swap; - swap(this->repr, rhs.repr); +template +void Vec::swap(Vec &rhs) noexcept { + using std::swap; + swap(this->repr, rhs.repr); } template @@ -598,21 +644,21 @@ Vec::Vec(unsafe_bitcopy_t, const Vec &bits) noexcept : repr(bits.repr) {} #ifndef CXXBRIDGE1_RUST_ERROR #define CXXBRIDGE1_RUST_ERROR class Error final : public std::exception { - public: - Error(const Error &); - Error(Error &&) noexcept; - ~Error() noexcept override; +public: + Error(const Error &); + Error(Error &&) noexcept; + ~Error() noexcept override; - Error &operator=(const Error &) &; - Error &operator=(Error &&) &noexcept; + Error &operator=(const Error &) &; + Error &operator=(Error &&) &noexcept; - const char *what() const noexcept override; + const char *what() const noexcept override; - private: - Error() noexcept = default; - friend impl; - const char *msg; - std::size_t len; +private: + Error() noexcept = default; + friend impl; + const char *msg; + std::size_t len; }; #endif // CXXBRIDGE1_RUST_ERROR @@ -631,57 +677,69 @@ struct is_complete : std::true_type {}; #ifndef CXXBRIDGE1_LAYOUT #define CXXBRIDGE1_LAYOUT class layout { - template friend std::size_t size_of(); - template friend std::size_t align_of(); - template - static typename std::enable_if::value, - std::size_t>::type - do_size_of() { - return T::layout::size(); - } - template - static typename std::enable_if::value, - std::size_t>::type - do_size_of() { - return sizeof(T); - } - template - static typename std::enable_if::value, - std::size_t>::type - size_of() { - return do_size_of(); - } - template - static typename std::enable_if::value, - std::size_t>::type - do_align_of() { - return T::layout::align(); - } - template - static typename std::enable_if::value, - std::size_t>::type - do_align_of() { - return alignof(T); - } - template - static typename std::enable_if::value, - std::size_t>::type - align_of() { - return do_align_of(); - } + template + friend std::size_t size_of(); + template + friend std::size_t align_of(); + template + static typename std::enable_if::value, + std::size_t>::type + do_size_of() { + return T::layout::size(); + } + template + static typename std::enable_if::value, + std::size_t>::type + do_size_of() { + return sizeof(T); + } + template + static + typename std::enable_if::value, std::size_t>::type + size_of() { + return do_size_of(); + } + template + static typename std::enable_if::value, + std::size_t>::type + do_align_of() { + return T::layout::align(); + } + template + static typename std::enable_if::value, + std::size_t>::type + do_align_of() { + return alignof(T); + } + template + static + typename std::enable_if::value, std::size_t>::type + align_of() { + return do_align_of(); + } }; -template std::size_t size_of() { return layout::size_of(); } +template +std::size_t size_of() { + return layout::size_of(); +} -template std::size_t align_of() { return layout::align_of(); } +template +std::size_t align_of() { + return layout::align_of(); +} #endif // CXXBRIDGE1_LAYOUT #ifndef CXXBRIDGE1_RELOCATABLE #define CXXBRIDGE1_RELOCATABLE namespace detail { -template struct make_void { using type = void; }; +template +struct make_void { + using type = void; +}; -template using void_t = typename make_void::type; +template +using void_t = typename make_void::type; template class, typename...> struct detect : std::false_type {}; @@ -691,7 +749,8 @@ struct detect>, T, A...> : std::true_type {}; template