From 818bedc799073966a4c56fd83ab1df358b9e9c24 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Tue, 29 Apr 2014 11:04:19 +0200 Subject: Add value version, analogous to attribute --- tests/parser/driver.cxx | 11 +++++++++++ xml/parser.hxx | 1 + xml/parser.ixx | 7 +++++++ 3 files changed, 19 insertions(+) diff --git a/tests/parser/driver.cxx b/tests/parser/driver.cxx index b882188..c5d18f0 100644 --- a/tests/parser/driver.cxx +++ b/tests/parser/driver.cxx @@ -84,6 +84,17 @@ main () // cerr << e.what () << endl; } + // Test value extraction. + // + { + istringstream is ("123"); + parser p (is, "test"); + p.next_expect (parser::start_element, "root"); + p.next_expect (parser::characters); + assert (p.value () == 123); + p.next_expect (parser::end_element); + } + // Test attribute maps. // { diff --git a/xml/parser.hxx b/xml/parser.hxx index f3a2e34..b9b5d4c 100644 --- a/xml/parser.hxx +++ b/xml/parser.hxx @@ -208,6 +208,7 @@ namespace xml const std::string& prefix () const {return pqname_->prefix ();} const std::string& value () const {return *pvalue_;} + template T value () const; unsigned long long line () const {return line_;} unsigned long long column () const {return column_;} diff --git a/xml/parser.ixx b/xml/parser.ixx index adb8751..ac27b46 100644 --- a/xml/parser.ixx +++ b/xml/parser.ixx @@ -6,6 +6,13 @@ namespace xml { + template + inline T parser:: + value () const + { + return value_traits::parse (value (), *this); + } + inline const std::string& parser:: attribute (const std::string& n) const { -- cgit v1.1