Index: boost/xml/dom/attribute.hpp =================================================================== --- boost/xml/dom/attribute.hpp (revision 7403) +++ boost/xml/dom/attribute.hpp (working copy) @@ -15,7 +15,7 @@ template class attribute : public node { - friend node_ptr > detail::ptr_factory >(xmlNode *); + friend node_ptr > ptr_factory >(xmlNode *); friend class element; public: S name() const { return converter::out(this->impl()->name);} Index: boost/xml/dom/detail.hpp =================================================================== --- boost/xml/dom/detail.hpp (revision 7403) +++ boost/xml/dom/detail.hpp (working copy) @@ -22,6 +22,15 @@ COMMENT, }; +template +node_ptr ptr_factory(xmlNode *n) { return N(n);} + +template +std::auto_ptr > factory(xmlDoc *d) +{ + return std::auto_ptr >(new document(d));} + + namespace detail { @@ -51,7 +60,7 @@ template class wrapper; -//. +//. class accessor { protected: @@ -70,6 +79,7 @@ friend class accessor; public: wrapper(T t) : impl_(t) {} + operator bool() const { return 0 != this->impl();} protected: using accessor::impl; @@ -80,17 +90,11 @@ }; template -node_ptr ptr_factory(xmlNode *n) { return N(n);} - -template -std::auto_ptr > factory(xmlDoc *d) -{ - return std::auto_ptr >(new document(d));} - -template class node_iterator : public wrapper { public: + typedef std::bidirectional_iterator_tag iterator_category; + typedef size_t difference_type; typedef node_iterator self; typedef node_ptr value_type; typedef value_type &reference; @@ -99,7 +103,7 @@ node_iterator(xmlNode *current = 0) : detail::wrapper(current) {} bool operator == (self i) { return impl() == impl(i);} bool operator != (self i) { return !operator==(i);} - value_type operator *() { return detail::ptr_factory(impl());} + value_type operator *() { return ptr_factory(impl());} pointer operator ->() { return &(operator *());} self operator ++(int) { increment(); return *this;} self operator ++() { self tmp = *this; increment(); return tmp;} Index: boost/xml/dom/document.hpp =================================================================== --- boost/xml/dom/document.hpp (revision 7403) +++ boost/xml/dom/document.hpp (working copy) @@ -20,7 +20,7 @@ template class document : public detail::wrapper { - friend std::auto_ptr > detail::factory<>(xmlDoc *); + friend std::auto_ptr > factory<>(xmlDoc *); friend void process_xinclude<>(document &); public: document(std::string const &version = "1.0") @@ -29,18 +29,17 @@ std::string encoding() const; dtd_ptr internal_subset() const; dtd_ptr create_internal_subset(std::string const &name, - std::string const &external_id, - std::string const &system_id); + std::string const &external_id, + std::string const &system_id); node_ptr const> root() const; node_ptr > root(); node_ptr > create_root(std::string const &name, - std::string const &ns = std::string(), - std::string const &ns_prefix = std::string()); + std::string const &ns = std::string(), + std::string const &ns_prefix = std::string()); void write_to_file(const std::string &filename, - const std::string &encoding = std::string()) - throw(std::runtime_error); + const std::string &encoding = std::string()); private: document(xmlDoc *doc) : detail::wrapper(doc) {} }; @@ -63,13 +62,13 @@ template inline dtd_ptr document::create_internal_subset(std::string const &name, - std::string const &external_id, - std::string const &system_id) + std::string const &external_id, + std::string const &system_id) { xmlDtd *d = xmlCreateIntSubset(this->impl(), - reinterpret_cast(name.c_str()), - reinterpret_cast(external_id.c_str()), - reinterpret_cast(system_id.c_str())); + reinterpret_cast(name.c_str()), + reinterpret_cast(external_id.c_str()), + reinterpret_cast(system_id.c_str())); return dtd(d); } @@ -78,7 +77,7 @@ { xmlNode *root = xmlDocGetRootElement(this->impl()); assert(root); - return detail::ptr_factory const>(root); + return ptr_factory const>(root); } template @@ -90,16 +89,16 @@ } template -inline node_ptr > +inline node_ptr > document::create_root(std::string const &name, - std::string const &ns_href, - std::string const &ns_prefix) + std::string const &ns_href, + std::string const &ns_prefix) { xmlNode *node = xmlNewDocNode(this->impl(), 0, (xmlChar *)name.c_str(), 0); if(!ns_prefix.empty()) xmlNewNs(node, - (xmlChar *)(ns_href.empty() ? 0 : ns_href.c_str()), - (xmlChar *) ns_prefix.c_str()); + (xmlChar *)(ns_href.empty() ? 0 : ns_href.c_str()), + (xmlChar *) ns_prefix.c_str()); xmlDocSetRootElement(this->impl(), node); @@ -108,13 +107,12 @@ template inline void document::write_to_file(const std::string &filename, - const std::string &encoding) - throw(std::runtime_error) + const std::string &encoding) { int result = 0; if(!encoding.empty()) result = xmlSaveFormatFileEnc(filename.c_str(), - this->impl(), encoding.c_str(), 1); + this->impl(), encoding.c_str(), 1); else result = xmlSaveFormatFile(filename.c_str(), this->impl(), 1); Index: boost/xml/dom/element.hpp =================================================================== --- boost/xml/dom/element.hpp (revision 7403) +++ boost/xml/dom/element.hpp (working copy) @@ -7,6 +7,7 @@ #include #include #include +#include namespace boost { @@ -19,7 +20,8 @@ class element : public node { friend class document; - friend node_ptr > detail::ptr_factory<>(xmlNode *); + friend class node_ptr >; + friend node_ptr > ptr_factory<>(xmlNode *); public: typedef detail::node_iterator > child_iterator; typedef detail::node_iterator const> const_child_iterator; @@ -36,21 +38,21 @@ //. Remove the attribute with the given name and value, if it exists. void unset_attribute(S const &name); - attribute_iterator begin_attributes() + attribute_iterator begin_attributes() { xmlAttr *attr = this->impl()->properties; return attribute_iterator(reinterpret_cast(attr)); } - const_attribute_iterator begin_attributes() const + const_attribute_iterator begin_attributes() const { xmlAttr *attr = this->impl()->properties; return const_attribute_iterator(reinterpret_cast(attr)); } - attribute_iterator end_attributes() + attribute_iterator end_attributes() { return attribute_iterator(); } - const_attribute_iterator end_attributes() const + const_attribute_iterator end_attributes() const { return const_attribute_iterator(); } @@ -89,13 +91,13 @@ void set_content(S const &content); void append_content(S const &content); - child_iterator begin_children() + child_iterator begin_children() { return child_iterator(this->impl()->children);} - const_child_iterator begin_children() const + const_child_iterator begin_children() const { return const_child_iterator(this->impl()->children);} - child_iterator end_children() + child_iterator end_children() { return child_iterator();} - const_child_iterator end_children() const + const_child_iterator end_children() const { return const_child_iterator();} //. Declare the namespace prefix to be an alias for uri. @@ -136,13 +138,13 @@ } template -inline node_ptr > +inline node_ptr > element::set_attribute(S const &name, S const &value) { xmlAttr *attr = xmlSetProp(this->impl(), converter::in(name), converter::in(value)); - return dom::attribute(attr); + return dom::attribute((xmlNode *)attr); } template @@ -152,7 +154,7 @@ } template -inline node_ptr > +inline node_ptr > element::append_element(S const &name) { xmlNode *node = xmlAddChild(this->impl(), xmlNewNode(0, converter::in(name))); @@ -160,7 +162,7 @@ } template -inline node_ptr > +inline node_ptr > element::insert_element(child_iterator i, S const &name) { xmlNode *node = xmlNewNode(0, converter::in(name)); @@ -172,7 +174,7 @@ } template -inline node_ptr > +inline node_ptr > element::append_text(S const &name) { xmlNode *node = xmlAddChild(this->impl(), xmlNewText(converter::in(name))); @@ -180,7 +182,7 @@ } template -inline node_ptr > +inline node_ptr > element::insert_text(child_iterator i, S const &name) { xmlNode *node = xmlNewText(converter::in(name)); @@ -196,7 +198,7 @@ element::append_comment(S const &content) { xmlNode *node = xmlAddChild(this->impl(), - xmlNewComment(converter::in(content))); + xmlNewComment(converter::in(content))); return comment(node); } @@ -217,15 +219,15 @@ element::append_pi(S const &name, S const &content) { xmlNode *node = xmlAddChild(this->impl(), xmlNewPI(converter::in(name), - converter::in(content))); + converter::in(content))); return pi(node); } template inline node_ptr > element::insert_pi(child_iterator i, - S const &name, - S const &content) + S const &name, + S const &content) { xmlNode *node = xmlNewPI(converter::in(name), converter::in(content)); if (impl(i)) @@ -263,7 +265,7 @@ template inline node_ptr > element::insert(child_iterator i, - node_ptr > child) + node_ptr > child) { xmlUnlinkNode(impl(*child)); if (impl(i)) @@ -273,7 +275,7 @@ } template -inline void element::remove(element::child_iterator i) +inline void element::remove(typename element::child_iterator i) { if (i != end_children()) { @@ -318,7 +320,7 @@ } template -typename element::const_child_iterator +typename element::const_child_iterator element::find(node_ptr const> n) const { xmlNode *child = impl(*n); @@ -328,7 +330,7 @@ } template -typename element::child_iterator +typename element::child_iterator element::find(node_ptr const> n) { // xmlNode *child = impl(*n); Index: boost/xml/dom/node.hpp =================================================================== --- boost/xml/dom/node.hpp (revision 7403) +++ boost/xml/dom/node.hpp (working copy) @@ -3,6 +3,7 @@ #include #include +#include #include namespace boost @@ -15,13 +16,14 @@ class invalid_cast : public std::invalid_argument { public: - invalid_cast(std::string const &msg) + invalid_cast(std::string const &msg) : std::invalid_argument("invalid cast from " + msg) {} }; template class node_ptr { + friend class node_ptr; public: node_ptr() : impl_(0) {} node_ptr(N const &n) : impl_(n) {} @@ -31,7 +33,7 @@ N &operator*() { return this->impl_;} N *operator->() { return &this->impl_;} N *get() { return &this->impl_;} - operator bool() const { return this->impl_.impl();} + operator bool() const { return this->impl_;} private: N impl_; @@ -45,8 +47,8 @@ friend class node_ptr const>; friend class element; friend class xpath; - friend node_ptr > detail::ptr_factory >(xmlNode *); - friend node_ptr const> detail::ptr_factory const>(xmlNode *); + friend node_ptr > ptr_factory >(xmlNode *); + friend node_ptr const> ptr_factory const>(xmlNode *); template friend T cast(node_ptr); public: @@ -59,19 +61,19 @@ S path() const; //. Return the node's active base (See XBase). S base() const; - //. Return the node's active language. + //. Return the node's active language. S lang() const; //. Return the parent node, if any. - node_ptr const> parent() const - { return detail::ptr_factory >(this->impl()->parent);} - node_ptr > parent() - { return detail::ptr_factory >(this->impl()->parent);} + node_ptr const> parent() const + { return ptr_factory >(this->impl()->parent);} + node_ptr > parent() + { return ptr_factory >(this->impl()->parent);} protected: node(xmlNode *n) : detail::wrapper(n) {} node(node const &n) : detail::wrapper(n) {} - node &operator=(node const &n) + node &operator=(node const &n) { detail::wrapper::operator=(n); return *this; @@ -105,16 +107,16 @@ return retn; } -template +template inline T cast(node_ptr n) { - if (n->impl() && + if (n->impl() && detail::node_type_table[n->impl()->type] != detail::target::type) { node_type type = detail::node_type_table[n->impl()->type]; throw invalid_cast(detail::node_type_names[type]); } - return detail::ptr_factory::type>(n->impl()); + return ptr_factory::type>(n->impl()); } } // namespace boost::xml::dom Index: boost/xml/dom/node_set.hpp =================================================================== --- boost/xml/dom/node_set.hpp (revision 7403) +++ boost/xml/dom/node_set.hpp (working copy) @@ -21,12 +21,12 @@ ~node_set() { xmlXPathFreeNodeSet(this->impl());} size_t size() const { return this->impl()->nodeNr;} - node_ptr > operator[] (size_t i) + node_ptr > operator[] (size_t i) { - return detail::ptr_factory >(this->impl()->nodeTab[i]); + return ptr_factory >(this->impl()->nodeTab[i]); } - iterator begin() + iterator begin() { if (!this->impl()) return iterator(0, 0); else return iterator(this->impl()->nodeTab, this->impl()->nodeNr); @@ -49,7 +49,7 @@ iterator(xmlNode **array, int rest) : current_(array), rest_(rest ? --rest : 0), - tmp_(detail::ptr_factory >(current_ ? *current_ : 0)) + tmp_(ptr_factory >(current_ ? *current_ : 0)) { } bool operator == (iterator i) { return current_ == i.current_;} @@ -59,13 +59,13 @@ iterator operator ++(int) { increment(); return *this;} iterator operator ++() { iterator tmp = *this; increment(); return tmp;} private: - void increment() + void increment() { if (rest_) { --rest_; ++current_; - tmp_ = detail::ptr_factory >(*current_); + tmp_ = ptr_factory >(*current_); } else { Index: boost/xml/dom/parser.hpp =================================================================== --- boost/xml/dom/parser.hpp (revision 7403) +++ boost/xml/dom/parser.hpp (working copy) @@ -99,9 +99,9 @@ throw parse_error("Document not well-formed."); } - std::auto_ptr > doc = detail::factory(context->myDoc); + std::auto_ptr > doc = factory(context->myDoc); - bool well_formed = context->wellFormed; + bool well_formed = 0 != context->wellFormed; xmlFreeParserCtxt(context);