summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2017-02-07 20:38:10 +0300
committerAndrei Karas <akaras@inbox.ru>2017-03-24 00:08:35 +0300
commitd1590377de1141144d59ca1160de2822177f6f2a (patch)
treea368b251dedc7164cadbfe459de4cf5c983acf98
parent65422e722cfe0616c65498c71aa0651857dcc49a (diff)
downloadplus-d1590377de1141144d59ca1160de2822177f6f2a.tar.gz
plus-d1590377de1141144d59ca1160de2822177f6f2a.tar.bz2
plus-d1590377de1141144d59ca1160de2822177f6f2a.tar.xz
plus-d1590377de1141144d59ca1160de2822177f6f2a.zip
Add support for tinyxml2 for reading / writing xml files.
-rwxr-xr-xconfigure.ac16
-rw-r--r--src/Makefile.am18
-rw-r--r--src/configuration.cpp14
-rw-r--r--src/configuration.h4
-rw-r--r--src/effectmanager.cpp2
-rw-r--r--src/gui/theme.cpp6
-rw-r--r--src/gui/windows/equipmentwindow.cpp10
-rw-r--r--src/gui/windows/equipmentwindow.h8
-rw-r--r--src/gui/windows/serverdialog.cpp4
-rw-r--r--src/gui/windows/skilldialog.cpp4
-rw-r--r--src/gui/windows/skilldialog.h4
-rw-r--r--src/gui/windows/updaterwindow.cpp2
-rw-r--r--src/particle/particle.cpp2
-rw-r--r--src/particle/particleemitter.cpp2
-rw-r--r--src/particle/particleemitter.h2
-rw-r--r--src/particle/particleengine.cpp2
-rw-r--r--src/particle/rotationalparticle.cpp2
-rw-r--r--src/particle/rotationalparticle.h2
-rw-r--r--src/resources/animation/simpleanimation.cpp4
-rw-r--r--src/resources/animation/simpleanimation.h4
-rw-r--r--src/resources/db/avatardb.cpp2
-rw-r--r--src/resources/db/chardb.cpp4
-rw-r--r--src/resources/db/chardb.h2
-rw-r--r--src/resources/db/colordb.cpp4
-rw-r--r--src/resources/db/commandsdb.cpp2
-rw-r--r--src/resources/db/deaddb.cpp2
-rw-r--r--src/resources/db/elementaldb.cpp2
-rw-r--r--src/resources/db/homunculusdb.cpp2
-rw-r--r--src/resources/db/itemdb.cpp24
-rw-r--r--src/resources/db/itemfielddb.cpp4
-rw-r--r--src/resources/db/mapdb.cpp4
-rw-r--r--src/resources/db/mercenarydb.cpp2
-rw-r--r--src/resources/db/moddb.cpp2
-rw-r--r--src/resources/db/monsterdb.cpp2
-rw-r--r--src/resources/db/npcdb.cpp2
-rw-r--r--src/resources/db/npcdialogdb.cpp6
-rw-r--r--src/resources/db/petdb.cpp2
-rw-r--r--src/resources/db/questdb.cpp6
-rw-r--r--src/resources/db/skillunitdb.cpp2
-rw-r--r--src/resources/db/sounddb.cpp2
-rw-r--r--src/resources/db/statdb.cpp6
-rw-r--r--src/resources/db/statuseffectdb.cpp2
-rw-r--r--src/resources/db/unitsdb.cpp2
-rw-r--r--src/resources/mapreader.cpp8
-rw-r--r--src/resources/mapreader.h8
-rw-r--r--src/resources/sprite/spritedef.cpp12
-rw-r--r--src/resources/sprite/spritedef.h10
-rw-r--r--src/utils/xml.h2
-rw-r--r--src/utils/xml/libxml.cpp14
-rw-r--r--src/utils/xml/libxml.h14
-rw-r--r--src/utils/xml/libxml.inc7
-rw-r--r--src/utils/xml/pugixml.cpp14
-rw-r--r--src/utils/xml/pugixml.h14
-rw-r--r--src/utils/xml/pugixml.inc6
-rw-r--r--src/utils/xml/tinyxml2.cpp306
-rw-r--r--src/utils/xml/tinyxml2.h161
-rw-r--r--src/utils/xml/tinyxml2.inc70
-rw-r--r--src/utils/xml_unittest.cc22
-rw-r--r--src/utils/xmlutils.cpp6
59 files changed, 731 insertions, 143 deletions
diff --git a/configure.ac b/configure.ac
index c473ceac0..dd51ff4a8 100755
--- a/configure.ac
+++ b/configure.ac
@@ -374,10 +374,17 @@ case $xmllib in
"libxml")
AM_CONDITIONAL(ENABLE_LIBXML, true)
AM_CONDITIONAL(ENABLE_PUGIXML, false)
+ AM_CONDITIONAL(ENABLE_TINYXML2, false)
;;
"pugixml")
AM_CONDITIONAL(ENABLE_LIBXML, false)
AM_CONDITIONAL(ENABLE_PUGIXML, true)
+ AM_CONDITIONAL(ENABLE_TINYXML2, false)
+ ;;
+ "tinyxml2")
+ AM_CONDITIONAL(ENABLE_LIBXML, false)
+ AM_CONDITIONAL(ENABLE_PUGIXML, false)
+ AM_CONDITIONAL(ENABLE_TINYXML2, true)
;;
*)
AC_MSG_ERROR([[Wrong xml lib name]])
@@ -406,6 +413,15 @@ if test "$xmllib" == "pugixml"; then
AC_MSG_ERROR([ *** pugixml library found but cannot find headers (http://pugixml.org/)]))
fi
+if test "$xmllib" == "tinyxml2"; then
+ if test "$skip_check_lib" == "no"; then
+ AC_CHECK_LIB([tinyxml2], [main], ,
+ AC_MSG_ERROR([ *** Unable to find tinyxml2 library (http://grinninglizard.com/tinyxml2/)]))
+ fi
+ AC_CHECK_HEADERS([tinyxml2.h], ,
+ AC_MSG_ERROR([ *** tinyxml2 library found but cannot find headers (http://grinninglizard.com/tinyxml2/)]))
+fi
+
if test "$skip_check_lib" == "no"; then
AC_CHECK_LIB(png, png_write_info, ,
AC_MSG_ERROR([ *** Unable to find png library]))
diff --git a/src/Makefile.am b/src/Makefile.am
index f3dae8c8e..ddf446344 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -65,6 +65,10 @@ if ENABLE_LIBXML
manaplus_CXXFLAGS += -DENABLE_LIBXML
dyecmd_CXXFLAGS += -DENABLE_LIBXML
endif
+if ENABLE_TINYXML2
+manaplus_CXXFLAGS += -DENABLE_TINYXML2
+dyecmd_CXXFLAGS += -DENABLE_TINYXML2
+endif
if ENABLE_PORTABLE
dyecmd_CXXFLAGS += -DENABLE_PORTABLE
@@ -881,6 +885,11 @@ BASE_SRC += utils/xml/libxml.cpp \
utils/xml/libxml.h \
utils/xml/libxml.inc
endif
+if ENABLE_TINYXML2
+BASE_SRC += utils/xml/tinyxml2.cpp \
+ utils/xml/tinyxml2.h \
+ utils/xml/tinyxml2.inc
+endif
dyecmd_SOURCES += ${BASE_SRC}
@@ -1944,6 +1953,15 @@ check_PROGRAMS = manaplustests
manaplustests_CXXFLAGS = ${manaplus_CXXFLAGS} \
-DUNITTESTS
manaplustests_LDFLAGS =
+if ENABLE_PUGIXML
+manaplustests_CXXFLAGS += -DENABLE_PUGIXML
+endif
+if ENABLE_LIBXML
+manaplustests_CXXFLAGS += -DENABLE_LIBXML
+endif
+if ENABLE_TINYXML2
+manaplustests_CXXFLAGS += -DENABLE_TINYXML2
+endif
if USE_PHYSFS
manaplustests_CXXFLAGS += -DUSE_PHYSFS
endif
diff --git a/src/configuration.cpp b/src/configuration.cpp
index 40d701e76..cabd2ddfa 100644
--- a/src/configuration.cpp
+++ b/src/configuration.cpp
@@ -703,7 +703,7 @@ bool Configuration::resetBoolValue(const std::string &key)
}
-void ConfigurationObject::initFromXML(const XmlNodePtrConst parentNode)
+void ConfigurationObject::initFromXML(XmlNodeConstPtrConst parentNode)
{
clear();
@@ -773,7 +773,7 @@ void Configuration::init(const std::string &filename,
return;
}
- const XmlNodePtrConst rootNode = doc.rootNode();
+ XmlNodeConstPtrConst rootNode = doc.rootNode();
if (!rootNode || !xmlNameEqual(rootNode, "configuration"))
{
@@ -793,7 +793,7 @@ void Configuration::reInit()
return;
}
- const XmlNodePtrConst rootNode = doc.rootNode();
+ XmlNodeConstPtrConst rootNode = doc.rootNode();
if (!rootNode || !xmlNameEqual(rootNode, "configuration"))
{
@@ -804,7 +804,7 @@ void Configuration::reInit()
initFromXML(rootNode);
}
-void ConfigurationObject::writeToXML(const XmlTextWriterPtr writer)
+void ConfigurationObject::writeToXML(XmlTextWriterPtr writer A_UNUSED)
{
FOR_EACH (Options::const_iterator, i, mOptions)
{
@@ -874,7 +874,7 @@ void Configuration::write()
fclose(testFile);
}
- const XmlTextWriterPtr writer = XmlNewTextWriterFilename(
+ XmlTextWriterPtr writer = XmlNewTextWriterFilename(
mConfigPath.c_str(), 0);
if (!writer)
@@ -889,11 +889,13 @@ void Configuration::write()
XmlTextWriterSetIndent(writer, 1);
XmlTextWriterStartDocument(writer, nullptr, nullptr, nullptr);
// xmlTextWriterStartDocument(writer, nullptr, "utf8", nullptr);
- XmlTextWriterStartElement(writer, "configuration");
+ XmlTextWriterStartRootElement(writer, "configuration");
writeToXML(writer);
XmlTextWriterEndDocument(writer);
+ XmlSaveTextWriterFilename(writer,
+ mConfigPath.c_str());
XmlFreeTextWriter(writer);
BLOCK_END("Configuration::write")
}
diff --git a/src/configuration.h b/src/configuration.h
index 9e46221b8..f1eda72d6 100644
--- a/src/configuration.h
+++ b/src/configuration.h
@@ -208,8 +208,8 @@ class ConfigurationObject notfinal
protected:
ConfigurationObject();
- virtual void initFromXML(const XmlNodePtrConst parentNode);
- virtual void writeToXML(const XmlTextWriterPtr writer);
+ virtual void initFromXML(XmlNodeConstPtrConst parentNode);
+ virtual void writeToXML(XmlTextWriterPtr writer);
void deleteList(const std::string &name);
diff --git a/src/effectmanager.cpp b/src/effectmanager.cpp
index 875deb36a..4b2cc9188 100644
--- a/src/effectmanager.cpp
+++ b/src/effectmanager.cpp
@@ -51,7 +51,7 @@ void EffectManager::loadXmlFile(const std::string &fileName,
const SkipError skipError)
{
XML::Document doc(fileName, UseVirtFs_true, skipError);
- const XmlNodePtrConst root = doc.rootNode();
+ XmlNodeConstPtrConst root = doc.rootNode();
if (!root ||
!xmlNameEqual(root, "being-effects"))
diff --git a/src/gui/theme.cpp b/src/gui/theme.cpp
index 2d33d36e7..94826e537 100644
--- a/src/gui/theme.cpp
+++ b/src/gui/theme.cpp
@@ -406,7 +406,7 @@ Skin *Theme::readSkin(const std::string &filename, const bool full)
SkipError_true);
if (!doc)
return nullptr;
- const XmlNodePtr rootNode = doc->rootNode();
+ XmlNodeConstPtr rootNode = doc->rootNode();
if (!rootNode || !xmlNameEqual(rootNode, "skinset"))
{
doc->decRef();
@@ -1011,7 +1011,7 @@ void Theme::loadColors(std::string file)
SkipError_false);
if (!doc)
return;
- const XmlNodePtrConst root = doc->rootNode();
+ XmlNodeConstPtrConst root = doc->rootNode();
if (!root || !xmlNameEqual(root, "colors"))
{
@@ -1220,7 +1220,7 @@ ThemeInfo *Theme::loadInfo(const std::string &themeName)
SkipError_false);
if (!doc)
return nullptr;
- const XmlNodePtrConst rootNode = doc->rootNode();
+ XmlNodeConstPtrConst rootNode = doc->rootNode();
if (!rootNode || !xmlNameEqual(rootNode, "info"))
{
diff --git a/src/gui/windows/equipmentwindow.cpp b/src/gui/windows/equipmentwindow.cpp
index 1910bb8e1..c0ed8b5d4 100644
--- a/src/gui/windows/equipmentwindow.cpp
+++ b/src/gui/windows/equipmentwindow.cpp
@@ -630,7 +630,7 @@ void EquipmentWindow::fillBoxes()
paths.getStringValue("equipmentWindowFile"),
UseVirtFs_true,
SkipError_false);
- const XmlNodePtr root = doc->rootNode();
+ XmlNodeConstPtr root = doc->rootNode();
if (!root)
{
delete doc;
@@ -666,7 +666,7 @@ void EquipmentWindow::addDefaultPage()
}
}
-void EquipmentWindow::loadPage(const XmlNodePtr node)
+void EquipmentWindow::loadPage(XmlNodeConstPtr node)
{
if (!node)
return;
@@ -682,7 +682,7 @@ void EquipmentWindow::loadPage(const XmlNodePtr node)
}
}
-void EquipmentWindow::loadPlayerBox(const XmlNodePtr playerBoxNode,
+void EquipmentWindow::loadPlayerBox(XmlNodeConstPtr playerBoxNode,
const int page)
{
EquipmentPage *const data = mPages[page];
@@ -692,7 +692,7 @@ void EquipmentWindow::loadPlayerBox(const XmlNodePtr playerBoxNode,
data->height = XML::getProperty(playerBoxNode, "height", 168);
}
-void EquipmentWindow::loadSlot(const XmlNodePtr slotNode,
+void EquipmentWindow::loadSlot(XmlNodeConstPtr slotNode,
const ImageSet *const imageset,
const int page)
{
@@ -739,7 +739,7 @@ void EquipmentWindow::prepareSlotNames()
XML::Document doc(paths.getStringValue("equipmentSlotsFile"),
UseVirtFs_true,
SkipError_false);
- const XmlNodePtrConst root = doc.rootNode();
+ XmlNodeConstPtrConst root = doc.rootNode();
if (!root)
return;
diff --git a/src/gui/windows/equipmentwindow.h b/src/gui/windows/equipmentwindow.h
index d45dc6a41..00db41fd8 100644
--- a/src/gui/windows/equipmentwindow.h
+++ b/src/gui/windows/equipmentwindow.h
@@ -114,13 +114,13 @@ class EquipmentWindow final : public Window,
void addBox(const int idx, int x, int y, const int imageIndex);
- void loadWindow(const XmlNodePtrConst windowNode);
+ void loadWindow(XmlNodeConstPtrConst windowNode);
- void loadPage(const XmlNodePtr node);
+ void loadPage(XmlNodeConstPtr node);
- void loadPlayerBox(const XmlNodePtr playerBoxNode, const int page);
+ void loadPlayerBox(XmlNodeConstPtr playerBoxNode, const int page);
- void loadSlot(const XmlNodePtr slotNode,
+ void loadSlot(XmlNodeConstPtr slotNode,
const ImageSet *const imageset,
const int page);
diff --git a/src/gui/windows/serverdialog.cpp b/src/gui/windows/serverdialog.cpp
index e1fe669ee..d04deb0fb 100644
--- a/src/gui/windows/serverdialog.cpp
+++ b/src/gui/windows/serverdialog.cpp
@@ -449,7 +449,7 @@ void ServerDialog::downloadServerList()
config.setValue("serverslistupdate", getDateString());
}
-static void loadHostsGroup(const XmlNodePtr node,
+static void loadHostsGroup(XmlNodeConstPtr node,
ServerInfo &server)
{
HostsGroup group;
@@ -482,7 +482,7 @@ void ServerDialog::loadServers(const bool addNew)
branding.getStringValue("onlineServerFile")),
UseVirtFs_false,
SkipError_false);
- const XmlNodePtr rootNode = doc.rootNode();
+ XmlNodeConstPtr rootNode = doc.rootNode();
if (!rootNode || !xmlNameEqual(rootNode, "serverlist"))
{
diff --git a/src/gui/windows/skilldialog.cpp b/src/gui/windows/skilldialog.cpp
index eec6a2ac5..992ec3a1f 100644
--- a/src/gui/windows/skilldialog.cpp
+++ b/src/gui/windows/skilldialog.cpp
@@ -436,7 +436,7 @@ void SkillDialog::loadXmlFile(const std::string &fileName,
}
}
-SkillInfo *SkillDialog::loadSkill(XmlNodePtr node,
+SkillInfo *SkillDialog::loadSkill(XmlNodeConstPtr node,
SkillModel *const model)
{
int id = XML::getIntProperty(node, "id", -1, -1, 1000000);
@@ -492,7 +492,7 @@ SkillInfo *SkillDialog::loadSkill(XmlNodePtr node,
return skill;
}
-void SkillDialog::loadSkillData(XmlNodePtr node,
+void SkillDialog::loadSkillData(XmlNodeConstPtr node,
SkillInfo *const skill)
{
if (!skill)
diff --git a/src/gui/windows/skilldialog.h b/src/gui/windows/skilldialog.h
index 80e848f41..0c19f9308 100644
--- a/src/gui/windows/skilldialog.h
+++ b/src/gui/windows/skilldialog.h
@@ -209,10 +209,10 @@ class SkillDialog final : public Window,
void addSkillDuration(SkillInfo *const skill);
- SkillInfo *loadSkill(XmlNodePtr node,
+ SkillInfo *loadSkill(XmlNodeConstPtr node,
SkillModel *const model);
- void loadSkillData(XmlNodePtr node,
+ void loadSkillData(XmlNodeConstPtr node,
SkillInfo *const skill);
void addDefaultTab();
diff --git a/src/gui/windows/updaterwindow.cpp b/src/gui/windows/updaterwindow.cpp
index 2bff2e8cd..783b36635 100644
--- a/src/gui/windows/updaterwindow.cpp
+++ b/src/gui/windows/updaterwindow.cpp
@@ -79,7 +79,7 @@ static std::vector<UpdateFile> loadXMLFile(const std::string &fileName,
{
std::vector<UpdateFile> files;
XML::Document doc(fileName, UseVirtFs_false, SkipError_false);
- const XmlNodePtrConst rootNode = doc.rootNode();
+ XmlNodeConstPtrConst rootNode = doc.rootNode();
if (!rootNode || !xmlNameEqual(rootNode, "updates"))
{
diff --git a/src/particle/particle.cpp b/src/particle/particle.cpp
index 9f5708b26..d518a15a3 100644
--- a/src/particle/particle.cpp
+++ b/src/particle/particle.cpp
@@ -417,7 +417,7 @@ Particle *Particle::addEffect(const std::string &restrict particleEffectFile,
SkipError_false);
if (!doc)
return nullptr;
- const XmlNodePtrConst rootNode = doc->rootNode();
+ XmlNodeConstPtrConst rootNode = doc->rootNode();
if (!rootNode || !xmlNameEqual(rootNode, "effect"))
{
diff --git a/src/particle/particleemitter.cpp b/src/particle/particleemitter.cpp
index 9492a01b1..09008b363 100644
--- a/src/particle/particleemitter.cpp
+++ b/src/particle/particleemitter.cpp
@@ -48,7 +48,7 @@ static const float DEG_RAD_FACTOR = 0.017453293F;
typedef std::vector<ImageSet*>::const_iterator ImageSetVectorCIter;
typedef std::list<ParticleEmitter>::const_iterator ParticleEmitterListCIter;
-ParticleEmitter::ParticleEmitter(const XmlNodePtrConst emitterNode,
+ParticleEmitter::ParticleEmitter(XmlNodeConstPtrConst emitterNode,
Particle *const target,
Map *const map, const int rotation,
const std::string& dyePalettes) :
diff --git a/src/particle/particleemitter.h b/src/particle/particleemitter.h
index 0d5110e77..7164d3e1d 100644
--- a/src/particle/particleemitter.h
+++ b/src/particle/particleemitter.h
@@ -43,7 +43,7 @@ class Particle;
class ParticleEmitter final
{
public:
- ParticleEmitter(const XmlNodePtrConst emitterNode,
+ ParticleEmitter(XmlNodeConstPtrConst emitterNode,
Particle *const target,
Map *const map,
const int rotation = 0,
diff --git a/src/particle/particleengine.cpp b/src/particle/particleengine.cpp
index b63d1c53c..2ac1d7166 100644
--- a/src/particle/particleengine.cpp
+++ b/src/particle/particleengine.cpp
@@ -142,7 +142,7 @@ Particle *ParticleEngine::addEffect(const std::string &restrict
if (!doc)
return nullptr;
- const XmlNodePtrConst rootNode = doc->rootNode();
+ XmlNodeConstPtrConst rootNode = doc->rootNode();
if (!rootNode || !xmlNameEqual(rootNode, "effect"))
{
diff --git a/src/particle/rotationalparticle.cpp b/src/particle/rotationalparticle.cpp
index c471bd01a..0693530d6 100644
--- a/src/particle/rotationalparticle.cpp
+++ b/src/particle/rotationalparticle.cpp
@@ -33,7 +33,7 @@ RotationalParticle::RotationalParticle(Animation *restrict const animation) :
mAnimation = new SimpleAnimation(animation);
}
-RotationalParticle::RotationalParticle(const XmlNodePtr animationNode,
+RotationalParticle::RotationalParticle(XmlNodeConstPtr animationNode,
const std::string &restrict
dyePalettes) :
ImageParticle(nullptr)
diff --git a/src/particle/rotationalparticle.h b/src/particle/rotationalparticle.h
index a51035c50..60c8461b1 100644
--- a/src/particle/rotationalparticle.h
+++ b/src/particle/rotationalparticle.h
@@ -34,7 +34,7 @@ class RotationalParticle final : public ImageParticle
public:
explicit RotationalParticle(Animation *restrict const animation);
- explicit RotationalParticle(const XmlNodePtr animationNode,
+ explicit RotationalParticle(XmlNodeConstPtr animationNode,
const std::string &restrict dyePalettes
= std::string());
diff --git a/src/resources/animation/simpleanimation.cpp b/src/resources/animation/simpleanimation.cpp
index ee489debb..7f20b5eef 100644
--- a/src/resources/animation/simpleanimation.cpp
+++ b/src/resources/animation/simpleanimation.cpp
@@ -49,7 +49,7 @@ SimpleAnimation::SimpleAnimation(Animation *const animation) :
{
}
-SimpleAnimation::SimpleAnimation(const XmlNodePtr animationNode,
+SimpleAnimation::SimpleAnimation(XmlNodeConstPtr animationNode,
const std::string& dyePalettes) :
mAnimation(new Animation("simple animation")),
mAnimationTime(0),
@@ -145,7 +145,7 @@ Image *SimpleAnimation::getCurrentImage() const
return nullptr;
}
-void SimpleAnimation::initializeAnimation(const XmlNodePtr animationNode,
+void SimpleAnimation::initializeAnimation(XmlNodeConstPtr animationNode,
const std::string &dyePalettes)
{
mInitialized = false;
diff --git a/src/resources/animation/simpleanimation.h b/src/resources/animation/simpleanimation.h
index 630477d42..2c068acff 100644
--- a/src/resources/animation/simpleanimation.h
+++ b/src/resources/animation/simpleanimation.h
@@ -50,7 +50,7 @@ class SimpleAnimation final
/**
* Creates a simple animation that creates its animation from XML Data.
*/
- SimpleAnimation(const XmlNodePtr animationNode,
+ SimpleAnimation(XmlNodeConstPtr animationNode,
const std::string& dyePalettes);
A_DELETE_COPY(SimpleAnimation)
@@ -74,7 +74,7 @@ class SimpleAnimation final
Image *getCurrentImage() const A_WARN_UNUSED;
private:
- void initializeAnimation(const XmlNodePtr animationNode,
+ void initializeAnimation(XmlNodeConstPtr animationNode,
const std::string&
dyePalettes = std::string());
diff --git a/src/resources/db/avatardb.cpp b/src/resources/db/avatardb.cpp
index 8af32cd6c..eddf08b29 100644
--- a/src/resources/db/avatardb.cpp
+++ b/src/resources/db/avatardb.cpp
@@ -57,7 +57,7 @@ void AvatarDB::loadXmlFile(const std::string &fileName,
XML::Document doc(fileName,
UseVirtFs_true,
skipError);
- const XmlNodePtrConst rootNode = doc.rootNode();
+ XmlNodeConstPtrConst rootNode = doc.rootNode();
if (!rootNode || !xmlNameEqual(rootNode, "avatars"))
{
diff --git a/src/resources/db/chardb.cpp b/src/resources/db/chardb.cpp
index eb96538c5..b0984a56f 100644
--- a/src/resources/db/chardb.cpp
+++ b/src/resources/db/chardb.cpp
@@ -52,7 +52,7 @@ void CharDB::load()
paths.getStringValue("charCreationFile"),
UseVirtFs_true,
SkipError_false);
- const XmlNodePtrConst root = doc->rootNode();
+ XmlNodeConstPtrConst root = doc->rootNode();
if (!root || !xmlNameEqual(root, "chars"))
{
@@ -109,7 +109,7 @@ void CharDB::load()
mLoaded = true;
}
-void CharDB::loadMinMax(const XmlNodePtr node,
+void CharDB::loadMinMax(XmlNodeConstPtr node,
unsigned *restrict const min,
unsigned *restrict const max)
{
diff --git a/src/resources/db/chardb.h b/src/resources/db/chardb.h
index 128777827..9715497f1 100644
--- a/src/resources/db/chardb.h
+++ b/src/resources/db/chardb.h
@@ -43,7 +43,7 @@ namespace CharDB
*/
void unload();
- void loadMinMax(const XmlNodePtr node,
+ void loadMinMax(XmlNodeConstPtr node,
unsigned *restrict const min,
unsigned *restrict const max);
diff --git a/src/resources/db/colordb.cpp b/src/resources/db/colordb.cpp
index 9261e8a76..cf377eca1 100644
--- a/src/resources/db/colordb.cpp
+++ b/src/resources/db/colordb.cpp
@@ -81,7 +81,7 @@ void ColorDB::loadHair(const std::string &fileName,
XML::Document *doc = new XML::Document(fileName,
UseVirtFs_true,
skipError);
- const XmlNodePtrConst root = doc->rootNode();
+ XmlNodeConstPtrConst root = doc->rootNode();
if (!root || !xmlNameEqual(root, "colors"))
{
@@ -127,7 +127,7 @@ void ColorDB::loadColorLists(const std::string &fileName,
XML::Document *doc = new XML::Document(fileName,
UseVirtFs_true,
skipError);
- const XmlNodePtrConst root = doc->rootNode();
+ XmlNodeConstPtrConst root = doc->rootNode();
if (!root)
{
delete doc;
diff --git a/src/resources/db/commandsdb.cpp b/src/resources/db/commandsdb.cpp
index 2338287c2..115046b1d 100644
--- a/src/resources/db/commandsdb.cpp
+++ b/src/resources/db/commandsdb.cpp
@@ -62,7 +62,7 @@ void CommandsDB::loadXmlFile(const std::string &fileName,
const SkipError skipError)
{
XML::Document doc(fileName, UseVirtFs_true, skipError);
- const XmlNodePtrConst rootNode = doc.rootNode();
+ XmlNodeConstPtrConst rootNode = doc.rootNode();
if (!rootNode || !xmlNameEqual(rootNode, "commands"))
{
diff --git a/src/resources/db/deaddb.cpp b/src/resources/db/deaddb.cpp
index eddc4ff42..53a0f6e0f 100644
--- a/src/resources/db/deaddb.cpp
+++ b/src/resources/db/deaddb.cpp
@@ -52,7 +52,7 @@ void DeadDB::loadXmlFile(const std::string &fileName,
XML::Document *doc = new XML::Document(fileName,
UseVirtFs_true,
skipError);
- const XmlNodePtrConst root = doc->rootNode();
+ XmlNodeConstPtrConst root = doc->rootNode();
if (!root || !xmlNameEqual(root, "messages"))
{
diff --git a/src/resources/db/elementaldb.cpp b/src/resources/db/elementaldb.cpp
index 21788b08e..2a626a10e 100644
--- a/src/resources/db/elementaldb.cpp
+++ b/src/resources/db/elementaldb.cpp
@@ -55,7 +55,7 @@ void ElementalDb::loadXmlFile(const std::string &fileName,
const SkipError skipError)
{
XML::Document doc(fileName, UseVirtFs_true, skipError);
- const XmlNodePtr rootNode = doc.rootNode();
+ XmlNodeConstPtr rootNode = doc.rootNode();
if (!rootNode || !xmlNameEqual(rootNode, "elementals"))
{
diff --git a/src/resources/db/homunculusdb.cpp b/src/resources/db/homunculusdb.cpp
index 77c1b4323..cf627dc01 100644
--- a/src/resources/db/homunculusdb.cpp
+++ b/src/resources/db/homunculusdb.cpp
@@ -56,7 +56,7 @@ void HomunculusDB::loadXmlFile(const std::string &fileName,
const SkipError skipError)
{
XML::Document doc(fileName, UseVirtFs_true, skipError);
- const XmlNodePtr rootNode = doc.rootNode();
+ XmlNodeConstPtr rootNode = doc.rootNode();
if (!rootNode || !xmlNameEqual(rootNode, "homunculuses"))
{
diff --git a/src/resources/db/itemdb.cpp b/src/resources/db/itemdb.cpp
index e347528eb..e6affd378 100644
--- a/src/resources/db/itemdb.cpp
+++ b/src/resources/db/itemdb.cpp
@@ -64,15 +64,15 @@ namespace
// Forward declarations
static void loadSpriteRef(ItemInfo *const itemInfo,
- const XmlNodePtr node) A_NONNULL(1);
+ XmlNodeConstPtr node) A_NONNULL(1);
static void loadSoundRef(ItemInfo *const itemInfo,
- const XmlNodePtr node) A_NONNULL(1);
+ XmlNodeConstPtr node) A_NONNULL(1);
static void loadFloorSprite(SpriteDisplay &display,
- const XmlNodePtrConst node);
+ XmlNodeConstPtrConst node);
static void loadReplaceSprite(ItemInfo *const itemInfo,
- const XmlNodePtr replaceNode) A_NONNULL(1);
+ XmlNodeConstPtr replaceNode) A_NONNULL(1);
static void loadOrderSprite(ItemInfo *const itemInfo,
- const XmlNodePtr node,
+ XmlNodeConstPtr node,
const bool drawAfter) A_NONNULL(1);
static int parseSpriteName(const std::string &name);
static int parseDirectionName(const std::string &name);
@@ -125,7 +125,7 @@ static std::string useButton2FromItemType(const ItemDbTypeT &type)
}
static void readFields(std::string &effect,
- const XmlNodePtr node,
+ XmlNodeConstPtr node,
const ItemFieldDb::FieldInfos &fields)
{
FOR_EACH (ItemFieldDb::FieldInfos::const_iterator, it, fields)
@@ -243,7 +243,7 @@ void ItemDB::loadXmlFile(const std::string &fileName,
XML::Document doc(fileName,
UseVirtFs_true,
skipError);
- const XmlNodePtrConst rootNode = doc.rootNode();
+ XmlNodeConstPtrConst rootNode = doc.rootNode();
if (!rootNode || !xmlNameEqual(rootNode, "items"))
{
@@ -829,7 +829,7 @@ static int parseDirectionName(const std::string &name)
return id;
}
-static void loadSpriteRef(ItemInfo *const itemInfo, const XmlNodePtr node)
+static void loadSpriteRef(ItemInfo *const itemInfo, XmlNodeConstPtr node)
{
const std::string gender = XML::getProperty(node, "gender", "unisex");
if (!node || !XmlHaveChildContent(node))
@@ -846,7 +846,7 @@ static void loadSpriteRef(ItemInfo *const itemInfo, const XmlNodePtr node)
itemInfo->setSprite(filename, Gender::OTHER, race);
}
-static void loadSoundRef(ItemInfo *const itemInfo, const XmlNodePtr node)
+static void loadSoundRef(ItemInfo *const itemInfo, XmlNodeConstPtr node)
{
if (!node || !XmlHaveChildContent(node))
return;
@@ -868,7 +868,7 @@ static void loadSoundRef(ItemInfo *const itemInfo, const XmlNodePtr node)
}
static void loadFloorSprite(SpriteDisplay &display,
- const XmlNodePtrConst floorNode)
+ XmlNodeConstPtrConst floorNode)
{
if (!floorNode)
return;
@@ -892,7 +892,7 @@ static void loadFloorSprite(SpriteDisplay &display,
}
static void loadReplaceSprite(ItemInfo *const itemInfo,
- const XmlNodePtr replaceNode)
+ XmlNodeConstPtr replaceNode)
{
if (!replaceNode)
return;
@@ -1025,7 +1025,7 @@ static void loadReplaceSprite(ItemInfo *const itemInfo,
}
static void loadOrderSprite(ItemInfo *const itemInfo,
- const XmlNodePtr node,
+ XmlNodeConstPtr node,
const bool drawAfter)
{
const int sprite = parseSpriteName(XML::getProperty(node, "name", ""));
diff --git a/src/resources/db/itemfielddb.cpp b/src/resources/db/itemfielddb.cpp
index 6ba76db2c..65020e824 100644
--- a/src/resources/db/itemfielddb.cpp
+++ b/src/resources/db/itemfielddb.cpp
@@ -51,7 +51,7 @@ void ItemFieldDb::load()
mLoaded = true;
}
-static void loadFields(const XmlNodePtr groupNode,
+static void loadFields(XmlNodeConstPtr groupNode,
ItemFieldDb::FieldInfos &fields1,
ItemFieldDb::FieldInfos &fields2)
{
@@ -105,7 +105,7 @@ void ItemFieldDb::loadXmlFile(const std::string &fileName,
XML::Document doc(fileName,
UseVirtFs_true,
skipError);
- const XmlNodePtrConst rootNode = doc.rootNode();
+ XmlNodeConstPtrConst rootNode = doc.rootNode();
if (!rootNode || !xmlNameEqual(rootNode, "itemfields"))
{
diff --git a/src/resources/db/mapdb.cpp b/src/resources/db/mapdb.cpp
index b9c6818b3..14c10b3b8 100644
--- a/src/resources/db/mapdb.cpp
+++ b/src/resources/db/mapdb.cpp
@@ -66,7 +66,7 @@ void MapDB::loadRemapXmlFile(const std::string &fileName,
UseVirtFs_true,
skipError);
- const XmlNodePtrConst root = doc->rootNode();
+ XmlNodeConstPtrConst root = doc->rootNode();
if (!root)
{
delete doc;
@@ -153,7 +153,7 @@ void MapDB::loadInfo(const std::string &fileName,
XML::Document *doc = new XML::Document(fileName,
UseVirtFs_true,
skipError);
- const XmlNodePtrConst root = doc->rootNode();
+ XmlNodeConstPtrConst root = doc->rootNode();
if (!root)
{
delete doc;
diff --git a/src/resources/db/mercenarydb.cpp b/src/resources/db/mercenarydb.cpp
index 0e2fdcae0..bc1b20840 100644
--- a/src/resources/db/mercenarydb.cpp
+++ b/src/resources/db/mercenarydb.cpp
@@ -58,7 +58,7 @@ void MercenaryDB::loadXmlFile(const std::string &fileName,
XML::Document doc(fileName,
UseVirtFs_true,
skipError);
- const XmlNodePtr rootNode = doc.rootNode();
+ XmlNodeConstPtr rootNode = doc.rootNode();
if (!rootNode || !xmlNameEqual(rootNode, "mercenaries"))
{
diff --git a/src/resources/db/moddb.cpp b/src/resources/db/moddb.cpp
index 4e67cb612..7a23e255f 100644
--- a/src/resources/db/moddb.cpp
+++ b/src/resources/db/moddb.cpp
@@ -52,7 +52,7 @@ void ModDB::loadXmlFile(const std::string &fileName,
const SkipError skipError)
{
XML::Document doc(fileName, UseVirtFs_true, skipError);
- const XmlNodePtrConst rootNode = doc.rootNode();
+ XmlNodeConstPtrConst rootNode = doc.rootNode();
if (!rootNode || !xmlNameEqual(rootNode, "mods"))
{
diff --git a/src/resources/db/monsterdb.cpp b/src/resources/db/monsterdb.cpp
index 2c87f19f8..1ed0caa27 100644
--- a/src/resources/db/monsterdb.cpp
+++ b/src/resources/db/monsterdb.cpp
@@ -60,7 +60,7 @@ void MonsterDB::loadXmlFile(const std::string &fileName,
const SkipError skipError)
{
XML::Document doc(fileName, UseVirtFs_true, skipError);
- const XmlNodePtr rootNode = doc.rootNode();
+ XmlNodeConstPtr rootNode = doc.rootNode();
if (!rootNode || !xmlNameEqual(rootNode, "monsters"))
{
diff --git a/src/resources/db/npcdb.cpp b/src/resources/db/npcdb.cpp
index 9c77950b7..9be217819 100644
--- a/src/resources/db/npcdb.cpp
+++ b/src/resources/db/npcdb.cpp
@@ -61,7 +61,7 @@ void NPCDB::loadXmlFile(const std::string &fileName,
const SkipError skipError)
{
XML::Document doc(fileName, UseVirtFs_true, skipError);
- const XmlNodePtrConst rootNode = doc.rootNode();
+ XmlNodeConstPtrConst rootNode = doc.rootNode();
if (!rootNode || !xmlNameEqual(rootNode, "npcs"))
{
diff --git a/src/resources/db/npcdialogdb.cpp b/src/resources/db/npcdialogdb.cpp
index 6ab48e4bd..76eaea7c5 100644
--- a/src/resources/db/npcdialogdb.cpp
+++ b/src/resources/db/npcdialogdb.cpp
@@ -50,7 +50,7 @@ void NpcDialogDB::load()
}
static void loadNpcDialogMenu(NpcDialogInfo *const dialog,
- const XmlNodePtrConst node)
+ XmlNodeConstPtrConst node)
{
for_each_xml_child_node(childNode, node)
{
@@ -132,7 +132,7 @@ static void loadNpcDialogInventory(NpcDialogInfo *const dialog,
}
static void loadNpcDialog(NpcDialogInfo *const dialog,
- const XmlNodePtrConst node)
+ XmlNodeConstPtrConst node)
{
for_each_xml_child_node(childNode, node)
{
@@ -154,7 +154,7 @@ void NpcDialogDB::loadXmlFile(const std::string &fileName,
UseVirtFs_true,
skipError);
- const XmlNodePtrConst root = doc->rootNode();
+ XmlNodeConstPtrConst root = doc->rootNode();
if (!root)
{
delete doc;
diff --git a/src/resources/db/petdb.cpp b/src/resources/db/petdb.cpp
index d3d166675..5dca543a0 100644
--- a/src/resources/db/petdb.cpp
+++ b/src/resources/db/petdb.cpp
@@ -59,7 +59,7 @@ void PETDB::loadXmlFile(const std::string &fileName,
XML::Document doc(fileName,
UseVirtFs_true,
skipError);
- const XmlNodePtrConst rootNode = doc.rootNode();
+ XmlNodeConstPtrConst rootNode = doc.rootNode();
if (!rootNode || !xmlNameEqual(rootNode, "pets"))
{
diff --git a/src/resources/db/questdb.cpp b/src/resources/db/questdb.cpp
index 91dd44ac4..41b3b0062 100644
--- a/src/resources/db/questdb.cpp
+++ b/src/resources/db/questdb.cpp
@@ -52,7 +52,7 @@ void QuestDb::load()
}
static void loadQuest(const int var,
- const XmlNodePtr node)
+ XmlNodeConstPtr node)
{
if (!node)
return;
@@ -155,7 +155,7 @@ static void loadQuest(const int var,
}
static void loadEffect(const int var,
- const XmlNodePtr node)
+ XmlNodeConstPtr node)
{
QuestEffect *const effect = new QuestEffect;
effect->map = XML::getProperty(node, "map", "");
@@ -180,7 +180,7 @@ void QuestDb::loadXmlFile(const std::string &fileName,
XML::Document doc(fileName,
UseVirtFs_true,
skipError);
- const XmlNodePtrConst root = doc.rootNode();
+ XmlNodeConstPtrConst root = doc.rootNode();
if (!root)
return;
diff --git a/src/resources/db/skillunitdb.cpp b/src/resources/db/skillunitdb.cpp
index 8beae1ac2..cec48a4a1 100644
--- a/src/resources/db/skillunitdb.cpp
+++ b/src/resources/db/skillunitdb.cpp
@@ -57,7 +57,7 @@ void SkillUnitDb::loadXmlFile(const std::string &fileName,
const SkipError skipError)
{
XML::Document doc(fileName, UseVirtFs_true, skipError);
- const XmlNodePtrConst rootNode = doc.rootNode();
+ XmlNodeConstPtrConst rootNode = doc.rootNode();
if (!rootNode || !xmlNameEqual(rootNode, "skillunits"))
{
diff --git a/src/resources/db/sounddb.cpp b/src/resources/db/sounddb.cpp
index a62045505..d58a585ee 100644
--- a/src/resources/db/sounddb.cpp
+++ b/src/resources/db/sounddb.cpp
@@ -49,7 +49,7 @@ void SoundDB::loadXmlFile(const std::string &fileName,
XML::Document *doc = new XML::Document(fileName,
UseVirtFs_true,
skipError);
- const XmlNodePtrConst root = doc->rootNode();
+ XmlNodeConstPtrConst root = doc->rootNode();
if (!root || !xmlNameEqual(root, "sounds"))
{
diff --git a/src/resources/db/statdb.cpp b/src/resources/db/statdb.cpp
index e2d4292a1..12126f36a 100644
--- a/src/resources/db/statdb.cpp
+++ b/src/resources/db/statdb.cpp
@@ -96,7 +96,7 @@ void StatDb::load()
mLoaded = true;
}
-static void loadBasicStats(const XmlNodePtr rootNode)
+static void loadBasicStats(XmlNodeConstPtr rootNode)
{
const int maxAttr = static_cast<int>(Attributes::MAX_ATTRIBUTE);
for_each_xml_child_node(node, rootNode)
@@ -131,7 +131,7 @@ static void loadBasicStats(const XmlNodePtr rootNode)
}
}
-static void loadStats(const XmlNodePtr rootNode,
+static void loadStats(XmlNodeConstPtr rootNode,
const std::string &page)
{
const int maxAttr = static_cast<int>(Attributes::MAX_ATTRIBUTE);
@@ -173,7 +173,7 @@ void StatDb::loadXmlFile(const std::string &fileName,
XML::Document doc(fileName,
UseVirtFs_true,
skipError);
- const XmlNodePtrConst rootNode = doc.rootNode();
+ XmlNodeConstPtrConst rootNode = doc.rootNode();
if (!rootNode || !xmlNameEqual(rootNode, "stats"))
{
diff --git a/src/resources/db/statuseffectdb.cpp b/src/resources/db/statuseffectdb.cpp
index fea06230e..58c5cf30d 100644
--- a/src/resources/db/statuseffectdb.cpp
+++ b/src/resources/db/statuseffectdb.cpp
@@ -88,7 +88,7 @@ void StatusEffectDB::loadXmlFile(const std::string &fileName,
const SkipError skipError)
{
XML::Document doc(fileName, UseVirtFs_true, skipError);
- const XmlNodePtrConst rootNode = doc.rootNode();
+ XmlNodeConstPtrConst rootNode = doc.rootNode();
if (!rootNode || !xmlNameEqual(rootNode, "status-effects"))
{
diff --git a/src/resources/db/unitsdb.cpp b/src/resources/db/unitsdb.cpp
index 0c06f6a4c..0437c81e4 100644
--- a/src/resources/db/unitsdb.cpp
+++ b/src/resources/db/unitsdb.cpp
@@ -191,7 +191,7 @@ void UnitsDb::loadXmlFile(const std::string &fileName,
const SkipError skipError)
{
XML::Document doc(fileName, UseVirtFs_true, skipError);
- const XmlNodePtrConst root = doc.rootNode();
+ XmlNodeConstPtrConst root = doc.rootNode();
if (!root || !xmlNameEqual(root, "units"))
{
diff --git a/src/resources/mapreader.cpp b/src/resources/mapreader.cpp
index 59ddaddb7..2fa44f57e 100644
--- a/src/resources/mapreader.cpp
+++ b/src/resources/mapreader.cpp
@@ -501,7 +501,7 @@ Map *MapReader::readMap(XmlNodePtrConst node, const std::string &path)
return map;
}
-void MapReader::readProperties(const XmlNodePtrConst node,
+void MapReader::readProperties(XmlNodeConstPtrConst node,
Properties *const props)
{
BLOCK_START("MapReader::readProperties")
@@ -635,7 +635,7 @@ inline static void setTile(Map *const map,
}
}
-bool MapReader::readBase64Layer(const XmlNodePtrConst childNode,
+bool MapReader::readBase64Layer(XmlNodeConstPtrConst childNode,
Map *const map,
MapLayer *const layer,
const MapLayerTypeT &layerType,
@@ -772,7 +772,7 @@ bool MapReader::readBase64Layer(const XmlNodePtrConst childNode,
return true;
}
-bool MapReader::readCsvLayer(const XmlNodePtrConst childNode,
+bool MapReader::readCsvLayer(XmlNodeConstPtrConst childNode,
Map *const map,
MapLayer *const layer,
const MapLayerTypeT &layerType,
@@ -854,7 +854,7 @@ bool MapReader::readCsvLayer(const XmlNodePtrConst childNode,
return true;
}
-void MapReader::readLayer(const XmlNodePtr node, Map *const map)
+void MapReader::readLayer(XmlNodeConstPtr node, Map *const map)
{
if (!node)
return;
diff --git a/src/resources/mapreader.h b/src/resources/mapreader.h
index 30ce41c93..2fd1e067c 100644
--- a/src/resources/mapreader.h
+++ b/src/resources/mapreader.h
@@ -63,7 +63,7 @@ class MapReader final
/**
* Reads a map layer and adds it to the given map.
*/
- static void readLayer(const XmlNodePtr node,
+ static void readLayer(XmlNodeConstPtr node,
Map *const map) A_NONNULL(2);
#ifdef USE_OPENGL
@@ -79,10 +79,10 @@ class MapReader final
* @param props The Properties instance to which the properties will
* be assigned.
*/
- static void readProperties(const XmlNodePtrConst node,
+ static void readProperties(XmlNodeConstPtrConst node,
Properties *const props) A_NONNULL(2);
- static bool readBase64Layer(const XmlNodePtrConst childNode,
+ static bool readBase64Layer(XmlNodeConstPtrConst childNode,
Map *const map,
MapLayer *const layer,
const MapLayerTypeT &layerType,
@@ -91,7 +91,7 @@ class MapReader final
int &restrict x, int &restrict y,
const int w, const int h) A_NONNULL(2);
- static bool readCsvLayer(const XmlNodePtrConst childNode,
+ static bool readCsvLayer(XmlNodeConstPtrConst childNode,
Map *const map,
MapLayer *const layer,
const MapLayerTypeT &layerType,
diff --git a/src/resources/sprite/spritedef.cpp b/src/resources/sprite/spritedef.cpp
index 3eb30d27d..fc168b53f 100644
--- a/src/resources/sprite/spritedef.cpp
+++ b/src/resources/sprite/spritedef.cpp
@@ -197,7 +197,7 @@ void SpriteDef::substituteActions()
substituteAction(SpriteAction::DEADRIDE, SpriteAction::DEAD);
}
-void SpriteDef::loadSprite(const XmlNodePtr spriteNode,
+void SpriteDef::loadSprite(XmlNodeConstPtr spriteNode,
const int variant,
const std::string &palettes)
{
@@ -230,7 +230,7 @@ void SpriteDef::loadSprite(const XmlNodePtr spriteNode,
BLOCK_END("SpriteDef::loadSprite")
}
-void SpriteDef::loadImageSet(const XmlNodePtr node,
+void SpriteDef::loadImageSet(XmlNodeConstPtr node,
const std::string &palettes)
{
const std::string name = XML::getProperty(node, "name", "");
@@ -275,7 +275,7 @@ const ImageSet *SpriteDef::getImageSet(const std::string &imageSetName) const
return si->second;
}
-void SpriteDef::loadAction(const XmlNodePtr node,
+void SpriteDef::loadAction(XmlNodeConstPtr node,
const int variant_offset)
{
if (!node)
@@ -315,7 +315,7 @@ void SpriteDef::loadAction(const XmlNodePtr node,
}
}
-void SpriteDef::loadAnimation(const XmlNodePtr animationNode,
+void SpriteDef::loadAnimation(XmlNodeConstPtr animationNode,
Action *const action,
const ImageSet *const imageSet0,
const int variant_offset) const
@@ -471,7 +471,7 @@ void SpriteDef::loadAnimation(const XmlNodePtr animationNode,
} // for frameNode
}
-void SpriteDef::includeSprite(const XmlNodePtr includeNode, const int variant)
+void SpriteDef::includeSprite(XmlNodeConstPtr includeNode, const int variant)
{
std::string filename = XML::getProperty(includeNode, "file", "");
@@ -493,7 +493,7 @@ void SpriteDef::includeSprite(const XmlNodePtr includeNode, const int variant)
SkipError_false);
if (!doc)
return;
- const XmlNodePtr rootNode = doc->rootNode();
+ XmlNodeConstPtr rootNode = doc->rootNode();
if (!rootNode || !xmlNameEqual(rootNode, "sprite"))
{
diff --git a/src/resources/sprite/spritedef.h b/src/resources/sprite/spritedef.h
index 3afc3c42c..fcb019d31 100644
--- a/src/resources/sprite/spritedef.h
+++ b/src/resources/sprite/spritedef.h
@@ -100,26 +100,26 @@ class SpriteDef final : public Resource
/**
* Loads a sprite element.
*/
- void loadSprite(const XmlNodePtr spriteNode,
+ void loadSprite(XmlNodeConstPtr spriteNode,
const int variant,
const std::string &palettes = "");
/**
* Loads an imageset element.
*/
- void loadImageSet(const XmlNodePtr node,
+ void loadImageSet(XmlNodeConstPtr node,
const std::string &palettes);
/**
* Loads an action element.
*/
- void loadAction(const XmlNodePtr node,
+ void loadAction(XmlNodeConstPtr node,
const int variant_offset);
/**
* Loads an animation element.
*/
- void loadAnimation(const XmlNodePtr animationNode,
+ void loadAnimation(XmlNodeConstPtr animationNode,
Action *const action,
const ImageSet *const imageSet,
const int variant_offset) const;
@@ -127,7 +127,7 @@ class SpriteDef final : public Resource
/**
* Include another sprite into this one.
*/
- void includeSprite(const XmlNodePtr includeNode,
+ void includeSprite(XmlNodeConstPtr includeNode,
const int variant);
const ImageSet *getImageSet(const std::string &imageSetName) const;
diff --git a/src/utils/xml.h b/src/utils/xml.h
index d15afd1b9..ac93231fc 100644
--- a/src/utils/xml.h
+++ b/src/utils/xml.h
@@ -23,6 +23,8 @@
#ifdef ENABLE_PUGIXML
#include "utils/xml/pugixml.h"
+#elif defined(ENABLE_TINYXML2)
+#include "utils/xml/tinyxml2.h"
#else // ENABLE_PUGIXML
#include "utils/xml/libxml.h"
#endif // ENABLE_PUGIXML
diff --git a/src/utils/xml/libxml.cpp b/src/utils/xml/libxml.cpp
index f6e38f08f..cb350a639 100644
--- a/src/utils/xml/libxml.cpp
+++ b/src/utils/xml/libxml.cpp
@@ -165,7 +165,7 @@ namespace XML
return mDoc ? xmlDocGetRootElement(mDoc) : nullptr;
}
- int getProperty(const XmlNodePtr node,
+ int getProperty(XmlNodeConstPtr node,
const char *const name,
int def)
{
@@ -181,7 +181,7 @@ namespace XML
return ret;
}
- int getIntProperty(const XmlNodePtr node,
+ int getIntProperty(XmlNodeConstPtr node,
const char *const name,
int def,
const int min,
@@ -202,7 +202,7 @@ namespace XML
return ret;
}
- double getFloatProperty(const XmlNodePtr node,
+ double getFloatProperty(XmlNodeConstPtr node,
const char *const name,
double def)
{
@@ -218,7 +218,7 @@ namespace XML
return ret;
}
- std::string getProperty(const XmlNodePtr node,
+ std::string getProperty(XmlNodeConstPtr node,
const char *const name,
const std::string &def)
{
@@ -233,7 +233,7 @@ namespace XML
return def;
}
- std::string langProperty(const XmlNodePtr node,
+ std::string langProperty(XmlNodeConstPtr node,
const char *const name,
const std::string &def)
{
@@ -244,7 +244,7 @@ namespace XML
return translator->getStr(str);
}
- bool getBoolProperty(const XmlNodePtr node,
+ bool getBoolProperty(XmlNodeConstPtr node,
const char *const name,
const bool def)
{
@@ -264,7 +264,7 @@ namespace XML
return def;
}
- XmlNodePtr findFirstChildByName(const XmlNodePtrConst parent,
+ XmlNodePtr findFirstChildByName(XmlNodeConstPtrConst parent,
const char *const name)
{
if (!parent)
diff --git a/src/utils/xml/libxml.h b/src/utils/xml/libxml.h
index 9ef419121..d9f707a5e 100644
--- a/src/utils/xml/libxml.h
+++ b/src/utils/xml/libxml.h
@@ -98,21 +98,21 @@ namespace XML
/**
* Gets an floating point property from an XmlNodePtr.
*/
- double getFloatProperty(const XmlNodePtr node,
+ double getFloatProperty(XmlNodeConstPtr node,
const char *const name,
double def) A_WARN_UNUSED;
/**
* Gets an integer property from an XmlNodePtr.
*/
- int getProperty(const XmlNodePtr node,
+ int getProperty(XmlNodeConstPtr node,
const char *const name,
int def) A_WARN_UNUSED;
/**
* Gets an integer property from an XmlNodePtr.
*/
- int getIntProperty(const XmlNodePtr node,
+ int getIntProperty(XmlNodeConstPtr node,
const char *const name,
int def,
const int min,
@@ -121,28 +121,28 @@ namespace XML
/**
* Gets a string property from an XmlNodePtr.
*/
- std::string getProperty(const XmlNodePtr node,
+ std::string getProperty(XmlNodeConstPtr node,
const char *const name,
const std::string &def) A_WARN_UNUSED;
/**
* Gets a translated string property from an XmlNodePtr.
*/
- std::string langProperty(const XmlNodePtr node,
+ std::string langProperty(XmlNodeConstPtr node,
const char *const name,
const std::string &def) A_WARN_UNUSED;
/**
* Gets a boolean property from an XmlNodePtr.
*/
- bool getBoolProperty(const XmlNodePtr node,
+ bool getBoolProperty(XmlNodeConstPtr node,
const char *const name,
const bool def) A_WARN_UNUSED;
/**
* Finds the first child node with the given name
*/
- XmlNodePtr findFirstChildByName(const XmlNodePtrConst parent,
+ XmlNodePtr findFirstChildByName(XmlNodeConstPtrConst parent,
const char *const name) A_WARN_UNUSED;
void initXML();
diff --git a/src/utils/xml/libxml.inc b/src/utils/xml/libxml.inc
index 1bf4fddd5..ec837f224 100644
--- a/src/utils/xml/libxml.inc
+++ b/src/utils/xml/libxml.inc
@@ -29,16 +29,20 @@ __XML_XMLWRITER_H__
#define XmlNodePtr xmlNodePtr
#define XmlNodePtrConst xmlNode *const
+#define XmlNodeConstPtr const xmlNodePtr
+#define XmlNodeConstPtrConst const xmlNode *const
#define XmlStrEqual(str1, str2) xmlStrEqual(str1, \
reinterpret_cast<const xmlChar*>(str2))
#define xmlNameEqual(node, str) xmlStrEqual((node)->name, \
reinterpret_cast<const xmlChar*>(str))
-#define XmlTextWriterPtr xmlTextWriterPtr
+#define XmlTextWriterPtr const xmlTextWriterPtr
#define xmlTypeEqual(node, typ) ((node)->type == (typ))
#define XmlHasProp(node, name) (xmlHasProp(node, \
reinterpret_cast<const xmlChar*>(name)) != nullptr)
#define XmlGetProp(node, name) xmlGetProp(node, \
reinterpret_cast<const xmlChar*>(name))
+#define XmlTextWriterStartRootElement(writer, name) \
+ xmlTextWriterStartElement(writer, reinterpret_cast<const xmlChar*>(name))
#define XmlTextWriterStartElement(writer, name) \
xmlTextWriterStartElement(writer, reinterpret_cast<const xmlChar*>(name))
#define XmlTextWriterEndElement(writer) xmlTextWriterEndElement(writer)
@@ -49,6 +53,7 @@ __XML_XMLWRITER_H__
#define XmlNodeGetContent(node) xmlNodeGetContent(node)
#define XmlNewTextWriterFilename(name, flags) \
xmlNewTextWriterFilename(name, flags)
+#define XmlSaveTextWriterFilename(writer, name)
#define XmlTextWriterSetIndent(writer, flags) \
xmlTextWriterSetIndent(writer, flags)
#define XmlTextWriterStartDocument(writer, p1, p2, p3) \
diff --git a/src/utils/xml/pugixml.cpp b/src/utils/xml/pugixml.cpp
index 8d5e8db59..1897bc943 100644
--- a/src/utils/xml/pugixml.cpp
+++ b/src/utils/xml/pugixml.cpp
@@ -176,7 +176,7 @@ namespace XML
return mDoc.first_child();
}
- int getProperty(const XmlNodePtr node,
+ int getProperty(XmlNodeConstPtr node,
const char *const name,
int def)
{
@@ -191,7 +191,7 @@ namespace XML
return ret;
}
- int getIntProperty(const XmlNodePtr node,
+ int getIntProperty(XmlNodeConstPtr node,
const char *const name,
int def,
const int min,
@@ -212,7 +212,7 @@ namespace XML
return ret;
}
- double getFloatProperty(const XmlNodePtr node,
+ double getFloatProperty(XmlNodeConstPtr node,
const char *const name,
double def)
{
@@ -227,7 +227,7 @@ namespace XML
return ret;
}
- std::string getProperty(const XmlNodePtr node,
+ std::string getProperty(XmlNodeConstPtr node,
const char *const name,
const std::string &def)
{
@@ -240,7 +240,7 @@ namespace XML
return def;
}
- std::string langProperty(const XmlNodePtr node,
+ std::string langProperty(XmlNodeConstPtr node,
const char *const name,
const std::string &def)
{
@@ -251,7 +251,7 @@ namespace XML
return translator->getStr(str);
}
- bool getBoolProperty(const XmlNodePtr node,
+ bool getBoolProperty(XmlNodeConstPtr node,
const char *const name,
const bool def)
{
@@ -270,7 +270,7 @@ namespace XML
return def;
}
- XmlNodePtr findFirstChildByName(const XmlNodePtrConst parent,
+ XmlNodePtr findFirstChildByName(XmlNodeConstPtrConst parent,
const char *const name)
{
if (!parent || !name)
diff --git a/src/utils/xml/pugixml.h b/src/utils/xml/pugixml.h
index b6d9e5bfd..14a3bdbdf 100644
--- a/src/utils/xml/pugixml.h
+++ b/src/utils/xml/pugixml.h
@@ -99,21 +99,21 @@ namespace XML
/**
* Gets an floating point property from an XmlNodePtr.
*/
- double getFloatProperty(const XmlNodePtr node,
+ double getFloatProperty(XmlNodeConstPtr node,
const char *const name,
double def) A_WARN_UNUSED;
/**
* Gets an integer property from an XmlNodePtr.
*/
- int getProperty(const XmlNodePtr node,
+ int getProperty(XmlNodeConstPtr node,
const char *const name,
int def) A_WARN_UNUSED;
/**
* Gets an integer property from an XmlNodePtr.
*/
- int getIntProperty(const XmlNodePtr node,
+ int getIntProperty(XmlNodeConstPtr node,
const char *const name,
int def,
const int min,
@@ -122,28 +122,28 @@ namespace XML
/**
* Gets a string property from an XmlNodePtr.
*/
- std::string getProperty(const XmlNodePtr node,
+ std::string getProperty(XmlNodeConstPtr node,
const char *const name,
const std::string &def) A_WARN_UNUSED;
/**
* Gets a translated string property from an XmlNodePtr.
*/
- std::string langProperty(const XmlNodePtr node,
+ std::string langProperty(XmlNodeConstPtr node,
const char *const name,
const std::string &def) A_WARN_UNUSED;
/**
* Gets a boolean property from an XmlNodePtr.
*/
- bool getBoolProperty(const XmlNodePtr node,
+ bool getBoolProperty(XmlNodeConstPtr node,
const char *const name,
const bool def) A_WARN_UNUSED;
/**
* Finds the first child node with the given name
*/
- XmlNodePtr findFirstChildByName(const XmlNodePtrConst parent,
+ XmlNodePtr findFirstChildByName(XmlNodeConstPtrConst parent,
const char *const name) A_WARN_UNUSED;
void initXML();
diff --git a/src/utils/xml/pugixml.inc b/src/utils/xml/pugixml.inc
index d8ef38242..c8685f877 100644
--- a/src/utils/xml/pugixml.inc
+++ b/src/utils/xml/pugixml.inc
@@ -27,6 +27,8 @@
#define XmlNodePtr pugi::xml_node
#define XmlNodePtrConst pugi::xml_node
+#define XmlNodeConstPtr const pugi::xml_node
+#define XmlNodeConstPtrConst const pugi::xml_node
#define xmlNameEqual(node, str) !strcmp((node).name(), str)
#define xmlTypeEqual(node, typ) ((node).type() == (typ))
#define XmlHasProp(node, name) (!((node).attribute(name).empty()))
@@ -37,12 +39,14 @@
#define XmlFree(ptr)
#define XmlNodeDefault pugi::xml_node()
#define XmlNodeGetContent(node) (node).child_value()
-#define XmlTextWriterPtr XML::Writer *
+#define XmlTextWriterPtr const XML::Writer *
+#define XmlTextWriterStartRootElement(writer, name) (writer)->startNode(name)
#define XmlTextWriterStartElement(writer, name) (writer)->startNode(name)
#define XmlTextWriterEndElement(writer) (writer)->endNode()
#define XmlTextWriterWriteAttribute(writer, name, content) \
(writer)->addAttribute(name, content)
#define XmlNewTextWriterFilename(name, flags) new XML::Writer(name);
+#define XmlSaveTextWriterFilename(writer, name)
#define XmlTextWriterSetIndent(writer, flags)
#define XmlTextWriterStartDocument(writer, p1, p2, p3)
#define XmlTextWriterEndDocument(writer) (writer)->endDocument()
diff --git a/src/utils/xml/tinyxml2.cpp b/src/utils/xml/tinyxml2.cpp
new file mode 100644
index 000000000..6805ef48d
--- /dev/null
+++ b/src/utils/xml/tinyxml2.cpp
@@ -0,0 +1,306 @@
+/*
+ * The ManaPlus Client
+ * Copyright (C) 2004-2009 The Mana World Development Team
+ * Copyright (C) 2009-2010 The Mana Developers
+ * Copyright (C) 2011-2017 The ManaPlus Developers
+ *
+ * This file is part of The ManaPlus Client.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifdef ENABLE_TINYXML2
+
+#include "utils/xml/tinyxml2.h"
+
+#include "fs/virtfstools.h"
+
+#include "utils/checkutils.h"
+#include "utils/fuzzer.h"
+#include "utils/stringutils.h"
+
+#include "utils/translation/podict.h"
+
+#include "debug.h"
+
+namespace
+{
+ bool valid = false;
+} // namespace
+
+namespace XML
+{
+ static void showErrorStatus(tinyxml2::XMLDocument &doc)
+ {
+ logger->log("xml error: %s, in lines: %s\n%s",
+ doc.ErrorName(),
+ doc.GetErrorStr1(),
+ doc.GetErrorStr2());
+ }
+
+ Document::Document(const std::string &filename,
+ const UseVirtFs useResman,
+ const SkipError skipError) :
+ Resource(),
+ mDoc(),
+ mData(nullptr),
+ mIsValid(false)
+ {
+#ifdef USE_FUZZER
+ if (Fuzzer::conditionTerminate(filename.c_str()))
+ return;
+#endif // USE_FUZZER
+
+ BLOCK_START("XML::Document::Document")
+ int size = 0;
+ char *data = nullptr;
+ valid = true;
+ if (useResman == UseVirtFs_true)
+ {
+ data = static_cast<char*>(VirtFs::loadFile(
+ filename.c_str(), size));
+ }
+ else
+ {
+ std::ifstream file;
+ file.open(filename.c_str(), std::ios::in);
+
+ if (file.is_open())
+ {
+ // Get length of file
+ file.seekg(0, std::ios::end);
+ size = CAST_S32(file.tellg());
+ if (size < 0)
+ {
+ reportAlways("Error loading XML file %s",
+ filename.c_str());
+ }
+ else
+ {
+ file.seekg(0, std::ios::beg);
+ data = static_cast<char*>(malloc(size));
+ file.read(data, size);
+ }
+ file.close();
+ }
+ else
+ {
+ reportAlways("Error loading XML file %s",
+ filename.c_str());
+ }
+ }
+
+ if (data)
+ {
+ tinyxml2::XMLError result = mDoc.Parse(data,
+ size);
+ if (result != tinyxml2::XML_SUCCESS)
+ {
+ showErrorStatus(mDoc);
+ free(data);
+ }
+ else
+ {
+ mData = data;
+ }
+ }
+ else if (skipError == SkipError_false)
+ {
+ reportAlways("Error loading %s", filename.c_str());
+ }
+ mIsValid = valid;
+ BLOCK_END("XML::Document::Document")
+ }
+
+ Document::Document(const char *const data, const int size) :
+ Resource(),
+ mDoc(),
+ mData(nullptr),
+ mIsValid(true)
+ {
+ if (!data)
+ return;
+
+ char *buf = static_cast<char*>(calloc(size + 1, 1));
+ strncpy(buf, data, size);
+ buf[size] = 0;
+
+ tinyxml2::XMLError result = mDoc.Parse(buf,
+ size);
+ if (result != tinyxml2::XML_SUCCESS)
+ {
+ showErrorStatus(mDoc);
+ free(buf);
+ }
+ else
+ {
+ mData = buf;
+ }
+ }
+
+ Document::~Document()
+ {
+ free(mData);
+ mData = nullptr;
+ }
+
+ XmlNodeConstPtr Document::rootNode()
+ {
+ return mDoc.FirstChildElement();
+ }
+
+ int getProperty(XmlNodeConstPtr node,
+ const char *const name,
+ int def)
+ {
+ int &ret = def;
+
+ if (!node)
+ return ret;
+ const char *attr = node->Attribute(name);
+ if (attr != nullptr)
+ ret = atoi(attr);
+
+ return ret;
+ }
+
+ int getIntProperty(XmlNodeConstPtr node,
+ const char *const name,
+ int def,
+ const int min,
+ const int max)
+ {
+ int &ret = def;
+
+ if (!node)
+ return ret;
+ const char *attr = node->Attribute(name);
+ if (attr != nullptr)
+ ret = atoi(attr);
+
+ if (ret < min)
+ ret = min;
+ else if (ret > max)
+ ret = max;
+ return ret;
+ }
+
+ double getFloatProperty(XmlNodeConstPtr node,
+ const char *const name,
+ double def)
+ {
+ double &ret = def;
+
+ if (!node)
+ return ret;
+ const char *attr = node->Attribute(name);
+ if (attr != nullptr)
+ ret = atof(attr);
+
+ return ret;
+ }
+
+ std::string getProperty(XmlNodeConstPtr node,
+ const char *const name,
+ const std::string &def)
+ {
+ if (!node)
+ return def;
+ const char *attr = node->Attribute(name);
+ if (attr != nullptr)
+ return attr;
+
+ return def;
+ }
+
+ std::string langProperty(XmlNodeConstPtr node,
+ const char *const name,
+ const std::string &def)
+ {
+ std::string str = getProperty(node, name, def);
+ if (!translator)
+ return str;
+
+ return translator->getStr(str);
+ }
+
+ bool getBoolProperty(XmlNodeConstPtr node,
+ const char *const name,
+ const bool def)
+ {
+ if (!node)
+ return def;
+ const char *attr = node->Attribute(name);
+ if (attr != nullptr)
+ {
+ std::string val = attr;
+ if (val == "true")
+ return true;
+ if (val == "false")
+ return false;
+ }
+
+ return def;
+ }
+
+ XmlNodeConstPtr findFirstChildByName(XmlNodeConstPtrConst parent,
+ const char *const name)
+ {
+ if (!parent || !name)
+ return nullptr;
+ return parent->FirstChildElement(name);
+ }
+
+ // Initialize xml
+ void initXML()
+ {
+ }
+
+ // Shutdown xml
+ void cleanupXML()
+ {
+ }
+
+ bool Document::validateXml(const std::string &fileName)
+ {
+ tinyxml2::XMLDocument doc;
+ tinyxml2::XMLError result = doc.LoadFile(fileName.c_str());
+
+ if (result != tinyxml2::XML_SUCCESS)
+ {
+ showErrorStatus(doc);
+ return false;
+ }
+
+ std::ifstream file;
+ file.open(fileName.c_str(), std::ios::in);
+ if (!file.is_open())
+ {
+ file.close();
+ return false;
+ }
+ char line[101];
+ if (!file.getline(line, 100))
+ return false;
+ file.close();
+
+ const std::string str = line;
+ if (!strStartWith(str, "<?xml "))
+ return false;
+
+ return true;
+ }
+} // namespace XML
+
+#endif // ENABLE_TINYXML2
diff --git a/src/utils/xml/tinyxml2.h b/src/utils/xml/tinyxml2.h
new file mode 100644
index 000000000..e817f7276
--- /dev/null
+++ b/src/utils/xml/tinyxml2.h
@@ -0,0 +1,161 @@
+/*
+ * The ManaPlus Client
+ * Copyright (C) 2004-2009 The Mana World Development Team
+ * Copyright (C) 2009-2010 The Mana Developers
+ * Copyright (C) 2011-2017 The ManaPlus Developers
+ *
+ * This file is part of The ManaPlus Client.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef UTILS_XML_TINYXML2_H
+#define UTILS_XML_TINYXML2_H
+
+#ifdef ENABLE_TINYXML2
+
+#define XML_INCLUDE_DEFINE
+
+#include "enums/simpletypes/skiperror.h"
+#include "enums/simpletypes/usevirtfs.h"
+
+#include "utils/xml/tinyxml2.inc"
+
+#include "resources/resource.h"
+
+#ifndef _GLIBCXX_STRING
+#include <string>
+#endif // _GLIBCXX_STRING
+
+#include "localconsts.h"
+
+/**
+ * XML helper functions.
+ */
+namespace XML
+{
+ /**
+ * A helper class for parsing an XML document, which also cleans it up
+ * again (RAII).
+ */
+ class Document final : public Resource
+ {
+ public:
+ /**
+ * Constructor that attempts to load the given file through the
+ * resource manager. Logs errors.
+ */
+ Document(const std::string &filename,
+ const UseVirtFs useResman,
+ const SkipError skipError);
+
+ /**
+ * Constructor that attempts to load an XML document from memory.
+ * Does not log errors.
+ *
+ * @param data the string to parse as XML
+ * @param size the length of the string in bytes
+ */
+ Document(const char *const data, const int size);
+
+ A_DELETE_COPY(Document)
+
+ /**
+ * Destructor. Frees the loaded XML file.
+ */
+ ~Document();
+
+ /**
+ * Returns the root node of the document (or NULL if there was a
+ * load error).
+ */
+ XmlNodePtr rootNode() A_WARN_UNUSED;
+
+ bool isLoaded() const
+ { return mDoc.Error() == false; }
+
+ bool isValid() const
+ { return mIsValid; }
+
+ static bool validateXml(const std::string &fileName);
+
+ private:
+ tinyxml2::XMLDocument mDoc;
+ char *mData;
+ bool mIsValid;
+ };
+
+ /**
+ * Gets an floating point property from an XmlNodePtr.
+ */
+ double getFloatProperty(XmlNodeConstPtr node,
+ const char *const name,
+ double def) A_WARN_UNUSED;
+
+ /**
+ * Gets an integer property from an XmlNodePtr.
+ */
+ int getProperty(XmlNodeConstPtr node,
+ const char *const name,
+ int def) A_WARN_UNUSED;
+
+ /**
+ * Gets an integer property from an XmlNodePtr.
+ */
+ int getIntProperty(XmlNodeConstPtr node,
+ const char *const name,
+ int def,
+ const int min,
+ const int max) A_WARN_UNUSED;
+
+ /**
+ * Gets a string property from an XmlNodePtr.
+ */
+ std::string getProperty(XmlNodeConstPtr node,
+ const char *const name,
+ const std::string &def) A_WARN_UNUSED;
+
+ /**
+ * Gets a translated string property from an XmlNodePtr.
+ */
+ std::string langProperty(XmlNodeConstPtr node,
+ const char *const name,
+ const std::string &def) A_WARN_UNUSED;
+
+ /**
+ * Gets a boolean property from an XmlNodePtr.
+ */
+ bool getBoolProperty(XmlNodeConstPtr node,
+ const char *const name,
+ const bool def) A_WARN_UNUSED;
+
+ /**
+ * Finds the first child node with the given name
+ */
+ XmlNodeConstPtr findFirstChildByName(XmlNodeConstPtrConst parent,
+ const char *const name)
+ A_WARN_UNUSED;
+
+ void initXML();
+
+ void cleanupXML();
+} // namespace XML
+
+#define for_each_xml_child_node(var, parent) \
+ for (const tinyxml2::XMLElement *var = parent->FirstChildElement(); \
+ var != nullptr; \
+ var = var->NextSiblingElement())
+
+#endif // ENABLE_TINYXML2
+#endif // UTILS_XML_TINYXML2_H
diff --git a/src/utils/xml/tinyxml2.inc b/src/utils/xml/tinyxml2.inc
new file mode 100644
index 000000000..a0554e5b9
--- /dev/null
+++ b/src/utils/xml/tinyxml2.inc
@@ -0,0 +1,70 @@
+/*
+ * The ManaPlus Client
+ * Copyright (C) 2011-2017 The ManaPlus Developers
+ *
+ * This file is part of The ManaPlus Client.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef UTILS_XML_TINYXML2_INC
+#define UTILS_XML_TINYXML2_INC
+
+#ifdef ENABLE_TINYXML2
+
+#include <tinyxml2.h>
+
+TINYXML2_INCLUDED
+
+#define XML_ELEMENT_NODE tinyxml2::XMLElement
+
+#define XmlNodePtr const tinyxml2::XMLElement*
+#define XmlNodePtrConst const tinyxml2::XMLElement *const
+#define XmlNodeConstPtr const tinyxml2::XMLElement*
+#define XmlNodeConstPtrConst const tinyxml2::XMLElement *const
+#define xmlNameEqual(node, str) !strcmp((node)->Value(), str)
+#define XmlTextWriterPtr tinyxml2::XMLPrinter*
+// +++ need replace xmlTypeEqual to isXmlElementNode
+#define xmlTypeEqual(node, typ) true
+#define XmlHasProp(node, name) ((node)->Attribute(name) != nullptr)
+
+#define XmlNodeGetContent(node) (node)->GetText()
+#define XmlHaveChildContent(node) ((node)->GetText() != nullptr)
+#define XmlChildContent(node) ((node)->GetText())
+
+#define XmlFree(ptr)
+#define XmlNodeDefault nullptr
+#define XmlChar const char
+#define XmlConstChar const char
+
+#define XmlTextWriterStartElement(writer, name) (writer)->OpenElement(name)
+#define XmlTextWriterStartRootElement(writer, name) (writer)->OpenElement(name)
+#define XmlTextWriterEndElement(writer) (writer)->CloseElement()
+#define XmlTextWriterWriteAttribute(writer, name, content) \
+ (writer)->PushAttribute(name, content)
+#define XmlNewTextWriterFilename(name, flags) new tinyxml2::XMLPrinter
+#define XmlSaveTextWriterFilename(writer, name) \
+ { \
+ FILE *const writer##File = fopen(name, "wb"); \
+ fwrite((writer)->CStr(), 1, (writer)->CStrSize() - 1, writer##File); \
+ fclose(writer##File); \
+ }
+#define XmlTextWriterSetIndent(writer, flags)
+#define XmlTextWriterStartDocument(writer, p1, p2, p3) \
+ (writer)->PushDeclaration("xml version=\"1.0\" encoding=\"utf-8\"")
+#define XmlTextWriterEndDocument(writer) (writer)->CloseElement()
+#define XmlFreeTextWriter(writer) delete writer
+
+#endif // ENABLE_TINYXML2
+#endif // UTILS_XML_TINYXML2_INC
diff --git a/src/utils/xml_unittest.cc b/src/utils/xml_unittest.cc
index fc7818085..69940b0af 100644
--- a/src/utils/xml_unittest.cc
+++ b/src/utils/xml_unittest.cc
@@ -152,7 +152,7 @@ TEST_CASE("xml doc")
UseVirtFs_true,
SkipError_false);
- const XmlNodePtr rootNode = doc.rootNode();
+ XmlNodeConstPtr rootNode = doc.rootNode();
REQUIRE(XML::getProperty(rootNode, "image", "") == "window.png");
}
@@ -162,7 +162,7 @@ TEST_CASE("xml doc")
UseVirtFs_true,
SkipError_false);
- const XmlNodePtr rootNode = doc.rootNode();
+ XmlNodeConstPtr rootNode = doc.rootNode();
// REQUIRE(XmlHaveChildContent(rootNode) == true);
XmlNodePtr node = XmlNodeDefault;
for_each_xml_child_node(widgetNode, rootNode)
@@ -202,7 +202,7 @@ TEST_CASE("xml doc")
UseVirtFs_true,
SkipError_false);
- const XmlNodePtr rootNode = doc.rootNode();
+ XmlNodeConstPtr rootNode = doc.rootNode();
XmlNodePtr node = XML::findFirstChildByName(rootNode, "widget");
REQUIRE(node != nullptr);
REQUIRE(xmlTypeEqual(node, XML_ELEMENT_NODE) == true);
@@ -234,7 +234,7 @@ TEST_CASE("xml doc")
"<root><data option1=\"false\" option2=\"true\" "
"option3=\"10.5\"/></root>";
XML::Document doc(xml, strlen(xml));
- const XmlNodePtr rootNode = doc.rootNode();
+ XmlNodeConstPtr rootNode = doc.rootNode();
REQUIRE(XmlHaveChildContent(rootNode) == false);
XmlNodePtr node = XML::findFirstChildByName(rootNode, "data");
REQUIRE(node != nullptr);
@@ -257,7 +257,7 @@ TEST_CASE("xml doc")
"<data option1=\"false\" option2=\"true\" "
"option3=\"10.5\"/><!-- comment --></root>";
XML::Document doc(xml.c_str(), xml.size());
- const XmlNodePtr rootNode = doc.rootNode();
+ XmlNodeConstPtr rootNode = doc.rootNode();
// REQUIRE(XmlHaveChildContent(rootNode) == true);
XmlNodePtr node = XML::findFirstChildByName(rootNode, "data");
REQUIRE(node != nullptr);
@@ -292,13 +292,15 @@ TEST_CASE("xml doc")
FILE *const testFile = fopen(tempXmlName, "w");
REQUIRE(testFile);
fclose(testFile);
- const XmlTextWriterPtr writer = XmlNewTextWriterFilename(
+ XmlTextWriterPtr writer = XmlNewTextWriterFilename(
tempXmlName,
0);
XmlTextWriterSetIndent(writer, 1);
XmlTextWriterStartDocument(writer, nullptr, nullptr, nullptr);
- XmlTextWriterStartElement(writer, "root");
+ XmlTextWriterStartRootElement(writer, "root");
XmlTextWriterEndDocument(writer);
+ XmlSaveTextWriterFilename(writer, tempXmlName);
+ logger->log("xml test: %s", writer->CStr());
XmlFreeTextWriter(writer);
// load
@@ -326,12 +328,12 @@ TEST_CASE("xml doc")
FILE *const testFile = fopen(tempXmlName, "w");
REQUIRE(testFile);
fclose(testFile);
- const XmlTextWriterPtr writer = XmlNewTextWriterFilename(
+ XmlTextWriterPtr writer = XmlNewTextWriterFilename(
tempXmlName,
0);
XmlTextWriterSetIndent(writer, 1);
XmlTextWriterStartDocument(writer, nullptr, nullptr, nullptr);
- XmlTextWriterStartElement(writer, "root");
+ XmlTextWriterStartRootElement(writer, "root");
XmlTextWriterStartElement(writer, "option");
XmlTextWriterWriteAttribute(writer, "name", "the name");
@@ -339,6 +341,7 @@ TEST_CASE("xml doc")
XmlTextWriterEndElement(writer);
XmlTextWriterEndDocument(writer);
+ XmlSaveTextWriterFilename(writer, tempXmlName);
XmlFreeTextWriter(writer);
// load
@@ -366,6 +369,7 @@ TEST_CASE("xml doc")
// clean again
::remove(tempXmlName);
}
+
delete2(theme);
delete2(client);
VirtFs::unmountDirSilent("data");
diff --git a/src/utils/xmlutils.cpp b/src/utils/xmlutils.cpp
index 450a392d4..a6648c212 100644
--- a/src/utils/xmlutils.cpp
+++ b/src/utils/xmlutils.cpp
@@ -35,7 +35,7 @@ void readXmlIntVector(const std::string &fileName,
const SkipError skipError)
{
XML::Document doc(fileName, UseVirtFs_true, skipError);
- const XmlNodePtrConst rootNode = doc.rootNode();
+ XmlNodeConstPtrConst rootNode = doc.rootNode();
if (!rootNode || !xmlNameEqual(rootNode, rootName.c_str()))
{
@@ -86,7 +86,7 @@ void readXmlStringMap(const std::string &fileName,
const SkipError skipError)
{
XML::Document doc(fileName, UseVirtFs_true, skipError);
- const XmlNodePtrConst rootNode = doc.rootNode();
+ XmlNodeConstPtrConst rootNode = doc.rootNode();
if (!rootNode || !xmlNameEqual(rootNode, rootName.c_str()))
{
@@ -140,7 +140,7 @@ void readXmlIntMap(const std::string &fileName,
const SkipError skipError)
{
XML::Document doc(fileName, UseVirtFs_true, skipError);
- const XmlNodePtrConst rootNode = doc.rootNode();
+ XmlNodeConstPtrConst rootNode = doc.rootNode();
if (!rootNode || !xmlNameEqual(rootNode, rootName.c_str()))
{