diff options
author | Claudius Holeksa <mail@keldu.de> | 2023-05-23 16:38:43 +0200 |
---|---|---|
committer | Claudius Holeksa <mail@keldu.de> | 2023-05-23 16:38:43 +0200 |
commit | 613cfebc0b2a2968260e5f9122d7b5e7ba3755c3 (patch) | |
tree | 5ebbd0fc749c1939e16432351005a5999b317f2b | |
parent | 3be2ae868746f2fc09f69e667e18b838cef82be9 (diff) |
c++: Renamed class and fixed namespace naming
-rw-r--r-- | src/kelunit/distance/meter.h | 6 | ||||
-rw-r--r-- | src/kelunit/time/second.h | 4 | ||||
-rw-r--r-- | src/kelunit/unit.h | 28 | ||||
-rw-r--r-- | src/kelunit/unit.tmpl.h | 22 | ||||
-rw-r--r-- | src/kelunit/unit_reduction.h | 54 |
5 files changed, 57 insertions, 57 deletions
diff --git a/src/kelunit/distance/meter.h b/src/kelunit/distance/meter.h index 57ca58e..0d9fb3b 100644 --- a/src/kelunit/distance/meter.h +++ b/src/kelunit/distance/meter.h @@ -4,7 +4,7 @@ #include <string_view> -namespace kelun { +namespace kel { namespace unit_type { struct meter{ static constexpr std::string_view name = "meter"; @@ -13,8 +13,8 @@ struct meter{ } template<typename S> -using meter = unit<S,unit_base<unit_type::meter,1>>; +using meter = unit<S,unit_component<unit_type::meter,1>>; template<typename S> -using square_meter = unit<S,unit_base<unit_type::meter,2>>; +using square_meter = unit<S,unit_component<unit_type::meter,2>>; } diff --git a/src/kelunit/time/second.h b/src/kelunit/time/second.h index 07145ca..6dca456 100644 --- a/src/kelunit/time/second.h +++ b/src/kelunit/time/second.h @@ -2,7 +2,7 @@ #include "../unit.h" -namespace kelun { +namespace kel { namespace unit_type { struct second{ static constexpr std::string_view name = "second"; @@ -11,5 +11,5 @@ struct second{ } template<typename S> -using second = unit<S,unit_base<unit_type::second,1>>; +using second = unit<S,unit_component<unit_type::second,1>>; } diff --git a/src/kelunit/unit.h b/src/kelunit/unit.h index 4958eb9..a8e8320 100644 --- a/src/kelunit/unit.h +++ b/src/kelunit/unit.h @@ -1,41 +1,41 @@ #pragma once -#include "./unit_reduction.h" +#include "unit_reduction.h" -namespace kelun { +namespace kel { template<typename UnitType, int64_t Exponent> -struct unit_base {}; +struct unit_component {}; template<typename StorageT, typename... T> class unit; template<typename StorageT, typename... UnitTypes, int64_t... Exponents> -class unit<StorageT, unit_base<UnitTypes, Exponents>...> { +class unit<StorageT, unit_component<UnitTypes, Exponents>...> { public: using value_type = StorageT; unit() = default; - unit(const unit<StorageT,unit_base<UnitTypes, Exponents>...>&) = default; - unit(unit<StorageT,unit_base<UnitTypes,Exponents>...>&&) = default; + unit(const unit<StorageT,unit_component<UnitTypes, Exponents>...>&) = default; + unit(unit<StorageT,unit_component<UnitTypes,Exponents>...>&&) = default; - unit<StorageT,unit_base<UnitTypes,Exponents>...>& operator=(const unit<StorageT,unit_base<UnitTypes,Exponents>...>&) = default; - unit<StorageT,unit_base<UnitTypes,Exponents>...>& operator=(unit<StorageT,unit_base<UnitTypes,Exponents>...>&&) = default; + unit<StorageT,unit_component<UnitTypes,Exponents>...>& operator=(const unit<StorageT,unit_component<UnitTypes,Exponents>...>&) = default; + unit<StorageT,unit_component<UnitTypes,Exponents>...>& operator=(unit<StorageT,unit_component<UnitTypes,Exponents>...>&&) = default; unit(const value_type&); unit(value_type&&); - unit<StorageT,unit_base<UnitTypes,Exponents>...>& operator=(const value_type&); - unit<StorageT,unit_base<UnitTypes,Exponents>...>& operator=(value_type&&); + unit<StorageT,unit_component<UnitTypes,Exponents>...>& operator=(const value_type&); + unit<StorageT,unit_component<UnitTypes,Exponents>...>& operator=(value_type&&); - unit<StorageT,unit_base<UnitTypes,Exponents>...> operator+(const unit<StorageT,unit_base<UnitTypes,Exponents>...>& rhs); - unit<StorageT,unit_base<UnitTypes,Exponents>...> operator-(const unit<StorageT,unit_base<UnitTypes,Exponents>...>& rhs); + unit<StorageT,unit_component<UnitTypes,Exponents>...> operator+(const unit<StorageT,unit_component<UnitTypes,Exponents>...>& rhs); + unit<StorageT,unit_component<UnitTypes,Exponents>...> operator-(const unit<StorageT,unit_component<UnitTypes,Exponents>...>& rhs); template<typename... Trhs> - typename unit_multiplication<unit<StorageT,unit_base<UnitTypes,Exponents>...>, unit<StorageT,Trhs...>>::type operator*(const unit<StorageT, Trhs...>& rhs); + typename unit_multiplication<unit<StorageT,unit_component<UnitTypes,Exponents>...>, unit<StorageT,Trhs...>>::type operator*(const unit<StorageT, Trhs...>& rhs); template<typename... Trhs> - typename unit_multiplication<unit<StorageT, unit_base<UnitTypes,Exponents>...>, typename unit_invert<StorageT,Trhs...>::type>::type operator/(const unit<StorageT, Trhs...>& rhs); + typename unit_multiplication<unit<StorageT, unit_component<UnitTypes,Exponents>...>, typename unit_invert<StorageT,Trhs...>::type>::type operator/(const unit<StorageT, Trhs...>& rhs); value_type data() const; private: diff --git a/src/kelunit/unit.tmpl.h b/src/kelunit/unit.tmpl.h index 42b96ef..d89e0c1 100644 --- a/src/kelunit/unit.tmpl.h +++ b/src/kelunit/unit.tmpl.h @@ -3,51 +3,51 @@ namespace kelun { template<typename StorageT, typename... UnitTypes, int64_t... Exponents> -unit<StorageT,unit_base<UnitTypes, Exponents>...>::unit(const value_type& value_): +unit<StorageT,unit_component<UnitTypes, Exponents>...>::unit(const value_type& value_): value{value_}{} template<typename StorageT, typename... UnitTypes, int64_t... Exponents> -unit<StorageT,unit_base<UnitTypes, Exponents>...>::unit(value_type&& value_):value{std::move(value_)}{} +unit<StorageT,unit_component<UnitTypes, Exponents>...>::unit(value_type&& value_):value{std::move(value_)}{} template<typename StorageT, typename... UnitTypes, int64_t... Exponents> -unit<StorageT,unit_base<UnitTypes, Exponents>...>& unit<StorageT,unit_base<UnitTypes, Exponents>...>::operator=(const typename unit<StorageT,unit_base<UnitTypes, Exponents>...>::value_type& value_){ +unit<StorageT,unit_component<UnitTypes, Exponents>...>& unit<StorageT,unit_component<UnitTypes, Exponents>...>::operator=(const typename unit<StorageT,unit_component<UnitTypes, Exponents>...>::value_type& value_){ value = value_; return *this; } template<typename StorageT, typename... UnitTypes, int64_t... Exponents> -unit<StorageT,unit_base<UnitTypes, Exponents>...>& unit<StorageT,unit_base<UnitTypes, Exponents>...>::operator=(typename unit<StorageT,unit_base<UnitTypes, Exponents>...>::value_type&& value_){ +unit<StorageT,unit_component<UnitTypes, Exponents>...>& unit<StorageT,unit_component<UnitTypes, Exponents>...>::operator=(typename unit<StorageT,unit_component<UnitTypes, Exponents>...>::value_type&& value_){ value = std::move(value_); return *this; } template<typename StorageT, typename... UnitTypes, int64_t... Exponents> -unit<StorageT,unit_base<UnitTypes, Exponents>...> unit<StorageT,unit_base<UnitTypes, Exponents>...>::operator+(const unit<StorageT,unit_base<UnitTypes, Exponents>...>& rhs){ +unit<StorageT,unit_component<UnitTypes, Exponents>...> unit<StorageT,unit_component<UnitTypes, Exponents>...>::operator+(const unit<StorageT,unit_component<UnitTypes, Exponents>...>& rhs){ return value + rhs.value; } template<typename StorageT, typename... UnitTypes, int64_t... Exponents> -unit<StorageT,unit_base<UnitTypes, Exponents>...> unit<StorageT,unit_base<UnitTypes, Exponents>...>::operator-(const unit<StorageT,unit_base<UnitTypes, Exponents>...>& rhs){ +unit<StorageT,unit_component<UnitTypes, Exponents>...> unit<StorageT,unit_component<UnitTypes, Exponents>...>::operator-(const unit<StorageT,unit_component<UnitTypes, Exponents>...>& rhs){ return value - rhs.value; } template<typename StorageT, typename... UnitTypes, int64_t... Exponents> template<typename... Trhs> -typename unit_multiplication<unit<StorageT,unit_base<UnitTypes,Exponents>...>, unit<StorageT, Trhs...>>::type -unit<StorageT,unit_base<UnitTypes, Exponents>...>::operator*(const unit<StorageT,Trhs...>& rhs){ +typename unit_multiplication<unit<StorageT,unit_component<UnitTypes,Exponents>...>, unit<StorageT, Trhs...>>::type +unit<StorageT,unit_component<UnitTypes, Exponents>...>::operator*(const unit<StorageT,Trhs...>& rhs){ return value * rhs.data(); } template<typename StorageT, typename... UnitTypes, int64_t... Exponents> template<typename... Trhs> -typename unit_multiplication<unit<StorageT,unit_base<UnitTypes,Exponents>...>, typename unit_invert<StorageT,Trhs...>::type>::type -unit<StorageT,unit_base<UnitTypes,Exponents>...>::operator/(const unit<StorageT, Trhs...>& rhs){ +typename unit_multiplication<unit<StorageT,unit_component<UnitTypes,Exponents>...>, typename unit_invert<StorageT,Trhs...>::type>::type +unit<StorageT,unit_component<UnitTypes,Exponents>...>::operator/(const unit<StorageT, Trhs...>& rhs){ typename unit_invert<StorageT, Trhs...>::type rhs_inverted{static_cast<StorageT>(1)/rhs.data()}; return value * rhs_inverted.data(); } template<typename StorageT, typename... UnitTypes, int64_t... Exponents> -typename unit<StorageT,unit_base<UnitTypes, Exponents>...>::value_type unit<StorageT,unit_base<UnitTypes, Exponents>...>::data() const { +typename unit<StorageT,unit_component<UnitTypes, Exponents>...>::value_type unit<StorageT,unit_component<UnitTypes, Exponents>...>::data() const { return value; } } diff --git a/src/kelunit/unit_reduction.h b/src/kelunit/unit_reduction.h index d3299ff..d9060d2 100644 --- a/src/kelunit/unit_reduction.h +++ b/src/kelunit/unit_reduction.h @@ -8,7 +8,7 @@ template<typename... T> constexpr bool is_always_false = false; template<typename UnitType, int64_t Exponent> -struct unit_base; +struct unit_component; template<typename StorageT, typename... T> class unit; @@ -26,8 +26,8 @@ class unit_redux_list { }; template<typename T0, int64_t E0, typename... TL, int64_t... EL> -struct unit_redux_list<unit_base<T0,E0>, unit_base<TL,EL>...> { - using reduced_type = typename unit_matching<unit_redux_list<unit_base<T0,E0>, unit_base<TL,EL>...>, unit_redux_list<>>::type; +struct unit_redux_list<unit_component<T0,E0>, unit_component<TL,EL>...> { + using reduced_type = typename unit_matching<unit_redux_list<unit_component<T0,E0>, unit_component<TL,EL>...>, unit_redux_list<>>::type; }; template<typename T, typename U, typename V> @@ -37,24 +37,24 @@ public: }; 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<unit_base<T,E>, unit_redux_list<unit_base<T0,E0>,unit_base<TL,EL>...>, unit_redux_list<unit_base<TR,ER>...>> { +class unit_matching_reduce<unit_component<T,E>, unit_redux_list<unit_component<T0,E0>,unit_component<TL,EL>...>, unit_redux_list<unit_component<TR,ER>...>> { public: static constexpr bool is_same = std::is_same_v<T,T0>; - using match_reduce_type = typename std::conditional<is_same, unit_base<T,E+E0>, unit_base<T,E>>::type; - using match_reduce_unit_redux_list = typename std::conditional<is_same, unit_redux_list<unit_base<TR,ER>...>, unit_redux_list<unit_base<TR,ER>..., unit_base<T0,E0>>>::type; + using match_reduce_type = typename std::conditional<is_same, unit_component<T,E+E0>, unit_component<T,E>>::type; + using match_reduce_unit_redux_list = typename std::conditional<is_same, unit_redux_list<unit_component<TR,ER>...>, unit_redux_list<unit_component<TR,ER>..., unit_component<T0,E0>>>::type; - using value_type = typename unit_matching_reduce<match_reduce_type, unit_redux_list<unit_base<TL,EL>...>, match_reduce_unit_redux_list>::value_type; - using unit_redux_list_type = typename unit_matching_reduce<match_reduce_type, unit_redux_list<unit_base<TL,EL>...>, match_reduce_unit_redux_list>::unit_redux_list_type; + using value_type = typename unit_matching_reduce<match_reduce_type, unit_redux_list<unit_component<TL,EL>...>, match_reduce_unit_redux_list>::value_type; + using unit_redux_list_type = typename unit_matching_reduce<match_reduce_type, unit_redux_list<unit_component<TL,EL>...>, match_reduce_unit_redux_list>::unit_redux_list_type; - static constexpr int64_t value_num = unit_matching_reduce<match_reduce_type, unit_redux_list<unit_base<TL,EL>...>, match_reduce_unit_redux_list>::value_num; + static constexpr int64_t value_num = unit_matching_reduce<match_reduce_type, unit_redux_list<unit_component<TL,EL>...>, match_reduce_unit_redux_list>::value_num; }; template<typename T, int64_t E, typename... TR, int64_t... ER> -class unit_matching_reduce<unit_base<T,E>, unit_redux_list<>, unit_redux_list<unit_base<TR,ER>...>> { +class unit_matching_reduce<unit_component<T,E>, unit_redux_list<>, unit_redux_list<unit_component<TR,ER>...>> { public: - using value_type = unit_base<T,E>; - using unit_redux_list_type = unit_redux_list<unit_base<TR,ER>...>; + using value_type = unit_component<T,E>; + using unit_redux_list_type = unit_redux_list<unit_component<TR,ER>...>; static constexpr int64_t value_num = E; }; @@ -65,20 +65,20 @@ class unit_matching { }; template<typename... T, int64_t... E> -class unit_matching<unit_redux_list<>,unit_redux_list<unit_base<T,E>...>> { +class unit_matching<unit_redux_list<>,unit_redux_list<unit_component<T,E>...>> { public: - using type = unit_redux_list<unit_base<T,E>...>; + using type = unit_redux_list<unit_component<T,E>...>; }; template<typename T0, int64_t E0, typename... TL, int64_t... EL, typename... TR, int64_t... ER> -class unit_matching<unit_redux_list<unit_base<T0,E0>,unit_base<TL,EL>...>, unit_redux_list<unit_base<TR,ER>...>> { +class unit_matching<unit_redux_list<unit_component<T0,E0>,unit_component<TL,EL>...>, unit_redux_list<unit_component<TR,ER>...>> { public: - using reduced_value_type = typename unit_matching_reduce<unit_base<T0,E0>, unit_redux_list<unit_base<TL,EL>...>, unit_redux_list<>>::value_type; - using reduced_unit_redux_list_type = typename unit_matching_reduce<unit_base<T0,E0>, unit_redux_list<unit_base<TL,EL>...>, unit_redux_list<>>::unit_redux_list_type; + using reduced_value_type = typename unit_matching_reduce<unit_component<T0,E0>, unit_redux_list<unit_component<TL,EL>...>, unit_redux_list<>>::value_type; + using reduced_unit_redux_list_type = typename unit_matching_reduce<unit_component<T0,E0>, unit_redux_list<unit_component<TL,EL>...>, unit_redux_list<>>::unit_redux_list_type; - static constexpr int64_t reduced_value_num = unit_matching_reduce<unit_base<T0,E0>, unit_redux_list<unit_base<TL,EL>...>, unit_redux_list<>>::value_num; - using reduced_result_unit_redux_list = typename std::conditional<reduced_value_num == 0, unit_redux_list<unit_base<TR,ER>...>, unit_redux_list<unit_base<TR,ER>...,reduced_value_type>>::type; + static constexpr int64_t reduced_value_num = unit_matching_reduce<unit_component<T0,E0>, unit_redux_list<unit_component<TL,EL>...>, unit_redux_list<>>::value_num; + using reduced_result_unit_redux_list = typename std::conditional<reduced_value_num == 0, unit_redux_list<unit_component<TR,ER>...>, unit_redux_list<unit_component<TR,ER>...,reduced_value_type>>::type; using type = typename unit_matching<reduced_unit_redux_list_type, reduced_result_unit_redux_list>::type; }; @@ -90,9 +90,9 @@ public: }; template<typename StorageT, typename... UnitTypes, int64_t... UnitExponents> -class unit_matching_add_storage<unit_redux_list<unit_base<UnitTypes,UnitExponents>...>, StorageT> { +class unit_matching_add_storage<unit_redux_list<unit_component<UnitTypes,UnitExponents>...>, StorageT> { public: - using type = unit<StorageT, unit_base<UnitTypes,UnitExponents>...>; + using type = unit<StorageT, unit_component<UnitTypes,UnitExponents>...>; }; } @@ -103,9 +103,9 @@ class unit_reduction { }; template<typename StorageT, typename... UnitT, int64_t... UnitE> -class unit_reduction<StorageT, unit_base<UnitT, UnitE>...> { +class unit_reduction<StorageT, unit_component<UnitT, UnitE>...> { public: - using list_type = typename impl::unit_matching<impl::unit_redux_list<unit_base<UnitT, UnitE>...>, impl::unit_redux_list<>>::type; + using list_type = typename impl::unit_matching<impl::unit_redux_list<unit_component<UnitT, UnitE>...>, impl::unit_redux_list<>>::type; using type = typename impl::unit_matching_add_storage<list_type, StorageT>::type; }; @@ -115,9 +115,9 @@ class unit_invert { }; template<typename StorageT, typename... UnitT, int64_t... UnitE> -class unit_invert<StorageT, unit_base<UnitT, UnitE>...> { +class unit_invert<StorageT, unit_component<UnitT, UnitE>...> { public: - using type = unit<StorageT, unit_base<UnitT, -UnitE>...>; + using type = unit<StorageT, unit_component<UnitT, -UnitE>...>; }; template<typename T, typename U> @@ -126,8 +126,8 @@ class unit_multiplication{ }; template<typename StorageT, typename... UnitT, int64_t... UnitE, typename... UnitRhsT, int64_t... UnitRhsE> -class unit_multiplication<unit<StorageT, unit_base<UnitT,UnitE>...>, unit<StorageT, unit_base<UnitRhsT, UnitRhsE>...>> { +class unit_multiplication<unit<StorageT, unit_component<UnitT,UnitE>...>, unit<StorageT, unit_component<UnitRhsT, UnitRhsE>...>> { public: - using type = typename unit_reduction<StorageT, unit_base<UnitT,UnitE>..., unit_base<UnitRhsT, UnitRhsE>...>::type; + using type = typename unit_reduction<StorageT, unit_component<UnitT,UnitE>..., unit_component<UnitRhsT, UnitRhsE>...>::type; }; } |