diff --git a/src/systems/data/include/units/data/bitrate.h b/src/systems/data/include/units/data/bitrate.h index 5e871443..19c3ab6e 100644 --- a/src/systems/data/include/units/data/bitrate.h +++ b/src/systems/data/include/units/data/bitrate.h @@ -38,6 +38,12 @@ struct gibibit_per_second : deduced_unit {}; struct pebibit_per_second : deduced_unit {}; +struct kilobit_per_second : deduced_unit {}; +struct megabit_per_second : deduced_unit {}; +struct gigabit_per_second : deduced_unit {}; +struct terabit_per_second : deduced_unit {}; +struct petabit_per_second : deduced_unit {}; + template concept Bitrate = QuantityOf; @@ -54,6 +60,12 @@ constexpr auto operator"" _q_Gib_per_s(unsigned long long l) { gsl_ExpectsAudit( constexpr auto operator"" _q_Tib_per_s(unsigned long long l) { gsl_ExpectsAudit(std::in_range(l)); return bitrate(static_cast(l)); } constexpr auto operator"" _q_Pib_per_s(unsigned long long l) { gsl_ExpectsAudit(std::in_range(l)); return bitrate(static_cast(l)); } +constexpr auto operator"" _q_kb_per_s(unsigned long long l) { gsl_ExpectsAudit(std::in_range(l)); return bitrate(static_cast(l)); } +constexpr auto operator"" _q_Mb_per_s(unsigned long long l) { gsl_ExpectsAudit(std::in_range(l)); return bitrate(static_cast(l)); } +constexpr auto operator"" _q_Gb_per_s(unsigned long long l) { gsl_ExpectsAudit(std::in_range(l)); return bitrate(static_cast(l)); } +constexpr auto operator"" _q_Tb_per_s(unsigned long long l) { gsl_ExpectsAudit(std::in_range(l)); return bitrate(static_cast(l)); } +constexpr auto operator"" _q_Pb_per_s(unsigned long long l) { gsl_ExpectsAudit(std::in_range(l)); return bitrate(static_cast(l)); } + } // namespace literals namespace references { @@ -65,6 +77,12 @@ inline constexpr auto Gib_per_s = reference{}; inline constexpr auto Tib_per_s = reference{}; inline constexpr auto Pib_per_s = reference{}; +inline constexpr auto kb_per_s = reference{}; +inline constexpr auto Mb_per_s = reference{}; +inline constexpr auto Gb_per_s = reference{}; +inline constexpr auto Tb_per_s = reference{}; +inline constexpr auto Pb_per_s = reference{}; + } // namespace references } // namespace units::data diff --git a/src/systems/data/include/units/data/information.h b/src/systems/data/include/units/data/information.h index 47de34a4..6850a7bd 100644 --- a/src/systems/data/include/units/data/information.h +++ b/src/systems/data/include/units/data/information.h @@ -24,6 +24,7 @@ #include #include +#include #include #include #include @@ -37,6 +38,13 @@ struct gibibit : prefixed_unit {}; struct tebibit : prefixed_unit {}; struct pebibit : prefixed_unit {}; +struct si_bit : alias_unit {}; +struct kilobit : prefixed_unit {}; +struct megabit : prefixed_unit {}; +struct gigabit : prefixed_unit {}; +struct terabit : prefixed_unit {}; +struct petabit : prefixed_unit {}; + struct byte : named_scaled_unit {}; struct kibibyte : prefixed_unit {}; struct mebibyte : prefixed_unit {}; @@ -62,6 +70,13 @@ constexpr auto operator"" _q_Gib(unsigned long long l) { gsl_ExpectsAudit(std::i constexpr auto operator"" _q_Tib(unsigned long long l) { gsl_ExpectsAudit(std::in_range(l)); return information(static_cast(l)); } constexpr auto operator"" _q_Pib(unsigned long long l) { gsl_ExpectsAudit(std::in_range(l)); return information(static_cast(l)); } +// bits (SI) +constexpr auto operator"" _q_kb(unsigned long long l) { gsl_ExpectsAudit(std::in_range(l)); return information(static_cast(l)); } +constexpr auto operator"" _q_Mb(unsigned long long l) { gsl_ExpectsAudit(std::in_range(l)); return information(static_cast(l)); } +constexpr auto operator"" _q_Gb(unsigned long long l) { gsl_ExpectsAudit(std::in_range(l)); return information(static_cast(l)); } +constexpr auto operator"" _q_Tb(unsigned long long l) { gsl_ExpectsAudit(std::in_range(l)); return information(static_cast(l)); } +constexpr auto operator"" _q_Pb(unsigned long long l) { gsl_ExpectsAudit(std::in_range(l)); return information(static_cast(l)); } + // bytes constexpr auto operator"" _q_B(unsigned long long l) { gsl_ExpectsAudit(std::in_range(l)); return information(static_cast(l)); } constexpr auto operator"" _q_KiB(unsigned long long l) { gsl_ExpectsAudit(std::in_range(l)); return information(static_cast(l)); } @@ -75,12 +90,19 @@ constexpr auto operator"" _q_PiB(unsigned long long l) { gsl_ExpectsAudit(std::i namespace references { inline constexpr auto b = reference{}; + inline constexpr auto Kib = reference{}; inline constexpr auto Mib = reference{}; inline constexpr auto Gib = reference{}; inline constexpr auto Tib = reference{}; inline constexpr auto Pib = reference{}; +inline constexpr auto kb = reference{}; +inline constexpr auto Mb = reference{}; +inline constexpr auto Gb = reference{}; +inline constexpr auto Tb = reference{}; +inline constexpr auto Pb = reference{}; + inline constexpr auto B = reference{}; inline constexpr auto KiB = reference{}; inline constexpr auto MiB = reference{}; diff --git a/test/unit_test/runtime/digital_info_test.cpp b/test/unit_test/runtime/digital_info_test.cpp index d1f269dc..deb6ef01 100644 --- a/test/unit_test/runtime/digital_info_test.cpp +++ b/test/unit_test/runtime/digital_info_test.cpp @@ -56,5 +56,9 @@ TEST_CASE("operator<< on a data quantity", "[text][ostream]") stream << 8_q_Kib * 8_q_Kib / 2_q_b; REQUIRE(stream.str() == "32 Mib"); } + SECTION("prefixed coherent unit (SI)") { + stream << 32_q_kb; + REQUIRE(stream.str() == "32 kb"); + } } } diff --git a/test/unit_test/static/data_test.cpp b/test/unit_test/static/data_test.cpp index 45ba9bed..4a333ae5 100644 --- a/test/unit_test/static/data_test.cpp +++ b/test/unit_test/static/data_test.cpp @@ -36,6 +36,9 @@ static_assert(1024_q_B == 1_q_KiB); static_assert(8 * 1024_q_b == 1_q_KiB); static_assert(8 * 1_q_Kib == 1_q_KiB); +static_assert(1_q_kb == 1000_q_b); +static_assert(2000_q_Mib == 2097152_q_kb); + static_assert(1_q_Kib == 1024_q_b); static_assert(1_q_Mib == 1024_q_Kib); static_assert(1_q_Gib == 1024_q_Mib);