2014-05-02 06:30:32 +00:00
|
|
|
#include "stdafx.h"
|
2014-07-11 11:59:13 +00:00
|
|
|
#include "Utilities/rXml.h"
|
2014-05-02 06:30:32 +00:00
|
|
|
|
|
|
|
rXmlNode::rXmlNode()
|
|
|
|
{
|
|
|
|
ownPtr = true;
|
2016-04-02 20:28:53 +00:00
|
|
|
handle = new pugi::xml_node;
|
2014-05-02 06:30:32 +00:00
|
|
|
}
|
|
|
|
|
2016-04-02 20:28:53 +00:00
|
|
|
rXmlNode::rXmlNode(pugi::xml_node *ptr)
|
2014-05-02 06:30:32 +00:00
|
|
|
{
|
|
|
|
ownPtr = false;
|
|
|
|
handle = ptr;
|
|
|
|
}
|
|
|
|
|
2016-04-02 20:28:53 +00:00
|
|
|
rXmlNode::~rXmlNode()
|
|
|
|
{
|
|
|
|
if (ownPtr)
|
|
|
|
{
|
|
|
|
delete handle;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-02 06:30:32 +00:00
|
|
|
rXmlNode::rXmlNode(const rXmlNode& other)
|
|
|
|
{
|
|
|
|
ownPtr = true;
|
2016-04-02 20:28:53 +00:00
|
|
|
handle = new pugi::xml_node(*other.handle);
|
2014-05-02 06:30:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
rXmlNode &rXmlNode::operator=(const rXmlNode& other)
|
|
|
|
{
|
|
|
|
if (ownPtr)
|
|
|
|
{
|
2016-04-02 20:28:53 +00:00
|
|
|
delete handle;
|
2014-05-02 06:30:32 +00:00
|
|
|
}
|
2016-04-02 20:28:53 +00:00
|
|
|
handle = new pugi::xml_node(*other.handle);
|
2014-05-02 06:30:32 +00:00
|
|
|
ownPtr = true;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::shared_ptr<rXmlNode> rXmlNode::GetChildren()
|
|
|
|
{
|
2016-04-02 20:28:53 +00:00
|
|
|
// it.begin() returns node_iterator*, *it.begin() return node*.
|
|
|
|
pugi::xml_object_range<pugi::xml_node_iterator> it = handle->children();
|
|
|
|
pugi::xml_node begin = *it.begin();
|
|
|
|
|
|
|
|
if (begin)
|
2014-06-08 11:43:13 +00:00
|
|
|
{
|
2016-04-02 20:28:53 +00:00
|
|
|
return std::make_shared<rXmlNode>(&begin);
|
2014-06-08 11:43:13 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-04-02 20:28:53 +00:00
|
|
|
return nullptr;
|
2014-06-08 11:43:13 +00:00
|
|
|
}
|
2014-05-02 06:30:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
std::shared_ptr<rXmlNode> rXmlNode::GetNext()
|
|
|
|
{
|
2016-04-02 20:28:53 +00:00
|
|
|
pugi::xml_node result = handle->next_sibling();
|
2014-06-08 11:43:13 +00:00
|
|
|
if (result)
|
|
|
|
{
|
2016-04-02 20:28:53 +00:00
|
|
|
return std::make_shared<rXmlNode>(&result);
|
2014-06-08 11:43:13 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-04-02 20:28:53 +00:00
|
|
|
return nullptr;
|
2014-06-08 11:43:13 +00:00
|
|
|
}
|
2014-05-02 06:30:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
std::string rXmlNode::GetName()
|
|
|
|
{
|
2016-04-02 20:28:53 +00:00
|
|
|
return handle->name();
|
2014-05-02 06:30:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
std::string rXmlNode::GetAttribute(const std::string &name)
|
|
|
|
{
|
2016-04-02 20:28:53 +00:00
|
|
|
auto pred = [&name](pugi::xml_attribute attr) { return (name == attr.name()); };
|
|
|
|
return handle->find_attribute(pred).value();
|
2014-05-02 06:30:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
std::string rXmlNode::GetNodeContent()
|
|
|
|
{
|
2016-04-02 20:28:53 +00:00
|
|
|
return handle->text().get();
|
2014-05-02 06:30:32 +00:00
|
|
|
}
|
|
|
|
|
2016-04-02 20:28:53 +00:00
|
|
|
void *rXmlNode::AsVoidPtr()
|
2014-05-02 06:30:32 +00:00
|
|
|
{
|
2016-04-02 20:28:53 +00:00
|
|
|
return static_cast<void*>(handle);
|
2014-05-02 06:30:32 +00:00
|
|
|
}
|
|
|
|
|
2016-04-02 20:28:53 +00:00
|
|
|
rXmlDocument::rXmlDocument()
|
2014-05-02 06:30:32 +00:00
|
|
|
{
|
2016-04-02 20:28:53 +00:00
|
|
|
handle = new pugi::xml_document;
|
2014-05-02 06:30:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
rXmlDocument::~rXmlDocument()
|
|
|
|
{
|
2016-04-02 20:28:53 +00:00
|
|
|
delete handle;
|
2014-05-02 06:30:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void rXmlDocument::Load(const std::string & path)
|
|
|
|
{
|
2016-04-02 20:28:53 +00:00
|
|
|
// TODO: Unsure of use of c_str.
|
|
|
|
handle->load_string(path.c_str());
|
2014-05-02 06:30:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
std::shared_ptr<rXmlNode> rXmlDocument::GetRoot()
|
|
|
|
{
|
2016-04-02 20:28:53 +00:00
|
|
|
pugi::xml_node root = handle->root();
|
|
|
|
return std::make_shared<rXmlNode>(&root);
|
|
|
|
}
|
|
|
|
|
|
|
|
void *rXmlDocument::AsVoidPtr()
|
|
|
|
{
|
|
|
|
return static_cast<void*>(handle);
|
2014-05-02 06:30:32 +00:00
|
|
|
}
|