diff --git a/CMakeLists.txt b/CMakeLists.txt index 2709e6c..c2bd21e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -29,7 +29,7 @@ endif() find_package(Threads) include(GNUInstallDirs) -add_library(abieos STATIC abieos/src/abi.cpp abieos/src/crypto.cpp abieos/include/sysio/fpconv.c) +add_library(abieos STATIC abieos/src/abi.cpp abieos/src/crypto.cpp) target_include_directories(abieos PUBLIC abieos/include abieos/external/rapidjson/include) if(ABIEOS_NO_INT128) diff --git a/abieos b/abieos index 902311b..3bcc383 160000 --- a/abieos +++ b/abieos @@ -1 +1 @@ -Subproject commit 902311b1c3da1eca738cef453c33e0bb24b81b37 +Subproject commit 3bcc3838a1464e3d16cf899bc9bab4c6f7fb770a diff --git a/include/.clang-format b/include/.clang-format deleted file mode 100644 index b55bfd7..0000000 --- a/include/.clang-format +++ /dev/null @@ -1,76 +0,0 @@ -BasedOnStyle: LLVM -IndentWidth: 3 -UseTab: Never -ColumnLimit: 120 - ---- -Language: Cpp -# always align * and & to the type -DerivePointerAlignment: false -PointerAlignment: Left - -# regroup includes to these classes -IncludeCategories: - - Regex: '(<|"(eosio)/)' - Priority: 4 - - Regex: '(<|"(boost)/)' - Priority: 3 - - Regex: '(<|"(llvm|llvm-c|clang|clang-c)/' - Priority: 3 - - Regex: '<[[:alnum:]]+>' - Priority: 2 - - Regex: '.*' - Priority: 1 - -#IncludeBlocks: Regroup - -# set indent for public, private and protected -#AccessModifierOffset: 3 - -# make line continuations twice the normal indent -ContinuationIndentWidth: 6 - -# add missing namespace comments -FixNamespaceComments: true - -# add spaces to braced list i.e. int* foo = { 0, 1, 2 }; instead of int* foo = {0,1,2}; -Cpp11BracedListStyle: false -AlignAfterOpenBracket: Align -AlignConsecutiveAssignments: true -AlignConsecutiveDeclarations: true -AlignOperands: true -AlignTrailingComments: true -AllowShortCaseLabelsOnASingleLine: true -AllowShortFunctionsOnASingleLine: All -AllowShortBlocksOnASingleLine: true -#AllowShortIfStatementsOnASingleLine: WithoutElse -#AllowShortIfStatementsOnASingleLine: true -#AllowShortLambdasOnASingleLine: All -AllowShortLoopsOnASingleLine: true -AlwaysBreakTemplateDeclarations: true - -BinPackParameters: true -### use this with clang9 -BreakBeforeBraces: Custom -BraceWrapping: - #AfterCaseLabel: true - AfterClass: false - AfterControlStatement: false - AfterEnum: false - AfterFunction: false - AfterNamespace: false - AfterStruct: false - AfterUnion: false - AfterExternBlock: false - BeforeCatch: false - BeforeElse: false - -BreakConstructorInitializers: BeforeColon -CompactNamespaces: true -IndentCaseLabels: true -IndentPPDirectives: AfterHash -NamespaceIndentation: Inner -ReflowComments: true -SortIncludes: true -SortUsingDeclarations: true ---- diff --git a/include/eosio_OLD/abi.hpp b/include/eosio_OLD/abi.hpp deleted file mode 100644 index f541c06..0000000 --- a/include/eosio_OLD/abi.hpp +++ /dev/null @@ -1,423 +0,0 @@ -#pragma once - -#include "name.hpp" -#include "types.hpp" -#include -#include -#include -#include -#include -#include "fixed_bytes.hpp" -#include "crypto.hpp" -#include "varint.hpp" -#include "float.hpp" -#include "time.hpp" -#include "bytes.hpp" -#include "asset.hpp" - -#include "opaque.hpp" - -namespace eosio { - -enum class abi_error { - no_error, - - recursion_limit_reached, - invalid_nesting, - unknown_type, - missing_name, - redefined_type, - base_not_a_struct, - extension_typedef, - bad_abi -}; - -constexpr inline std::string_view convert_abi_error(eosio::abi_error e) { - switch (e) { - case abi_error::no_error: return "No error"; - case abi_error::recursion_limit_reached: return "Recursion limit reached"; - case abi_error::invalid_nesting: return "Invalid nesting"; - case abi_error::unknown_type: return "Unknown type"; - case abi_error::missing_name: return "Missing name"; - case abi_error::redefined_type: return "Redefined type"; - case abi_error::base_not_a_struct: return "Base not a struct"; - case abi_error::extension_typedef: return "Extension typedef"; - case abi_error::bad_abi: return "Bad ABI"; - default: return "internal failure"; - }; -} - -struct abi_serializer; - -template -struct might_not_exist { - T value{}; -}; - -template -void from_bin(might_not_exist& obj, S& stream) { - if (stream.remaining()) - return from_bin(obj.value, stream); -} - -template -void to_bin(const might_not_exist& obj, S& stream) { - return to_bin(obj.value, stream); -} - -template -void from_json(might_not_exist& obj, S& stream) { - return from_json(obj.value, stream); -} - -template -void to_json(const might_not_exist& val, S& stream) { - return to_json(val.value, stream); -} - -using abi_extensions_type = std::vector>>; - -struct type_def { - std::string new_type_name{}; - std::string type{}; -}; - -EOSIO_REFLECT(type_def, new_type_name, type); - -struct field_def { - std::string name{}; - std::string type{}; -}; - -EOSIO_REFLECT(field_def, name, type); - -struct struct_def { - std::string name{}; - std::string base{}; - std::vector fields{}; -}; - -EOSIO_REFLECT(struct_def, name, base, fields); - -struct action_def { - eosio::name name{}; - std::string type{}; - std::string ricardian_contract{}; -}; - -EOSIO_REFLECT(action_def, name, type, ricardian_contract); - -struct table_def { - eosio::name name{}; - std::string index_type{}; - std::vector key_names{}; - std::vector key_types{}; - std::string type{}; -}; - -EOSIO_REFLECT(table_def, name, index_type, key_names, key_types, type); - -struct clause_pair { - std::string id{}; - std::string body{}; -}; - -EOSIO_REFLECT(clause_pair, id, body); - -struct error_message { - uint64_t error_code{}; - std::string error_msg{}; -}; - -EOSIO_REFLECT(error_message, error_code, error_msg); - -struct variant_def { - std::string name{}; - std::vector types{}; -}; - -EOSIO_REFLECT(variant_def, name, types); - -struct action_result_def { - eosio::name name{}; - std::string result_type{}; -}; - -EOSIO_REFLECT(action_result_def, name, result_type); - -struct primary_key_index_def { - eosio::name name{}; - std::string type; -}; - -EOSIO_REFLECT(primary_key_index_def, name, type); - -struct secondary_index_def { - std::string type; -}; - -EOSIO_REFLECT(secondary_index_def, type); - -struct kv_table_entry_def { - std::string type; - primary_key_index_def primary_index; - std::map secondary_indices; -}; - -EOSIO_REFLECT(kv_table_entry_def, type, primary_index, secondary_indices); - -struct abi_def { - std::string version{}; - std::vector types{}; - std::vector structs{}; - std::vector actions{}; - std::vector tables{}; - std::vector ricardian_clauses{}; - std::vector error_messages{}; - abi_extensions_type abi_extensions{}; - might_not_exist> variants{}; - might_not_exist> action_results{}; - might_not_exist> kv_tables{}; -}; - -EOSIO_REFLECT(abi_def, version, types, structs, actions, tables, ricardian_clauses, error_messages, abi_extensions, - variants, action_results, kv_tables); - -struct abi_type; - -struct abi_field { - std::string name; - const abi_type* type; -}; - -struct abi_type { - std::string name; - - struct builtin {}; - using alias_def = std::string; - struct alias { - abi_type* type; - }; - struct optional { - abi_type* type; - }; - struct extension { - abi_type* type; - }; - struct array { - abi_type* type; - }; - struct szarray { - abi_type* type; - }; - struct struct_ { - abi_type* base = nullptr; - std::vector fields; - }; - using variant = std::vector; - std::variant _data; - const abi_serializer* ser = nullptr; - - template - abi_type(std::string name, T&& arg, const abi_serializer* ser) - : name(std::move(name)), _data(std::forward(arg)), ser(ser) {} - abi_type(const abi_type&) = delete; - abi_type& operator=(const abi_type&) = delete; - - // result json_to_bin(std::vector& bin, std::string_view json); - const abi_type* optional_of() const { - if (auto* t = std::get_if(&_data)) - return t->type; - else - return nullptr; - } - const abi_type* extension_of() const { - if (auto* t = std::get_if(&_data)) - return t->type; - else - return nullptr; - } - const abi_type* array_of() const { - if (auto* t = std::get_if(&_data)) - return t->type; - else - return nullptr; - } - const abi_type* szarray_of() const { - if (auto* t = std::get_if(&_data)) - return t->type; - else - return nullptr; - } - const struct_* as_struct() const { return std::get_if(&_data); } - const variant* as_variant() const { return std::get_if(&_data); } - - const abi_serializer* get_serializer() const { - const alias* a = std::get_if(&_data); - if (a) { - return a->type->get_serializer(); - } - return ser; - } - - std::string bin_to_json( - input_stream& bin, std::function f = [] {}) const; - std::vector json_to_bin( - std::string_view json, std::function f = [] {}) const; - std::vector json_to_bin_reorderable( - std::string_view json, std::function f = [] {}) const; -}; - -struct abi { - std::map action_types; - std::map table_types; - std::map kv_tables; - std::map abi_types; - std::map action_result_types; - const abi_type* get_type(const std::string& name); - - // Adds a type to the abi. Has no effect if the type is already present. - // If the type is a struct, all members will be added recursively. - // Exception Safety: basic. If add_type fails, some objects may have - // an incomplete list of fields. - template - abi_type* add_type(); -}; - -void convert(const abi_def& def, abi&); -void convert(const abi& def, abi_def&); - -extern const abi_serializer* const object_abi_serializer; -extern const abi_serializer* const variant_abi_serializer; -extern const abi_serializer* const array_abi_serializer; -extern const abi_serializer* const szarray_abi_serializer; -extern const abi_serializer* const extension_abi_serializer; -extern const abi_serializer* const optional_abi_serializer; - -using basic_abi_types = - std::tuple; - -namespace detail { - template - constexpr bool contains(std::tuple*) { - return (std::is_same_v || ...); - } -} // namespace detail - -template -constexpr bool is_basic_abi_type(T*) { - return detail::contains((basic_abi_types*)nullptr); -} - -template -constexpr bool is_basic_abi_type_v = is_basic_abi_type((T*)nullptr); - -template -auto add_type(abi& a, T*) -> std::enable_if_t && !is_basic_abi_type_v, abi_type*> { - std::string name = get_type_name((T*)nullptr); - auto [iter, inserted] = a.abi_types.try_emplace(name, name, abi_type::struct_{}, object_abi_serializer); - if (!inserted) - return &iter->second; - auto& s = std::get(iter->second._data); - for_each_field([&](const char* name, auto&& member) { - auto member_type = a.add_type>(); - s.fields.push_back({ name, member_type }); - }); - return &iter->second; -} - -template -auto add_type(abi& a, T* t) -> std::enable_if_t, abi_type*> { - auto iter = a.abi_types.find(get_type_name(t)); - check(iter != a.abi_types.end(), convert_abi_error(abi_error::unknown_type)); - return &iter->second; -} - -template -abi_type* add_type(abi& a, std::vector*) { - auto element_type = a.add_type(); - check(!(element_type->optional_of() || element_type->array_of() || element_type->extension_of()), - convert_abi_error(abi_error::invalid_nesting)); - std::string name = get_type_name((std::vector*)nullptr); - auto [iter, inserted] = a.abi_types.try_emplace(name, name, abi_type::array{ element_type }, array_abi_serializer); - return &iter->second; -} - -template -auto add_type(abi& a, std::variant*) -> std::enable_if_t>, abi_type*> { - abi_type::variant types; - ( - [&](auto* t) { - auto type = add_type(a, t); - types.push_back({ type->name, type }); - }((T*)nullptr), - ...); - std::string name = get_type_name((std::variant*)nullptr); - - auto [iter, inserted] = a.abi_types.try_emplace(name, name, std::move(types), variant_abi_serializer); - return &iter->second; -} - -template -abi_type* add_type(abi& a, opaque*) { - a.add_type(); - auto iter = a.abi_types.find("bytes"); - check(iter != a.abi_types.end(), convert_abi_error(abi_error::unknown_type)); - return &iter->second; -} - -template -abi_type* add_type(abi& a, std::optional*) { - auto element_type = a.add_type(); - check(!(element_type->optional_of() || element_type->array_of() || element_type->extension_of()), - convert_abi_error(abi_error::invalid_nesting)); - std::string name = get_type_name((std::optional*)nullptr); - auto [iter, inserted] = - a.abi_types.try_emplace(name, name, abi_type::optional{ element_type }, optional_abi_serializer); - return &iter->second; -} - -template -abi_type* add_type(abi& a, might_not_exist*) { - auto element_type = a.add_type(); - check(!element_type->extension_of(), convert_abi_error(abi_error::invalid_nesting)); - std::string name = element_type->name + "$"; - auto [iter, inserted] = - a.abi_types.try_emplace(name, name, abi_type::extension{ element_type }, extension_abi_serializer); - return &iter->second; -} - -template -abi_type* abi::add_type() { - using eosio::add_type; - return add_type(*this, (T*)nullptr); -} - -template -void to_json_write_helper(const T& field, const std::string_view field_name, const bool need_comma, S& stream) { - if (need_comma) { - stream.write(','); - } - to_json(field_name, stream); - stream.write(':'); - to_json(field, stream); -} - -template -void to_json(const abi_def& def, S& stream) { - stream.write('{'); - to_json_write_helper(def.version, "version", false, stream); - to_json_write_helper(def.types, "types", true, stream); - to_json_write_helper(def.structs, "structs", true, stream); - to_json_write_helper(def.actions, "actions", true, stream); - to_json_write_helper(def.tables, "tables", true, stream); - to_json_write_helper(def.ricardian_clauses, "ricardian_clauses", true, stream); - to_json_write_helper(def.error_messages, "error_messages", true, stream); - to_json_write_helper(def.variants.value, "variants", true, stream); - to_json_write_helper(def.action_results.value, "action_results", true, stream); - stream.write('}'); -} -} // namespace eosio diff --git a/include/eosio_OLD/asset.hpp b/include/eosio_OLD/asset.hpp deleted file mode 100644 index 9281752..0000000 --- a/include/eosio_OLD/asset.hpp +++ /dev/null @@ -1,458 +0,0 @@ -#pragma once - -#include "chain_conversions.hpp" -#include "check.hpp" -#include "reflection.hpp" -#include "symbol.hpp" - -#include -#include - -namespace eosio { - -char* write_decimal(char* begin, char* end, bool dry_run, uint64_t number, uint8_t num_decimal_places, bool negative); - -/** - * @defgroup asset Asset - * @ingroup core - * @brief Defines C++ API for managing assets - */ - -/** - * Stores information for owner of asset - * - * @ingroup asset - */ -struct asset { - /** - * The amount of the asset - */ - int64_t amount = 0; - - /** - * The symbol name of the asset - */ - eosio::symbol symbol; - - /** - * Maximum amount possible for this asset. It's capped to 2^62 - 1 - */ - static constexpr int64_t max_amount = (1LL << 62) - 1; - - asset() {} - - /** - * Construct a new asset given the symbol name and the amount - * - * @param a - The amount of the asset - * @param s - The name of the symbol - */ - asset(int64_t a, class symbol s) : amount(a), symbol{ s } { - eosio::check(is_amount_within_range(), "magnitude of asset amount must be less than 2^62"); - eosio::check(symbol.is_valid(), "invalid symbol name"); - } - - /** - * Check if the amount doesn't exceed the max amount - * - * @return true - if the amount doesn't exceed the max amount - * @return false - otherwise - */ - bool is_amount_within_range() const { return -max_amount <= amount && amount <= max_amount; } - - /** - * Check if the asset is valid. %A valid asset has its amount <= max_amount and its symbol name valid - * - * @return true - if the asset is valid - * @return false - otherwise - */ - bool is_valid() const { return is_amount_within_range() && symbol.is_valid(); } - - /** - * Set the amount of the asset - * - * @param a - New amount for the asset - */ - void set_amount(int64_t a) { - amount = a; - eosio::check(is_amount_within_range(), "magnitude of asset amount must be less than 2^62"); - } - - /// @cond OPERATORS - - /** - * Unary minus operator - * - * @return asset - New asset with its amount is the negative amount of this asset - */ - asset operator-() const { - asset r = *this; - r.amount = -r.amount; - return r; - } - - /** - * Subtraction assignment operator - * - * @param a - Another asset to subtract this asset with - * @return asset& - Reference to this asset - * @post The amount of this asset is subtracted by the amount of asset a - */ - asset& operator-=(const asset& a) { - eosio::check(a.symbol == symbol, "attempt to subtract asset with different symbol"); - amount -= a.amount; - eosio::check(-max_amount <= amount, "subtraction underflow"); - eosio::check(amount <= max_amount, "subtraction overflow"); - return *this; - } - - /** - * Addition Assignment operator - * - * @param a - Another asset to subtract this asset with - * @return asset& - Reference to this asset - * @post The amount of this asset is added with the amount of asset a - */ - asset& operator+=(const asset& a) { - eosio::check(a.symbol == symbol, "attempt to add asset with different symbol"); - amount += a.amount; - eosio::check(-max_amount <= amount, "addition underflow"); - eosio::check(amount <= max_amount, "addition overflow"); - return *this; - } - - /** - * Addition operator - * - * @param a - The first asset to be added - * @param b - The second asset to be added - * @return asset - New asset as the result of addition - */ - inline friend asset operator+(const asset& a, const asset& b) { - asset result = a; - result += b; - return result; - } - - /** - * Subtraction operator - * - * @param a - The asset to be subtracted - * @param b - The asset used to subtract - * @return asset - New asset as the result of subtraction of a with b - */ - inline friend asset operator-(const asset& a, const asset& b) { - asset result = a; - result -= b; - return result; - } - - /** - * Multiplication assignment operator, with a number - * - * @details Multiplication assignment operator. Multiply the amount of this asset with a number and then assign the - * value to itself. - * @param a - The multiplier for the asset's amount - * @return asset - Reference to this asset - * @post The amount of this asset is multiplied by a - */ -#ifndef ABIEOS_NO_INT128 - asset& operator*=(int64_t a) { - __int128 tmp = (__int128)amount * (__int128)a; - eosio::check(tmp <= max_amount, "multiplication overflow"); - eosio::check(tmp >= -max_amount, "multiplication underflow"); - amount = (int64_t)tmp; - return *this; - } -#endif - - /** - * Multiplication operator, with a number proceeding - * - * @brief Multiplication operator, with a number proceeding - * @param a - The asset to be multiplied - * @param b - The multiplier for the asset's amount - * @return asset - New asset as the result of multiplication - */ -#ifndef ABIEOS_NO_INT128 - friend asset operator*(const asset& a, int64_t b) { - asset result = a; - result *= b; - return result; - } -#endif - - /** - * Multiplication operator, with a number preceeding - * - * @param a - The multiplier for the asset's amount - * @param b - The asset to be multiplied - * @return asset - New asset as the result of multiplication - */ -#ifndef ABIEOS_NO_INT128 - friend asset operator*(int64_t b, const asset& a) { - asset result = a; - result *= b; - return result; - } -#endif - - /** - * @brief Division assignment operator, with a number - * - * @details Division assignment operator. Divide the amount of this asset with a number and then assign the value to - * itself. - * @param a - The divisor for the asset's amount - * @return asset - Reference to this asset - * @post The amount of this asset is divided by a - */ - asset& operator/=(int64_t a) { - eosio::check(a != 0, "divide by zero"); - eosio::check(!(amount == std::numeric_limits::min() && a == -1), "signed division overflow"); - amount /= a; - return *this; - } - - /** - * Division operator, with a number proceeding - * - * @param a - The asset to be divided - * @param b - The divisor for the asset's amount - * @return asset - New asset as the result of division - */ - friend asset operator/(const asset& a, int64_t b) { - asset result = a; - result /= b; - return result; - } - - /** - * Division operator, with another asset - * - * @param a - The asset which amount acts as the dividend - * @param b - The asset which amount acts as the divisor - * @return int64_t - the resulted amount after the division - * @pre Both asset must have the same symbol - */ - friend int64_t operator/(const asset& a, const asset& b) { - eosio::check(b.amount != 0, "divide by zero"); - eosio::check(a.symbol == b.symbol, "comparison of assets with different symbols is not allowed"); - return a.amount / b.amount; - } - - /** - * Equality operator - * - * @param a - The first asset to be compared - * @param b - The second asset to be compared - * @return true - if both asset has the same amount - * @return false - otherwise - * @pre Both asset must have the same symbol - */ - friend bool operator==(const asset& a, const asset& b) { - eosio::check(a.symbol == b.symbol, "comparison of assets with different symbols is not allowed"); - return a.amount == b.amount; - } - - /** - * Inequality operator - * - * @param a - The first asset to be compared - * @param b - The second asset to be compared - * @return true - if both asset doesn't have the same amount - * @return false - otherwise - * @pre Both asset must have the same symbol - */ - friend bool operator!=(const asset& a, const asset& b) { return !(a == b); } - - /** - * Less than operator - * - * @param a - The first asset to be compared - * @param b - The second asset to be compared - * @return true - if the first asset's amount is less than the second asset amount - * @return false - otherwise - * @pre Both asset must have the same symbol - */ - friend bool operator<(const asset& a, const asset& b) { - eosio::check(a.symbol == b.symbol, "comparison of assets with different symbols is not allowed"); - return a.amount < b.amount; - } - - /** - * Less or equal to operator - * - * @param a - The first asset to be compared - * @param b - The second asset to be compared - * @return true - if the first asset's amount is less or equal to the second asset amount - * @return false - otherwise - * @pre Both asset must have the same symbol - */ - friend bool operator<=(const asset& a, const asset& b) { - eosio::check(a.symbol == b.symbol, "comparison of assets with different symbols is not allowed"); - return a.amount <= b.amount; - } - - /** - * Greater than operator - * - * @param a - The first asset to be compared - * @param b - The second asset to be compared - * @return true - if the first asset's amount is greater than the second asset amount - * @return false - otherwise - * @pre Both asset must have the same symbol - */ - friend bool operator>(const asset& a, const asset& b) { - eosio::check(a.symbol == b.symbol, "comparison of assets with different symbols is not allowed"); - return a.amount > b.amount; - } - - /** - * Greater or equal to operator - * - * @param a - The first asset to be compared - * @param b - The second asset to be compared - * @return true - if the first asset's amount is greater or equal to the second asset amount - * @return false - otherwise - * @pre Both asset must have the same symbol - */ - friend bool operator>=(const asset& a, const asset& b) { - eosio::check(a.symbol == b.symbol, "comparison of assets with different symbols is not allowed"); - return a.amount >= b.amount; - } - - /// @endcond - - /** - * %asset to std::string - * - * @brief %asset to std::string - */ - std::string to_string() const { return asset_to_string(amount, symbol.value); } -}; - -EOSIO_REFLECT(asset, amount, symbol); - -template -inline void from_string(asset& result, S& stream) { - int64_t amount; - uint64_t sym; - check(eosio::string_to_asset(amount, sym, stream.pos, stream.end, true), - convert_stream_error(eosio::stream_error::invalid_asset_format)); - result = asset{ amount, symbol{ sym } }; -} - -template -void to_json(const asset& obj, S& stream) { - to_json(asset_to_string(obj.amount, obj.symbol.value), stream); -} - -template -void from_json(asset& obj, S& stream) { - auto s = stream.get_string(); - check(string_to_asset(obj.amount, obj.symbol.value, s.data(), s.data() + s.size()), - convert_json_error(eosio::from_json_error::expected_symbol_code)); -} - -/** - * Extended asset which stores the information of the owner of the asset - * - * @ingroup asset - */ -struct extended_asset { - /** - * The asset - */ - asset quantity; - - /** - * The owner of the asset - */ - name contract; - - /** - * Get the extended symbol of the asset - * - * @return extended_symbol - The extended symbol of the asset - */ - extended_symbol get_extended_symbol() const { return extended_symbol{ quantity.symbol, contract }; } - - /** - * Default constructor - */ - extended_asset() = default; - - /** - * Construct a new extended asset given the amount and extended symbol - */ - extended_asset(int64_t v, extended_symbol s) : quantity(v, s.get_symbol()), contract(s.get_contract()) {} - /** - * Construct a new extended asset given the asset and owner name - */ - extended_asset(asset a, name c) : quantity(a), contract(c) {} - - /// @cond OPERATORS - - // Unary minus operator - extended_asset operator-() const { return { -quantity, contract }; } - - // Subtraction operator - friend extended_asset operator-(const extended_asset& a, const extended_asset& b) { - eosio::check(a.contract == b.contract, "type mismatch"); - return { a.quantity - b.quantity, a.contract }; - } - - // Addition operator - friend extended_asset operator+(const extended_asset& a, const extended_asset& b) { - eosio::check(a.contract == b.contract, "type mismatch"); - return { a.quantity + b.quantity, a.contract }; - } - - /// Addition operator. - friend extended_asset& operator+=(extended_asset& a, const extended_asset& b) { - eosio::check(a.contract == b.contract, "type mismatch"); - a.quantity += b.quantity; - return a; - } - - /// Subtraction operator. - friend extended_asset& operator-=(extended_asset& a, const extended_asset& b) { - eosio::check(a.contract == b.contract, "type mismatch"); - a.quantity -= b.quantity; - return a; - } - - /// Less than operator - friend bool operator<(const extended_asset& a, const extended_asset& b) { - eosio::check(a.contract == b.contract, "type mismatch"); - return a.quantity < b.quantity; - } - - /// Comparison operator - friend bool operator==(const extended_asset& a, const extended_asset& b) { - return std::tie(a.quantity, a.contract) == std::tie(b.quantity, b.contract); - } - - /// Comparison operator - friend bool operator!=(const extended_asset& a, const extended_asset& b) { - return std::tie(a.quantity, a.contract) != std::tie(b.quantity, b.contract); - } - - /// Comparison operator - friend bool operator<=(const extended_asset& a, const extended_asset& b) { - eosio::check(a.contract == b.contract, "type mismatch"); - return a.quantity <= b.quantity; - } - - /// Comparison operator - friend bool operator>=(const extended_asset& a, const extended_asset& b) { - eosio::check(a.contract == b.contract, "type mismatch"); - return a.quantity >= b.quantity; - } - - std::string to_string() const { return quantity.to_string() + "@" + contract.to_string(); } - /// @endcond -}; - -EOSIO_REFLECT(extended_asset, quantity, contract); -} // namespace eosio diff --git a/include/eosio_OLD/bytes.hpp b/include/eosio_OLD/bytes.hpp deleted file mode 100644 index a0f3809..0000000 --- a/include/eosio_OLD/bytes.hpp +++ /dev/null @@ -1,27 +0,0 @@ -#pragma once - -#include "from_json.hpp" -#include "to_json.hpp" -#include "operators.hpp" -#include - -namespace eosio { - -struct bytes { - std::vector data; -}; - -EOSIO_REFLECT(bytes, data); -EOSIO_COMPARE(bytes); - -template -void from_json(bytes& obj, S& stream) { - return eosio::from_json_hex(obj.data, stream); -} - -template -void to_json(const bytes& obj, S& stream) { - return eosio::to_json_hex(obj.data.data(), obj.data.size(), stream); -} - -} // namespace eosio diff --git a/include/eosio_OLD/chain_conversions.hpp b/include/eosio_OLD/chain_conversions.hpp deleted file mode 100644 index 42c3353..0000000 --- a/include/eosio_OLD/chain_conversions.hpp +++ /dev/null @@ -1,450 +0,0 @@ -#pragma once - -#include "stream.hpp" -#include -#include -#include -#include -#include -#include - -namespace eosio { - -// TODO remove in c++20 -namespace { -using days = std::chrono::duration - , std::chrono::hours::period>>; - -using weeks = std::chrono::duration - , days::period>>; - -using years = std::chrono::duration - , days::period>>; - -using months = std::chrono::duration - >>; - -struct day { - inline explicit day(uint32_t d) : d(d) {} - uint32_t d; -}; -struct month { - inline explicit month(uint32_t m) : m(m) {} - uint32_t m; -}; -struct month_day { - inline month_day( eosio::month m, eosio::day d ) : m(m), d(d) {} - inline auto month() const { return m; } - inline auto day() const { return d; } - struct month m; - struct day d; -}; -struct year { - inline explicit year( uint32_t y ) - : y(y) {} - uint32_t y; -}; - -template -using sys_time = std::chrono::time_point; - -using sys_days = sys_time; -using sys_seconds = sys_time; - -typedef year year_t; -typedef month month_t; -typedef day day_t; -struct year_month_day { - inline auto from_days( days ds ) { - const auto z = ds.count() + 719468; - const auto era = (z >= 0 ? z : z - 146096) / 146097; - const auto doe = static_cast(z - era * 146097); - const auto yoe = (doe - doe/1460 + doe/36524 - doe/146096) / 365; - const auto y = static_cast(yoe) + era * 400; - const auto doy = doe - (365 * yoe + yoe/4 - yoe/100); - const auto mp = (5*doy + 2)/153; - const auto d = doy - (153*mp+2)/5 + 1; - const auto m = mp < 10 ? mp+3 : mp-9; - return year_month_day{year_t{static_cast(y + (m <= 2))}, month_t(m), day_t(d)}; - } - inline auto to_days() const { - const auto _y = static_cast(y.y) - (m.m <= month_t{2}.m); - const auto _m = static_cast(m.m); - const auto _d = static_cast(d.d); - const auto era = (_y >= 0 ? _y : _y-399) / 400; - const auto yoe = static_cast(_y - era * 400); - const auto doy = (153*(_m > 2 ? _m-3 : _m+9) + 2)/5 + _d-1; - const auto doe = yoe * 365 + yoe/4 -yoe/100 + doy; - return days{era * 146097 + static_cast(doe) - 719468}; - } - inline year_month_day(const year_t& y, const month_t& m, const day_t& d) - : y(y), m(m), d(d) {} - inline year_month_day(const year_month_day&) = default; - inline year_month_day(year_month_day&&) = default; - inline year_month_day(sys_days ds) - : year_month_day(from_days(ds.time_since_epoch())) {} - inline auto year() const { return y.y; } - inline auto month() const { return m.m; } - inline auto day() const { return d.d; } - year_t y; - month_t m; - day_t d; -}; -} - -inline constexpr uint64_t char_to_name_digit(char c) { - if (c >= 'a' && c <= 'z') - return (c - 'a') + 6; - if (c >= '1' && c <= '5') - return (c - '1') + 1; - return 0; -} - -inline constexpr uint64_t string_to_name(const char* str, int size) { - uint64_t name = 0; - int i = 0; - for (; i < size && i < 12; ++i) name |= (char_to_name_digit(str[i]) & 0x1f) << (64 - 5 * (i + 1)); - if (i < size) - name |= char_to_name_digit(str[i]) & 0x0F; - return name; -} - -inline constexpr uint64_t string_to_name(const char* str) { - int len = 0; - while (str[len]) ++len; - return string_to_name(str, len); -} - -inline constexpr uint64_t string_to_name(std::string_view str) { return string_to_name(str.data(), str.size()); } - -inline uint64_t string_to_name(const std::string& str) { return string_to_name(str.data(), str.size()); } - -constexpr inline bool is_valid_char(char c) { - return (c >= 'a' && c <= 'z') || - (c >= '1' && c <= '5') || - (c == '.'); -} - -template -constexpr inline uint64_t char_to_name_digit_strict() { - static_assert(is_valid_char(C), "character is not for an eosio name"); - if constexpr (C >= 'a' && C <= 'z') - return (C - 'a') + 6; - else if constexpr (C >= '1' && C <= '5') - return (C - '1') + 1; - else if constexpr (C == '.') - return 0; -} - -[[nodiscard]] inline constexpr bool char_to_name_digit_strict(char c, uint64_t& result) { - if (c >= 'a' && c <= 'z') { - result = (c - 'a') + 6; - return true; - } - if (c >= '1' && c <= '5') { - result = (c - '1') + 1; - return true; - } - if (c == '.') { - result = 0; - return true; - } - else { - return false; - } -} - -template -constexpr inline uint64_t string_to_name_strict_impl() { - if constexpr (N == 12) - static_assert((char_to_name_digit_strict() & 0xf) == char_to_name_digit_strict(), - "eosio name 13th character cannot be a letter after j"); - if constexpr (sizeof...(Rest) > 0) - return string_to_name_strict_impl() & 0x1f) << (64 - 5 * (N+1)), Rest...>(); - else - return ValueSoFar | (char_to_name_digit_strict() & 0x1f) << (64 + (N == 12) - 5 * (N+1)); -} - -template -constexpr inline uint64_t string_to_name_strict() { - static_assert(sizeof...(Str) <= 13, "eosio name string is too long"); - if constexpr (sizeof...(Str) == 0) - return 0; - else - return string_to_name_strict_impl<0, 0, Str...>(); -} - -// std::optional is killing constexpr'ness -namespace detail { - struct simple_optional { - explicit constexpr inline simple_optional( stream_error e ) : valid(e) {} - explicit constexpr inline simple_optional( uint64_t v ) : val(v) {} - explicit constexpr inline operator bool() const { return valid == stream_error::no_error; } - constexpr inline auto value() const { return val; } - stream_error valid = stream_error::no_error; - uint64_t val = 0; - }; -} - -[[nodiscard]] constexpr inline detail::simple_optional try_string_to_name_strict(std::string_view str) { - uint64_t name = 0; - unsigned i = 0; - for (; i < str.size() && i < 12; ++i) { - uint64_t x = 0; - if (!char_to_name_digit_strict(str[i], x)) return detail::simple_optional{stream_error::invalid_name_char}; - name |= (x & 0x1f) << (64 - 5 * (i + 1)); - } - if (i < str.size() && i == 12) { - uint64_t x = 0; - if (!char_to_name_digit_strict(str[i], x)) return detail::simple_optional{stream_error::invalid_name_char}; - - if(x != (x & 0xf)) return detail::simple_optional{stream_error::invalid_name_char13}; - name |= x; - ++i; - } - if(i < str.size()) return detail::simple_optional{stream_error::name_too_long}; - return detail::simple_optional{name}; -} - -constexpr inline uint64_t string_to_name_strict(std::string_view str) { - if(auto r = try_string_to_name_strict(str)) return r.val; - else check(false, convert_stream_error(r.valid)); - __builtin_unreachable(); -} - -inline std::string name_to_string(uint64_t name) { - static const char* charmap = ".12345abcdefghijklmnopqrstuvwxyz"; - std::string str(13, '.'); - - uint64_t tmp = name; - for (uint32_t i = 0; i <= 12; ++i) { - char c = charmap[tmp & (i == 0 ? 0x0f : 0x1f)]; - str[12 - i] = c; - tmp >>= (i == 0 ? 4 : 5); - } - - const auto last = str.find_last_not_of('.'); - return str.substr(0, last + 1); -} - -inline std::string microseconds_to_str(uint64_t microseconds) { - std::string result; - - auto append_uint = [&result](uint32_t value, int digits) { - char s[20]; - char* ch = s; - while (digits--) { - *ch++ = '0' + (value % 10); - value /= 10; - }; - std::reverse(s, ch); - result.insert(result.end(), s, ch); - }; - - std::chrono::microseconds us{ microseconds }; - sys_days sd(std::chrono::floor(us)); - auto ymd = year_month_day{ sd }; - uint32_t ms = (std::chrono::floor(us) - sd.time_since_epoch()).count(); - us -= sd.time_since_epoch(); - append_uint((int)ymd.year(), 4); - result.push_back('-'); - append_uint((unsigned)ymd.month(), 2); - result.push_back('-'); - append_uint((unsigned)ymd.day(), 2); - result.push_back('T'); - append_uint(ms / 3600000 % 60, 2); - result.push_back(':'); - append_uint(ms / 60000 % 60, 2); - result.push_back(':'); - append_uint(ms / 1000 % 60, 2); - result.push_back('.'); - append_uint(ms % 1000, 3); - return result; -} - -[[nodiscard]] inline bool string_to_utc_seconds(uint32_t& result, const char*& s, const char* end, bool eat_fractional, - bool require_end) { - auto parse_uint = [&](uint32_t& result, int digits) { - result = 0; - while (digits--) { - if (s != end && *s >= '0' && *s <= '9') - result = result * 10 + *s++ - '0'; - else - return false; - } - return true; - }; - uint32_t y, m, d, h, min, sec; - if (!parse_uint(y, 4)) - return false; - if (s == end || *s++ != '-') - return false; - if (!parse_uint(m, 2)) - return false; - if (s == end || *s++ != '-') - return false; - if (!parse_uint(d, 2)) - return false; - if (s == end || *s++ != 'T') - return false; - if (!parse_uint(h, 2)) - return false; - if (s == end || *s++ != ':') - return false; - if (!parse_uint(min, 2)) - return false; - if (s == end || *s++ != ':') - return false; - if (!parse_uint(sec, 2)) - return false; - result = sys_days(year_month_day{year_t{y}, month_t{m}, day_t{d}}.to_days()).time_since_epoch().count() * 86400 + h * 3600 + min * 60 + sec; - if (eat_fractional && s != end && *s == '.') { - ++s; - while (s != end && *s >= '0' && *s <= '9') ++s; - } - return s == end || !require_end; -} - -[[nodiscard]] inline bool string_to_utc_seconds(uint32_t& result, const char* s, const char* end) { - return string_to_utc_seconds(result, s, end, true, true); -} - -[[nodiscard]] inline bool string_to_utc_microseconds(uint64_t& result, const char*& s, const char* end, - bool require_end) { - uint32_t sec; - if (!string_to_utc_seconds(sec, s, end, false, false)) - return false; - result = sec * 1000000ull; - if (s == end) - return true; - if (*s != '.') - return !require_end; - ++s; - uint32_t scale = 100000; - while (scale >= 1 && s != end && *s >= '0' && *s <= '9') { - result += (*s++ - '0') * scale; - scale /= 10; - } - return s == end || !require_end; -} - -[[nodiscard]] inline bool string_to_utc_microseconds(uint64_t& result, const char* s, const char* end) { - return string_to_utc_microseconds(result, s, end, true); -} - -[[nodiscard]] inline bool string_to_symbol_code(uint64_t& result, const char*& pos, const char* end, bool require_end) { - while (pos != end && *pos == ' ') ++pos; - result = 0; - uint32_t i = 0; - while (pos != end && *pos >= 'A' && *pos <= 'Z') { - if (i >= 7) - return false; - result |= uint64_t(*pos++) << (8 * i++); - } - return i && (pos == end || !require_end); -} - -[[nodiscard]] inline bool string_to_symbol_code(uint64_t& result, const char* pos, const char* end) { - return string_to_symbol_code(result, pos, end, true); -} - -inline std::string symbol_code_to_string(uint64_t v) { - std::string result; - while (v > 0) { - result += char(v & 0xFF); - v >>= 8; - } - return result; -} - -[[nodiscard]] inline bool string_to_symbol(uint64_t& result, uint8_t precision, const char*& pos, const char* end, - bool require_end) { - if (!eosio::string_to_symbol_code(result, pos, end, require_end)) - return false; - result = (result << 8) | precision; - return true; -} - -[[nodiscard]] inline bool string_to_symbol(uint64_t& result, const char*& pos, const char* end, bool require_end) { - uint8_t precision = 0; - bool found = false; - while (pos != end && *pos >= '0' && *pos <= '9') { - precision = precision * 10 + (*pos - '0'); - found = true; - ++pos; - } - if (!found || pos == end || *pos++ != ',') - return false; - return string_to_symbol(result, precision, pos, end, require_end); -} - -[[nodiscard]] inline bool string_to_symbol(uint64_t& result, const char* pos, const char* end) { - return string_to_symbol(result, pos, end, true); -} - -inline std::string symbol_to_string(uint64_t v) { - return std::to_string(v & 0xff) + "," + eosio::symbol_code_to_string(v >> 8); -} - -[[nodiscard]] inline bool string_to_asset(int64_t& amount, uint64_t& symbol, const char*& s, const char* end, - bool expect_end) { - // todo: check overflow - while (s != end && *s == ' ') // - ++s; - uint64_t uamount = 0; - uint8_t precision = 0; - bool negative = false; - if (s != end && *s == '-') { - ++s; - negative = true; - } - while (s != end && *s >= '0' && *s <= '9') // - uamount = uamount * 10 + (*s++ - '0'); - if (s != end && *s == '.') { - ++s; - while (s != end && *s >= '0' && *s <= '9') { - uamount = uamount * 10 + (*s++ - '0'); - ++precision; - } - } - if (negative) - uamount = -uamount; - amount = uamount; - uint64_t code; - if (!eosio::string_to_symbol_code(code, s, end, expect_end)) - return false; - symbol = (code << 8) | precision; - return true; -} - -[[nodiscard]] inline bool string_to_asset(int64_t& amount, uint64_t& symbol, const char* s, const char* end) { - return string_to_asset(amount, symbol, s, end, true); -} - -inline std::string asset_to_string(int64_t amount, uint64_t symbol) { - std::string result; - uint64_t uamount; - if (amount < 0) - uamount = -amount; - else - uamount = amount; - uint8_t precision = symbol; - if (precision) { - while (precision--) { - result += '0' + uamount % 10; - uamount /= 10; - } - result += '.'; - } - do { - result += '0' + uamount % 10; - uamount /= 10; - } while (uamount); - if (amount < 0) - result += '-'; - std::reverse(result.begin(), result.end()); - return result + ' ' + eosio::symbol_code_to_string(symbol >> 8); -} - -} // namespace eosio diff --git a/include/eosio_OLD/chain_types.hpp b/include/eosio_OLD/chain_types.hpp deleted file mode 100644 index 3235ec1..0000000 --- a/include/eosio_OLD/chain_types.hpp +++ /dev/null @@ -1,14 +0,0 @@ -#pragma once -#include "ship_protocol.hpp" - -namespace chain_types { -using namespace eosio::ship_protocol; - -struct block_info { - uint32_t block_num = {}; - eosio::checksum256 block_id = {}; - eosio::block_timestamp timestamp; -}; - -EOSIO_REFLECT(block_info, block_num, block_id, timestamp); -}; // namespace chain_types \ No newline at end of file diff --git a/include/eosio_OLD/check.hpp b/include/eosio_OLD/check.hpp deleted file mode 100644 index d9165d2..0000000 --- a/include/eosio_OLD/check.hpp +++ /dev/null @@ -1,178 +0,0 @@ -/** - * @file - * @copyright defined in eos/LICENSE - */ -#pragma once - -#ifdef __eosio_cdt__ -#include -namespace eosio { -namespace internal_use_do_not_use { -extern "C" { -__attribute__((eosio_wasm_import, noreturn)) -void eosio_assert_message(uint32_t, const char*, uint32_t); -__attribute__((eosio_wasm_import, noreturn)) -void eosio_assert(uint32_t, const char*); -__attribute__((eosio_wasm_import, noreturn)) -void eosio_assert_code(uint32_t, uint64_t); -} -} -} -#else -#include -#endif - -#include -#include - -namespace eosio { - -/** - * @defgroup system System - * @ingroup core - * @brief Defines wrappers over eosio_assert - */ - - -struct eosio_error : std::exception { - explicit eosio_error(uint64_t code) {} -}; - -namespace detail { - [[noreturn]] inline void assert_or_throw(std::string_view msg) { -#ifdef __eosio_cdt__ - internal_use_do_not_use::eosio_assert_message(false, msg.data(), msg.size()); -#else - throw std::runtime_error(std::string(msg)); -#endif - } - [[noreturn]] inline void assert_or_throw(const char* msg) { -#ifdef __eosio_cdt__ - internal_use_do_not_use::eosio_assert(false, msg); -#else - throw std::runtime_error(msg); -#endif - } - [[noreturn]] inline void assert_or_throw(std::string&& msg) { -#ifdef __eosio_cdt__ - internal_use_do_not_use::eosio_assert_message(false, msg.c_str(), msg.size()); -#else - throw std::runtime_error(std::move(msg)); -#endif - } - [[noreturn]] inline void assert_or_throw(uint64_t code) { -#ifdef __eosio_cdt__ - internal_use_do_not_use::eosio_assert_code(false, code); -#else - throw std::runtime_error(std::to_string(code)); -#endif - } -} // ns eosio::detail - -/** - * Assert if the predicate fails and use the supplied message. - * - * @ingroup system - * - * Example: - * @code - * eosio::check(a == b, "a does not equal b"); - * @endcode - */ -inline void check(bool pred, std::string_view msg) { - if (!pred) - eosio::detail::assert_or_throw(msg); -} - -/** - * Assert if the predicate fails and use the supplied message. - * - * @ingroup system - * - * Example: - * @code - * eosio::check(a == b, "a does not equal b"); - * @endcode - */ -inline void check(bool pred, const char* msg) { - if (!pred) - eosio::detail::assert_or_throw(msg); -} - -/** - * Assert if the predicate fails and use the supplied message. - * - * @ingroup system - * - * Example: - * @code - * eosio::check(a == b, "a does not equal b"); - * @endcode - */ -inline void check(bool pred, const std::string& msg) { - if (!pred) - eosio::detail::assert_or_throw(std::string_view{msg.c_str(), msg.size()}); -} - -/** - * Assert if the predicate fails and use the supplied message. - * - * @ingroup system - * - * Example: - * @code - * eosio::check(a == b, "a does not equal b"); - * @endcode - */ -inline void check(bool pred, std::string&& msg) { - if (!pred) - eosio::detail::assert_or_throw(std::move(msg)); -} - -/** - * Assert if the predicate fails and use a subset of the supplied message. - * - * @ingroup system - * - * Example: - * @code - * const char* msg = "a does not equal b b does not equal a"; - * eosio::check(a == b, "a does not equal b", 18); - * @endcode - */ -inline void check(bool pred, const char* msg, size_t n) { - if (!pred) - eosio::detail::assert_or_throw(std::string_view{msg, n}); -} - -/** - * Assert if the predicate fails and use a subset of the supplied message. - * - * @ingroup system - * - * Example: - * @code - * std::string msg = "a does not equal b b does not equal a"; - * eosio::check(a == b, msg, 18); - * @endcode - */ -inline void check(bool pred, const std::string& msg, size_t n) { - if (!pred) - eosio::detail::assert_or_throw(msg.substr(0, n)); -} - -/** - * Assert if the predicate fails and use the supplied error code. - * - * @ingroup system - * - * Example: - * @code - * eosio::check(a == b, 13); - * @endcode - */ -inline void check(bool pred, uint64_t code) { - if (!pred) - eosio::detail::assert_or_throw(code); -} -} // namespace eosio diff --git a/include/eosio_OLD/convert.hpp b/include/eosio_OLD/convert.hpp deleted file mode 100644 index a9e0d4b..0000000 --- a/include/eosio_OLD/convert.hpp +++ /dev/null @@ -1,95 +0,0 @@ -#pragma once - -#include "for_each_field.hpp" -#include "stream.hpp" -#include -#include -#include -#include -#include - -namespace eosio { -struct no_conversion { - using reverse = no_conversion; -}; -struct widening_conversion; -// Fields must match exactly -struct strict_conversion { - using reverse = strict_conversion; -}; -// Can discard some fields -struct narrowing_conversion { - using reverse = widening_conversion; -}; -// Can default construct some fields -struct widening_conversion { - using reverse = narrowing_conversion; -}; - -no_conversion conversion_kind(...); -void serialize_as(...); - -template -using serialization_type = decltype(serialize_as(std::declval())); - -template -using conversion_kind_t = - std::conditional_t(), std::declval())), no_conversion>, - typename decltype(conversion_kind(std::declval(), std::declval()))::reverse, - decltype(conversion_kind(std::declval(), std::declval()))>; - -template -auto convert_impl(Field field, const T& src, U& dst, F&& f, int) - -> std::void_t { - convert(field(&src), field(&dst), f); -} - -template -auto convert_impl(Field field, const T& src, U& dst, F&& f, long) { - static_assert(!std::is_same_v, strict_conversion>, "Member not found"); - static_assert(!std::is_same_v, widening_conversion>, "Member not found"); -} - -inline constexpr auto choose_first = [](auto src, auto dest) { return src; }; -inline constexpr auto choose_second = [](auto src, auto dest) { return dest; }; - -// TODO: add some validation - -template -void convert(const T& src, U& dst, F&& chooser) { - if constexpr (std::is_same_v) { - dst = src; - } else { - static_assert(!std::is_same_v, no_conversion>, "Conversion not defined"); - for_each_field>( - [&](const char*, auto field) { convert_impl(field, src, dst, chooser, 0); }); - } -} - -template -void convert(const std::variant& src, U& dst, F&& chooser) { - std::visit([&](auto& src) { return convert(src, dst, chooser); }, src); -} - -template -void convert(const std::vector& src, std::vector& dst, F&& chooser) { - dst.resize(src.size()); - for (std::size_t i = 0; i < src.size(); ++i) { convert(src[i], dst[i], chooser); } -} - -template -void convert(const std::optional& src, std::optional& dst, F&& chooser) { - if (src) { - dst.emplace(); - convert(*src, *dst, chooser); - } else { - dst = std::nullopt; - } -} - -struct stream; -template -void convert(const input_stream& src, std::vector& dst, F&& chooser) { - dst.assign(src.pos, src.end); -} -} // namespace eosio diff --git a/include/eosio_OLD/crypto.hpp b/include/eosio_OLD/crypto.hpp deleted file mode 100644 index fd5597f..0000000 --- a/include/eosio_OLD/crypto.hpp +++ /dev/null @@ -1,148 +0,0 @@ -#pragma once - -#include -#include "operators.hpp" -#include "reflection.hpp" -#include -#include -#include -#include - -namespace eosio { - -/** - * @defgroup public_key Public Key Type - * @ingroup core - * @ingroup types - * @brief Specifies public key type - */ - -/** - * EOSIO ECC public key data - * - * Fixed size representation of either a K1 or R1 compressed public key - - * @ingroup public_key - */ -using ecc_public_key = std::array; - -/** - * EOSIO WebAuthN public key - * - * @ingroup public_key - */ -struct webauthn_public_key { - /** - * Enumeration of the various results of a Test of User Presence - * @see https://w3c.github.io/webauthn/#test-of-user-presence - */ - enum class user_presence_t : uint8_t { USER_PRESENCE_NONE, USER_PRESENCE_PRESENT, USER_PRESENCE_VERIFIED }; - - /** - * The ECC key material - */ - ecc_public_key key; - - /** - * expected result of the test of user presence for a valid signature - * @see https://w3c.github.io/webauthn/#test-of-user-presence - */ - user_presence_t user_presence; - - /** - * the Relying Party Identifier for WebAuthN - * @see https://w3c.github.io/webauthn/#relying-party-identifier - */ - std::string rpid; -}; -EOSIO_REFLECT(webauthn_public_key, key, user_presence, rpid); -EOSIO_COMPARE(webauthn_public_key); - -/** - * EOSIO Public Key - * - * A public key is a variant of - * 0 : a ECC K1 public key - * 1 : a ECC R1 public key - * 2 : a WebAuthN public key (requires the host chain to activate the WEBAUTHN_KEY consensus upgrade) - * - * @ingroup public_key - */ -using public_key = std::variant; - -using ecc_private_key = std::array; -using private_key = std::variant; - -/** - * EOSIO ECC signature data - * - * Fixed size representation of either a K1 or R1 ECC compact signature - - * @ingroup signature - */ -using ecc_signature = std::array; - -struct webauthn_signature { - /** - * The ECC signature data - */ - ecc_signature compact_signature; - - /** - * The Encoded Authenticator Data returned from WebAuthN ceremony - * @see https://w3c.github.io/webauthn/#sctn-authenticator-data - */ - std::vector auth_data; - - /** - * the JSON encoded Collected Client Data from a WebAuthN ceremony - * @see https://w3c.github.io/webauthn/#dictdef-collectedclientdata - */ - std::string client_json; -}; - -EOSIO_REFLECT(webauthn_signature, compact_signature, auth_data, client_json); -EOSIO_COMPARE(webauthn_signature); - -using signature = std::variant; -constexpr const char* get_type_name(public_key*) { return "public_key"; } -constexpr const char* get_type_name(private_key*) { return "private_key"; } -constexpr const char* get_type_name(signature*) { return "signature"; } - -std::string public_key_to_string(const public_key& obj); -public_key public_key_from_string(std::string_view s); -std::string private_key_to_string(const private_key& obj); -private_key private_key_from_string(std::string_view s); -std::string signature_to_string(const signature& obj); -signature signature_from_string(std::string_view s); - -template -void to_json(const public_key& obj, S& stream) { - to_json(public_key_to_string(obj), stream); -} -template -void from_json(public_key& obj, S& stream) { - auto s = stream.get_string(); - obj = public_key_from_string(s); -} -template -void to_json(const private_key& obj, S& stream) { - to_json(private_key_to_string(obj), stream); -} -template -void from_json(private_key& obj, S& stream) { - obj = private_key_from_string(stream.get_string()); -} -template -void to_json(const signature& obj, S& stream) { - return to_json(signature_to_string(obj), stream); -} -template -void from_json(signature& obj, S& stream) { - obj = signature_from_string(stream.get_string()); -} - -std::string to_base58(const char* d, size_t s ); -std::vector from_base58(const std::string_view& s); - -} // namespace eosio diff --git a/include/eosio_OLD/fixed_bytes.hpp b/include/eosio_OLD/fixed_bytes.hpp deleted file mode 100644 index adb1da2..0000000 --- a/include/eosio_OLD/fixed_bytes.hpp +++ /dev/null @@ -1,250 +0,0 @@ -#pragma once - -#include -#include -#include -#include "from_json.hpp" -#include "operators.hpp" -#include "reflection.hpp" -#include "to_json.hpp" -#include - -namespace eosio { - -/** - * @defgroup fixed_bytes Fixed Size Byte Array - * @ingroup core - * @ingroup types - * @brief Fixed size array of bytes sorted lexicographically - */ - -/** - * Fixed size byte array sorted lexicographically - * - * @ingroup fixed_bytes - * @tparam Size - Size of the fixed_bytes object - * @tparam Word - Type to use for storage - */ -template -class fixed_bytes { - private: - // Returns the minimum number of objects of type T required to hold at least Size bytes. - // T must be an unsigned integer type. - template - static constexpr std::size_t count_words() { - return (Size + sizeof(T) - 1) / sizeof(T); - } - // Divides a value into words and writes the highest words first. - // If U is 1 byte, this is equivalent to big-endian encoding. - // sizeof(T) must be divisible by sizeof(U). - // Writes up to sizeof(T)/sizeof(U) elements to the range [ptr, end) - // Returns the end of the range written. - template - static constexpr U* write_be(U* ptr, U* end, T t) { - constexpr std::size_t words = sizeof(T) / sizeof(U); - for (std::size_t i = 0; i < words && ptr < end; ++i) { - *ptr++ = static_cast(t >> std::numeric_limits::digits * (words - i - 1)); - } - return ptr; - } - // The opposite of write_be. If there are insufficient elements in [ptr, end), - // fills `out` as if the missing elements were 0. - template - static constexpr const U* read_be(const U* ptr, const U* end, T& out) { - constexpr std::size_t words = sizeof(T) / sizeof(U); - T result = 0; - for (std::size_t i = 0; i < words && ptr < end; ++i, ++ptr) { - result |= static_cast(*ptr) << (std::numeric_limits::digits * (words - i - 1)); - } - out = result; - return ptr; - } - // Either splits or combines words depending on whether - // T is larger than U. - // Both arrays must hold the minimum number of elements - // required to store Size bytes. - template - static constexpr void convert_array(const T* t, U* u) { - constexpr std::size_t t_elems = count_words(); - constexpr std::size_t u_elems = count_words(); - if constexpr (sizeof(T) > sizeof(U)) { - U* const end = u + u_elems; - for (std::size_t i = 0; i < t_elems; ++i) { u = write_be(u, end, t[i]); } - } else { - const T* const end = t + t_elems; - for (std::size_t i = 0; i < u_elems; ++i) { t = read_be(t, end, u[i]); } - } - } - - template - static constexpr std::array()> convert_array(const U* u) { - std::array()> result{0}; - convert_array(u, result.data()); - return result; - } - - template - static constexpr std::array()> convert_array(const U* u, const U* end) { - std::array()> tmp{0}; - std::size_t count = std::min(static_cast(end - u), tmp.size()); - for (std::size_t i = 0; i < count; ++i) { tmp[i] = u[i]; } - return convert_array(tmp.data()); - } - - template - using require_word = std::enable_if_t>; - - public: - using word_t = Word; - /** - * Get number of words contained in this fixed_bytes object. A word is defined to be 16 bytes in size - */ - static constexpr std::size_t num_words() { return count_words(); } - - /** - * Get number of padded bytes contained in this fixed_bytes object. Padded bytes are the remaining bytes - * inside the fixed_bytes object after all the words are allocated - */ - static constexpr size_t padded_bytes() { return num_words() * sizeof(Word) - Size; } - - /** - * Default constructor to fixed_bytes object which initializes all bytes to zero - */ - constexpr fixed_bytes() = default; - - /** - * Constructor to fixed_bytes object from initializer list of bytes. - */ - constexpr fixed_bytes(std::initializer_list il) : value(convert_array(il.begin(), il.end())) {} - - /** - * Constructor to fixed_bytes object from std::array of num_words() word_t types - * - * @param arr data - */ - constexpr fixed_bytes(const std::array& arr) : value(arr) {} - - /** - * Constructor to fixed_bytes object from std::array of unsigned integral types. - * - * @param arr - Source data. arr cannot hold more words than are required to fill Size bytes. If it contains - * fewer than Size bytes, the remaining bytes will be zero-filled. - */ - template && N <= count_words()>> - constexpr fixed_bytes(const std::array& arr) : value(convert_array(arr.begin(), arr.end())) {} - - /** - * Constructor to fixed_bytes object from fixed-sized C array of unsigned integral types. - * - * @param arr - Source data. arr cannot hold more words than are required to fill Size bytes. If it contains - * fewer than Size bytes, the remaining bytes will be zero-filled. - */ - template && N <= count_words()>> - constexpr fixed_bytes(const T (&arr)[N]) : value(convert_array(&arr[0], &arr[0] + N)) {} - - /** - * Create a new fixed_bytes object from a sequence of words - * - * @tparam T - The type of the words. T must be specified explicitly. - * @param a - The words in the sequence. All the parameters must have type T. The number of parameters must - * be equal to the number of values of type T required to fill Size bytes. - */ - template && (std::is_same_v && ...) && - (count_words() == sizeof...(A)))>> - static constexpr fixed_bytes make_from_word_sequence(A... a) { - T args[count_words()] = { a... }; - return fixed_bytes(args); - } - /** - * Extract the contained data as an array of words - * - * @tparam T - The word type to return. T must be an unsigned integral type. - */ - template - constexpr auto extract_as_word_array() const { - return convert_array(data()); - } - /** - * Extract the contained data as an array of bytes - * - * @return - the extracted data as array of bytes - */ - constexpr std::array extract_as_byte_array() const { - return extract_as_word_array(); - } - /** - * Get the underlying data of the contained std::array - */ - constexpr Word* data() { return value.data(); } - /** - * Get the underlying data of the contained std::array - */ - constexpr const Word* data() const { return value.data(); } - constexpr std::size_t size() const { return value.size(); } - /** - * Get the Word storing capacity in the underlying data of the contained std::array - */ - constexpr std::size_t capacity() const { return Size; } - /** - * Get the contained std::array - */ - constexpr const auto& get_array() const { return value; } - std::array()> value{0}; -}; - -// This is only needed to make eosio.cdt/tests/unit/fixed_bytes_tests.cpp pass. -// Everything else should be using one of the typedefs below. -template -void eosio_for_each_field(fixed_bytes*, F&& f) { - f("value", - [](auto* p) -> decltype(&std::decay_t::value) { return &std::decay_t::value; }); -} - -template -EOSIO_COMPARE(fixed_bytes); - -using checksum160 = fixed_bytes<20,uint32_t>; -using checksum256 = fixed_bytes<32>; -using checksum512 = fixed_bytes<64>; - -EOSIO_REFLECT(checksum160, value); -EOSIO_REFLECT(checksum256, value); -EOSIO_REFLECT(checksum512, value); - -template -void from_bin(fixed_bytes& obj, S& stream) { - std::array bytes; - from_bin(bytes, stream); - obj = fixed_bytes(bytes); -} - -template -void to_bin(const fixed_bytes& obj, S& stream) { - to_bin(obj.extract_as_byte_array(), stream); -} - -template -void to_key(const fixed_bytes& obj, S& stream) { - to_bin(obj.extract_as_byte_array(), stream); -} - -template -void from_json(fixed_bytes& obj, S& stream) { - std::vector v; - eosio::from_json_hex(v, stream); - check(v.size() == Size, convert_json_error(eosio::from_json_error::hex_string_incorrect_length)); - std::array bytes; - std::memcpy(bytes.data(), v.data(), Size); - obj = fixed_bytes(bytes); -} - -template -void to_json(const fixed_bytes& obj, S& stream) { - auto bytes = obj.extract_as_byte_array(); - eosio::to_json_hex((const char*)bytes.data(), bytes.size(), stream); -} - -} // namespace eosio diff --git a/include/eosio_OLD/float.hpp b/include/eosio_OLD/float.hpp deleted file mode 100644 index 0362b15..0000000 --- a/include/eosio_OLD/float.hpp +++ /dev/null @@ -1,35 +0,0 @@ -#pragma once - -#ifdef __eosio_cdt__ - -namespace eosio { - -using float32 = float; -using float64 = double; -using float128 = long double; - -} // namespace eosio - -#else - -# include -# include - -namespace eosio { - -using float32 = float; -using float64 = double; -using float128 = fixed_bytes<16>; - -static_assert(sizeof(float32) == 4 && std::numeric_limits::is_iec559 && - std::numeric_limits::digits == 24, - "Unexpected float representation"); -static_assert(sizeof(float64) == 8 && std::numeric_limits::is_iec559 && - std::numeric_limits::digits == 53, - "Unexpected double representation"); - -EOSIO_REFLECT(float128, value); - -} // namespace eosio - -#endif diff --git a/include/eosio_OLD/for_each_field.hpp b/include/eosio_OLD/for_each_field.hpp deleted file mode 100644 index f39ed51..0000000 --- a/include/eosio_OLD/for_each_field.hpp +++ /dev/null @@ -1,48 +0,0 @@ -#pragma once - -#include "reflection.hpp" -#include - -#if __has_include() - -# include - -namespace eosio { -template -constexpr auto for_each_field(T&& t, F&& f) -> std::enable_if_t>> { - return boost::pfr::for_each_field(static_cast(t), static_cast(f)); -} -} // namespace eosio -#endif - -namespace eosio { - -template -constexpr auto for_each_field(T&& t, F&& f) -> std::enable_if_t>> { - eosio_for_each_field((std::decay_t*)nullptr, [&](const char*, auto member) { - if constexpr (std::is_member_object_pointer_v) { - f(t.*member(&t)); - } - }); -} - -template -constexpr void for_each_field(F&& f) { - eosio_for_each_field((T*)nullptr, [&f](const char* name, auto member) { - if constexpr (std::is_member_object_pointer_v) { - f(name, [member](auto p) -> decltype((p->*member(p))) { return p->*member(p); }); - } - }); -} - -// Calls f(#fn_name, &T::fn_name) for every reflected member function of T. -template -constexpr void for_each_method(F&& f) { - eosio_for_each_field((T*)nullptr, [&f](const char* name, auto member) { - if constexpr (std::is_member_function_pointer_v) { - f(name, member((T*)nullptr)); - } - }); -} - -} // namespace eosio diff --git a/include/eosio_OLD/fpconv.c b/include/eosio_OLD/fpconv.c deleted file mode 100644 index 54c6d6f..0000000 --- a/include/eosio_OLD/fpconv.c +++ /dev/null @@ -1,336 +0,0 @@ -/// From https://github.com/night-shift/fpconv -/// Boost Software License 1.0 -/// See accompanying license file - -#include -#include - -#include "fpconv.h" -#include "powers.h" - -#define fracmask 0x000FFFFFFFFFFFFFU -#define expmask 0x7FF0000000000000U -#define hiddenbit 0x0010000000000000U -#define signmask 0x8000000000000000U -#define expbias (1023 + 52) - -#define absv(n) ((n) < 0 ? -(n) : (n)) -#define minv(a, b) ((a) < (b) ? (a) : (b)) - -static uint64_t tens[] = { - 10000000000000000000U, 1000000000000000000U, 100000000000000000U, - 10000000000000000U, 1000000000000000U, 100000000000000U, - 10000000000000U, 1000000000000U, 100000000000U, - 10000000000U, 1000000000U, 100000000U, - 10000000U, 1000000U, 100000U, - 10000U, 1000U, 100U, - 10U, 1U -}; - -static inline uint64_t get_dbits(double d) -{ - union { - double dbl; - uint64_t i; - } dbl_bits = { d }; - - return dbl_bits.i; -} - -static Fp build_fp(double d) -{ - uint64_t bits = get_dbits(d); - - Fp fp; - fp.frac = bits & fracmask; - fp.exp = (bits & expmask) >> 52; - - if(fp.exp) { - fp.frac += hiddenbit; - fp.exp -= expbias; - - } else { - fp.exp = -expbias + 1; - } - - return fp; -} - -static void normalize(Fp* fp) -{ - while ((fp->frac & hiddenbit) == 0) { - fp->frac <<= 1; - fp->exp--; - } - - int shift = 64 - 52 - 1; - fp->frac <<= shift; - fp->exp -= shift; -} - -static void get_normalized_boundaries(Fp* fp, Fp* lower, Fp* upper) -{ - upper->frac = (fp->frac << 1) + 1; - upper->exp = fp->exp - 1; - - while ((upper->frac & (hiddenbit << 1)) == 0) { - upper->frac <<= 1; - upper->exp--; - } - - int u_shift = 64 - 52 - 2; - - upper->frac <<= u_shift; - upper->exp = upper->exp - u_shift; - - - int l_shift = fp->frac == hiddenbit ? 2 : 1; - - lower->frac = (fp->frac << l_shift) - 1; - lower->exp = fp->exp - l_shift; - - - lower->frac <<= lower->exp - upper->exp; - lower->exp = upper->exp; -} - -static Fp multiply(Fp* a, Fp* b) -{ - const uint64_t lomask = 0x00000000FFFFFFFF; - - uint64_t ah_bl = (a->frac >> 32) * (b->frac & lomask); - uint64_t al_bh = (a->frac & lomask) * (b->frac >> 32); - uint64_t al_bl = (a->frac & lomask) * (b->frac & lomask); - uint64_t ah_bh = (a->frac >> 32) * (b->frac >> 32); - - uint64_t tmp = (ah_bl & lomask) + (al_bh & lomask) + (al_bl >> 32); - /* round up */ - tmp += 1U << 31; - - Fp fp = { - ah_bh + (ah_bl >> 32) + (al_bh >> 32) + (tmp >> 32), - a->exp + b->exp + 64 - }; - - return fp; -} - -static void round_digit(char* digits, int ndigits, uint64_t delta, uint64_t rem, uint64_t kappa, uint64_t frac) -{ - while (rem < frac && delta - rem >= kappa && - (rem + kappa < frac || frac - rem > rem + kappa - frac)) { - - digits[ndigits - 1]--; - rem += kappa; - } -} - -static int generate_digits(Fp* fp, Fp* upper, Fp* lower, char* digits, int* K) -{ - uint64_t wfrac = upper->frac - fp->frac; - uint64_t delta = upper->frac - lower->frac; - - Fp one; - one.frac = 1ULL << -upper->exp; - one.exp = upper->exp; - - uint64_t part1 = upper->frac >> -one.exp; - uint64_t part2 = upper->frac & (one.frac - 1); - - int idx = 0, kappa = 10; - uint64_t* divp; - /* 1000000000 */ - for(divp = tens + 10; kappa > 0; divp++) { - - uint64_t div = *divp; - unsigned digit = part1 / div; - - if (digit || idx) { - digits[idx++] = digit + '0'; - } - - part1 -= digit * div; - kappa--; - - uint64_t tmp = (part1 <<-one.exp) + part2; - if (tmp <= delta) { - *K += kappa; - round_digit(digits, idx, delta, tmp, div << -one.exp, wfrac); - - return idx; - } - } - - /* 10 */ - uint64_t* unit = tens + 18; - - while(true) { - part2 *= 10; - delta *= 10; - kappa--; - - unsigned digit = part2 >> -one.exp; - if (digit || idx) { - digits[idx++] = digit + '0'; - } - - part2 &= one.frac - 1; - if (part2 < delta) { - *K += kappa; - round_digit(digits, idx, delta, part2, one.frac, wfrac * *unit); - - return idx; - } - - unit--; - } -} - -static int grisu2(double d, char* digits, int* K) -{ - Fp w = build_fp(d); - - Fp lower, upper; - get_normalized_boundaries(&w, &lower, &upper); - - normalize(&w); - - int k; - Fp cp = find_cachedpow10(upper.exp, &k); - - w = multiply(&w, &cp); - upper = multiply(&upper, &cp); - lower = multiply(&lower, &cp); - - lower.frac++; - upper.frac--; - - *K = -k; - - return generate_digits(&w, &upper, &lower, digits, K); -} - -static int emit_digits(char* digits, int ndigits, char* dest, int K, bool neg) -{ - int exp = absv(K + ndigits - 1); - - /* write plain integer */ - if(K >= 0 && (exp < (ndigits + 7))) { - memcpy(dest, digits, ndigits); - memset(dest + ndigits, '0', K); - - return ndigits + K; - } - - /* write decimal w/o scientific notation */ - if(K < 0 && (K > -7 || exp < 4)) { - int offset = ndigits - absv(K); - /* fp < 1.0 -> write leading zero */ - if(offset <= 0) { - offset = -offset; - dest[0] = '0'; - dest[1] = '.'; - memset(dest + 2, '0', offset); - memcpy(dest + offset + 2, digits, ndigits); - - return ndigits + 2 + offset; - - /* fp > 1.0 */ - } else { - memcpy(dest, digits, offset); - dest[offset] = '.'; - memcpy(dest + offset + 1, digits + offset, ndigits - offset); - - return ndigits + 1; - } - } - - /* write decimal w/ scientific notation */ - ndigits = minv(ndigits, 18 - neg); - - int idx = 0; - dest[idx++] = digits[0]; - - if(ndigits > 1) { - dest[idx++] = '.'; - memcpy(dest + idx, digits + 1, ndigits - 1); - idx += ndigits - 1; - } - - dest[idx++] = 'e'; - - char sign = K + ndigits - 1 < 0 ? '-' : '+'; - dest[idx++] = sign; - - int cent = 0; - - if(exp > 99) { - cent = exp / 100; - dest[idx++] = cent + '0'; - exp -= cent * 100; - } - if(exp > 9) { - int dec = exp / 10; - dest[idx++] = dec + '0'; - exp -= dec * 10; - - } else if(cent) { - dest[idx++] = '0'; - } - - dest[idx++] = exp % 10 + '0'; - - return idx; -} - -static int filter_special(double fp, char* dest) -{ - if(fp == 0.0) { - dest[0] = '0'; - return 1; - } - - uint64_t bits = get_dbits(fp); - - bool nan = (bits & expmask) == expmask; - - if(!nan) { - return 0; - } - - if(bits & fracmask) { - dest[0] = 'n'; dest[1] = 'a'; dest[2] = 'n'; - - } else { - dest[0] = 'i'; dest[1] = 'n'; dest[2] = 'f'; - } - - return 3; -} - -int fpconv_dtoa(double d, char dest[24]) -{ - char digits[18]; - - int str_len = 0; - bool neg = false; - - if(get_dbits(d) & signmask) { - dest[0] = '-'; - str_len++; - neg = true; - } - - int spec = filter_special(d, dest + str_len); - - if(spec) { - return str_len + spec; - } - - int K = 0; - int ndigits = grisu2(d, digits, &K); - - str_len += emit_digits(digits, ndigits, dest + str_len, K, neg); - - return str_len; -} diff --git a/include/eosio_OLD/fpconv.h b/include/eosio_OLD/fpconv.h deleted file mode 100644 index 5c9dc78..0000000 --- a/include/eosio_OLD/fpconv.h +++ /dev/null @@ -1,41 +0,0 @@ -/// From https://github.com/night-shift/fpconv -/// Boost Software License 1.0 -/// See accompanying license file - -#ifndef FPCONV_H -# define FPCONV_H - -/* Fast and accurate double to string conversion based on Florian Loitsch's - * Grisu-algorithm[1]. - * - * Input: - * fp -> the double to convert, dest -> destination buffer. - * The generated string will never be longer than 24 characters. - * Make sure to pass a pointer to at least 24 bytes of memory. - * The emitted string will not be null terminated. - * - * Output: - * The number of written characters. - * - * Exemplary usage: - * - * void print(double d) - * { - * char buf[24 + 1] // plus null terminator - * int str_len = fpconv_dtoa(d, buf); - * - * buf[str_len] = '\0'; - * printf("%s", buf); - * } - * - */ - -# ifdef __cplusplus -extern "C" int fpconv_dtoa(double fp, char dest[24]); -# else -int fpconv_dtoa(double fp, char dest[24]); -# endif - -#endif - -/* [1] http://florian.loitsch.com/publications/dtoa-pldi2010.pdf */ diff --git a/include/eosio_OLD/fpconv.license b/include/eosio_OLD/fpconv.license deleted file mode 100644 index 36b7cd9..0000000 --- a/include/eosio_OLD/fpconv.license +++ /dev/null @@ -1,23 +0,0 @@ -Boost Software License - Version 1.0 - August 17th, 2003 - -Permission is hereby granted, free of charge, to any person or organization -obtaining a copy of the software and accompanying documentation covered by -this license (the "Software") to use, reproduce, display, distribute, -execute, and transmit the Software, and to prepare derivative works of the -Software, and to permit third-parties to whom the Software is furnished to -do so, all subject to the following: - -The copyright notices in the Software and this entire statement, including -the above license grant, this restriction and the following disclaimer, -must be included in all copies of the Software, in whole or in part, and -all derivative works of the Software, unless such copies or derivative -works are solely in the form of machine-executable object code generated by -a source language processor. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT -SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE -FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, -ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -DEALINGS IN THE SOFTWARE. diff --git a/include/eosio_OLD/from_bin.hpp b/include/eosio_OLD/from_bin.hpp deleted file mode 100644 index 2326049..0000000 --- a/include/eosio_OLD/from_bin.hpp +++ /dev/null @@ -1,272 +0,0 @@ -#pragma once - -#include -#include "convert.hpp" -#include "for_each_field.hpp" -#include "stream.hpp" -#include -#include -#include -#include -#include -#include -#include -#include - -namespace eosio { - -template -void from_bin(T& obj, S& stream); - -template -void varuint32_from_bin(uint32_t& dest, S& stream) { - dest = 0; - int shift = 0; - uint8_t b = 0; - do { - check( shift < 35, convert_stream_error(stream_error::invalid_varuint_encoding) ); - from_bin(b, stream); - dest |= uint32_t(b & 0x7f) << shift; - shift += 7; - } while (b & 0x80); -} - -template -void varuint64_from_bin(uint64_t& dest, S& stream) { - dest = 0; - int shift = 0; - uint8_t b = 0; - do { - check( shift < 70, convert_stream_error(stream_error::invalid_varuint_encoding) ); - from_bin(b, stream); - dest |= uint64_t(b & 0x7f) << shift; - shift += 7; - } while (b & 0x80); -} - -template -void varint32_from_bin(int32_t& result, S& stream) { - uint32_t v; - varuint32_from_bin(v, stream); - if (v & 1) - result = ((~v) >> 1) | 0x8000'0000; - else - result = v >> 1; -} - -template -void from_bin_assoc(T& v, S& stream) { - uint32_t size; - varuint32_from_bin(size, stream); - for (size_t i = 0; i < size; ++i) { - typename T::value_type elem; - from_bin(elem, stream); - v.emplace(elem); - } -} - -template -void from_bin_sequence(T& v, S& stream) { - uint32_t size; - varuint32_from_bin(size, stream); - for (size_t i = 0; i < size; ++i) { - v.emplace_back(); - from_bin(v.back(), stream); - } -} - -template -void from_bin(T (&v)[N], S& stream) { - uint32_t size; - varuint32_from_bin(size, stream); - check( size == N, convert_stream_error(stream_error::array_size_mismatch) ); - if constexpr (has_bitwise_serialization()) { - stream.read(reinterpret_cast(v), size * sizeof(T)); - } else { - for (size_t i = 0; i < size; ++i) { - from_bin(v[i], stream); - } - } -} - -template -void from_bin(std::vector& v, S& stream) { - if constexpr (has_bitwise_serialization()) { - if constexpr (sizeof(size_t) >= 8) { - uint64_t size; - varuint64_from_bin(size, stream); - stream.check_available(size * sizeof(T)); - v.resize(size); - stream.read(reinterpret_cast(v.data()), size * sizeof(T)); - } else { - uint32_t size; - varuint32_from_bin(size, stream); - stream.check_available(size * sizeof(T)); - v.resize(size); - stream.read(reinterpret_cast(v.data()), size * sizeof(T)); - } - } else { - uint32_t size; - varuint32_from_bin(size, stream); - v.resize(size); - for (size_t i = 0; i < size; ++i) { - from_bin(v[i], stream); - } - } -} - -template -void from_bin(std::set& v, S& stream) { - return from_bin_assoc(v, stream); -} - -template -void from_bin(std::map& v, S& stream) { - uint32_t size; - varuint32_from_bin(size, stream); - for (size_t i = 0; i < size; ++i) { - std::pair elem; - from_bin(elem, stream); - v.emplace(elem); - } -} - -template -void from_bin(std::deque& v, S& stream) { - return from_bin_sequence(v, stream); -} - -template -void from_bin(std::list& v, S& stream) { - return from_bin_sequence(v, stream); -} - -template -void from_bin(input_stream& obj, S& stream) { - if constexpr (sizeof(size_t) >= 8) { - uint64_t size; - varuint64_from_bin(size, stream); - stream.check_available(size); - stream.read_reuse_storage(obj.pos, size); - obj.end = obj.pos + size; - } else { - uint32_t size; - varuint32_from_bin(size, stream); - stream.check_available(size); - stream.read_reuse_storage(obj.pos, size); - obj.end = obj.pos + size; - } -} - -template -void from_bin(std::pair& obj, S& stream) { - from_bin(obj.first, stream); - from_bin(obj.second, stream); -} - -template -inline void from_bin(std::string& obj, S& stream) { - uint32_t size; - varuint32_from_bin(size, stream); - obj.resize(size); - stream.read(obj.data(), obj.size()); -} - -template -inline void from_bin(std::string_view& obj, S& stream) { - uint32_t size; - varuint32_from_bin(size, stream); - obj = std::string_view(stream.get_pos(),size); - stream.skip(size); -} - -template -void from_bin(std::optional& obj, S& stream) { - bool present; - from_bin(present, stream); - if (!present) { - obj.reset(); - return; - } - obj.emplace(); - from_bin(*obj, stream); -} - -template -void variant_from_bin(std::variant& v, uint32_t i, S& stream) { - if constexpr (I < std::variant_size_v>) { - if (i == I) { - auto& x = v.template emplace(); - from_bin(x, stream); - } else { - variant_from_bin(v, i, stream); - } - } else { - check( false, convert_stream_error(stream_error::bad_variant_index) ); - } -} - -template -void from_bin(std::variant& obj, S& stream) { - uint32_t u; - varuint32_from_bin(u, stream); - variant_from_bin<0>(obj, u, stream); -} - -template -void from_bin(std::array& obj, S& stream) { - for (T& elem : obj) { - from_bin(elem, stream); - } -} - -template -void from_bin_tuple(T& obj, S& stream) { - if constexpr (N < std::tuple_size_v) { - from_bin(std::get(obj), stream); - from_bin_tuple(obj, stream); - } -} - -template -void from_bin(std::tuple& obj, S& stream) { - return from_bin_tuple<0>(obj, stream); -} - -template -void from_bin(T& obj, S& stream) { - if constexpr (has_bitwise_serialization()) { - stream.read(reinterpret_cast(&obj), sizeof(T)); - } else if constexpr (std::is_same_v, void>) { - for_each_field(obj, [&](auto& member) { - from_bin(member, stream); - }); - } else { - // TODO: This can operate in place for standard serializers - decltype(serialize_as(obj)) temp; - from_bin(temp, stream); - convert(temp, obj, choose_first); - } -} - -template -T from_bin(S& stream) { - T obj; - from_bin(obj, stream); - return obj; -} - -template -void convert_from_bin(T& obj, const std::vector& bin) { - input_stream stream{ bin }; - return from_bin(obj, stream); -} - -template -T convert_from_bin(const std::vector& bin) { - T obj; - convert_from_bin(obj, bin); - return obj; -} - -} // namespace eosio diff --git a/include/eosio_OLD/from_json.hpp b/include/eosio_OLD/from_json.hpp deleted file mode 100644 index bb0e2e0..0000000 --- a/include/eosio_OLD/from_json.hpp +++ /dev/null @@ -1,749 +0,0 @@ -#pragma once - -#include -#include "for_each_field.hpp" -#include "check.hpp" -#include -#include -#include -#include -#include -#include -#include - -namespace eosio { -enum class from_json_error { - no_error, - - expected_end, - expected_null, - expected_bool, - expected_string, - expected_hex_string, - hex_string_incorrect_length, - invalid_signature, - invalid_name, - expected_start_object, - expected_key, - expected_end_object, - expected_start_array, - expected_end_array, - expected_positive_uint, - expected_field, - expected_variant, - expected_public_key, - expected_private_key, - expected_signature, - expected_number, - expected_int, - expected_time_point, - expected_symbol_code, - expected_symbol, - expected_asset, - invalid_type_for_variant, - unexpected_field, - number_out_of_range, - from_json_no_pair, - - // These are from rapidjson: - document_empty, - document_root_not_singular, - value_invalid, - object_miss_name, - object_miss_colon, - object_miss_comma_or_curly_bracket, - array_miss_comma_or_square_bracket, - string_unicode_escape_invalid_hex, - string_unicode_surrogate_invalid, - string_escape_invalid, - string_miss_quotation_mark, - string_invalid_encoding, - number_too_big, - number_miss_fraction, - number_miss_exponent, - terminated, - unspecific_syntax_error, -}; // from_json_error - -constexpr inline std::string_view convert_json_error(from_json_error e) { - switch (e) { - // clang-format off - case from_json_error::no_error: return "No error"; - - case from_json_error::expected_end: return "Expected end of json"; - case from_json_error::expected_null: return "Expected null"; - case from_json_error::expected_bool: return "Expected true or false"; - case from_json_error::expected_string: return "Expected string"; - case from_json_error::expected_hex_string: return "Expected string containing hex"; - case from_json_error::hex_string_incorrect_length: return "Hex string has incorrect length"; - case from_json_error::invalid_signature: return "Invalid signature format"; - case from_json_error::invalid_name: return "Invalid name"; - case from_json_error::expected_start_object: return "Expected {"; - case from_json_error::expected_key: return "Expected key"; - case from_json_error::expected_end_object: return "Expected }"; - case from_json_error::expected_start_array: return "Expected ["; - case from_json_error::expected_end_array: return "Expected ]"; - case from_json_error::expected_positive_uint: return "Expected positive integer"; - case from_json_error::expected_field: return "Expected field"; - case from_json_error::expected_variant: return R"(Expected variant: ["type", value])"; - case from_json_error::expected_public_key: return "Expected public key"; - case from_json_error::expected_private_key: return "Expected private key"; - case from_json_error::expected_signature: return "Expected signature"; - case from_json_error::expected_number: return "Expected number or boolean"; - case from_json_error::expected_int: return "Expected integer"; - case from_json_error::expected_time_point: return "Expected time point"; - case from_json_error::expected_symbol_code: return "Expected symbol code"; - case from_json_error::expected_symbol: return "Expected symbol"; - case from_json_error::expected_asset: return "Expected asset"; - case from_json_error::invalid_type_for_variant: return "Invalid type for variant"; - case from_json_error::unexpected_field: return "Unexpected field"; - case from_json_error::number_out_of_range: return "number is out of range"; - case from_json_error::from_json_no_pair: return "from_json does not support std::pair"; - - case from_json_error::document_empty: return "The document is empty"; - case from_json_error::document_root_not_singular: return "The document root must not follow by other values"; - case from_json_error::value_invalid: return "Invalid value"; - case from_json_error::object_miss_name: return "Missing a name for object member"; - case from_json_error::object_miss_colon: return "Missing a colon after a name of object member"; - case from_json_error::object_miss_comma_or_curly_bracket: return "Missing a comma or '}' after an object member"; - case from_json_error::array_miss_comma_or_square_bracket: return "Missing a comma or ']' after an array element"; - case from_json_error::string_unicode_escape_invalid_hex: return "Incorrect hex digit after \\u escape in string"; - case from_json_error::string_unicode_surrogate_invalid: return "The surrogate pair in string is invalid"; - case from_json_error::string_escape_invalid: return "Invalid escape character in string"; - case from_json_error::string_miss_quotation_mark: return "Missing a closing quotation mark in string"; - case from_json_error::string_invalid_encoding: return "Invalid encoding in string"; - case from_json_error::number_too_big: return "Number too big to be stored in double"; - case from_json_error::number_miss_fraction: return "Miss fraction part in number"; - case from_json_error::number_miss_exponent: return "Miss exponent in number"; - case from_json_error::terminated: return "Parsing was terminated"; - case from_json_error::unspecific_syntax_error: return "Unspecific syntax error"; - // clang-format on - - default: return "unknown"; - } -} - -constexpr inline std::string_view convert_json_error(int e) { - return convert_json_error(static_cast(e)); -} - -inline from_json_error convert_error(rapidjson::ParseErrorCode err) { - switch (err) { - // clang-format off - case rapidjson::kParseErrorNone: return from_json_error::no_error; - case rapidjson::kParseErrorDocumentEmpty: return from_json_error::document_empty; - case rapidjson::kParseErrorDocumentRootNotSingular: return from_json_error::document_root_not_singular; - case rapidjson::kParseErrorValueInvalid: return from_json_error::value_invalid; - case rapidjson::kParseErrorObjectMissName: return from_json_error::object_miss_name; - case rapidjson::kParseErrorObjectMissColon: return from_json_error::object_miss_colon; - case rapidjson::kParseErrorObjectMissCommaOrCurlyBracket: return from_json_error::object_miss_comma_or_curly_bracket; - case rapidjson::kParseErrorArrayMissCommaOrSquareBracket: return from_json_error::array_miss_comma_or_square_bracket; - case rapidjson::kParseErrorStringUnicodeEscapeInvalidHex: return from_json_error::string_unicode_escape_invalid_hex; - case rapidjson::kParseErrorStringUnicodeSurrogateInvalid: return from_json_error::string_unicode_surrogate_invalid; - case rapidjson::kParseErrorStringEscapeInvalid: return from_json_error::string_escape_invalid; - case rapidjson::kParseErrorStringMissQuotationMark: return from_json_error::string_miss_quotation_mark; - case rapidjson::kParseErrorStringInvalidEncoding: return from_json_error::string_invalid_encoding; - case rapidjson::kParseErrorNumberTooBig: return from_json_error::number_too_big; - case rapidjson::kParseErrorNumberMissFraction: return from_json_error::number_miss_fraction; - case rapidjson::kParseErrorNumberMissExponent: return from_json_error::number_miss_exponent; - case rapidjson::kParseErrorTermination: return from_json_error::terminated; - case rapidjson::kParseErrorUnspecificSyntaxError: return from_json_error::unspecific_syntax_error; - // clang-format on - - default: return from_json_error::unspecific_syntax_error; - } -} - - -inline auto convert_error_to_string_view(rapidjson::ParseErrorCode err) { - return convert_json_error(convert_error(err)); -} - -enum class json_token_type { - type_unread, - type_null, - type_bool, - type_string, - type_start_object, - type_key, - type_end_object, - type_start_array, - type_end_array, -}; - -struct json_token { - json_token_type type = {}; - std::string_view key = {}; - bool value_bool = {}; - std::string_view value_string = {}; -}; - -class json_token_stream : public rapidjson::BaseReaderHandler, json_token_stream> { - private: - rapidjson::Reader reader; - rapidjson::InsituStringStream ss; - - public: - json_token current_token; - - // This modifies json - json_token_stream(char* json) : ss{ json } { reader.IterativeParseInit(); } - - bool complete() { return reader.IterativeParseComplete(); } - - std::reference_wrapper peek_token() { - if (current_token.type != json_token_type::type_unread) - return current_token; - check( reader.IterativeParseNext(ss, *this), - convert_error_to_string_view(reader.GetParseErrorCode()) ); - return current_token; - } - - void eat_token() { current_token.type = json_token_type::type_unread; } - - void get_end() { - check( current_token.type == json_token_type::type_unread && complete(), - convert_json_error(from_json_error::expected_end) ); - } - bool get_null_pred() { - auto t = peek_token(); - if(t.get().type != json_token_type::type_null) - return false; - eat_token(); - return true; - } - void get_null() { - check(get_null_pred(), - convert_json_error(from_json_error::expected_null) ); - } - - bool get_bool() { - auto t = peek_token(); - check(t.get().type == json_token_type::type_bool, - convert_json_error(from_json_error::expected_bool) ); - eat_token(); - return t.get().value_bool; - } - - std::string_view get_string() { - auto t = peek_token(); - check(t.get().type == json_token_type::type_string, - convert_json_error(from_json_error::expected_string) ); - eat_token(); - return t.get().value_string; - } - - void get_start_object() { - auto t = peek_token(); - check(t.get().type == json_token_type::type_start_object, - convert_json_error(from_json_error::expected_start_object) ); - eat_token(); - } - - std::string_view get_key() { - auto t = peek_token(); - check(t.get().type == json_token_type::type_key, - convert_json_error(from_json_error::expected_key) ); - eat_token(); - return t.get().key; - } - - std::optional maybe_get_key() { - auto t = peek_token(); - if(t.get().type != json_token_type::type_key) - return {}; - eat_token(); - return t.get().key; - } - - bool get_end_object_pred() { - auto t = peek_token(); - if(t.get().type != json_token_type::type_end_object) - return false; - eat_token(); - return true; - } - - void get_end_object() { - auto t = peek_token(); - check(t.get().type == json_token_type::type_end_object, - convert_json_error(from_json_error::expected_end_object) ); - eat_token(); - } - - bool get_start_array_pred() { - auto t = peek_token(); - if(t.get().type != json_token_type::type_start_array) - return false; - eat_token(); - return true; - } - - bool get_end_array_pred() { - auto t = peek_token(); - if(t.get().type != json_token_type::type_end_array) - return false; - eat_token(); - return true; - } - void get_start_array() { - check(get_start_array_pred(), - convert_json_error(from_json_error::expected_start_array) ); - } - - void get_end_array() { - check(get_end_array_pred(), - convert_json_error(from_json_error::expected_end_array)); - } - - // BaseReaderHandler methods - bool Null() { - current_token.type = json_token_type::type_null; - return true; - } - bool Bool(bool v) { - current_token.type = json_token_type::type_bool; - current_token.value_bool = v; - return true; - } - bool RawNumber(const char* v, rapidjson::SizeType length, bool copy) { return String(v, length, copy); } - bool Int(int v) { return false; } - bool Uint(unsigned v) { return false; } - bool Int64(int64_t v) { return false; } - bool Uint64(uint64_t v) { return false; } - bool Double(double v) { return false; } - bool String(const char* v, rapidjson::SizeType length, bool) { - current_token.type = json_token_type::type_string; - current_token.value_string = { v, length }; - return true; - } - bool StartObject() { - current_token.type = json_token_type::type_start_object; - return true; - } - bool Key(const char* v, rapidjson::SizeType length, bool) { - current_token.key = { v, length }; - current_token.type = json_token_type::type_key; - return true; - } - bool EndObject(rapidjson::SizeType) { - current_token.type = json_token_type::type_end_object; - return true; - } - bool StartArray() { - current_token.type = json_token_type::type_start_array; - return true; - } - bool EndArray(rapidjson::SizeType) { - current_token.type = json_token_type::type_end_array; - return true; - } -}; // json_token_stream - -template -[[nodiscard]] bool unhex(DestIt dest, SrcIt begin, SrcIt end) { - auto get_digit = [&](uint8_t& nibble) { - if (*begin >= '0' && *begin <= '9') - nibble = *begin++ - '0'; - else if (*begin >= 'a' && *begin <= 'f') - nibble = *begin++ - 'a' + 10; - else if (*begin >= 'A' && *begin <= 'F') - nibble = *begin++ - 'A' + 10; - else - return false; - return true; - }; - while (begin != end) { - uint8_t h, l; - if (!get_digit(h) || !get_digit(l)) - return false; - *dest++ = (h << 4) | l; - } - return true; -} - -/// \exclude -template -void from_json(T& result, S& stream); - -/// \group from_json_explicit Parse JSON (Explicit Types) -/// Parse JSON and convert to `result`. These overloads handle specified types. -template -void from_json(std::string_view& result, S& stream) { - auto r = stream.get_string(); - result = r; -} - -/// \group from_json_explicit Parse JSON (Explicit Types) -/// Parse JSON and convert to `result`. These overloads handle specified types. -template -void from_json(std::string& result, S& stream) { - result = stream.get_string(); -} - -/// \exclude -template -void from_json_int(T& result, S& stream) { - auto r = stream.get_string(); - auto pos = r.data(); - auto end = pos + r.size(); - bool found = false; - result = 0; - T limit; - T sign; - if (std::is_signed_v && pos != end && *pos == '-') { - ++pos; - sign = -1; - limit = std::numeric_limits::min(); - } else { - sign = 1; - limit = std::numeric_limits::max(); - } - while (pos != end && *pos >= '0' && *pos <= '9') { - T digit = (*pos++ - '0'); - // abs(result) can overflow. Use -abs(result) instead. - // TODO refactor this logic, don't have time now - check(!(std::is_signed_v && (-sign * limit + digit) / 10 > -sign * result), - convert_json_error(from_json_error::number_out_of_range) ); - check(!(!std::is_signed_v && (limit - digit) / 10 < result), - convert_json_error(from_json_error::number_out_of_range) ); - result = result * 10 + sign * digit; - found = true; - } - check( pos == end && found, convert_json_error(from_json_error::expected_int) ); -} - -/// \group from_json_explicit -template -void from_json(uint8_t& result, S& stream) { - from_json_int(result, stream); -} - -/// \group from_json_explicit -template -void from_json(uint16_t& result, S& stream) { - from_json_int(result, stream); -} - -/// \group from_json_explicit -template -void from_json(uint32_t& result, S& stream) { - from_json_int(result, stream); -} - -/// \group from_json_explicit -template -void from_json(uint64_t& result, S& stream) { - from_json_int(result, stream); -} - -/// \group from_json_explicit -#ifndef ABIEOS_NO_INT128 -template -void from_json(unsigned __int128& result, S& stream) { - from_json_int(result, stream); -} -#endif - -/// \group from_json_explicit -template -void from_json(int8_t& result, S& stream) { - from_json_int(result, stream); -} - -/// \group from_json_explicit -template -void from_json(int16_t& result, S& stream) { - from_json_int(result, stream); -} - -/// \group from_json_explicit -template -void from_json(int32_t& result, S& stream) { - from_json_int(result, stream); -} - -/// \group from_json_explicit -template -void from_json(int64_t& result, S& stream) { - from_json_int(result, stream); -} - -/// \group from_json_explicit -#ifndef ABIEOS_NO_INT128 -template -void from_json(__int128& result, S& stream) { - from_json_int(result, stream); -} -#endif - -template -void from_json(float& result, S& stream) { - auto sv = stream.get_string(); - check( !sv.empty(), convert_json_error(from_json_error::expected_number) ); - std::string s(sv); // strtof expects a null-terminated string - errno = 0; - char* end; - result = std::strtof(s.c_str(), &end); - check( !errno && end == s.c_str() + s.size(), - convert_json_error(from_json_error::expected_number) ); -} - -template -void from_json(double& result, S& stream) { - auto sv = stream.get_string(); - check( !sv.empty(), convert_json_error(from_json_error::expected_number) ); - std::string s(sv); - errno = 0; - char* end; - result = std::strtod(s.c_str(), &end); - check( !errno && end == s.c_str() + s.size(), convert_json_error(from_json_error::expected_number) ); -} - -/* -/// \group from_json_explicit -template -result from_json(int32_t& result, S& stream) { - bool in_str = false; - if (pos != end && *pos == '"') { - in_str = true; - from_json_skip_space(pos, end); - } - bool neg = false; - if (pos != end && *pos == '-') { - neg = true; - ++pos; - } - bool found = false; - result = 0; - while (pos != end && *pos >= '0' && *pos <= '9') { - result = result * 10 + *pos++ - '0'; - found = true; - } - check(found, "expected integer"); - from_json_skip_space(pos, end); - if (in_str) { - from_json_expect(pos, end, '"', "expected integer"); - from_json_skip_space(pos, end); - } - if (neg) - result = -result; -} -*/ -/// \group from_json_explicit -template -void from_json(bool& result, S& stream) { - result = stream.get_bool(); -} - -/// \group from_json_explicit -template -void from_json(std::vector& result, S& stream) { - stream.get_start_array(); - while (true) { - auto t = stream.peek_token(); - if (t.get().type == json_token_type::type_end_array) - break; - result.emplace_back(); - from_json(result.back(), stream); - } - stream.get_end_array(); -} - -/// \group from_json_explicit -template -void from_json(std::optional& result, S& stream) { - if(stream.get_null_pred()) { - result = std::nullopt; - } else { - result.emplace(); - from_json(*result, stream); - } -} - -/// \output_section Parse JSON -/// Parse JSON and convert to `map`. This overload works with -/// [reflected objects](standardese://reflection/). -template -void from_json(std::map& result, S& stream) { - from_json_object(stream, [&](std::string_view key) { - from_json(result[Key(key)], stream); - }); -} - - -template -void set_variant_impl(std::variant& result, uint32_t type) { - if (type == N) { - result.template emplace(); - } else if constexpr (N + 1 < sizeof...(T)) { - set_variant_impl(result, type); - } -} - -/// \group from_json_explicit -template -void from_json(std::variant& result, S& stream) { - stream.get_start_array(); - std::string_view type; - from_json(type, stream); - const char* const type_names[] = { get_type_name((T*)nullptr)... }; - uint32_t type_idx = std::find(type_names, type_names + sizeof...(T), type) - type_names; - check( type_idx < sizeof...(T), convert_json_error(from_json_error::invalid_type_for_variant) ); - set_variant_impl(result, type_idx); - std::visit([&](auto& x) { from_json(x, stream); }, result); - stream.get_end_array(); -} - -/// \group from_json_explicit -template -void from_json_hex(std::vector& result, S& stream) { - auto s = stream.get_string(); - check( !(s.size() & 1), convert_json_error(from_json_error::expected_hex_string) ); - result.clear(); - result.reserve(s.size() / 2); - check( unhex(std::back_inserter(result), s.begin(), s.end()), - convert_json_error(from_json_error::expected_hex_string) ); -} - -#ifdef __eosio_cdt__ - -template void from_json(long double& result, S& stream) { - auto s = stream.get_string(); - check( s.size() == 32, convert_json_error(from_json_error::expected_hex_string) ); - check( unhex(reinterpret_cast(&result), s.begin(), s.end()), - convert_json_error(from_json_error::expected_hex_string) ); -} - -#endif - -/// \exclude -template -inline void from_json_object(S& stream, F f) { - stream.get_start_object(); - while (true) { - auto t = stream.peek_token(); - if (t.get().type == json_token_type::type_end_object) - break; - auto k = stream.get_key(); - f(k); - } - stream.get_end_object(); -} - -template -void from_json_skip_value(S& stream) { - uint64_t depth = 0; - do { - auto t = stream.peek_token(); - auto type = t.get().type; - if (type == json_token_type::type_start_object || type == json_token_type::type_start_array) - ++depth; - else if (type == json_token_type::type_end_object || type == json_token_type::type_end_array) - --depth; - stream.eat_token(); - } while (depth); -} - -/// \output_section Parse JSON (Reflected Objects) -/// Parse JSON and convert to `obj`. This overload works with -/// [reflected objects](standardese://reflection/). -template -void from_json(T& obj, S& stream) { - from_json_object(stream, [&](std::string_view key) { - bool found = false; - eosio::for_each_field([&](std::string_view member_name, auto member) { - if (!found && key == member_name) { - from_json(member(&obj), stream); - found = true; - } - }); - if (!found) - from_json_skip_value(stream); - }); -} - -template -void from_json(std::pair& obj, S& stream) { - check( false, convert_json_error(from_json_error::from_json_no_pair) ); -} - -/* -/// \output_section Convenience Wrappers -/// Parse JSON and return result. This overload wraps the other `to_json` overloads. -template -T from_json(const std::vector& v) { - const char* pos = v.data(); - const char* end = pos + v.size(); - from_json_skip_space(pos, end); - T result; - from_json(result, pos, end); - from_json_expect_end(pos, end); - return result; -} - -/// Parse JSON and return result. This overload wraps the other `to_json` overloads. -template -T from_json(std::string_view s) { - const char* pos = s.data(); - const char* end = pos + s.size(); - from_json_skip_space(pos, end); - T result; - from_json(result, pos, end); - from_json_expect_end(pos, end); - return result; -} -*/ - -/// Parse JSON and return result. This overload wraps the other `to_json` overloads. -template -T from_json(S& stream) { - T x; - from_json(x, stream); - return x; -} - -/* -/// \exclude -template -__attribute__((noinline)) void parse_named_variant_impl(tagged_variant& v, size_t i, - const char*& pos, const char* end) { - if constexpr (I < sizeof...(NamedTypes)) { - if (i == I) { - auto& q = v.value; - auto& x = q.template emplace(); - if constexpr (!is_named_empty_type_v>) { - from_json_expect(pos, end, ',', "expected ,"); - from_json(x, pos, end); - } - } else { - return parse_named_variant_impl(v, i, pos, end); - } - } else { - check(false, "invalid variant index"); - } -} - -/// \group from_json_explicit -template -__attribute__((noinline)) result from_json(tagged_variant& result, const char*& pos, - const char* end) { - from_json_skip_space(pos, end); - from_json_expect(pos, end, '[', "expected array"); - - eosio::name name; - from_json(name, pos, end); - - for (size_t i = 0; i < sizeof...(NamedTypes); ++i) { - if (name == tagged_variant::keys[i]) { - parse_named_variant_impl<0>(result, i, pos, end); - from_json_expect(pos, end, ']', "expected ]"); - return; - } - } - check(false, "invalid variant index name"); -} -*/ - -} // namespace eosio diff --git a/include/eosio_OLD/from_string.hpp b/include/eosio_OLD/from_string.hpp deleted file mode 100644 index e657289..0000000 --- a/include/eosio_OLD/from_string.hpp +++ /dev/null @@ -1,28 +0,0 @@ -#pragma once - -#include "stream.hpp" -#include - -namespace eosio { - -template -T from_string(S& stream) { - T obj; - from_string(obj, stream); - return obj; -} - -template -void convert_from_string(T& obj, std::string_view s) { - input_stream stream{ s }; - from_string(obj, stream); -} - -template -T convert_from_string(std::string_view s) { - T obj; - convert_from_string(obj, s); - return obj; -} - -} // namespace eosio diff --git a/include/eosio_OLD/map_macro.h b/include/eosio_OLD/map_macro.h deleted file mode 100644 index c8fd541..0000000 --- a/include/eosio_OLD/map_macro.h +++ /dev/null @@ -1,64 +0,0 @@ -/* - * Copyright (C) 2012 William Swanson - * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the "Software"), to deal in the Software without - * restriction, including without limitation the rights to use, copy, - * modify, merge, publish, distribute, sublicense, and/or sell copies - * of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY - * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF - * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - * - * Except as contained in this notice, the names of the authors or - * their institutions shall not be used in advertising or otherwise to - * promote the sale, use or other dealings in this Software without - * prior written authorization from the authors. - */ - -/* - * This file has been modified by block.one - */ - -#ifndef EOSIO_MAP_MACRO_H_INCLUDED -#define EOSIO_MAP_MACRO_H_INCLUDED - -#define EOSIO_EVAL0(...) __VA_ARGS__ -#define EOSIO_EVAL1(...) EOSIO_EVAL0(EOSIO_EVAL0(EOSIO_EVAL0(__VA_ARGS__))) -#define EOSIO_EVAL2(...) EOSIO_EVAL1(EOSIO_EVAL1(EOSIO_EVAL1(__VA_ARGS__))) -#define EOSIO_EVAL3(...) EOSIO_EVAL2(EOSIO_EVAL2(EOSIO_EVAL2(__VA_ARGS__))) -#define EOSIO_EVAL4(...) EOSIO_EVAL3(EOSIO_EVAL3(EOSIO_EVAL3(__VA_ARGS__))) -#define EOSIO_EVAL(...) EOSIO_EVAL4(EOSIO_EVAL4(EOSIO_EVAL4(__VA_ARGS__))) - -#define EOSIO_MAP_END(...) -#define EOSIO_MAP_OUT - -#define EOSIO_MAP_GET_END2() 0, EOSIO_MAP_END -#define EOSIO_MAP_GET_END1(...) EOSIO_MAP_GET_END2 -#define EOSIO_MAP_GET_END(...) EOSIO_MAP_GET_END1 -#define EOSIO_MAP_NEXT0(test, next, ...) next EOSIO_MAP_OUT -#define EOSIO_MAP_NEXT1(test, next) EOSIO_MAP_NEXT0(test, next, 0) -#define EOSIO_MAP_NEXT(test, next) EOSIO_MAP_NEXT1(EOSIO_MAP_GET_END test, next) - -// Macros below this point added by block.one - -#define EOSIO_MAP_REUSE_ARG0_0(f, arg0, x, peek, ...) \ - f(arg0, x) EOSIO_MAP_NEXT(peek, EOSIO_MAP_REUSE_ARG0_1)(f, arg0, peek, __VA_ARGS__) -#define EOSIO_MAP_REUSE_ARG0_1(f, arg0, x, peek, ...) \ - f(arg0, x) EOSIO_MAP_NEXT(peek, EOSIO_MAP_REUSE_ARG0_0)(f, arg0, peek, __VA_ARGS__) -// Handle 0 arguments -#define EOSIO_MAP_REUSE_ARG0_I(f, arg0, peek, ...) \ - EOSIO_MAP_NEXT(peek, EOSIO_MAP_REUSE_ARG0_1)(f, arg0, peek, __VA_ARGS__) -#define EOSIO_MAP_REUSE_ARG0(f, ...) EOSIO_EVAL(EOSIO_MAP_REUSE_ARG0_I(f, __VA_ARGS__, ()()(), ()()(), ()()(), 0)) - -#endif diff --git a/include/eosio_OLD/murmur.hpp b/include/eosio_OLD/murmur.hpp deleted file mode 100644 index 504e916..0000000 --- a/include/eosio_OLD/murmur.hpp +++ /dev/null @@ -1,55 +0,0 @@ - -namespace eosio { -namespace { - inline constexpr uint64_t unaligned_load(const char* p) - { - uint64_t r = 0; - for( uint32_t i = 0; i < 8; ++i ) { - r |= p[i]; - r <<= 8; - } - return r; - } - - // Loads n bytes, where 1 <= n < 8. - inline constexpr uint64_t load_bytes(const char* p, int n) - { - std::uint64_t result = 0; - --n; - do - result = (result << 8) + (unsigned char)(p[n]); - while (--n >= 0); - return result; - } - - inline constexpr uint64_t shift_mix(std::uint64_t v) - { return v ^ (v >> 47);} -} - -// Implementation of Murmur hash for 64-bit size_t. - inline constexpr uint64_t murmur64(const char* ptr, uint64_t len, uint64_t seed = 0xbadd00d00) - { - const uint64_t mul = (((uint64_t) 0xc6a4a793UL) << 32UL) - + (uint64_t) 0x5bd1e995UL; - const char* const buf = ptr; - - // Remove the bytes not divisible by the sizeof(uint64_t). This - // allows the main loop to process the data as 64-bit integers. - const uint64_t len_aligned = len & ~(uint64_t)0x7; - const char* const end = buf + len_aligned; - uint64_t hash = seed ^ (len * mul); - for (const char* p = buf; p != end; p += 8) { - const uint64_t data = shift_mix(unaligned_load(p) * mul) * mul; - hash ^= data; - hash *= mul; - } - if ((len & 0x7) != 0) { - const uint64_t data = load_bytes(end, len & 0x7); - hash ^= data; - hash *= mul; - } - hash = shift_mix(hash) * mul; - hash = shift_mix(hash); - return hash; - } -} // namespace eosio diff --git a/include/eosio_OLD/name.hpp b/include/eosio_OLD/name.hpp deleted file mode 100644 index 836770d..0000000 --- a/include/eosio_OLD/name.hpp +++ /dev/null @@ -1,179 +0,0 @@ -#pragma once - -#include "chain_conversions.hpp" -#include "check.hpp" -#include "operators.hpp" -#include "reflection.hpp" -#include "murmur.hpp" -#include - -namespace eosio { - -struct name { - enum class raw : uint64_t {}; - uint64_t value = 0; - - constexpr name() = default; - constexpr explicit name(uint64_t value) : value{ value } {} - constexpr explicit name(name::raw value) : value{ static_cast(value) } {} - constexpr explicit name(std::string_view str) : value{ string_to_name_strict(str) } { } - - constexpr name(const name&) = default; - constexpr name& operator=(const name&) = default; - - constexpr operator raw() const { return static_cast(value); } - explicit operator std::string() const { return eosio::name_to_string(value); } - std::string to_string() const { return std::string(*this); } - /** - * Explicit cast to bool of the uint64_t value of the name - * - * @return Returns true if the name is set to the default value of 0 else true. - */ - constexpr explicit operator bool() const { return value != 0; } - - /** - * Converts a %name Base32 symbol into its corresponding value - * - * @param c - Character to be converted - * @return constexpr char - Converted value - */ - static constexpr uint8_t char_to_value(char c) { - if (c == '.') - return 0; - else if (c >= '1' && c <= '5') - return (c - '1') + 1; - else if (c >= 'a' && c <= 'z') - return (c - 'a') + 6; - else - eosio::check(false, "character is not in allowed character set for names"); - - return 0; // control flow will never reach here; just added to suppress warning - } - - /** - * Returns the length of the %name - */ - constexpr uint8_t length() const { - constexpr uint64_t mask = 0xF800000000000000ull; - - if (value == 0) - return 0; - - uint8_t l = 0; - uint8_t i = 0; - for (auto v = value; i < 13; ++i, v <<= 5) { - if ((v & mask) > 0) { - l = i; - } - } - - return l + 1; - } - - /** - * Returns the suffix of the %name - */ - constexpr name suffix() const { - uint32_t remaining_bits_after_last_actual_dot = 0; - uint32_t tmp = 0; - for (int32_t remaining_bits = 59; remaining_bits >= 4; - remaining_bits -= 5) { // Note: remaining_bits must remain signed integer - // Get characters one-by-one in name in order from left to right (not including the 13th character) - auto c = (value >> remaining_bits) & 0x1Full; - if (!c) { // if this character is a dot - tmp = static_cast(remaining_bits); - } else { // if this character is not a dot - remaining_bits_after_last_actual_dot = tmp; - } - } - - uint64_t thirteenth_character = value & 0x0Full; - if (thirteenth_character) { // if 13th character is not a dot - remaining_bits_after_last_actual_dot = tmp; - } - - if (remaining_bits_after_last_actual_dot == - 0) // there is no actual dot in the %name other than potentially leading dots - return name{ value }; - - // At this point remaining_bits_after_last_actual_dot has to be within the range of 4 to 59 (and restricted to - // increments of 5). - - // Mask for remaining bits corresponding to characters after last actual dot, except for 4 least significant bits - // (corresponds to 13th character). - uint64_t mask = (1ull << remaining_bits_after_last_actual_dot) - 16; - uint32_t shift = 64 - remaining_bits_after_last_actual_dot; - - return name{ ((value & mask) << shift) + (thirteenth_character << (shift - 1)) }; - } - - /** - * Returns the prefix of the %name - */ - constexpr name prefix() const { - uint64_t result = value; - bool not_dot_character_seen = false; - uint64_t mask = 0xFull; - - // Get characters one-by-one in name in order from right to left - for (int32_t offset = 0; offset <= 59;) { - auto c = (value >> offset) & mask; - - if (!c) { // if this character is a dot - if (not_dot_character_seen) { // we found the rightmost dot character - result = (value >> offset) << offset; - break; - } - } else { - not_dot_character_seen = true; - } - - if (offset == 0) { - offset += 4; - mask = 0x1Full; - } else { - offset += 5; - } - } - - return name{ result }; - } -}; - -// TODO this seems weird and the name is misleading -// and I don't think this has ever been truly constexpr -inline constexpr uint64_t hash_name( std::string_view str ) { - auto r = try_string_to_name_strict(str); - if( r ) return r.value(); - return murmur64( str.data(), str.size() ); -} - -EOSIO_REFLECT(name, value); -EOSIO_COMPARE(name); - -template -void from_json(name& obj, S& stream) { - auto r = stream.get_string(); - obj = name(hash_name(r)); -} - -template -void to_json(const name& obj, S& stream) { - to_json(eosio::name_to_string(obj.value), stream); -} - -inline namespace literals { -#if defined(__clang__) -# pragma clang diagnostic push -# pragma clang diagnostic ignored "-Wgnu-string-literal-operator-template" -#endif - template - inline constexpr name operator""_n() { - return name(string_to_name_strict()); } - inline constexpr name operator""_h(const char* s, size_t) { return name( hash_name(s) ); } -#if defined(__clang__) -# pragma clang diagnostic pop -#endif -} // namespace literals - -} // namespace eosio diff --git a/include/eosio_OLD/opaque.hpp b/include/eosio_OLD/opaque.hpp deleted file mode 100644 index 06bd986..0000000 --- a/include/eosio_OLD/opaque.hpp +++ /dev/null @@ -1,184 +0,0 @@ -#pragma once -#include "to_bin.hpp" -#include "from_bin.hpp" -#include "stream.hpp" -#include "types.hpp" - -namespace eosio { - -/// -/// opaque type provides a type safe alternative to input_stream to declare a field -/// to be skiped during deserialization of its containing data structure. Afterwards, -/// the underlying value can be restored with correct type information. -/// -/// The serialization opaque consists of a variable length byte count followed by the -/// serialized bytes for a value of type T. The purpose to serialized as opaque as oppose -/// to T is to allow the client to delay deserialization until the value is actually needed and -/// thus saving some CPU cycles or memory requirement. -/// -/// For example, given a foo_type, -/// -/// -/// struct foo_type { -/// uint32_t field1; -/// string field2; -/// opaque> field3; -/// }; -/// -/// -/// the deserialization can be implemented as follows: -/// -/// -/// input_stream serialized_foo_stream(...); -/// foo_type foo_value; -/// from_bin(foo_value, serialized_foo_stream); -/// if (foo_value.field1 > 1 || foo_value.field2 == "meet_precondition") { -/// if(!foo_value.field3.empty()) { -/// loop_until(foo_value.field3, [](const auto& x) { -/// if (x.size() > 1) { -/// return true; -/// } -/// do_something(x); -/// return false; -/// }); -/// } -/// } -/// - -template -class opaque_base { - protected: - input_stream bin; - - opaque_base(input_stream b) : bin(b) {} - - public: - opaque_base() = default; - explicit opaque_base(const std::vector& data) : bin(data) {} - - /** - * @pre !this->empty() - */ - [[deprecated("Use unpack() free function instead.")]] void unpack(T& obj) { eosio::from_bin(obj, bin); } - - /** - * @pre !this->empty() - */ - [[deprecated("Use unpack() free function instead.")]] T unpack() { - T obj; - this->unpack(obj); - return obj; - } - - bool empty() const { return !bin.remaining(); } - size_t num_bytes() const { return bin.remaining(); } - - template - void from(S& stream) { - eosio::from_bin(this->bin, stream); - } - - template - void to_bin(S& stream) const { - eosio::to_bin(this->bin, stream); - } - - input_stream get() const { return bin; } -}; - -template -class opaque : public opaque_base { - public: - using opaque_base::opaque_base; - - template >> - opaque(opaque other) : opaque_base(other.bin) {} - - template - friend opaque as_opaque(input_stream bin); -}; - -template -class opaque> : public opaque_base> { - public: - using opaque_base>::opaque_base; - - /** Determine the size of the vector to be unpacked. - * - * @pre !this->empty() - */ - [[deprecated("Use for_each() or loop_until() free function instead.")]] uint64_t unpack_size() { - uint64_t num; - varuint64_from_bin(num, this->bin); - return num; - } - - [[deprecated("Use for_each() or loop_until() free function instead.")]] void unpack_next(T& obj) { - eosio::from_bin(obj, this->bin); - } - - [[deprecated("Use for_each() or loop_until() free function instead.")]] T unpack_next() { - T obj; - this->unpack_next(obj); - return obj; - } - - template - friend opaque as_opaque(input_stream bin); -}; - -template -constexpr const char* get_type_name(opaque*) { - return "bytes"; -} - -template -void from_bin(opaque& obj, S& stream) { - obj.from(stream); -} - -template -void to_bin(const opaque& obj, S& stream) { - obj.to_bin(stream); -} - -template -opaque as_opaque(input_stream bin) { - opaque result; - result.bin = bin; - return result; -} - -template -std::enable_if_t, bool> unpack(opaque opq, U& obj) { - if (opq.empty()) - return false; - input_stream bin = opq.get(); - eosio::from_bin(obj, bin); - return true; -} - -template -void loop_until(opaque> opq, Predicate&& f) { - if (opq.empty()) - return; - input_stream bin = opq.get(); - uint64_t num; - varuint64_from_bin(num, bin); - for (uint64_t i = 0; i < num; ++i) { - T obj; - eosio::from_bin(obj, bin); - if (f(std::move(obj))) - return; - } -} - -template -void for_each(opaque> opq, UnaryFunction&& f) { - loop_until(opq, [&f](auto&& x) { - f(std::forward(x)); - return false; - }); -} - -} // namespace eosio diff --git a/include/eosio_OLD/operators.hpp b/include/eosio_OLD/operators.hpp deleted file mode 100644 index fba63d7..0000000 --- a/include/eosio_OLD/operators.hpp +++ /dev/null @@ -1,71 +0,0 @@ -#pragma once - -#include "for_each_field.hpp" - -namespace eosio { namespace operators { - -// Defines comparison operators for a reflected struct -#define EOSIO_COMPARE(...) \ - auto eosio_enable_comparison(const __VA_ARGS__&)->bool; \ - using ::eosio::operators::operator==; \ - using ::eosio::operators::operator!=; \ - using ::eosio::operators::operator<; \ - using ::eosio::operators::operator>; \ - using ::eosio::operators::operator<=; \ - using ::eosio::operators::operator>=; \ - using ::eosio::operators::eosio_compare - - template - constexpr auto operator==(const T& lhs, const T& rhs) -> decltype(eosio_enable_comparison(lhs)) { - bool result = true; - for_each_field([&](const char*, auto&& member) { result = result && (member(&lhs) == member(&rhs)); }); - return result; - } - template - constexpr auto operator!=(const T& lhs, const T& rhs) -> decltype(eosio_enable_comparison(lhs)) { - return !(lhs == rhs); - } - - namespace internal_use_do_not_use { - // This is a worse match than the user-visible overload - template - constexpr int eosio_compare(const T& lhs, const U& rhs) { - if (lhs < rhs) - return -1; - else if (rhs < lhs) - return 1; - else - return 0; - } - } // namespace internal_use_do_not_use - - template - constexpr auto eosio_compare(const T& lhs, const T& rhs) -> decltype((eosio_enable_comparison(lhs), 0)) { - int result = 0; - for_each_field([&](const char*, auto&& member) { - if (!result) { - using internal_use_do_not_use::eosio_compare; - result = eosio_compare(member(&lhs), member(&rhs)); - } - }); - return result; - } - - template - constexpr auto operator<(const T& lhs, const T& rhs) -> decltype(eosio_enable_comparison(lhs)) { - return eosio_compare(lhs, rhs) < 0; - } - template - constexpr auto operator>(const T& lhs, const T& rhs) -> decltype(eosio_enable_comparison(lhs)) { - return eosio_compare(lhs, rhs) > 0; - } - template - constexpr auto operator<=(const T& lhs, const T& rhs) -> decltype(eosio_enable_comparison(lhs)) { - return eosio_compare(lhs, rhs) <= 0; - } - template - constexpr auto operator>=(const T& lhs, const T& rhs) -> decltype(eosio_enable_comparison(lhs)) { - return eosio_compare(lhs, rhs) >= 0; - } - -}} // namespace eosio::operators diff --git a/include/eosio_OLD/powers.h b/include/eosio_OLD/powers.h deleted file mode 100644 index 1d22d8e..0000000 --- a/include/eosio_OLD/powers.h +++ /dev/null @@ -1,76 +0,0 @@ -/// From https://github.com/night-shift/fpconv -/// Boost Software License 1.0 -/// See accompanying license file - -#pragma once - -#include - -#define npowers 87 -#define steppowers 8 -#define firstpower -348 /* 10 ^ -348 */ - -#define expmax -32 -#define expmin -60 - -typedef struct Fp { - uint64_t frac; - int exp; -} Fp; - -static Fp powers_ten[] = { - { 18054884314459144840U, -1220 }, { 13451937075301367670U, -1193 }, { 10022474136428063862U, -1166 }, - { 14934650266808366570U, -1140 }, { 11127181549972568877U, -1113 }, { 16580792590934885855U, -1087 }, - { 12353653155963782858U, -1060 }, { 18408377700990114895U, -1034 }, { 13715310171984221708U, -1007 }, - { 10218702384817765436U, -980 }, { 15227053142812498563U, -954 }, { 11345038669416679861U, -927 }, - { 16905424996341287883U, -901 }, { 12595523146049147757U, -874 }, { 9384396036005875287U, -847 }, - { 13983839803942852151U, -821 }, { 10418772551374772303U, -794 }, { 15525180923007089351U, -768 }, - { 11567161174868858868U, -741 }, { 17236413322193710309U, -715 }, { 12842128665889583758U, -688 }, - { 9568131466127621947U, -661 }, { 14257626930069360058U, -635 }, { 10622759856335341974U, -608 }, - { 15829145694278690180U, -582 }, { 11793632577567316726U, -555 }, { 17573882009934360870U, -529 }, - { 13093562431584567480U, -502 }, { 9755464219737475723U, -475 }, { 14536774485912137811U, -449 }, - { 10830740992659433045U, -422 }, { 16139061738043178685U, -396 }, { 12024538023802026127U, -369 }, - { 17917957937422433684U, -343 }, { 13349918974505688015U, -316 }, { 9946464728195732843U, -289 }, - { 14821387422376473014U, -263 }, { 11042794154864902060U, -236 }, { 16455045573212060422U, -210 }, - { 12259964326927110867U, -183 }, { 18268770466636286478U, -157 }, { 13611294676837538539U, -130 }, - { 10141204801825835212U, -103 }, { 15111572745182864684U, -77 }, { 11258999068426240000U, -50 }, - { 16777216000000000000U, -24 }, { 12500000000000000000U, 3 }, { 9313225746154785156U, 30 }, - { 13877787807814456755U, 56 }, { 10339757656912845936U, 83 }, { 15407439555097886824U, 109 }, - { 11479437019748901445U, 136 }, { 17105694144590052135U, 162 }, { 12744735289059618216U, 189 }, - { 9495567745759798747U, 216 }, { 14149498560666738074U, 242 }, { 10542197943230523224U, 269 }, - { 15709099088952724970U, 295 }, { 11704190886730495818U, 322 }, { 17440603504673385349U, 348 }, - { 12994262207056124023U, 375 }, { 9681479787123295682U, 402 }, { 14426529090290212157U, 428 }, - { 10748601772107342003U, 455 }, { 16016664761464807395U, 481 }, { 11933345169920330789U, 508 }, - { 17782069995880619868U, 534 }, { 13248674568444952270U, 561 }, { 9871031767461413346U, 588 }, - { 14708983551653345445U, 614 }, { 10959046745042015199U, 641 }, { 16330252207878254650U, 667 }, - { 12166986024289022870U, 694 }, { 18130221999122236476U, 720 }, { 13508068024458167312U, 747 }, - { 10064294952495520794U, 774 }, { 14996968138956309548U, 800 }, { 11173611982879273257U, 827 }, - { 16649979327439178909U, 853 }, { 12405201291620119593U, 880 }, { 9242595204427927429U, 907 }, - { 13772540099066387757U, 933 }, { 10261342003245940623U, 960 }, { 15290591125556738113U, 986 }, - { 11392378155556871081U, 1013 }, { 16975966327722178521U, 1039 }, { 12648080533535911531U, 1066 } -}; - -static Fp find_cachedpow10(int exp, int* k) { - const double one_log_ten = 0.30102999566398114; - - int approx = -(exp + npowers) * one_log_ten; - int idx = (approx - firstpower) / steppowers; - - while (1) { - int current = exp + powers_ten[idx].exp + 64; - - if (current < expmin) { - idx++; - continue; - } - - if (current > expmax) { - idx--; - continue; - } - - *k = (firstpower + idx * steppowers); - - return powers_ten[idx]; - } -} diff --git a/include/eosio_OLD/reflection.hpp b/include/eosio_OLD/reflection.hpp deleted file mode 100644 index 016d94d..0000000 --- a/include/eosio_OLD/reflection.hpp +++ /dev/null @@ -1,61 +0,0 @@ -#pragma once - -#include "map_macro.h" -#include - -namespace eosio { namespace reflection { - - template - struct has_for_each_field { - private: - struct F { - template - void operator()(const A&, const B&); - }; - - template - static char test(decltype(eosio_for_each_field((C*)nullptr, std::declval()))*); - - template - static long test(...); - - public: - static constexpr bool value = sizeof(test((void*)nullptr)) == sizeof(char); - }; - - template - inline constexpr bool has_for_each_field_v = has_for_each_field::value; - -#define EOSIO_REFLECT_MEMBER(STRUCT, FIELD) \ - f(#FIELD, [](auto p) -> decltype(&std::decay_t::FIELD) { return &std::decay_t::FIELD; }); - -#define EOSIO_REFLECT_STRIP_BASEbase -#define EOSIO_REFLECT_BASE(STRUCT, BASE) \ - static_assert(std::is_base_of_v, #BASE " is not a base class of " #STRUCT); \ - eosio_for_each_field((EOSIO_REFLECT_STRIP_BASE##BASE*)nullptr, f); - -#define EOSIO_REFLECT_SIGNATURE(STRUCT, ...) \ - [[maybe_unused]] inline constexpr const char* get_type_name(STRUCT*) { return #STRUCT; } \ - template \ - constexpr void eosio_for_each_field(STRUCT*, F f) - -/** - * EOSIO_REFLECT(, ...) - * Each parameter should be either the keyword 'base' followed by a base class of the struct or - * an identifier which names a non-static data member of the struct. - */ -#define EOSIO_REFLECT(...) \ - EOSIO_REFLECT_SIGNATURE(__VA_ARGS__) { EOSIO_MAP_REUSE_ARG0(EOSIO_REFLECT_INTERNAL, __VA_ARGS__) } - -// Identity the keyword 'base' followed by at least one token -#define EOSIO_REFLECT_SELECT_I(a, b, c, d, ...) EOSIO_REFLECT_##d -#define EOSIO_REFLECT_IS_BASE() ~, ~ -#define EOSIO_REFLECT_IS_BASE_TESTbase ~, EOSIO_REFLECT_IS_BASE - -#define EOSIO_APPLY(m, x) m x -#define EOSIO_CAT(x, y) x##y -#define EOSIO_REFLECT_INTERNAL(STRUCT, FIELD) \ - EOSIO_APPLY(EOSIO_REFLECT_SELECT_I, (EOSIO_CAT(EOSIO_REFLECT_IS_BASE_TEST, FIELD()), MEMBER, BASE, MEMBER)) \ - (STRUCT, FIELD) - -}} // namespace eosio::reflection diff --git a/include/eosio_OLD/ship_protocol.hpp b/include/eosio_OLD/ship_protocol.hpp deleted file mode 100644 index f0045f2..0000000 --- a/include/eosio_OLD/ship_protocol.hpp +++ /dev/null @@ -1,850 +0,0 @@ -#pragma once - -#include "abi.hpp" -#include "check.hpp" -#include "crypto.hpp" -#include "fixed_bytes.hpp" -#include "float.hpp" -#include "name.hpp" -#include "opaque.hpp" -#include "stream.hpp" -#include "time.hpp" -#include "varint.hpp" - -// todo: move -namespace eosio { -template -void to_json(const input_stream& data, S& stream) { - return to_json_hex(data.pos, data.end - data.pos, stream); -} - -constexpr const char* get_type_name(const input_stream*) { return "bytes"; } -} // namespace eosio - -namespace eosio { namespace ship_protocol { - - typedef __uint128_t uint128_t; - -#ifdef __eosio_cdt__ -# pragma clang diagnostic push -# pragma clang diagnostic ignored "-Winvalid-noreturn" - [[noreturn]] inline void report_error(const std::string& s) { eosio::check(false, s); } -# pragma clang diagnostic pop -#else - [[noreturn]] inline void report_error(const std::string& s) { throw std::runtime_error(s); } -#endif - - struct extension { - uint16_t type = {}; - eosio::input_stream data = {}; - }; - - EOSIO_REFLECT(extension, type, data) - - enum class transaction_status : uint8_t { - executed = 0, // succeed, no error handler executed - soft_fail = 1, // objectively failed (not executed), error handler executed - hard_fail = 2, // objectively failed and error handler objectively failed thus no state change - delayed = 3, // transaction delayed/deferred/scheduled for future execution - expired = 4, // transaction expired and storage space refunded to user - }; - - // todo: switch to eosio::result. switch to new serializer string support. - inline std::string to_string(transaction_status status) { - switch (status) { - case transaction_status::executed: return "executed"; - case transaction_status::soft_fail: return "soft_fail"; - case transaction_status::hard_fail: return "hard_fail"; - case transaction_status::delayed: return "delayed"; - case transaction_status::expired: return "expired"; - } - report_error("unknown status: " + std::to_string((uint8_t)status)); - } - - // todo: switch to eosio::result. switch to new serializer string support. - inline transaction_status get_transaction_status(const std::string& s) { - if (s == "executed") - return transaction_status::executed; - if (s == "soft_fail") - return transaction_status::soft_fail; - if (s == "hard_fail") - return transaction_status::hard_fail; - if (s == "delayed") - return transaction_status::delayed; - if (s == "expired") - return transaction_status::expired; - report_error("unknown status: " + s); - } - - struct get_status_request_v0 {}; - - EOSIO_REFLECT(get_status_request_v0) - - struct block_position { - uint32_t block_num = {}; - eosio::checksum256 block_id = {}; - }; - - EOSIO_REFLECT(block_position, block_num, block_id) - - struct get_status_result_v0 { - block_position head = {}; - block_position last_irreversible = {}; - uint32_t trace_begin_block = {}; - uint32_t trace_end_block = {}; - uint32_t chain_state_begin_block = {}; - uint32_t chain_state_end_block = {}; - might_not_exist chain_id; - }; - - EOSIO_REFLECT(get_status_result_v0, head, last_irreversible, trace_begin_block, trace_end_block, - chain_state_begin_block, chain_state_end_block, chain_id) - - struct get_blocks_request_v0 { - uint32_t start_block_num = {}; - uint32_t end_block_num = {}; - uint32_t max_messages_in_flight = {}; - std::vector have_positions = {}; - bool irreversible_only = {}; - bool fetch_block = {}; - bool fetch_traces = {}; - bool fetch_deltas = {}; - }; - - EOSIO_REFLECT(get_blocks_request_v0, start_block_num, end_block_num, max_messages_in_flight, have_positions, - irreversible_only, fetch_block, fetch_traces, fetch_deltas) - - struct get_blocks_ack_request_v0 { - uint32_t num_messages = {}; - }; - - EOSIO_REFLECT(get_blocks_ack_request_v0, num_messages) - - using request = std::variant; - - struct get_blocks_result_base { - block_position head = {}; - block_position last_irreversible = {}; - std::optional this_block = {}; - std::optional prev_block = {}; - }; - - EOSIO_REFLECT(get_blocks_result_base, head, last_irreversible, this_block, prev_block) - - struct get_blocks_result_v0 : get_blocks_result_base { - std::optional block = {}; - std::optional traces = {}; - std::optional deltas = {}; - }; - - EOSIO_REFLECT(get_blocks_result_v0, base get_blocks_result_base, block, traces, deltas) - - struct row_v0 { - bool present = {}; // false (not present), true (present, old / new) - eosio::input_stream data = {}; - }; - - EOSIO_REFLECT(row_v0, present, data) - - struct table_delta_v0 { - std::string name = {}; - std::vector rows = {}; - }; - - EOSIO_REFLECT(table_delta_v0, name, rows) - - using table_delta = std::variant; - - struct permission_level { - eosio::name actor = {}; - eosio::name permission = {}; - }; - - EOSIO_REFLECT(permission_level, actor, permission) - - struct action { - eosio::name account = {}; - eosio::name name = {}; - std::vector authorization = {}; - eosio::input_stream data = {}; - }; - - EOSIO_REFLECT(action, account, name, authorization, data) - - struct account_auth_sequence { - eosio::name account = {}; - uint64_t sequence = {}; - }; - - EOSIO_REFLECT(account_auth_sequence, account, sequence) - EOSIO_COMPARE(account_auth_sequence); - - struct action_receipt_v0 { - eosio::name receiver = {}; - eosio::checksum256 act_digest = {}; - uint64_t global_sequence = {}; - uint64_t recv_sequence = {}; - std::vector auth_sequence = {}; - eosio::varuint32 code_sequence = {}; - eosio::varuint32 abi_sequence = {}; - }; - - EOSIO_REFLECT(action_receipt_v0, receiver, act_digest, global_sequence, recv_sequence, auth_sequence, code_sequence, - abi_sequence) - - using action_receipt = std::variant; - - struct account_delta { - eosio::name account = {}; - int64_t delta = {}; - }; - - EOSIO_REFLECT(account_delta, account, delta) - EOSIO_COMPARE(account_delta); - - struct action_trace_v0 { - eosio::varuint32 action_ordinal = {}; - eosio::varuint32 creator_action_ordinal = {}; - std::optional receipt = {}; - eosio::name receiver = {}; - action act = {}; - bool context_free = {}; - int64_t elapsed = {}; - std::string console = {}; - std::vector account_ram_deltas = {}; - std::optional except = {}; - std::optional error_code = {}; - }; - - EOSIO_REFLECT(action_trace_v0, action_ordinal, creator_action_ordinal, receipt, receiver, act, context_free, elapsed, - console, account_ram_deltas, except, error_code) - - struct action_trace_v1 { - eosio::varuint32 action_ordinal = {}; - eosio::varuint32 creator_action_ordinal = {}; - std::optional receipt = {}; - eosio::name receiver = {}; - action act = {}; - bool context_free = {}; - int64_t elapsed = {}; - std::string console = {}; - std::vector account_ram_deltas = {}; - std::optional except = {}; - std::optional error_code = {}; - eosio::input_stream return_value = {}; - }; - - EOSIO_REFLECT(action_trace_v1, action_ordinal, creator_action_ordinal, receipt, receiver, act, context_free, elapsed, - console, account_ram_deltas, except, error_code, return_value) - - using action_trace = std::variant; - - struct partial_transaction_v0 { - eosio::time_point_sec expiration = {}; - uint16_t ref_block_num = {}; - uint32_t ref_block_prefix = {}; - eosio::varuint32 max_net_usage_words = {}; - uint8_t max_cpu_usage_ms = {}; - eosio::varuint32 delay_sec = {}; - std::vector transaction_extensions = {}; - std::vector signatures = {}; - std::vector context_free_data = {}; - }; - - EOSIO_REFLECT(partial_transaction_v0, expiration, ref_block_num, ref_block_prefix, max_net_usage_words, - max_cpu_usage_ms, delay_sec, transaction_extensions, signatures, context_free_data) - - using partial_transaction = std::variant; - - struct recurse_transaction_trace; - - struct transaction_trace_v0 { - eosio::checksum256 id = {}; - transaction_status status = {}; - uint32_t cpu_usage_us = {}; - eosio::varuint32 net_usage_words = {}; - int64_t elapsed = {}; - uint64_t net_usage = {}; - bool scheduled = {}; - std::vector action_traces = {}; - std::optional account_ram_delta = {}; - std::optional except = {}; - std::optional error_code = {}; - // semantically, this should be std::optional; - // optional serializes as bool[,transaction_trace] - // vector serializes as size[,transaction_trace..] but vector will only ever have 0 or 1 transaction trace - // This assumes that bool and size for false/true serializes to same as size 0/1 - std::vector failed_dtrx_trace = {}; - std::optional partial = {}; - }; - - EOSIO_REFLECT(transaction_trace_v0, id, status, cpu_usage_us, net_usage_words, elapsed, net_usage, scheduled, - action_traces, account_ram_delta, except, error_code, failed_dtrx_trace, partial) - - using transaction_trace = std::variant; - - struct recurse_transaction_trace { - transaction_trace recurse = {}; - }; - - struct producer_key { - eosio::name producer_name = {}; - eosio::public_key block_signing_key = {}; - }; - - EOSIO_REFLECT(producer_key, producer_name, block_signing_key) - - struct producer_schedule { - uint32_t version = {}; - std::vector producers = {}; - }; - - EOSIO_REFLECT(producer_schedule, version, producers) - - struct transaction_receipt_header { - transaction_status status = {}; - uint32_t cpu_usage_us = {}; - eosio::varuint32 net_usage_words = {}; - }; - - EOSIO_REFLECT(transaction_receipt_header, status, cpu_usage_us, net_usage_words) - - struct packed_transaction { - std::vector signatures = {}; - uint8_t compression = {}; - eosio::input_stream packed_context_free_data = {}; - eosio::input_stream packed_trx = {}; - }; - - EOSIO_REFLECT(packed_transaction, signatures, compression, packed_context_free_data, packed_trx) - - using transaction_variant_v0 = std::variant; - - struct transaction_receipt_v0 : transaction_receipt_header { - transaction_variant_v0 trx = {}; - }; - - EOSIO_REFLECT(transaction_receipt_v0, base transaction_receipt_header, trx) - - using transaction_variant = std::variant; - - struct transaction_receipt : transaction_receipt_header { - transaction_variant trx = {}; - }; - - EOSIO_REFLECT(transaction_receipt, base transaction_receipt_header, trx) - - struct block_header { - eosio::block_timestamp timestamp{}; - eosio::name producer = {}; - uint16_t confirmed = {}; - eosio::checksum256 previous = {}; - eosio::checksum256 transaction_mroot = {}; - eosio::checksum256 action_mroot = {}; - uint32_t schedule_version = {}; - std::optional new_producers = {}; - std::vector header_extensions = {}; - }; - - EOSIO_REFLECT(block_header, timestamp, producer, confirmed, previous, transaction_mroot, action_mroot, - schedule_version, new_producers, header_extensions) - - struct signed_block_header : block_header { - eosio::signature producer_signature = {}; - }; - - EOSIO_REFLECT(signed_block_header, base block_header, producer_signature) - - struct signed_block : signed_block_header { - std::vector transactions = {}; - std::vector block_extensions = {}; - }; - - EOSIO_REFLECT(signed_block, base signed_block_header, transactions, block_extensions) - - using result = std::variant; - - struct transaction_header { - eosio::time_point_sec expiration = {}; - uint16_t ref_block_num = {}; - uint32_t ref_block_prefix = {}; - eosio::varuint32 max_net_usage_words = {}; - uint8_t max_cpu_usage_ms = {}; - eosio::varuint32 delay_sec = {}; - }; - - EOSIO_REFLECT(transaction_header, expiration, ref_block_num, ref_block_prefix, max_net_usage_words, max_cpu_usage_ms, - delay_sec) - - struct transaction : transaction_header { - std::vector context_free_actions = {}; - std::vector actions = {}; - std::vector transaction_extensions = {}; - }; - - EOSIO_REFLECT(transaction, base transaction_header, context_free_actions, actions, transaction_extensions) - - struct code_id { - uint8_t vm_type = {}; - uint8_t vm_version = {}; - eosio::checksum256 code_hash = {}; - }; - - EOSIO_REFLECT(code_id, vm_type, vm_version, code_hash) - - struct account_v0 { - eosio::name name = {}; - eosio::block_timestamp creation_date = {}; - eosio::input_stream abi = {}; - }; - - EOSIO_REFLECT(account_v0, name, creation_date, abi) - - using account = std::variant; - - struct account_metadata_v0 { - eosio::name name = {}; - bool privileged = {}; - eosio::time_point last_code_update = {}; - std::optional code = {}; - }; - - EOSIO_REFLECT(account_metadata_v0, name, privileged, last_code_update, code) - - using account_metadata = std::variant; - - struct code_v0 { - uint8_t vm_type = {}; - uint8_t vm_version = {}; - eosio::checksum256 code_hash = {}; - eosio::input_stream code = {}; - }; - - EOSIO_REFLECT(code_v0, vm_type, vm_version, code_hash, code) - - using code = std::variant; - - struct contract_table_v0 { - eosio::name code = {}; - eosio::name scope = {}; - eosio::name table = {}; - eosio::name payer = {}; - }; - - EOSIO_REFLECT(contract_table_v0, code, scope, table, payer) - - using contract_table = std::variant; - - struct contract_row_v0 { - eosio::name code = {}; - eosio::name scope = {}; - eosio::name table = {}; - uint64_t primary_key = {}; - eosio::name payer = {}; - eosio::input_stream value = {}; - }; - - EOSIO_REFLECT(contract_row_v0, code, scope, table, primary_key, payer, value) - - using contract_row = std::variant; - - struct contract_index64_v0 { - eosio::name code = {}; - eosio::name scope = {}; - eosio::name table = {}; - uint64_t primary_key = {}; - eosio::name payer = {}; - uint64_t secondary_key = {}; - }; - - EOSIO_REFLECT(contract_index64_v0, code, scope, table, primary_key, payer, secondary_key) - - using contract_index64 = std::variant; - - struct contract_index128_v0 { - eosio::name code = {}; - eosio::name scope = {}; - eosio::name table = {}; - uint64_t primary_key = {}; - eosio::name payer = {}; - uint128_t secondary_key = {}; - }; - - EOSIO_REFLECT(contract_index128_v0, code, scope, table, primary_key, payer, secondary_key) - - using contract_index128 = std::variant; - - struct contract_index256_v0 { - eosio::name code = {}; - eosio::name scope = {}; - eosio::name table = {}; - uint64_t primary_key = {}; - eosio::name payer = {}; - eosio::checksum256 secondary_key = {}; - }; - - EOSIO_REFLECT(contract_index256_v0, code, scope, table, primary_key, payer, secondary_key) - - using contract_index256 = std::variant; - - struct contract_index_double_v0 { - eosio::name code = {}; - eosio::name scope = {}; - eosio::name table = {}; - uint64_t primary_key = {}; - eosio::name payer = {}; - double secondary_key = {}; - }; - - EOSIO_REFLECT(contract_index_double_v0, code, scope, table, primary_key, payer, secondary_key) - - using contract_index_double = std::variant; - - struct contract_index_long_double_v0 { - eosio::name code = {}; - eosio::name scope = {}; - eosio::name table = {}; - uint64_t primary_key = {}; - eosio::name payer = {}; - eosio::float128 secondary_key = {}; - }; - - EOSIO_REFLECT(contract_index_long_double_v0, code, scope, table, primary_key, payer, secondary_key) - - using contract_index_long_double = std::variant; - - struct key_weight { - eosio::public_key key = {}; - uint16_t weight = {}; - }; - - EOSIO_REFLECT(key_weight, key, weight) - - struct block_signing_authority_v0 { - uint32_t threshold = {}; - std::vector keys = {}; - }; - - EOSIO_REFLECT(block_signing_authority_v0, threshold, keys) - - using block_signing_authority = std::variant; - - struct producer_authority { - eosio::name producer_name = {}; - block_signing_authority authority = {}; - }; - - EOSIO_REFLECT(producer_authority, producer_name, authority) - - struct producer_authority_schedule { - uint32_t version = {}; - std::vector producers = {}; - }; - - EOSIO_REFLECT(producer_authority_schedule, version, producers) - - struct chain_config_v0 { - uint64_t max_block_net_usage = {}; - uint32_t target_block_net_usage_pct = {}; - uint32_t max_transaction_net_usage = {}; - uint32_t base_per_transaction_net_usage = {}; - uint32_t net_usage_leeway = {}; - uint32_t context_free_discount_net_usage_num = {}; - uint32_t context_free_discount_net_usage_den = {}; - uint32_t max_block_cpu_usage = {}; - uint32_t target_block_cpu_usage_pct = {}; - uint32_t max_transaction_cpu_usage = {}; - uint32_t min_transaction_cpu_usage = {}; - uint32_t max_transaction_lifetime = {}; - uint32_t deferred_trx_expiration_window = {}; - uint32_t max_transaction_delay = {}; - uint32_t max_inline_action_size = {}; - uint16_t max_inline_action_depth = {}; - uint16_t max_authority_depth = {}; - }; - - EOSIO_REFLECT(chain_config_v0, max_block_net_usage, target_block_net_usage_pct, max_transaction_net_usage, - base_per_transaction_net_usage, net_usage_leeway, context_free_discount_net_usage_num, - context_free_discount_net_usage_den, max_block_cpu_usage, target_block_cpu_usage_pct, - max_transaction_cpu_usage, min_transaction_cpu_usage, max_transaction_lifetime, - deferred_trx_expiration_window, max_transaction_delay, max_inline_action_size, max_inline_action_depth, - max_authority_depth) - - struct chain_config_v1 { - uint64_t max_block_net_usage = {}; - uint32_t target_block_net_usage_pct = {}; - uint32_t max_transaction_net_usage = {}; - uint32_t base_per_transaction_net_usage = {}; - uint32_t net_usage_leeway = {}; - uint32_t context_free_discount_net_usage_num = {}; - uint32_t context_free_discount_net_usage_den = {}; - uint32_t max_block_cpu_usage = {}; - uint32_t target_block_cpu_usage_pct = {}; - uint32_t max_transaction_cpu_usage = {}; - uint32_t min_transaction_cpu_usage = {}; - uint32_t max_transaction_lifetime = {}; - uint32_t deferred_trx_expiration_window = {}; - uint32_t max_transaction_delay = {}; - uint32_t max_inline_action_size = {}; - uint16_t max_inline_action_depth = {}; - uint16_t max_authority_depth = {}; - uint32_t max_action_return_value_size = {}; - }; - - EOSIO_REFLECT(chain_config_v1, max_block_net_usage, target_block_net_usage_pct, max_transaction_net_usage, - base_per_transaction_net_usage, net_usage_leeway, context_free_discount_net_usage_num, - context_free_discount_net_usage_den, max_block_cpu_usage, target_block_cpu_usage_pct, - max_transaction_cpu_usage, min_transaction_cpu_usage, max_transaction_lifetime, - deferred_trx_expiration_window, max_transaction_delay, max_inline_action_size, max_inline_action_depth, - max_authority_depth, max_action_return_value_size) - - using chain_config = std::variant; - - struct wasm_config_v0 { - uint32_t max_mutable_global_bytes = {}; - uint32_t max_table_elements = {}; - uint32_t max_section_elements = {}; - uint32_t max_linear_memory_init = {}; - uint32_t max_func_local_bytes = {}; - uint32_t max_nested_structures = {}; - uint32_t max_symbol_bytes = {}; - uint32_t max_module_bytes = {}; - uint32_t max_code_bytes = {}; - uint32_t max_pages = {}; - uint32_t max_call_depth = {}; - }; - - EOSIO_REFLECT(wasm_config_v0, max_mutable_global_bytes, max_table_elements, max_section_elements, - max_linear_memory_init, max_func_local_bytes, max_nested_structures, max_symbol_bytes, - max_module_bytes, max_code_bytes, max_pages, max_call_depth) - - using wasm_config = std::variant; - - struct global_property_v0 { - std::optional proposed_schedule_block_num = {}; - producer_schedule proposed_schedule = {}; - chain_config configuration = {}; - }; - - EOSIO_REFLECT(global_property_v0, proposed_schedule_block_num, proposed_schedule, configuration) - - struct global_property_v1 { - std::optional proposed_schedule_block_num = {}; - producer_authority_schedule proposed_schedule = {}; - chain_config configuration = {}; - eosio::checksum256 chain_id = {}; - might_not_exist wasm_configuration; - }; - - EOSIO_REFLECT(global_property_v1, proposed_schedule_block_num, proposed_schedule, configuration, chain_id, wasm_configuration) - - using global_property = std::variant; - - struct generated_transaction_v0 { - eosio::name sender = {}; - uint128_t sender_id = {}; - eosio::name payer = {}; - eosio::checksum256 trx_id = {}; - eosio::input_stream packed_trx = {}; - }; - - EOSIO_REFLECT(generated_transaction_v0, sender, sender_id, payer, trx_id, packed_trx) - - using generated_transaction = std::variant; - - struct activated_protocol_feature_v0 { - eosio::checksum256 feature_digest = {}; - uint32_t activation_block_num = {}; - }; - - EOSIO_REFLECT(activated_protocol_feature_v0, feature_digest, activation_block_num) - - using activated_protocol_feature = std::variant; - - struct protocol_state_v0 { - std::vector activated_protocol_features = {}; - }; - - EOSIO_REFLECT(protocol_state_v0, activated_protocol_features) - - using protocol_state = std::variant; - - struct permission_level_weight { - permission_level permission = {}; - uint16_t weight = {}; - }; - - EOSIO_REFLECT(permission_level_weight, permission, weight) - - struct wait_weight { - uint32_t wait_sec = {}; - uint16_t weight = {}; - }; - - EOSIO_REFLECT(wait_weight, wait_sec, weight) - - struct authority { - uint32_t threshold = {}; - std::vector keys = {}; - std::vector accounts = {}; - std::vector waits = {}; - }; - - EOSIO_REFLECT(authority, threshold, keys, accounts, waits) - - struct permission_v0 { - eosio::name owner = {}; - eosio::name name = {}; - eosio::name parent = {}; - eosio::time_point last_updated = {}; - authority auth = {}; - }; - - EOSIO_REFLECT(permission_v0, owner, name, parent, last_updated, auth) - - using permission = std::variant; - - struct permission_link_v0 { - eosio::name account = {}; - eosio::name code = {}; - eosio::name message_type = {}; - eosio::name required_permission = {}; - }; - - EOSIO_REFLECT(permission_link_v0, account, code, message_type, required_permission) - - using permission_link = std::variant; - - struct resource_limits_v0 { - eosio::name owner = {}; - int64_t net_weight = {}; - int64_t cpu_weight = {}; - int64_t ram_bytes = {}; - }; - - EOSIO_REFLECT(resource_limits_v0, owner, net_weight, cpu_weight, ram_bytes) - - using resource_limits = std::variant; - - struct usage_accumulator_v0 { - uint32_t last_ordinal = {}; - uint64_t value_ex = {}; - uint64_t consumed = {}; - }; - - EOSIO_REFLECT(usage_accumulator_v0, last_ordinal, value_ex, consumed) - - using usage_accumulator = std::variant; - - struct resource_usage_v0 { - eosio::name owner = {}; - usage_accumulator net_usage = {}; - usage_accumulator cpu_usage = {}; - uint64_t ram_usage = {}; - }; - - EOSIO_REFLECT(resource_usage_v0, owner, net_usage, cpu_usage, ram_usage) - - using resource_usage = std::variant; - - struct resource_limits_state_v0 { - usage_accumulator average_block_net_usage = {}; - usage_accumulator average_block_cpu_usage = {}; - uint64_t total_net_weight = {}; - uint64_t total_cpu_weight = {}; - uint64_t total_ram_bytes = {}; - uint64_t virtual_net_limit = {}; - uint64_t virtual_cpu_limit = {}; - }; - - EOSIO_REFLECT(resource_limits_state_v0, average_block_net_usage, average_block_cpu_usage, total_net_weight, - total_cpu_weight, total_ram_bytes, virtual_net_limit, virtual_cpu_limit) - - using resource_limits_state = std::variant; - - struct resource_limits_ratio_v0 { - uint64_t numerator = {}; - uint64_t denominator = {}; - }; - - EOSIO_REFLECT(resource_limits_ratio_v0, numerator, denominator) - - using resource_limits_ratio = std::variant; - - struct elastic_limit_parameters_v0 { - uint64_t target = {}; - uint64_t max = {}; - uint32_t periods = {}; - uint32_t max_multiplier = {}; - resource_limits_ratio contract_rate = {}; - resource_limits_ratio expand_rate = {}; - }; - - EOSIO_REFLECT(elastic_limit_parameters_v0, target, max, periods, max_multiplier, contract_rate, expand_rate) - - using elastic_limit_parameters = std::variant; - - struct resource_limits_config_v0 { - elastic_limit_parameters cpu_limit_parameters = {}; - elastic_limit_parameters net_limit_parameters = {}; - uint32_t account_cpu_usage_average_window = {}; - uint32_t account_net_usage_average_window = {}; - }; - - EOSIO_REFLECT(resource_limits_config_v0, cpu_limit_parameters, net_limit_parameters, - account_cpu_usage_average_window, account_net_usage_average_window) - - using resource_limits_config = std::variant; - -}} // namespace eosio::ship_protocol - -namespace eosio { - - template - void to_json(const ship_protocol::transaction_status& status, S& stream) { - // todo: switch to new serializer string support. - return eosio::to_json((uint8_t)status, stream); - } - - template - void from_json(ship_protocol::transaction_status& status, S& stream) { - uint8_t v; - eosio::from_json(v, stream); - status = (ship_protocol::transaction_status)v; - } - - template - void to_bin(const ship_protocol::recurse_transaction_trace& obj, S& stream) { - return to_bin(obj.recurse, stream); - } - - template - void from_bin(ship_protocol::recurse_transaction_trace& obj, S& stream) { - return from_bin(obj.recurse, stream); - } - - template - void to_json(const ship_protocol::recurse_transaction_trace& obj, S& stream) { - return to_json(obj.recurse, stream); - } - - template - void to_json(const std::vector& obj, S& stream) { - if (!obj.empty()) { - to_json(obj[0], stream); - } else { - stream.write("null", 4); - } - } - - template - void from_json(std::vector& result, S& stream) { - if(stream.get_null_pred()) { - result.clear(); - } else { - result.emplace_back(); - from_json(result[0], stream); - } - } - -} diff --git a/include/eosio_OLD/stream.hpp b/include/eosio_OLD/stream.hpp deleted file mode 100644 index b5752be..0000000 --- a/include/eosio_OLD/stream.hpp +++ /dev/null @@ -1,235 +0,0 @@ -#pragma once - -#include "check.hpp" -#include -#include -#include -#include -#include -#include -#include -#include - -namespace eosio { - -enum class stream_error { - no_error, - overrun, - underrun, - float_error, - varuint_too_big, - invalid_varuint_encoding, - bad_variant_index, - invalid_asset_format, - array_size_mismatch, - invalid_name_char, - invalid_name_char13, - name_too_long, - json_writer_error, // !!! -}; // stream_error - -constexpr inline std::string_view convert_stream_error(stream_error e) { - switch (e) { - // clang-format off - case stream_error::no_error: return "No error"; - case stream_error::overrun: return "Stream overrun"; - case stream_error::underrun: return "Stream underrun"; - case stream_error::float_error: return "Float error"; - case stream_error::varuint_too_big: return "Varuint too big"; - case stream_error::invalid_varuint_encoding: return "Invalid varuint encoding"; - case stream_error::bad_variant_index: return "Bad variant index"; - case stream_error::invalid_asset_format: return "Invalid asset format"; - case stream_error::array_size_mismatch: return "T[] size and unpacked size don't match"; - case stream_error::invalid_name_char: return "character is not in allowed character set for names"; - case stream_error::invalid_name_char13: return "thirteenth character in name cannot be a letter that comes after j"; - case stream_error::name_too_long: return "string is too long to be a valid name"; - case stream_error::json_writer_error: return "Error writing json"; - // clang-format on - - default: return "unknown"; - } -} - -template -constexpr bool has_bitwise_serialization() { - if constexpr (std::is_arithmetic_v -#ifndef ABIEOS_NO_INT128 - || std::is_same_v || std::is_same_v -#endif - ) { - return true; - } else if constexpr (std::is_enum_v) { - static_assert(!std::is_convertible_v>, "Serializing unscoped enum"); - return true; - } else { - return false; - } -} - -template -struct small_buffer { - char data[max_size]; - char* pos{ data }; - - void reverse() { std::reverse(data, pos); } -}; - -struct vector_stream { - std::vector& data; - vector_stream(std::vector& data) : data(data) {} - - void write(char c) { - data.push_back(c); - } - void write(const void* src, std::size_t sz) { - auto s = reinterpret_cast(src); - data.insert( data.end(), s, s + sz ); - } - template - void write_raw(const T& v) { - write(&v, sizeof(v)); - } -}; - -struct fixed_buf_stream { - char* pos; - char* end; - - fixed_buf_stream(char* pos, size_t size) : pos{ pos }, end{ pos + size } {} - - void write(char c) { - check( pos < end, convert_stream_error(stream_error::overrun) ); - *pos++ = c; - } - - void write(const void* src, std::size_t sz) { - check( pos + sz <= end, convert_stream_error(stream_error::overrun) ); - memcpy(pos, src, sz); - pos += sz; - } - - template - void write(const char (&src)[Size]) { - write(src, Size); - } - - template - void write_raw(const T& v) { - write(&v, sizeof(v)); - } -}; - -struct size_stream { - size_t size = 0; - - void write(char c) { - ++size; - } - - void write(const void* src, std::size_t sz) { - size += sz; - } - - template - void write(const char (&src)[Size]) { - size += Size; - } - - template - void write_raw(const T& v) { - size += sizeof(v); - } -}; - -template -void increase_indent(S&) { -} - -template -void decrease_indent(S&) { -} - -template -void write_colon(S& s) { - s.write(':'); -} - -template -void write_newline(S&) { -} - -template -struct pretty_stream : Base { - using Base::Base; - int indent_size = 4; - std::vector current_indent; -}; - -template -void increase_indent(pretty_stream& s) { - s.current_indent.resize(s.current_indent.size() + s.indent_size, ' '); -} - -template -void decrease_indent(pretty_stream& s) { - check( s.current_indent.size() >= s.indent_size, - convert_stream_error(stream_error::overrun) ); - s.current_indent.resize(s.current_indent.size() - s.indent_size); -} - -template -void write_colon(pretty_stream& s) { - s.write(": ", 2); -} - -template -void write_newline(pretty_stream& s) { - s.write('\n'); - s.write(s.current_indent.data(), s.current_indent.size()); -} - -struct input_stream { - const char* pos; - const char* end; - - input_stream() : pos{ nullptr }, end{ nullptr } {} - input_stream(const char* pos, size_t size) : pos{ pos }, end{ pos + size } {} - input_stream(const char* pos, const char* end) : pos{ pos }, end{ end } {} - input_stream(const std::vector& v) : pos{ v.data() }, end{ v.data() + v.size() } {} - input_stream(std::string_view v) : pos{ v.data() }, end{ v.data() + v.size() } {} - input_stream(const input_stream&) = default; - - input_stream& operator=(const input_stream&) = default; - - size_t remaining() const { return end - pos; } - - void check_available(size_t size) const { - check( size <= std::size_t(end-pos), convert_stream_error(stream_error::overrun) ); - } - - auto get_pos() const { return pos; } - - void read(void* dest, size_t size) { - check( size <= size_t(end-pos), convert_stream_error(stream_error::overrun) ); - memcpy(dest, pos, size); - pos += size; - } - - template - void read_raw(T& dest) { - read(&dest, sizeof(dest)); - } - - void skip(size_t size) { - check( size <= size_t(end-pos), convert_stream_error(stream_error::overrun) ); - pos += size; - } - - void read_reuse_storage(const char*& result, size_t size) { - check( size <= size_t(end-pos), convert_stream_error(stream_error::overrun) ); - result = pos; - pos += size; - } -}; - -} // namespace eosio diff --git a/include/eosio_OLD/symbol.hpp b/include/eosio_OLD/symbol.hpp deleted file mode 100644 index e33dd3e..0000000 --- a/include/eosio_OLD/symbol.hpp +++ /dev/null @@ -1,300 +0,0 @@ -/** - * @file - * @copyright defined in eos/LICENSE - */ -#pragma once - -#include "chain_conversions.hpp" -#include "check.hpp" -#include "from_json.hpp" -#include "name.hpp" -#include "operators.hpp" -#include "reflection.hpp" - -#include -#include -#include - -namespace eosio { -/** - * @defgroup symbol Symbol - * @ingroup core - * @brief Defines C++ API for managing symbols - */ - -/** - * Stores the symbol code as a uint64_t value - * - * @ingroup symbol - */ -class symbol_code { - public: - /** - * Default constructor, construct a new symbol_code - * - * @brief Construct a new symbol_code object defaulting to a value of 0 - * - */ - constexpr symbol_code() : value(0) {} - - /** - * Construct a new symbol_code given a scoped enumerated type of raw (uint64_t). - * - * @brief Construct a new symbol_code object initialising value with raw - * @param raw - The raw value which is a scoped enumerated type of unit64_t - * - */ - constexpr explicit symbol_code(uint64_t raw) : value(raw) {} - - /** - * Construct a new symbol_code given an string. - * - * @brief Construct a new symbol_code object initialising value with str - * @param str - The string value which validated then converted to unit64_t - * - */ - constexpr explicit symbol_code(std::string_view str) : value(0) { - if (str.size() > 7) { - eosio::check(false, "string is too long to be a valid symbol_code"); - } - for (auto itr = str.rbegin(); itr != str.rend(); ++itr) { - if (*itr < 'A' || *itr > 'Z') { - eosio::check(false, "only uppercase letters allowed in symbol_code string"); - } - value <<= 8; - value |= *itr; - } - } - - /** - * Checks if the symbol code is valid - * @return true - if symbol is valid - */ - constexpr bool is_valid() const { - auto sym = value; - for (int i = 0; i < 7; i++) { - char c = (char)(sym & 0xFF); - if (!('A' <= c && c <= 'Z')) - return false; - sym >>= 8; - if (!(sym & 0xFF)) { - do { - sym >>= 8; - if ((sym & 0xFF)) - return false; - i++; - } while (i < 7); - } - } - return true; - } - - /** - * Returns the character length of the provided symbol - * - * @return length - character length of the provided symbol - */ - constexpr uint32_t length() const { - auto sym = value; - uint32_t len = 0; - while (sym & 0xFF && len <= 7) { - len++; - sym >>= 8; - } - return len; - } - - /** - * Returns the suffix of the %name - */ - constexpr name suffix() const { - uint32_t remaining_bits_after_last_actual_dot = 0; - uint32_t tmp = 0; - for (int32_t remaining_bits = 59; remaining_bits >= 4; - remaining_bits -= 5) { // Note: remaining_bits must remain signed integer - // Get characters one-by-one in name in order from left to right (not including the 13th character) - auto c = (value >> remaining_bits) & 0x1Full; - if (!c) { // if this character is a dot - tmp = static_cast(remaining_bits); - } else { // if this character is not a dot - remaining_bits_after_last_actual_dot = tmp; - } - } - - uint64_t thirteenth_character = value & 0x0Full; - if (thirteenth_character) { // if 13th character is not a dot - remaining_bits_after_last_actual_dot = tmp; - } - - if (remaining_bits_after_last_actual_dot == - 0) // there is no actual dot in the %name other than potentially leading dots - return name{ value }; - - // At this point remaining_bits_after_last_actual_dot has to be within the range of 4 to 59 (and restricted to - // increments of 5). - - // Mask for remaining bits corresponding to characters after last actual dot, except for 4 least significant bits - // (corresponds to 13th character). - uint64_t mask = (1ull << remaining_bits_after_last_actual_dot) - 16; - uint32_t shift = 64 - remaining_bits_after_last_actual_dot; - - return name{ ((value & mask) << shift) + (thirteenth_character << (shift - 1)) }; - } - - /** - * Casts a symbol code to raw - * - * @return Returns an instance of raw based on the value of a symbol_code - */ - constexpr uint64_t raw() const { return value; } - - /** - * Explicit cast to bool of the symbol_code - * - * @return Returns true if the symbol_code is set to the default value of 0 else true. - */ - constexpr explicit operator bool() const { return value != 0; } - - /** - * Returns the name value as a string by calling write_as_string() and returning the buffer produced by - * write_as_string() - */ - std::string to_string() const { return symbol_code_to_string(value); } - - uint64_t value = 0; -}; - -EOSIO_REFLECT(symbol_code, value); -EOSIO_COMPARE(symbol_code); - -template -void to_json(const symbol_code& obj, S& stream) { - to_json(symbol_code_to_string(obj.value), stream); -} - -template -void from_json(symbol_code& obj, S& stream) { - auto s = stream.get_string(); - check(string_to_symbol_code(obj.value, s.data(), s.data() + s.size()), - convert_json_error(eosio::from_json_error::expected_symbol_code)); -} - -/** - * Stores information about a symbol, the symbol can be 7 characters long. - * - * @ingroup symbol - */ -class symbol { - public: - /** - * Construct a new symbol object defaulting to a value of 0 - */ - constexpr symbol() : value(0) {} - - /** - * Construct a new symbol given a scoped enumerated type of raw (uint64_t). - * - * @param raw - The raw value which is a scoped enumerated type of unit64_t - */ - constexpr explicit symbol(uint64_t raw) : value(raw) {} - - /** - * Construct a new symbol given a symbol_code and a uint8_t precision. - * - * @param sc - The symbol_code - * @param precision - The number of decimal places used for the symbol - */ - constexpr symbol(symbol_code sc, uint8_t precision) : value((sc.raw() << 8) | static_cast(precision)) {} - - /** - * Construct a new symbol given a string and a uint8_t precision. - * - * @param ss - The string containing the symbol - * @param precision - The number of decimal places used for the symbol - */ - constexpr symbol(std::string_view ss, uint8_t precision) - : value((symbol_code(ss).raw() << 8) | static_cast(precision)) {} - - /** - * Is this symbol valid - */ - constexpr bool is_valid() const { return code().is_valid(); } - - /** - * This symbol's precision - */ - constexpr uint8_t precision() const { return static_cast(value & 0xFFull); } - - /** - * Returns representation of symbol name - */ - constexpr symbol_code code() const { return symbol_code{ value >> 8 }; } - - /** - * Returns uint64_t repreresentation of the symbol - */ - constexpr uint64_t raw() const { return value; } - - constexpr explicit operator bool() const { return value != 0; } - - std::string to_string() const { return symbol_to_string(value); } - - uint64_t value = 0; -}; - -EOSIO_REFLECT(symbol, value); -EOSIO_COMPARE(symbol); - -template -void to_json(const symbol& obj, S& stream) { - to_json(symbol_to_string(obj.value), stream); -} - -template -void from_json(symbol& obj, S& stream) { - auto s = stream.get_string(); - check(string_to_symbol(obj.value, s.data(), s.data() + s.size()), - convert_json_error(eosio::from_json_error::expected_symbol)); -} - -/** - * Extended asset which stores the information of the owner of the symbol - * - * @ingroup symbol - */ -class extended_symbol { - public: - /** - * Default constructor, construct a new extended_symbol - */ - constexpr extended_symbol() {} - - /** - * Construct a new symbol_code object initialising symbol and contract with the passed in symbol and name - * - * @param sym - The symbol - * @param con - The name of the contract - */ - constexpr extended_symbol(symbol s, name con) : sym(s), contract(con) {} - - /** - * Returns the symbol in the extended_contract - * - * @return symbol - */ - constexpr symbol get_symbol() const { return sym; } - - /** - * Returns the name of the contract in the extended_symbol - * - * @return name - */ - constexpr name get_contract() const { return contract; } - - symbol sym; ///< the symbol - name contract; ///< the token contract hosting the symbol -}; - -EOSIO_REFLECT(extended_symbol, sym, contract); -EOSIO_COMPARE(extended_symbol); -} // namespace eosio diff --git a/include/eosio_OLD/time.hpp b/include/eosio_OLD/time.hpp deleted file mode 100644 index c021595..0000000 --- a/include/eosio_OLD/time.hpp +++ /dev/null @@ -1,264 +0,0 @@ -#pragma once -#include "chain_conversions.hpp" -#include "check.hpp" -#include "operators.hpp" -#include "reflection.hpp" -#include "from_json.hpp" -#include -#include - -namespace eosio { -/** - * @defgroup time - * @ingroup core - * @brief Classes for working with time. - */ - -class microseconds { - public: - microseconds() = default; - - explicit microseconds(int64_t c) : _count(c) {} - - /// @cond INTERNAL - static microseconds maximum() { return microseconds(0x7fffffffffffffffll); } - friend microseconds operator+(const microseconds& l, const microseconds& r) { - return microseconds(l._count + r._count); - } - friend microseconds operator-(const microseconds& l, const microseconds& r) { - return microseconds(l._count - r._count); - } - - microseconds& operator+=(const microseconds& c) { - _count += c._count; - return *this; - } - microseconds& operator-=(const microseconds& c) { - _count -= c._count; - return *this; - } - int64_t count() const { return _count; } - int64_t to_seconds() const { return _count / 1000000; } - - int64_t _count = 0; - /// @endcond -}; - -EOSIO_REFLECT(microseconds, _count); -EOSIO_COMPARE(microseconds); - -inline microseconds seconds(int64_t s) { return microseconds(s * 1000000); } -inline microseconds milliseconds(int64_t s) { return microseconds(s * 1000); } -inline microseconds minutes(int64_t m) { return seconds(60 * m); } -inline microseconds hours(int64_t h) { return minutes(60 * h); } -inline microseconds days(int64_t d) { return hours(24 * d); } - -/** - * High resolution time point in microseconds - * - * @ingroup time - */ -class time_point { - public: - time_point() = default; - explicit time_point(microseconds e) : elapsed(e) {} - const microseconds& time_since_epoch() const { return elapsed; } - uint32_t sec_since_epoch() const { return uint32_t(elapsed.count() / 1000000); } - - static time_point max() { return time_point( microseconds::maximum() ); } - - /// @cond INTERNAL - time_point& operator+=(const microseconds& m) { - elapsed += m; - return *this; - } - time_point& operator-=(const microseconds& m) { - elapsed -= m; - return *this; - } - time_point operator+(const microseconds& m) const { return time_point(elapsed + m); } - time_point operator+(const time_point& m) const { return time_point(elapsed + m.elapsed); } - time_point operator-(const microseconds& m) const { return time_point(elapsed - m); } - microseconds operator-(const time_point& m) const { return microseconds(elapsed.count() - m.elapsed.count()); } - microseconds elapsed; - /// @endcond -}; - -EOSIO_REFLECT(time_point, elapsed); -EOSIO_COMPARE(time_point); - -template -void from_json(time_point& obj, S& stream) { - auto s = stream.get_string(); - uint64_t utc_microseconds; - if (!eosio::string_to_utc_microseconds(utc_microseconds, s.data(), s.data() + s.size())) { - check(false, convert_json_error(eosio::from_json_error::expected_time_point)); - } - obj = time_point(microseconds(utc_microseconds)); -} - -template -void to_json(const time_point& obj, S& stream) { - return to_json(eosio::microseconds_to_str(obj.elapsed._count), stream); -} - -/** - * A lower resolution time_point accurate only to seconds from 1970 - * - * @ingroup time - */ -class time_point_sec { - public: - time_point_sec() : utc_seconds(0) {} - - explicit time_point_sec(uint32_t seconds) : utc_seconds(seconds) {} - - time_point_sec(const time_point& t) : utc_seconds(uint32_t(t.time_since_epoch().count() / 1000000ll)) {} - - static time_point_sec maximum() { return time_point_sec(0xffffffff); } - static time_point_sec min() { return time_point_sec(0); } - - operator time_point() const { return time_point(eosio::seconds(utc_seconds)); } - uint32_t sec_since_epoch() const { return utc_seconds; } - - /// @cond INTERNAL - time_point_sec operator=(const eosio::time_point& t) { - utc_seconds = uint32_t(t.time_since_epoch().count() / 1000000ll); - return *this; - } - time_point_sec& operator+=(uint32_t m) { - utc_seconds += m; - return *this; - } - time_point_sec& operator+=(microseconds m) { - utc_seconds += m.to_seconds(); - return *this; - } - time_point_sec& operator+=(time_point_sec m) { - utc_seconds += m.utc_seconds; - return *this; - } - time_point_sec& operator-=(uint32_t m) { - utc_seconds -= m; - return *this; - } - time_point_sec& operator-=(microseconds m) { - utc_seconds -= m.to_seconds(); - return *this; - } - time_point_sec& operator-=(time_point_sec m) { - utc_seconds -= m.utc_seconds; - return *this; - } - time_point_sec operator+(uint32_t offset) const { return time_point_sec(utc_seconds + offset); } - time_point_sec operator-(uint32_t offset) const { return time_point_sec(utc_seconds - offset); } - - friend time_point operator+(const time_point_sec& t, const microseconds& m) { return time_point(t) + m; } - friend time_point operator-(const time_point_sec& t, const microseconds& m) { return time_point(t) - m; } - friend microseconds operator-(const time_point_sec& t, const time_point_sec& m) { - return time_point(t) - time_point(m); - } - friend microseconds operator-(const time_point& t, const time_point_sec& m) { return time_point(t) - time_point(m); } - uint32_t utc_seconds; - - /// @endcond -}; - -EOSIO_REFLECT(time_point_sec, utc_seconds); -EOSIO_COMPARE(time_point); - -template -void from_json(time_point_sec& obj, S& stream) { - auto s = stream.get_string(); - const char* p = s.data(); - if (!eosio::string_to_utc_seconds(obj.utc_seconds, p, s.data() + s.size(), true, true)) { - check(false, convert_json_error(from_json_error::expected_time_point)); - } -} - -template -void to_json(const time_point_sec& obj, S& stream) { - return to_json(eosio::microseconds_to_str(uint64_t(obj.utc_seconds) * 1'000'000), stream); -} - -/** - * This class is used in the block headers to represent the block time - * It is a parameterised class that takes an Epoch in milliseconds and - * and an interval in milliseconds and computes the number of slots. - * - * @ingroup time - **/ -class block_timestamp { - public: - block_timestamp() = default; - - explicit block_timestamp(uint32_t s) : slot(s) {} - - block_timestamp(const time_point& t) { set_time_point(t); } - - block_timestamp(const time_point_sec& t) { set_time_point(t); } - - static block_timestamp maximum() { return block_timestamp(0xffff); } - static block_timestamp min() { return block_timestamp(0); } - - block_timestamp next() const { - eosio::check(std::numeric_limits::max() - slot >= 1, "block timestamp overflow"); - auto result = block_timestamp(*this); - result.slot += 1; - return result; - } - - time_point to_time_point() const { return (time_point)(*this); } - - operator time_point() const { - int64_t msec = slot * (int64_t)block_interval_ms; - msec += block_timestamp_epoch; - return time_point(milliseconds(msec)); - } - - /// @cond INTERNAL - void operator=(const time_point& t) { set_time_point(t); } - - bool operator>(const block_timestamp& t) const { return slot > t.slot; } - bool operator>=(const block_timestamp& t) const { return slot >= t.slot; } - bool operator<(const block_timestamp& t) const { return slot < t.slot; } - bool operator<=(const block_timestamp& t) const { return slot <= t.slot; } - bool operator==(const block_timestamp& t) const { return slot == t.slot; } - bool operator!=(const block_timestamp& t) const { return slot != t.slot; } - uint32_t slot = 0; - static constexpr int32_t block_interval_ms = 500; - static constexpr int64_t block_timestamp_epoch = 946684800000ll; // epoch is year 2000 - /// @endcond - private: - void set_time_point(const time_point& t) { - int64_t micro_since_epoch = t.time_since_epoch().count(); - int64_t msec_since_epoch = micro_since_epoch / 1000; - slot = uint32_t((msec_since_epoch - block_timestamp_epoch) / int64_t(block_interval_ms)); - } - - void set_time_point(const time_point_sec& t) { - int64_t sec_since_epoch = t.sec_since_epoch(); - slot = uint32_t((sec_since_epoch * 1000 - block_timestamp_epoch) / block_interval_ms); - } -}; // block_timestamp - -/** - * @ingroup time - */ -typedef block_timestamp block_timestamp_type; - -EOSIO_REFLECT(block_timestamp_type, slot); - -template -void from_json(block_timestamp& obj, S& stream) { - time_point tp; - from_json(tp, stream); - obj = block_timestamp(tp); -} - -template -void to_json(const block_timestamp& obj, S& stream) { - return to_json(time_point(obj), stream); -} - -} // namespace eosio diff --git a/include/eosio_OLD/to_bin.hpp b/include/eosio_OLD/to_bin.hpp deleted file mode 100644 index d9c4aa5..0000000 --- a/include/eosio_OLD/to_bin.hpp +++ /dev/null @@ -1,189 +0,0 @@ -#pragma once - -#include -#include "for_each_field.hpp" -#include "stream.hpp" -#include -#include -#include -#include -#include -#include - -namespace eosio { - -template -bool to_bin(std::string_view sv, S& stream, std::string_view&); - -template -bool to_bin(const std::string& s, S& stream, std::string_view&); - -template -bool to_bin(const std::vector& obj, S& stream, std::string_view&); - -template -bool to_bin(const std::optional& obj, S& stream, std::string_view&); - -template -bool to_bin(const std::variant& obj, S& stream, std::string_view&); - -template -bool to_bin(const std::tuple& obj, S& stream, std::string_view&); - -template -bool to_bin(const T& obj, S& stream, std::string_view&); - -template -void varuint32_to_bin(uint64_t val, S& stream) { - check( !(val >> 32), convert_stream_error( stream_error::varuint_too_big) ); - do { - uint8_t b = val & 0x7f; - val >>= 7; - b |= ((val > 0) << 7); - stream.write(b); - } while (val); -} - -inline void push_varuint32(std::vector& bin, uint32_t v) { - vector_stream st{ bin }; - varuint32_to_bin(v, st); -} - -template -void to_bin(std::string_view sv, S& stream) { - varuint32_to_bin(sv.size(), stream); - stream.write(sv.data(), sv.size()); -} - -template -void to_bin(const std::string& s, S& stream) { - to_bin(std::string_view{ s }, stream); -} - -template -void to_bin_range(const T& obj, S& stream) { - varuint32_to_bin(obj.size(), stream); - for (auto& x : obj) { - to_bin(x, stream); - } -} - -template -void to_bin(const T (&obj)[N], S& stream) { - varuint32_to_bin(N, stream); - if constexpr (has_bitwise_serialization()) { - stream.write(reinterpret_cast(&obj), N * sizeof(T)); - } else { - for (auto& x : obj) { - to_bin(x, stream); - } - } -} - -template -void to_bin(const std::vector& obj, S& stream) { - varuint32_to_bin(obj.size(), stream); - if constexpr (has_bitwise_serialization()) { - stream.write(reinterpret_cast(obj.data()), obj.size() * sizeof(T)); - } else { - for (auto& x : obj) { - to_bin(x, stream); - } - } -} - -template -void to_bin(const std::list& obj, S& stream) { - to_bin_range(obj, stream); -} - -template -void to_bin(const std::deque& obj, S& stream) { - to_bin_range(obj, stream); -} - -template -void to_bin(const std::set& obj, S& stream) { - to_bin_range(obj, stream); -} - -template -void to_bin(const std::map& obj, S& stream) { - to_bin_range(obj, stream); -} - -template -void to_bin(const input_stream& obj, S& stream) { - varuint32_to_bin(obj.end - obj.pos, stream); - stream.write(obj.pos, obj.end - obj.pos); -} - -template -void to_bin(const std::pair& obj, S& stream) { - to_bin(obj.first, stream); - return to_bin(obj.second, stream); -} - -template -void to_bin(const std::optional& obj, S& stream) { - to_bin(obj.has_value(), stream); - if (obj) - to_bin(*obj, stream); -} - -template -void to_bin(const std::variant& obj, S& stream) { - varuint32_to_bin(obj.index(), stream); - std::visit([&](auto& x) { return to_bin(x, stream); }, obj); -} - -template -void to_bin_tuple(const T& obj, S& stream) { - if constexpr (i < std::tuple_size_v) { - to_bin(std::get(obj), stream); - to_bin_tuple(obj, stream); - } -} - -template -void to_bin(const std::tuple& obj, S& stream) { - to_bin_tuple<0>(obj, stream); -} - -template -void to_bin(const std::array& obj, S& stream) { - for (const T& elem : obj) { - to_bin(elem, stream); - } -} - -template -void to_bin(const T& obj, S& stream) { - if constexpr (has_bitwise_serialization()) { - stream.write(reinterpret_cast(&obj), sizeof(obj)); - } else { - for_each_field(obj, [&](auto& member) { - to_bin(member, stream); - }); - } -} - -template -void convert_to_bin(const T& t, std::vector& bin) { - size_stream ss; - to_bin(t, ss); - auto orig_size = bin.size(); - bin.resize(orig_size + ss.size); - fixed_buf_stream fbs(bin.data() + orig_size, ss.size); - to_bin(t, fbs); - check( fbs.pos == fbs.end, convert_stream_error(stream_error::underrun) ); -} - -template -std::vector convert_to_bin(const T& t) { - std::vector result; - convert_to_bin(t, result); - return result; -} - -} // namespace eosio diff --git a/include/eosio_OLD/to_json.hpp b/include/eosio_OLD/to_json.hpp deleted file mode 100644 index a45c08c..0000000 --- a/include/eosio_OLD/to_json.hpp +++ /dev/null @@ -1,334 +0,0 @@ -#pragma once - -#include -#include "for_each_field.hpp" -#include "fpconv.h" -#include "stream.hpp" -#include "types.hpp" -#include -#include -#include -#include -#include - -namespace eosio { - -inline constexpr char hex_digits[] = "0123456789ABCDEF"; - -// Adaptors for rapidjson -struct stream_adaptor { - stream_adaptor(const char* src, int sz) { - int chars = std::min(sz, 4); - memcpy(buf, src, chars); - memset(buf + chars, 0, 4 - chars); - } - void Put(char ch) {} - char Take() { return buf[idx++]; } - char buf[4]; - int idx = 0; -}; - -// Replaces any invalid utf-8 bytes with ? -template -void to_json(std::string_view sv, S& stream) { - stream.write('"'); - auto begin = sv.begin(); - auto end = sv.end(); - while (begin != end) { - auto pos = begin; - while (pos != end && *pos != '"' && *pos != '\\' && (unsigned char)(*pos) >= 32 && *pos != 127) ++pos; - while (begin != pos) { - stream_adaptor s2(begin, static_cast(pos - begin)); - if (rapidjson::UTF8<>::Validate(s2, s2)) { - stream.write(begin, s2.idx); - begin += s2.idx; - } else { - ++begin; - stream.write('?'); - } - } - if (begin != end) { - if (*begin == '"') { - stream.write("\\\"", 2); - } else if (*begin == '\\') { - stream.write("\\\\", 2); - } else { - stream.write("\\u00", 4); - stream.write(hex_digits[(unsigned char)(*begin) >> 4]); - stream.write(hex_digits[(unsigned char)(*begin) & 15]); - } - ++begin; - } - } - stream.write('"'); -} - -template -void to_json(const std::string& s, S& stream) { - to_json(std::string_view{ s }, stream); -} - -template -void to_json(const char* s, S& stream) { - to_json(std::string_view{ s }, stream); -} - -/* -template -result to_json(const shared_memory& s, S& stream) { - return to_json(*s, stream); -} -*/ - -template -void to_json(bool value, S& stream) { - if (value) - stream.write("true", 4); - else - stream.write("false", 5); -} - -template -struct make_unsigned : std::make_unsigned {}; - -#ifndef ABIEOS_NO_INT128 -// some standard library does not support std::make_unsigned<__int128> yet. -template <> -struct make_unsigned<__int128> { - using type = unsigned __int128; -}; - -template <> -struct make_unsigned { - using type = unsigned __int128; -}; -#endif - -template -using make_unsigned_t = typename make_unsigned::type; - -template -char* int_to_decimal(T value, char* buffer) { - char* pos = buffer; - auto uvalue = make_unsigned_t(value); - bool neg = value < 0; - if (neg) - uvalue = -uvalue; - - do { - *pos++ = '0' + (uvalue % 10); - uvalue /= 10; - } while (uvalue); - - if (neg) - *pos++ = '-'; - std::reverse(buffer, pos); - return pos; -} - -template -void int_to_json(T value, S& stream) { - // For older versions of libstdc++ (g++ version 9 and below) std::numeric_limits<__int128>::digits10 - // would return 0 when compiling with -std=c++17 flag - const int num_digits = sizeof(T) == 16 ? 38 : std::numeric_limits::digits10; - small_buffer b; - if (sizeof(T) > 4) - *b.pos++ = '"'; - b.pos = int_to_decimal(value, b.pos); - if (sizeof(T) > 4) - *b.pos++ = '"'; - stream.write(b.data, b.pos - b.data); -} - -template -void fp_to_json(double value, S& stream) { - // fpconv is not quite consistent with javascript for nans and infinities - if (value == std::numeric_limits::infinity()) { - stream.write("\"Infinity\"", 10); - } else if (value == -std::numeric_limits::infinity()) { - stream.write("\"-Infinity\"", 11); - } else if (std::isnan(value)) { - stream.write("\"NaN\"", 5); - } else { - small_buffer<24> b; // fpconv_dtoa generates at most 24 characters - int n = fpconv_dtoa(value, b.pos); - check( n > 0, convert_stream_error(stream_error::float_error) ); - b.pos += n; - stream.write(b.data, b.pos - b.data); - } -} - -// clang-format off -template void to_json(unsigned char value, S& stream) { return int_to_json(value, stream); } -template void to_json(uint16_t value, S& stream) { return int_to_json(value, stream); } -template void to_json(uint32_t value, S& stream) { return int_to_json(value, stream); } -template void to_json(uint64_t value, S& stream) { return int_to_json(value, stream); } -template void to_json(char value, S& stream) { return int_to_json(value, stream); } -template void to_json(signed char value, S& stream) { return int_to_json(value, stream); } -template void to_json(int16_t value, S& stream) { return int_to_json(value, stream); } -template void to_json(int32_t value, S& stream) { return int_to_json(value, stream); } -template void to_json(int64_t value, S& stream) { return int_to_json(value, stream); } -template void to_json(double value, S& stream) { return fp_to_json(value, stream); } -template void to_json(float value, S& stream) { return fp_to_json(value, stream); } - -#ifndef ABIEOS_NO_INT128 -template void to_json(unsigned __int128 value, S& stream) { return int_to_json(value, stream); } -template void to_json(__int128 value, S& stream) { return int_to_json(value, stream); } -#endif - -// clang-format on - -template -void to_json(const std::vector& obj, S& stream) { - stream.write('['); - bool first = true; - for (auto& v : obj) { - if (first) { - increase_indent(stream); - } else { - stream.write(','); - } - write_newline(stream); - first = false; - to_json(v, stream); - } - if (!first) { - decrease_indent(stream); - write_newline(stream); - } - stream.write(']'); -} - -template -void to_json(const std::map& obj, S& stream) { - stream.write('{'); - bool first = true; - for (const auto& [k,v] : obj) { - if (first) { - increase_indent(stream); - } else { - stream.write(','); - } - write_newline(stream); - first = false; - to_json(k, stream); - stream.write(':'); - to_json(v, stream); - } - if (!first) { - decrease_indent(stream); - write_newline(stream); - } - stream.write('}'); -} - -template -void to_json(const std::optional& obj, S& stream) { - if (obj) { - to_json(*obj, stream); - } else { - stream.write("null", 4); - } -} - -template -void to_json(const std::variant& obj, S& stream) { - stream.write('['); - increase_indent(stream); - write_newline(stream); - std::visit( - [&](const auto& t) { to_json(get_type_name((std::decay_t*)nullptr), stream); }, obj); - stream.write(','); - write_newline(stream); - std::visit([&](auto& x) { return to_json(x, stream); }, obj); - decrease_indent(stream); - write_newline(stream); - stream.write(']'); -} - - template - struct is_std_optional : std::false_type {}; - - template - struct is_std_optional> : std::true_type { - using value_type = T; - }; - -template -void to_json(const T& t, S& stream) { - bool first = true; - stream.write('{'); - eosio::for_each_field([&](const char* name, auto&& member) { - auto addfield = [&]() { - if (first) { - increase_indent(stream); - first = false; - } else { - stream.write(','); - } - write_newline(stream); - to_json(name, stream); - write_colon(stream); - to_json(member(&t), stream); - }; - - auto m = member(&t); - using member_type = std::decay_t; - if constexpr ( not is_std_optional::value ) { - addfield(); - } else { - // !!! Skipping empty optionals breaks the tests, because - // abi serialization can't handle it. - if( !!m || true ) - addfield(); - } - }); - if (!first) { - decrease_indent(stream); - write_newline(stream); - } - stream.write('}'); -} - -template -void to_json_hex(const char* data, size_t size, S& stream) { - stream.write('"'); - for (size_t i = 0; i < size; ++i) { - unsigned char byte = data[i]; - stream.write(hex_digits[byte >> 4]); - stream.write(hex_digits[byte & 15]); - } - stream.write('"'); -} - -#ifdef __eosio_cdt__ - -template void to_json(long double value, S& stream) { - return to_json_hex(reinterpret_cast(&value), sizeof(long double), stream); -} - -#endif - -template -std::string convert_to_json(const T& t) { - size_stream ss; - to_json(t, ss); - std::string result(ss.size, 0); - fixed_buf_stream fbs(result.data(), result.size()); - to_json(t, fbs); - check( fbs.pos == fbs.end, convert_stream_error(stream_error::underrun) ); - return result; -} - -template -std::string format_json(const T& t) { - pretty_stream ss; - to_json(t, ss); - std::string result(ss.size, 0); - pretty_stream fbs(result.data(), result.size()); - to_json(t, fbs); - check( fbs.pos == fbs.end, convert_stream_error(stream_error::underrun) ); - return result; -} - -} // namespace eosio diff --git a/include/eosio_OLD/to_key.hpp b/include/eosio_OLD/to_key.hpp deleted file mode 100644 index 55c317a..0000000 --- a/include/eosio_OLD/to_key.hpp +++ /dev/null @@ -1,305 +0,0 @@ -#pragma once - -#include -#include "for_each_field.hpp" -#include "stream.hpp" -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -namespace eosio { - -template -void to_key(const std::tuple& obj, S& stream); - -// to_key defines a conversion from a type to a sequence of bytes whose lexicograpical -// ordering is the same as the ordering of the original type. -// -// For any two objects of type T, a and b: -// -// - key(a) < key(b) iff a < b -// - key(a) is not a prefix of key(b) -// -// Overloads of to_key for user-defined types can be found by Koenig lookup. -// -// Abieos provides specializations of to_key for the following types -// - std::string and std::string_view -// - std::vector, std::list, std::deque -// - std::tuple -// - std::array -// - std::optional -// - std::variant -// - Arithmetic types -// - Scoped enumeration types -// - Reflected structs -// - All smart-contract related types defined by abieos -template -void to_key(const T& obj, S& stream); - -template -void to_key_tuple(const T& obj, S& stream) { - if constexpr (i < std::tuple_size_v) { - to_key(std::get(obj), stream); - to_key_tuple(obj, stream); - } -} - -template -void to_key(const std::tuple& obj, S& stream) { - to_key_tuple<0>(obj, stream); -} - -template -void to_key(const std::array& obj, S& stream) { - for (const T& elem : obj) { to_key(elem, stream); } -} - -template -void to_key_optional(const bool* obj, S& stream) { - if (obj == nullptr) - stream.write('\0'); - else if (!*obj) - stream.write('\1'); - else - stream.write('\2'); -} - -template -void to_key_optional(const T* obj, S& stream) { - if constexpr (has_bitwise_serialization() && sizeof(T) == 1) { - if (obj == nullptr) - stream.write("\0", 2); - else { - char buf[1]; - fixed_buf_stream tmp_stream(buf, 1); - to_key(*obj, tmp_stream); - stream.write(buf[0]); - if (buf[0] == '\0') - stream.write('\1'); - } - } else { - if (obj) { - stream.write('\1'); - to_key(*obj, stream); - } else { - stream.write('\0'); - } - } -} - -template -void to_key(const std::pair& obj, S& stream) { - to_key(obj.first, stream); - to_key(obj.second, stream); -} - -template -void to_key_range(const T& obj, S& stream) { - for (const auto& elem : obj) { to_key_optional(&elem, stream); } - to_key_optional((decltype(&*std::begin(obj))) nullptr, stream); -} - -template -void to_key(const std::vector& obj, S& stream) { - for (const T& elem : obj) { to_key_optional(&elem, stream); } - to_key_optional((const T*)nullptr, stream); -} - -template -void to_key(const std::vector& obj, S& stream) { - for (bool elem : obj) { to_key_optional(&elem, stream); } - to_key_optional((const bool*)nullptr, stream); -} - -template -void to_key(const std::list& obj, S& stream) { - to_key_range(obj, stream); -} - -template -void to_key(const std::deque& obj, S& stream) { - to_key_range(obj, stream); -} - -template -void to_key(const std::set& obj, S& stream) { - to_key_range(obj, stream); -} - -template -void to_key(const std::map& obj, S& stream) { - to_key_range(obj, stream); -} - -template -void to_key(const std::optional& obj, S& stream) { - to_key_optional(obj ? &*obj : nullptr, stream); -} - -// The first byte holds: -// 0-4 1's (number of additional bytes) 0 (terminator) bits -// -// The number is represented as big-endian using the low order -// bits of the first byte and all of the remaining bytes. -// -// Notes: -// - values must be encoded using the minimum number of bytes, -// as non-canonical representations will break the sort order. -template -void to_key_varuint32(std::uint32_t obj, S& stream) { - int num_bytes; - if (obj < 0x80u) { - num_bytes = 1; - } else if (obj < 0x4000u) { - num_bytes = 2; - } else if (obj < 0x200000u) { - num_bytes = 3; - } else if (obj < 0x10000000u) { - num_bytes = 4; - } else { - num_bytes = 5; - } - - stream.write( - static_cast(~(0xFFu >> (num_bytes - 1)) | (num_bytes == 5 ? 0 : (obj >> ((num_bytes - 1) * 8))))); - for (int i = num_bytes - 2; i >= 0; --i) { stream.write(static_cast((obj >> i * 8) & 0xFFu)); } -} - -// for non-negative values -// The first byte holds: -// 1 (signbit) 0-4 1's (number of additional bytes) 0 (terminator) bits -// The value is represented as big endian -// for negative values -// The first byte holds: -// 0 (signbit) 0-4 0's (number of additional bytes) 1 (terminator) bits -// The value is adjusted to be positive based on the range that can -// be represented with this number of bytes and then encoded as big endian. -// -// Notes: -// - negative values must sort before positive values -// - For negative value, numbers that need more bytes are smaller, hence -// the encoding of the width must be opposite the encoding used for -// non-negative values. -// - A 5-byte varint can represent values in $[-2^34, 2^34)$. In this case, -// the argument will be sign-extended. -template -void to_key_varint32(std::int32_t obj, S& stream) { - static_assert(std::is_same_v, "to_key for varint32 has been temporarily disabled"); - int num_bytes; - bool sign = (obj < 0); - if (obj < 0x40 && obj >= -0x40) { - num_bytes = 1; - } else if (obj < 0x2000 && obj >= -0x2000) { - num_bytes = 2; - } else if (obj < 0x100000 && obj >= -0x100000) { - num_bytes = 3; - } else if (obj < 0x08000000 && obj >= -0x08000000) { - num_bytes = 4; - } else { - num_bytes = 5; - } - - unsigned char width_field; - if (sign) { - width_field = 0x80u >> num_bytes; - } else { - width_field = 0x80u | ~(0xFFu >> num_bytes); - } - auto uobj = static_cast(obj); - unsigned char value_mask = (0xFFu >> (num_bytes + 1)); - unsigned char high_byte = (num_bytes == 5 ? (sign ? 0xFF : 0) : (uobj >> ((num_bytes - 1) * 8))); - stream.write(width_field | (high_byte & value_mask)); - for (int i = num_bytes - 2; i >= 0; --i) { stream.write(static_cast((uobj >> i * 8) & 0xFFu)); } -} - -template -void to_key(const std::variant& obj, S& stream) { - to_key_varuint32(static_cast(obj.index()), stream); - std::visit([&](const auto& item) { to_key(item, stream); }, obj); -} - -template -void to_key(std::string_view obj, S& stream) { - for (char ch : obj) { - stream.write(ch); - if (ch == '\0') { - stream.write('\1'); - } - } - stream.write("\0", 2); -} - -template -void to_key(const std::string& obj, S& stream) { - to_key(std::string_view(obj), stream); -} - -template -void to_key(bool obj, S& stream) { - stream.write(static_cast(obj ? 1 : 0)); -} - -template -UInt float_to_key(T value) { - static_assert(sizeof(T) == sizeof(UInt), "Expected unsigned int of the same size"); - UInt result; - std::memcpy(&result, &value, sizeof(T)); - UInt signbit = (static_cast(1) << (std::numeric_limits::digits - 1)); - UInt mask = 0; - if (result == signbit) - result = 0; - if (result & signbit) - mask = ~mask; - return result ^ (mask | signbit); -} - -template -void to_key(const T& obj, S& stream) { - if constexpr (std::is_floating_point_v) { - if constexpr (sizeof(T) == 4) { - to_key(float_to_key(obj), stream); - } else { - static_assert(sizeof(T) == 8, "Unknown floating point type"); - to_key(float_to_key(obj), stream); - } - } else if constexpr (std::is_integral_v) { - auto v = static_cast>(obj); - v -= static_cast>(std::numeric_limits::min()); - std::reverse(reinterpret_cast(&v), reinterpret_cast(&v + 1)); - stream.write_raw(v); - } else if constexpr (std::is_enum_v) { - static_assert(!std::is_convertible_v>, "Serializing unscoped enum"); - to_key(static_cast>(obj), stream); - } else { - eosio::for_each_field(obj, [&](const auto& member) { - to_key(member, stream); - }); - } -} - -template -void convert_to_key(const T& t, std::vector& bin) { - size_stream ss; - to_key(t, ss); - auto orig_size = bin.size(); - bin.resize(orig_size + ss.size); - fixed_buf_stream fbs(bin.data() + orig_size, ss.size); - to_key(t, fbs); - check( fbs.pos == fbs.end, convert_stream_error(stream_error::underrun) ); -} - -template -std::vector convert_to_key(const T& t) { - std::vector result; - convert_to_key(t, result); - return result; -} - -} // namespace eosio diff --git a/include/eosio_OLD/types.hpp b/include/eosio_OLD/types.hpp deleted file mode 100644 index f3bb737..0000000 --- a/include/eosio_OLD/types.hpp +++ /dev/null @@ -1,103 +0,0 @@ -#pragma once - -#include -#include -#include -#include -#include -#include - -namespace eosio { - -constexpr const char* get_type_name(bool*) { return "bool"; } -constexpr const char* get_type_name(std::int8_t*) { return "int8"; } -constexpr const char* get_type_name(std::uint8_t*) { return "uint8"; } -constexpr const char* get_type_name(std::int16_t*) { return "int16"; } -constexpr const char* get_type_name(std::uint16_t*) { return "uint16"; } -constexpr const char* get_type_name(std::int32_t*) { return "int32"; } -constexpr const char* get_type_name(std::uint32_t*) { return "uint32"; } -constexpr const char* get_type_name(std::int64_t*) { return "int64"; } -constexpr const char* get_type_name(std::uint64_t*) { return "uint64"; } -constexpr const char* get_type_name(float*) { return "float32"; } -constexpr const char* get_type_name(double*) { return "float64"; } -constexpr const char* get_type_name(std::string*) { return "string"; } - -#ifndef ABIEOS_NO_INT128 -constexpr const char* get_type_name(__int128*) { return "int128"; } -constexpr const char* get_type_name(unsigned __int128*) { return "uint128"; } -#endif - -#ifdef __eosio_cdt__ -constexpr const char* get_type_name(long double*) { return "float128"; } -#endif - -template -constexpr std::array array_cat(std::array lhs, std::array rhs) { - std::array result{}; - for (std::size_t i = 0; i < N; ++i) { result[i] = lhs[i]; } - for (std::size_t i = 0; i < M; ++i) { result[i + N] = rhs[i]; } - return result; -} - -template -constexpr std::array to_array(std::string_view s) { - std::array result{}; - for (std::size_t i = 0; i < N; ++i) { result[i] = s[i]; } - return result; -} - -template -constexpr auto append_type_name(const char (&suffix)[N]) { - constexpr std::string_view name = get_type_name((T*)nullptr); - return array_cat(to_array(name), to_array({ suffix, N })); -} - -template -constexpr auto vector_type_name = append_type_name("[]"); - -template -constexpr auto optional_type_name = append_type_name("?"); - -template -constexpr const char* get_type_name(std::vector*) { - return vector_type_name.data(); -} - -template -constexpr const char* get_type_name(std::optional*) { - return optional_type_name.data(); -} - -struct variant_type_appender { - char* buf; - constexpr variant_type_appender operator+(std::string_view s) { - *buf++ = '_'; - for (auto ch : s) *buf++ = ch; - return *this; - } -}; - -template -constexpr auto get_variant_type_name() { - constexpr std::size_t size = sizeof("variant") + ((std::string_view(get_type_name((T*)nullptr)).size() + 1) + ...); - std::array buffer{ 'v', 'a', 'r', 'i', 'a', 'n', 't' }; - (variant_type_appender{ buffer.data() + 7 } + ... + std::string_view(get_type_name((T*)nullptr))); - buffer[buffer.size() - 1] = '\0'; - return buffer; -} - -template -constexpr auto variant_type_name = get_variant_type_name(); - -} // namespace eosio - -namespace std { -// For all the types defined in ship_protocal.hpp, it relies on the argument-dependent name lookup -// to work; that is, the get_type_name() should be defined in the namespace which is the same namespace of -// the first argument. For variant, it is defined in the namespace; therefore, we need to define get_type_name() -// in the std namespace. -template -constexpr const char* get_type_name(std::variant*) { - return eosio::variant_type_name.data(); -} -} diff --git a/include/eosio_OLD/varint.hpp b/include/eosio_OLD/varint.hpp deleted file mode 100644 index 9ad7e51..0000000 --- a/include/eosio_OLD/varint.hpp +++ /dev/null @@ -1,452 +0,0 @@ -/** - * @file - * @copyright defined in eos/LICENSE - */ -#pragma once - -#include "from_bin.hpp" -#include "from_json.hpp" -#include "to_bin.hpp" -#include "to_json.hpp" - -namespace eosio { -/** - * @defgroup varint Variable Length Integer Type - * @ingroup core - * @ingroup types - * @brief Defines variable length integer type which provides more efficient serialization - */ - -/** - * Variable Length Unsigned Integer. This provides more efficient serialization of 32-bit unsigned int. - * It serialuzes a 32-bit unsigned integer in as few bytes as possible - * `varuint32` is unsigned and uses [VLQ or Base-128 encoding](https://en.wikipedia.org/wiki/Variable-length_quantity) - * - * @ingroup varint - */ -struct unsigned_int { - /** - * Construct a new unsigned int object - * - * @param v - Source - */ - unsigned_int(uint32_t v = 0) : value(v) {} - - /** - * Construct a new unsigned int object from a type that is convertible to uint32_t - * - * @tparam T - Type of the source - * @param v - Source - * @pre T must be convertible to uint32_t - */ - template - unsigned_int(T v) : value(v) {} - - // operator uint32_t()const { return value; } - // operator uint64_t()const { return value; } - - /** - * Convert unsigned_int as T - * - * @tparam T - Target type of conversion - * @return T - Converted target - */ - template - operator T() const { - return static_cast(value); - } - - /// @cond OPERATORS - - /** - * Assign 32-bit unsigned integer - * - * @param v - Soruce - * @return unsigned_int& - Reference to this object - */ - unsigned_int& operator=(uint32_t v) { - value = v; - return *this; - } - - /// @endcond - - /** - * Contained value - */ - uint32_t value; - - /// @cond OPERATORS - - /** - * Check equality between a unsigned_int object and 32-bit unsigned integer - * - * @param i - unsigned_int object to compare - * @param v - 32-bit unsigned integer to compare - * @return true - if equal - * @return false - otherwise - */ - friend bool operator==(const unsigned_int& i, const uint32_t& v) { return i.value == v; } - - /** - * Check equality between 32-bit unsigned integer and a unsigned_int object - * - * @param i - 32-bit unsigned integer to compare - * @param v - unsigned_int object to compare - * @return true - if equal - * @return false - otherwise - */ - friend bool operator==(const uint32_t& i, const unsigned_int& v) { return i == v.value; } - - /** - * Check equality between two unsigned_int objects - * - * @param i - First unsigned_int object to compare - * @param v - Second unsigned_int object to compare - * @return true - if equal - * @return false - otherwise - */ - friend bool operator==(const unsigned_int& i, const unsigned_int& v) { return i.value == v.value; } - - /** - * Check inequality between a unsigned_int object and 32-bit unsigned integer - * - * @param i - unsigned_int object to compare - * @param v - 32-bit unsigned integer to compare - * @return true - if inequal - * @return false - otherwise - */ - friend bool operator!=(const unsigned_int& i, const uint32_t& v) { return i.value != v; } - - /** - * Check inequality between 32-bit unsigned integer and a unsigned_int object - * - * @param i - 32-bit unsigned integer to compare - * @param v - unsigned_int object to compare - * @return true - if unequal - * @return false - otherwise - */ - friend bool operator!=(const uint32_t& i, const unsigned_int& v) { return i != v.value; } - - /** - * Check inequality between two unsigned_int objects - * - * @param i - First unsigned_int object to compare - * @param v - Second unsigned_int object to compare - * @return true - if inequal - * @return false - otherwise - */ - friend bool operator!=(const unsigned_int& i, const unsigned_int& v) { return i.value != v.value; } - - /** - * Check if the given unsigned_int object is less than the given 32-bit unsigned integer - * - * @param i - unsigned_int object to compare - * @param v - 32-bit unsigned integer to compare - * @return true - if i less than v - * @return false - otherwise - */ - friend bool operator<(const unsigned_int& i, const uint32_t& v) { return i.value < v; } - - /** - * Check if the given 32-bit unsigned integer is less than the given unsigned_int object - * - * @param i - 32-bit unsigned integer to compare - * @param v - unsigned_int object to compare - * @return true - if i less than v - * @return false - otherwise - */ - friend bool operator<(const uint32_t& i, const unsigned_int& v) { return i < v.value; } - - /** - * Check if the first given unsigned_int is less than the second given unsigned_int object - * - * @param i - First unsigned_int object to compare - * @param v - Second unsigned_int object to compare - * @return true - if i less than v - * @return false - otherwise - */ - friend bool operator<(const unsigned_int& i, const unsigned_int& v) { return i.value < v.value; } - - /** - * Check if the given unsigned_int object is greater or equal to the given 32-bit unsigned integer - * - * @param i - unsigned_int object to compare - * @param v - 32-bit unsigned integer to compare - * @return true - if i is greater or equal to v - * @return false - otherwise - */ - friend bool operator>=(const unsigned_int& i, const uint32_t& v) { return i.value >= v; } - - /** - * Check if the given 32-bit unsigned integer is greater or equal to the given unsigned_int object - * - * @param i - 32-bit unsigned integer to compare - * @param v - unsigned_int object to compare - * @return true - if i is greater or equal to v - * @return false - otherwise - */ - friend bool operator>=(const uint32_t& i, const unsigned_int& v) { return i >= v.value; } - - /** - * Check if the first given unsigned_int is greater or equal to the second given unsigned_int object - * - * @param i - First unsigned_int object to compare - * @param v - Second unsigned_int object to compare - * @return true - if i is greater or equal to v - * @return false - otherwise - */ - friend bool operator>=(const unsigned_int& i, const unsigned_int& v) { return i.value >= v.value; } - - /// @endcond -}; - -using varuint32 = unsigned_int; -EOSIO_REFLECT(varuint32, value); - -template -void convert(const varuint32& src, uint32_t& dst, F&& chooser) { - dst = src.value; -} - -template -void from_bin(varuint32& obj, S& stream) { - return varuint32_from_bin(obj.value, stream); -} - -template -void to_bin(const varuint32& obj, S& stream) { - return varuint32_to_bin(obj.value, stream); -} - -template -void from_json(varuint32& obj, S& stream) { - return from_json(obj.value, stream); -} - -template -void to_json(const varuint32& obj, S& stream) { - return to_json(obj.value, stream); -} - -template -void to_key(const varuint32& obj, S& stream) { - return to_key_varuint32(obj.value, stream); -} - -/** - * Variable Length Signed Integer. This provides more efficient serialization of 32-bit signed int. - * It serializes a 32-bit signed integer in as few bytes as possible. - * - * @ingroup varint - * @note `varint32' is signed and uses [Zig-Zag - * encoding](https://developers.google.com/protocol-buffers/docs/encoding#signed-integers) - */ -struct signed_int { - /** - * Construct a new signed int object - * - * @param v - Source - */ - signed_int(int32_t v = 0) : value(v) {} - - /// @cond OPERATORS - - /** - * Convert signed_int to primitive 32-bit signed integer - * - * @return int32_t - The converted result - */ - operator int32_t() const { return value; } - - /** - * Assign an object that is convertible to int32_t - * - * @tparam T - Type of the assignment object - * @param v - Source - * @return unsigned_int& - Reference to this object - */ - template - signed_int& operator=(const T& v) { - value = v; - return *this; - } - - /** - * Increment operator - * - * @return signed_int - New signed_int with value incremented from the current object's value - */ - signed_int operator++(int) { return value++; } - - /** - * Increment operator - * - * @return signed_int - Reference to current object - */ - signed_int& operator++() { - ++value; - return *this; - } - - /// @endcond - - /** - * Contained value - */ - int32_t value; - - /// @cond OPERATORS - - /** - * Check equality between a signed_int object and 32-bit integer - * - * @param i - signed_int object to compare - * @param v - 32-bit integer to compare - * @return true - if equal - * @return false - otherwise - */ - friend bool operator==(const signed_int& i, const int32_t& v) { return i.value == v; } - - /** - * Check equality between 32-bit integer and a signed_int object - * - * @param i - 32-bit integer to compare - * @param v - signed_int object to compare - * @return true - if equal - * @return false - otherwise - */ - friend bool operator==(const int32_t& i, const signed_int& v) { return i == v.value; } - - /** - * Check equality between two signed_int objects - * - * @param i - First signed_int object to compare - * @param v - Second signed_int object to compare - * @return true - if equal - * @return false - otherwise - */ - friend bool operator==(const signed_int& i, const signed_int& v) { return i.value == v.value; } - - /** - * Check inequality between a signed_int object and 32-bit integer - * - * @param i - signed_int object to compare - * @param v - 32-bit integer to compare - * @return true - if inequal - * @return false - otherwise - */ - friend bool operator!=(const signed_int& i, const int32_t& v) { return i.value != v; } - - /** - * Check inequality between 32-bit integer and a signed_int object - * - * @param i - 32-bit integer to compare - * @param v - signed_int object to compare - * @return true - if unequal - * @return false - otherwise - */ - friend bool operator!=(const int32_t& i, const signed_int& v) { return i != v.value; } - - /** - * Check inequality between two signed_int objects - * - * @param i - First signed_int object to compare - * @param v - Second signed_int object to compare - * @return true - if inequal - * @return false - otherwise - */ - friend bool operator!=(const signed_int& i, const signed_int& v) { return i.value != v.value; } - - /** - * Check if the given signed_int object is less than the given 32-bit integer - * - * @param i - signed_int object to compare - * @param v - 32-bit integer to compare - * @return true - if i less than v - * @return false - otherwise - */ - friend bool operator<(const signed_int& i, const int32_t& v) { return i.value < v; } - - /** - * Check if the given 32-bit integer is less than the given signed_int object - * - * @param i - 32-bit integer to compare - * @param v - signed_int object to compare - * @return true - if i less than v - * @return false - otherwise - */ - friend bool operator<(const int32_t& i, const signed_int& v) { return i < v.value; } - - /** - * Check if the first given signed_int is less than the second given signed_int object - * - * @param i - First signed_int object to compare - * @param v - Second signed_int object to compare - * @return true - if i less than v - * @return false - otherwise - */ - friend bool operator<(const signed_int& i, const signed_int& v) { return i.value < v.value; } - - /** - * Check if the given signed_int object is greater or equal to the given 32-bit integer - * - * @param i - signed_int object to compare - * @param v - 32-bit integer to compare - * @return true - if i is greater or equal to v - * @return false - otherwise - */ - friend bool operator>=(const signed_int& i, const int32_t& v) { return i.value >= v; } - - /** - * Check if the given 32-bit integer is greater or equal to the given signed_int object - * - * @param i - 32-bit integer to compare - * @param v - signed_int object to compare - * @return true - if i is greater or equal to v - * @return false - otherwise - */ - friend bool operator>=(const int32_t& i, const signed_int& v) { return i >= v.value; } - - /** - * Check if the first given signed_int is greater or equal to the second given signed_int object - * - * @param i - First signed_int object to compare - * @param v - Second signed_int object to compare - * @return true - if i is greater or equal to v - * @return false - otherwise - */ - friend bool operator>=(const signed_int& i, const signed_int& v) { return i.value >= v.value; } - - /// @endcond -}; - -using varint32 = signed_int; -EOSIO_REFLECT(varint32, value); - -template -void from_bin(varint32& obj, S& stream) { - return varint32_from_bin(obj.value, stream); -} - -template -void to_bin(const varint32& obj, S& stream) { - return varuint32_to_bin((uint32_t(obj.value) << 1) ^ uint32_t(obj.value >> 31), stream); -} - -template -void from_json(varint32& obj, S& stream) { - return from_json(obj.value, stream); -} - -template -void to_json(const varint32& obj, S& stream) { - return to_json(obj.value, stream); -} - -template -void to_key(const varint32& obj, S& stream) { - return to_key_varint32(obj.value, stream); -} - -} // namespace eosio diff --git a/include/outcome-basic.hpp b/include/outcome-basic.hpp deleted file mode 100644 index 411394c..0000000 --- a/include/outcome-basic.hpp +++ /dev/null @@ -1,6836 +0,0 @@ -/* A less simple result type -(C) 2017-2019 Niall Douglas (20 commits) -File Created: June 2017 - - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License in the accompanying file -Licence.txt or at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. - - -Distributed under the Boost Software License, Version 1.0. - (See accompanying file Licence.txt or copy at - http://www.boost.org/LICENSE_1_0.txt) -*/ - -#ifndef OUTCOME_BASIC_OUTCOME_HPP -#define OUTCOME_BASIC_OUTCOME_HPP -/* Configure Outcome with QuickCppLib -(C) 2015-2019 Niall Douglas (24 commits) -File Created: August 2015 - - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License in the accompanying file -Licence.txt or at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. - - -Distributed under the Boost Software License, Version 1.0. - (See accompanying file Licence.txt or copy at - http://www.boost.org/LICENSE_1_0.txt) -*/ - -#ifndef OUTCOME_V2_CONFIG_HPP -#define OUTCOME_V2_CONFIG_HPP -/* Sets Outcome version -(C) 2017-2019 Niall Douglas (4 commits) - - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License in the accompanying file -Licence.txt or at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. - - -Distributed under the Boost Software License, Version 1.0. - (See accompanying file Licence.txt or copy at - http://www.boost.org/LICENSE_1_0.txt) -*/ - -/*! AWAITING HUGO JSON CONVERSION TOOL */ -#define OUTCOME_VERSION_MAJOR 2 -/*! AWAITING HUGO JSON CONVERSION TOOL */ -#define OUTCOME_VERSION_MINOR 2 -/*! AWAITING HUGO JSON CONVERSION TOOL */ -#define OUTCOME_VERSION_PATCH 0 -/*! AWAITING HUGO JSON CONVERSION TOOL */ -#define OUTCOME_VERSION_REVISION 0 // Revision version for cmake and DLL version stamping - -/*! AWAITING HUGO JSON CONVERSION TOOL */ -#ifndef OUTCOME_DISABLE_ABI_PERMUTATION -#define OUTCOME_UNSTABLE_VERSION -#endif -// Pull in detection of __MINGW64_VERSION_MAJOR -#if defined(__MINGW32__) && !0 -#include <_mingw.h> -#endif -/* Configure QuickCppLib -(C) 2016-2017 Niall Douglas (8 commits) - - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License in the accompanying file -Licence.txt or at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. - - -Distributed under the Boost Software License, Version 1.0. - (See accompanying file Licence.txt or copy at - http://www.boost.org/LICENSE_1_0.txt) -*/ - -#ifndef QUICKCPPLIB_CONFIG_HPP -#define QUICKCPPLIB_CONFIG_HPP -/* Provides SG-10 feature checking for all C++ compilers -(C) 2014-2017 Niall Douglas (13 commits) -File Created: Nov 2014 - - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License in the accompanying file -Licence.txt or at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. - - -Distributed under the Boost Software License, Version 1.0. - (See accompanying file Licence.txt or copy at - http://www.boost.org/LICENSE_1_0.txt) -*/ - -#ifndef QUICKCPPLIB_HAS_FEATURE_H -#define QUICKCPPLIB_HAS_FEATURE_H - -#if __cplusplus >= 201103 - -// Some of these macros ended up getting removed by ISO standards, -// they are prefixed with //// -////#if !defined(__cpp_alignas) -////#define __cpp_alignas 190000 -////#endif -////#if !defined(__cpp_default_function_template_args) -////#define __cpp_default_function_template_args 190000 -////#endif -////#if !defined(__cpp_defaulted_functions) -////#define __cpp_defaulted_functions 190000 -////#endif -////#if !defined(__cpp_deleted_functions) -////#define __cpp_deleted_functions 190000 -////#endif -////#if !defined(__cpp_generalized_initializers) -////#define __cpp_generalized_initializers 190000 -////#endif -////#if !defined(__cpp_implicit_moves) -////#define __cpp_implicit_moves 190000 -////#endif -////#if !defined(__cpp_inline_namespaces) -////#define __cpp_inline_namespaces 190000 -////#endif -////#if !defined(__cpp_local_type_template_args) -////#define __cpp_local_type_template_args 190000 -////#endif -////#if !defined(__cpp_noexcept) -////#define __cpp_noexcept 190000 -////#endif -////#if !defined(__cpp_nonstatic_member_init) -////#define __cpp_nonstatic_member_init 190000 -////#endif -////#if !defined(__cpp_nullptr) -////#define __cpp_nullptr 190000 -////#endif -////#if !defined(__cpp_override_control) -////#define __cpp_override_control 190000 -////#endif -////#if !defined(__cpp_thread_local) -////#define __cpp_thread_local 190000 -////#endif -////#if !defined(__cpp_auto_type) -////#define __cpp_auto_type 190000 -////#endif -////#if !defined(__cpp_strong_enums) -////#define __cpp_strong_enums 190000 -////#endif -////#if !defined(__cpp_trailing_return) -////#define __cpp_trailing_return 190000 -////#endif -////#if !defined(__cpp_unrestricted_unions) -////#define __cpp_unrestricted_unions 190000 -////#endif - -#if !defined(__cpp_alias_templates) -#define __cpp_alias_templates 190000 -#endif - -#if !defined(__cpp_attributes) -#define __cpp_attributes 190000 -#endif - -#if !defined(__cpp_constexpr) -#if __cplusplus >= 201402 -#define __cpp_constexpr 201304 // relaxed constexpr -#else -#define __cpp_constexpr 190000 -#endif -#endif - -#if !defined(__cpp_decltype) -#define __cpp_decltype 190000 -#endif - -#if !defined(__cpp_delegating_constructors) -#define __cpp_delegating_constructors 190000 -#endif - -#if !defined(__cpp_explicit_conversion) //// renamed from __cpp_explicit_conversions -#define __cpp_explicit_conversion 190000 -#endif - -#if !defined(__cpp_inheriting_constructors) -#define __cpp_inheriting_constructors 190000 -#endif - -#if !defined(__cpp_initializer_lists) //// NEW -#define __cpp_initializer_lists 190000 -#endif - -#if !defined(__cpp_lambdas) -#define __cpp_lambdas 190000 -#endif - -#if !defined(__cpp_nsdmi) -#define __cpp_nsdmi 190000 //// NEW -#endif - -#if !defined(__cpp_range_based_for) //// renamed from __cpp_range_for -#define __cpp_range_based_for 190000 -#endif - -#if !defined(__cpp_raw_strings) -#define __cpp_raw_strings 190000 -#endif - -#if !defined(__cpp_ref_qualifiers) //// renamed from __cpp_reference_qualified_functions -#define __cpp_ref_qualifiers 190000 -#endif - -#if !defined(__cpp_rvalue_references) -#define __cpp_rvalue_references 190000 -#endif - -#if !defined(__cpp_static_assert) -#define __cpp_static_assert 190000 -#endif - -#if !defined(__cpp_unicode_characters) //// NEW -#define __cpp_unicode_characters 190000 -#endif - -#if !defined(__cpp_unicode_literals) -#define __cpp_unicode_literals 190000 -#endif - -#if !defined(__cpp_user_defined_literals) -#define __cpp_user_defined_literals 190000 -#endif - -#if !defined(__cpp_variadic_templates) -#define __cpp_variadic_templates 190000 -#endif - -#endif - -#if __cplusplus >= 201402 - -// Some of these macros ended up getting removed by ISO standards, -// they are prefixed with //// -////#if !defined(__cpp_contextual_conversions) -////#define __cpp_contextual_conversions 190000 -////#endif -////#if !defined(__cpp_digit_separators) -////#define __cpp_digit_separators 190000 -////#endif -////#if !defined(__cpp_relaxed_constexpr) -////#define __cpp_relaxed_constexpr 190000 -////#endif -////#if !defined(__cpp_runtime_arrays) -////# define __cpp_runtime_arrays 190000 -////#endif - - -#if !defined(__cpp_aggregate_nsdmi) -#define __cpp_aggregate_nsdmi 190000 -#endif - -#if !defined(__cpp_binary_literals) -#define __cpp_binary_literals 190000 -#endif - -#if !defined(__cpp_decltype_auto) -#define __cpp_decltype_auto 190000 -#endif - -#if !defined(__cpp_generic_lambdas) -#define __cpp_generic_lambdas 190000 -#endif - -#if !defined(__cpp_init_captures) -#define __cpp_init_captures 190000 -#endif - -#if !defined(__cpp_return_type_deduction) -#define __cpp_return_type_deduction 190000 -#endif - -#if !defined(__cpp_sized_deallocation) -#define __cpp_sized_deallocation 190000 -#endif - -#if !defined(__cpp_variable_templates) -#define __cpp_variable_templates 190000 -#endif - -#endif - - -// VS2010: _MSC_VER=1600 -// VS2012: _MSC_VER=1700 -// VS2013: _MSC_VER=1800 -// VS2015: _MSC_VER=1900 -// VS2017: _MSC_VER=1910 -#if defined(_MSC_VER) && !defined(__clang__) - -#if !defined(__cpp_exceptions) && defined(_CPPUNWIND) -#define __cpp_exceptions 190000 -#endif - -#if !defined(__cpp_rtti) && defined(_CPPRTTI) -#define __cpp_rtti 190000 -#endif - - -// C++ 11 - -#if !defined(__cpp_alias_templates) && _MSC_VER >= 1800 -#define __cpp_alias_templates 190000 -#endif - -#if !defined(__cpp_attributes) -#define __cpp_attributes 190000 -#endif - -#if !defined(__cpp_constexpr) && _MSC_FULL_VER >= 190023506 /* VS2015 */ -#define __cpp_constexpr 190000 -#endif - -#if !defined(__cpp_decltype) && _MSC_VER >= 1600 -#define __cpp_decltype 190000 -#endif - -#if !defined(__cpp_delegating_constructors) && _MSC_VER >= 1800 -#define __cpp_delegating_constructors 190000 -#endif - -#if !defined(__cpp_explicit_conversion) && _MSC_VER >= 1800 -#define __cpp_explicit_conversion 190000 -#endif - -#if !defined(__cpp_inheriting_constructors) && _MSC_VER >= 1900 -#define __cpp_inheriting_constructors 190000 -#endif - -#if !defined(__cpp_initializer_lists) && _MSC_VER >= 1900 -#define __cpp_initializer_lists 190000 -#endif - -#if !defined(__cpp_lambdas) && _MSC_VER >= 1600 -#define __cpp_lambdas 190000 -#endif - -#if !defined(__cpp_nsdmi) && _MSC_VER >= 1900 -#define __cpp_nsdmi 190000 -#endif - -#if !defined(__cpp_range_based_for) && _MSC_VER >= 1700 -#define __cpp_range_based_for 190000 -#endif - -#if !defined(__cpp_raw_strings) && _MSC_VER >= 1800 -#define __cpp_raw_strings 190000 -#endif - -#if !defined(__cpp_ref_qualifiers) && _MSC_VER >= 1900 -#define __cpp_ref_qualifiers 190000 -#endif - -#if !defined(__cpp_rvalue_references) && _MSC_VER >= 1600 -#define __cpp_rvalue_references 190000 -#endif - -#if !defined(__cpp_static_assert) && _MSC_VER >= 1600 -#define __cpp_static_assert 190000 -#endif - -//#if !defined(__cpp_unicode_literals) -//# define __cpp_unicode_literals 190000 -//#endif - -#if !defined(__cpp_user_defined_literals) && _MSC_VER >= 1900 -#define __cpp_user_defined_literals 190000 -#endif - -#if !defined(__cpp_variadic_templates) && _MSC_VER >= 1800 -#define __cpp_variadic_templates 190000 -#endif - - -// C++ 14 - -//#if !defined(__cpp_aggregate_nsdmi) -//#define __cpp_aggregate_nsdmi 190000 -//#endif - -#if !defined(__cpp_binary_literals) && _MSC_VER >= 1900 -#define __cpp_binary_literals 190000 -#endif - -#if !defined(__cpp_decltype_auto) && _MSC_VER >= 1900 -#define __cpp_decltype_auto 190000 -#endif - -#if !defined(__cpp_generic_lambdas) && _MSC_VER >= 1900 -#define __cpp_generic_lambdas 190000 -#endif - -#if !defined(__cpp_init_captures) && _MSC_VER >= 1900 -#define __cpp_init_captures 190000 -#endif - -#if !defined(__cpp_return_type_deduction) && _MSC_VER >= 1900 -#define __cpp_return_type_deduction 190000 -#endif - -#if !defined(__cpp_sized_deallocation) && _MSC_VER >= 1900 -#define __cpp_sized_deallocation 190000 -#endif - -#if !defined(__cpp_variable_templates) && _MSC_FULL_VER >= 190023506 -#define __cpp_variable_templates 190000 -#endif - -#endif // _MSC_VER - - -// Much to my surprise, GCC's support of these is actually incomplete, so fill in the gaps -#if (defined(__GNUC__) && !defined(__clang__)) - -#define QUICKCPPLIB_GCC (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__) - -#if !defined(__cpp_exceptions) && defined(__EXCEPTIONS) -#define __cpp_exceptions 190000 -#endif - -#if !defined(__cpp_rtti) && defined(__GXX_RTTI) -#define __cpp_rtti 190000 -#endif - - -// C++ 11 -#if defined(__GXX_EXPERIMENTAL_CXX0X__) - -#if !defined(__cpp_alias_templates) && (QUICKCPPLIB_GCC >= 40700) -#define __cpp_alias_templates 190000 -#endif - -#if !defined(__cpp_attributes) && (QUICKCPPLIB_GCC >= 40800) -#define __cpp_attributes 190000 -#endif - -#if !defined(__cpp_constexpr) && (QUICKCPPLIB_GCC >= 40600) -#define __cpp_constexpr 190000 -#endif - -#if !defined(__cpp_decltype) && (QUICKCPPLIB_GCC >= 40300) -#define __cpp_decltype 190000 -#endif - -#if !defined(__cpp_delegating_constructors) && (QUICKCPPLIB_GCC >= 40700) -#define __cpp_delegating_constructors 190000 -#endif - -#if !defined(__cpp_explicit_conversion) && (QUICKCPPLIB_GCC >= 40500) -#define __cpp_explicit_conversion 190000 -#endif - -#if !defined(__cpp_inheriting_constructors) && (QUICKCPPLIB_GCC >= 40800) -#define __cpp_inheriting_constructors 190000 -#endif - -#if !defined(__cpp_initializer_lists) && (QUICKCPPLIB_GCC >= 40800) -#define __cpp_initializer_lists 190000 -#endif - -#if !defined(__cpp_lambdas) && (QUICKCPPLIB_GCC >= 40500) -#define __cpp_lambdas 190000 -#endif - -#if !defined(__cpp_nsdmi) && (QUICKCPPLIB_GCC >= 40700) -#define __cpp_nsdmi 190000 -#endif - -#if !defined(__cpp_range_based_for) && (QUICKCPPLIB_GCC >= 40600) -#define __cpp_range_based_for 190000 -#endif - -#if !defined(__cpp_raw_strings) && (QUICKCPPLIB_GCC >= 40500) -#define __cpp_raw_strings 190000 -#endif - -#if !defined(__cpp_ref_qualifiers) && (QUICKCPPLIB_GCC >= 40801) -#define __cpp_ref_qualifiers 190000 -#endif - -// __cpp_rvalue_reference deviation -#if !defined(__cpp_rvalue_references) && defined(__cpp_rvalue_reference) -#define __cpp_rvalue_references __cpp_rvalue_reference -#endif - -#if !defined(__cpp_static_assert) && (QUICKCPPLIB_GCC >= 40300) -#define __cpp_static_assert 190000 -#endif - -#if !defined(__cpp_unicode_characters) && (QUICKCPPLIB_GCC >= 40500) -#define __cpp_unicode_characters 190000 -#endif - -#if !defined(__cpp_unicode_literals) && (QUICKCPPLIB_GCC >= 40500) -#define __cpp_unicode_literals 190000 -#endif - -#if !defined(__cpp_user_defined_literals) && (QUICKCPPLIB_GCC >= 40700) -#define __cpp_user_defined_literals 190000 -#endif - -#if !defined(__cpp_variadic_templates) && (QUICKCPPLIB_GCC >= 40400) -#define __cpp_variadic_templates 190000 -#endif - - -// C++ 14 -// Every C++ 14 supporting GCC does the right thing here - -#endif // __GXX_EXPERIMENTAL_CXX0X__ - -#endif // GCC - - -// clang deviates in some places from the present SG-10 draft, plus older -// clangs are quite incomplete -#if defined(__clang__) - -#define QUICKCPPLIB_CLANG (__clang_major__ * 10000 + __clang_minor__ * 100 + __clang_patchlevel__) - -#if !defined(__cpp_exceptions) && (defined(__EXCEPTIONS) || defined(_CPPUNWIND)) -#define __cpp_exceptions 190000 -#endif - -#if !defined(__cpp_rtti) && (defined(__GXX_RTTI) || defined(_CPPRTTI)) -#define __cpp_rtti 190000 -#endif - - -// C++ 11 -#if defined(__GXX_EXPERIMENTAL_CXX0X__) - -#if !defined(__cpp_alias_templates) && (QUICKCPPLIB_CLANG >= 30000) -#define __cpp_alias_templates 190000 -#endif - -#if !defined(__cpp_attributes) && (QUICKCPPLIB_CLANG >= 30300) -#define __cpp_attributes 190000 -#endif - -#if !defined(__cpp_constexpr) && (QUICKCPPLIB_CLANG >= 30100) -#define __cpp_constexpr 190000 -#endif - -#if !defined(__cpp_decltype) && (QUICKCPPLIB_CLANG >= 20900) -#define __cpp_decltype 190000 -#endif - -#if !defined(__cpp_delegating_constructors) && (QUICKCPPLIB_CLANG >= 30000) -#define __cpp_delegating_constructors 190000 -#endif - -#if !defined(__cpp_explicit_conversion) && (QUICKCPPLIB_CLANG >= 30000) -#define __cpp_explicit_conversion 190000 -#endif - -#if !defined(__cpp_inheriting_constructors) && (QUICKCPPLIB_CLANG >= 30300) -#define __cpp_inheriting_constructors 190000 -#endif - -#if !defined(__cpp_initializer_lists) && (QUICKCPPLIB_CLANG >= 30100) -#define __cpp_initializer_lists 190000 -#endif - -#if !defined(__cpp_lambdas) && (QUICKCPPLIB_CLANG >= 30100) -#define __cpp_lambdas 190000 -#endif - -#if !defined(__cpp_nsdmi) && (QUICKCPPLIB_CLANG >= 30000) -#define __cpp_nsdmi 190000 -#endif - -#if !defined(__cpp_range_based_for) && (QUICKCPPLIB_CLANG >= 30000) -#define __cpp_range_based_for 190000 -#endif - -// __cpp_raw_string_literals deviation -#if !defined(__cpp_raw_strings) && defined(__cpp_raw_string_literals) -#define __cpp_raw_strings __cpp_raw_string_literals -#endif -#if !defined(__cpp_raw_strings) && (QUICKCPPLIB_CLANG >= 30000) -#define __cpp_raw_strings 190000 -#endif - -#if !defined(__cpp_ref_qualifiers) && (QUICKCPPLIB_CLANG >= 20900) -#define __cpp_ref_qualifiers 190000 -#endif - -// __cpp_rvalue_reference deviation -#if !defined(__cpp_rvalue_references) && defined(__cpp_rvalue_reference) -#define __cpp_rvalue_references __cpp_rvalue_reference -#endif -#if !defined(__cpp_rvalue_references) && (QUICKCPPLIB_CLANG >= 20900) -#define __cpp_rvalue_references 190000 -#endif - -#if !defined(__cpp_static_assert) && (QUICKCPPLIB_CLANG >= 20900) -#define __cpp_static_assert 190000 -#endif - -#if !defined(__cpp_unicode_characters) && (QUICKCPPLIB_CLANG >= 30000) -#define __cpp_unicode_characters 190000 -#endif - -#if !defined(__cpp_unicode_literals) && (QUICKCPPLIB_CLANG >= 30000) -#define __cpp_unicode_literals 190000 -#endif - -// __cpp_user_literals deviation -#if !defined(__cpp_user_defined_literals) && defined(__cpp_user_literals) -#define __cpp_user_defined_literals __cpp_user_literals -#endif -#if !defined(__cpp_user_defined_literals) && (QUICKCPPLIB_CLANG >= 30100) -#define __cpp_user_defined_literals 190000 -#endif - -#if !defined(__cpp_variadic_templates) && (QUICKCPPLIB_CLANG >= 20900) -#define __cpp_variadic_templates 190000 -#endif - - -// C++ 14 -// Every C++ 14 supporting clang does the right thing here - -#endif // __GXX_EXPERIMENTAL_CXX0X__ - -#endif // clang - -#endif -#ifndef QUICKCPPLIB_DISABLE_ABI_PERMUTATION -// Note the second line of this file must ALWAYS be the git SHA, third line ALWAYS the git SHA update time -#define QUICKCPPLIB_PREVIOUS_COMMIT_REF 8a81b159cae78d83b151f756c1fd08a972b44cc4 -#define QUICKCPPLIB_PREVIOUS_COMMIT_DATE "2020-03-16 18:12:07 +00:00" -#define QUICKCPPLIB_PREVIOUS_COMMIT_UNIQUE 8a81b159 -#endif - -#define QUICKCPPLIB_VERSION_GLUE2(a, b) a##b -#define QUICKCPPLIB_VERSION_GLUE(a, b) QUICKCPPLIB_VERSION_GLUE2(a, b) - -// clang-format off - - - - - - - - - - - - -#if defined(QUICKCPPLIB_DISABLE_ABI_PERMUTATION) -#define QUICKCPPLIB_NAMESPACE quickcpplib -#define QUICKCPPLIB_NAMESPACE_BEGIN namespace quickcpplib { -#define QUICKCPPLIB_NAMESPACE_END } -#else -#define QUICKCPPLIB_NAMESPACE quickcpplib::QUICKCPPLIB_VERSION_GLUE(_, QUICKCPPLIB_PREVIOUS_COMMIT_UNIQUE) -#define QUICKCPPLIB_NAMESPACE_BEGIN namespace quickcpplib { namespace QUICKCPPLIB_VERSION_GLUE(_, QUICKCPPLIB_PREVIOUS_COMMIT_UNIQUE) { -#define QUICKCPPLIB_NAMESPACE_END } } -#endif -// clang-format on - -#ifdef _MSC_VER -#define QUICKCPPLIB_BIND_MESSAGE_PRAGMA2(x) __pragma(message(x)) -#define QUICKCPPLIB_BIND_MESSAGE_PRAGMA(x) QUICKCPPLIB_BIND_MESSAGE_PRAGMA2(x) -#define QUICKCPPLIB_BIND_MESSAGE_PREFIX(type) __FILE__ "(" QUICKCPPLIB_BIND_STRINGIZE2(__LINE__) "): " type ": " -#define QUICKCPPLIB_BIND_MESSAGE_(type, prefix, msg) QUICKCPPLIB_BIND_MESSAGE_PRAGMA(prefix msg) -#else -#define QUICKCPPLIB_BIND_MESSAGE_PRAGMA2(x) _Pragma(#x) -#define QUICKCPPLIB_BIND_MESSAGE_PRAGMA(type, x) QUICKCPPLIB_BIND_MESSAGE_PRAGMA2(type x) -#define QUICKCPPLIB_BIND_MESSAGE_(type, prefix, msg) QUICKCPPLIB_BIND_MESSAGE_PRAGMA(type, msg) -#endif -//! Have the compiler output a message -#define QUICKCPPLIB_MESSAGE(msg) QUICKCPPLIB_BIND_MESSAGE_(message, QUICKCPPLIB_BIND_MESSAGE_PREFIX("message"), msg) -//! Have the compiler output a note -#define QUICKCPPLIB_NOTE(msg) QUICKCPPLIB_BIND_MESSAGE_(message, QUICKCPPLIB_BIND_MESSAGE_PREFIX("note"), msg) -//! Have the compiler output a warning -#define QUICKCPPLIB_WARNING(msg) QUICKCPPLIB_BIND_MESSAGE_(GCC warning, QUICKCPPLIB_BIND_MESSAGE_PREFIX("warning"), msg) -//! Have the compiler output an error -#define QUICKCPPLIB_ERROR(msg) QUICKCPPLIB_BIND_MESSAGE_(GCC error, QUICKCPPLIB_BIND_MESSAGE_PREFIX("error"), msg) - - - - - - - - - - - - - - - - -#define QUICKCPPLIB_ANNOTATE_RWLOCK_CREATE(p) -#define QUICKCPPLIB_ANNOTATE_RWLOCK_DESTROY(p) -#define QUICKCPPLIB_ANNOTATE_RWLOCK_ACQUIRED(p, s) -#define QUICKCPPLIB_ANNOTATE_RWLOCK_RELEASED(p, s) -#define QUICKCPPLIB_ANNOTATE_IGNORE_READS_BEGIN() -#define QUICKCPPLIB_ANNOTATE_IGNORE_READS_END() -#define QUICKCPPLIB_ANNOTATE_IGNORE_WRITES_BEGIN() -#define QUICKCPPLIB_ANNOTATE_IGNORE_WRITES_END() -#define QUICKCPPLIB_DRD_IGNORE_VAR(x) -#define QUICKCPPLIB_DRD_STOP_IGNORING_VAR(x) -#define QUICKCPPLIB_RUNNING_ON_VALGRIND (0) - - -#ifndef QUICKCPPLIB_IN_THREAD_SANITIZER -#if defined(__has_feature) -#if __has_feature(thread_sanitizer) -#define QUICKCPPLIB_IN_THREAD_SANITIZER 1 -#endif -#elif defined(__SANITIZE_ADDRESS__) -#define QUICKCPPLIB_IN_THREAD_SANITIZER 1 -#endif -#endif -#ifndef QUICKCPPLIB_IN_THREAD_SANITIZER -#define QUICKCPPLIB_IN_THREAD_SANITIZER 0 -#endif - -#if QUICKCPPLIB_IN_THREAD_SANITIZER -#define QUICKCPPLIB_DISABLE_THREAD_SANITIZE __attribute__((no_sanitize_thread)) -#else -#define QUICKCPPLIB_DISABLE_THREAD_SANITIZE -#endif - -#ifndef QUICKCPPLIB_SMT_PAUSE -#if !defined(__clang__) && defined(_MSC_VER) && _MSC_VER >= 1310 && (defined(_M_IX86) || defined(_M_X64)) -extern "C" void _mm_pause(); -#pragma intrinsic(_mm_pause) -#define QUICKCPPLIB_SMT_PAUSE _mm_pause(); -#elif !defined(__c2__) && defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__)) -#define QUICKCPPLIB_SMT_PAUSE __asm__ __volatile__("rep; nop" : : : "memory"); -#endif -#endif - -#ifndef QUICKCPPLIB_FORCEINLINE -#if defined(_MSC_VER) -#define QUICKCPPLIB_FORCEINLINE __forceinline -#elif defined(__GNUC__) -#define QUICKCPPLIB_FORCEINLINE __attribute__((always_inline)) -#else -#define QUICKCPPLIB_FORCEINLINE -#endif -#endif - -#ifndef QUICKCPPLIB_NOINLINE -#if defined(_MSC_VER) -#define QUICKCPPLIB_NOINLINE __declspec(noinline) -#elif defined(__GNUC__) -#define QUICKCPPLIB_NOINLINE __attribute__((noinline)) -#else -#define QUICKCPPLIB_NOINLINE -#endif -#endif - -#ifdef __has_cpp_attribute -#define QUICKCPPLIB_HAS_CPP_ATTRIBUTE(attr) __has_cpp_attribute(attr) -#else -#define QUICKCPPLIB_HAS_CPP_ATTRIBUTE(attr) (0) -#endif - -#if !defined(QUICKCPPLIB_NORETURN) -#if QUICKCPPLIB_HAS_CPP_ATTRIBUTE(noreturn) -#define QUICKCPPLIB_NORETURN [[noreturn]] -#elif defined(_MSC_VER) -#define QUICKCPPLIB_NORETURN __declspec(noreturn) -#elif defined(__GNUC__) -#define QUICKCPPLIB_NORETURN __attribute__((__noreturn__)) -#else -#define QUICKCPPLIB_NORETURN -#endif -#endif - -#ifndef QUICKCPPLIB_NODISCARD -#if 0 || (_HAS_CXX17 && _MSC_VER >= 1911 /* VS2017.3 */) -#define QUICKCPPLIB_NODISCARD [[nodiscard]] -#endif -#endif -#ifndef QUICKCPPLIB_NODISCARD -#if QUICKCPPLIB_HAS_CPP_ATTRIBUTE(nodiscard) -#define QUICKCPPLIB_NODISCARD [[nodiscard]] -#elif defined(__clang__) // deliberately not GCC -#define QUICKCPPLIB_NODISCARD __attribute__((warn_unused_result)) -#elif defined(_MSC_VER) -// _Must_inspect_result_ expands into this -#define QUICKCPPLIB_NODISCARD __declspec("SAL_name" "(" "\"_Must_inspect_result_\"" "," "\"\"" "," "\"2\"" ")") __declspec("SAL_begin") __declspec("SAL_post") __declspec("SAL_mustInspect") __declspec("SAL_post") __declspec("SAL_checkReturn") __declspec("SAL_end") - - - - - - - - -#endif -#endif -#ifndef QUICKCPPLIB_NODISCARD -#define QUICKCPPLIB_NODISCARD -#endif - -#ifndef QUICKCPPLIB_SYMBOL_VISIBLE -#if defined(_MSC_VER) -#define QUICKCPPLIB_SYMBOL_VISIBLE -#elif defined(__GNUC__) -#define QUICKCPPLIB_SYMBOL_VISIBLE __attribute__((visibility("default"))) -#else -#define QUICKCPPLIB_SYMBOL_VISIBLE -#endif -#endif - -#ifndef QUICKCPPLIB_SYMBOL_EXPORT -#if defined(_MSC_VER) -#define QUICKCPPLIB_SYMBOL_EXPORT __declspec(dllexport) -#elif defined(__GNUC__) -#define QUICKCPPLIB_SYMBOL_EXPORT __attribute__((visibility("default"))) -#else -#define QUICKCPPLIB_SYMBOL_EXPORT -#endif -#endif - -#ifndef QUICKCPPLIB_SYMBOL_IMPORT -#if defined(_MSC_VER) -#define QUICKCPPLIB_SYMBOL_IMPORT __declspec(dllimport) -#elif defined(__GNUC__) -#define QUICKCPPLIB_SYMBOL_IMPORT -#else -#define QUICKCPPLIB_SYMBOL_IMPORT -#endif -#endif - -#ifndef QUICKCPPLIB_THREAD_LOCAL -#if _MSC_VER >= 1800 -#define QUICKCPPLIB_THREAD_LOCAL_IS_CXX11 1 -#elif __cplusplus >= 201103 -#if __GNUC__ >= 5 && !defined(__clang__) -#define QUICKCPPLIB_THREAD_LOCAL_IS_CXX11 1 -#elif defined(__has_feature) -#if __has_feature(cxx_thread_local) -#define QUICKCPPLIB_THREAD_LOCAL_IS_CXX11 1 -#endif -#endif -#endif -#ifdef QUICKCPPLIB_THREAD_LOCAL_IS_CXX11 -#define QUICKCPPLIB_THREAD_LOCAL thread_local -#endif -#ifndef QUICKCPPLIB_THREAD_LOCAL -#if defined(_MSC_VER) -#define QUICKCPPLIB_THREAD_LOCAL __declspec(thread) -#elif defined(__GNUC__) -#define QUICKCPPLIB_THREAD_LOCAL __thread -#else -#error Unknown compiler, cannot set QUICKCPPLIB_THREAD_LOCAL -#endif -#endif -#endif -/* MSVC capable preprocessor macro overloading -(C) 2014-2017 Niall Douglas (3 commits) -File Created: Aug 2014 - - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License in the accompanying file -Licence.txt or at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. - - -Distributed under the Boost Software License, Version 1.0. - (See accompanying file Licence.txt or copy at - http://www.boost.org/LICENSE_1_0.txt) -*/ - -#ifndef QUICKCPPLIB_PREPROCESSOR_MACRO_OVERLOAD_H -#define QUICKCPPLIB_PREPROCESSOR_MACRO_OVERLOAD_H - -#define QUICKCPPLIB_GLUE(x, y) x y - -#define QUICKCPPLIB_RETURN_ARG_COUNT(_1_, _2_, _3_, _4_, _5_, _6_, _7_, _8_, count, ...) count -#define QUICKCPPLIB_EXPAND_ARGS(args) QUICKCPPLIB_RETURN_ARG_COUNT args -#define QUICKCPPLIB_COUNT_ARGS_MAX8(...) QUICKCPPLIB_EXPAND_ARGS((__VA_ARGS__, 8, 7, 6, 5, 4, 3, 2, 1, 0)) - -#define QUICKCPPLIB_OVERLOAD_MACRO2(name, count) name##count -#define QUICKCPPLIB_OVERLOAD_MACRO1(name, count) QUICKCPPLIB_OVERLOAD_MACRO2(name, count) -#define QUICKCPPLIB_OVERLOAD_MACRO(name, count) QUICKCPPLIB_OVERLOAD_MACRO1(name, count) - -#define QUICKCPPLIB_CALL_OVERLOAD(name, ...) QUICKCPPLIB_GLUE(QUICKCPPLIB_OVERLOAD_MACRO(name, QUICKCPPLIB_COUNT_ARGS_MAX8(__VA_ARGS__)), (__VA_ARGS__)) - -#define QUICKCPPLIB_GLUE_(x, y) x y - -#define QUICKCPPLIB_RETURN_ARG_COUNT_(_1_, _2_, _3_, _4_, _5_, _6_, _7_, _8_, count, ...) count -#define QUICKCPPLIB_EXPAND_ARGS_(args) QUICKCPPLIB_RETURN_ARG_COUNT_ args -#define QUICKCPPLIB_COUNT_ARGS_MAX8_(...) QUICKCPPLIB_EXPAND_ARGS_((__VA_ARGS__, 8, 7, 6, 5, 4, 3, 2, 1, 0)) - -#define QUICKCPPLIB_OVERLOAD_MACRO2_(name, count) name##count -#define QUICKCPPLIB_OVERLOAD_MACRO1_(name, count) QUICKCPPLIB_OVERLOAD_MACRO2_(name, count) -#define QUICKCPPLIB_OVERLOAD_MACRO_(name, count) QUICKCPPLIB_OVERLOAD_MACRO1_(name, count) - -#define QUICKCPPLIB_CALL_OVERLOAD_(name, ...) QUICKCPPLIB_GLUE_(QUICKCPPLIB_OVERLOAD_MACRO_(name, QUICKCPPLIB_COUNT_ARGS_MAX8_(__VA_ARGS__)), (__VA_ARGS__)) - -#endif -#if defined(__cpp_concepts) && !defined(QUICKCPPLIB_DISABLE_CONCEPTS_SUPPORT) -#define QUICKCPPLIB_TREQUIRES_EXPAND8(a, b, c, d, e, f, g, h) a &&QUICKCPPLIB_TREQUIRES_EXPAND7(b, c, d, e, f, g, h) -#define QUICKCPPLIB_TREQUIRES_EXPAND7(a, b, c, d, e, f, g) a &&QUICKCPPLIB_TREQUIRES_EXPAND6(b, c, d, e, f, g) -#define QUICKCPPLIB_TREQUIRES_EXPAND6(a, b, c, d, e, f) a &&QUICKCPPLIB_TREQUIRES_EXPAND5(b, c, d, e, f) -#define QUICKCPPLIB_TREQUIRES_EXPAND5(a, b, c, d, e) a &&QUICKCPPLIB_TREQUIRES_EXPAND4(b, c, d, e) -#define QUICKCPPLIB_TREQUIRES_EXPAND4(a, b, c, d) a &&QUICKCPPLIB_TREQUIRES_EXPAND3(b, c, d) -#define QUICKCPPLIB_TREQUIRES_EXPAND3(a, b, c) a &&QUICKCPPLIB_TREQUIRES_EXPAND2(b, c) -#define QUICKCPPLIB_TREQUIRES_EXPAND2(a, b) a &&QUICKCPPLIB_TREQUIRES_EXPAND1(b) -#define QUICKCPPLIB_TREQUIRES_EXPAND1(a) a - -//! Expands into a && b && c && ... -#define QUICKCPPLIB_TREQUIRES(...) requires QUICKCPPLIB_CALL_OVERLOAD(QUICKCPPLIB_TREQUIRES_EXPAND, __VA_ARGS__) - -#define QUICKCPPLIB_TEMPLATE(...) template <__VA_ARGS__> -#define QUICKCPPLIB_TEXPR(...) requires { (__VA_ARGS__); } - -#define QUICKCPPLIB_TPRED(...) (__VA_ARGS__) -#if !defined(_MSC_VER) || _MSC_FULL_VER >= 192400000 // VS 2019 16.3 is broken here -#define QUICKCPPLIB_REQUIRES(...) requires(__VA_ARGS__) -#else -#define QUICKCPPLIB_REQUIRES(...) -#endif -#else -#define QUICKCPPLIB_TEMPLATE(...) template <__VA_ARGS__ -#define QUICKCPPLIB_TREQUIRES(...) , __VA_ARGS__ > -#define QUICKCPPLIB_TEXPR(...) typename = decltype(__VA_ARGS__) -#ifdef _MSC_VER -// MSVC gives an error if every specialisation of a template is always ill-formed, so -// the more powerful SFINAE form below causes pukeage :( -#define QUICKCPPLIB_TPRED(...) typename = typename std::enable_if<(__VA_ARGS__)>::type -#else -#define QUICKCPPLIB_TPRED(...) typename std::enable_if<(__VA_ARGS__), bool>::type = true -#endif -#define QUICKCPPLIB_REQUIRES(...) -#endif - - -#endif -#ifndef __cpp_variadic_templates -#error Outcome needs variadic template support in the compiler -#endif -#if __cpp_constexpr < 201304 && _MSC_FULL_VER < 191100000 -#error Outcome needs constexpr (C++ 14) support in the compiler -#endif -#ifndef __cpp_variable_templates -#error Outcome needs variable template support in the compiler -#endif -#if !defined(__clang__) && defined(__GNUC__) && __GNUC__ < 6 -#error Due to a bug in nested template variables parsing, Outcome does not work on GCCs earlier than v6. -#endif - - - - - - - - - - - - - - -#ifndef OUTCOME_SYMBOL_VISIBLE -#define OUTCOME_SYMBOL_VISIBLE QUICKCPPLIB_SYMBOL_VISIBLE -#endif -#ifndef OUTCOME_FORCEINLINE -#define OUTCOME_FORCEINLINE QUICKCPPLIB_FORCEINLINE -#endif -#ifndef OUTCOME_NODISCARD -#define OUTCOME_NODISCARD QUICKCPPLIB_NODISCARD -#endif -#ifndef OUTCOME_THREAD_LOCAL -#define OUTCOME_THREAD_LOCAL QUICKCPPLIB_THREAD_LOCAL -#endif -#ifndef OUTCOME_TEMPLATE -#define OUTCOME_TEMPLATE(...) QUICKCPPLIB_TEMPLATE(__VA_ARGS__) -#endif -#ifndef OUTCOME_TREQUIRES -#define OUTCOME_TREQUIRES(...) QUICKCPPLIB_TREQUIRES(__VA_ARGS__) -#endif -#ifndef OUTCOME_TEXPR -#define OUTCOME_TEXPR(...) QUICKCPPLIB_TEXPR(__VA_ARGS__) -#endif -#ifndef OUTCOME_TPRED -#define OUTCOME_TPRED(...) QUICKCPPLIB_TPRED(__VA_ARGS__) -#endif -#ifndef OUTCOME_REQUIRES -#define OUTCOME_REQUIRES(...) QUICKCPPLIB_REQUIRES(__VA_ARGS__) -#endif -/* Convenience macros for importing local namespace binds -(C) 2014-2017 Niall Douglas (9 commits) -File Created: Aug 2014 - - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License in the accompanying file -Licence.txt or at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. - - -Distributed under the Boost Software License, Version 1.0. - (See accompanying file Licence.txt or copy at - http://www.boost.org/LICENSE_1_0.txt) -*/ - -#ifndef QUICKCPPLIB_BIND_IMPORT_HPP -#define QUICKCPPLIB_BIND_IMPORT_HPP - -/* 2014-10-9 ned: I lost today figuring out the below. I really hate the C preprocessor now. - * - * Anyway, infinity = 8. It's easy to expand below if needed. - */ - - -#define QUICKCPPLIB_BIND_STRINGIZE(a) #a -#define QUICKCPPLIB_BIND_STRINGIZE2(a) QUICKCPPLIB_BIND_STRINGIZE(a) -#define QUICKCPPLIB_BIND_NAMESPACE_VERSION8(a, b, c, d, e, f, g, h) a##_##b##_##c##_##d##_##e##_##f##_##g##_##h -#define QUICKCPPLIB_BIND_NAMESPACE_VERSION7(a, b, c, d, e, f, g) a##_##b##_##c##_##d##_##e##_##f##_##g -#define QUICKCPPLIB_BIND_NAMESPACE_VERSION6(a, b, c, d, e, f) a##_##b##_##c##_##d##_##e##_##f -#define QUICKCPPLIB_BIND_NAMESPACE_VERSION5(a, b, c, d, e) a##_##b##_##c##_##d##_##e -#define QUICKCPPLIB_BIND_NAMESPACE_VERSION4(a, b, c, d) a##_##b##_##c##_##d -#define QUICKCPPLIB_BIND_NAMESPACE_VERSION3(a, b, c) a##_##b##_##c -#define QUICKCPPLIB_BIND_NAMESPACE_VERSION2(a, b) a##_##b -#define QUICKCPPLIB_BIND_NAMESPACE_VERSION1(a) a -//! Concatenates each parameter with _ -#define QUICKCPPLIB_BIND_NAMESPACE_VERSION(...) QUICKCPPLIB_CALL_OVERLOAD(QUICKCPPLIB_BIND_NAMESPACE_VERSION, __VA_ARGS__) - -#define QUICKCPPLIB_BIND_NAMESPACE_SELECT_2(name, modifier) name -#define QUICKCPPLIB_BIND_NAMESPACE_SELECT2(name, modifier) ::name -#define QUICKCPPLIB_BIND_NAMESPACE_SELECT_1(name) name -#define QUICKCPPLIB_BIND_NAMESPACE_SELECT1(name) ::name -#define QUICKCPPLIB_BIND_NAMESPACE_SELECT_(...) QUICKCPPLIB_CALL_OVERLOAD_(QUICKCPPLIB_BIND_NAMESPACE_SELECT_, __VA_ARGS__) -#define QUICKCPPLIB_BIND_NAMESPACE_SELECT(...) QUICKCPPLIB_CALL_OVERLOAD_(QUICKCPPLIB_BIND_NAMESPACE_SELECT, __VA_ARGS__) -#define QUICKCPPLIB_BIND_NAMESPACE_EXPAND8(a, b, c, d, e, f, g, h) QUICKCPPLIB_BIND_NAMESPACE_SELECT_ a QUICKCPPLIB_BIND_NAMESPACE_SELECT b QUICKCPPLIB_BIND_NAMESPACE_SELECT c QUICKCPPLIB_BIND_NAMESPACE_SELECT d QUICKCPPLIB_BIND_NAMESPACE_SELECT e QUICKCPPLIB_BIND_NAMESPACE_SELECT f QUICKCPPLIB_BIND_NAMESPACE_SELECT g QUICKCPPLIB_BIND_NAMESPACE_SELECT h - -#define QUICKCPPLIB_BIND_NAMESPACE_EXPAND7(a, b, c, d, e, f, g) QUICKCPPLIB_BIND_NAMESPACE_SELECT_ a QUICKCPPLIB_BIND_NAMESPACE_SELECT b QUICKCPPLIB_BIND_NAMESPACE_SELECT c QUICKCPPLIB_BIND_NAMESPACE_SELECT d QUICKCPPLIB_BIND_NAMESPACE_SELECT e QUICKCPPLIB_BIND_NAMESPACE_SELECT f QUICKCPPLIB_BIND_NAMESPACE_SELECT g -#define QUICKCPPLIB_BIND_NAMESPACE_EXPAND6(a, b, c, d, e, f) QUICKCPPLIB_BIND_NAMESPACE_SELECT_ a QUICKCPPLIB_BIND_NAMESPACE_SELECT b QUICKCPPLIB_BIND_NAMESPACE_SELECT c QUICKCPPLIB_BIND_NAMESPACE_SELECT d QUICKCPPLIB_BIND_NAMESPACE_SELECT e QUICKCPPLIB_BIND_NAMESPACE_SELECT f -#define QUICKCPPLIB_BIND_NAMESPACE_EXPAND5(a, b, c, d, e) QUICKCPPLIB_BIND_NAMESPACE_SELECT_ a QUICKCPPLIB_BIND_NAMESPACE_SELECT b QUICKCPPLIB_BIND_NAMESPACE_SELECT c QUICKCPPLIB_BIND_NAMESPACE_SELECT d QUICKCPPLIB_BIND_NAMESPACE_SELECT e -#define QUICKCPPLIB_BIND_NAMESPACE_EXPAND4(a, b, c, d) QUICKCPPLIB_BIND_NAMESPACE_SELECT_ a QUICKCPPLIB_BIND_NAMESPACE_SELECT b QUICKCPPLIB_BIND_NAMESPACE_SELECT c QUICKCPPLIB_BIND_NAMESPACE_SELECT d -#define QUICKCPPLIB_BIND_NAMESPACE_EXPAND3(a, b, c) QUICKCPPLIB_BIND_NAMESPACE_SELECT_ a QUICKCPPLIB_BIND_NAMESPACE_SELECT b QUICKCPPLIB_BIND_NAMESPACE_SELECT c -#define QUICKCPPLIB_BIND_NAMESPACE_EXPAND2(a, b) QUICKCPPLIB_BIND_NAMESPACE_SELECT_ a QUICKCPPLIB_BIND_NAMESPACE_SELECT b -#define QUICKCPPLIB_BIND_NAMESPACE_EXPAND1(a) QUICKCPPLIB_BIND_NAMESPACE_SELECT_ a -//! Expands into a::b::c:: ... -#define QUICKCPPLIB_BIND_NAMESPACE(...) QUICKCPPLIB_CALL_OVERLOAD(QUICKCPPLIB_BIND_NAMESPACE_EXPAND, __VA_ARGS__) - -#define QUICKCPPLIB_BIND_NAMESPACE_BEGIN_NAMESPACE_SELECT2(name, modifier) modifier namespace name { - - -#define QUICKCPPLIB_BIND_NAMESPACE_BEGIN_NAMESPACE_SELECT1(name) namespace name { - - -#define QUICKCPPLIB_BIND_NAMESPACE_BEGIN_NAMESPACE_SELECT(...) QUICKCPPLIB_CALL_OVERLOAD_(QUICKCPPLIB_BIND_NAMESPACE_BEGIN_NAMESPACE_SELECT, __VA_ARGS__) -#define QUICKCPPLIB_BIND_NAMESPACE_BEGIN_EXPAND8(a, b, c, d, e, f, g, h) QUICKCPPLIB_BIND_NAMESPACE_BEGIN_NAMESPACE_SELECT a QUICKCPPLIB_BIND_NAMESPACE_BEGIN_EXPAND7(b, c, d, e, f, g, h) -#define QUICKCPPLIB_BIND_NAMESPACE_BEGIN_EXPAND7(a, b, c, d, e, f, g) QUICKCPPLIB_BIND_NAMESPACE_BEGIN_NAMESPACE_SELECT a QUICKCPPLIB_BIND_NAMESPACE_BEGIN_EXPAND6(b, c, d, e, f, g) -#define QUICKCPPLIB_BIND_NAMESPACE_BEGIN_EXPAND6(a, b, c, d, e, f) QUICKCPPLIB_BIND_NAMESPACE_BEGIN_NAMESPACE_SELECT a QUICKCPPLIB_BIND_NAMESPACE_BEGIN_EXPAND5(b, c, d, e, f) -#define QUICKCPPLIB_BIND_NAMESPACE_BEGIN_EXPAND5(a, b, c, d, e) QUICKCPPLIB_BIND_NAMESPACE_BEGIN_NAMESPACE_SELECT a QUICKCPPLIB_BIND_NAMESPACE_BEGIN_EXPAND4(b, c, d, e) -#define QUICKCPPLIB_BIND_NAMESPACE_BEGIN_EXPAND4(a, b, c, d) QUICKCPPLIB_BIND_NAMESPACE_BEGIN_NAMESPACE_SELECT a QUICKCPPLIB_BIND_NAMESPACE_BEGIN_EXPAND3(b, c, d) -#define QUICKCPPLIB_BIND_NAMESPACE_BEGIN_EXPAND3(a, b, c) QUICKCPPLIB_BIND_NAMESPACE_BEGIN_NAMESPACE_SELECT a QUICKCPPLIB_BIND_NAMESPACE_BEGIN_EXPAND2(b, c) -#define QUICKCPPLIB_BIND_NAMESPACE_BEGIN_EXPAND2(a, b) QUICKCPPLIB_BIND_NAMESPACE_BEGIN_NAMESPACE_SELECT a QUICKCPPLIB_BIND_NAMESPACE_BEGIN_EXPAND1(b) -#define QUICKCPPLIB_BIND_NAMESPACE_BEGIN_EXPAND1(a) QUICKCPPLIB_BIND_NAMESPACE_BEGIN_NAMESPACE_SELECT a - -//! Expands into namespace a { namespace b { namespace c ... -#define QUICKCPPLIB_BIND_NAMESPACE_BEGIN(...) QUICKCPPLIB_CALL_OVERLOAD(QUICKCPPLIB_BIND_NAMESPACE_BEGIN_EXPAND, __VA_ARGS__) - -#define QUICKCPPLIB_BIND_NAMESPACE_EXPORT_BEGIN_NAMESPACE_SELECT2(name, modifier) modifier namespace name { - - -#define QUICKCPPLIB_BIND_NAMESPACE_EXPORT_BEGIN_NAMESPACE_SELECT1(name) export namespace name { - - -#define QUICKCPPLIB_BIND_NAMESPACE_EXPORT_BEGIN_NAMESPACE_SELECT(...) QUICKCPPLIB_CALL_OVERLOAD_(QUICKCPPLIB_BIND_NAMESPACE_EXPORT_BEGIN_NAMESPACE_SELECT, __VA_ARGS__) -#define QUICKCPPLIB_BIND_NAMESPACE_EXPORT_BEGIN_EXPAND8(a, b, c, d, e, f, g, h) QUICKCPPLIB_BIND_NAMESPACE_EXPORT_BEGIN_NAMESPACE_SELECT a QUICKCPPLIB_BIND_NAMESPACE_EXPORT_BEGIN_EXPAND7(b, c, d, e, f, g, h) -#define QUICKCPPLIB_BIND_NAMESPACE_EXPORT_BEGIN_EXPAND7(a, b, c, d, e, f, g) QUICKCPPLIB_BIND_NAMESPACE_EXPORT_BEGIN_NAMESPACE_SELECT a QUICKCPPLIB_BIND_NAMESPACE_EXPORT_BEGIN_EXPAND6(b, c, d, e, f, g) -#define QUICKCPPLIB_BIND_NAMESPACE_EXPORT_BEGIN_EXPAND6(a, b, c, d, e, f) QUICKCPPLIB_BIND_NAMESPACE_EXPORT_BEGIN_NAMESPACE_SELECT a QUICKCPPLIB_BIND_NAMESPACE_EXPORT_BEGIN_EXPAND5(b, c, d, e, f) -#define QUICKCPPLIB_BIND_NAMESPACE_EXPORT_BEGIN_EXPAND5(a, b, c, d, e) QUICKCPPLIB_BIND_NAMESPACE_EXPORT_BEGIN_NAMESPACE_SELECT a QUICKCPPLIB_BIND_NAMESPACE_EXPORT_BEGIN_EXPAND4(b, c, d, e) -#define QUICKCPPLIB_BIND_NAMESPACE_EXPORT_BEGIN_EXPAND4(a, b, c, d) QUICKCPPLIB_BIND_NAMESPACE_EXPORT_BEGIN_NAMESPACE_SELECT a QUICKCPPLIB_BIND_NAMESPACE_EXPORT_BEGIN_EXPAND3(b, c, d) -#define QUICKCPPLIB_BIND_NAMESPACE_EXPORT_BEGIN_EXPAND3(a, b, c) QUICKCPPLIB_BIND_NAMESPACE_EXPORT_BEGIN_NAMESPACE_SELECT a QUICKCPPLIB_BIND_NAMESPACE_EXPORT_BEGIN_EXPAND2(b, c) -#define QUICKCPPLIB_BIND_NAMESPACE_EXPORT_BEGIN_EXPAND2(a, b) QUICKCPPLIB_BIND_NAMESPACE_EXPORT_BEGIN_NAMESPACE_SELECT a QUICKCPPLIB_BIND_NAMESPACE_EXPORT_BEGIN_EXPAND1(b) -#define QUICKCPPLIB_BIND_NAMESPACE_EXPORT_BEGIN_EXPAND1(a) QUICKCPPLIB_BIND_NAMESPACE_EXPORT_BEGIN_NAMESPACE_SELECT a - -//! Expands into export namespace a { namespace b { namespace c ... -#define QUICKCPPLIB_BIND_NAMESPACE_EXPORT_BEGIN(...) QUICKCPPLIB_CALL_OVERLOAD(QUICKCPPLIB_BIND_NAMESPACE_EXPORT_BEGIN_EXPAND, __VA_ARGS__) - -#define QUICKCPPLIB_BIND_NAMESPACE_END_NAMESPACE_SELECT2(name, modifier) } -#define QUICKCPPLIB_BIND_NAMESPACE_END_NAMESPACE_SELECT1(name) } -#define QUICKCPPLIB_BIND_NAMESPACE_END_NAMESPACE_SELECT(...) QUICKCPPLIB_CALL_OVERLOAD_(QUICKCPPLIB_BIND_NAMESPACE_END_NAMESPACE_SELECT, __VA_ARGS__) -#define QUICKCPPLIB_BIND_NAMESPACE_END_EXPAND8(a, b, c, d, e, f, g, h) QUICKCPPLIB_BIND_NAMESPACE_END_NAMESPACE_SELECT a QUICKCPPLIB_BIND_NAMESPACE_END_EXPAND7(b, c, d, e, f, g, h) -#define QUICKCPPLIB_BIND_NAMESPACE_END_EXPAND7(a, b, c, d, e, f, g) QUICKCPPLIB_BIND_NAMESPACE_END_NAMESPACE_SELECT a QUICKCPPLIB_BIND_NAMESPACE_END_EXPAND6(b, c, d, e, f, g) -#define QUICKCPPLIB_BIND_NAMESPACE_END_EXPAND6(a, b, c, d, e, f) QUICKCPPLIB_BIND_NAMESPACE_END_NAMESPACE_SELECT a QUICKCPPLIB_BIND_NAMESPACE_END_EXPAND5(b, c, d, e, f) -#define QUICKCPPLIB_BIND_NAMESPACE_END_EXPAND5(a, b, c, d, e) QUICKCPPLIB_BIND_NAMESPACE_END_NAMESPACE_SELECT a QUICKCPPLIB_BIND_NAMESPACE_END_EXPAND4(b, c, d, e) -#define QUICKCPPLIB_BIND_NAMESPACE_END_EXPAND4(a, b, c, d) QUICKCPPLIB_BIND_NAMESPACE_END_NAMESPACE_SELECT a QUICKCPPLIB_BIND_NAMESPACE_END_EXPAND3(b, c, d) -#define QUICKCPPLIB_BIND_NAMESPACE_END_EXPAND3(a, b, c) QUICKCPPLIB_BIND_NAMESPACE_END_NAMESPACE_SELECT a QUICKCPPLIB_BIND_NAMESPACE_END_EXPAND2(b, c) -#define QUICKCPPLIB_BIND_NAMESPACE_END_EXPAND2(a, b) QUICKCPPLIB_BIND_NAMESPACE_END_NAMESPACE_SELECT a QUICKCPPLIB_BIND_NAMESPACE_END_EXPAND1(b) -#define QUICKCPPLIB_BIND_NAMESPACE_END_EXPAND1(a) QUICKCPPLIB_BIND_NAMESPACE_END_NAMESPACE_SELECT a - -//! Expands into } } ... -#define QUICKCPPLIB_BIND_NAMESPACE_END(...) QUICKCPPLIB_CALL_OVERLOAD(QUICKCPPLIB_BIND_NAMESPACE_END_EXPAND, __VA_ARGS__) - -//! Expands into a static const char string array used to mark BindLib compatible namespaces -#define QUICKCPPLIB_BIND_DECLARE(decl, desc) static const char *quickcpplib_out[] = {#decl, desc}; - -#endif -#if defined(OUTCOME_UNSTABLE_VERSION) -/* UPDATED BY SCRIPT -(C) 2017-2019 Niall Douglas (225 commits) - - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License in the accompanying file -Licence.txt or at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. - - -Distributed under the Boost Software License, Version 1.0. - (See accompanying file Licence.txt or copy at - http://www.boost.org/LICENSE_1_0.txt) -*/ - -// Note the second line of this file must ALWAYS be the git SHA, third line ALWAYS the git SHA update time -#define OUTCOME_PREVIOUS_COMMIT_REF f2fce2dc31cd1050c4693d1eea852a08c98fc164 -#define OUTCOME_PREVIOUS_COMMIT_DATE "2020-03-12 10:35:46 +00:00" -#define OUTCOME_PREVIOUS_COMMIT_UNIQUE f2fce2dc -#define OUTCOME_V2 (QUICKCPPLIB_BIND_NAMESPACE_VERSION(outcome_v2, OUTCOME_PREVIOUS_COMMIT_UNIQUE)) -#else -#define OUTCOME_V2 (QUICKCPPLIB_BIND_NAMESPACE_VERSION(outcome_v2)) -#endif - -#if defined(GENERATING_OUTCOME_MODULE_INTERFACE) -#define OUTCOME_V2_NAMESPACE QUICKCPPLIB_BIND_NAMESPACE(OUTCOME_V2) -#define OUTCOME_V2_NAMESPACE_BEGIN QUICKCPPLIB_BIND_NAMESPACE_BEGIN(OUTCOME_V2) -#define OUTCOME_V2_NAMESPACE_EXPORT_BEGIN QUICKCPPLIB_BIND_NAMESPACE_EXPORT_BEGIN(OUTCOME_V2) -#define OUTCOME_V2_NAMESPACE_END QUICKCPPLIB_BIND_NAMESPACE_END(OUTCOME_V2) -#else -#define OUTCOME_V2_NAMESPACE QUICKCPPLIB_BIND_NAMESPACE(OUTCOME_V2) -#define OUTCOME_V2_NAMESPACE_BEGIN QUICKCPPLIB_BIND_NAMESPACE_BEGIN(OUTCOME_V2) -#define OUTCOME_V2_NAMESPACE_EXPORT_BEGIN QUICKCPPLIB_BIND_NAMESPACE_BEGIN(OUTCOME_V2) -#define OUTCOME_V2_NAMESPACE_END QUICKCPPLIB_BIND_NAMESPACE_END(OUTCOME_V2) -#endif - -#include // for uint32_t etc -#include -#include // for future serialisation -#include // for placement in moves etc -#include - -#ifndef OUTCOME_USE_STD_IN_PLACE_TYPE -#if defined(_MSC_VER) && _HAS_CXX17 -#define OUTCOME_USE_STD_IN_PLACE_TYPE 1 // MSVC always has std::in_place_type -#elif __cplusplus >= 201700 -// libstdc++ before GCC 6 doesn't have it, despite claiming C++ 17 support -#ifdef __has_include -#if !__has_include() -#define OUTCOME_USE_STD_IN_PLACE_TYPE 0 // must have it if is present -#endif -#endif - -#ifndef OUTCOME_USE_STD_IN_PLACE_TYPE -#define OUTCOME_USE_STD_IN_PLACE_TYPE 1 -#endif -#else -#define OUTCOME_USE_STD_IN_PLACE_TYPE 0 -#endif -#endif - -#if OUTCOME_USE_STD_IN_PLACE_TYPE -#include // for in_place_type_t - -OUTCOME_V2_NAMESPACE_BEGIN -template using in_place_type_t = std::in_place_type_t; -using std::in_place_type; -OUTCOME_V2_NAMESPACE_END -#else -OUTCOME_V2_NAMESPACE_BEGIN -/*! AWAITING HUGO JSON CONVERSION TOOL -type definition template in_place_type_t. Potential doc page: `in_place_type_t` -*/ -template struct in_place_type_t -{ - explicit in_place_type_t() = default; -}; -/*! AWAITING HUGO JSON CONVERSION TOOL -SIGNATURE NOT RECOGNISED -*/ -template constexpr in_place_type_t in_place_type{}; -OUTCOME_V2_NAMESPACE_END -#endif - -#ifndef OUTCOME_TRIVIAL_ABI -#if 0 || __clang_major__ >= 7 -//! Defined to be `[[clang::trivial_abi]]` when on a new enough clang compiler. Usually automatic, can be overriden. -#define OUTCOME_TRIVIAL_ABI [[clang::trivial_abi]] -#else -#define OUTCOME_TRIVIAL_ABI -#endif -#endif - -OUTCOME_V2_NAMESPACE_BEGIN -namespace detail -{ - // Test if type is an in_place_type_t - template struct is_in_place_type_t - { - static constexpr bool value = false; - }; - template struct is_in_place_type_t> - { - static constexpr bool value = true; - }; - - // Replace void with constructible void_type - struct empty_type - { - }; - struct void_type - { - // We always compare true to another instance of me - constexpr bool operator==(void_type /*unused*/) const noexcept { return true; } - constexpr bool operator!=(void_type /*unused*/) const noexcept { return false; } - }; - template using devoid = std::conditional_t::value, void_type, T>; - - template using rebind_type5 = Output; - template - using rebind_type4 = std::conditional_t< // - std::is_volatile::value, // - std::add_volatile_t>>, // - rebind_type5>; - template - using rebind_type3 = std::conditional_t< // - std::is_const::value, // - std::add_const_t>>, // - rebind_type4>; - template - using rebind_type2 = std::conditional_t< // - std::is_lvalue_reference::value, // - std::add_lvalue_reference_t>>, // - rebind_type3>; - template - using rebind_type = std::conditional_t< // - std::is_rvalue_reference::value, // - std::add_rvalue_reference_t>>, // - rebind_type2>; - - // static_assert(std::is_same_v, volatile const int &&>, ""); - - - /* True if type is the same or constructible. Works around a bug where clang + libstdc++ - pukes on std::is_constructible (this bug is fixed upstream). - */ - - - template struct _is_explicitly_constructible - { - static constexpr bool value = std::is_constructible::value; - }; - template struct _is_explicitly_constructible - { - static constexpr bool value = false; - }; - template <> struct _is_explicitly_constructible - { - static constexpr bool value = false; - }; - template static constexpr bool is_explicitly_constructible = _is_explicitly_constructible::value; - - template struct _is_implicitly_constructible - { - static constexpr bool value = std::is_convertible::value; - }; - template struct _is_implicitly_constructible - { - static constexpr bool value = false; - }; - template <> struct _is_implicitly_constructible - { - static constexpr bool value = false; - }; - template static constexpr bool is_implicitly_constructible = _is_implicitly_constructible::value; - -#ifndef OUTCOME_USE_STD_IS_NOTHROW_SWAPPABLE -#if defined(_MSC_VER) && _HAS_CXX17 -#define OUTCOME_USE_STD_IS_NOTHROW_SWAPPABLE 1 // MSVC always has std::is_nothrow_swappable -#elif __cplusplus >= 201700 -// libstdc++ before GCC 6 doesn't have it, despite claiming C++ 17 support -#ifdef __has_include -#if !__has_include() -#define OUTCOME_USE_STD_IS_NOTHROW_SWAPPABLE 0 -#endif -#endif - -#ifndef OUTCOME_USE_STD_IS_NOTHROW_SWAPPABLE -#define OUTCOME_USE_STD_IS_NOTHROW_SWAPPABLE 1 -#endif -#else -#define OUTCOME_USE_STD_IS_NOTHROW_SWAPPABLE 0 -#endif -#endif - -// True if type is nothrow swappable -#if !0 && OUTCOME_USE_STD_IS_NOTHROW_SWAPPABLE - template using is_nothrow_swappable = std::is_nothrow_swappable; -#else - template struct is_nothrow_swappable - { - static constexpr bool value = std::is_nothrow_move_constructible::value && std::is_nothrow_move_assignable::value; - }; -#endif -} // namespace detail -OUTCOME_V2_NAMESPACE_END - - -#ifndef OUTCOME_THROW_EXCEPTION -#ifdef __cpp_exceptions -#define OUTCOME_THROW_EXCEPTION(expr) throw expr -#else - -#ifdef __ANDROID__ -#define OUTCOME_DISABLE_EXECINFO -#endif - -#ifndef OUTCOME_DISABLE_EXECINFO -#ifdef _WIN32 -/* Implements backtrace() et al from glibc on win64 -(C) 2016-2017 Niall Douglas (4 commits) -File Created: Mar 2016 - - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License in the accompanying file -Licence.txt or at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. - - -Distributed under the Boost Software License, Version 1.0. - (See accompanying file Licence.txt or copy at - http://www.boost.org/LICENSE_1_0.txt) -*/ - -#ifndef BOOST_BINDLIB_EXECINFO_WIN64_H -#define BOOST_BINDLIB_EXECINFO_WIN64_H - -#ifndef _WIN32 -#error Can only be included on Windows -#endif - -#include -#include - -#ifdef QUICKCPPLIB_EXPORTS -#define EXECINFO_DECL extern __declspec(dllexport) -#else -#if defined(__cplusplus) && (!defined(QUICKCPPLIB_HEADERS_ONLY) || QUICKCPPLIB_HEADERS_ONLY == 1) && !0 -#define EXECINFO_DECL inline -#elif defined(QUICKCPPLIB_DYN_LINK) && !defined(QUICKCPPLIB_STATIC_LINK) -#define EXECINFO_DECL extern __declspec(dllimport) -#else -#define EXECINFO_DECL extern -#endif -#endif - -#ifdef __cplusplus -extern "C" { -#endif - -//! Fill the array of void * at bt with up to len entries, returning entries filled. -EXECINFO_DECL _Check_return_ size_t backtrace(_Out_writes_(len) void **bt, _In_ size_t len); - -//! Returns a malloced block of string representations of the input backtrace. -EXECINFO_DECL _Check_return_ _Ret_writes_maybenull_(len) char **backtrace_symbols(_In_reads_(len) void *const *bt, _In_ size_t len); - -// extern void backtrace_symbols_fd(void *const *bt, size_t len, int fd); - -#ifdef __cplusplus -} - -#if (!defined(QUICKCPPLIB_HEADERS_ONLY) || QUICKCPPLIB_HEADERS_ONLY == 1) && !0 -#define QUICKCPPLIB_INCLUDED_BY_HEADER 1 -/* Implements backtrace() et al from glibc on win64 -(C) 2016-2017 Niall Douglas (14 commits) -File Created: Mar 2016 - - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License in the accompanying file -Licence.txt or at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. - - -Distributed under the Boost Software License, Version 1.0. - (See accompanying file Licence.txt or copy at - http://www.boost.org/LICENSE_1_0.txt) -*/ -/* Implements backtrace() et al from glibc on win64 -(C) 2016-2017 Niall Douglas (4 commits) -File Created: Mar 2016 - - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License in the accompanying file -Licence.txt or at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. - - -Distributed under the Boost Software License, Version 1.0. - (See accompanying file Licence.txt or copy at - http://www.boost.org/LICENSE_1_0.txt) -*/ -#include // for abort -#include - -// To avoid including windows.h, this source has been macro expanded and win32 function shimmed for C++ only -#if defined(__cplusplus) && !defined(__clang__) -namespace win32 -{ - extern _Ret_maybenull_ void *__stdcall LoadLibraryA(_In_ const char *lpLibFileName); - typedef int(__stdcall *GetProcAddress_returntype)(); - extern GetProcAddress_returntype __stdcall GetProcAddress(_In_ void *hModule, _In_ const char *lpProcName); - extern _Success_(return != 0) unsigned short __stdcall RtlCaptureStackBackTrace(_In_ unsigned long FramesToSkip, _In_ unsigned long FramesToCapture, _Out_writes_to_(FramesToCapture, return ) void **BackTrace, _Out_opt_ unsigned long *BackTraceHash); - extern _Success_(return != 0) - _When_((cchWideChar == -1) && (cbMultiByte != 0), _Post_equal_to_(_String_length_(lpMultiByteStr) + 1)) int __stdcall WideCharToMultiByte(_In_ unsigned int CodePage, _In_ unsigned long dwFlags, const wchar_t *lpWideCharStr, _In_ int cchWideChar, _Out_writes_bytes_to_opt_(cbMultiByte, return ) char *lpMultiByteStr, - _In_ int cbMultiByte, _In_opt_ const char *lpDefaultChar, _Out_opt_ int *lpUsedDefaultChar); -#pragma comment(lib, "kernel32.lib") -#if defined(_WIN64) -#pragma comment(linker, "/alternatename:?LoadLibraryA@win32@@YAPEAXPEBD@Z=LoadLibraryA") -#pragma comment(linker, "/alternatename:?GetProcAddress@win32@@YAP6AHXZPEAXPEBD@Z=GetProcAddress") -#pragma comment(linker, "/alternatename:?RtlCaptureStackBackTrace@win32@@YAGKKPEAPEAXPEAK@Z=RtlCaptureStackBackTrace") -#pragma comment(linker, "/alternatename:?WideCharToMultiByte@win32@@YAHIKPEB_WHPEADHPEBDPEAH@Z=WideCharToMultiByte") -#else -#pragma comment(linker, "/alternatename:?LoadLibraryA@win32@@YGPAXPBD@Z=__imp__LoadLibraryA@4") -#pragma comment(linker, "/alternatename:?GetProcAddress@win32@@YGP6GHXZPAXPBD@Z=__imp__GetProcAddress@8") -#pragma comment(linker, "/alternatename:?RtlCaptureStackBackTrace@win32@@YGGKKPAPAXPAK@Z=__imp__RtlCaptureStackBackTrace@16") -#pragma comment(linker, "/alternatename:?WideCharToMultiByte@win32@@YGHIKPB_WHPADHPBDPAH@Z=__imp__WideCharToMultiByte@32") -#endif -} // namespace win32 -#else -#ifndef WIN32_LEAN_AND_MEAN -#define WIN32_LEAN_AND_MEAN -#endif -#ifndef NOMINMAX -#define NOMINMAX -#endif -#include -#endif - -#ifdef __cplusplus -namespace -{ -#endif - - typedef struct _IMAGEHLP_LINE64 - { - unsigned long SizeOfStruct; - void *Key; - unsigned long LineNumber; - wchar_t *FileName; - unsigned long long int Address; - } IMAGEHLP_LINE64, *PIMAGEHLP_LINE64; - - typedef int(__stdcall *SymInitialize_t)(_In_ void *hProcess, _In_opt_ const wchar_t *UserSearchPath, _In_ int fInvadeProcess); - - typedef int(__stdcall *SymGetLineFromAddr64_t)(_In_ void *hProcess, _In_ unsigned long long int dwAddr, _Out_ unsigned long *pdwDisplacement, _Out_ PIMAGEHLP_LINE64 Line); - -#if defined(__cplusplus) && !defined(__clang__) - static void *dbghelp; -#else -static HMODULE dbghelp; -#endif - static SymInitialize_t SymInitialize; - static SymGetLineFromAddr64_t SymGetLineFromAddr64; - - static void load_dbghelp() - { -#if defined(__cplusplus) && !defined(__clang__) - using win32::GetProcAddress; - using win32::LoadLibraryA; -#endif - if(dbghelp) - return; - dbghelp = LoadLibraryA("DBGHELP.DLL"); - if(dbghelp) - { - SymInitialize = (SymInitialize_t) GetProcAddress(dbghelp, "SymInitializeW"); - if(!SymInitialize) - abort(); - if(!SymInitialize((void *) (size_t) -1 /*GetCurrentProcess()*/, NULL, 1)) - abort(); - SymGetLineFromAddr64 = (SymGetLineFromAddr64_t) GetProcAddress(dbghelp, "SymGetLineFromAddrW64"); - if(!SymGetLineFromAddr64) - abort(); - } - } - -#ifdef __cplusplus -} -#endif - -#ifdef __cplusplus -extern "C" -{ -#endif - - _Check_return_ size_t backtrace(_Out_writes_(len) void **bt, _In_ size_t len) - { -#if defined(__cplusplus) && !defined(__clang__) - using win32::RtlCaptureStackBackTrace; -#endif - return RtlCaptureStackBackTrace(1, (unsigned long) len, bt, NULL); - } - -#ifdef _MSC_VER -#pragma warning(push) -#pragma warning(disable : 6385 6386) // MSVC static analyser can't grok this function. clang's analyser gives it thumbs up. -#endif - _Check_return_ _Ret_writes_maybenull_(len) char **backtrace_symbols(_In_reads_(len) void *const *bt, _In_ size_t len) - { -#if defined(__cplusplus) && !defined(__clang__) - using win32::WideCharToMultiByte; -#endif - size_t bytes = (len + 1) * sizeof(void *) + 256, n; - if(!len) - return NULL; - else - { - char **ret = (char **) malloc(bytes); - char *p = (char *) (ret + len + 1), *end = (char *) ret + bytes; - if(!ret) - return NULL; - for(n = 0; n < len + 1; n++) - ret[n] = NULL; - load_dbghelp(); - for(n = 0; n < len; n++) - { - unsigned long displ; - IMAGEHLP_LINE64 ihl; - memset(&ihl, 0, sizeof(ihl)); - ihl.SizeOfStruct = sizeof(IMAGEHLP_LINE64); - int please_realloc = 0; - if(!bt[n]) - { - ret[n] = NULL; - } - else - { - // Keep offset till later - ret[n] = (char *) ((char *) p - (char *) ret); - if(!SymGetLineFromAddr64 || !SymGetLineFromAddr64((void *) (size_t) -1 /*GetCurrentProcess()*/, (size_t) bt[n], &displ, &ihl)) - { - if(n == 0) - { - free(ret); - return NULL; - } - ihl.FileName = (wchar_t *) L"unknown"; - ihl.LineNumber = 0; - } - retry: - if(please_realloc) - { - char **temp = (char **) realloc(ret, bytes + 256); - if(!temp) - { - free(ret); - return NULL; - } - p = (char *) temp + (p - (char *) ret); - ret = temp; - bytes += 256; - end = (char *) ret + bytes; - } - if(ihl.FileName && ihl.FileName[0]) - { - int plen = WideCharToMultiByte(65001 /*CP_UTF8*/, 0, ihl.FileName, -1, p, (int) (end - p), NULL, NULL); - if(!plen) - { - please_realloc = 1; - goto retry; - } - p[plen - 1] = 0; - p += plen - 1; - } - else - { - if(end - p < 16) - { - please_realloc = 1; - goto retry; - } - _ui64toa_s((size_t) bt[n], p, end - p, 16); - p = strchr(p, 0); - } - if(end - p < 16) - { - please_realloc = 1; - goto retry; - } - *p++ = ':'; - _itoa_s(ihl.LineNumber, p, end - p, 10); - p = strchr(p, 0) + 1; - } - } - for(n = 0; n < len; n++) - { - if(ret[n]) - ret[n] = (char *) ret + (size_t) ret[n]; - } - return ret; - } - } -#ifdef _MSC_VER -#pragma warning(pop) -#endif - - // extern void backtrace_symbols_fd(void *const *bt, size_t len, int fd); - -#ifdef __cplusplus -} -#endif -#undef QUICKCPPLIB_INCLUDED_BY_HEADER -#endif - -#endif - -#endif -#else -#include -#endif -#endif // OUTCOME_DISABLE_EXECINFO -#include -#include -OUTCOME_V2_NAMESPACE_BEGIN -namespace detail -{ - QUICKCPPLIB_NORETURN inline void do_fatal_exit(const char *expr) - { -#if !defined(OUTCOME_DISABLE_EXECINFO) - void *bt[16]; - size_t btlen = backtrace(bt, sizeof(bt) / sizeof(bt[0])); // NOLINT -#endif - fprintf(stderr, "FATAL: Outcome throws exception %s with exceptions disabled\n", expr); // NOLINT -#if !defined(OUTCOME_DISABLE_EXECINFO) - char **bts = backtrace_symbols(bt, btlen); // NOLINT - if(bts != nullptr) - { - for(size_t n = 0; n < btlen; n++) - { - fprintf(stderr, " %s\n", bts[n]); // NOLINT - } - free(bts); // NOLINT - } -#endif - abort(); - } -} // namespace detail -OUTCOME_V2_NAMESPACE_END -#define OUTCOME_THROW_EXCEPTION(expr) OUTCOME_V2_NAMESPACE::detail::do_fatal_exit(#expr), (void) (expr) - -#endif -#endif - -#ifndef BOOST_OUTCOME_AUTO_TEST_CASE -#define BOOST_OUTCOME_AUTO_TEST_CASE(a, b) BOOST_AUTO_TEST_CASE(a, b) -#endif - -#endif -/* A very simple result type -(C) 2017-2019 Niall Douglas (14 commits) -File Created: June 2017 - - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License in the accompanying file -Licence.txt or at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. - - -Distributed under the Boost Software License, Version 1.0. - (See accompanying file Licence.txt or copy at - http://www.boost.org/LICENSE_1_0.txt) -*/ - -#ifndef OUTCOME_BASIC_RESULT_HPP -#define OUTCOME_BASIC_RESULT_HPP -/* Says how to convert value, error and exception types -(C) 2017-2019 Niall Douglas (12 commits) -File Created: Nov 2017 - - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License in the accompanying file -Licence.txt or at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. - - -Distributed under the Boost Software License, Version 1.0. - (See accompanying file Licence.txt or copy at - http://www.boost.org/LICENSE_1_0.txt) -*/ - -#ifndef OUTCOME_CONVERT_HPP -#define OUTCOME_CONVERT_HPP -/* Storage for a very simple basic_result type -(C) 2017-2019 Niall Douglas (6 commits) -File Created: Oct 2017 - - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License in the accompanying file -Licence.txt or at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. - - -Distributed under the Boost Software License, Version 1.0. - (See accompanying file Licence.txt or copy at - http://www.boost.org/LICENSE_1_0.txt) -*/ - -#ifndef OUTCOME_BASIC_RESULT_STORAGE_HPP -#define OUTCOME_BASIC_RESULT_STORAGE_HPP -/* Type sugar for success and failure -(C) 2017-2019 Niall Douglas (25 commits) -File Created: July 2017 - - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License in the accompanying file -Licence.txt or at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. - - -Distributed under the Boost Software License, Version 1.0. - (See accompanying file Licence.txt or copy at - http://www.boost.org/LICENSE_1_0.txt) -*/ - -#ifndef OUTCOME_SUCCESS_FAILURE_HPP -#define OUTCOME_SUCCESS_FAILURE_HPP - - - -OUTCOME_V2_NAMESPACE_BEGIN - -/*! AWAITING HUGO JSON CONVERSION TOOL -type definition template success_type. Potential doc page: `success_type` -*/ -template struct OUTCOME_NODISCARD success_type -{ - using value_type = T; - -private: - value_type _value; - -public: - success_type() = default; - success_type(const success_type &) = default; - success_type(success_type &&) = default; // NOLINT - success_type &operator=(const success_type &) = default; - success_type &operator=(success_type &&) = default; // NOLINT - ~success_type() = default; - OUTCOME_TEMPLATE(class U) - OUTCOME_TREQUIRES(OUTCOME_TPRED(!std::is_same>::value)) - constexpr explicit success_type(U &&v) - : _value(static_cast(v)) // NOLINT - { - } - - constexpr value_type &value() & { return _value; } - constexpr const value_type &value() const & { return _value; } - constexpr value_type &&value() && { return static_cast(_value); } - constexpr const value_type &&value() const && { return static_cast(_value); } -}; -template <> struct OUTCOME_NODISCARD success_type -{ - using value_type = void; -}; -/*! Returns type sugar for implicitly constructing a `basic_result` with a successful state, -default constructing `T` if necessary. -*/ -inline constexpr success_type success() noexcept -{ - return success_type{}; -} -/*! Returns type sugar for implicitly constructing a `basic_result` with a successful state. -\effects Copies or moves the successful state supplied into the returned type sugar. -*/ -template inline constexpr success_type> success(T &&v) -{ - return success_type>{static_cast(v)}; -} - -/*! AWAITING HUGO JSON CONVERSION TOOL -type definition template failure_type. Potential doc page: `failure_type` -*/ -template struct OUTCOME_NODISCARD failure_type -{ - using error_type = EC; - using exception_type = E; - -private: - bool _have_error{}, _have_exception{}; - error_type _error; - exception_type _exception; - - struct error_init_tag - { - }; - struct exception_init_tag - { - }; - -public: - failure_type() = default; - failure_type(const failure_type &) = default; - failure_type(failure_type &&) = default; // NOLINT - failure_type &operator=(const failure_type &) = default; - failure_type &operator=(failure_type &&) = default; // NOLINT - ~failure_type() = default; - template - constexpr explicit failure_type(U &&u, V &&v) - : _have_error(true) - , _have_exception(true) - , _error(static_cast(u)) - , _exception(static_cast(v)) - { - } - template - constexpr explicit failure_type(in_place_type_t /*unused*/, U &&u, error_init_tag /*unused*/ = error_init_tag()) - : _have_error(true) - , _error(static_cast(u)) - , _exception() - { - } - template - constexpr explicit failure_type(in_place_type_t /*unused*/, U &&u, exception_init_tag /*unused*/ = exception_init_tag()) - : _have_exception(true) - , _error() - , _exception(static_cast(u)) - { - } - - constexpr bool has_error() const { return _have_error; } - constexpr bool has_exception() const { return _have_exception; } - - constexpr error_type &error() & { return _error; } - constexpr const error_type &error() const & { return _error; } - constexpr error_type &&error() && { return static_cast(_error); } - constexpr const error_type &&error() const && { return static_cast(_error); } - - constexpr exception_type &exception() & { return _exception; } - constexpr const exception_type &exception() const & { return _exception; } - constexpr exception_type &&exception() && { return static_cast(_exception); } - constexpr const exception_type &&exception() const && { return static_cast(_exception); } -}; -template struct OUTCOME_NODISCARD failure_type -{ - using error_type = EC; - using exception_type = void; - -private: - error_type _error; - -public: - failure_type() = default; - failure_type(const failure_type &) = default; - failure_type(failure_type &&) = default; // NOLINT - failure_type &operator=(const failure_type &) = default; - failure_type &operator=(failure_type &&) = default; // NOLINT - ~failure_type() = default; - OUTCOME_TEMPLATE(class U) - OUTCOME_TREQUIRES(OUTCOME_TPRED(!std::is_same>::value)) - constexpr explicit failure_type(U &&u) - : _error(static_cast(u)) // NOLINT - { - } - - constexpr error_type &error() & { return _error; } - constexpr const error_type &error() const & { return _error; } - constexpr error_type &&error() && { return static_cast(_error); } - constexpr const error_type &&error() const && { return static_cast(_error); } -}; -template struct OUTCOME_NODISCARD failure_type -{ - using error_type = void; - using exception_type = E; - -private: - exception_type _exception; - -public: - failure_type() = default; - failure_type(const failure_type &) = default; - failure_type(failure_type &&) = default; // NOLINT - failure_type &operator=(const failure_type &) = default; - failure_type &operator=(failure_type &&) = default; // NOLINT - ~failure_type() = default; - OUTCOME_TEMPLATE(class V) - OUTCOME_TREQUIRES(OUTCOME_TPRED(!std::is_same>::value)) - constexpr explicit failure_type(V &&v) - : _exception(static_cast(v)) // NOLINT - { - } - - constexpr exception_type &exception() & { return _exception; } - constexpr const exception_type &exception() const & { return _exception; } - constexpr exception_type &&exception() && { return static_cast(_exception); } - constexpr const exception_type &&exception() const && { return static_cast(_exception); } -}; -/*! AWAITING HUGO JSON CONVERSION TOOL -SIGNATURE NOT RECOGNISED -*/ -template inline constexpr failure_type> failure(EC &&v) -{ - return failure_type>{static_cast(v)}; -} -/*! AWAITING HUGO JSON CONVERSION TOOL -SIGNATURE NOT RECOGNISED -*/ -template inline constexpr failure_type, std::decay_t> failure(EC &&v, E &&w) -{ - return failure_type, std::decay_t>{static_cast(v), static_cast(w)}; -} - -namespace detail -{ - template struct is_success_type - { - static constexpr bool value = false; - }; - template struct is_success_type> - { - static constexpr bool value = true; - }; - template struct is_failure_type - { - static constexpr bool value = false; - }; - template struct is_failure_type> - { - static constexpr bool value = true; - }; -} // namespace detail - -/*! AWAITING HUGO JSON CONVERSION TOOL -SIGNATURE NOT RECOGNISED -*/ -template static constexpr bool is_success_type = detail::is_success_type>::value; - -/*! AWAITING HUGO JSON CONVERSION TOOL -SIGNATURE NOT RECOGNISED -*/ -template static constexpr bool is_failure_type = detail::is_failure_type>::value; - -OUTCOME_V2_NAMESPACE_END - -#endif -/* Traits for Outcome -(C) 2018-2019 Niall Douglas (8 commits) -File Created: March 2018 - - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License in the accompanying file -Licence.txt or at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. - - -Distributed under the Boost Software License, Version 1.0. - (See accompanying file Licence.txt or copy at - http://www.boost.org/LICENSE_1_0.txt) -*/ - -#ifndef OUTCOME_TRAIT_HPP -#define OUTCOME_TRAIT_HPP - - - -OUTCOME_V2_NAMESPACE_BEGIN - -namespace trait -{ - /*! AWAITING HUGO JSON CONVERSION TOOL -SIGNATURE NOT RECOGNISED -*/ - - - template // - static constexpr bool type_can_be_used_in_basic_result = // - (!std::is_reference::value // - && !OUTCOME_V2_NAMESPACE::detail::is_in_place_type_t>::value // - && !is_success_type // - && !is_failure_type // - && !std::is_array::value // - && (std::is_void::value || (std::is_object::value // - && std::is_destructible::value)) // - ); - - /*! AWAITING HUGO JSON CONVERSION TOOL -type definition is_error_type. Potential doc page: NOT FOUND -*/ - - - template struct is_error_type - { - static constexpr bool value = false; - }; - - /*! AWAITING HUGO JSON CONVERSION TOOL -type definition is_error_type_enum. Potential doc page: NOT FOUND -*/ - - - template struct is_error_type_enum - { - static constexpr bool value = false; - }; - - namespace detail - { - template using devoid = OUTCOME_V2_NAMESPACE::detail::devoid; - template std::add_rvalue_reference_t> declval() noexcept; - - // From http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2015/n4436.pdf - namespace detector_impl - { - template using void_t = void; - template class Op, class... Args> struct detector - { - static constexpr bool value = false; - using type = Default; - }; - template class Op, class... Args> struct detector>, Op, Args...> - { - static constexpr bool value = true; - using type = Op; - }; - } // namespace detector_impl - template