mirror of
https://github.com/paboyle/Grid.git
synced 2025-06-18 15:57:05 +01:00
More flexible XML control in Lime files
This commit is contained in:
@ -121,17 +121,26 @@ XmlReader::XmlReader(const std::string &s, const bool isBuffer,
|
||||
}
|
||||
}
|
||||
|
||||
#define XML_SAFE_NODE(expr)\
|
||||
if (expr)\
|
||||
{\
|
||||
node_ = expr;\
|
||||
return true;\
|
||||
}\
|
||||
else\
|
||||
{\
|
||||
return false;\
|
||||
}
|
||||
|
||||
bool XmlReader::push(const std::string &s)
|
||||
{
|
||||
if (node_.child(s.c_str()))
|
||||
if (s.empty())
|
||||
{
|
||||
node_ = node_.child(s.c_str());
|
||||
|
||||
return true;
|
||||
XML_SAFE_NODE(node_.first_child());
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
XML_SAFE_NODE(node_.child(s.c_str()));
|
||||
}
|
||||
}
|
||||
|
||||
@ -142,18 +151,26 @@ void XmlReader::pop(void)
|
||||
|
||||
bool XmlReader::nextElement(const std::string &s)
|
||||
{
|
||||
if (node_.next_sibling(s.c_str()))
|
||||
if (s.empty())
|
||||
{
|
||||
node_ = node_.next_sibling(s.c_str());
|
||||
|
||||
return true;
|
||||
XML_SAFE_NODE(node_.next_sibling());
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
XML_SAFE_NODE(node_.next_sibling(s.c_str()));
|
||||
}
|
||||
}
|
||||
|
||||
void XmlReader::readCurrentSubtree(std::string &s)
|
||||
{
|
||||
std::ostringstream oss;
|
||||
pugi::xml_document doc;
|
||||
|
||||
doc.append_copy(node_);
|
||||
doc.save(oss, indent_.c_str(), pugi::format_default | pugi::format_no_declaration);
|
||||
s = oss.str();
|
||||
}
|
||||
|
||||
template <>
|
||||
void XmlReader::readDefault(const std::string &s, std::string &output)
|
||||
{
|
||||
|
@ -72,16 +72,18 @@ namespace Grid
|
||||
XmlReader(const std::string &fileName, const bool isBuffer = false,
|
||||
std::string toplev = std::string("grid") );
|
||||
virtual ~XmlReader(void) = default;
|
||||
bool push(const std::string &s);
|
||||
bool push(const std::string &s = "");
|
||||
void pop(void);
|
||||
bool nextElement(const std::string &s);
|
||||
bool nextElement(const std::string &s = "");
|
||||
template <typename U>
|
||||
void readDefault(const std::string &s, U &output);
|
||||
template <typename U>
|
||||
void readDefault(const std::string &s, std::vector<U> &output);
|
||||
void readCurrentSubtree(std::string &s);
|
||||
private:
|
||||
void checkParse(const pugi::xml_parse_result &result, const std::string name);
|
||||
private:
|
||||
const std::string indent_{" "};
|
||||
pugi::xml_document doc_;
|
||||
pugi::xml_node node_;
|
||||
std::string fileName_;
|
||||
|
Reference in New Issue
Block a user