diff options
| author | Claudius "keldu" Holeksa <mail@keldu.de> | 2026-08-04 16:16:32 +0200 |
|---|---|---|
| committer | Claudius "keldu" Holeksa <mail@keldu.de> | 2026-08-04 16:16:32 +0200 |
| commit | 4bde4893c9ab3a0d09570946b67734751bc84408 (patch) | |
| tree | 29916f5319d541214c2e9180a0c01357a59953b4 /modules/codec-unit | |
| parent | 728fe910b288321760042d5aa520eedeabb3af96 (diff) | |
| download | forstio-forstio-4bde4893c9ab3a0d09570946b67734751bc84408.tar.gz | |
Pushing something
Diffstat (limited to 'modules/codec-unit')
| -rw-r--r-- | modules/codec-unit/c++/unit_schema.hpp | 12 | ||||
| -rw-r--r-- | modules/codec-unit/c++/unit_transform.hpp | 27 |
2 files changed, 23 insertions, 16 deletions
diff --git a/modules/codec-unit/c++/unit_schema.hpp b/modules/codec-unit/c++/unit_schema.hpp index 5de8770..a675e23 100644 --- a/modules/codec-unit/c++/unit_schema.hpp +++ b/modules/codec-unit/c++/unit_schema.hpp @@ -4,11 +4,17 @@ namespace saw { namespace schema { -template<typename Unit, int64_t Exponent> -struct UnitElement {}; +template<typename Un, int64_t Expo = 0, int64_t Scal = 0> +struct UnitElement { + using Schema = Un; + static constexpr int64_t Exponent = Expo; + static constexpr int64_t Scaling = Scal; +}; template<typename BaseSchema, typename ... Components> -struct Unit {}; +struct Unit { + using Schema = BaseSchema; +}; template<typename BaseSchema> using Pure = Unit<BaseSchema>; diff --git a/modules/codec-unit/c++/unit_transform.hpp b/modules/codec-unit/c++/unit_transform.hpp index 5e90878..40a85a1 100644 --- a/modules/codec-unit/c++/unit_transform.hpp +++ b/modules/codec-unit/c++/unit_transform.hpp @@ -18,9 +18,9 @@ class unit_redux_list { using Type = unit_redux_list<>; }; -template<typename T0, int64_t E0, typename... TL, int64_t... EL> -struct unit_redux_list<schema::UnitElement<T0,E0>, schema::UnitElement<TL,EL>...> { - using Type = typename unit_matching<unit_redux_list<schema::UnitElement<T0,E0>, schema::UnitElement<TL,EL>...>, unit_redux_list<>>::TypeList; +template<typename T0, int64_t E0, int64_t S0, typename... TL, int64_t... EL, int64_t... SL> +struct unit_redux_list<schema::UnitElement<T0,E0,S0>, schema::UnitElement<TL,EL,SL>...> { + using Type = typename unit_matching<unit_redux_list<schema::UnitElement<T0,E0,S0>, schema::UnitElement<TL,EL,SL>...>, unit_redux_list<>>::TypeList; }; template<typename T, typename U, typename V> @@ -32,16 +32,16 @@ public: /** * Iterate over the left list to check against the left element. */ -template<typename T, int64_t E, typename T0, int64_t E0, typename... TL, int64_t... EL, typename... TR, int64_t... ER> -class unit_matching_reduce<schema::UnitElement<T,E>, unit_redux_list<schema::UnitElement<T0,E0>,schema::UnitElement<TL,EL>...>, unit_redux_list<schema::UnitElement<TR,ER>...>> { +template<typename T, int64_t E, int64_t S, typename T0, int64_t E0, int64_t S0, typename... TL, int64_t... EL, int64_t... SL, typename... TR, int64_t... ER, int64_t... SR> +class unit_matching_reduce<schema::UnitElement<T,E,S>, unit_redux_list<schema::UnitElement<T0,E0,S0>,schema::UnitElement<TL,EL,SL>...>, unit_redux_list<schema::UnitElement<TR,ER,SR>...>> { public: - static constexpr bool is_same = std::is_same_v<T,T0>; + static constexpr bool is_same = std::is_same_v<T,T0> and std::is_same_v<S,S0>; // Match T,E against T0,E0 - using ReducedType = typename std::conditional<is_same, schema::UnitElement<T,E+E0>, schema::UnitElement<T,E>>::type; - using ReducedTypeList = typename std::conditional<is_same, unit_redux_list<schema::UnitElement<TR,ER>...>, unit_redux_list<schema::UnitElement<TR,ER>..., schema::UnitElement<T0,E0>>>::type; + using ReducedType = typename std::conditional<is_same, schema::UnitElement<T,E+E0,S>, schema::UnitElement<T,E,S>>::type; + using ReducedTypeList = typename std::conditional<is_same, unit_redux_list<schema::UnitElement<TR,ER,SR>...>, unit_redux_list<schema::UnitElement<TR,ER,SR>..., schema::UnitElement<T0,E0,S0>>>::type; - using NextMatcher = unit_matching_reduce<ReducedType, unit_redux_list<schema::UnitElement<TL,EL>...>, ReducedTypeList>; + using NextMatcher = unit_matching_reduce<ReducedType, unit_redux_list<schema::UnitElement<TL,EL,SL>...>, ReducedTypeList>; using Type = typename NextMatcher::Type; using TypeList = typename NextMatcher::TypeList; static constexpr int64_t Num = NextMatcher::Num; @@ -51,12 +51,13 @@ public: * Final step after going through the list. This contains the final match result. * On the left is the accumulated type and on the right its's a list of non matching types */ -template<typename T, int64_t E, typename... TR, int64_t... ER> -class unit_matching_reduce<schema::UnitElement<T,E>, unit_redux_list<>, unit_redux_list<schema::UnitElement<TR,ER>...>> { +template<typename T, int64_t E, int64_t S, typename... TR, int64_t... ER, int64_t... SR> +class unit_matching_reduce<schema::UnitElement<T,E,S>, unit_redux_list<>, unit_redux_list<schema::UnitElement<TR,ER,SR>...>> { public: - using Type = schema::UnitElement<T,E>; - using TypeList = unit_redux_list<schema::UnitElement<TR,ER>...>; + using Type = schema::UnitElement<T,E,S>; + using TypeList = unit_redux_list<schema::UnitElement<TR,ER,SR>...>; static constexpr int64_t Num = E; + static constexpr int64_t Scale = S; }; template<typename LR, typename RR> |
