mirror of
https://github.com/paboyle/Grid.git
synced 2025-04-09 21:50:45 +01: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
|
// Read a generic serialisable object
|
||||||
////////////////////////////////////////////
|
////////////////////////////////////////////
|
||||||
template<class serialisable_object>
|
void readLimeObject(std::string &xmlstring,std::string record_name)
|
||||||
void readLimeObject(serialisable_object &object,std::string object_name,std::string record_name)
|
|
||||||
{
|
{
|
||||||
// should this be a do while; can we miss a first record??
|
// should this be a do while; can we miss a first record??
|
||||||
while ( limeReaderNextRecord(LimeR) == LIME_SUCCESS ) {
|
while ( limeReaderNextRecord(LimeR) == LIME_SUCCESS ) {
|
||||||
@ -266,15 +265,23 @@ class GridLimeReader : public BinaryIO {
|
|||||||
limeReaderReadData((void *)&xmlc[0], &nbytes, LimeR);
|
limeReaderReadData((void *)&xmlc[0], &nbytes, LimeR);
|
||||||
// std::cout << GridLogMessage<< " readLimeObject matches XML " << &xmlc[0] <<std::endl;
|
// std::cout << GridLogMessage<< " readLimeObject matches XML " << &xmlc[0] <<std::endl;
|
||||||
|
|
||||||
std::string xmlstring(&xmlc[0]);
|
xmlstring = std::string(&xmlc[0]);
|
||||||
XmlReader RD(xmlstring, true, "");
|
|
||||||
read(RD,object_name,object);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
assert(0);
|
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
|
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)
|
bool XmlReader::push(const std::string &s)
|
||||||
{
|
{
|
||||||
if (node_.child(s.c_str()))
|
if (s.empty())
|
||||||
{
|
{
|
||||||
node_ = node_.child(s.c_str());
|
XML_SAFE_NODE(node_.first_child());
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
else
|
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)
|
bool XmlReader::nextElement(const std::string &s)
|
||||||
{
|
{
|
||||||
if (node_.next_sibling(s.c_str()))
|
if (s.empty())
|
||||||
{
|
{
|
||||||
node_ = node_.next_sibling(s.c_str());
|
XML_SAFE_NODE(node_.next_sibling());
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
else
|
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 <>
|
template <>
|
||||||
void XmlReader::readDefault(const std::string &s, std::string &output)
|
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,
|
XmlReader(const std::string &fileName, const bool isBuffer = false,
|
||||||
std::string toplev = std::string("grid") );
|
std::string toplev = std::string("grid") );
|
||||||
virtual ~XmlReader(void) = default;
|
virtual ~XmlReader(void) = default;
|
||||||
bool push(const std::string &s);
|
bool push(const std::string &s = "");
|
||||||
void pop(void);
|
void pop(void);
|
||||||
bool nextElement(const std::string &s);
|
bool nextElement(const std::string &s = "");
|
||||||
template <typename U>
|
template <typename U>
|
||||||
void readDefault(const std::string &s, U &output);
|
void readDefault(const std::string &s, U &output);
|
||||||
template <typename U>
|
template <typename U>
|
||||||
void readDefault(const std::string &s, std::vector<U> &output);
|
void readDefault(const std::string &s, std::vector<U> &output);
|
||||||
|
void readCurrentSubtree(std::string &s);
|
||||||
private:
|
private:
|
||||||
void checkParse(const pugi::xml_parse_result &result, const std::string name);
|
void checkParse(const pugi::xml_parse_result &result, const std::string name);
|
||||||
private:
|
private:
|
||||||
|
const std::string indent_{" "};
|
||||||
pugi::xml_document doc_;
|
pugi::xml_document doc_;
|
||||||
pugi::xml_node node_;
|
pugi::xml_node node_;
|
||||||
std::string fileName_;
|
std::string fileName_;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user