ManaPlus
Data Structures | Functions
XML Namespace Reference

Data Structures

class  Document
 

Functions

int getProperty (const xmlNodePtr node, const char *const name, int def)
 
int getIntProperty (const xmlNodePtr node, const char *const name, int def, const int min, const int max)
 
float getFloatProperty (const xmlNodePtr node, const char *const name, float def)
 
double getDoubleProperty (const xmlNodePtr node, const char *const name, double def)
 
std::string getProperty (const xmlNodePtr node, const char *const name, const std::string &def)
 
std::string langProperty (const xmlNodePtr node, const char *const name, const std::string &def)
 
bool getBoolProperty (const xmlNodePtr node, const char *const name, const bool def)
 
xmlNodePtr findFirstChildByName (const xmlNode *const parent, const char *const name)
 
void initXML ()
 
void cleanupXML ()
 

Detailed Description

XML helper functions.

Function Documentation

◆ cleanupXML()

void XML::cleanupXML ( )

Definition at line 314 of file libxml.cpp.

315  {
316  xmlCleanupParser();
317  }

Referenced by Client::gameClear().

◆ findFirstChildByName()

xmlNodePtr XML::findFirstChildByName ( const xmlNode *const  parent,
const char *const  name 
)

Finds the first child node with the given name

Definition at line 288 of file libxml.cpp.

290  {
291  if (parent == nullptr)
292  return nullptr;
293  for_each_xml_child_node(child, parent)
294  {
295  if (xmlNameEqual(child, name))
296  return child;
297  }
298 
299  return nullptr;
300  }

References for_each_xml_child_node.

Referenced by Particle::addEffect(), and ParticleEngine::addEffect().

◆ getBoolProperty()

bool XML::getBoolProperty ( const xmlNodePtr  node,
const char *const  name,
const bool  def 
)

Gets a boolean property from an XmlNodePtr.

Definition at line 268 of file libxml.cpp.

271  {
272  xmlChar *const prop = XmlGetProp(node, name);
273 
274  if (XmlStrEqual(prop, "true"))
275  {
276  XmlFree(prop);
277  return true;
278  }
279  if (XmlStrEqual(prop, "false"))
280  {
281  XmlFree(prop);
282  return false;
283  }
284  XmlFree(prop);
285  return def;
286  }

Referenced by Particle::addEffect(), ParticleEngine::addEffect(), loadFields(), CharDB::loadFlags(), loadPermissions(), SkillDialog::loadSkill(), SkillDialog::loadSkillData(), TextDb::loadXmlFile(), SkillUnitDb::loadXmlFile(), PETDB::loadXmlFile(), GroupDb::loadXmlFile(), NpcDialogDB::loadXmlFile(), ItemDB::loadXmlFile(), NPCDB::loadXmlFile(), and ParticleEmitter::ParticleEmitter().

◆ getDoubleProperty()

double XML::getDoubleProperty ( const xmlNodePtr  node,
const char *const  name,
double  def 
)

Gets an double point property from an XmlNodePtr.

Definition at line 226 of file libxml.cpp.

229  {
230  double &ret = def;
231 
232  xmlChar *const prop = XmlGetProp(node, name);
233  if (prop != nullptr)
234  {
235  ret = atof(reinterpret_cast<char*>(prop));
236  xmlFree(prop);
237  }
238 
239  return ret;
240  }

Referenced by ParticleEmitter::readParticleEmitterProp().

◆ getFloatProperty()

float XML::getFloatProperty ( const xmlNodePtr  node,
const char *const  name,
float  def 
)

Gets an floating point property from an XmlNodePtr.

Definition at line 210 of file libxml.cpp.

213  {
214  float &ret = def;
215 
216  xmlChar *const prop = XmlGetProp(node, name);
217  if (prop != nullptr)
218  {
219  ret = static_cast<float>(atof(reinterpret_cast<char*>(prop)));
220  xmlFree(prop);
221  }
222 
223  return ret;
224  }

Referenced by Particle::addEffect(), ParticleEngine::addEffect(), SkillDialog::loadSkillData(), ItemDB::loadXmlFile(), and BeingCommon::readObjectNodes().

◆ getIntProperty()

int XML::getIntProperty ( const xmlNodePtr  node,
const char *const  name,
int  def,
const int  min,
const int  max 
)

Gets an integer property from an XmlNodePtr.

Definition at line 189 of file libxml.cpp.

194  {
195  int &ret = def;
196 
197  xmlChar *const prop = XmlGetProp(node, name);
198  if (prop != nullptr)
199  {
200  ret = atoi(reinterpret_cast<char*>(prop));
201  xmlFree(prop);
202  }
203  if (ret < min)
204  ret = min;
205  else if (ret > max)
206  ret = max;
207  return ret;
208  }

Referenced by SimpleAnimation::initializeAnimation(), SpriteDef::loadAnimation(), loadNpcDialogInventory(), loadNpcDialogMenu(), loadQuest(), SkillDialog::loadSkill(), CommandsDB::loadXmlFile(), ItemDB::loadXmlFile(), and ParticleEmitter::ParticleEmitter().

◆ getProperty() [1/2]

std::string XML::getProperty ( const xmlNodePtr  node,
const char *const  name,
const std::string &  def 
)

Gets a string property from an XmlNodePtr.

Definition at line 242 of file libxml.cpp.

245  {
246  xmlChar *const prop = XmlGetProp(node, name);
247  if (prop != nullptr)
248  {
249  std::string val = reinterpret_cast<char*>(prop);
250  xmlFree(prop);
251  return val;
252  }
253 
254  return def;
255  }

◆ getProperty() [2/2]

int XML::getProperty ( const xmlNodePtr  node,
const char *const  name,
int  def 
)

Gets an integer property from an XmlNodePtr.

Definition at line 173 of file libxml.cpp.

176  {
177  int &ret = def;
178 
179  xmlChar *const prop = XmlGetProp(node, name);
180  if (prop != nullptr)
181  {
182  ret = atoi(reinterpret_cast<const char*>(prop));
183  xmlFree(prop);
184  }
185 
186  return ret;
187  }

Referenced by Particle::addEffect(), ParticleEngine::addEffect(), addFieldByName(), MapReader::addLayerToList(), EquipmentWindow::fillBoxes(), ParticleEmitter::getImageSet(), SpriteDef::includeSprite(), ConfigurationObject::initFromXML(), SimpleAnimation::initializeAnimation(), langProperty(), CharDB::load(), SpriteDef::loadAction(), SpriteDef::loadAnimation(), loadBasicStats(), ColorDB::loadColorLists(), Theme::loadColors(), loadCommands(), loadCurrencies(), loadEffect(), loadFields(), loadFloorSprite(), ColorDB::loadHair(), SpriteDef::loadImageSet(), MapDB::loadInfo(), loadMenu(), CharDB::loadMinMax(), loadNpcDialogInventory(), loadNpcDialogMenu(), loadOffset(), loadOrderSprite(), loadPermissions(), EquipmentWindow::loadPlayerBox(), loadQuest(), MapDB::loadRemapXmlFile(), loadReplaceSprite(), loadRiderOffset(), ServerDialog::loadServers(), SkillDialog::loadSkill(), SkillDialog::loadSkillData(), EquipmentWindow::loadSlot(), loadSoundRef(), EmoteDB::loadSpecialXmlFile(), SpriteDef::loadSprite(), loadSpriteRef(), loadStats(), loadUnit(), TextDb::loadXmlFile(), SoundDB::loadXmlFile(), LanguageDb::loadXmlFile(), ItemFieldDb::loadXmlFile(), StatDb::loadXmlFile(), DeadDB::loadXmlFile(), PETDB::loadXmlFile(), SkillUnitDb::loadXmlFile(), ModDB::loadXmlFile(), UnitsDb::loadXmlFile(), GroupDb::loadXmlFile(), QuestDb::loadXmlFile(), ItemOptionDb::loadXmlFile(), NpcDialogDB::loadXmlFile(), HorseDB::loadXmlFile(), AvatarDB::loadXmlFile(), ClanDb::loadXmlFile(), ElementalDb::loadXmlFile(), HomunculusDB::loadXmlFile(), CommandsDB::loadXmlFile(), MercenaryDB::loadXmlFile(), MonsterDB::loadXmlFile(), EmoteDB::loadXmlFile(), ItemDB::loadXmlFile(), NPCDB::loadXmlFile(), EffectManager::loadXmlFile(), StatusEffectDB::loadXmlFile(), loadXMLFile(), SkillDialog::loadXmlFile(), ParticleEmitter::ParticleEmitter(), EquipmentWindow::prepareSlotNames(), BeingCommon::readAiAttributes(), MapDB::readAtlas(), BeingCommon::readBasicAttributes(), readField(), MapReader::readLayer(), MapDB::readMap(), BeingCommon::readObjectNodes(), ParticleEmitter::readParticleEmitterProp(), MapReader::readProperties(), Theme::readSkin(), MapReader::readTileset(), BeingCommon::readWalkingAttributes(), readXmlIntMap(), readXmlIntVector(), and readXmlStringMap().

◆ initXML()

void XML::initXML ( )

Definition at line 304 of file libxml.cpp.

305  {
306  xmlInitParser();
307  LIBXML_TEST_VERSION
308 
309  // Suppress libxml2 error messages
310  xmlSetGenericErrorFunc(nullptr, &xmlErrorLogger);
311  }

References xmlErrorLogger().

Referenced by mainGui().

◆ langProperty()

std::string XML::langProperty ( const xmlNodePtr  node,
const char *const  name,
const std::string &  def 
)
PoDict::getStr
const std::string getStr(const std::string &str)
Definition: podict.cpp:44
xmlErrorLogger
static void xmlErrorLogger(void *ctx, const char *msg,...)
Definition: libxml.cpp:55
XML::getProperty
std::string getProperty(const xmlNodePtr node, const char *const name, const std::string &def)
Definition: libxml.cpp:242
for_each_xml_child_node
#define for_each_xml_child_node(var, parent)
Definition: libxml.h:160
translator
PoDict * translator
Definition: podict.cpp:27