- stubbed out use of xerces as no code was using it any longer. Xerces is no longer a requirement to build, we have been using rapidxml for a long time now. For now the MACRO: WANT_XERCES will build Xerces support into th egame, but it is still not used. We will likely deprecate xerces from megaglest soon.

This commit is contained in:
SoftCoder 2014-01-25 17:09:52 -08:00
parent 12422bbf53
commit 08af18429d
6 changed files with 144 additions and 22 deletions

View File

@ -6419,7 +6419,6 @@ string Game::saveGame(string name, string path) {
xmlTreeSaveGame.save(replayFile);
}
//XmlTree xmlTree(XML_XERCES_ENGINE);
XmlTree xmlTree;
xmlTree.init("megaglest-saved-game");
XmlNode *rootNode = xmlTree.getRootNode();

View File

@ -262,8 +262,12 @@ static void cleanupProcessObjects() {
std::map<string, vector<FileReader<Pixmap3D> const * >* > &list3d = FileReader<Pixmap3D>::getFileReadersMap();
deleteMapValues(list3d.begin(),list3d.end());
#if defined(WANT_XERCES)
XmlIo::getInstance().cleanup();
#endif
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
SystemFlags::globalCleanupHTTP();
@ -4260,10 +4264,14 @@ int glestMain(int argc, char** argv) {
}
}
#if defined(WANT_XERCES)
if(hasCommandArgument(argc, argv,GAME_ARGS[GAME_ARG_XERCES_INFO]) == true) {
printf("XERCES version: %s\n", XERCES_FULLVERSIONDOT);
}
#endif
if( (hasCommandArgument(argc, argv,GAME_ARGS[GAME_ARG_VERSION]) == true ||
hasCommandArgument(argc, argv,GAME_ARGS[GAME_ARG_SDL_INFO]) == true ||
hasCommandArgument(argc, argv,GAME_ARGS[GAME_ARG_LUA_INFO]) == true ||

View File

@ -302,10 +302,15 @@ void MenuStateLoadGame::mouseClick(int x, int y, MouseButton mouseButton){
if(fileExists(filename) == true) {
// Xerces is infinitely slower than rapidxml
xml_engine_parser_type engine_type = XML_RAPIDXML_ENGINE;
#if defined(WANT_XERCES)
if(Config::getInstance().getBool("ForceXMLLoadGameUsingXerces","false") == true) {
engine_type = XML_XERCES_ENGINE;
}
// XmlTree xmlTree(XML_XERCES_ENGINE);
#endif
XmlTree xmlTree(engine_type);
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("Before load of XML\n");

View File

@ -14,8 +14,14 @@
#include <string>
#include <vector>
#include <xercesc/util/XercesDefs.hpp>
#include <map>
#if defined(WANT_XERCES)
#include <xercesc/util/XercesDefs.hpp>
#endif
#include "rapidxml/rapidxml.hpp"
#include "data_types.h"
#include "leak_dumper.h"
@ -23,6 +29,8 @@
using namespace rapidxml;
using namespace std;
#if defined(WANT_XERCES)
namespace XERCES_CPP_NAMESPACE{
class DOMImplementation;
class DOMDocument;
@ -38,10 +46,15 @@ namespace XERCES_CPP_NAMESPACE{
XERCES_CPP_NAMESPACE_USE
#endif
namespace Shared { namespace Xml {
enum xml_engine_parser_type {
#if defined(WANT_XERCES)
XML_XERCES_ENGINE = 0,
#endif
XML_RAPIDXML_ENGINE = 1
} ;
@ -52,6 +65,7 @@ class XmlTree;
class XmlNode;
class XmlAttribute;
#if defined(WANT_XERCES)
// =====================================================
// class XmlIo
//
@ -93,6 +107,8 @@ public:
void save(const string &path, const XmlNode *node);
};
#endif
class XmlIoRapid {
private:
static bool initialized;
@ -158,7 +174,14 @@ private:
bool hasChildNoSuper(const string& childName) const;
public:
#if defined(WANT_XERCES)
XmlNode(XERCES_CPP_NAMESPACE::DOMNode *node, const std::map<string,string> &mapTagReplacementValues);
XERCES_CPP_NAMESPACE::DOMElement *buildElement(XERCES_CPP_NAMESPACE::DOMDocument *document) const;
#endif
XmlNode(xml_node<> *node, const std::map<string,string> &mapTagReplacementValues);
XmlNode(const string &name);
~XmlNode();
@ -186,8 +209,6 @@ public:
XmlNode *addChild(const string &name, const string text = "");
XmlAttribute *addAttribute(const string &name, const string &value, const std::map<string,string> &mapTagReplacementValues);
XERCES_CPP_NAMESPACE::DOMElement *buildElement(XERCES_CPP_NAMESPACE::DOMDocument *document) const;
xml_node<>* buildElement(xml_document<> *document) const;
};
@ -208,7 +229,13 @@ private:
void operator =(XmlAttribute&);
public:
#if defined(WANT_XERCES)
XmlAttribute(XERCES_CPP_NAMESPACE::DOMNode *attribute, const std::map<string,string> &mapTagReplacementValues);
#endif
XmlAttribute(xml_attribute<> *attribute, const std::map<string,string> &mapTagReplacementValues);
XmlAttribute(const string &name, const string &value, const std::map<string,string> &mapTagReplacementValues);

View File

@ -18,9 +18,15 @@
#include <algorithm>
#include "conversion.h"
#if defined(WANT_XERCES)
#include <xercesc/dom/DOM.hpp>
#include <xercesc/util/PlatformUtils.hpp>
#include <xercesc/framework/LocalFileFormatTarget.hpp>
#endif
#include "util.h"
#include "properties.h"
#include "platform_common.h"
@ -30,8 +36,12 @@
#include "rapidxml/rapidxml_print.hpp"
#include "leak_dumper.h"
#if defined(WANT_XERCES)
XERCES_CPP_NAMESPACE_USE
#endif
using namespace std;
using namespace Shared::PlatformCommon;
@ -39,6 +49,15 @@ namespace Shared { namespace Xml {
using namespace Util;
// =====================================================
// class XmlIo
// =====================================================
bool XmlIoRapid::initialized= false;
#if defined(WANT_XERCES)
bool XmlIo::initialized = false;
// =====================================================
// class ErrorHandler
// =====================================================
@ -57,13 +76,6 @@ public:
}
};
// =====================================================
// class XmlIo
// =====================================================
bool XmlIo::initialized = false;
bool XmlIoRapid::initialized= false;
XmlIo::XmlIo() : parser(NULL) {
init();
}
@ -285,6 +297,8 @@ void XmlIo::save(const string &path, const XmlNode *node){
}
}
#endif
// =====================================================
// class XmlIoRapid
// =====================================================
@ -495,8 +509,10 @@ XmlTree::XmlTree(xml_engine_parser_type engine_type) {
rootNode= NULL;
switch(engine_type) {
#if defined(WANT_XERCES)
case XML_XERCES_ENGINE:
break;
#endif
case XML_RAPIDXML_ENGINE:
break;
@ -542,21 +558,28 @@ void XmlTree::load(const string &path, const std::map<string,string> &mapTagRepl
loadPath = path;
#if defined(WANT_XERCES)
if(this->engine_type == XML_XERCES_ENGINE) {
this->rootNode= XmlIo::getInstance().load(path, mapTagReplacementValues, noValidation,skipStackTrace);
}
else {
else
#endif
{
this->rootNode= XmlIoRapid::getInstance().load(path, mapTagReplacementValues, noValidation,skipStackTrace);
}
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line: %d] about to load [%s]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,path.c_str());
}
void XmlTree::save(const string &path){
void XmlTree::save(const string &path) {
#if defined(WANT_XERCES)
if(this->engine_type == XML_XERCES_ENGINE) {
XmlIo::getInstance().save(path, rootNode);
}
else {
else
#endif
{
XmlIoRapid::getInstance().save(path, rootNode);
}
}
@ -587,6 +610,8 @@ XmlTree::~XmlTree() {
// class XmlNode
// =====================================================
#if defined(WANT_XERCES)
XmlNode::XmlNode(DOMNode *node, const std::map<string,string> &mapTagReplacementValues): superNode(NULL) {
if(node == NULL || node->getNodeName() == NULL) {
throw megaglest_runtime_error("XML structure seems to be corrupt!");
@ -634,6 +659,8 @@ XmlNode::XmlNode(DOMNode *node, const std::map<string,string> &mapTagReplacement
}
}
#endif
XmlNode::XmlNode(xml_node<> *node, const std::map<string,string> &mapTagReplacementValues) : superNode(NULL) {
if(node == NULL || node->name() == NULL) {
throw megaglest_runtime_error("XML structure seems to be corrupt!");
@ -852,6 +879,8 @@ XmlAttribute *XmlNode::addAttribute(const string &name, const string &value, con
return attr;
}
#if defined(WANT_XERCES)
DOMElement *XmlNode::buildElement(XERCES_CPP_NAMESPACE_QUALIFIER DOMDocument *document) const{
XMLCh str[strSize];
XMLString::transcode(name.c_str(), str, strSize-1);
@ -875,6 +904,8 @@ DOMElement *XmlNode::buildElement(XERCES_CPP_NAMESPACE_QUALIFIER DOMDocument *do
return node;
}
#endif
xml_node<>* XmlNode::buildElement(xml_document<> *document) const {
xml_node<>* node = document->allocate_node(node_element, document->allocate_string(name.c_str()));
@ -913,6 +944,8 @@ string XmlNode::getTreeString() const {
// class XmlAttribute
// =====================================================
#if defined(WANT_XERCES)
XmlAttribute::XmlAttribute(DOMNode *attribute, const std::map<string,string> &mapTagReplacementValues) {
if(attribute == NULL || attribute->getNodeName() == NULL) {
throw megaglest_runtime_error("XML attribute seems to be corrupt!");
@ -932,6 +965,8 @@ XmlAttribute::XmlAttribute(DOMNode *attribute, const std::map<string,string> &ma
name= str;
}
#endif
XmlAttribute::XmlAttribute(xml_attribute<> *attribute, const std::map<string,string> &mapTagReplacementValues) {
if(attribute == NULL || attribute->name() == NULL) {
throw megaglest_runtime_error("XML attribute seems to be corrupt!");

View File

@ -15,10 +15,15 @@
#include "xml_parser.h"
#include "platform_util.h"
#if defined(WANT_XERCES)
#include <xercesc/dom/DOM.hpp>
//#include <xercesc/util/PlatformUtils.hpp>
//#include <xercesc/framework/LocalFileFormatTarget.hpp>
#endif
#ifdef WIN32
#include <io.h>
#else
@ -72,6 +77,8 @@ public:
};
//
#if defined(WANT_XERCES)
//
// Tests for XmlIo
//
@ -148,6 +155,8 @@ public:
}
};
#endif
//
// Tests for XmlIoRapid
//
@ -242,12 +251,26 @@ class XmlTreeTest : public CppUnit::TestFixture {
public:
#if defined(WANT_XERCES)
void test_invalid_xml_engine_lowerbound() {
xml_engine_parser_type testType = static_cast<xml_engine_parser_type>(XML_XERCES_ENGINE - 1);
if((int)testType == (int)(XML_XERCES_ENGINE - 1)) {
XmlTree xml(testType);
}
}
#else
void test_invalid_xml_engine_lowerbound() {
xml_engine_parser_type testType = static_cast<xml_engine_parser_type>(XML_RAPIDXML_ENGINE - 1);
if((int)testType == (int)(XML_RAPIDXML_ENGINE - 1)) {
XmlTree xml(testType);
}
}
#endif
void test_invalid_xml_engine_upperbound() {
xml_engine_parser_type testType = static_cast<xml_engine_parser_type>(XML_RAPIDXML_ENGINE + 1);
if((int)testType == (int)(XML_RAPIDXML_ENGINE + 1)) {
@ -301,9 +324,14 @@ class XmlNodeTest : public CppUnit::TestFixture {
// Register the suite of tests for this fixture
CPPUNIT_TEST_SUITE( XmlNodeTest );
#if defined(WANT_XERCES)
CPPUNIT_TEST_EXCEPTION( test_null_xerces_node, megaglest_runtime_error );
CPPUNIT_TEST_EXCEPTION( test_null_rapidxml_node, megaglest_runtime_error );
CPPUNIT_TEST( test_valid_xerces_node );
#endif
CPPUNIT_TEST_EXCEPTION( test_null_rapidxml_node, megaglest_runtime_error );
CPPUNIT_TEST( test_valid_named_node );
CPPUNIT_TEST( test_child_nodes );
CPPUNIT_TEST( test_node_attributes );
@ -313,6 +341,8 @@ class XmlNodeTest : public CppUnit::TestFixture {
private:
#if defined(WANT_XERCES)
class XmlIoMock : public XmlIo {
protected:
virtual void releaseDOMParser() { }
@ -329,18 +359,18 @@ private:
}
};
#endif
public:
#if defined(WANT_XERCES)
void test_null_xerces_node() {
XERCES_CPP_NAMESPACE::DOMNode *node = NULL;
const std::map<string,string> mapTagReplacementValues;
XmlNode(node, mapTagReplacementValues);
}
void test_null_rapidxml_node() {
xml_node<> *node = NULL;
const std::map<string,string> mapTagReplacementValues;
XmlNode(node, mapTagReplacementValues);
}
void test_valid_xerces_node() {
const string test_filename = "xml_test_valid.xml";
createValidXMLTestFile(test_filename);
@ -360,6 +390,14 @@ public:
CPPUNIT_ASSERT( node.hasAttribute("mytest-attribute") == true );
CPPUNIT_ASSERT( node.hasChild("menu-background-model") == true );
}
#endif
void test_null_rapidxml_node() {
xml_node<> *node = NULL;
const std::map<string,string> mapTagReplacementValues;
XmlNode(node, mapTagReplacementValues);
}
void test_valid_named_node() {
XmlNode node("testNode");
@ -435,6 +473,7 @@ public:
};
#if defined(WANT_XERCES)
//
// Tests for XmlAttribute
//
@ -443,6 +482,7 @@ class XmlAttributeTest : public CppUnit::TestFixture {
CPPUNIT_TEST_SUITE( XmlAttributeTest );
CPPUNIT_TEST_EXCEPTION( test_null_xerces_attribute, megaglest_runtime_error );
CPPUNIT_TEST( test_node_attributes );
CPPUNIT_TEST_EXCEPTION( test_node_attributes_restricted, megaglest_runtime_error );
CPPUNIT_TEST_EXCEPTION( test_node_attributes_int_outofrange, megaglest_runtime_error );
@ -578,11 +618,19 @@ public:
}
};
#endif
// Test Suite Registrations
CPPUNIT_TEST_SUITE_REGISTRATION( XmlIoTest );
CPPUNIT_TEST_SUITE_REGISTRATION( XmlIoRapidTest );
CPPUNIT_TEST_SUITE_REGISTRATION( XmlTreeTest );
CPPUNIT_TEST_SUITE_REGISTRATION( XmlNodeTest );
#if defined(WANT_XERCES)
CPPUNIT_TEST_SUITE_REGISTRATION( XmlIoTest );
CPPUNIT_TEST_SUITE_REGISTRATION( XmlAttributeTest );
#endif
//