ManaPlus
Functions
ItemFieldDb Namespace Reference

Functions

void load ()
 
void unload ()
 
void loadXmlFile (const std::string &fileName, const SkipError skipError)
 
const ItemFieldInfosgetRequiredFields ()
 
const ItemFieldInfosgetAddFields ()
 

Function Documentation

◆ getAddFields()

const ItemFieldInfos & ItemFieldDb::getAddFields ( )

◆ getRequiredFields()

const ItemFieldInfos & ItemFieldDb::getRequiredFields ( )

Definition at line 146 of file itemfielddb.cpp.

147 {
148  return mRequiredInfos;
149 }

References anonymous_namespace{itemfielddb.cpp}::mRequiredInfos.

Referenced by ItemOptionDb::loadXmlFile(), and ItemDB::loadXmlFile().

◆ load()

void ItemFieldDb::load ( )

Definition at line 42 of file itemfielddb.cpp.

43 {
44  if (mLoaded)
45  unload();
46 
47  logger->log1("Initializing item field database...");
48 
49  loadXmlFile(paths.getStringValue("itemFieldsFile"), SkipError_false);
50  loadXmlFile(paths.getStringValue("itemFieldsPatchFile"), SkipError_true);
51  loadXmlDir("itemFieldsPatchDir", loadXmlFile)
52  mLoaded = true;
53 }
static void loadXmlFile(const std::string &file, const std::string &name, BadgesInfos &arr, const SkipError skipError)
Definition: badgesdb.cpp:43
#define loadXmlDir(name, function)
Definition: beingcommon.h:39
std::string getStringValue(const std::string &key) const
void log1(const char *const log_text)
Definition: logger.cpp:238
Configuration paths
Logger * logger
Definition: logger.cpp:89
void unload()
Definition: net.cpp:180
const bool SkipError_false
Definition: skiperror.h:30
const bool SkipError_true
Definition: skiperror.h:30

References Configuration::getStringValue(), loadXmlDir, loadXmlFile(), Logger::log1(), logger, anonymous_namespace{itemfielddb.cpp}::mLoaded, paths, SkipError_false, SkipError_true, and Net::unload().

Referenced by DbManager::loadDb().

◆ loadXmlFile()

void ItemFieldDb::loadXmlFile ( const std::string &  fileName,
const SkipError  skipError 
)

Definition at line 103 of file itemfielddb.cpp.

105 {
108  skipError);
109  XmlNodeConstPtrConst rootNode = doc.rootNode();
110 
111  if ((rootNode == nullptr) || !xmlNameEqual(rootNode, "itemfields"))
112  {
113  logger->log("ItemFieldDb: Error while loading %s!",
114  fileName.c_str());
115  return;
116  }
117 
118  for_each_xml_child_node(node, rootNode)
119  {
120  if (xmlNameEqual(node, "include"))
121  {
122  const std::string name = XML::getProperty(node, "name", "");
123  if (!name.empty())
124  loadXmlFile(name, skipError);
125  continue;
126  }
127 
128  if (xmlNameEqual(node, "required"))
130  else if (xmlNameEqual(node, "add"))
132  }
133 }
void log(const char *const log_text,...)
Definition: logger.cpp:269
static void loadFields(const xmlNodePtr groupNode, ItemFieldInfos &fields1, ItemFieldInfos &fields2)
Definition: itemfielddb.cpp:55
#define for_each_xml_child_node(var, parent)
Definition: libxml.h:161
int getProperty(const xmlNodePtr node, const char *const name, int def)
Definition: libxml.cpp:174
std::string fileName
Definition: testmain.cpp:39
const bool UseVirtFs_true
Definition: usevirtfs.h:30

References fileName, for_each_xml_child_node, XML::getProperty(), loadFields(), loadXmlFile(), Logger::log(), logger, anonymous_namespace{itemfielddb.cpp}::mAddInfos, anonymous_namespace{itemfielddb.cpp}::mRequiredInfos, XML::Document::rootNode(), and UseVirtFs_true.

◆ unload()

void ItemFieldDb::unload ( )

Definition at line 135 of file itemfielddb.cpp.

136 {
137  logger->log1("Unloading item database...");
138 
140  mRequiredInfos.clear();
142  mAddInfos.clear();
143  mLoaded = false;
144 }
void delete_all(Container &c)
Definition: dtor.h:56

References delete_all(), Logger::log1(), logger, anonymous_namespace{itemfielddb.cpp}::mAddInfos, anonymous_namespace{itemfielddb.cpp}::mLoaded, and anonymous_namespace{itemfielddb.cpp}::mRequiredInfos.

Referenced by DbManager::unloadDb().