From 87db03e9ffa559eaf5f6b970ad42776f33ae34b2 Mon Sep 17 00:00:00 2001 From: "Claudius \"keldu\" Holeksa" Date: Thu, 8 Jan 2026 19:03:09 +0100 Subject: dangling --- modules/codec/c++/data.hpp | 3 +- modules/codec/c++/data_print.hpp | 94 ++++++++++++++++++++++++++++++++++++++++ modules/codec/tests/args.cpp | 2 +- modules/codec/tests/forst.cpp | 18 +++++++- modules/codec/tests/print.cpp | 57 ++++++++++++++++++++++++ modules/core/c++/test/suite.hpp | 2 +- 6 files changed, 172 insertions(+), 4 deletions(-) create mode 100644 modules/codec/c++/data_print.hpp create mode 100644 modules/codec/tests/print.cpp diff --git a/modules/codec/c++/data.hpp b/modules/codec/c++/data.hpp index dca98ac..585501b 100644 --- a/modules/codec/c++/data.hpp +++ b/modules/codec/c++/data.hpp @@ -82,8 +82,9 @@ struct native_data_type> { using type = double; }; +// Give a variable for setting the default encoding. Maybe add a static assert to guarantee that this encoding supports immediate access? #ifndef FORSTIO_DEFAULT_DATA_ENCODING -#define FORSTIO_DEFAULT_DATA_ENCODING encode::Native +#define FORSTIO_DEFAULT_DATA_ENCODING ::saw::encode::Native #endif template diff --git a/modules/codec/c++/data_print.hpp b/modules/codec/c++/data_print.hpp new file mode 100644 index 0000000..8eba274 --- /dev/null +++ b/modules/codec/c++/data_print.hpp @@ -0,0 +1,94 @@ +#pragma once + +#include "data.hpp" +#include + +namespace saw { +namespace impl { +struct data_print_tab_helper { + static void apply(std::ostream& o, uint64_t tabs){ + for(uint64_t i = 0u; i < tabs; ++i){ + o<<'\t'; + } + } +}; + +template +struct data_print_std_helper { + static void apply(std::ostream& o, const data& dat){ + // Blueprint + (void)o; + (void)dat; + } +}; + +template +struct data_print_std_helper, Encode> { + static void apply(std::ostream& o, const data,Encode>& dat, uint64_t tabs){ + (void) tabs; + // Blueprint + o< +struct data_print_std_helper { + static void apply(std::ostream& o, const data& dat, uint64_t tabs){ + (void) tabs; + // Blueprint + auto size = dat.size(); + o<<"\""; + for(saw::data i{0u}; i < size; ++i){ + o< +struct data_print_std_helper, Encode> { + static void apply(std::ostream& o, const data,Encode>& dat, uint64_t tabs){ + (void) tabs; + // Blueprint + auto size = dat.size(); + o<<"\""; + for(saw::data i{0u}; i < size; ++i){ + o< +struct data_print_std_helper, Encode> { + template + static void apply(std::ostream& o, const data,Encode>& dat, uint64_t tabs){ + if constexpr (i < sizeof...(Members)){ + using Memb = parameter_pack_type::type; + + data_print_tab_helper::apply(o,tabs); + o<<"- \""<::apply(o,dat.template get(), tabs); + o<<"\n"; + apply(o,dat,tabs); + } + } + + static void apply(std::ostream& o, const data,Encode>& dat, uint64_t tabs){ + data_print_tab_helper::apply(o,tabs); + + apply<0u>(o,dat,tabs+1u); + } +}; + +} +} + +namespace std { +template +inline ostream& operator<<(ostream& o, const saw::data& dat){ + + saw::impl::data_print_std_helper::apply(o, dat, 0u); + + return o; +} +} diff --git a/modules/codec/tests/args.cpp b/modules/codec/tests/args.cpp index f42056a..2b5b14c 100644 --- a/modules/codec/tests/args.cpp +++ b/modules/codec/tests/args.cpp @@ -40,7 +40,7 @@ SAW_TEST("Codec Args Decode Basic"){ codec, encode::Args> args_codec; auto eov = args_codec.decode(dat_args, dat_nat); - SAW_EOV_EXPECT(eov, "Couldn't decode data. "); + SAW_EXPECT_EOV(eov, "Couldn't decode data"); auto& prog = dat_nat.template get<"program">(); auto& str = dat_nat.template get<"args">(); diff --git a/modules/codec/tests/forst.cpp b/modules/codec/tests/forst.cpp index 1d9c0c3..2bf6442 100644 --- a/modules/codec/tests/forst.cpp +++ b/modules/codec/tests/forst.cpp @@ -18,7 +18,7 @@ using TestStruct = Struct< using TestArray = Array< TestStruct >; - +/* SAW_TEST("Codec Forst Layer Info"){ using namespace saw; @@ -82,5 +82,21 @@ SAW_TEST("Codec Forst Primitive"){ SAW_EXPECT(val == foo, "Unexpected value"); } + +SAW_TEST("Codec Forst Struct of Primitives"){ + using namespace saw; + + data test_dat; + + auto& test_a = test_dat.template get<"string">(); + auto& test_b = test_dat.template get<"number">(); + auto& test_c = test_dat.template get<"signed">(); + + test_b.set(50u); + test_c.set(-23); + test_a.set("cheese"); + +} +*/ } } diff --git a/modules/codec/tests/print.cpp b/modules/codec/tests/print.cpp new file mode 100644 index 0000000..695f7a0 --- /dev/null +++ b/modules/codec/tests/print.cpp @@ -0,0 +1,57 @@ +#include +#include "../c++/data_print.hpp" + +namespace { +namespace sch { +using namespace saw::schema; + +using TestStruct = Struct< + Member, + Member, + Member, + Member +>; +} + +/* +SAW_TEST("Math/Basic"){ + using namespace saw; + + data> a; + data> b; + + auto c = a + b; +} +*/ + +SAW_TEST("Data Print/Primitive Float64"){ + using namespace saw; + + + data a{40.1}; + + std::stringstream oss; + oss< a; + + auto& banana = a.template get<"banana">(); + + banana.set("banned"); + + std::stringstream oss; + oss<