1
0
mirror of https://github.com/paboyle/Grid.git synced 2024-11-10 07:55:35 +00:00
Grid/lib/serialisation/XmlIO.cc

59 lines
1.2 KiB
C++
Raw Normal View History

2015-11-16 18:14:37 +00:00
#include <Grid.h>
2015-11-29 11:14:44 +00:00
namespace Grid {
2015-11-16 18:14:37 +00:00
// Writer implementation ///////////////////////////////////////////////////////
2015-11-29 11:14:44 +00:00
XmlWriter::XmlWriter(const std::string &fileName)
2015-11-16 18:14:37 +00:00
: fileName_(fileName)
{
node_ = doc_.append_child();
node_.set_name("grid");
}
XmlWriter::~XmlWriter(void)
{
doc_.save_file(fileName_.c_str(), " ");
}
2015-11-29 11:14:44 +00:00
void XmlWriter::push(const std::string &s)
2015-11-16 18:14:37 +00:00
{
node_ = node_.append_child(s.c_str());
}
void XmlWriter::pop(void)
{
node_ = node_.parent();
}
// Reader implementation ///////////////////////////////////////////////////////
2015-11-29 11:14:44 +00:00
XmlReader::XmlReader(const std::string &fileName)
2015-11-16 18:14:37 +00:00
: fileName_(fileName)
{
pugi::xml_parse_result result = doc_.load_file(fileName_.c_str());
if ( !result )
{
2015-11-29 11:14:44 +00:00
std::cerr << "XML error description: " << result.description() << "\n";
std::cerr << "XML error offset : " << result.offset << "\n";
std::abort();
2015-11-16 18:14:37 +00:00
}
node_ = doc_.child("grid");
}
2015-11-29 11:14:44 +00:00
void XmlReader::push(const std::string &s)
2015-11-16 18:14:37 +00:00
{
node_ = node_.child(s.c_str());
}
void XmlReader::pop(void)
{
node_ = node_.parent();
}
template <>
2015-11-29 11:14:44 +00:00
void XmlReader::readDefault(const std::string &s, std::string &output)
2015-11-16 18:14:37 +00:00
{
output = node_.child(s.c_str()).first_child().value();
}
2015-11-29 11:14:44 +00:00
}