2014-05-02 06:30:32 +00:00
|
|
|
#include "stdafx.h"
|
2017-01-28 12:32:45 +00:00
|
|
|
#include "restore_new.h"
|
2014-07-11 11:59:13 +00:00
|
|
|
#include "Utilities/rXml.h"
|
2017-01-28 12:32:45 +00:00
|
|
|
#include "define_new_memleakdetect.h"
|
2014-05-02 06:30:32 +00:00
|
|
|
|
2016-04-16 21:21:22 +00:00
|
|
|
rXmlNode::rXmlNode() : handle()
|
2014-05-02 06:30:32 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2016-04-16 21:21:22 +00:00
|
|
|
rXmlNode::rXmlNode(const pugi::xml_node &node)
|
2014-05-02 06:30:32 +00:00
|
|
|
{
|
2016-04-16 21:21:22 +00:00
|
|
|
handle = node;
|
2014-05-02 06:30:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
std::shared_ptr<rXmlNode> rXmlNode::GetChildren()
|
|
|
|
{
|
2016-04-02 20:28:53 +00:00
|
|
|
// it.begin() returns node_iterator*, *it.begin() return node*.
|
2016-04-16 21:21:22 +00:00
|
|
|
pugi::xml_object_range<pugi::xml_node_iterator> it = handle.children();
|
2016-04-02 20:28:53 +00:00
|
|
|
pugi::xml_node begin = *it.begin();
|
|
|
|
|
|
|
|
if (begin)
|
2014-06-08 11:43:13 +00:00
|
|
|
{
|
2016-04-16 21:21:22 +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-16 21:21:22 +00:00
|
|
|
pugi::xml_node result = handle.next_sibling();
|
2014-06-08 11:43:13 +00:00
|
|
|
if (result)
|
|
|
|
{
|
2016-04-16 21:21:22 +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-16 21:21:22 +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()); };
|
2016-04-16 21:21:22 +00:00
|
|
|
return handle.find_attribute(pred).value();
|
2014-05-02 06:30:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
std::string rXmlNode::GetNodeContent()
|
|
|
|
{
|
2016-04-16 21:21:22 +00:00
|
|
|
return handle.text().get();
|
2014-05-02 06:30:32 +00:00
|
|
|
}
|
|
|
|
|
2016-04-16 21:21:22 +00:00
|
|
|
rXmlDocument::rXmlDocument() : 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.
|
2016-04-16 21:21:22 +00:00
|
|
|
handle.load_file(path.c_str());
|
2014-05-02 06:30:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
std::shared_ptr<rXmlNode> rXmlDocument::GetRoot()
|
|
|
|
{
|
2016-04-16 21:21:22 +00:00
|
|
|
return std::make_shared<rXmlNode>(handle.root());
|
2016-04-02 20:28:53 +00:00
|
|
|
}
|
|
|
|
|