ManaPlus
Functions
TextDb Namespace Reference

Functions

void load ()
 
void loadXmlFile (const std::string &fileName, const SkipError skipError)
 
std::string getByIndex (const int index)
 
const StringVectgetTexts ()
 
void unload ()
 

Function Documentation

◆ getByIndex()

std::string TextDb::getByIndex ( const int  index)

Definition at line 97 of file textdb.cpp.

98 {
99  if (index < 0 ||
100  static_cast<size_t>(index) >= mTexts.size())
101  {
102  return std::string();
103  }
104  return mTexts[index];
105 }

References anonymous_namespace{textdb.cpp}::mTexts.

Referenced by ChatWindow::action().

◆ getTexts()

const StringVect & TextDb::getTexts ( )

Definition at line 92 of file textdb.cpp.

93 {
94  return mTexts;
95 }

References anonymous_namespace{textdb.cpp}::mTexts.

Referenced by EmoteWindow::show().

◆ load()

void TextDb::load ( )

Definition at line 37 of file textdb.cpp.

38 {
39  unload();
40  logger->log1("Initializing text database...");
42  loadXmlFile(paths.getStringValue("textsPatchFile"), SkipError_true);
43  loadXmlDir("textsPatchDir", loadXmlFile)
44 }
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, paths, SkipError_false, SkipError_true, and Net::unload().

Referenced by DbManager::loadDb().

◆ loadXmlFile()

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

Definition at line 46 of file textdb.cpp.

48 {
51  skipError);
52  XmlNodeConstPtrConst root = doc->rootNode();
53 
54  if ((root == nullptr) || !xmlNameEqual(root, "texts"))
55  {
56  delete doc;
57  return;
58  }
59 
60  for_each_xml_child_node(node, root)
61  {
62  if (xmlNameEqual(node, "include"))
63  {
64  const std::string name = XML::getProperty(node, "name", "");
65  if (!name.empty())
66  loadXmlFile(name, skipError);
67  continue;
68  }
69  else if (xmlNameEqual(node, "text"))
70  {
71  const bool show = XML::getBoolProperty(node, "show", false);
72  if (show == true)
73  {
74  if (!XmlHaveChildContent(node))
75  continue;
76 
77  std::string text = XmlChildContent(node);
78  mTexts.push_back(text);
79  }
80  }
81  }
82 
83  delete doc;
84 }
xmlNodePtr rootNode()
Definition: libxml.cpp:169
#define for_each_xml_child_node(var, parent)
Definition: libxml.h:161
bool getBoolProperty(const xmlNodePtr node, const char *const name, const bool def)
Definition: libxml.cpp:269
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::getBoolProperty(), XML::getProperty(), loadXmlFile(), anonymous_namespace{textdb.cpp}::mTexts, XML::Document::rootNode(), and UseVirtFs_true.

◆ unload()

void TextDb::unload ( )

Definition at line 86 of file textdb.cpp.

87 {
88  logger->log1("Unloading text database...");
89  mTexts.clear();
90 }

References Logger::log1(), logger, and anonymous_namespace{textdb.cpp}::mTexts.

Referenced by DbManager::unloadDb().