LightLib
PROS library for VEX V5: EKF/MCL localization, RAMSETE path following, high-level chassis API
Loading...
Searching...
No Matches
RQuantityName.hpp
Go to the documentation of this file.
4#include <stdexcept>
5#include <typeindex>
6#include <unordered_map>
7
8#pragma once
9
10namespace okapi {
11
20template <class QType> std::string getShortUnitName(QType q) {
21 const std::unordered_map<std::type_index, std::unordered_map<double, const char *>> shortNameMap =
22 {{typeid(meter),
23 {
24 {meter.getValue(), "m"},
25 {decimeter.getValue(), "dm"},
26 {centimeter.getValue(), "cm"},
27 {millimeter.getValue(), "mm"},
28 {kilometer.getValue(), "km"},
29 {inch.getValue(), "in"},
30 {foot.getValue(), "ft"},
31 {yard.getValue(), "yd"},
32 {mile.getValue(), "mi"},
33 {tile.getValue(), "tile"},
34 }},
35 {typeid(degree), {{degree.getValue(), "deg"}, {radian.getValue(), "rad"}}}};
36
37 try {
38 return shortNameMap.at(typeid(q)).at(q.getValue());
39 } catch (const std::out_of_range &e) {
40 throw std::domain_error(
41 "You have requested the shortname of an unknown unit somewhere (likely odometry strings). "
42 "Shortname for provided unit is unspecified. You can override this function to add more "
43 "names or manually specify the name instead.");
44 }
45}
46} // namespace okapi
constexpr QLength kilometer
Definition QLength.hpp:21
constexpr QLength tile
Definition QLength.hpp:26
constexpr QLength yard
Definition QLength.hpp:24
std::string getShortUnitName(QType q)
Returns a short name for a unit.
constexpr QAngle radian(1.0)
constexpr QLength meter(1.0)
constexpr QAngle degree
Definition QAngle.hpp:19
constexpr QLength foot
Definition QLength.hpp:23
constexpr QLength inch
Definition QLength.hpp:22
constexpr QLength centimeter
Definition QLength.hpp:19
constexpr QLength millimeter
Definition QLength.hpp:20
constexpr QLength mile
Definition QLength.hpp:25
constexpr QLength decimeter
Definition QLength.hpp:18