Move config/unit.h to unit.h and it's own namespace

pull/71/head
Yuri D'Elia 2021-07-25 22:14:56 +02:00
parent 49275b2cb2
commit 187858d228
2 changed files with 33 additions and 24 deletions

View File

@ -1,9 +1,11 @@
#pragma once #pragma once
#include <stdint.h> #include <stdint.h>
#include "unit.h" #include "../unit.h"
namespace config { namespace config {
using namespace unit;
/// Axis configuration data /// Axis configuration data
struct AxisConfig { struct AxisConfig {
bool dirOn; ///< direction ON state (for inversion) bool dirOn; ///< direction ON state (for inversion)

View File

@ -1,28 +1,27 @@
#pragma once #pragma once
#include <stdint.h> #include <stdint.h>
// In this header we introduce a minimal Unit class that can be used for conformability, /// Introduce a minimal Unit class that can be used for conformability, type checking and
// type checking and conversion at compile time. Template parameters are abused to create /// conversion at compile time. Template parameters are abused to create unique types,
// unique types, which then can go through (explicit) overload and conversion. Despite /// which then can go through (explicit) overload and conversion. Despite looking
// looking daunting, usage is quite straightforward once the appropriate aliases and /// daunting, usage is quite straightforward once the appropriate aliases and inline
// inline operators are defined: /// operators are defined:
// ///
// U_mm distance = 10.0_mm; /// U_mm distance = 10.0_mm;
// auto another = 20.5_mm; /// auto another = 20.5_mm;
// auto sum = distance + another; /// auto sum = distance + another;
// ///
// auto angle = 15.0_deg; /// auto angle = 15.0_deg;
// auto test = distance + angle; // compile time error /// auto test = distance + angle; // compile time error
// ///
// Template parameters are only used for type checking. The Unit contains a single value /// Template parameters are only used for type checking. The Unit contains a single value
// Unit<T>::v and is thus well suited for parameter passing and inline initialization. /// Unit<T>::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 /// 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, 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 /// 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. /// units and operators are not exported into the global namespace by default.
namespace unit {
namespace config {
/// Base units for conformability testing /// Base units for conformability testing
enum UnitBase : uint8_t { enum UnitBase : uint8_t {
@ -86,4 +85,12 @@ static constexpr U_deg_s2 operator"" _deg_s2(long double deg_s2) {
return { 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;