1
0
mirror of https://github.com/RPCS3/rpcs3.git synced 2024-11-22 02:32:36 +01:00

rXml: fix broken things (#1669)

Not sure if it works completely now but at least it doesn't crash in
Metal Slug 3 now.
This commit is contained in:
Danila Malyutin 2016-04-17 00:21:22 +03:00 committed by Ivan
parent fe1e7a1bdb
commit 85d0fff233
2 changed files with 17 additions and 68 deletions

View File

@ -1,52 +1,24 @@
#include "stdafx.h" #include "stdafx.h"
#include "Utilities/rXml.h" #include "Utilities/rXml.h"
rXmlNode::rXmlNode() rXmlNode::rXmlNode() : handle()
{ {
ownPtr = true;
handle = new pugi::xml_node;
} }
rXmlNode::rXmlNode(pugi::xml_node *ptr) rXmlNode::rXmlNode(const pugi::xml_node &node)
{ {
ownPtr = false; handle = node;
handle = ptr;
}
rXmlNode::~rXmlNode()
{
if (ownPtr)
{
delete handle;
}
}
rXmlNode::rXmlNode(const rXmlNode& other)
{
ownPtr = true;
handle = new pugi::xml_node(*other.handle);
}
rXmlNode &rXmlNode::operator=(const rXmlNode& other)
{
if (ownPtr)
{
delete handle;
}
handle = new pugi::xml_node(*other.handle);
ownPtr = true;
return *this;
} }
std::shared_ptr<rXmlNode> rXmlNode::GetChildren() std::shared_ptr<rXmlNode> rXmlNode::GetChildren()
{ {
// it.begin() returns node_iterator*, *it.begin() return node*. // it.begin() returns node_iterator*, *it.begin() return node*.
pugi::xml_object_range<pugi::xml_node_iterator> it = handle->children(); pugi::xml_object_range<pugi::xml_node_iterator> it = handle.children();
pugi::xml_node begin = *it.begin(); pugi::xml_node begin = *it.begin();
if (begin) if (begin)
{ {
return std::make_shared<rXmlNode>(&begin); return std::make_shared<rXmlNode>(begin);
} }
else else
{ {
@ -56,10 +28,10 @@ std::shared_ptr<rXmlNode> rXmlNode::GetChildren()
std::shared_ptr<rXmlNode> rXmlNode::GetNext() std::shared_ptr<rXmlNode> rXmlNode::GetNext()
{ {
pugi::xml_node result = handle->next_sibling(); pugi::xml_node result = handle.next_sibling();
if (result) if (result)
{ {
return std::make_shared<rXmlNode>(&result); return std::make_shared<rXmlNode>(result);
} }
else else
{ {
@ -69,48 +41,32 @@ std::shared_ptr<rXmlNode> rXmlNode::GetNext()
std::string rXmlNode::GetName() std::string rXmlNode::GetName()
{ {
return handle->name(); return handle.name();
} }
std::string rXmlNode::GetAttribute(const std::string &name) std::string rXmlNode::GetAttribute(const std::string &name)
{ {
auto pred = [&name](pugi::xml_attribute attr) { return (name == attr.name()); }; auto pred = [&name](pugi::xml_attribute attr) { return (name == attr.name()); };
return handle->find_attribute(pred).value(); return handle.find_attribute(pred).value();
} }
std::string rXmlNode::GetNodeContent() std::string rXmlNode::GetNodeContent()
{ {
return handle->text().get(); return handle.text().get();
} }
void *rXmlNode::AsVoidPtr() rXmlDocument::rXmlDocument() : handle()
{ {
return static_cast<void*>(handle);
}
rXmlDocument::rXmlDocument()
{
handle = new pugi::xml_document;
}
rXmlDocument::~rXmlDocument()
{
delete handle;
} }
void rXmlDocument::Load(const std::string & path) void rXmlDocument::Load(const std::string & path)
{ {
// TODO: Unsure of use of c_str. // TODO: Unsure of use of c_str.
handle->load_string(path.c_str()); handle.load_file(path.c_str());
} }
std::shared_ptr<rXmlNode> rXmlDocument::GetRoot() std::shared_ptr<rXmlNode> rXmlDocument::GetRoot()
{ {
pugi::xml_node root = handle->root(); return std::make_shared<rXmlNode>(handle.root());
return std::make_shared<rXmlNode>(&root);
} }
void *rXmlDocument::AsVoidPtr()
{
return static_cast<void*>(handle);
}

View File

@ -9,19 +9,14 @@
struct rXmlNode struct rXmlNode
{ {
rXmlNode(); rXmlNode();
rXmlNode(pugi::xml_node *); rXmlNode(const pugi::xml_node &);
rXmlNode(const rXmlNode& other);
rXmlNode &operator=(const rXmlNode& other);
~rXmlNode();
std::shared_ptr<rXmlNode> GetChildren(); std::shared_ptr<rXmlNode> GetChildren();
std::shared_ptr<rXmlNode> GetNext(); std::shared_ptr<rXmlNode> GetNext();
std::string GetName(); std::string GetName();
std::string GetAttribute( const std::string &name); std::string GetAttribute( const std::string &name);
std::string GetNodeContent(); std::string GetNodeContent();
void *AsVoidPtr();
pugi::xml_node *handle; pugi::xml_node handle;
bool ownPtr;
}; };
struct rXmlDocument struct rXmlDocument
@ -29,10 +24,8 @@ struct rXmlDocument
rXmlDocument(); rXmlDocument();
rXmlDocument(const rXmlDocument& other) = delete; rXmlDocument(const rXmlDocument& other) = delete;
rXmlDocument &operator=(const rXmlDocument& other) = delete; rXmlDocument &operator=(const rXmlDocument& other) = delete;
~rXmlDocument();
void Load(const std::string & path); void Load(const std::string & path);
std::shared_ptr<rXmlNode> GetRoot(); std::shared_ptr<rXmlNode> GetRoot();
void *AsVoidPtr();
pugi::xml_document *handle; pugi::xml_document handle;
}; };