ManaPlus
Typedefs | Functions
ItemOptionDb Namespace Reference

Typedefs

typedef std::map< int, std::vector< ItemFieldType * > > OptionInfos
 

Functions

void load ()
 
void unload ()
 
void loadXmlFile (const std::string &fileName, const SkipError skipError)
 
const std::vector< ItemFieldType * > & getFields (const int id)
 

Typedef Documentation

◆ OptionInfos

typedef std::map<int, std::vector <ItemFieldType*> > ItemOptionDb::OptionInfos

Definition at line 47 of file itemoptiondb.h.

Function Documentation

◆ getFields()

const std::vector< ItemFieldType * > & ItemOptionDb::getFields ( const int  id)

Definition at line 146 of file itemoptiondb.cpp.

147 {
148  OptionInfos::const_iterator it = mOptions.find(id);
149  if (it == mOptions.end())
150  return mEmptyOption;
151  return (*it).second;
152 }
const std::vector< ItemFieldType * > mEmptyOption
ItemOptionDb::OptionInfos mOptions

References anonymous_namespace{itemoptiondb.cpp}::mEmptyOption, and anonymous_namespace{itemoptiondb.cpp}::mOptions.

Referenced by ItemPopup::getOptionsString().

◆ load()

void ItemOptionDb::load ( )

Definition at line 41 of file itemoptiondb.cpp.

42 {
43  if (mLoaded)
44  unload();
45 
46  logger->log1("Initializing item options database...");
47  loadXmlFile(paths.getStringValue("itemOptionsFile"), SkipError_false);
48  loadXmlFile(paths.getStringValue("itemOptionsPatchFile"), SkipError_true);
49  loadXmlDir("itemOptionsPatchDir", loadXmlFile)
50  mLoaded = true;
51 }
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{itemoptiondb.cpp}::mLoaded, paths, SkipError_false, SkipError_true, and Net::unload().

Referenced by DbManager::loadDb().

◆ loadXmlFile()

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

Definition at line 85 of file itemoptiondb.cpp.

87 {
90  skipError);
91  XmlNodeConstPtrConst rootNode = doc.rootNode();
92 
93  if ((rootNode == nullptr) || !xmlNameEqual(rootNode, "itemoptions"))
94  {
95  if (skipError == SkipError_true)
96  {
97  logger->log("ItemFieldDb: Error while loading %s!",
98  fileName.c_str());
99  }
100  else
101  {
102  reportAlways("ItemFieldDb: Error while loading %s!",
103  fileName.c_str())
104  }
105  return;
106  }
107 
108  const ItemFieldInfos &requiredFields =
110  const ItemFieldInfos &addFields =
112 
113  for_each_xml_child_node(node, rootNode)
114  {
115  if (xmlNameEqual(node, "include"))
116  {
117  const std::string name = XML::getProperty(node, "name", "");
118  if (!name.empty())
119  loadXmlFile(name, skipError);
120  continue;
121  }
122  if (xmlNameEqual(node, "option"))
123  {
124  const int id = XML::getProperty(node,
125  "id",
126  0);
127  if (id <= 0)
128  {
129  reportAlways("Empty id field in ItemOptionDb")
130  continue;
131  }
132  STD_VECTOR<ItemFieldType*> &options = mOptions[id];
133  readOptionFields(options, node, requiredFields);
134  readOptionFields(options, node, addFields);
135  }
136  }
137 }
#define reportAlways(...)
Definition: checkutils.h:253
void log(const char *const log_text,...)
Definition: logger.cpp:269
std::map< std::string, ItemFieldType * > ItemFieldInfos
static void readOptionFields(std::vector< ItemFieldType * > &options, const xmlNodePtr node, const ItemFieldInfos &fields)
#define for_each_xml_child_node(var, parent)
Definition: libxml.h:161
const ItemFieldInfos & getRequiredFields()
const ItemFieldInfos & getAddFields()
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
#define STD_VECTOR
Definition: vector.h:30

References fileName, for_each_xml_child_node, ItemFieldDb::getAddFields(), XML::getProperty(), ItemFieldDb::getRequiredFields(), loadXmlFile(), Logger::log(), logger, anonymous_namespace{itemoptiondb.cpp}::mOptions, readOptionFields(), reportAlways, XML::Document::rootNode(), SkipError_true, and UseVirtFs_true.

◆ unload()

void ItemOptionDb::unload ( )

Definition at line 139 of file itemoptiondb.cpp.

140 {
141  logger->log1("Unloading item options database...");
142  mOptions.clear();
143  mLoaded = false;
144 }

References Logger::log1(), logger, anonymous_namespace{itemoptiondb.cpp}::mLoaded, and anonymous_namespace{itemoptiondb.cpp}::mOptions.

Referenced by DbManager::unloadDb().