From 5d82960de69aef6b9668b8454cb701e1db97af60 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Mon, 25 Jul 2016 17:45:11 +0300 Subject: Allow load stats for different pages from stats.xml But for now visible only basic stats and extended page. --- src/resources/db/statdb.cpp | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/resources/db/statdb.cpp b/src/resources/db/statdb.cpp index 5c7f5a288..b68ee9576 100644 --- a/src/resources/db/statdb.cpp +++ b/src/resources/db/statdb.cpp @@ -34,7 +34,7 @@ namespace { bool mLoaded = false; static std::vector mBasicStats; - static std::vector mExtendedStats; + static std::map > mStats; } // namespace void StatDb::addDefaultStats() @@ -72,7 +72,7 @@ const std::vector &StatDb::getBasicStats() const std::vector &StatDb::getExtendedStats() { - return mExtendedStats; + return mStats["extended"]; } void StatDb::load() @@ -111,9 +111,11 @@ static void loadBasicStats(const XmlNodePtr rootNode) } } -static void loadExtendedStats(const XmlNodePtr rootNode) +static void loadStats(const XmlNodePtr rootNode, + const std::string &page) { const int maxAttr = static_cast(Attributes::MAX_ATTRIBUTE); + std::vector &stats = mStats[page]; for_each_xml_child_node(node, rootNode) { if (xmlNameEqual(node, "stat")) @@ -126,7 +128,7 @@ static void loadExtendedStats(const XmlNodePtr rootNode) name.c_str()); continue; } - mExtendedStats.push_back(BasicStat(static_cast(id), + stats.push_back(BasicStat(static_cast(id), std::string(), name)); } @@ -165,13 +167,23 @@ void StatDb::loadXmlFile(const std::string &fileName, } else if (xmlNameEqual(node, "extended")) { - loadExtendedStats(node); + loadStats(node, "extended"); + } + else if (xmlNameEqual(node, "page")) + { + std::string page = XML::getProperty(node, "name", ""); + if (page.empty()) + { + reportAlways("Page without name in stats.xml"); + page = "Unknown"; + } + loadStats(node, page); } } if (skipError == SkipError_false) { if (mBasicStats.empty() && - mExtendedStats.empty()) + mStats.empty()) { reportAlways("StatDb: no stats found"); addDefaultStats(); @@ -184,6 +196,6 @@ void StatDb::unload() logger->log1("Unloading stat database..."); mBasicStats.clear(); - mExtendedStats.clear(); + mStats.clear(); mLoaded = false; } -- cgit v1.2.3-70-g09d2