ManaPlus
Namespaces | Functions | Variables
statdb.cpp File Reference

(986a3bf)

#include "resources/db/statdb.h"
#include "configuration.h"
#include "enums/being/attributesstrings.h"
#include "utils/checkutils.h"
#include "resources/beingcommon.h"
#include "utils/gettext.h"
#include "debug.h"

Go to the source code of this file.

Namespaces

 anonymous_namespace{statdb.cpp}
 

Functions

static void loadBasicStats (const xmlNodePtr rootNode)
 
static void loadStats (const xmlNodePtr rootNode, const std::string &page)
 

Variables

bool anonymous_namespace{statdb.cpp}::mLoaded = false
 
std::vector< BasicStatanonymous_namespace{statdb.cpp}::mBasicStats
 
std::map< std::string, std::vector< BasicStat > > anonymous_namespace{statdb.cpp}::mStats
 
std::vector< std::string > anonymous_namespace{statdb.cpp}::mPages
 

Function Documentation

◆ loadBasicStats()

static void loadBasicStats ( const xmlNodePtr  rootNode)
static

Definition at line 100 of file statdb.cpp.

101 {
102  const int maxAttr = static_cast<int>(Attributes::MAX_ATTRIBUTE);
103  for_each_xml_child_node(node, rootNode)
104  {
105  if (xmlNameEqual(node, "stat"))
106  {
107  const std::string name = XML::getProperty(node, "name", "");
108  const std::string attr = XML::getProperty(node, "attr", "");
109  if (attr.empty() || AttributesEnum::find(attr) == false)
110  {
111  const int id = XML::getProperty(node, "id", 0);
112  if (id <= 0 || id >= maxAttr)
113  {
114  reportAlways("Wrong attr or id for basic "
115  "stat with name %s",
116  name.c_str())
117  continue;
118  }
119  const std::string tag = XML::getProperty(node, "tag", "");
120  mBasicStats.push_back(BasicStat(static_cast<AttributesT>(id),
121  tag,
122  name));
123  }
124  else
125  {
126  const std::string tag = XML::getProperty(node, "tag", "");
127  mBasicStats.push_back(BasicStat(AttributesEnum::get(attr),
128  tag,
129  name));
130  }
131  }
132  }
133 }
Attributes ::T AttributesT
Definition: attributes.h:118
#define reportAlways(...)
Definition: checkutils.h:253
#define for_each_xml_child_node(var, parent)
Definition: libxml.h:161
bool find(const std::string &key)
AttributesT get(const std::string &key)
Definition: libxml.cpp:86
int getProperty(const xmlNodePtr node, const char *const name, int def)
Definition: libxml.cpp:174
std::vector< BasicStat > mBasicStats
Definition: statdb.cpp:39

References AttributesEnum::find(), for_each_xml_child_node, AttributesEnum::get(), XML::getProperty(), Attributes::MAX_ATTRIBUTE, anonymous_namespace{statdb.cpp}::mBasicStats, and reportAlways.

Referenced by StatDb::loadXmlFile().

◆ loadStats()

static void loadStats ( const xmlNodePtr  rootNode,
const std::string &  page 
)
static

Definition at line 135 of file statdb.cpp.

137 {
138  const int maxAttr = static_cast<int>(Attributes::MAX_ATTRIBUTE);
139  STD_VECTOR<BasicStat> &stats = mStats[page];
140  mPages.push_back(page);
141  for_each_xml_child_node(node, rootNode)
142  {
143  if (xmlNameEqual(node, "stat"))
144  {
145  const std::string name = XML::getProperty(node, "name", "");
146  const std::string attr = XML::getProperty(node, "attr", "");
147  if (attr.empty() || AttributesEnum::find(attr) == false)
148  {
149  const int id = XML::getProperty(node, "id", 0);
150  if (id <= 0 || id >= maxAttr)
151  {
152  reportAlways("Wrong attr or id for extended "
153  "stat with name %s",
154  name.c_str())
155  continue;
156  }
157  stats.push_back(BasicStat(static_cast<AttributesT>(id),
158  std::string(),
159  name));
160  }
161  else
162  {
163  stats.push_back(BasicStat(AttributesEnum::get(attr),
164  std::string(),
165  name));
166  }
167  }
168  }
169 }
std::map< std::string, std::vector< BasicStat > > mStats
Definition: statdb.cpp:40
std::vector< std::string > mPages
Definition: statdb.cpp:41

References AttributesEnum::find(), for_each_xml_child_node, AttributesEnum::get(), XML::getProperty(), Attributes::MAX_ATTRIBUTE, anonymous_namespace{statdb.cpp}::mPages, anonymous_namespace{statdb.cpp}::mStats, and reportAlways.

Referenced by StatDb::loadXmlFile().