Hi.
[This is more or less a copy of an email I tried to send to this list
about a month and a half ago. I am now a member of this list, and hope
this one gets through.]
I have been using libxml++ for a while and I find its API pleasant
to work with.
When it comes to preservation of const-ness, there appears to be some
inconsistencies between querying for certain nodes, like pointers to
parents or siblings, and querying for node collections containing
pointers to child or attribute nodes.
Currently the const-qualified member functions used for querying for
children and attributes,
const NodeList Node::get_children(const Glib::ustring &) const
const AttributeList Element::get_attributes() const
return STL containers that are const-qualified, while containing
non-const pointers to the objects (children or attributes). As a
consequence, client code may modify those objects, undermining the
const-qualification of the parent node. On the other hand, client code
is prohibited from modifying siblings or parents, since these pointers
are const-qualified when returned from the respective const member
functions.
The enclosed patch contains a proposed fix for this situation.
In addition, the two "find" member functions of Node have been
overloaded to work with both non-const and const Node objects, returning
std::vector<Node*> (NodeSet) and std::vector<const Node*>
(ConstNodeSet), respectively.
The patch also contains an overloaded definition of
Document::get_root_node(), preserving const from Document to root Element.
I also reorganized the code a bit to get rid of a few const_casts.
Shared code has been extracted into static *_impl functions.
I assume that some of these changes, if approved, would have to go into
a new major release, since these API changes are not backward compatible.
Keep up the good work with libxml++! :-)
--
Sincerely,
Knut Aksel Røysland
|