Initial version

This commit is contained in:
Mateusz Pusz committed 2018-08-22 12:11:19 +02:00
commit 4b376e3c2e
25 files changed
+1927

No files matched your search

+38
View File
@@ -0,0 +1,38 @@
// The MIT License (MIT)
//
// Copyright (c) 2018 Mateusz Pusz
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
#pragma once
#include "../dimension.h"
#include "../quantity.h"
namespace units {
struct base_dim_length : dim_id<0> {};
struct base_dim_mass : dim_id<1> {};
struct base_dim_time : dim_id<2> {};
struct base_dim_electric_current : dim_id<3> {};
struct base_dim_temperature : dim_id<4> {};
struct base_dim_amount_of_substance : dim_id<5> {};
struct base_dim_luminous_intensity : dim_id<6> {};
} // namespace units
+83
View File
@@ -0,0 +1,83 @@
// The MIT License (MIT)
//
// Copyright (c) 2018 Mateusz Pusz
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
#pragma once
#include "base_dimensions.h"
#include "time.h"
namespace units {
using dimension_frequency = make_dimension_t<exp<base_dim_time, -1>>;
template<typename Rep, class Ratio = std::ratio<1>>
using frequency = quantity<dimension_frequency, Rep, Ratio>;
template<typename Rep>
using millihertzs = frequency<Rep, std::milli>;
template<typename Rep>
using hertzs = frequency<Rep>;
template<typename Rep>
using kilohertzs = frequency<Rep, std::kilo>;
template<typename Rep>
using megahertzs = frequency<Rep, std::mega>;
template<typename Rep>
using gigahertzs = frequency<Rep, std::giga>;
template<typename Rep>
using terahertzs = frequency<Rep, std::tera>;
// ...
namespace literals {
// mHz
constexpr auto operator""_mHz(unsigned long long l) { return millihertzs<std::int64_t>(l); }
constexpr auto operator""_mHz(long double l) { return millihertzs<long double>(l); }
// Hz
constexpr auto operator""_Hz(unsigned long long l) { return hertzs<std::int64_t>(l); }
constexpr auto operator""_Hz(long double l) { return hertzs<long double>(l); }
// kHz
constexpr auto operator""_kHz(unsigned long long l) { return kilohertzs<std::int64_t>(l); }
constexpr auto operator""_kHz(long double l) { return kilohertzs<long double>(l); }
// MHz
constexpr auto operator""_MHz(unsigned long long l) { return megahertzs<std::int64_t>(l); }
constexpr auto operator""_MHz(long double l) { return megahertzs<long double>(l); }
// GHz
constexpr auto operator""_GHz(unsigned long long l) { return gigahertzs<std::int64_t>(l); }
constexpr auto operator""_GHz(long double l) { return gigahertzs<long double>(l); }
// THz
constexpr auto operator""_THz(unsigned long long l) { return terahertzs<std::int64_t>(l); }
constexpr auto operator""_THz(long double l) { return terahertzs<long double>(l); }
} // namespace literals
} // namespace units
+61
View File
@@ -0,0 +1,61 @@
// The MIT License (MIT)
//
// Copyright (c) 2018 Mateusz Pusz
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
#pragma once
#include "base_dimensions.h"
namespace units {
using dimension_length = make_dimension_t<exp<base_dim_length, 1>>;
template<typename Rep, class Ratio = std::ratio<1>>
using length = quantity<dimension_length, Rep, Ratio>;
template<typename Rep>
using millimeters = length<Rep, std::milli>;
template<typename Rep>
using meters = length<Rep>;
template<typename Rep>
using kilometers = length<Rep, std::kilo>;
// ...
namespace literals {
// mm
constexpr auto operator""_mm(unsigned long long l) { return millimeters<std::int64_t>(l); }
constexpr auto operator""_mm(long double l) { return millimeters<long double>(l); }
// m
constexpr auto operator""_m(unsigned long long l) { return meters<std::int64_t>(l); }
constexpr auto operator""_m(long double l) { return meters<long double>(l); }
// km
constexpr auto operator""_km(unsigned long long l) { return kilometers<std::int64_t>(l); }
constexpr auto operator""_km(long double l) { return kilometers<long double>(l); }
} // namespace literals
} // namespace units
+82
View File
@@ -0,0 +1,82 @@
// The MIT License (MIT)
//
// Copyright (c) 2018 Mateusz Pusz
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
#pragma once
#include "base_dimensions.h"
namespace units {
using dimension_time = make_dimension_t<exp<base_dim_time, 1>>;
template<typename Rep, class Ratio = std::ratio<1>>
using time = quantity<dimension_time, Rep, Ratio>;
template<typename Rep>
using nanoseconds = time<Rep, std::nano>;
template<typename Rep>
using microseconds = time<Rep, std::micro>;
template<typename Rep>
using milliseconds = time<Rep, std::milli>;
template<typename Rep>
using seconds = time<Rep>;
template<typename Rep>
using minutes = time<Rep, std::ratio<60>>;
template<typename Rep>
using hours = time<Rep, std::ratio<3600>>;
// ...
namespace literals {
// ns
constexpr auto operator""_ns(unsigned long long l) { return nanoseconds<std::int64_t>(l); }
constexpr auto operator""_ns(long double l) { return nanoseconds<long double>(l); }
// us
constexpr auto operator""_us(unsigned long long l) { return microseconds<std::int64_t>(l); }
constexpr auto operator""_us(long double l) { return microseconds<long double>(l); }
// ms
constexpr auto operator""_ms(unsigned long long l) { return milliseconds<std::int64_t>(l); }
constexpr auto operator""_ms(long double l) { return milliseconds<long double>(l); }
// s
constexpr auto operator""_s(unsigned long long l) { return seconds<std::int64_t>(l); }
constexpr auto operator""_s(long double l) { return seconds<long double>(l); }
// min
constexpr auto operator""_min(unsigned long long l) { return minutes<std::int64_t>(l); }
constexpr auto operator""_min(long double l) { return minutes<long double>(l); }
// h
constexpr auto operator""_h(unsigned long long l) { return hours<std::int64_t>(l); }
constexpr auto operator""_h(long double l) { return hours<long double>(l); }
} // namespace literals
} // namespace units
+63
View File
@@ -0,0 +1,63 @@
// The MIT License (MIT)
//
// Copyright (c) 2018 Mateusz Pusz
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
#pragma once
#include "base_dimensions.h"
#include "length.h"
#include "time.h"
namespace units {
using dimension_velocity = make_dimension_t<exp<base_dim_length, 1>, exp<base_dim_time, -1>>;
template<typename Rep, class Ratio = std::ratio<1>>
using velocity = quantity<dimension_velocity, Rep, Ratio>;
template<typename Rep>
using meters_per_second = velocity<Rep>;
template<typename Rep>
using kilometers_per_hour = velocity<Rep, std::ratio<1000, 3600>>;
template<typename Rep>
using miles_per_hour = velocity<Rep, std::ratio<44'704, 100'000>>;
// ...
namespace literals {
// mps
constexpr auto operator""_mps(unsigned long long l) { return meters_per_second<std::int64_t>(l); }
constexpr auto operator""_mps(long double l) { return meters_per_second<long double>(l); }
// kmph
constexpr auto operator""_kmph(unsigned long long l) { return kilometers_per_hour<std::int64_t>(l); }
constexpr auto operator""_kmph(long double l) { return kilometers_per_hour<long double>(l); }
// mph
constexpr auto operator""_mph(unsigned long long l) { return miles_per_hour<std::int64_t>(l); }
constexpr auto operator""_mph(long double l) { return miles_per_hour<long double>(l); }
} // namespace literals
} // namespace units