ActiveLib
Loading...
Searching...
No Matches
LengthUnit.h
1
6#ifndef ACTIVE_MEASURE_LENGTH_UNIT
7#define ACTIVE_MEASURE_LENGTH_UNIT
8
9#include "Active/Setting/Values/Measurement/Units/Unit.h"
10
11namespace active::measure {
12
13 // MARK: - Types
14
16 enum class LengthType : char {
17 millimetre,
18 centimetre,
19 metre,
20 kilometre,
21 inch,
22 foot,
23 yard,
24 mile,
25 };
26
27 // MARK: - Constructors
28
32 struct LengthUnit : public Unit<LengthUnit, LengthType> {
33
34 using Type = LengthType;
35
36 using enum LengthType;
37
38 // MARK: - Static functions
39
40 //Get unit for millimetres
41 static LengthUnit millimetres(uint8_t prec = 1, bool suffixes = true) { return LengthUnit{millimetre, prec, true, suffixes}; }
42 //Get unit for centimetres
43 static LengthUnit centimetres(uint8_t prec = 2, bool suffixes = true) { return LengthUnit{centimetre, prec, true, suffixes}; }
44 //Get unit for metres
45 static LengthUnit metres(uint8_t prec = 4, bool suffixes = true) { return LengthUnit{metre, prec, true, suffixes}; }
46 //Get unit for decimal inches
47 static LengthUnit decimalInches(uint8_t prec = 3, bool suffixes = true) { return LengthUnit{inch, prec, true, suffixes}; }
48 //Get unit for decimal feet
49 static LengthUnit decimalFeet(uint8_t prec = 4, bool suffixes = true) { return LengthUnit{foot, prec, true, suffixes}; }
50 //Get unit for feet & decimal inches
51 static LengthUnit feetDecInches(uint8_t prec = 3) { return LengthUnit{foot, inch, prec, true}; }
52 //Get unit for feet & fractional inches
53 static LengthUnit feetFracInches(uint8_t prec = 6) { return LengthUnit{foot, inch, prec, false}; }
54
55 // MARK: - Constructors
56
60 LengthUnit() : Unit{metre} {} //Default to metres - can be overridden as required
68 LengthUnit(LengthType type, uint8_t prec, bool isDecimal = true, bool suffixes = true) :
69 Unit{type, prec, isDecimal, suffixes} {}
77 LengthUnit(LengthType first, LengthType second, uint8_t prec, bool isDecimal = true) :
78 Unit{first, second, prec, isDecimal} {}
79
80 private:
81#ifdef WINDOWS
82 friend typename Unit;
83#else
84 friend struct Unit;
85#endif
86
87 // MARK: Unit constants
88
90 constexpr static int lengthCount = static_cast<int>(mile) + 1;
91
92 static std::array<const char*, lengthCount> tags;
93 static std::array<const char*, lengthCount> abbreviations;
94 static std::array<double, lengthCount> conversions;
95 static std::array<bool, lengthCount> metric;
96 };
97
98}
99
100#endif //ACTIVE_MEASURE_LENGTH_UNIT
Definition AngleUnit.cpp:14
LengthType
Enumeration of known length measurement units.
Definition LengthUnit.h:16
Definition LengthUnit.h:32
LengthUnit(LengthType type, uint8_t prec, bool isDecimal=true, bool suffixes=true)
Definition LengthUnit.h:68
LengthUnit()
Definition LengthUnit.h:60
LengthUnit(LengthType first, LengthType second, uint8_t prec, bool isDecimal=true)
Definition LengthUnit.h:77
Definition Unit.h:35
bool isDecimal() const
Definition Unit.h:102