Skip to content

Commit cf95074

Browse files
committed
refactor: Remove default cases for scoped enum
1 parent 80bebcd commit cf95074

File tree

1 file changed

+20
-21
lines changed

1 file changed

+20
-21
lines changed

src/qt/bitcoinunits.cpp

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66

77
#include <QStringList>
88

9+
#include <cassert>
10+
911
BitcoinUnits::BitcoinUnits(QObject *parent):
1012
QAbstractListModel(parent),
1113
unitlist(availableUnits())
@@ -24,60 +26,57 @@ QList<BitcoinUnit> BitcoinUnits::availableUnits()
2426

2527
QString BitcoinUnits::longName(Unit unit)
2628
{
27-
switch(unit)
28-
{
29+
switch (unit) {
2930
case Unit::BTC: return QString("BTC");
3031
case Unit::mBTC: return QString("mBTC");
3132
case Unit::uBTC: return QString::fromUtf8("µBTC (bits)");
3233
case Unit::SAT: return QString("Satoshi (sat)");
33-
default: return QString("???");
34-
}
34+
} // no default case, so the compiler can warn about missing cases
35+
assert(false);
3536
}
3637

3738
QString BitcoinUnits::shortName(Unit unit)
3839
{
39-
switch(unit)
40-
{
41-
case Unit::uBTC: return QString::fromUtf8("bits");
40+
switch (unit) {
41+
case Unit::BTC: return longName(unit);
42+
case Unit::mBTC: return longName(unit);
43+
case Unit::uBTC: return QString("bits");
4244
case Unit::SAT: return QString("sat");
43-
default: return longName(unit);
44-
}
45+
} // no default case, so the compiler can warn about missing cases
46+
assert(false);
4547
}
4648

4749
QString BitcoinUnits::description(Unit unit)
4850
{
49-
switch(unit)
50-
{
51+
switch (unit) {
5152
case Unit::BTC: return QString("Bitcoins");
5253
case Unit::mBTC: return QString("Milli-Bitcoins (1 / 1" THIN_SP_UTF8 "000)");
5354
case Unit::uBTC: return QString("Micro-Bitcoins (bits) (1 / 1" THIN_SP_UTF8 "000" THIN_SP_UTF8 "000)");
5455
case Unit::SAT: return QString("Satoshi (sat) (1 / 100" THIN_SP_UTF8 "000" THIN_SP_UTF8 "000)");
55-
default: return QString("???");
56-
}
56+
} // no default case, so the compiler can warn about missing cases
57+
assert(false);
5758
}
5859

5960
qint64 BitcoinUnits::factor(Unit unit)
6061
{
61-
switch(unit)
62-
{
62+
switch (unit) {
6363
case Unit::BTC: return 100000000;
6464
case Unit::mBTC: return 100000;
6565
case Unit::uBTC: return 100;
6666
case Unit::SAT: return 1;
67-
default: return 100000000;
68-
}
67+
} // no default case, so the compiler can warn about missing cases
68+
assert(false);
6969
}
7070

7171
int BitcoinUnits::decimals(Unit unit)
7272
{
73-
switch(unit)
74-
{
73+
switch (unit) {
7574
case Unit::BTC: return 8;
7675
case Unit::mBTC: return 5;
7776
case Unit::uBTC: return 2;
7877
case Unit::SAT: return 0;
79-
default: return 0;
80-
}
78+
} // no default case, so the compiler can warn about missing cases
79+
assert(false);
8180
}
8281

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

0 commit comments

Comments
 (0)