Units and dimensions redesigned

This commit is contained in:
Mateusz Pusz committed 2019-12-01 19:47:58 +01:00
1 parent 65ea59edbb
commit 1b4e8a2127
16 files changed
+922 -904

No files matched your search

+52 -26
View File
@@ -28,43 +28,69 @@
namespace units {
struct prefix_type {};
/**
* @brief The base for all prefix types
*
* Every prefix type should inherit from this type to satisfy PrefixType concept.
*/
struct prefix_type {};
template<typename T>
concept PrefixType = std::derived_from<T, prefix_type>;
template<typename T>
concept PrefixType = std::derived_from<T, prefix_type>;
namespace detail {
/**
* @brief No prefix possible for the unit
*
* This is a special prefix type tag specifying that the unit can not be scaled with any kind
* of the prefix.
*/
struct no_prefix : prefix_type {};
template<PrefixType PT, Ratio R>
struct prefix_base : downcast_base<prefix_base<PT, R>> {
using prefix_type = PT;
using ratio = R;
};
namespace detail {
}
template<PrefixType PT, Ratio R>
struct prefix_base : downcast_base<prefix_base<PT, R>> {
using prefix_type = PT;
using ratio = R;
};
template<typename Child, PrefixType PT, Ratio R, basic_fixed_string Symbol>
struct prefix : downcast_child<Child, detail::prefix_base<PT, R>> {
static constexpr auto symbol = Symbol;
};
} // namespace detail
/**
* @brief A prefix used to scale units
*
* Data from a prefix class is used in two cases:
* - when defining a prefixed_unit its ratio is used to scale the reference unit and its
* symbol is used to prepend to the symbol of referenced unit
* - when printing the symbol of a scaled unit that was not predefined by the user but its
* factor matches ratio of a prefix from the specified prefix family, its symbol will be
* prepended to the symbol of the unit
*
* @tparam Child inherited class type used by the downcasting facility (CRTP Idiom)
* @tparam PT a type of prefix family
* @tparam Symbol a text representation of the prefix
* @tparam R factor to be used to scale a unit
*/
template<typename Child, PrefixType PT, basic_fixed_string Symbol, Ratio R>
requires(!std::same_as<PT, no_prefix>)
struct prefix : downcast_child<Child, detail::prefix_base<PT, ratio<R::num, R::den>>> {
static constexpr auto symbol = Symbol;
};
// TODO gcc:92150
// https://gcc.gnu.org/bugzilla/show_bug.cgi?id=92150
// namespace detail {
// TODO gcc:92150
// https://gcc.gnu.org/bugzilla/show_bug.cgi?id=92150
// namespace detail {
// template<typename T>
// inline constexpr bool is_prefix = false;
// template<typename T>
// inline constexpr bool is_prefix = false;
// template<typename PrefixType, Ratio R, basic_fixed_string Symbol>
// inline constexpr bool is_prefix<prefix<PrefixType, R, Symbol>> = true;
// template<typename PrefixType, Ratio R, basic_fixed_string Symbol>
// inline constexpr bool is_prefix<prefix<PrefixType, R, Symbol>> = true;
// } // namespace detail
// } // namespace detail
template<typename T>
template<typename T>
// concept Prefix = detail::is_prefix<T>;
concept Prefix = true;
struct no_prefix : prefix_type {};
concept Prefix = true;
} // namespace units