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 315 of file libxml.cpp.

316  {
317  xmlCleanupParser();
318  }

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 289 of file libxml.cpp.

291  {
292  if (parent == nullptr)
293  return nullptr;
294  for_each_xml_child_node(child, parent)
295  {
296  if (xmlNameEqual(child, name))
297  return child;
298  }
299 
300  return nullptr;
301  }
#define for_each_xml_child_node(var, parent)
Definition: libxml.h:161

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 269 of file libxml.cpp.

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

Referenced by Particle::addEffect(), ParticleEngine::addEffect(), loadFields(), loadPermissions(), SkillDialog::loadSkill(), SkillDialog::loadSkillData(), GroupDb::loadXmlFile(), NPCDB::loadXmlFile(), NpcDialogDB::loadXmlFile(), PETDB::loadXmlFile(), SkillUnitDb::loadXmlFile(), TextDb::loadXmlFile(), ItemDB::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 227 of file libxml.cpp.

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

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 211 of file libxml.cpp.

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

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 190 of file libxml.cpp.

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

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 243 of file libxml.cpp.

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

◆ 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 174 of file libxml.cpp.

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

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(), loadXMLFile(), EffectManager::loadXmlFile(), SkillDialog::loadXmlFile(), AvatarDB::loadXmlFile(), ClanDb::loadXmlFile(), CommandsDB::loadXmlFile(), DeadDB::loadXmlFile(), ElementalDb::loadXmlFile(), EmoteDB::loadXmlFile(), GroupDb::loadXmlFile(), HomunculusDB::loadXmlFile(), HorseDB::loadXmlFile(), ItemFieldDb::loadXmlFile(), ItemOptionDb::loadXmlFile(), LanguageDb::loadXmlFile(), MercenaryDB::loadXmlFile(), ModDB::loadXmlFile(), MonsterDB::loadXmlFile(), NPCDB::loadXmlFile(), NpcDialogDB::loadXmlFile(), PETDB::loadXmlFile(), QuestDb::loadXmlFile(), SkillUnitDb::loadXmlFile(), SoundDB::loadXmlFile(), StatDb::loadXmlFile(), StatusEffectDB::loadXmlFile(), TextDb::loadXmlFile(), UnitsDb::loadXmlFile(), ItemDB::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 305 of file libxml.cpp.

306  {
307  xmlInitParser();
308  LIBXML_TEST_VERSION
309 
310  // Suppress libxml2 error messages
311  xmlSetGenericErrorFunc(nullptr, &xmlErrorLogger);
312  }
static void xmlErrorLogger(void *ctx, const char *msg,...)
Definition: libxml.cpp:56

References xmlErrorLogger().

Referenced by mainGui().

◆ langProperty()

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