diff --git a/src/systems/data/include/units/data/data.h b/src/systems/data/include/units/data/data.h index 357edbea..22cdaf1a 100644 --- a/src/systems/data/include/units/data/data.h +++ b/src/systems/data/include/units/data/data.h @@ -24,4 +24,5 @@ #include #include +#include #include diff --git a/src/systems/data/include/units/data/symbolrate.h b/src/systems/data/include/units/data/symbolrate.h new file mode 100644 index 00000000..bbd1b92f --- /dev/null +++ b/src/systems/data/include/units/data/symbolrate.h @@ -0,0 +1,62 @@ +// The MIT License (MIT) +// +// Copyright (c) 2021 Christoph Seitz +// +// 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 +#include + +namespace units::data { + +struct baud : alias_unit {}; +struct kilobaud : prefixed_alias_unit {}; +struct megabaud : prefixed_alias_unit {}; +struct gigabaud : prefixed_alias_unit {}; +struct terabaud : prefixed_alias_unit {}; +struct petabaud : prefixed_alias_unit {}; + +template U, QuantityValue Rep = double> +using symbolrate = quantity; + +inline namespace literals { + +constexpr auto operator"" _q_Bd(unsigned long long l) { gsl_ExpectsAudit(std::in_range(l)); return symbolrate(static_cast(l)); } +constexpr auto operator"" _q_kBd(unsigned long long l) { gsl_ExpectsAudit(std::in_range(l)); return symbolrate(static_cast(l)); } +constexpr auto operator"" _q_MBd(unsigned long long l) { gsl_ExpectsAudit(std::in_range(l)); return symbolrate(static_cast(l)); } +constexpr auto operator"" _q_GBd(unsigned long long l) { gsl_ExpectsAudit(std::in_range(l)); return symbolrate(static_cast(l)); } +constexpr auto operator"" _q_TBd(unsigned long long l) { gsl_ExpectsAudit(std::in_range(l)); return symbolrate(static_cast(l)); } +constexpr auto operator"" _q_PBd(unsigned long long l) { gsl_ExpectsAudit(std::in_range(l)); return symbolrate(static_cast(l)); } + +} // namespace literals + +namespace references { + +inline constexpr auto Bd = reference{}; +inline constexpr auto kBd = reference{}; +inline constexpr auto MBd = reference{}; +inline constexpr auto GBd = reference{}; +inline constexpr auto TBd = reference{}; +inline constexpr auto PBd = reference{}; + +} // namespace references + +} // namespace units::data diff --git a/test/unit_test/runtime/digital_info_test.cpp b/test/unit_test/runtime/digital_info_test.cpp index deb6ef01..6cd0779a 100644 --- a/test/unit_test/runtime/digital_info_test.cpp +++ b/test/unit_test/runtime/digital_info_test.cpp @@ -20,9 +20,10 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // SOFTWARE. -#include -#include #include +#include +#include +#include #include using namespace units::data; @@ -62,3 +63,15 @@ TEST_CASE("operator<< on a data quantity", "[text][ostream]") } } } + +TEST_CASE("fmt::format on data unit symbols", "[text][fmt]") +{ + SECTION("symbolrate") + { + CHECK(fmt::format("{}", 1_q_Bd) == "1 Bd"); + CHECK(fmt::format("{}", 1_q_kBd) == "1 kBd"); + CHECK(fmt::format("{}", 1_q_MBd) == "1 MBd"); + CHECK(fmt::format("{}", 1_q_GBd) == "1 GBd"); + CHECK(fmt::format("{}", 1_q_TBd) == "1 TBd"); + } +}