From 187858d2281503ae47cafb508832661a9e472565 Mon Sep 17 00:00:00 2001 From: Yuri D'Elia Date: Sun, 25 Jul 2021 22:14:56 +0200 Subject: [PATCH] Move config/unit.h to unit.h and it's own namespace --- src/config/axis.h | 4 +++- src/{config => }/unit.h | 53 +++++++++++++++++++++++------------------ 2 files changed, 33 insertions(+), 24 deletions(-) rename src/{config => }/unit.h (54%) diff --git a/src/config/axis.h b/src/config/axis.h index 6d5acd0..c55afbe 100644 --- a/src/config/axis.h +++ b/src/config/axis.h @@ -1,9 +1,11 @@ #pragma once #include -#include "unit.h" +#include "../unit.h" namespace config { +using namespace unit; + /// Axis configuration data struct AxisConfig { bool dirOn; ///< direction ON state (for inversion) diff --git a/src/config/unit.h b/src/unit.h similarity index 54% rename from src/config/unit.h rename to src/unit.h index c855934..f6a8f92 100644 --- a/src/config/unit.h +++ b/src/unit.h @@ -1,28 +1,27 @@ #pragma once #include -// In this header we introduce a minimal Unit class that can be used for conformability, -// type checking and conversion at compile time. Template parameters are abused to create -// unique types, which then can go through (explicit) overload and conversion. Despite -// looking daunting, usage is quite straightforward once the appropriate aliases and -// inline operators are defined: -// -// U_mm distance = 10.0_mm; -// auto another = 20.5_mm; -// auto sum = distance + another; -// -// auto angle = 15.0_deg; -// auto test = distance + angle; // compile time error -// -// Template parameters are only used for type checking. The Unit contains a single value -// Unit::v and is thus well suited for parameter passing and inline initialization. -// -// Conversion to physical steps is done in modules::motion through the sister class -// AxisUnit, which also ensures quantities from different axes are not mixed together. -// AxisUnit are the normal units that should be used at runtime, which is why physical -// units and operators are not exported into the global namespace by default. - -namespace config { +/// Introduce a minimal Unit class that can be used for conformability, type checking and +/// conversion at compile time. Template parameters are abused to create unique types, +/// which then can go through (explicit) overload and conversion. Despite looking +/// daunting, usage is quite straightforward once the appropriate aliases and inline +/// operators are defined: +/// +/// U_mm distance = 10.0_mm; +/// auto another = 20.5_mm; +/// auto sum = distance + another; +/// +/// auto angle = 15.0_deg; +/// auto test = distance + angle; // compile time error +/// +/// Template parameters are only used for type checking. The Unit contains a single value +/// Unit::v and is thus well suited for parameter passing and inline initialization. +/// +/// Conversion to physical steps is done in modules::motion through the sister class +/// AxisUnit, which also ensures quantities from different axes are not mixed together. +/// AxisUnit are the normal units that should be used at runtime, which is why physical +/// units and operators are not exported into the global namespace by default. +namespace unit { /// Base units for conformability testing enum UnitBase : uint8_t { @@ -86,4 +85,12 @@ static constexpr U_deg_s2 operator"" _deg_s2(long double deg_s2) { return { deg_s2 }; } -} // namespace config +} // namespace unit + +// Inject literal operators into the global namespace for convenience +using unit::operator"" _mm; +using unit::operator"" _mm_s; +using unit::operator"" _mm_s2; +using unit::operator"" _deg; +using unit::operator"" _deg_s; +using unit::operator"" _deg_s2;