From 914e441837d79303373bbc20fe04432a1bf08394 Mon Sep 17 00:00:00 2001 From: turuslan Date: Wed, 22 May 2024 15:34:28 +0500 Subject: [PATCH 1/3] qtils outcome Signed-off-by: turuslan --- CMakeLists.txt | 7 +- include/scale/encode_append.hpp | 2 +- include/scale/outcome/outcome-register.hpp | 91 ---------------------- include/scale/outcome/outcome.hpp | 37 --------- include/scale/scale.hpp | 2 +- include/scale/scale_error.hpp | 2 +- test/util/outcome.hpp | 5 +- 7 files changed, 10 insertions(+), 136 deletions(-) delete mode 100644 include/scale/outcome/outcome-register.hpp delete mode 100644 include/scale/outcome/outcome.hpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 307584a..f8e9863 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -13,8 +13,8 @@ endif() include(${CMAKE_CURRENT_LIST_DIR}/cmake/HunterGate.cmake) HunterGate( - URL https://github.com/qdrvm/hunter/archive/refs/tags/v0.23.257-qdrvm10.tar.gz - SHA1 72b446a4424ba28ea90f9a68a9134b0f8e44b5b2 + URL https://github.com/qdrvm/hunter/archive/f7e047b26b7baece6dd195d1010149e606c48ec3.zip + SHA1 be4f7995065c18d4ca894f69f616b367c3237366 ) project(Scale LANGUAGES CXX VERSION 1.1.0) @@ -30,6 +30,9 @@ option(BUILD_TESTS "Whether to include the test suite in build" OFF) hunter_add_package(Boost) find_package(Boost CONFIG REQUIRED) +hunter_add_package(qtils) +find_package(qtils CONFIG REQUIRED) + add_subdirectory(src) if (BUILD_TESTS) diff --git a/include/scale/encode_append.hpp b/include/scale/encode_append.hpp index 325cd17..4b1e1f4 100644 --- a/include/scale/encode_append.hpp +++ b/include/scale/encode_append.hpp @@ -6,7 +6,7 @@ #pragma once -#include +#include #include namespace scale { diff --git a/include/scale/outcome/outcome-register.hpp b/include/scale/outcome/outcome-register.hpp deleted file mode 100644 index 306facb..0000000 --- a/include/scale/outcome/outcome-register.hpp +++ /dev/null @@ -1,91 +0,0 @@ -/** - * Copyright Quadrivium LLC - * All Rights Reserved - * SPDX-License-Identifier: Apache-2.0 - */ - -#pragma once - -#include -#include // bring in std::error_code et al - -#include // for BOOST_SYMBOL_EXPORT - -#ifndef SCALE_EXPORT -#if defined(BOOST_SYMBOL_EXPORT) -#define SCALE_EXPORT BOOST_SYMBOL_EXPORT -#else -#define SCALE_EXPORT -#endif -#endif - -#define OUTCOME_USE_STD_IN_PLACE_TYPE 1 - -namespace scale::__outcome_detail { - - template - class Category : public std::error_category { - public: - const char *name() const noexcept final { - return typeid(T).name(); // enum Errc -> 4Errc - } - - std::string message(int c) const final { - return toString(static_cast(c)); - } - - static std::string toString(T t) { - static_assert( - !std::is_same::value, - "toString() was not specialised for the type T supplied"); - return ""; - } - - SCALE_EXPORT static const Category &get() { - static const Category c; - return c; - } - - ~Category() override = default; - Category(const Category &) = delete; - Category &operator=(const Category &) = delete; - Category(Category &&) = delete; - Category &operator=(Category &&) = delete; - - private: - Category() = default; - }; /* end of class */ - -} // namespace scale::__outcome_detail - -#define __OUTCOME_DEFINE_MAKE_ERROR_CODE(Enum) \ - extern std::error_code make_error_code(Enum e) { \ - return {static_cast(e), \ - scale::__outcome_detail::Category::get()}; \ - } - -#define __OUTCOME_DECLARE_MAKE_ERROR_CODE(Enum) \ - std::error_code make_error_code(Enum e); - -/// MUST BE EXECUTED A FILE LEVEL (no namespace) in HPP -// ns - fully qualified enum namespace. Example: libp2p::common -// Enum - enum name. Example: EncodeError -#define OUTCOME_HPP_DECLARE_ERROR(ns, Enum) \ - namespace ns { \ - __OUTCOME_DECLARE_MAKE_ERROR_CODE(Enum) \ - } \ - \ - template <> \ - struct std::is_error_code_enum : std::true_type {}; - -/// MUST BE EXECUTED AT FILE LEVEL(no namespace) IN CPP -// ns - fully qualified enum namespace. Example: libp2p::common -// Enum - enum name. Example: EncodeError -// Name - variable name. Example: e -#define OUTCOME_CPP_DEFINE_CATEGORY(ns, Enum, Name) \ - namespace ns { \ - __OUTCOME_DEFINE_MAKE_ERROR_CODE(Enum) \ - }; \ - template <> \ - std::string scale::__outcome_detail::Category::toString( \ - ns::Enum Name) diff --git a/include/scale/outcome/outcome.hpp b/include/scale/outcome/outcome.hpp deleted file mode 100644 index 299ab57..0000000 --- a/include/scale/outcome/outcome.hpp +++ /dev/null @@ -1,37 +0,0 @@ -/** - * Copyright Quadrivium LLC - * All Rights Reserved - * SPDX-License-Identifier: Apache-2.0 - */ - -#pragma once - -#pragma warning(push) -#pragma warning(disable : 4583) -#pragma warning(disable : 4582) -#include -#include -#pragma warning(pop) - -#include "outcome-register.hpp" - -namespace scale::outcome { - - using namespace BOOST_OUTCOME_V2_NAMESPACE; - - template > - using result = basic_result; - -} // namespace scale::outcome - -// To define OUTCOME_TRY macro, we will need to create OUTCOME_TRY_1 and -// OUTCOME_TRY_2 depending on number of arguments -#define OUTCOME_TRY_1(...) BOOST_OUTCOME_TRY(__VA_ARGS__) -#define OUTCOME_TRY_2(...) BOOST_OUTCOME_TRY(auto __VA_ARGS__) - -// trick from https://stackoverflow.com/a/11763277 to overload OUTCOME_TRY -#define GET_MACRO(_1, _2, NAME, ...) NAME -#define OUTCOME_TRY(...) \ - GET_MACRO(__VA_ARGS__, OUTCOME_TRY_2, OUTCOME_TRY_1)(__VA_ARGS__) diff --git a/include/scale/scale.hpp b/include/scale/scale.hpp index 81b2506..62558fe 100644 --- a/include/scale/scale.hpp +++ b/include/scale/scale.hpp @@ -10,7 +10,7 @@ #include #include -#include +#include #include #include diff --git a/include/scale/scale_error.hpp b/include/scale/scale_error.hpp index acf3679..366e3fb 100644 --- a/include/scale/scale_error.hpp +++ b/include/scale/scale_error.hpp @@ -6,7 +6,7 @@ #pragma once -#include +#include namespace scale { diff --git a/test/util/outcome.hpp b/test/util/outcome.hpp index 3fd21b7..f3972ba 100644 --- a/test/util/outcome.hpp +++ b/test/util/outcome.hpp @@ -19,11 +19,10 @@ * EXPECT_OUTCOME_TRUE(val, getResult()); */ #define EXPECT_OUTCOME_TRUE(val, expr) \ - EXPECT_OUTCOME_TRUE_name(BOOST_OUTCOME_TRY_UNIQUE_NAME, val, expr) + EXPECT_OUTCOME_TRUE_name(OUTCOME_UNIQUE, val, expr) #define _EXPECT_EC(tmp, expr, expected) \ auto &&tmp = expr; \ EXPECT_TRUE(tmp.has_error()); \ EXPECT_EQ(tmp.error(), expected); -#define EXPECT_EC(expr, expected) \ - _EXPECT_EC(BOOST_OUTCOME_TRY_UNIQUE_NAME, expr, expected) +#define EXPECT_EC(expr, expected) _EXPECT_EC(OUTCOME_UNIQUE, expr, expected) From 43666762dedfa216b47444d02b3544781108ed75 Mon Sep 17 00:00:00 2001 From: turuslan Date: Wed, 29 May 2024 18:44:15 +0500 Subject: [PATCH 2/3] include Signed-off-by: turuslan --- include/scale/enum_traits.hpp | 1 + 1 file changed, 1 insertion(+) diff --git a/include/scale/enum_traits.hpp b/include/scale/enum_traits.hpp index fb2f1b8..4d26389 100644 --- a/include/scale/enum_traits.hpp +++ b/include/scale/enum_traits.hpp @@ -6,6 +6,7 @@ #pragma once +#include #include #include From 7f3d6aeb33552b84009a7e1f40b9dc4fe562bd1a Mon Sep 17 00:00:00 2001 From: turuslan Date: Wed, 29 May 2024 20:15:07 +0500 Subject: [PATCH 3/3] hunter tag Signed-off-by: turuslan --- CMakeLists.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index f8e9863..447b90a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -13,8 +13,8 @@ endif() include(${CMAKE_CURRENT_LIST_DIR}/cmake/HunterGate.cmake) HunterGate( - URL https://github.com/qdrvm/hunter/archive/f7e047b26b7baece6dd195d1010149e606c48ec3.zip - SHA1 be4f7995065c18d4ca894f69f616b367c3237366 + URL https://github.com/qdrvm/hunter/archive/refs/tags/v0.25.3-qdrvm12.zip + SHA1 9d4b9844b84d3dfbf4a90923eedb3875718abf54 ) project(Scale LANGUAGES CXX VERSION 1.1.0)