- added insanely fast rapidxml as a supported xml engine to use. Currently its ONLY used for loading saved game xml and the currently class ONLY handles loading (not saving) xml's.
This commit is contained in:
parent
c3cd759302
commit
4bd6b53f9d
|
@ -1,7 +1,7 @@
|
||||||
CMAKE_MINIMUM_REQUIRED( VERSION 2.6.2 )
|
CMAKE_MINIMUM_REQUIRED( VERSION 2.6.2 )
|
||||||
PROJECT( MegaGlest )
|
PROJECT( MegaGlest )
|
||||||
|
|
||||||
# SET(CMAKE_VERBOSE_MAKEFILE ON)
|
#SET(CMAKE_VERBOSE_MAKEFILE ON)
|
||||||
|
|
||||||
#
|
#
|
||||||
# *NOTE: For now we assume some variation of GCC Compiler (or MingW for Windows binaries)
|
# *NOTE: For now we assume some variation of GCC Compiler (or MingW for Windows binaries)
|
||||||
|
|
|
@ -3594,7 +3594,7 @@ void Game::saveGame(string name) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void Game::loadGame(string name,Program *programPtr,bool isMasterserverMode) {
|
void Game::loadGame(string name,Program *programPtr,bool isMasterserverMode) {
|
||||||
XmlTree xmlTree;
|
XmlTree xmlTree(true);
|
||||||
|
|
||||||
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("Before load of XML\n");
|
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("Before load of XML\n");
|
||||||
std::map<string,string> mapExtraTagReplacementValues;
|
std::map<string,string> mapExtraTagReplacementValues;
|
||||||
|
@ -3602,6 +3602,9 @@ void Game::loadGame(string name,Program *programPtr,bool isMasterserverMode) {
|
||||||
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("After load of XML\n");
|
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("After load of XML\n");
|
||||||
|
|
||||||
const XmlNode *rootNode= xmlTree.getRootNode();
|
const XmlNode *rootNode= xmlTree.getRootNode();
|
||||||
|
if(rootNode->hasChild("megaglest-saved-game") == true) {
|
||||||
|
rootNode = rootNode->getChild("megaglest-saved-game");
|
||||||
|
}
|
||||||
|
|
||||||
//const XmlNode *versionNode= rootNode->getChild("megaglest-saved-game");
|
//const XmlNode *versionNode= rootNode->getChild("megaglest-saved-game");
|
||||||
const XmlNode *versionNode= rootNode;
|
const XmlNode *versionNode= rootNode;
|
||||||
|
|
|
@ -276,6 +276,7 @@ IF(BUILD_MEGAGLEST_MODEL_VIEWER OR BUILD_MEGAGLEST_MAP_EDITOR OR BUILD_MEGAGLEST
|
||||||
SET(MG_INCLUDE_FILES "")
|
SET(MG_INCLUDE_FILES "")
|
||||||
SET(MG_SOURCE_FILES "")
|
SET(MG_SOURCE_FILES "")
|
||||||
INCLUDE_DIRECTORIES( ${MG_INCLUDES_ROOT}platform/sdl )
|
INCLUDE_DIRECTORIES( ${MG_INCLUDES_ROOT}platform/sdl )
|
||||||
|
INCLUDE_DIRECTORIES( ${MG_INCLUDES_ROOT}xml/rapidxml )
|
||||||
|
|
||||||
IF(NOT WANT_STATIC_LIBS)
|
IF(NOT WANT_STATIC_LIBS)
|
||||||
MESSAGE(STATUS "*** Searching for libircclient since WANT_STATIC_LIBS is off ...")
|
MESSAGE(STATUS "*** Searching for libircclient since WANT_STATIC_LIBS is off ...")
|
||||||
|
|
|
@ -0,0 +1,52 @@
|
||||||
|
Use of this software is granted under one of the following two licenses,
|
||||||
|
to be chosen freely by the user.
|
||||||
|
|
||||||
|
1. Boost Software License - Version 1.0 - August 17th, 2003
|
||||||
|
===============================================================================
|
||||||
|
|
||||||
|
Copyright (c) 2006, 2007 Marcin Kalicinski
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person or organization
|
||||||
|
obtaining a copy of the software and accompanying documentation covered by
|
||||||
|
this license (the "Software") to use, reproduce, display, distribute,
|
||||||
|
execute, and transmit the Software, and to prepare derivative works of the
|
||||||
|
Software, and to permit third-parties to whom the Software is furnished to
|
||||||
|
do so, all subject to the following:
|
||||||
|
|
||||||
|
The copyright notices in the Software and this entire statement, including
|
||||||
|
the above license grant, this restriction and the following disclaimer,
|
||||||
|
must be included in all copies of the Software, in whole or in part, and
|
||||||
|
all derivative works of the Software, unless such copies or derivative
|
||||||
|
works are solely in the form of machine-executable object code generated by
|
||||||
|
a source language processor.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||||
|
SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||||
|
FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||||
|
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||||
|
DEALINGS IN THE SOFTWARE.
|
||||||
|
|
||||||
|
2. The MIT License
|
||||||
|
===============================================================================
|
||||||
|
|
||||||
|
Copyright (c) 2006, 2007 Marcin Kalicinski
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||||
|
of the Software, and to permit persons to whom the Software is furnished to do so,
|
||||||
|
subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all
|
||||||
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||||
|
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||||
|
IN THE SOFTWARE.
|
File diff suppressed because one or more lines are too long
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,174 @@
|
||||||
|
#ifndef RAPIDXML_ITERATORS_HPP_INCLUDED
|
||||||
|
#define RAPIDXML_ITERATORS_HPP_INCLUDED
|
||||||
|
|
||||||
|
// Copyright (C) 2006, 2009 Marcin Kalicinski
|
||||||
|
// Version 1.13
|
||||||
|
// Revision $DateTime: 2009/05/13 01:46:17 $
|
||||||
|
//! \file rapidxml_iterators.hpp This file contains rapidxml iterators
|
||||||
|
|
||||||
|
#include "rapidxml.hpp"
|
||||||
|
|
||||||
|
namespace rapidxml
|
||||||
|
{
|
||||||
|
|
||||||
|
//! Iterator of child nodes of xml_node
|
||||||
|
template<class Ch>
|
||||||
|
class node_iterator
|
||||||
|
{
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
typedef typename xml_node<Ch> value_type;
|
||||||
|
typedef typename xml_node<Ch> &reference;
|
||||||
|
typedef typename xml_node<Ch> *pointer;
|
||||||
|
typedef std::ptrdiff_t difference_type;
|
||||||
|
typedef std::bidirectional_iterator_tag iterator_category;
|
||||||
|
|
||||||
|
node_iterator()
|
||||||
|
: m_node(0)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
node_iterator(xml_node<Ch> *node)
|
||||||
|
: m_node(node->first_node())
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
reference operator *() const
|
||||||
|
{
|
||||||
|
assert(m_node);
|
||||||
|
return *m_node;
|
||||||
|
}
|
||||||
|
|
||||||
|
pointer operator->() const
|
||||||
|
{
|
||||||
|
assert(m_node);
|
||||||
|
return m_node;
|
||||||
|
}
|
||||||
|
|
||||||
|
node_iterator& operator++()
|
||||||
|
{
|
||||||
|
assert(m_node);
|
||||||
|
m_node = m_node->next_sibling();
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
node_iterator operator++(int)
|
||||||
|
{
|
||||||
|
node_iterator tmp = *this;
|
||||||
|
++this;
|
||||||
|
return tmp;
|
||||||
|
}
|
||||||
|
|
||||||
|
node_iterator& operator--()
|
||||||
|
{
|
||||||
|
assert(m_node && m_node->previous_sibling());
|
||||||
|
m_node = m_node->previous_sibling();
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
node_iterator operator--(int)
|
||||||
|
{
|
||||||
|
node_iterator tmp = *this;
|
||||||
|
++this;
|
||||||
|
return tmp;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool operator ==(const node_iterator<Ch> &rhs)
|
||||||
|
{
|
||||||
|
return m_node == rhs.m_node;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool operator !=(const node_iterator<Ch> &rhs)
|
||||||
|
{
|
||||||
|
return m_node != rhs.m_node;
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
xml_node<Ch> *m_node;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
//! Iterator of child attributes of xml_node
|
||||||
|
template<class Ch>
|
||||||
|
class attribute_iterator
|
||||||
|
{
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
typedef typename xml_attribute<Ch> value_type;
|
||||||
|
typedef typename xml_attribute<Ch> &reference;
|
||||||
|
typedef typename xml_attribute<Ch> *pointer;
|
||||||
|
typedef std::ptrdiff_t difference_type;
|
||||||
|
typedef std::bidirectional_iterator_tag iterator_category;
|
||||||
|
|
||||||
|
attribute_iterator()
|
||||||
|
: m_attribute(0)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
attribute_iterator(xml_node<Ch> *node)
|
||||||
|
: m_attribute(node->first_attribute())
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
reference operator *() const
|
||||||
|
{
|
||||||
|
assert(m_attribute);
|
||||||
|
return *m_attribute;
|
||||||
|
}
|
||||||
|
|
||||||
|
pointer operator->() const
|
||||||
|
{
|
||||||
|
assert(m_attribute);
|
||||||
|
return m_attribute;
|
||||||
|
}
|
||||||
|
|
||||||
|
attribute_iterator& operator++()
|
||||||
|
{
|
||||||
|
assert(m_attribute);
|
||||||
|
m_attribute = m_attribute->next_attribute();
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
attribute_iterator operator++(int)
|
||||||
|
{
|
||||||
|
attribute_iterator tmp = *this;
|
||||||
|
++this;
|
||||||
|
return tmp;
|
||||||
|
}
|
||||||
|
|
||||||
|
attribute_iterator& operator--()
|
||||||
|
{
|
||||||
|
assert(m_attribute && m_attribute->previous_attribute());
|
||||||
|
m_attribute = m_attribute->previous_attribute();
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
attribute_iterator operator--(int)
|
||||||
|
{
|
||||||
|
attribute_iterator tmp = *this;
|
||||||
|
++this;
|
||||||
|
return tmp;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool operator ==(const attribute_iterator<Ch> &rhs)
|
||||||
|
{
|
||||||
|
return m_attribute == rhs.m_attribute;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool operator !=(const attribute_iterator<Ch> &rhs)
|
||||||
|
{
|
||||||
|
return m_attribute != rhs.m_attribute;
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
xml_attribute<Ch> *m_attribute;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
|
@ -0,0 +1,421 @@
|
||||||
|
#ifndef RAPIDXML_PRINT_HPP_INCLUDED
|
||||||
|
#define RAPIDXML_PRINT_HPP_INCLUDED
|
||||||
|
|
||||||
|
// Copyright (C) 2006, 2009 Marcin Kalicinski
|
||||||
|
// Version 1.13
|
||||||
|
// Revision $DateTime: 2009/05/13 01:46:17 $
|
||||||
|
//! \file rapidxml_print.hpp This file contains rapidxml printer implementation
|
||||||
|
|
||||||
|
#include "rapidxml.hpp"
|
||||||
|
|
||||||
|
// Only include streams if not disabled
|
||||||
|
#ifndef RAPIDXML_NO_STREAMS
|
||||||
|
#include <ostream>
|
||||||
|
#include <iterator>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
namespace rapidxml
|
||||||
|
{
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////////////////
|
||||||
|
// Printing flags
|
||||||
|
|
||||||
|
const int print_no_indenting = 0x1; //!< Printer flag instructing the printer to suppress indenting of XML. See print() function.
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////////////////
|
||||||
|
// Internal
|
||||||
|
|
||||||
|
//! \cond internal
|
||||||
|
namespace internal
|
||||||
|
{
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////////////////////
|
||||||
|
// Internal character operations
|
||||||
|
|
||||||
|
// Copy characters from given range to given output iterator
|
||||||
|
template<class OutIt, class Ch>
|
||||||
|
inline OutIt copy_chars(const Ch *begin, const Ch *end, OutIt out)
|
||||||
|
{
|
||||||
|
while (begin != end)
|
||||||
|
*out++ = *begin++;
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Copy characters from given range to given output iterator and expand
|
||||||
|
// characters into references (< > ' " &)
|
||||||
|
template<class OutIt, class Ch>
|
||||||
|
inline OutIt copy_and_expand_chars(const Ch *begin, const Ch *end, Ch noexpand, OutIt out)
|
||||||
|
{
|
||||||
|
while (begin != end)
|
||||||
|
{
|
||||||
|
if (*begin == noexpand)
|
||||||
|
{
|
||||||
|
*out++ = *begin; // No expansion, copy character
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
switch (*begin)
|
||||||
|
{
|
||||||
|
case Ch('<'):
|
||||||
|
*out++ = Ch('&'); *out++ = Ch('l'); *out++ = Ch('t'); *out++ = Ch(';');
|
||||||
|
break;
|
||||||
|
case Ch('>'):
|
||||||
|
*out++ = Ch('&'); *out++ = Ch('g'); *out++ = Ch('t'); *out++ = Ch(';');
|
||||||
|
break;
|
||||||
|
case Ch('\''):
|
||||||
|
*out++ = Ch('&'); *out++ = Ch('a'); *out++ = Ch('p'); *out++ = Ch('o'); *out++ = Ch('s'); *out++ = Ch(';');
|
||||||
|
break;
|
||||||
|
case Ch('"'):
|
||||||
|
*out++ = Ch('&'); *out++ = Ch('q'); *out++ = Ch('u'); *out++ = Ch('o'); *out++ = Ch('t'); *out++ = Ch(';');
|
||||||
|
break;
|
||||||
|
case Ch('&'):
|
||||||
|
*out++ = Ch('&'); *out++ = Ch('a'); *out++ = Ch('m'); *out++ = Ch('p'); *out++ = Ch(';');
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
*out++ = *begin; // No expansion, copy character
|
||||||
|
}
|
||||||
|
}
|
||||||
|
++begin; // Step to next character
|
||||||
|
}
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Fill given output iterator with repetitions of the same character
|
||||||
|
template<class OutIt, class Ch>
|
||||||
|
inline OutIt fill_chars(OutIt out, int n, Ch ch)
|
||||||
|
{
|
||||||
|
for (int i = 0; i < n; ++i)
|
||||||
|
*out++ = ch;
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Find character
|
||||||
|
template<class Ch, Ch ch>
|
||||||
|
inline bool find_char(const Ch *begin, const Ch *end)
|
||||||
|
{
|
||||||
|
while (begin != end)
|
||||||
|
if (*begin++ == ch)
|
||||||
|
return true;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////////////////////
|
||||||
|
// Internal printing operations
|
||||||
|
|
||||||
|
// Print node
|
||||||
|
template<class OutIt, class Ch>
|
||||||
|
inline OutIt print_node(OutIt out, const xml_node<Ch> *node, int flags, int indent)
|
||||||
|
{
|
||||||
|
// Print proper node type
|
||||||
|
switch (node->type())
|
||||||
|
{
|
||||||
|
|
||||||
|
// Document
|
||||||
|
case node_document:
|
||||||
|
out = print_children(out, node, flags, indent);
|
||||||
|
break;
|
||||||
|
|
||||||
|
// Element
|
||||||
|
case node_element:
|
||||||
|
out = print_element_node(out, node, flags, indent);
|
||||||
|
break;
|
||||||
|
|
||||||
|
// Data
|
||||||
|
case node_data:
|
||||||
|
out = print_data_node(out, node, flags, indent);
|
||||||
|
break;
|
||||||
|
|
||||||
|
// CDATA
|
||||||
|
case node_cdata:
|
||||||
|
out = print_cdata_node(out, node, flags, indent);
|
||||||
|
break;
|
||||||
|
|
||||||
|
// Declaration
|
||||||
|
case node_declaration:
|
||||||
|
out = print_declaration_node(out, node, flags, indent);
|
||||||
|
break;
|
||||||
|
|
||||||
|
// Comment
|
||||||
|
case node_comment:
|
||||||
|
out = print_comment_node(out, node, flags, indent);
|
||||||
|
break;
|
||||||
|
|
||||||
|
// Doctype
|
||||||
|
case node_doctype:
|
||||||
|
out = print_doctype_node(out, node, flags, indent);
|
||||||
|
break;
|
||||||
|
|
||||||
|
// Pi
|
||||||
|
case node_pi:
|
||||||
|
out = print_pi_node(out, node, flags, indent);
|
||||||
|
break;
|
||||||
|
|
||||||
|
// Unknown
|
||||||
|
default:
|
||||||
|
assert(0);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
// If indenting not disabled, add line break after node
|
||||||
|
if (!(flags & print_no_indenting))
|
||||||
|
*out = Ch('\n'), ++out;
|
||||||
|
|
||||||
|
// Return modified iterator
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Print children of the node
|
||||||
|
template<class OutIt, class Ch>
|
||||||
|
inline OutIt print_children(OutIt out, const xml_node<Ch> *node, int flags, int indent)
|
||||||
|
{
|
||||||
|
for (xml_node<Ch> *child = node->first_node(); child; child = child->next_sibling())
|
||||||
|
out = print_node(out, child, flags, indent);
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Print attributes of the node
|
||||||
|
template<class OutIt, class Ch>
|
||||||
|
inline OutIt print_attributes(OutIt out, const xml_node<Ch> *node, int flags)
|
||||||
|
{
|
||||||
|
for (xml_attribute<Ch> *attribute = node->first_attribute(); attribute; attribute = attribute->next_attribute())
|
||||||
|
{
|
||||||
|
if (attribute->name() && attribute->value())
|
||||||
|
{
|
||||||
|
// Print attribute name
|
||||||
|
*out = Ch(' '), ++out;
|
||||||
|
out = copy_chars(attribute->name(), attribute->name() + attribute->name_size(), out);
|
||||||
|
*out = Ch('='), ++out;
|
||||||
|
// Print attribute value using appropriate quote type
|
||||||
|
if (find_char<Ch, Ch('"')>(attribute->value(), attribute->value() + attribute->value_size()))
|
||||||
|
{
|
||||||
|
*out = Ch('\''), ++out;
|
||||||
|
out = copy_and_expand_chars(attribute->value(), attribute->value() + attribute->value_size(), Ch('"'), out);
|
||||||
|
*out = Ch('\''), ++out;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
*out = Ch('"'), ++out;
|
||||||
|
out = copy_and_expand_chars(attribute->value(), attribute->value() + attribute->value_size(), Ch('\''), out);
|
||||||
|
*out = Ch('"'), ++out;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Print data node
|
||||||
|
template<class OutIt, class Ch>
|
||||||
|
inline OutIt print_data_node(OutIt out, const xml_node<Ch> *node, int flags, int indent)
|
||||||
|
{
|
||||||
|
assert(node->type() == node_data);
|
||||||
|
if (!(flags & print_no_indenting))
|
||||||
|
out = fill_chars(out, indent, Ch('\t'));
|
||||||
|
out = copy_and_expand_chars(node->value(), node->value() + node->value_size(), Ch(0), out);
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Print data node
|
||||||
|
template<class OutIt, class Ch>
|
||||||
|
inline OutIt print_cdata_node(OutIt out, const xml_node<Ch> *node, int flags, int indent)
|
||||||
|
{
|
||||||
|
assert(node->type() == node_cdata);
|
||||||
|
if (!(flags & print_no_indenting))
|
||||||
|
out = fill_chars(out, indent, Ch('\t'));
|
||||||
|
*out = Ch('<'); ++out;
|
||||||
|
*out = Ch('!'); ++out;
|
||||||
|
*out = Ch('['); ++out;
|
||||||
|
*out = Ch('C'); ++out;
|
||||||
|
*out = Ch('D'); ++out;
|
||||||
|
*out = Ch('A'); ++out;
|
||||||
|
*out = Ch('T'); ++out;
|
||||||
|
*out = Ch('A'); ++out;
|
||||||
|
*out = Ch('['); ++out;
|
||||||
|
out = copy_chars(node->value(), node->value() + node->value_size(), out);
|
||||||
|
*out = Ch(']'); ++out;
|
||||||
|
*out = Ch(']'); ++out;
|
||||||
|
*out = Ch('>'); ++out;
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Print element node
|
||||||
|
template<class OutIt, class Ch>
|
||||||
|
inline OutIt print_element_node(OutIt out, const xml_node<Ch> *node, int flags, int indent)
|
||||||
|
{
|
||||||
|
assert(node->type() == node_element);
|
||||||
|
|
||||||
|
// Print element name and attributes, if any
|
||||||
|
if (!(flags & print_no_indenting))
|
||||||
|
out = fill_chars(out, indent, Ch('\t'));
|
||||||
|
*out = Ch('<'), ++out;
|
||||||
|
out = copy_chars(node->name(), node->name() + node->name_size(), out);
|
||||||
|
out = print_attributes(out, node, flags);
|
||||||
|
|
||||||
|
// If node is childless
|
||||||
|
if (node->value_size() == 0 && !node->first_node())
|
||||||
|
{
|
||||||
|
// Print childless node tag ending
|
||||||
|
*out = Ch('/'), ++out;
|
||||||
|
*out = Ch('>'), ++out;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// Print normal node tag ending
|
||||||
|
*out = Ch('>'), ++out;
|
||||||
|
|
||||||
|
// Test if node contains a single data node only (and no other nodes)
|
||||||
|
xml_node<Ch> *child = node->first_node();
|
||||||
|
if (!child)
|
||||||
|
{
|
||||||
|
// If node has no children, only print its value without indenting
|
||||||
|
out = copy_and_expand_chars(node->value(), node->value() + node->value_size(), Ch(0), out);
|
||||||
|
}
|
||||||
|
else if (child->next_sibling() == 0 && child->type() == node_data)
|
||||||
|
{
|
||||||
|
// If node has a sole data child, only print its value without indenting
|
||||||
|
out = copy_and_expand_chars(child->value(), child->value() + child->value_size(), Ch(0), out);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// Print all children with full indenting
|
||||||
|
if (!(flags & print_no_indenting))
|
||||||
|
*out = Ch('\n'), ++out;
|
||||||
|
out = print_children(out, node, flags, indent + 1);
|
||||||
|
if (!(flags & print_no_indenting))
|
||||||
|
out = fill_chars(out, indent, Ch('\t'));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Print node end
|
||||||
|
*out = Ch('<'), ++out;
|
||||||
|
*out = Ch('/'), ++out;
|
||||||
|
out = copy_chars(node->name(), node->name() + node->name_size(), out);
|
||||||
|
*out = Ch('>'), ++out;
|
||||||
|
}
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Print declaration node
|
||||||
|
template<class OutIt, class Ch>
|
||||||
|
inline OutIt print_declaration_node(OutIt out, const xml_node<Ch> *node, int flags, int indent)
|
||||||
|
{
|
||||||
|
// Print declaration start
|
||||||
|
if (!(flags & print_no_indenting))
|
||||||
|
out = fill_chars(out, indent, Ch('\t'));
|
||||||
|
*out = Ch('<'), ++out;
|
||||||
|
*out = Ch('?'), ++out;
|
||||||
|
*out = Ch('x'), ++out;
|
||||||
|
*out = Ch('m'), ++out;
|
||||||
|
*out = Ch('l'), ++out;
|
||||||
|
|
||||||
|
// Print attributes
|
||||||
|
out = print_attributes(out, node, flags);
|
||||||
|
|
||||||
|
// Print declaration end
|
||||||
|
*out = Ch('?'), ++out;
|
||||||
|
*out = Ch('>'), ++out;
|
||||||
|
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Print comment node
|
||||||
|
template<class OutIt, class Ch>
|
||||||
|
inline OutIt print_comment_node(OutIt out, const xml_node<Ch> *node, int flags, int indent)
|
||||||
|
{
|
||||||
|
assert(node->type() == node_comment);
|
||||||
|
if (!(flags & print_no_indenting))
|
||||||
|
out = fill_chars(out, indent, Ch('\t'));
|
||||||
|
*out = Ch('<'), ++out;
|
||||||
|
*out = Ch('!'), ++out;
|
||||||
|
*out = Ch('-'), ++out;
|
||||||
|
*out = Ch('-'), ++out;
|
||||||
|
out = copy_chars(node->value(), node->value() + node->value_size(), out);
|
||||||
|
*out = Ch('-'), ++out;
|
||||||
|
*out = Ch('-'), ++out;
|
||||||
|
*out = Ch('>'), ++out;
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Print doctype node
|
||||||
|
template<class OutIt, class Ch>
|
||||||
|
inline OutIt print_doctype_node(OutIt out, const xml_node<Ch> *node, int flags, int indent)
|
||||||
|
{
|
||||||
|
assert(node->type() == node_doctype);
|
||||||
|
if (!(flags & print_no_indenting))
|
||||||
|
out = fill_chars(out, indent, Ch('\t'));
|
||||||
|
*out = Ch('<'), ++out;
|
||||||
|
*out = Ch('!'), ++out;
|
||||||
|
*out = Ch('D'), ++out;
|
||||||
|
*out = Ch('O'), ++out;
|
||||||
|
*out = Ch('C'), ++out;
|
||||||
|
*out = Ch('T'), ++out;
|
||||||
|
*out = Ch('Y'), ++out;
|
||||||
|
*out = Ch('P'), ++out;
|
||||||
|
*out = Ch('E'), ++out;
|
||||||
|
*out = Ch(' '), ++out;
|
||||||
|
out = copy_chars(node->value(), node->value() + node->value_size(), out);
|
||||||
|
*out = Ch('>'), ++out;
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Print pi node
|
||||||
|
template<class OutIt, class Ch>
|
||||||
|
inline OutIt print_pi_node(OutIt out, const xml_node<Ch> *node, int flags, int indent)
|
||||||
|
{
|
||||||
|
assert(node->type() == node_pi);
|
||||||
|
if (!(flags & print_no_indenting))
|
||||||
|
out = fill_chars(out, indent, Ch('\t'));
|
||||||
|
*out = Ch('<'), ++out;
|
||||||
|
*out = Ch('?'), ++out;
|
||||||
|
out = copy_chars(node->name(), node->name() + node->name_size(), out);
|
||||||
|
*out = Ch(' '), ++out;
|
||||||
|
out = copy_chars(node->value(), node->value() + node->value_size(), out);
|
||||||
|
*out = Ch('?'), ++out;
|
||||||
|
*out = Ch('>'), ++out;
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
//! \endcond
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////////////////////
|
||||||
|
// Printing
|
||||||
|
|
||||||
|
//! Prints XML to given output iterator.
|
||||||
|
//! \param out Output iterator to print to.
|
||||||
|
//! \param node Node to be printed. Pass xml_document to print entire document.
|
||||||
|
//! \param flags Flags controlling how XML is printed.
|
||||||
|
//! \return Output iterator pointing to position immediately after last character of printed text.
|
||||||
|
template<class OutIt, class Ch>
|
||||||
|
inline OutIt print(OutIt out, const xml_node<Ch> &node, int flags = 0)
|
||||||
|
{
|
||||||
|
return internal::print_node(out, &node, flags, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifndef RAPIDXML_NO_STREAMS
|
||||||
|
|
||||||
|
//! Prints XML to given output stream.
|
||||||
|
//! \param out Output stream to print to.
|
||||||
|
//! \param node Node to be printed. Pass xml_document to print entire document.
|
||||||
|
//! \param flags Flags controlling how XML is printed.
|
||||||
|
//! \return Output stream.
|
||||||
|
template<class Ch>
|
||||||
|
inline std::basic_ostream<Ch> &print(std::basic_ostream<Ch> &out, const xml_node<Ch> &node, int flags = 0)
|
||||||
|
{
|
||||||
|
print(std::ostream_iterator<Ch>(out), node, flags);
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
|
||||||
|
//! Prints formatted XML to given output stream. Uses default printing flags. Use print() function to customize printing process.
|
||||||
|
//! \param out Output stream to print to.
|
||||||
|
//! \param node Node to be printed.
|
||||||
|
//! \return Output stream.
|
||||||
|
template<class Ch>
|
||||||
|
inline std::basic_ostream<Ch> &operator <<(std::basic_ostream<Ch> &out, const xml_node<Ch> &node)
|
||||||
|
{
|
||||||
|
return print(out, node);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
|
@ -0,0 +1,122 @@
|
||||||
|
#ifndef RAPIDXML_UTILS_HPP_INCLUDED
|
||||||
|
#define RAPIDXML_UTILS_HPP_INCLUDED
|
||||||
|
|
||||||
|
// Copyright (C) 2006, 2009 Marcin Kalicinski
|
||||||
|
// Version 1.13
|
||||||
|
// Revision $DateTime: 2009/05/13 01:46:17 $
|
||||||
|
//! \file rapidxml_utils.hpp This file contains high-level rapidxml utilities that can be useful
|
||||||
|
//! in certain simple scenarios. They should probably not be used if maximizing performance is the main objective.
|
||||||
|
|
||||||
|
#include "rapidxml.hpp"
|
||||||
|
#include <vector>
|
||||||
|
#include <string>
|
||||||
|
#include <fstream>
|
||||||
|
#include <stdexcept>
|
||||||
|
|
||||||
|
namespace rapidxml
|
||||||
|
{
|
||||||
|
|
||||||
|
//! Represents data loaded from a file
|
||||||
|
template<class Ch = char>
|
||||||
|
class file
|
||||||
|
{
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
//! Loads file into the memory. Data will be automatically destroyed by the destructor.
|
||||||
|
//! \param filename Filename to load.
|
||||||
|
file(const char *filename)
|
||||||
|
{
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
// Open stream
|
||||||
|
basic_ifstream<Ch> stream(filename, ios::binary);
|
||||||
|
if (!stream)
|
||||||
|
throw runtime_error(string("cannot open file ") + filename);
|
||||||
|
stream.unsetf(ios::skipws);
|
||||||
|
|
||||||
|
// Determine stream size
|
||||||
|
stream.seekg(0, ios::end);
|
||||||
|
size_t size = stream.tellg();
|
||||||
|
stream.seekg(0);
|
||||||
|
|
||||||
|
// Load data and add terminating 0
|
||||||
|
m_data.resize(size + 1);
|
||||||
|
stream.read(&m_data.front(), static_cast<streamsize>(size));
|
||||||
|
m_data[size] = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
//! Loads file into the memory. Data will be automatically destroyed by the destructor
|
||||||
|
//! \param stream Stream to load from
|
||||||
|
file(std::basic_istream<Ch> &stream)
|
||||||
|
{
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
// Load data and add terminating 0
|
||||||
|
stream.unsetf(ios::skipws);
|
||||||
|
m_data.assign(istreambuf_iterator<Ch>(stream), istreambuf_iterator<Ch>());
|
||||||
|
if (stream.fail() || stream.bad())
|
||||||
|
throw runtime_error("error reading stream");
|
||||||
|
m_data.push_back(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
//! Gets file data.
|
||||||
|
//! \return Pointer to data of file.
|
||||||
|
Ch *data()
|
||||||
|
{
|
||||||
|
return &m_data.front();
|
||||||
|
}
|
||||||
|
|
||||||
|
//! Gets file data.
|
||||||
|
//! \return Pointer to data of file.
|
||||||
|
const Ch *data() const
|
||||||
|
{
|
||||||
|
return &m_data.front();
|
||||||
|
}
|
||||||
|
|
||||||
|
//! Gets file data size.
|
||||||
|
//! \return Size of file data, in characters.
|
||||||
|
std::size_t size() const
|
||||||
|
{
|
||||||
|
return m_data.size();
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
std::vector<Ch> m_data; // File data
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
//! Counts children of node. Time complexity is O(n).
|
||||||
|
//! \return Number of children of node
|
||||||
|
template<class Ch>
|
||||||
|
inline std::size_t count_children(xml_node<Ch> *node)
|
||||||
|
{
|
||||||
|
xml_node<Ch> *child = node->first_node();
|
||||||
|
std::size_t count = 0;
|
||||||
|
while (child)
|
||||||
|
{
|
||||||
|
++count;
|
||||||
|
child = child->next_sibling();
|
||||||
|
}
|
||||||
|
return count;
|
||||||
|
}
|
||||||
|
|
||||||
|
//! Counts attributes of node. Time complexity is O(n).
|
||||||
|
//! \return Number of attributes of node
|
||||||
|
template<class Ch>
|
||||||
|
inline std::size_t count_attributes(xml_node<Ch> *node)
|
||||||
|
{
|
||||||
|
xml_attribute<Ch> *attr = node->first_attribute();
|
||||||
|
std::size_t count = 0;
|
||||||
|
while (attr)
|
||||||
|
{
|
||||||
|
++count;
|
||||||
|
attr = attr->next_attribute();
|
||||||
|
}
|
||||||
|
return count;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
|
@ -16,8 +16,10 @@
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <xercesc/util/XercesDefs.hpp>
|
#include <xercesc/util/XercesDefs.hpp>
|
||||||
#include <map>
|
#include <map>
|
||||||
|
#include "rapidxml/rapidxml.hpp"
|
||||||
#include "leak_dumper.h"
|
#include "leak_dumper.h"
|
||||||
|
|
||||||
|
using namespace rapidxml;
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
namespace XERCES_CPP_NAMESPACE{
|
namespace XERCES_CPP_NAMESPACE{
|
||||||
|
@ -59,6 +61,23 @@ public:
|
||||||
void save(const string &path, const XmlNode *node);
|
void save(const string &path, const XmlNode *node);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class XmlIoRapid {
|
||||||
|
private:
|
||||||
|
static bool initialized;
|
||||||
|
rapidxml::xml_document<> *doc;
|
||||||
|
|
||||||
|
private:
|
||||||
|
XmlIoRapid();
|
||||||
|
|
||||||
|
public:
|
||||||
|
static XmlIoRapid &getInstance();
|
||||||
|
~XmlIoRapid();
|
||||||
|
void cleanup();
|
||||||
|
|
||||||
|
XmlNode *load(const string &path, std::map<string,string> mapTagReplacementValues,bool noValidation=false);
|
||||||
|
void save(const string &path, const XmlNode *node);
|
||||||
|
};
|
||||||
|
|
||||||
// =====================================================
|
// =====================================================
|
||||||
// class XmlTree
|
// class XmlTree
|
||||||
// =====================================================
|
// =====================================================
|
||||||
|
@ -67,12 +86,13 @@ class XmlTree{
|
||||||
private:
|
private:
|
||||||
XmlNode *rootNode;
|
XmlNode *rootNode;
|
||||||
string loadPath;
|
string loadPath;
|
||||||
|
bool wantRapidXmlTree;
|
||||||
private:
|
private:
|
||||||
XmlTree(XmlTree&);
|
XmlTree(XmlTree&);
|
||||||
void operator =(XmlTree&);
|
void operator =(XmlTree&);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
XmlTree();
|
XmlTree(bool wantRapidXmlTree = false);
|
||||||
~XmlTree();
|
~XmlTree();
|
||||||
|
|
||||||
void init(const string &name);
|
void init(const string &name);
|
||||||
|
@ -100,6 +120,7 @@ private:
|
||||||
|
|
||||||
public:
|
public:
|
||||||
XmlNode(XERCES_CPP_NAMESPACE::DOMNode *node, std::map<string,string> mapTagReplacementValues);
|
XmlNode(XERCES_CPP_NAMESPACE::DOMNode *node, std::map<string,string> mapTagReplacementValues);
|
||||||
|
XmlNode(xml_node<> *node, std::map<string,string> mapTagReplacementValues);
|
||||||
XmlNode(const string &name);
|
XmlNode(const string &name);
|
||||||
~XmlNode();
|
~XmlNode();
|
||||||
|
|
||||||
|
@ -150,6 +171,7 @@ private:
|
||||||
|
|
||||||
public:
|
public:
|
||||||
XmlAttribute(XERCES_CPP_NAMESPACE::DOMNode *attribute, std::map<string,string> mapTagReplacementValues);
|
XmlAttribute(XERCES_CPP_NAMESPACE::DOMNode *attribute, std::map<string,string> mapTagReplacementValues);
|
||||||
|
XmlAttribute(xml_attribute<> *attribute, std::map<string,string> mapTagReplacementValues);
|
||||||
XmlAttribute(const string &name, const string &value, std::map<string,string> mapTagReplacementValues);
|
XmlAttribute(const string &name, const string &value, std::map<string,string> mapTagReplacementValues);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
|
@ -26,8 +26,8 @@
|
||||||
#include "platform_common.h"
|
#include "platform_common.h"
|
||||||
#include "platform_util.h"
|
#include "platform_util.h"
|
||||||
#include "cache_manager.h"
|
#include "cache_manager.h"
|
||||||
#include "leak_dumper.h"
|
|
||||||
|
|
||||||
|
#include "leak_dumper.h"
|
||||||
|
|
||||||
XERCES_CPP_NAMESPACE_USE
|
XERCES_CPP_NAMESPACE_USE
|
||||||
|
|
||||||
|
@ -61,6 +61,7 @@ public:
|
||||||
// =====================================================
|
// =====================================================
|
||||||
|
|
||||||
bool XmlIo::initialized= false;
|
bool XmlIo::initialized= false;
|
||||||
|
bool XmlIoRapid::initialized= false;
|
||||||
|
|
||||||
XmlIo::XmlIo() {
|
XmlIo::XmlIo() {
|
||||||
try{
|
try{
|
||||||
|
@ -216,12 +217,154 @@ void XmlIo::save(const string &path, const XmlNode *node){
|
||||||
throw runtime_error("Exception while saving: " + path + ": " + XMLString::transcode(e.msg));
|
throw runtime_error("Exception while saving: " + path + ": " + XMLString::transcode(e.msg));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// =====================================================
|
||||||
|
// class XmlIoRapid
|
||||||
|
// =====================================================
|
||||||
|
XmlIoRapid::XmlIoRapid() {
|
||||||
|
try{
|
||||||
|
//printf("XmlIo init\n");
|
||||||
|
|
||||||
|
XmlIoRapid::initialized= true;
|
||||||
|
}
|
||||||
|
catch(const exception &e){
|
||||||
|
SystemFlags::OutputDebug(SystemFlags::debugError,"In [%s::%s Line: %d] Error initializing XML system, msg %s\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,e.what());
|
||||||
|
throw runtime_error("Error initializing XML system");
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
doc = new rapidxml::xml_document<>();
|
||||||
|
}
|
||||||
|
catch(const DOMException &ex) {
|
||||||
|
SystemFlags::OutputDebug(SystemFlags::debugError,"In [%s::%s Line: %d] Exception while creating XML parser, msg: %s\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,ex.getMessage());
|
||||||
|
throw runtime_error("Exception while creating XML parser");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
XmlIoRapid &XmlIoRapid::getInstance() {
|
||||||
|
static XmlIoRapid io;
|
||||||
|
return io;
|
||||||
|
}
|
||||||
|
|
||||||
|
void XmlIoRapid::cleanup() {
|
||||||
|
if(XmlIoRapid::initialized == true) {
|
||||||
|
XmlIoRapid::initialized= false;
|
||||||
|
//printf("XmlIo cleanup\n");
|
||||||
|
delete doc;
|
||||||
|
doc = NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
XmlIoRapid::~XmlIoRapid() {
|
||||||
|
cleanup();
|
||||||
|
}
|
||||||
|
|
||||||
|
XmlNode *XmlIoRapid::load(const string &path, std::map<string,string> mapTagReplacementValues,bool noValidation) {
|
||||||
|
Chrono chrono;
|
||||||
|
chrono.start();
|
||||||
|
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("Using RapidXml to load file [%s]\n",path.c_str());
|
||||||
|
|
||||||
|
XmlNode *rootNode = NULL;
|
||||||
|
try {
|
||||||
|
#if defined(WIN32) && !defined(__MINGW32__)
|
||||||
|
FILE *fp = _wfopen(utf8_decode(path).c_str(), L"rb");
|
||||||
|
ifstream xmlFile(fp);
|
||||||
|
#else
|
||||||
|
ifstream xmlFile(path.c_str());
|
||||||
|
#endif
|
||||||
|
if(xmlFile.is_open() == false) {
|
||||||
|
throw runtime_error("Can not open file: [" + path + "]");
|
||||||
|
}
|
||||||
|
|
||||||
|
// read file into input_xml
|
||||||
|
string inputXml = "";
|
||||||
|
string line = "";
|
||||||
|
while(getline(xmlFile,line)) {
|
||||||
|
inputXml += line;
|
||||||
|
}
|
||||||
|
// make a safe-to-modify copy of input_xml
|
||||||
|
// (you should never modify the contents of an std::string directly)
|
||||||
|
vector<char> buffer(inputXml.begin(), inputXml.end());
|
||||||
|
buffer.push_back('\0');
|
||||||
|
|
||||||
|
/* "Read file into vector<char>" See linked thread above*/
|
||||||
|
//vector<char> buffer((istreambuf_iterator<char>(xmlFile)), istreambuf_iterator<char>( ));
|
||||||
|
//buffer.push_back('\0');
|
||||||
|
doc->parse<parse_no_data_nodes>(&buffer[0]);
|
||||||
|
|
||||||
|
rootNode= new XmlNode(doc->first_node(),mapTagReplacementValues);
|
||||||
|
//parser->release();
|
||||||
|
|
||||||
|
#if defined(WIN32) && !defined(__MINGW32__)
|
||||||
|
if(fp) {
|
||||||
|
fclose(fp);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
catch(const DOMException &ex) {
|
||||||
|
char szBuf[8096]="";
|
||||||
|
sprintf(szBuf,"In [%s::%s Line: %d] Exception while loading: [%s], msg:\n%s",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,path.c_str(),XMLString::transcode(ex.msg));
|
||||||
|
SystemFlags::OutputDebug(SystemFlags::debugError,"%s\n",szBuf);
|
||||||
|
|
||||||
|
throw runtime_error(szBuf);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line: %d] took msecs: %lld\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,chrono.getMillis());
|
||||||
|
|
||||||
|
return rootNode;
|
||||||
|
}
|
||||||
|
|
||||||
|
void XmlIoRapid::save(const string &path, const XmlNode *node){
|
||||||
|
// try{
|
||||||
|
// XMLCh str[strSize];
|
||||||
|
// XMLString::transcode(node->getName().c_str(), str, strSize-1);
|
||||||
|
//
|
||||||
|
// XERCES_CPP_NAMESPACE_QUALIFIER DOMDocument *document= implementation->createDocument(0, str, 0);
|
||||||
|
// DOMElement *documentElement= document->getDocumentElement();
|
||||||
|
// for(unsigned int i = 0; i < node->getAttributeCount() ; ++i){
|
||||||
|
// XmlAttribute *attr = node->getAttribute(i);
|
||||||
|
//
|
||||||
|
// XMLCh strName[strSize];
|
||||||
|
// XMLString::transcode(attr->getName().c_str(), strName, strSize-1);
|
||||||
|
// XMLCh strValue[strSize];
|
||||||
|
// XMLString::transcode(attr->getValue("",false).c_str(), strValue, strSize-1);
|
||||||
|
//
|
||||||
|
// documentElement->setAttribute(strName,strValue);
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// for(unsigned int i=0; i<node->getChildCount(); ++i){
|
||||||
|
// documentElement->appendChild(node->getChild(i)->buildElement(document));
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// LocalFileFormatTarget file(path.c_str());
|
||||||
|
//#if XERCES_VERSION_MAJOR < 3
|
||||||
|
// DOMWriter* writer = implementation->createDOMWriter();
|
||||||
|
// writer->setFeature(XMLUni::fgDOMWRTFormatPrettyPrint, true);
|
||||||
|
// writer->writeNode(&file, *document);
|
||||||
|
//#else
|
||||||
|
// DOMLSSerializer *serializer = implementation->createLSSerializer();
|
||||||
|
// DOMLSOutput* output=implementation->createLSOutput();
|
||||||
|
// DOMConfiguration* config=serializer->getDomConfig();
|
||||||
|
// config->setParameter(XMLUni::fgDOMWRTFormatPrettyPrint,true);
|
||||||
|
// output->setByteStream(&file);
|
||||||
|
// serializer->write(document,output);
|
||||||
|
// output->release();
|
||||||
|
// serializer->release();
|
||||||
|
//#endif
|
||||||
|
// document->release();
|
||||||
|
// }
|
||||||
|
// catch(const DOMException &e){
|
||||||
|
// SystemFlags::OutputDebug(SystemFlags::debugError,"In [%s::%s Line: %d] Exception while saving: [%s], %s\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,path.c_str(),XMLString::transcode(e.msg));
|
||||||
|
// throw runtime_error("Exception while saving: " + path + ": " + XMLString::transcode(e.msg));
|
||||||
|
// }
|
||||||
|
}
|
||||||
|
|
||||||
// =====================================================
|
// =====================================================
|
||||||
// class XmlTree
|
// class XmlTree
|
||||||
// =====================================================
|
// =====================================================
|
||||||
|
XmlTree::XmlTree(bool wantRapidXmlTree) {
|
||||||
XmlTree::XmlTree(){
|
|
||||||
rootNode= NULL;
|
rootNode= NULL;
|
||||||
|
this->wantRapidXmlTree = wantRapidXmlTree;
|
||||||
}
|
}
|
||||||
|
|
||||||
void XmlTree::init(const string &name){
|
void XmlTree::init(const string &name){
|
||||||
|
@ -251,13 +394,23 @@ void XmlTree::load(const string &path, std::map<string,string> mapTagReplacement
|
||||||
safeMutex.ReleaseLock();
|
safeMutex.ReleaseLock();
|
||||||
|
|
||||||
loadPath = path;
|
loadPath = path;
|
||||||
|
if(this->wantRapidXmlTree == false) {
|
||||||
this->rootNode= XmlIo::getInstance().load(path, mapTagReplacementValues, noValidation);
|
this->rootNode= XmlIo::getInstance().load(path, mapTagReplacementValues, noValidation);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
this->rootNode= XmlIoRapid::getInstance().load(path, mapTagReplacementValues, noValidation);
|
||||||
|
}
|
||||||
|
|
||||||
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());
|
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(this->wantRapidXmlTree == false) {
|
||||||
XmlIo::getInstance().save(path, rootNode);
|
XmlIo::getInstance().save(path, rootNode);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
XmlIoRapid::getInstance().save(path, rootNode);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
XmlTree::~XmlTree() {
|
XmlTree::~XmlTree() {
|
||||||
|
@ -327,6 +480,44 @@ XmlNode::XmlNode(DOMNode *node, std::map<string,string> mapTagReplacementValues)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
XmlNode::XmlNode(xml_node<> *node, std::map<string,string> mapTagReplacementValues) : superNode(NULL) {
|
||||||
|
if(node == NULL || node->name() == NULL) {
|
||||||
|
throw runtime_error("XML structure seems to be corrupt!");
|
||||||
|
}
|
||||||
|
|
||||||
|
//get name
|
||||||
|
name = node->name();
|
||||||
|
|
||||||
|
//check document
|
||||||
|
if(node->type() == node_document) {
|
||||||
|
name="document";
|
||||||
|
}
|
||||||
|
|
||||||
|
//printf("Found XML Node [%s]\n",name.c_str());
|
||||||
|
|
||||||
|
//check children
|
||||||
|
for(xml_node<> *currentNode = node->first_node();
|
||||||
|
currentNode; currentNode = currentNode->next_sibling()) {
|
||||||
|
if(currentNode != NULL && currentNode->type() == node_element) {
|
||||||
|
XmlNode *xmlNode= new XmlNode(currentNode, mapTagReplacementValues);
|
||||||
|
children.push_back(xmlNode);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//check attributes
|
||||||
|
for (xml_attribute<> *attr = node->first_attribute();
|
||||||
|
attr; attr = attr->next_attribute()) {
|
||||||
|
XmlAttribute *xmlAttribute= new XmlAttribute(attr, mapTagReplacementValues);
|
||||||
|
attributes.push_back(xmlAttribute);
|
||||||
|
}
|
||||||
|
|
||||||
|
//get value
|
||||||
|
if(node->type() == node_element && children.size() == 0) {
|
||||||
|
text = node->value();
|
||||||
|
Properties::applyTagsToValue(this->text);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
XmlNode::XmlNode(const string &name): superNode(NULL) {
|
XmlNode::XmlNode(const string &name): superNode(NULL) {
|
||||||
this->name= name;
|
this->name= name;
|
||||||
}
|
}
|
||||||
|
@ -512,6 +703,21 @@ XmlAttribute::XmlAttribute(DOMNode *attribute, std::map<string,string> mapTagRep
|
||||||
name= str;
|
name= str;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
XmlAttribute::XmlAttribute(xml_attribute<> *attribute, std::map<string,string> mapTagReplacementValues) {
|
||||||
|
skipRestrictionCheck = false;
|
||||||
|
usesCommondata = false;
|
||||||
|
this->mapTagReplacementValues = mapTagReplacementValues;
|
||||||
|
//char str[strSize] = "";
|
||||||
|
|
||||||
|
//XMLString::transcode(attribute->getNodeValue(), str, strSize-1);
|
||||||
|
value= attribute->value();
|
||||||
|
usesCommondata = ((value.find("$COMMONDATAPATH") != string::npos) || (value.find("%%COMMONDATAPATH%%") != string::npos));
|
||||||
|
skipRestrictionCheck = Properties::applyTagsToValue(this->value,&this->mapTagReplacementValues);
|
||||||
|
|
||||||
|
//XMLString::transcode(attribute->getNodeName(), str, strSize-1);
|
||||||
|
name= attribute->name();
|
||||||
|
}
|
||||||
|
|
||||||
XmlAttribute::XmlAttribute(const string &name, const string &value, std::map<string,string> mapTagReplacementValues) {
|
XmlAttribute::XmlAttribute(const string &name, const string &value, std::map<string,string> mapTagReplacementValues) {
|
||||||
skipRestrictionCheck = false;
|
skipRestrictionCheck = false;
|
||||||
usesCommondata = false;
|
usesCommondata = false;
|
||||||
|
|
Loading…
Reference in New Issue