From 9383579d43f834519d5061527f749acf8dca59c6 Mon Sep 17 00:00:00 2001 From: "Claudius \"keldu\" Holeksa" Date: Thu, 16 Jul 2026 15:10:27 +0200 Subject: Prepping for abstract data in lbm --- modules/core/c++/abstract/alloc.hpp | 9 ++++ modules/core/c++/abstract/data.hpp | 53 +++++----------------- modules/core/c++/abstract/encode.hpp | 9 ++++ modules/core/c++/abstract/schema.hpp | 60 +++++++++++++++++++++++++ modules/core/c++/abstract/string_literal.hpp | 61 ++++++++++++++++++++++++++ modules/core/c++/abstract/stringify_schema.hpp | 51 +++++++++++++++++++++ 6 files changed, 200 insertions(+), 43 deletions(-) create mode 100644 modules/core/c++/abstract/alloc.hpp create mode 100644 modules/core/c++/abstract/encode.hpp create mode 100644 modules/core/c++/abstract/schema.hpp create mode 100644 modules/core/c++/abstract/string_literal.hpp create mode 100644 modules/core/c++/abstract/stringify_schema.hpp diff --git a/modules/core/c++/abstract/alloc.hpp b/modules/core/c++/abstract/alloc.hpp new file mode 100644 index 0000000..b15e737 --- /dev/null +++ b/modules/core/c++/abstract/alloc.hpp @@ -0,0 +1,9 @@ +#pragma once + +namespace kel { +namespace lbm { +namespace all { +struct Native {}; +} +} +} diff --git a/modules/core/c++/abstract/data.hpp b/modules/core/c++/abstract/data.hpp index ed23268..f1ae5a7 100644 --- a/modules/core/c++/abstract/data.hpp +++ b/modules/core/c++/abstract/data.hpp @@ -1,52 +1,19 @@ #pragma once -#include "templates.hpp" +#include "schema.hpp" +#include "encode.hpp" namespace kel { -namespace sch { -struct Void {}; - -struct UnsignedInteger {}; -struct SignedInteger {}; -struct FloatingPoint {}; - -template -struct MixedPrecision { - using Meta = Void; - using StorageType = StorageT; - using InterfaceType = InterfaceT; -}; - -template -struct Primitive { - using Meta = Void; - using Type = PrimType; - static constexpr uint64_t Bytes = N; -}; - -template -struct FixedArray { - using Meta = Void; - using Inner = T; - static constexpr std::array Dimensions{Dims...}; +namespace lbm { +template +class data final {}; + +template +class data,Encode> final { +private: +public: }; -template -struct Array { - using Meta = FixedArray; - using Inner = T; - static constexpr std::array Dimensions{Dims}; -}; - -template -struct Tuple { -}; } - -template -struct schema { - using Type = Sch; -}; - } diff --git a/modules/core/c++/abstract/encode.hpp b/modules/core/c++/abstract/encode.hpp new file mode 100644 index 0000000..64aef4a --- /dev/null +++ b/modules/core/c++/abstract/encode.hpp @@ -0,0 +1,9 @@ +#pragma once + +namespace kel { +namespace lbm { +namespace enc { +struct Native {}; +} +} +} diff --git a/modules/core/c++/abstract/schema.hpp b/modules/core/c++/abstract/schema.hpp new file mode 100644 index 0000000..8305005 --- /dev/null +++ b/modules/core/c++/abstract/schema.hpp @@ -0,0 +1,60 @@ +#pragma once + +#include "string_literal.hpp" +#include "templates.hpp" + +namespace kel { +namespace sch { +struct Void {}; + +struct UnsignedInteger {}; +struct SignedInteger {}; +struct FloatingPoint {}; + +template +struct MixedPrecision { + using Meta = Void; + using StorageType = StorageT; + using InterfaceType = InterfaceT; +}; + +template +struct Primitive { + using Meta = Void; + using StorageType = PrimType; + using InterfaceType = PrimType; + static constexpr uint64_t Bytes = N; +}; + +template +struct FixedArray { + using Meta = Void; + using Inner = T; + static constexpr std::array Dimensions{Dims...}; +}; + +template +struct Array { + using Meta = FixedArray; + using Inner = T; + static constexpr std::array Dimensions{Dims}; +}; + +template +struct Tuple { +}; + +template +struct Member {}; + +template +struct Struct {}; + +} + +template +struct schema { + using Type = Sch; +}; + +} diff --git a/modules/core/c++/abstract/string_literal.hpp b/modules/core/c++/abstract/string_literal.hpp new file mode 100644 index 0000000..51e58c8 --- /dev/null +++ b/modules/core/c++/abstract/string_literal.hpp @@ -0,0 +1,61 @@ +#pragma once + +#include +#include + +namespace kel { +namespace lbm { +/** + * Helper object which creates a templated string from the provided string + * literal. It guarantees compile time uniqueness and thus allows using strings + * in template parameters. + */ +template class string_literal { +public: + static_assert(N > 0, "string_literal needs a null terminator"); + + constexpr string_literal(const CharT (&input)[N]) noexcept { + for (size_t i = 0; i < N; ++i) { + data[i] = input[i]; + } + } + + std::array data{}; + + constexpr std::string_view view() const noexcept { + return std::string_view{data.data()}; + } + + constexpr bool + operator==(const string_literal &) const noexcept = default; + + template + constexpr bool + operator==(const string_literal &) const noexcept { + return false; + } + + template + constexpr string_literal operator+(const string_literal& rhs) const noexcept { + CharT sum[N+NR-1]; + + // The weird i+1 happens due to needing to skip the '\0' terminator + for(size_t i = 0; (i+1) < N; ++i){ + sum[i] = data[i]; + } + for(size_t i = 0; i < NR; ++i){ + sum[i+N-1] = rhs.data[i]; + } + + return string_literal{sum}; + } + + +}; + +template +constexpr string_literal operator""_sl() { + return string_literal{{Chars..., '\0'}}; +} +} +} diff --git a/modules/core/c++/abstract/stringify_schema.hpp b/modules/core/c++/abstract/stringify_schema.hpp new file mode 100644 index 0000000..866bc7e --- /dev/null +++ b/modules/core/c++/abstract/stringify_schema.hpp @@ -0,0 +1,51 @@ +#pragma once + +#include "schema.hpp" + +namespace kel { +namespace lbm { +namespace impl { +template +struct schema_to_string_helper { + static_assert(always_false, "schema_to_string_helper specialization not handled."); + + static constexpr string_literal apply(){ + return {}; + } +}; + +template<> +struct schema_to_string_helper final { + static constexpr string_literal apply(){ + return "SignedInteger"; + } +}; + +template<> +struct schema_to_string_helper final { + static constexpr string_literal apply(){ + return "UnsignedInteger"; + } +}; + +template<> +struct schema_to_string_helper final { + static constexpr string_literal apply(){ + return "FloatingPoint"; + } +}; + +template +struct schema_to_string_helper> final { + static constexpr string_literal apply(){ + return "Primitive<"+schema_to_string_helper::apply()+","+N+">"; + } +}; +} + +template +struct schema_to_string{ + static constexpr std::string_view value = impl::schema_to_string_helper::apply().view(); +}; +} +} -- cgit v1.2.3