From 981b89b8816850c871a1715b6be2be63a9c1d9a0 Mon Sep 17 00:00:00 2001 From: WHR Date: Tue, 24 May 2022 02:23:35 +0000 Subject: [PATCH] Add units TiBit, TiByte, PiBit, PiByte, TBit, TByte, PBit and PByte Fix https://github.com/rolandriegel/nload/issues/13/ --- src/app.cpp | 47 +++++++++++++++++++++++++++++++++++++++------- src/statistics.cpp | 28 +++++++++++++++++++++++++-- src/statistics.h | 32 +++++++++++++++++++------------ 3 files changed, 86 insertions(+), 21 deletions(-) diff --git a/src/app.cpp b/src/app.cpp index 968cf76..3e20211 100644 --- a/src/app.cpp +++ b/src/app.cpp @@ -92,12 +92,20 @@ App::App() valueMapping[toString(Statistics::mebiByte)] = "MiByte"; valueMapping[toString(Statistics::gibiBit)] = "GiBit"; valueMapping[toString(Statistics::gibiByte)] = "GiByte"; + valueMapping[toString(Statistics::tebiBit)] = "TiBit"; + valueMapping[toString(Statistics::tebiByte)] = "TiByte"; + valueMapping[toString(Statistics::pebiBit)] = "PiBit"; + valueMapping[toString(Statistics::pebiByte)] = "PiByte"; valueMapping[toString(Statistics::kiloBit)] = "kBit"; valueMapping[toString(Statistics::kiloByte)] = "kByte"; valueMapping[toString(Statistics::megaBit)] = "MBit"; valueMapping[toString(Statistics::megaByte)] = "MByte"; valueMapping[toString(Statistics::gigaBit)] = "GBit"; valueMapping[toString(Statistics::gigaByte)] = "GByte"; + valueMapping[toString(Statistics::teraBit)] = "TBit"; + valueMapping[toString(Statistics::teraByte)] = "TByte"; + valueMapping[toString(Statistics::petaBit)] = "PBit"; + valueMapping[toString(Statistics::petaByte)] = "PByte"; SettingStore::get("TrafficFormat").pushFilter(new SettingFilterMap(valueMapping)); SettingStore::get("DataFormat").pushFilter(new SettingFilterMap(valueMapping)); valueMapping.clear(); @@ -252,6 +260,18 @@ int App::run(const vector& arguments) case 'g': setting = Statistics::gibiBit; break; + case 'T': + setting = Statistics::tebiByte; + break; + case 't': + setting = Statistics::tebiBit; + break; + case 'P': + setting = Statistics::pebiByte; + break; + case 'p': + setting = Statistics::pebiBit; + break; default: printHelpAndExit = true; break; @@ -290,6 +310,18 @@ int App::run(const vector& arguments) case Statistics::gibiByte: setting = Statistics::gigaByte; break; + case Statistics::tebiBit: + setting = Statistics::teraBit; + break; + case Statistics::tebiByte: + setting = Statistics::teraByte; + break; + case Statistics::pebiBit: + setting = Statistics::petaBit; + break; + case Statistics::pebiByte: + setting = Statistics::petaByte; + break; } break; default: @@ -510,14 +542,15 @@ void App::printHelp(bool error) << " Default is " << STANDARD_MAX_DEFLECTION << ".\n" << "-t Determines the refresh interval of the display in milliseconds.\n" << " Default is " << STANDARD_REFRESH_INTERVAL << ".\n" - << "-u h|b|k|m|g| Sets the type of unit used for the display of traffic numbers.\n" - << " H|B|K|M|G h: auto, b: Bit/s, k: kBit/s, m: MBit/s etc.\n" - << " [i|s] H: auto, B: Byte/s, K: kByte/s, M: MByte/s etc.\n" - << " i: IEC binary prefixes, s: SI metric prefixes\n" + << "-u h|b|k|m|g|t|p|H|B|K|M|G|T|P[i|s]\n" + << " Sets the type of unit used for the display of traffic numbers.\n" + << " h: auto, b: Bit/s, k: {k|Ki}Bit/s, m: M[i]Bit/s etc.\n" + << " H: auto, B: Byte/s, K: {k|Ki}Byte/s, M: M[i]Byte/s etc.\n" + << " i: IEC binary prefixes, s: SI metric prefixes\n" << " Default is hi.\n" - << "-U h|b|k|m|g| Same as -u, but for a total amount of data (without \"/s\").\n" - << " H|B|K|M|G Default is Hi.\n" - << " [i|s]\n" + << "-U h|b|k|m|g|t|p|H|B|K|M|G|T|P[i|s]\n" + << " Same as -u, but for a total amount of data (without \"/s\").\n" + << " Default is Hi.\n" << "-f Append traffic data to the named file.\n" << " Network devices to use.\n" << " Default is to use all auto-detected devices.\n" diff --git a/src/statistics.cpp b/src/statistics.cpp index 94f57e0..b30fde9 100644 --- a/src/statistics.cpp +++ b/src/statistics.cpp @@ -132,6 +132,12 @@ float Statistics::getUnitFactor(dataUnit unit, unsigned long long value) case gibiBit: case gibiByte: return factor * 1024 * 1024 * 1024; + case tebiBit: + case tebiByte: + return factor * 1024 * 1024 * 1024 * 1024; + case pebiBit: + case pebiByte: + return factor * 1024 * 1024 * 1024 * 1024 * 1024; case kiloBit: case kiloByte: return factor * 1000; @@ -141,6 +147,12 @@ float Statistics::getUnitFactor(dataUnit unit, unsigned long long value) case gigaBit: case gigaByte: return factor * 1000 * 1000 * 1000; + case teraBit: + case teraByte: + return factor * 1000 * 1000 * 1000 * 1000; + case petaBit: + case petaByte: + return factor * 1000 * 1000 * 1000 * 1000 * 1000; default: // should never be executed return factor; } @@ -149,8 +161,8 @@ float Statistics::getUnitFactor(dataUnit unit, unsigned long long value) string Statistics::getUnitString(dataUnit unit, unsigned long long value) { const string description = (unit % 2 == 0 ? "Bit" : "Byte"); - const string units[] = { "", "Ki", "Mi", "Gi" }; - const string si_units[] = { "", "K", "M", "G" }; + const string units[] = { "", "Ki", "Mi", "Gi", "Ti", "Pi" }; + const string si_units[] = { "", "k", "M", "G", "T", "P" }; switch(unit) { @@ -187,6 +199,12 @@ string Statistics::getUnitString(dataUnit unit, unsigned long long value) case gibiBit: case gibiByte: return "Gi" + description; + case tebiBit: + case tebiByte: + return "Ti" + description; + case pebiBit: + case pebiByte: + return "Pi" + description; case kiloBit: case kiloByte: return "k" + description; @@ -196,6 +214,12 @@ string Statistics::getUnitString(dataUnit unit, unsigned long long value) case gigaBit: case gigaByte: return "G" + description; + case teraBit: + case teraByte: + return "T" + description; + case petaBit: + case petaByte: + return "P" + description; default: // should never be executed return description; } diff --git a/src/statistics.h b/src/statistics.h index 6b21bdf..1edcb37 100644 --- a/src/statistics.h +++ b/src/statistics.h @@ -37,18 +37,26 @@ class Statistics humanReadableByte = -1, bit = 0, byte = 1, - kibiBit = 2, - kibiByte = 3, - mebiBit = 4, - mebiByte = 5, - gibiBit = 6, - gibiByte = 7, - kiloBit = 8, - kiloByte = 9, - megaBit = 10, - megaByte = 11, - gigaBit = 12, - gigaByte = 13 + kibiBit, + kibiByte, + mebiBit, + mebiByte, + gibiBit, + gibiByte, + tebiBit, + tebiByte, + pebiBit, + pebiByte, + kiloBit, + kiloByte, + megaBit, + megaByte, + gigaBit, + gigaByte, + teraBit, + teraByte, + petaBit, + petaByte }; Statistics() {}