From 54fef2b6515e55cf54e51541441da49068ff5afc Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Tue, 31 Jan 2017 19:04:26 +0300 Subject: Remove unit type enum in unitsdb. --- src/resources/db/unitsdb.cpp | 62 +++++++++++++++++++++----------------------- 1 file changed, 30 insertions(+), 32 deletions(-) diff --git a/src/resources/db/unitsdb.cpp b/src/resources/db/unitsdb.cpp index 7e1e8f880..56e83a718 100644 --- a/src/resources/db/unitsdb.cpp +++ b/src/resources/db/unitsdb.cpp @@ -31,37 +31,36 @@ #include "debug.h" -struct UnitLevel final +namespace { - A_DEFAULT_COPY(UnitLevel) + struct UnitLevel final + { + A_DEFAULT_COPY(UnitLevel) - std::string symbol; - int count; - int round; - std::string separator; -}; + std::string symbol; + int count; + int round; + std::string separator; + }; -struct UnitDescription final -{ - A_DEFAULT_COPY(UnitDescription) + struct UnitDescription final + { + A_DEFAULT_COPY(UnitDescription) - std::vector levels; - double conversion; - bool mix; -}; + std::vector levels; + double conversion; + bool mix; + }; -enum UnitType -{ - UNIT_WEIGHT = 0, - UNIT_CURRENCY = 1, - UNIT_END -}; + UnitDescription defaultCurrency; + UnitDescription defaultWeight; +} // namespace -static std::string formatUnit(const int value, const int type); - -static std::string splitNumber(std::string str, const std::string &separator); +static std::string formatUnit(const int value, + const UnitDescription &ud); -struct UnitDescription units[UNIT_END]; +static std::string splitNumber(std::string str, + const std::string &separator); void UnitsDb::loadUnits() { @@ -89,7 +88,7 @@ void UnitsDb::loadUnits() }; ud.levels.push_back(ul); - units[UNIT_WEIGHT] = ud; + defaultWeight = ud; } { // Setup default currency @@ -101,7 +100,7 @@ void UnitsDb::loadUnits() UnitLevel bu = {"ยค", 1, 0, ""}; ud.levels.push_back(bu); - units[UNIT_CURRENCY] = ud; + defaultCurrency = ud; } loadXmlFile(paths.getStringValue("unitsFile"), SkipError_false); @@ -185,9 +184,9 @@ void UnitsDb::loadXmlFile(const std::string &fileName, ud.levels.push_back(lev); if (type == "weight") - units[UNIT_WEIGHT] = ud; + defaultWeight = ud; else if (type == "currency") - units[UNIT_CURRENCY] = ud; + defaultCurrency = ud; else logger->log("Error unknown unit type: %s", type.c_str()); } @@ -195,9 +194,8 @@ void UnitsDb::loadXmlFile(const std::string &fileName, } static std::string formatUnit(const int value, - const int type) + const UnitDescription &ud) { - const UnitDescription ud = units[type]; UnitLevel ul; // Shortcut for 0; do the same for values less than 0 (for now) @@ -278,12 +276,12 @@ static std::string formatUnit(const int value, std::string UnitsDb::formatCurrency(const int value) { - return formatUnit(value, UNIT_CURRENCY); + return formatUnit(value, defaultCurrency); } std::string UnitsDb::formatWeight(const int value) { - return formatUnit(value, UNIT_WEIGHT); + return formatUnit(value, defaultWeight); } static std::string splitNumber(std::string str, -- cgit v1.2.3-60-g2f50