Skip to content

Commit ffbc2fe

Browse files
hebastojb55
authored andcommitted
qt, refactor: Remove default cases for scoped enum
1 parent 152d5ba commit ffbc2fe

File tree

1 file changed

+18
-21
lines changed

1 file changed

+18
-21
lines changed

src/qt/bitcoinunits.cpp

Lines changed: 18 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -30,60 +30,57 @@ QList<BitcoinUnit> BitcoinUnits::availableUnits()
3030

3131
QString BitcoinUnits::longName(Unit unit)
3232
{
33-
switch(unit)
34-
{
33+
switch (unit) {
3534
case Unit::BTC: return QString("BTC");
3635
case Unit::mBTC: return QString("mBTC");
3736
case Unit::uBTC: return QString::fromUtf8("µBTC (bits)");
3837
case Unit::SAT: return QString("Satoshi (sat)");
39-
default: return QString("???");
40-
}
38+
} // no default case, so the compiler can warn about missing cases
39+
assert(false);
4140
}
4241

4342
QString BitcoinUnits::shortName(Unit unit)
4443
{
45-
switch(unit)
46-
{
47-
case Unit::uBTC: return QString::fromUtf8("bits");
44+
switch (unit) {
45+
case Unit::BTC: return longName(unit);
46+
case Unit::mBTC: return longName(unit);
47+
case Unit::uBTC: return QString("bits");
4848
case Unit::SAT: return QString("sat");
49-
default: return longName(unit);
50-
}
49+
} // no default case, so the compiler can warn about missing cases
50+
assert(false);
5151
}
5252

5353
QString BitcoinUnits::description(Unit unit)
5454
{
55-
switch(unit)
56-
{
55+
switch (unit) {
5756
case Unit::BTC: return QString("Bitcoins");
5857
case Unit::mBTC: return QString("Milli-Bitcoins (1 / 1" THIN_SP_UTF8 "000)");
5958
case Unit::uBTC: return QString("Micro-Bitcoins (bits) (1 / 1" THIN_SP_UTF8 "000" THIN_SP_UTF8 "000)");
6059
case Unit::SAT: return QString("Satoshi (sat) (1 / 100" THIN_SP_UTF8 "000" THIN_SP_UTF8 "000)");
61-
default: return QString("???");
62-
}
60+
} // no default case, so the compiler can warn about missing cases
61+
assert(false);
6362
}
6463

6564
qint64 BitcoinUnits::factor(Unit unit)
6665
{
67-
switch(unit)
68-
{
66+
switch (unit) {
6967
case Unit::BTC: return 100'000'000;
7068
case Unit::mBTC: return 100'000;
7169
case Unit::uBTC: return 100;
7270
case Unit::SAT: return 1;
73-
default: return 100'000'000;
74-
}
71+
} // no default case, so the compiler can warn about missing cases
72+
assert(false);
7573
}
7674

7775
int BitcoinUnits::decimals(Unit unit)
7876
{
79-
switch(unit)
80-
{
77+
switch (unit) {
8178
case Unit::BTC: return 8;
8279
case Unit::mBTC: return 5;
8380
case Unit::uBTC: return 2;
8481
case Unit::SAT: return 0;
85-
default: return 0;
86-
}
82+
} // no default case, so the compiler can warn about missing cases
83+
assert(false);
8784
}
8885

8986
QString BitcoinUnits::format(Unit unit, const CAmount& nIn, bool fPlus, SeparatorStyle separators, bool justify)

0 commit comments

Comments
 (0)