[libxml++] Element::get_attribute(): Propagate const qualifier to Attribute



commit c21bc5df99560b6f3029e51b54e176b7aa5a3fc5
Author: Knut Aksel Røysland <knutroy ifi uio no>
Date:   Thu Sep 17 13:34:11 2015 +0200

    Element::get_attribute(): Propagate const qualifier to Attribute
    
    * libxml++/nodes/element.[h|cc]: Let the const version of get_attribute()
    return a const Attribute*. Add a non-const version. Bug #632524.

 libxml++/nodes/element.cc |    8 +++++++-
 libxml++/nodes/element.h  |   15 ++++++++++++---
 2 files changed, 19 insertions(+), 4 deletions(-)
---
diff --git a/libxml++/nodes/element.cc b/libxml++/nodes/element.cc
index 63e47d1..ea97f6b 100644
--- a/libxml++/nodes/element.cc
+++ b/libxml++/nodes/element.cc
@@ -43,7 +43,7 @@ Element::const_AttributeList Element::get_attributes() const
 }
 
 Attribute* Element::get_attribute(const Glib::ustring& name,
-                                  const Glib::ustring& ns_prefix) const
+                                  const Glib::ustring& ns_prefix)
 {
   // An empty ns_prefix means "use no namespace".
   // The default namespace never applies to an attribute.
@@ -70,6 +70,12 @@ Attribute* Element::get_attribute(const Glib::ustring& name,
   return 0;
 }
 
+const Attribute* Element::get_attribute(const Glib::ustring& name,
+                                        const Glib::ustring& ns_prefix) const
+{
+  return const_cast<Element*>(this)->get_attribute(name, ns_prefix);
+}
+
 Glib::ustring Element::get_attribute_value(const Glib::ustring& name, const Glib::ustring& ns_prefix) const
 {
   const auto attr = get_attribute(name, ns_prefix);
diff --git a/libxml++/nodes/element.h b/libxml++/nodes/element.h
index fe23aee..5bb1aa3 100644
--- a/libxml++/nodes/element.h
+++ b/libxml++/nodes/element.h
@@ -56,8 +56,6 @@ public:
    */
   const_AttributeList get_attributes() const;
 
-  //TODO: There should be a const and non-const version.
-  //See the patch at https://bugzilla.gnome.org/show_bug.cgi?id=632524
   /** Get the attribute with this name, and optionally with this namespace.
    * @param name The name of the attribute that will be retrieved.
    * @param ns_prefix Namespace prefix.
@@ -67,7 +65,18 @@ public:
    *         of an attribute with a default value.
    */
   Attribute* get_attribute(const Glib::ustring& name,
-                           const Glib::ustring& ns_prefix = Glib::ustring()) const;
+                           const Glib::ustring& ns_prefix = Glib::ustring());
+
+  /** Get the attribute with this name, and optionally with this namespace.
+   * @param name The name of the attribute that will be retrieved.
+   * @param ns_prefix Namespace prefix.
+   * @return The attribute, or 0 if no suitable Attribute was found.
+   *         Is either an AttributeNode*, pointing to an explicitly set
+   *         attribute, or an AttributeDeclaration*, pointing to the declaration
+   *         of an attribute with a default value.
+   */
+  const Attribute* get_attribute(const Glib::ustring& name,
+                                 const Glib::ustring& ns_prefix = Glib::ustring()) const;
 
   /** Get the value of the attribute with this name, and optionally with this namespace.
    * For finer control, you might use get_attribute() and use the methods of the Attribute class.


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