ActiveLib
Loading...
Searching...
No Matches
MassUnit.h
1
6#ifndef ACTIVE_MEASURE_MASS_UNIT
7#define ACTIVE_MEASURE_MASS_UNIT
8
9#include "Active/Setting/Values/Measurement/Units/Unit.h"
10
11namespace active::measure {
12
14 enum class MassType : char {
15 milligram,
16 gram,
17 kilogram,
18 tonne,
19 ounce,
20 pound,
21 stone,
22 ton,
23 };
24
25
29 struct MassUnit : public Unit<MassUnit, MassType> {
30
31 using Type = MassType;
32
33 using enum MassType;
34
35 // MARK: - Static functions
36
37 //Get unit for grams
38 static MassUnit grams(uint8_t prec = 1, bool suffixes = true) { return MassUnit{gram, prec, true, suffixes}; }
39 //Get unit for kilograms
40 static MassUnit kilograms(uint8_t prec = 4, bool suffixes = true) { return MassUnit{kilogram, prec, true, suffixes}; }
41 //Get unit for pounds
42 static MassUnit pounds(uint8_t prec = 4, bool suffixes = true) { return MassUnit{pound, prec, true, suffixes}; }
43
44 // MARK: - Constructors
45
53 MassUnit() : Unit{kilogram} {} //Default to kilograms - can be overridden as required
61 MassUnit(MassType type, uint8_t prec, bool isDecimal = true, bool suffixes = true) :
62 Unit{type, prec, isDecimal, suffixes} {}
70 MassUnit(MassType first, MassType second, uint8_t prec, bool isDecimal = true) :
71 Unit{first, second, prec, isDecimal} {}
72
73 private:
74#ifdef WINDOWS
75 friend typename Unit;
76#else
77 friend struct Unit;
78#endif
79
80 // MARK: Unit constants
81
83 constexpr static int massCount = static_cast<int>(ton) + 1;
84
85 static std::array<const char*, massCount> tags;
86 static std::array<const char*, massCount> abbreviations;
87 static std::array<double, massCount> conversions;
88 static std::array<bool, massCount> metric;
89 };
90
91}
92
93#endif //ACTIVE_MEASURE_MASS_UNIT
Definition AngleUnit.cpp:14
MassType
Enumeration of known mass measurement units.
Definition MassUnit.h:14
Definition MassUnit.h:29
MassUnit(MassType type, uint8_t prec, bool isDecimal=true, bool suffixes=true)
Definition MassUnit.h:61
MassUnit(MassType first, MassType second, uint8_t prec, bool isDecimal=true)
Definition MassUnit.h:70
MassUnit()
Definition MassUnit.h:53
Definition Unit.h:35
bool isDecimal() const
Definition Unit.h:102