From ad6dd002753925c0bc6ed2dbdc9076be4e7700a9 Mon Sep 17 00:00:00 2001 From: tomangelo2 Date: Sun, 8 Apr 2018 23:43:22 +0200 Subject: [PATCH] Change new functions return type and switch to enum class As suggested by @krzys_h --- src/level/parser/parserparam.cpp | 12 ++++++------ src/level/parser/parserparam.h | 8 +++++--- src/level/robotmain.cpp | 2 +- src/level/scoreboard.h | 4 ++-- 4 files changed, 14 insertions(+), 12 deletions(-) diff --git a/src/level/parser/parserparam.cpp b/src/level/parser/parserparam.cpp index 3ccd7f9c..479f7cec 100644 --- a/src/level/parser/parserparam.cpp +++ b/src/level/parser/parserparam.cpp @@ -917,21 +917,21 @@ int CLevelParserParam::AsResearchFlag(int def) return AsResearchFlag(); } -int CLevelParserParam::ToSortType(std::string value) +SortType CLevelParserParam::ToSortType(std::string value) { - if (value == "Points" ) return SORT_POINTS; - if (value == "Name" ) return SORT_ID; - return Cast(value, "sorttype"); + if (value == "Points" ) return SortType::SORT_POINTS; + if (value == "Name" ) return SortType::SORT_ID; + return SortType::SORT_ID; } -int CLevelParserParam::AsSortType() +SortType CLevelParserParam::AsSortType() { if (m_empty) throw CLevelParserExceptionMissingParam(this); return ToSortType(m_value); } -int CLevelParserParam::AsSortType(int def) +SortType CLevelParserParam::AsSortType(SortType def) { if (m_empty) return def; diff --git a/src/level/parser/parserparam.h b/src/level/parser/parserparam.h index 1261bb65..b5af93d4 100644 --- a/src/level/parser/parserparam.h +++ b/src/level/parser/parserparam.h @@ -31,6 +31,8 @@ #include "graphics/engine/pyro_type.h" #include "graphics/engine/water.h" +#include "level/scoreboard.h" + #include "math/point.h" #include "object/drive_type.h" @@ -85,7 +87,7 @@ public: Gfx::EngineObjectType AsTerrainType(); int AsBuildFlag(); int AsResearchFlag(); - int AsSortType(); + SortType AsSortType(); Gfx::PyroType AsPyroType(); Gfx::CameraType AsCameraType(); MissionType AsMissionType(); @@ -109,7 +111,7 @@ public: Gfx::EngineObjectType AsTerrainType(Gfx::EngineObjectType def); int AsBuildFlag(int def); int AsResearchFlag(int def); - int AsSortType(int def); + SortType AsSortType(SortType def); Gfx::PyroType AsPyroType(Gfx::PyroType def); Gfx::CameraType AsCameraType(Gfx::CameraType def); MissionType AsMissionType(MissionType def); @@ -141,7 +143,7 @@ private: Gfx::EngineObjectType ToTerrainType(std::string value); int ToBuildFlag(std::string value); int ToResearchFlag(std::string value); - int ToSortType(std::string value); + SortType ToSortType(std::string value); Gfx::PyroType ToPyroType(std::string value); Gfx::CameraType ToCameraType(std::string value); MissionType ToMissionType(std::string value); diff --git a/src/level/robotmain.cpp b/src/level/robotmain.cpp index eed48aae..ad37c611 100644 --- a/src/level/robotmain.cpp +++ b/src/level/robotmain.cpp @@ -5919,7 +5919,7 @@ void CRobotMain::UpdateCodeBattleInterface() assert(pw != nullptr); std::set teams = GetAllTeams(); std::vector sortedTeams(teams.begin(), teams.end()); - if(m_scoreboard->GetSortType() == SORT_POINTS) + if(m_scoreboard->GetSortType() == SortType::SORT_POINTS) { std::sort(sortedTeams.begin(), sortedTeams.end(), [this](int teamA, int teamB) { diff --git a/src/level/scoreboard.h b/src/level/scoreboard.h index cd964de3..993418e5 100644 --- a/src/level/scoreboard.h +++ b/src/level/scoreboard.h @@ -42,7 +42,7 @@ struct Score float time = 0; //! Time when points were scored }; -enum SortType +enum class SortType { SORT_ID, //Sort by team ID SORT_POINTS, //Sort by points @@ -142,5 +142,5 @@ private: std::vector> m_rulesEndTake = {}; std::map m_score; int m_finishCounter = 0; - SortType m_sorttype = SORT_ID; + SortType m_sorttype = SortType::SORT_ID; };