From 86b06a3fee2cd7635a9ab486e2a35bdf1e81ce38 Mon Sep 17 00:00:00 2001 From: "Claudius \"keldu\" Holeksa" Date: Fri, 21 Jun 2024 19:44:34 +0200 Subject: Moving forward with basic test for sycl --- modules/codec/c++/interface.hpp | 22 +++++++++++++++++----- modules/codec/c++/schema.hpp | 6 ++++++ modules/codec/tests/codec.cpp | 18 +++++++++++++----- 3 files changed, 36 insertions(+), 10 deletions(-) (limited to 'modules/codec') diff --git a/modules/codec/c++/interface.hpp b/modules/codec/c++/interface.hpp index 0f41f55..e1c9a12 100644 --- a/modules/codec/c++/interface.hpp +++ b/modules/codec/c++/interface.hpp @@ -12,28 +12,40 @@ template +struct FuncReturnTypeHelper { + using Type = data; +}; + +template +struct FuncReturnTypeHelper { + using Type = void; +}; + template struct FuncTypeHelper { - using Type = std::function(data&, Ctx)>; + using Type = std::function::Type>(data&, Ctx)>; }; template struct FuncTypeHelper { - using Type = std::function(data&)>; + using Type = std::function::Type>(data&)>; }; + } template class function, Encode, Storage, Context> { private: typename impl::FuncTypeHelper::Type func_; + using ResponseDataType = typename impl::FuncReturnTypeHelper::Type; public: template function(Func func): func_{std::move(func)} {} - error_or> call(data& req, Context ctx = {}){ + error_or call(data& req, Context ctx = {}){ if constexpr (std::is_same_v){ (void) ctx; return func_(req); @@ -84,13 +96,13 @@ public: template error_or< - data< + typename impl::FuncReturnTypeHelper< typename parameter_pack_type< parameter_key_pack_index< Lit, Names... >::value , Responses...>::type - , Encode, Storage>> call( + , Encode, Storage>::Type > call( data< typename parameter_pack_type< parameter_key_pack_index< diff --git a/modules/codec/c++/schema.hpp b/modules/codec/c++/schema.hpp index 2ef7c77..6a69425 100644 --- a/modules/codec/c++/schema.hpp +++ b/modules/codec/c++/schema.hpp @@ -11,6 +11,12 @@ template struct is_primitive { namespace schema { // NOLINTBEGIN + +/** + * Void Type used for function schemas + */ +struct Void {}; + template struct Member { static constexpr string_literal name = "Member"; diff --git a/modules/codec/tests/codec.cpp b/modules/codec/tests/codec.cpp index 720b734..1bec214 100644 --- a/modules/codec/tests/codec.cpp +++ b/modules/codec/tests/codec.cpp @@ -40,12 +40,15 @@ using TestInt32Pair = Tuple< Int32 >; +using TestVoidReturnFunction = Function; + using TestCalcFunction = Function; using TestInterface = Interface< Member, Member, - Member + Member, + Member >; } SAW_TEST("One Dimensional Array") { @@ -378,7 +381,7 @@ SAW_TEST("Interface basics"){ data native; auto func_add = - [](data req){ + [](data& req){ data resp; resp.set(req.get<0>().get() + req.get<1>().get()); @@ -386,14 +389,14 @@ SAW_TEST("Interface basics"){ return resp; }; auto func_sub = - [](data req){ + [](data& req){ data resp; resp.set(req.get<0>().get() - req.get<1>().get()); return resp; }; - auto func_multiply = [](data req){ + auto func_multiply = [](data& req){ data resp; resp.set(req.get<0>().get() * req.get<1>().get()); @@ -401,7 +404,12 @@ SAW_TEST("Interface basics"){ return resp; }; - auto iface = interface_factory::create(std::move(func_add), std::move(func_sub), std::move(func_multiply)); + auto func_void = [](data& req) -> error_or { + (void) req; + return void_t{}; + }; + + auto iface = interface_factory::create(std::move(func_add), std::move(func_sub), std::move(func_multiply), std::move(func_void)); { data native; -- cgit v1.2.3