ActiveLib
Loading...
Searching...
No Matches
AreaUnit.h
1
6#ifndef ACTIVE_MEASURE_AREA_UNIT
7#define ACTIVE_MEASURE_AREA_UNIT
8
9#include "Active/Setting/Values/Measurement/Units/Unit.h"
10
11namespace active::measure {
12
14 enum class AreaType : char {
15 millimetreSquare,
16 centimetreSquare,
17 metreSquare,
18 are,
19 hectare,
20 inchSquare,
21 footSquare,
22 yardSquare,
23 mileSquare,
24 };
25
26
30 struct AreaUnit : public Unit<AreaUnit, AreaType> {
31
32 using Type = AreaType;
33
34 using enum AreaType;
35
36 // MARK: - Static functions
37
38 //Get unit for square metres
39 static AreaUnit metresSquare(uint8_t prec = 6, bool suffixes = true) { return AreaUnit{metreSquare, prec, true, suffixes}; }
40 //Get unit for hectares
41 static AreaUnit hectares(uint8_t prec = 2, bool suffixes = true) { return AreaUnit{hectare, prec, true, suffixes}; }
42 //Get unit for square feet
43 static AreaUnit feetSquare(uint8_t prec = 5, bool suffixes = true) { return AreaUnit{footSquare, prec, true, suffixes}; }
44
45 // MARK: - Constructors
46
50 AreaUnit() : Unit{metreSquare} {} //Default to square metres - can be overridden as required
58 AreaUnit(AreaType type, uint8_t prec, bool isDecimal = true, bool suffixes = true) :
59 Unit{type, prec, isDecimal, suffixes} {}
60
61 private:
62#ifdef WINDOWS
63 friend typename Unit;
64#else
65 friend struct Unit;
66#endif
67
68 // MARK: Unit constants
69
71 constexpr static int areaCount = static_cast<int>(mileSquare) + 1;
72
73 static std::array<const char*, areaCount> tags;
74 static std::array<const char*, areaCount> abbreviations;
75 static std::array<double, areaCount> conversions;
76 static std::array<bool, areaCount> metric;
77 };
78
79}
80
81#endif //ACTIVE_MEASURE_AREA_UNIT
Definition AngleUnit.cpp:14
AreaType
Enumeration of known area measurement units.
Definition AreaUnit.h:14
Definition AreaUnit.h:30
AreaUnit()
Definition AreaUnit.h:50
AreaUnit(AreaType type, uint8_t prec, bool isDecimal=true, bool suffixes=true)
Definition AreaUnit.h:58
Definition Unit.h:35
bool isDecimal() const
Definition Unit.h:102