aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2013-03-28 10:54:31 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2013-03-28 10:54:31 +0200
commit3a1b35c227d8b51d1bb488db511f82c666a38ea0 (patch)
treee14db1288422dcf744fb714c1c34df425f8d55dc
parent1d3d9dfb7b11da8e398f6f9c638291a0539f7bf0 (diff)
Add direct access to attribute map in XML parserxml
-rw-r--r--cutl/xml/parser.cxx10
-rw-r--r--cutl/xml/parser.hxx32
-rw-r--r--cutl/xml/parser.ixx12
-rw-r--r--cutl/xml/parser.txx2
4 files changed, 38 insertions, 18 deletions
diff --git a/cutl/xml/parser.cxx b/cutl/xml/parser.cxx
index 42ce9ce..219fb00 100644
--- a/cutl/xml/parser.cxx
+++ b/cutl/xml/parser.cxx
@@ -200,7 +200,7 @@ namespace cutl
{
if (const element_entry* e = get_element ())
{
- attribute_map::const_iterator i (e->attr_map_.find (qn));
+ attribute_map_type::const_iterator i (e->attr_map_.find (qn));
if (i != e->attr_map_.end ())
{
@@ -221,7 +221,7 @@ namespace cutl
{
if (const element_entry* e = get_element ())
{
- attribute_map::const_iterator i (e->attr_map_.find (qn));
+ attribute_map_type::const_iterator i (e->attr_map_.find (qn));
if (i != e->attr_map_.end ())
{
@@ -242,7 +242,7 @@ namespace cutl
{
if (const element_entry* e = get_element ())
{
- attribute_map::const_iterator i (e->attr_map_.find (qn));
+ attribute_map_type::const_iterator i (e->attr_map_.find (qn));
if (i != e->attr_map_.end ())
{
@@ -308,7 +308,7 @@ namespace cutl
{
// Find the first unhandled attribute and report it.
//
- for (attribute_map::const_iterator i (e.attr_map_.begin ());
+ for (attribute_map_type::const_iterator i (e.attr_map_.begin ());
i != e.attr_map_.end (); ++i)
{
if (!i->second.handled)
@@ -662,7 +662,7 @@ namespace cutl
{
qname_type qn;
split_name (*atts, qn);
- attribute_map::value_type v (qn, attribute_value ());
+ attribute_map_type::value_type v (qn, attribute_value_type ());
v.second.value = *(atts + 1);
v.second.handled = false;
pe->attr_map_.insert (v);
diff --git a/cutl/xml/parser.hxx b/cutl/xml/parser.hxx
index 7806041..67beaf4 100644
--- a/cutl/xml/parser.hxx
+++ b/cutl/xml/parser.hxx
@@ -255,6 +255,20 @@ namespace cutl
bool
attribute_present (const qname_type& qname) const;
+ // Low-level attribute map access. Note that this API assumes
+ // all attributes are handled.
+ //
+ struct attribute_value_type
+ {
+ std::string value;
+ mutable bool handled;
+ };
+
+ typedef std::map<qname_type, attribute_value_type> attribute_map_type;
+
+ const attribute_map_type&
+ attribute_map () const;
+
// Optional content processing.
//
public:
@@ -363,16 +377,6 @@ namespace cutl
namespace_decls end_ns_;
namespace_decls::size_type end_ns_i_; // Index of the current decl.
- // Attributes as a map.
- //
- struct attribute_value
- {
- std::string value;
- mutable bool handled;
- };
-
- typedef std::map<qname_type, attribute_value> attribute_map;
-
// Element state consisting of the content model and attribute map.
//
struct element_entry
@@ -382,13 +386,17 @@ namespace cutl
std::size_t depth;
content_type content;
- attribute_map attr_map_;
- mutable attribute_map::size_type attr_unhandled_;
+ attribute_map_type attr_map_;
+ mutable attribute_map_type::size_type attr_unhandled_;
};
typedef std::vector<element_entry> element_state;
std::vector<element_entry> element_state_;
+ // Empty attribute map to return when an element has no attributes.
+ //
+ const attribute_map_type empty_attr_map_;
+
// Return the element entry corresponding to the current depth, if
// exists, and NULL otherwise.
//
diff --git a/cutl/xml/parser.ixx b/cutl/xml/parser.ixx
index 2bedae4..65834b6 100644
--- a/cutl/xml/parser.ixx
+++ b/cutl/xml/parser.ixx
@@ -47,6 +47,18 @@ namespace cutl
return attribute_present (qname_type (n));
}
+ inline const parser::attribute_map_type& parser::
+ attribute_map () const
+ {
+ if (const element_entry* e = get_element ())
+ {
+ e->attr_unhandled_ = 0; // Assume all handled.
+ return e->attr_map_;
+ }
+
+ return empty_attr_map_;
+ }
+
inline void parser::
next_expect (event_type e, const qname_type& qn)
{
diff --git a/cutl/xml/parser.txx b/cutl/xml/parser.txx
index e5286f8..8189883 100644
--- a/cutl/xml/parser.txx
+++ b/cutl/xml/parser.txx
@@ -14,7 +14,7 @@ namespace cutl
{
if (const element_entry* e = get_element ())
{
- attribute_map::const_iterator i (e->attr_map_.find (qn));
+ attribute_map_type::const_iterator i (e->attr_map_.find (qn));
if (i != e->attr_map_.end ())
{