Skyward boardcore
Loading...
Searching...
No Matches
Length.h
Go to the documentation of this file.
1/* Copyright (c) 2023 Skyward Experimental Rocketry
2 * Author: Davide Basso
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a copy
5 * of this software and associated documentation files (the "Software"), to deal
6 * in the Software without restriction, including without limitation the rights
7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 * copies of the Software, and to permit persons to whom the Software is
9 * furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
13 *
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20 * THE SOFTWARE.
21 */
22
23#pragma once
24
25#include <ratio>
26
27#include "Units.h"
28
29namespace Boardcore
30{
31namespace Units
32{
33namespace Length
34{
35
36template <class Ratio = std::ratio<1>>
37using Length = Unit<UnitKind::Length, Ratio>;
38
39template <class ToLength, class FromLength>
40ToLength length_cast(FromLength const& from)
41{
42 return ToLength(from);
43}
44
45using Millimeter = Length<std::milli>; // Length in millimeters
46using Centimeter = Length<std::centi>; // Length in centimeters
47using Decimeter = Length<std::deci>; // Length in decimeters
48using Meter = Length<>; // Length in meters
49using Kilometer = Length<std::kilo>; // Length in kilometers
50
51// Floats
52constexpr auto operator""_mm(long double n)
53{
54 return Millimeter(static_cast<float>(n));
55};
56constexpr auto operator""_cm(long double n)
57{
58 return Centimeter(static_cast<float>(n));
59};
60constexpr auto operator""_dm(long double n)
61{
62 return Decimeter(static_cast<float>(n));
63};
64constexpr auto operator""_m(long double n)
65{
66 return Meter(static_cast<float>(n));
67};
68constexpr auto operator""_km(long double n)
69{
70 return Kilometer(static_cast<float>(n));
71};
72// Integers
73constexpr auto operator""_mm(unsigned long long n)
74{
75 return Millimeter(static_cast<float>(n));
76};
77constexpr auto operator""_cm(unsigned long long n)
78{
79 return Centimeter(static_cast<float>(n));
80};
81constexpr auto operator""_dm(unsigned long long n)
82{
83 return Decimeter(static_cast<float>(n));
84};
85constexpr auto operator""_m(unsigned long long n)
86{
87 return Meter(static_cast<float>(n));
88};
89constexpr auto operator""_km(unsigned long long n)
90{
91 return Kilometer(static_cast<float>(n));
92};
93
94} // namespace Length
95} // namespace Units
96} // namespace Boardcore
Length< std::centi > Centimeter
Definition Length.h:46
Length< std::kilo > Kilometer
Definition Length.h:49
Unit< UnitKind::Length, Ratio > Length
Definition Length.h:37
ToLength length_cast(FromLength const &from)
Definition Length.h:40
Length< std::deci > Decimeter
Definition Length.h:47
Length< std::milli > Millimeter
Definition Length.h:45
This file includes all the types the logdecoder script will decode.