summaryrefslogtreecommitdiff
path: root/src/resources/db
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2017-01-31 19:04:26 +0300
committerAndrei Karas <akaras@inbox.ru>2017-01-31 19:04:26 +0300
commit54fef2b6515e55cf54e51541441da49068ff5afc (patch)
treec1f4aa5942e2aa43de1bd7eb6692f29a647121af /src/resources/db
parent5719a23f9b0729f04ed1fa5dc6cc680c58d514d4 (diff)
downloadplus-54fef2b6515e55cf54e51541441da49068ff5afc.tar.gz
plus-54fef2b6515e55cf54e51541441da49068ff5afc.tar.bz2
plus-54fef2b6515e55cf54e51541441da49068ff5afc.tar.xz
plus-54fef2b6515e55cf54e51541441da49068ff5afc.zip
Remove unit type enum in unitsdb.
Diffstat (limited to 'src/resources/db')
-rw-r--r--src/resources/db/unitsdb.cpp62
1 files 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<struct UnitLevel> levels;
- double conversion;
- bool mix;
-};
+ std::vector<struct UnitLevel> 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,