X-Git-Url: https://git.ucc.asn.au/?a=blobdiff_plain;f=src%2Ftests%2Fxml.cpp;fp=src%2Ftests%2Fxml.cpp;h=a9335cdd2cbf787e48f876c8e82d45b5ed0a37a3;hb=bf0f1cab25fa460ad4716ca60c11abab78a52cbd;hp=0000000000000000000000000000000000000000;hpb=f4edbd77e3c9a1d8b54a900792674b772b0773e2;p=ipdf%2Fcode.git diff --git a/src/tests/xml.cpp b/src/tests/xml.cpp new file mode 100644 index 0000000..a9335cd --- /dev/null +++ b/src/tests/xml.cpp @@ -0,0 +1,47 @@ +#include "main.h" +#include "../../contrib/pugixml-1.4/src/pugixml.hpp" +#include "../../contrib/pugixml-1.4/src/pugixml.cpp" + +using namespace std; + +/** + * This tester reads XML and uses it to produce rectangles in our viewer + * We use pugixml because I really didn't feel like implementing an XML parser + */ +int main(int argc, char ** argv) +{ + pugi::xml_document doc_xml; + Document doc; + pugi::xml_parse_result result = doc_xml.load(cin); // load from stdin + + if (!result) + { + Fatal("XML from stdin has errors: %s", result.description()); + } + + Debug("pugixml load result was: %s", result.description()); + int count = 0; + for (pugi::xml_node rect : doc_xml.children("rect")) + { + + Real coords[4]; + const char * attrib_names[] = {"x", "y", "w", "h"}; + for (size_t i = 0; i < sizeof(attrib_names)/sizeof(char*); ++i) + { + coords[i] = rect.attribute(attrib_names[i]).as_float(); + } + + bool outline = false; + outline = rect.attribute("outline").as_bool(); + + Debug("rect node %d is {%lf, %lf, %lf, %lf} (%s)", count++, coords[0], coords[1], coords[2], coords[3], (outline) ? "outline" : "filled"); + doc.Add(outline?RECT_OUTLINE:RECT_FILLED, Rect(coords[0], coords[1], coords[2], coords[3])); + } + + + MainLoop(doc); + + + + return 0; +}