Skip to content

Commit

Permalink
Replace assert(0) by throw std::runtime_error("unreachable");.
Browse files Browse the repository at this point in the history
  • Loading branch information
Jarod42 committed Mar 11, 2024
1 parent b3544ca commit 56f38c0
Show file tree
Hide file tree
Showing 10 changed files with 39 additions and 73 deletions.
5 changes: 2 additions & 3 deletions src/lib/game/data/base/base.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -290,9 +290,8 @@ int cSubBase::getResource (eResourceType storeResType) const
case eResourceType::Gold:
return stored.gold;
default:
assert (0);
throw std::runtime_error("unreachable");
}
return 0;
}

//------------------------------------------------------------------------------
Expand All @@ -310,7 +309,7 @@ void cSubBase::setResource (eResourceType storeResType, int value)
setGold (value);
break;
default:
assert (0);
throw std::runtime_error ("unreachable");
}
}

Expand Down
7 changes: 3 additions & 4 deletions src/lib/game/data/freezemode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ void cFreezeModes::enable (eFreezeMode mode)
waitForServer = true;
return;
}
assert (false);
throw std::runtime_error ("unreachable");
}

//------------------------------------------------------------------------------
Expand All @@ -82,7 +82,7 @@ void cFreezeModes::disable (eFreezeMode mode)
waitForServer = false;
return;
}
assert (false);
throw std::runtime_error ("unreachable");
}

//------------------------------------------------------------------------------
Expand All @@ -107,6 +107,5 @@ bool cFreezeModes::isEnabled (eFreezeMode mode) const
case eFreezeMode::WaitForClient: return waitForClient;
case eFreezeMode::WaitForServer: return waitForServer;
}
assert (0); // Incorrect parameter
return false;
throw std::runtime_error ("unreachable");
}
4 changes: 1 addition & 3 deletions src/lib/game/data/report/savedreport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,10 +104,8 @@ std::unique_ptr<cSavedReport> cSavedReport::createFromImpl (Archive& archive)
case eSavedReportType::TurnWait:
case eSavedReportType::TurnAutoMove:
return std::make_unique<cSavedReportSimple> (type);
default:
assert (false);
return nullptr;
}
throw std::runtime_error ("unreachable");
}

//------------------------------------------------------------------------------
Expand Down
6 changes: 2 additions & 4 deletions src/lib/game/logic/action/actioninitnewgame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,7 @@ namespace
case eGameSettingsResourceDensity::TooMuch:
return 3;
}
assert (false);
return 0;
throw std::runtime_error ("unreachable");
}

//--------------------------------------------------------------------------
Expand All @@ -70,8 +69,7 @@ namespace
case eGameSettingsResourceAmount::TooMuch:
return 3;
}
assert (false);
return 0;
throw std::runtime_error ("unreachable");
}

//--------------------------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion src/lib/game/logic/upgradecalculator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1607,7 +1607,7 @@ void cUnitUpgrade::updateUnitData (cDynamicUnitData& data) const
case sUnitUpgrade::eUpgradeType::None:
break;
default:
assert (false);
throw std::runtime_error ("unreachable");
}
}
}
Expand Down
64 changes: 21 additions & 43 deletions src/lib/input/mouse/cursor/mousecursorsimple.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,50 +34,28 @@ SDL_Surface* cMouseCursorSimple::getSurface() const
{
switch (type)
{
case eMouseCursorSimpleType::Hand:
return GraphicsData.gfx_Chand.get();
case eMouseCursorSimpleType::No:
return GraphicsData.gfx_Cno.get();
case eMouseCursorSimpleType::Select:
return GraphicsData.gfx_Cselect.get();
case eMouseCursorSimpleType::Move:
return GraphicsData.gfx_Cmove.get();
case eMouseCursorSimpleType::ArrowLeftDown:
return GraphicsData.gfx_Cpfeil1.get();
case eMouseCursorSimpleType::ArrowDown:
return GraphicsData.gfx_Cpfeil2.get();
case eMouseCursorSimpleType::ArrowRightDown:
return GraphicsData.gfx_Cpfeil3.get();
case eMouseCursorSimpleType::ArrowLeft:
return GraphicsData.gfx_Cpfeil4.get();
case eMouseCursorSimpleType::ArrowRight:
return GraphicsData.gfx_Cpfeil6.get();
case eMouseCursorSimpleType::ArrowLeftUp:
return GraphicsData.gfx_Cpfeil7.get();
case eMouseCursorSimpleType::ArrowUp:
return GraphicsData.gfx_Cpfeil8.get();
case eMouseCursorSimpleType::ArrowRightUp:
return GraphicsData.gfx_Cpfeil9.get();
case eMouseCursorSimpleType::Help:
return GraphicsData.gfx_Chelp.get();
case eMouseCursorSimpleType::Band:
return GraphicsData.gfx_Cband.get();
case eMouseCursorSimpleType::Transfer:
return GraphicsData.gfx_Ctransf.get();
case eMouseCursorSimpleType::Load:
return GraphicsData.gfx_Cload.get();
case eMouseCursorSimpleType::Muni:
return GraphicsData.gfx_Cmuni.get();
case eMouseCursorSimpleType::Repair:
return GraphicsData.gfx_Crepair.get();
case eMouseCursorSimpleType::Activate:
return GraphicsData.gfx_Cactivate.get();
case eMouseCursorSimpleType::MoveDraft:
return GraphicsData.gfx_Cmove_draft.get();
default:
assert (false);
case eMouseCursorSimpleType::Hand: return GraphicsData.gfx_Chand.get();
case eMouseCursorSimpleType::No: return GraphicsData.gfx_Cno.get();
case eMouseCursorSimpleType::Select: return GraphicsData.gfx_Cselect.get();
case eMouseCursorSimpleType::Move: return GraphicsData.gfx_Cmove.get();
case eMouseCursorSimpleType::ArrowLeftDown: return GraphicsData.gfx_Cpfeil1.get();
case eMouseCursorSimpleType::ArrowDown: return GraphicsData.gfx_Cpfeil2.get();
case eMouseCursorSimpleType::ArrowRightDown: return GraphicsData.gfx_Cpfeil3.get();
case eMouseCursorSimpleType::ArrowLeft: return GraphicsData.gfx_Cpfeil4.get();
case eMouseCursorSimpleType::ArrowRight: return GraphicsData.gfx_Cpfeil6.get();
case eMouseCursorSimpleType::ArrowLeftUp: return GraphicsData.gfx_Cpfeil7.get();
case eMouseCursorSimpleType::ArrowUp: return GraphicsData.gfx_Cpfeil8.get();
case eMouseCursorSimpleType::ArrowRightUp: return GraphicsData.gfx_Cpfeil9.get();
case eMouseCursorSimpleType::Help: return GraphicsData.gfx_Chelp.get();
case eMouseCursorSimpleType::Band: return GraphicsData.gfx_Cband.get();
case eMouseCursorSimpleType::Transfer: return GraphicsData.gfx_Ctransf.get();
case eMouseCursorSimpleType::Load: return GraphicsData.gfx_Cload.get();
case eMouseCursorSimpleType::Muni: return GraphicsData.gfx_Cmuni.get();
case eMouseCursorSimpleType::Repair: return GraphicsData.gfx_Crepair.get();
case eMouseCursorSimpleType::Activate: return GraphicsData.gfx_Cactivate.get();
case eMouseCursorSimpleType::MoveDraft: return GraphicsData.gfx_Cmove_draft.get();
}
return GraphicsData.gfx_Chand.get();
throw std::runtime_error ("unreachable");
}

//------------------------------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion src/ui/graphical/game/widgets/gamemapwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -764,7 +764,7 @@ void cGameMapWidget::toggleMouseInputMode (eMouseModeType mouseModeType)
case eMouseModeType::SelectBuildPosition:
case eMouseModeType::Activate:
assert (false);
// fall through
[[fallthrough]];
default:
case eMouseModeType::Default:
setMouseInputMode (std::make_unique<cMouseModeDefault> (mapView.get(), unitSelection, player.get()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,12 +85,11 @@ void cBuildSpeedHandlerWidget::setBuildSpeedIndex (size_t speedIndex)
}

//------------------------------------------------------------------------------
size_t cBuildSpeedHandlerWidget::getBuildSpeedIndex()
size_t cBuildSpeedHandlerWidget::getBuildSpeedIndex() const
{
for (size_t i = 0; i < elementsCount; ++i)
{
if (buttons[i]->isChecked()) return i;
}
assert (false);
return 0;
throw std::runtime_error ("unreachable");
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class cBuildSpeedHandlerWidget : public cWidget
void setValues (const std::array<int, elementsCount>& turns, const std::array<int, elementsCount>& costs);

void setBuildSpeedIndex (size_t speedIndex);
size_t getBuildSpeedIndex();
size_t getBuildSpeedIndex() const;

private:
std::array<cLabel*, elementsCount> turnLabels;
Expand Down
15 changes: 5 additions & 10 deletions src/ui/translations.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,7 @@ std::string toTranslatedString (eGameSettingsResourceAmount amount)
case eGameSettingsResourceAmount::TooMuch:
return lngPack.i18n ("Option~TooMuch");
}
assert (false);
return "";
throw std::runtime_error ("unreachable");
}

//------------------------------------------------------------------------------
Expand All @@ -161,8 +160,7 @@ std::string toTranslatedString (eGameSettingsResourceDensity density)
case eGameSettingsResourceDensity::TooMuch:
return lngPack.i18n ("Option~TooMuch");
}
assert (false);
return "";
throw std::runtime_error ("unreachable");
}

//------------------------------------------------------------------------------
Expand All @@ -175,8 +173,7 @@ std::string toTranslatedString (eGameSettingsBridgeheadType type)
case eGameSettingsBridgeheadType::Mobile:
return lngPack.i18n ("Option~Mobile");
}
assert (false);
return "";
throw std::runtime_error ("unreachable");
}

//------------------------------------------------------------------------------
Expand All @@ -191,8 +188,7 @@ std::string toTranslatedString (eGameSettingsGameType type)
case eGameSettingsGameType::HotSeat:
return lngPack.i18n ("Option~Type_HotSeat");
}
assert (false);
return "";
throw std::runtime_error ("unreachable");
}

//------------------------------------------------------------------------------
Expand All @@ -207,8 +203,7 @@ std::string toTranslatedString (eGameSettingsVictoryCondition condition, int tur
case eGameSettingsVictoryCondition::Death:
return lngPack.i18n ("Comp~NoLimit");
}
assert (false);
return "";
throw std::runtime_error ("unreachable");
}

//------------------------------------------------------------------------------
Expand Down

0 comments on commit 56f38c0

Please sign in to comment.