mirror of
https://github.com/paboyle/Grid.git
synced 2024-11-10 07:55:35 +00:00
More flexible XML control in Lime files
This commit is contained in:
parent
2458a11d1d
commit
6448fe7121
@ -250,8 +250,7 @@ class GridLimeReader : public BinaryIO {
|
||||
////////////////////////////////////////////
|
||||
// Read a generic serialisable object
|
||||
////////////////////////////////////////////
|
||||
template<class serialisable_object>
|
||||
void readLimeObject(serialisable_object &object,std::string object_name,std::string record_name)
|
||||
void readLimeObject(std::string &xmlstring,std::string record_name)
|
||||
{
|
||||
// should this be a do while; can we miss a first record??
|
||||
while ( limeReaderNextRecord(LimeR) == LIME_SUCCESS ) {
|
||||
@ -266,15 +265,23 @@ class GridLimeReader : public BinaryIO {
|
||||
limeReaderReadData((void *)&xmlc[0], &nbytes, LimeR);
|
||||
// std::cout << GridLogMessage<< " readLimeObject matches XML " << &xmlc[0] <<std::endl;
|
||||
|
||||
std::string xmlstring(&xmlc[0]);
|
||||
XmlReader RD(xmlstring, true, "");
|
||||
read(RD,object_name,object);
|
||||
xmlstring = std::string(&xmlc[0]);
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
assert(0);
|
||||
}
|
||||
|
||||
template<class serialisable_object>
|
||||
void readLimeObject(serialisable_object &object,std::string object_name,std::string record_name)
|
||||
{
|
||||
std::string xmlstring;
|
||||
|
||||
readLimeObject(xmlstring, record_name);
|
||||
XmlReader RD(xmlstring, true, "");
|
||||
read(RD,object_name,object);
|
||||
}
|
||||
};
|
||||
|
||||
class GridLimeWriter : public BinaryIO
|
||||
|
@ -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_;
|
||||
|
Loading…
Reference in New Issue
Block a user