Skip to content

Commit

Permalink
Umstellung von Eiheitentypen auf Eiheitenkonstanten
Browse files Browse the repository at this point in the history
  • Loading branch information
martinfehrs committed Jan 21, 2024
1 parent a08b837 commit b7310b2
Show file tree
Hide file tree
Showing 26 changed files with 215 additions and 396 deletions.
6 changes: 3 additions & 3 deletions include/zollstock/angle_unit_constants.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,16 @@
namespace zollstock::inline unit::inline constants
{

ZOLLSTOCK_DEFINE_SI_CONSTANTS(, radian, rad)
ZOLLSTOCK_DEFINE_SI_BASE_UNIT_CONSTANTS(radian, rad)

inline constexpr degree deg {};

inline constexpr arcminute arcmin{};

inline constexpr arcsecond arcsec{};
ZOLLSTOCK_DEFINE_SI_PREFIXED_CONSTANTS(, arcsecond, as);
ZOLLSTOCK_DEFINE_SI_PREFIXED_BASE_UNIT_CONSTANTS(arcsecond, as)

ZOLLSTOCK_DEFINE_SI_CONSTANTS(, gradian, gon)
ZOLLSTOCK_DEFINE_SI_BASE_UNIT_CONSTANTS(gradian, gon)

}

Expand Down
5 changes: 3 additions & 2 deletions include/zollstock/area_unit_constants.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@
#define __ZOLLSTOCK_AREA_UNIT_CONSTANTS_HPP__


#include <zollstock/area_unit_types.hpp>
#include <zollstock/length_unit_constants.hpp>
#include <zollstock/definition_helpers.hpp>
#include <zollstock/unit_algorithms.hpp>


namespace zollstock::inline unit::inline constants
{

ZOLLSTOCK_DEFINE_SI_CONSTANTS(square_, meter, m2)
ZOLLSTOCK_DEFINE_SI_DERIVED_UNIT_CONSTANTS(m, 2)

}

Expand Down
41 changes: 0 additions & 41 deletions include/zollstock/area_unit_types.hpp

This file was deleted.

1 change: 0 additions & 1 deletion include/zollstock/area_units.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
#define __ZOLLSTOCK_AREA_UNITS_HPP__


#include <zollstock/area_unit_types.hpp>
#include <zollstock/area_unit_constants.hpp>
#include <zollstock/area_unit_literals.hpp>

Expand Down
164 changes: 100 additions & 64 deletions include/zollstock/definition_helpers.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,76 +2,112 @@
#define __ZOLLSTOCK_DEFINITION_HELPERS_HPP__


#define ZOLLSTOCK_DEFINE_LITERAL(symbol) \
#define ZOLLSTOCK_DEFINE_LITERAL(symbol) \
[[nodiscard]] constexpr auto operator""_##symbol(unsigned long long int value) noexcept \
{ \
return scalar<symbol>{ static_cast<double>(value) }; \
} \
\
[[nodiscard]] constexpr auto operator""_##symbol(long double value) noexcept \
{ \
return scalar<symbol>{ static_cast<double>(value) }; \
} \
{ \
return scalar<symbol>{ static_cast<double>(value) }; \
} \
\
[[nodiscard]] constexpr auto operator""_##symbol(long double value) noexcept \
{ \
return scalar<symbol>{ static_cast<double>(value) }; \
} \

#define ZOLLSTOCK_DEFINE_SI_PREFIXED_LITERALS(base_symbol) \
ZOLLSTOCK_DEFINE_LITERAL(q##base_symbol ) \
ZOLLSTOCK_DEFINE_LITERAL(r##base_symbol ) \
ZOLLSTOCK_DEFINE_LITERAL(y##base_symbol ) \
ZOLLSTOCK_DEFINE_LITERAL(z##base_symbol ) \
ZOLLSTOCK_DEFINE_LITERAL(a##base_symbol ) \
ZOLLSTOCK_DEFINE_LITERAL(f##base_symbol ) \
ZOLLSTOCK_DEFINE_LITERAL(p##base_symbol ) \
ZOLLSTOCK_DEFINE_LITERAL(n##base_symbol ) \
ZOLLSTOCK_DEFINE_LITERAL(mic##base_symbol) \
ZOLLSTOCK_DEFINE_LITERAL(m##base_symbol ) \
ZOLLSTOCK_DEFINE_LITERAL(c##base_symbol ) \
ZOLLSTOCK_DEFINE_LITERAL(d##base_symbol ) \
ZOLLSTOCK_DEFINE_LITERAL(da##base_symbol ) \
ZOLLSTOCK_DEFINE_LITERAL(h##base_symbol ) \
ZOLLSTOCK_DEFINE_LITERAL(k##base_symbol ) \
ZOLLSTOCK_DEFINE_LITERAL(M##base_symbol ) \
ZOLLSTOCK_DEFINE_LITERAL(G##base_symbol ) \
ZOLLSTOCK_DEFINE_LITERAL(T##base_symbol ) \
ZOLLSTOCK_DEFINE_LITERAL(P##base_symbol ) \
ZOLLSTOCK_DEFINE_LITERAL(E##base_symbol ) \
ZOLLSTOCK_DEFINE_LITERAL(Z##base_symbol ) \
ZOLLSTOCK_DEFINE_LITERAL(Y##base_symbol ) \
ZOLLSTOCK_DEFINE_LITERAL(R##base_symbol ) \
ZOLLSTOCK_DEFINE_LITERAL(Q##base_symbol ) \
ZOLLSTOCK_DEFINE_LITERAL(q##base_symbol ) \
ZOLLSTOCK_DEFINE_LITERAL(r##base_symbol ) \
ZOLLSTOCK_DEFINE_LITERAL(y##base_symbol ) \
ZOLLSTOCK_DEFINE_LITERAL(z##base_symbol ) \
ZOLLSTOCK_DEFINE_LITERAL(a##base_symbol ) \
ZOLLSTOCK_DEFINE_LITERAL(f##base_symbol ) \
ZOLLSTOCK_DEFINE_LITERAL(p##base_symbol ) \
ZOLLSTOCK_DEFINE_LITERAL(n##base_symbol ) \
ZOLLSTOCK_DEFINE_LITERAL(mic##base_symbol) \
ZOLLSTOCK_DEFINE_LITERAL(m##base_symbol ) \
ZOLLSTOCK_DEFINE_LITERAL(c##base_symbol ) \
ZOLLSTOCK_DEFINE_LITERAL(d##base_symbol ) \
ZOLLSTOCK_DEFINE_LITERAL(da##base_symbol ) \
ZOLLSTOCK_DEFINE_LITERAL(h##base_symbol ) \
ZOLLSTOCK_DEFINE_LITERAL(k##base_symbol ) \
ZOLLSTOCK_DEFINE_LITERAL(M##base_symbol ) \
ZOLLSTOCK_DEFINE_LITERAL(G##base_symbol ) \
ZOLLSTOCK_DEFINE_LITERAL(T##base_symbol ) \
ZOLLSTOCK_DEFINE_LITERAL(P##base_symbol ) \
ZOLLSTOCK_DEFINE_LITERAL(E##base_symbol ) \
ZOLLSTOCK_DEFINE_LITERAL(Z##base_symbol ) \
ZOLLSTOCK_DEFINE_LITERAL(Y##base_symbol ) \
ZOLLSTOCK_DEFINE_LITERAL(R##base_symbol ) \
ZOLLSTOCK_DEFINE_LITERAL(Q##base_symbol ) \

#define ZOLLSTOCK_DEFINE_SI_LITERALS(base_symbol) \
ZOLLSTOCK_DEFINE_LITERAL(base_symbol) \
ZOLLSTOCK_DEFINE_SI_PREFIXED_LITERALS(base_symbol)
#define ZOLLSTOCK_DEFINE_SI_LITERALS(base_symbol) \
ZOLLSTOCK_DEFINE_LITERAL(base_symbol) \
ZOLLSTOCK_DEFINE_SI_PREFIXED_LITERALS(base_symbol) \

#define ZOLLSTOCK_DEFINE_SI_PREFIXED_CONSTANTS(type_prefix, base_type, base_symbol) \
inline constexpr type_prefix##quecto##base_type q##base_symbol {}; \
inline constexpr type_prefix##ronto##base_type r##base_symbol {}; \
inline constexpr type_prefix##yocto##base_type y##base_symbol {}; \
inline constexpr type_prefix##zepto##base_type z##base_symbol {}; \
inline constexpr type_prefix##atto##base_type a##base_symbol {}; \
inline constexpr type_prefix##femto##base_type f##base_symbol {}; \
inline constexpr type_prefix##pico##base_type p##base_symbol {}; \
inline constexpr type_prefix##nano##base_type n##base_symbol {}; \
inline constexpr type_prefix##micro##base_type mic##base_symbol{}; \
inline constexpr type_prefix##milli##base_type m##base_symbol {}; \
inline constexpr type_prefix##centi##base_type c##base_symbol {}; \
inline constexpr type_prefix##deci##base_type d##base_symbol {}; \
inline constexpr type_prefix##deca##base_type da##base_symbol {}; \
inline constexpr type_prefix##hecto##base_type h##base_symbol {}; \
inline constexpr type_prefix##kilo##base_type k##base_symbol {}; \
inline constexpr type_prefix##mega##base_type M##base_symbol {}; \
inline constexpr type_prefix##giga##base_type G##base_symbol {}; \
inline constexpr type_prefix##tera##base_type T##base_symbol {}; \
inline constexpr type_prefix##peta##base_type P##base_symbol {}; \
inline constexpr type_prefix##exa##base_type E##base_symbol {}; \
inline constexpr type_prefix##zetta##base_type Z##base_symbol {}; \
inline constexpr type_prefix##yotta##base_type Y##base_symbol {}; \
inline constexpr type_prefix##ronna##base_type R##base_symbol {}; \
inline constexpr type_prefix##quetta##base_type Q##base_symbol {}; \
#define ZOLLSTOCK_DEFINE_BASE_UNIT_CONSTANT(type, symbol) \
inline constexpr type symbol{}; \

#define ZOLLSTOCK_DEFINE_SI_CONSTANTS(type_prefix, base_type, base_symbol) \
ZOLLSTOCK_DEFINE_SI_PREFIXED_CONSTANTS(type_prefix, base_type, base_symbol) \
inline constexpr type_prefix##base_type base_symbol{};
#define ZOLLSTOCK_DEFINE_SI_PREFIXED_BASE_UNIT_CONSTANTS(base_type, base_symbol) \
ZOLLSTOCK_DEFINE_BASE_UNIT_CONSTANT(quecto##base_type, q##base_symbol ) \
ZOLLSTOCK_DEFINE_BASE_UNIT_CONSTANT(ronto##base_type , r##base_symbol ) \
ZOLLSTOCK_DEFINE_BASE_UNIT_CONSTANT(yocto##base_type , y##base_symbol ) \
ZOLLSTOCK_DEFINE_BASE_UNIT_CONSTANT(zepto##base_type , z##base_symbol ) \
ZOLLSTOCK_DEFINE_BASE_UNIT_CONSTANT(atto##base_type , a##base_symbol ) \
ZOLLSTOCK_DEFINE_BASE_UNIT_CONSTANT(femto##base_type , f##base_symbol ) \
ZOLLSTOCK_DEFINE_BASE_UNIT_CONSTANT(pico##base_type , p##base_symbol ) \
ZOLLSTOCK_DEFINE_BASE_UNIT_CONSTANT(nano##base_type , n##base_symbol ) \
ZOLLSTOCK_DEFINE_BASE_UNIT_CONSTANT(micro##base_type , mic##base_symbol) \
ZOLLSTOCK_DEFINE_BASE_UNIT_CONSTANT(milli##base_type , m##base_symbol ) \
ZOLLSTOCK_DEFINE_BASE_UNIT_CONSTANT(centi##base_type , c##base_symbol ) \
ZOLLSTOCK_DEFINE_BASE_UNIT_CONSTANT(deci##base_type , d##base_symbol ) \
ZOLLSTOCK_DEFINE_BASE_UNIT_CONSTANT(deca##base_type , da##base_symbol ) \
ZOLLSTOCK_DEFINE_BASE_UNIT_CONSTANT(hecto##base_type , h##base_symbol ) \
ZOLLSTOCK_DEFINE_BASE_UNIT_CONSTANT(kilo##base_type , k##base_symbol ) \
ZOLLSTOCK_DEFINE_BASE_UNIT_CONSTANT(mega##base_type , M##base_symbol ) \
ZOLLSTOCK_DEFINE_BASE_UNIT_CONSTANT(giga##base_type , G##base_symbol ) \
ZOLLSTOCK_DEFINE_BASE_UNIT_CONSTANT(tera##base_type , T##base_symbol ) \
ZOLLSTOCK_DEFINE_BASE_UNIT_CONSTANT(peta##base_type , P##base_symbol ) \
ZOLLSTOCK_DEFINE_BASE_UNIT_CONSTANT(exa##base_type , E##base_symbol ) \
ZOLLSTOCK_DEFINE_BASE_UNIT_CONSTANT(zetta##base_type , Z##base_symbol ) \
ZOLLSTOCK_DEFINE_BASE_UNIT_CONSTANT(yotta##base_type , Y##base_symbol ) \
ZOLLSTOCK_DEFINE_BASE_UNIT_CONSTANT(ronna##base_type , R##base_symbol ) \
ZOLLSTOCK_DEFINE_BASE_UNIT_CONSTANT(quetta##base_type, Q##base_symbol ) \

#define ZOLLSTOCK_DEFINE_SI_BASE_UNIT_CONSTANTS(base_type, base_symbol) \
ZOLLSTOCK_DEFINE_SI_PREFIXED_BASE_UNIT_CONSTANTS(base_type, base_symbol) \
ZOLLSTOCK_DEFINE_BASE_UNIT_CONSTANT(base_type, base_symbol) \

#define ZOLLSTOCK_DEFINE_DERIVED_UNIT_CONSTANT(base_symbol, exponent) \
inline constexpr auto base_symbol##exponent = zollstock::pow<exponent>(base_symbol); \

#define ZOLLSTOCK_DEFINE_SI_PREFIXED_DERIVED_UNIT_CONSTANTS(base_symbol, exponent) \
ZOLLSTOCK_DEFINE_DERIVED_UNIT_CONSTANT(q##base_symbol , exponent) \
ZOLLSTOCK_DEFINE_DERIVED_UNIT_CONSTANT(r##base_symbol , exponent) \
ZOLLSTOCK_DEFINE_DERIVED_UNIT_CONSTANT(y##base_symbol , exponent) \
ZOLLSTOCK_DEFINE_DERIVED_UNIT_CONSTANT(z##base_symbol , exponent) \
ZOLLSTOCK_DEFINE_DERIVED_UNIT_CONSTANT(a##base_symbol , exponent) \
ZOLLSTOCK_DEFINE_DERIVED_UNIT_CONSTANT(f##base_symbol , exponent) \
ZOLLSTOCK_DEFINE_DERIVED_UNIT_CONSTANT(p##base_symbol , exponent) \
ZOLLSTOCK_DEFINE_DERIVED_UNIT_CONSTANT(n##base_symbol , exponent) \
ZOLLSTOCK_DEFINE_DERIVED_UNIT_CONSTANT(mic##base_symbol, exponent) \
ZOLLSTOCK_DEFINE_DERIVED_UNIT_CONSTANT(m##base_symbol , exponent) \
ZOLLSTOCK_DEFINE_DERIVED_UNIT_CONSTANT(c##base_symbol , exponent) \
ZOLLSTOCK_DEFINE_DERIVED_UNIT_CONSTANT(d##base_symbol , exponent) \
ZOLLSTOCK_DEFINE_DERIVED_UNIT_CONSTANT(da##base_symbol , exponent) \
ZOLLSTOCK_DEFINE_DERIVED_UNIT_CONSTANT(h##base_symbol , exponent) \
ZOLLSTOCK_DEFINE_DERIVED_UNIT_CONSTANT(k##base_symbol , exponent) \
ZOLLSTOCK_DEFINE_DERIVED_UNIT_CONSTANT(M##base_symbol , exponent) \
ZOLLSTOCK_DEFINE_DERIVED_UNIT_CONSTANT(G##base_symbol , exponent) \
ZOLLSTOCK_DEFINE_DERIVED_UNIT_CONSTANT(T##base_symbol , exponent) \
ZOLLSTOCK_DEFINE_DERIVED_UNIT_CONSTANT(P##base_symbol , exponent) \
ZOLLSTOCK_DEFINE_DERIVED_UNIT_CONSTANT(E##base_symbol , exponent) \
ZOLLSTOCK_DEFINE_DERIVED_UNIT_CONSTANT(Z##base_symbol , exponent) \
ZOLLSTOCK_DEFINE_DERIVED_UNIT_CONSTANT(Y##base_symbol , exponent) \
ZOLLSTOCK_DEFINE_DERIVED_UNIT_CONSTANT(R##base_symbol , exponent) \
ZOLLSTOCK_DEFINE_DERIVED_UNIT_CONSTANT(Q##base_symbol , exponent) \

#define ZOLLSTOCK_DEFINE_SI_DERIVED_UNIT_CONSTANTS(base_symbol, exponent) \
ZOLLSTOCK_DEFINE_SI_PREFIXED_DERIVED_UNIT_CONSTANTS(base_symbol, exponent) \
ZOLLSTOCK_DEFINE_DERIVED_UNIT_CONSTANT(base_symbol, exponent) \


#endif //__ZOLLSTOCK_DEFINITION_HELPERS_HPP__
2 changes: 1 addition & 1 deletion include/zollstock/length_unit_constants.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
namespace zollstock::inline unit::inline constants
{

ZOLLSTOCK_DEFINE_SI_CONSTANTS(, meter, m)
ZOLLSTOCK_DEFINE_SI_BASE_UNIT_CONSTANTS(meter, m)

}

Expand Down
10 changes: 5 additions & 5 deletions include/zollstock/time_unit_constants.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@
namespace zollstock::inline unit::inline constants
{

ZOLLSTOCK_DEFINE_SI_CONSTANTS(, second, s)
ZOLLSTOCK_DEFINE_SI_BASE_UNIT_CONSTANTS(second, s)

inline constexpr minute min{};
inline constexpr hour h {};
inline constexpr day d {};
inline constexpr year a {};
ZOLLSTOCK_DEFINE_BASE_UNIT_CONSTANT(minute, min)
ZOLLSTOCK_DEFINE_BASE_UNIT_CONSTANT(hour , h )
ZOLLSTOCK_DEFINE_BASE_UNIT_CONSTANT(day , d )
ZOLLSTOCK_DEFINE_BASE_UNIT_CONSTANT(year , a )

}

Expand Down
9 changes: 4 additions & 5 deletions include/zollstock/unit_algorithms.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -153,19 +153,19 @@ namespace zollstock


template <unit_c Unit1, unit_c Unit2>
[[nodiscard]] constexpr multiply_units_v<Unit1, Unit2> operator*(Unit1, Unit2) noexcept
[[nodiscard]] consteval multiply_units_v<Unit1, Unit2> operator*(Unit1, Unit2) noexcept
{
return {};
}

template <unit_c Unit1, unit_c Unit2>
[[nodiscard]] constexpr divide_units_v<Unit1, Unit2> operator/(Unit1, Unit2) noexcept
[[nodiscard]] consteval divide_units_v<Unit1, Unit2> operator/(Unit1, Unit2) noexcept
{
return {};
}

template <int exponent, unit_c Unit>
[[nodiscard]] constexpr auto pow(Unit unit) noexcept
template<int exponent, unit_c Unit>
[[nodiscard]] consteval auto pow(Unit unit) noexcept
{
if constexpr(exponent == 0)
{
Expand All @@ -179,7 +179,6 @@ namespace zollstock
{
return (_1 / unit) * pow<exponent + 1>(unit);
}

}

namespace detail
Expand Down
40 changes: 0 additions & 40 deletions include/zollstock/velocity_unit_types.hpp

This file was deleted.

8 changes: 0 additions & 8 deletions include/zollstock/velocity_units.hpp

This file was deleted.

5 changes: 3 additions & 2 deletions include/zollstock/volume_unit_constants.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@
#define __ZOLLSTOCK_VOLUME_UNIT_CONSTANTS_HPP__


#include <zollstock/volume_unit_types.hpp>
#include <zollstock/length_unit_constants.hpp>
#include <zollstock/definition_helpers.hpp>
#include <zollstock/unit_algorithms.hpp>


namespace zollstock::inline unit::inline constants
{

ZOLLSTOCK_DEFINE_SI_CONSTANTS(cubic_, meter, m3)
ZOLLSTOCK_DEFINE_SI_DERIVED_UNIT_CONSTANTS(m, 3)

}

Expand Down
Loading

0 comments on commit b7310b2

Please sign in to comment.