From 535498274de9aec26b7baad3df6a9720e9370ede Mon Sep 17 00:00:00 2001 From: Claudius 'keldu' Holeksa Date: Wed, 9 Oct 2024 17:43:08 +0200 Subject: Dangling changes for language things --- modules/core/c++/reduce_templates.hpp | 11 +++- modules/core/tests/templates.cpp | 20 +++++++ modules/lang/c++/c_helper.hpp | 19 +++++++ modules/lang/c++/c_language.hpp | 20 +++++++ modules/lang/c++/c_rpc.hpp | 3 - modules/lang/c++/c_transfer.hpp | 5 +- modules/lang/c++/c_types.hpp | 85 +++++++++++++++++++++++++++++ modules/lang/c++/language.hpp | 6 ++ modules/remote/c++/remote_loopback_base.hpp | 2 +- 9 files changed, 161 insertions(+), 10 deletions(-) create mode 100644 modules/core/tests/templates.cpp create mode 100644 modules/lang/c++/c_helper.hpp create mode 100644 modules/lang/c++/c_language.hpp create mode 100644 modules/lang/c++/c_types.hpp create mode 100644 modules/lang/c++/language.hpp diff --git a/modules/core/c++/reduce_templates.hpp b/modules/core/c++/reduce_templates.hpp index ef5fa4c..fb643df 100644 --- a/modules/core/c++/reduce_templates.hpp +++ b/modules/core/c++/reduce_templates.hpp @@ -13,23 +13,28 @@ struct tmpl_group_reduce_match { template struct tmpl_group_reduce_match> { + /** + * Check if type already exists in list + */ static constexpr bool has_type = std::is_same_v or tmpl_group_reduce_match>::has_type; using type = typename std::conditional, tmpl_group>::type; }; +/** + * Reducing in outer loop + */ template struct tmpl_group_reduce { using reduced_type = T; }; -/** - * Reducing in outer loop - */ template struct tmpl_group_reduce> { + // Compile Time outer iteration using reduced_inner_list = typename tmpl_group_reduce>::reduced_type; + // Actual reduction. Basically an inner loop call using reduced_type = typename tmpl_group_reduce_match::type; }; } diff --git a/modules/core/tests/templates.cpp b/modules/core/tests/templates.cpp new file mode 100644 index 0000000..2a069a6 --- /dev/null +++ b/modules/core/tests/templates.cpp @@ -0,0 +1,20 @@ +#include "../c++/reduce_templates.hpp" + +#include "../c++/test/suite.hpp" + +namespace { +struct Foo{}; + +struct Bar{}; +struct Baz{}; + +SAW_TEST("Templates/Reduce tmpl_group"){ + using namespace saw; + + using DuplGrp = tmpl_group; + + using UniqGrp = tmpl_group; + + SAW_EXPECT((std::is_same_v), "Expected Uniquess Reduction"); +} +} diff --git a/modules/lang/c++/c_helper.hpp b/modules/lang/c++/c_helper.hpp new file mode 100644 index 0000000..550e55c --- /dev/null +++ b/modules/lang/c++/c_helper.hpp @@ -0,0 +1,19 @@ +#pragma once + +#include "c_common.hpp" + +namespace saw { +namespace impl { +struct lang_helper { + static error_or append_string(std::string& buff, const std::string_view& str){ + try{ + buff += str; + }catch(const std::exception&){ + return make_error(); + } + + return make_void(); + } +}; +} +} diff --git a/modules/lang/c++/c_language.hpp b/modules/lang/c++/c_language.hpp new file mode 100644 index 0000000..c4b1d48 --- /dev/null +++ b/modules/lang/c++/c_language.hpp @@ -0,0 +1,20 @@ +#pragma once + +#include "c_transfer.hpp" +#include "c_helper.hpp" +#include "c_rpc.hpp" + +namespace saw { +template +class language { +public: + struct config { + std::string prefix; + }; +public: + error_or generate_rpc(const config& cfg){ + return make_error(); + } +}; + +} diff --git a/modules/lang/c++/c_rpc.hpp b/modules/lang/c++/c_rpc.hpp index 75c2f7c..7a1c6ab 100644 --- a/modules/lang/c++/c_rpc.hpp +++ b/modules/lang/c++/c_rpc.hpp @@ -1,7 +1,4 @@ #pragma once -#include "c_rpc_types.hpp" - namespace saw { - } diff --git a/modules/lang/c++/c_transfer.hpp b/modules/lang/c++/c_transfer.hpp index 6c2061b..5de204c 100644 --- a/modules/lang/c++/c_transfer.hpp +++ b/modules/lang/c++/c_transfer.hpp @@ -1,8 +1,7 @@ #pragma once -#include "c_common.hpp" +#include "language.hpp" +#include "c_types.hpp" namespace saw { -template -struct language {}; } diff --git a/modules/lang/c++/c_types.hpp b/modules/lang/c++/c_types.hpp new file mode 100644 index 0000000..ff3f5a8 --- /dev/null +++ b/modules/lang/c++/c_types.hpp @@ -0,0 +1,85 @@ +#pragma once + +#include + +#include "c_common.hpp" + +namespace saw { +/** + * Helper to determine if we are dealing with primitive types + */ +template +struct c_is_primitive { + static constexpr bool value = false; +}; + +template +struct c_is_primitive> { + static constexpr bool value = true; +}; + +template +struct c_primitive_string { + static_assert(always_false, "Not supported"); +}; + +template<> +struct c_primitive_string { + static constexpr string_literal name = "int8"; + static constexpr string_literal value = "int8_t"; +}; + +template<> +struct c_primitive_string { + static constexpr string_literal name = "int16"; + static constexpr string_literal value = "int16_t"; +}; + +template<> +struct c_primitive_string { + static constexpr string_literal name = "int32"; + static constexpr string_literal value = "int32_t"; +}; + +template<> +struct c_primitive_string { + static constexpr string_literal name = "int64"; + static constexpr string_literal value = "int64_t"; +}; + +template<> +struct c_primitive_string { + static constexpr string_literal name = "uint8"; + static constexpr string_literal value = "uint8_t"; +}; + +template<> +struct c_primitive_string { + static constexpr string_literal name = "uint16"; + static constexpr string_literal value = "uint16_t"; +}; + +template<> +struct c_primitive_string { + static constexpr string_literal name = "uint32"; + static constexpr string_literal value = "uint32_t"; +}; + +template<> +struct c_primitive_string { + static constexpr string_literal name = "uint64"; + static constexpr string_literal value = "uint64_t"; +}; + +template<> +struct c_primitive_string { + static constexpr string_literal name = "float32"; + static constexpr string_literal value = "float"; +}; + +template<> +struct c_primitive_string { + static constexpr string_literal name = "float64"; + static constexpr string_literal value = "double"; +}; +} diff --git a/modules/lang/c++/language.hpp b/modules/lang/c++/language.hpp new file mode 100644 index 0000000..1c05f81 --- /dev/null +++ b/modules/lang/c++/language.hpp @@ -0,0 +1,6 @@ +#pragma once + +namespace saw { +template +struct language {}; +} diff --git a/modules/remote/c++/remote_loopback_base.hpp b/modules/remote/c++/remote_loopback_base.hpp index b53ae49..6ca244f 100644 --- a/modules/remote/c++/remote_loopback_base.hpp +++ b/modules/remote/c++/remote_loopback_base.hpp @@ -68,7 +68,7 @@ public: * Start listening */ template - rpc_server listen(const remote_address& addr, typename rpc_server::InterfaceT iface){ + rpc_server rpc_listen(const remote_address& addr, typename rpc_server::InterfaceT iface){ return {addr, std::move(iface)}; } -- cgit v1.2.3