[libxml++] Parser: Add input operator>>()



commit 2bd4773ca3e89fe83b0cbc8c3b476b682735028f
Author: Kjell Ahlstedt <kjell ahlstedt bredband net>
Date:   Tue Oct 21 16:21:44 2014 +0200

    Parser: Add input operator>>()
    
    * libxml++/parsers/parser.h: Add operator>>(std::istream& in, Parser& parser).
    * examples/dom_parse_entities/main.cc: Use operator>>(). Bug #329281.

 examples/dom_parse_entities/main.cc |   16 ++++++++++++----
 libxml++/parsers/parser.h           |   10 ++++++++++
 2 files changed, 22 insertions(+), 4 deletions(-)
---
diff --git a/examples/dom_parse_entities/main.cc b/examples/dom_parse_entities/main.cc
index bf97994..e476ac4 100644
--- a/examples/dom_parse_entities/main.cc
+++ b/examples/dom_parse_entities/main.cc
@@ -1,5 +1,3 @@
-// -*- C++ -*-
-
 /* main.cc
  *
  * Copyright (C) 2002 The libxml++ development team
@@ -26,6 +24,7 @@
 #include "../testutilities.h"
 #include <libxml++/libxml++.h>
 #include <iostream>
+#include <fstream>
 #include <cstdlib>
 
 void print_node(const xmlpp::Node* node, bool substitute_entities, unsigned int indentation = 0)
@@ -93,7 +92,17 @@ int main(int argc, char* argv[])
       xmlpp::DomParser parser;
       parser.set_validate();
       parser.set_substitute_entities(substitute_entities);
-      parser.parse_file(filepath);
+
+      // Two ways of reading the XML file.
+      if (substitute_entities)
+        parser.parse_file(filepath);
+      else
+      {
+        std::ifstream instream(filepath.c_str());
+        if (!instream)
+          throw xmlpp::internal_error("Could not open file " + filepath);
+        instream >> parser;
+      }
       if(parser)
       {
         //Walk the tree:
@@ -114,4 +123,3 @@ int main(int argc, char* argv[])
 
   return return_code;
 }
-
diff --git a/libxml++/parsers/parser.h b/libxml++/parsers/parser.h
index 66297de..4706df9 100644
--- a/libxml++/parsers/parser.h
+++ b/libxml++/parsers/parser.h
@@ -199,6 +199,16 @@ protected:
   //int clear_options_;
 };
 
+/** Equivalent to Parser::parse_stream().
+ *
+ * @newin{2,38}
+ */
+inline std::istream& operator>>(std::istream& in, Parser& parser)
+{
+  parser.parse_stream(in);
+  return in;
+}
+
 } // namespace xmlpp
 
 #endif //__LIBXMLPP_PARSER_H


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]