diff options
| author | Claudius "keldu" Holeksa <mail@keldu.de> | 2026-07-16 17:23:34 +0200 |
|---|---|---|
| committer | Claudius "keldu" Holeksa <mail@keldu.de> | 2026-07-16 17:23:34 +0200 |
| commit | 879188f7c55b4f8383002b6bf09ef32dd592ab90 (patch) | |
| tree | 32e8e1c4816337fa6457f30c51ddf996e888aeb0 /modules/core/c++/abstract | |
| parent | 91f75c895fb2c344805ddcb91439b93bba0293c4 (diff) | |
| parent | bd9f266756849a7381d7a4ff575d5f1ccc6e28bb (diff) | |
| download | libs-lbm-879188f7c55b4f8383002b6bf09ef32dd592ab90.tar.gz | |
Merge branch 'dev'
Diffstat (limited to 'modules/core/c++/abstract')
| -rw-r--r-- | modules/core/c++/abstract/alloc.hpp | 9 | ||||
| -rw-r--r-- | modules/core/c++/abstract/data.hpp | 53 | ||||
| -rw-r--r-- | modules/core/c++/abstract/encode.hpp | 9 | ||||
| -rw-r--r-- | modules/core/c++/abstract/schema.hpp | 60 | ||||
| -rw-r--r-- | modules/core/c++/abstract/string_literal.hpp | 61 | ||||
| -rw-r--r-- | modules/core/c++/abstract/stringify_schema.hpp | 51 |
6 files changed, 200 insertions, 43 deletions
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<typename StorageT, typename InterfaceT> -struct MixedPrecision { - using Meta = Void; - using StorageType = StorageT; - using InterfaceType = InterfaceT; -}; - -template<typename PrimType, uint64_t N> -struct Primitive { - using Meta = Void; - using Type = PrimType; - static constexpr uint64_t Bytes = N; -}; - -template<typename T, uint64_t... Dims> -struct FixedArray { - using Meta = Void; - using Inner = T; - static constexpr std::array<uint64_t,sizeof...(Dims)> Dimensions{Dims...}; +namespace lbm { +template<typename Schema, typename Encode = enc::Native> +class data final {}; + +template<typename T, uint64_t N> +class data<sch::Primitive<T,N>,Encode> final { +private: +public: }; -template<typename T, uint64_t Dims> -struct Array { - using Meta = FixedArray<UInt64,Dims>; - using Inner = T; - static constexpr std::array<uint64_t,sizeof...(Dims)> Dimensions{Dims}; -}; - -template<typename... T> -struct Tuple { -}; } - -template<typename Sch> -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<typename StorageT, typename InterfaceT> +struct MixedPrecision { + using Meta = Void; + using StorageType = StorageT; + using InterfaceType = InterfaceT; +}; + +template<typename PrimType, uint64_t N> +struct Primitive { + using Meta = Void; + using StorageType = PrimType; + using InterfaceType = PrimType; + static constexpr uint64_t Bytes = N; +}; + +template<typename T, uint64_t... Dims> +struct FixedArray { + using Meta = Void; + using Inner = T; + static constexpr std::array<uint64_t,sizeof...(Dims)> Dimensions{Dims...}; +}; + +template<typename T, uint64_t Dims> +struct Array { + using Meta = FixedArray<UInt64,Dims>; + using Inner = T; + static constexpr std::array<uint64_t,sizeof...(Dims)> Dimensions{Dims}; +}; + +template<typename... T> +struct Tuple { +}; + +template<typename Value, string_literal Key> +struct Member {}; + +template<typename... SL> +struct Struct {}; + +} + +template<typename Sch> +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 <array> +#include <string_view> + +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 CharT, size_t N> 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<CharT, N> data{}; + + constexpr std::string_view view() const noexcept { + return std::string_view{data.data()}; + } + + constexpr bool + operator==(const string_literal<CharT, N> &) const noexcept = default; + + template <class CharTR, size_t NR> + constexpr bool + operator==(const string_literal<CharTR, NR> &) const noexcept { + return false; + } + + template<size_t NR> + constexpr string_literal<CharT, N+NR-1> operator+(const string_literal<CharT, NR>& 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<CharT, N+NR-1>{sum}; + } + + +}; + +template <typename T, T... Chars> +constexpr string_literal<T, sizeof...(Chars) + 1u> operator""_sl() { + return string_literal<T, sizeof...(Chars) + 1u>{{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<class T> +struct schema_to_string_helper { + static_assert(always_false<T>, "schema_to_string_helper specialization not handled."); + + static constexpr string_literal apply(){ + return {}; + } +}; + +template<> +struct schema_to_string_helper<sch::SignedInteger> final { + static constexpr string_literal apply(){ + return "SignedInteger"; + } +}; + +template<> +struct schema_to_string_helper<sch::UnsignedInteger> final { + static constexpr string_literal apply(){ + return "UnsignedInteger"; + } +}; + +template<> +struct schema_to_string_helper<sch::FloatingPoint> final { + static constexpr string_literal apply(){ + return "FloatingPoint"; + } +}; + +template<typename T, uint64_t N> +struct schema_to_string_helper<sch::Primitive<T,N>> final { + static constexpr string_literal apply(){ + return "Primitive<"+schema_to_string_helper<T>::apply()+","+N+">"; + } +}; +} + +template<class T> +struct schema_to_string{ + static constexpr std::string_view value = impl::schema_to_string_helper<T>::apply().view(); +}; +} +} |
