From: <tbr...@us...> - 2012-03-19 23:02:56
|
Revision: 195 http://xmlwrapp.svn.sourceforge.net/xmlwrapp/?rev=195&view=rev Author: tbrowder2 Date: 2012-03-19 23:02:47 +0000 (Mon, 19 Mar 2012) Log Message: ----------- change C++ source file suffix from .cxx to .cc Added Paths: ----------- trunk/src/libxml/ait_impl.cc trunk/src/libxml/attributes.cc trunk/src/libxml/document.cc trunk/src/libxml/dtd_impl.cc trunk/src/libxml/event_parser.cc trunk/src/libxml/init.cc trunk/src/libxml/node.cc trunk/src/libxml/node_iterator.cc trunk/src/libxml/node_manip.cc trunk/src/libxml/nodes_view.cc trunk/src/libxml/tree_parser.cc trunk/src/libxml/utility.cc trunk/src/libxslt/init.cc trunk/src/libxslt/stylesheet.cc Removed Paths: ------------- trunk/src/libxml/ait_impl.cxx trunk/src/libxml/attributes.cxx trunk/src/libxml/document.cxx trunk/src/libxml/dtd_impl.cxx trunk/src/libxml/event_parser.cxx trunk/src/libxml/init.cxx trunk/src/libxml/node.cxx trunk/src/libxml/node_iterator.cxx trunk/src/libxml/node_manip.cxx trunk/src/libxml/nodes_view.cxx trunk/src/libxml/tree_parser.cxx trunk/src/libxml/utility.cxx trunk/src/libxslt/init.cxx trunk/src/libxslt/stylesheet.cxx Copied: trunk/src/libxml/ait_impl.cc (from rev 186, trunk/src/libxml/ait_impl.cxx) =================================================================== --- trunk/src/libxml/ait_impl.cc (rev 0) +++ trunk/src/libxml/ait_impl.cc 2012-03-19 23:02:47 UTC (rev 195) @@ -0,0 +1,459 @@ +/* + * Copyright (C) 2001-2003 Peter J Jones (pj...@pm...) + * All Rights Reserved + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name of the Author nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A + * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR + * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +// xmlwrapp includes +#include "ait_impl.h" +#include "utility.h" +#include "xmlwrapp/attributes.h" +#include "xmlwrapp/exception.h" + +// standard includes +#include <algorithm> + +// libxml2 includes +#include <libxml/tree.h> + +namespace xml +{ + +using namespace impl; + +// ------------------------------------------------------------------------ +// xml::impl::ait_impl +// ------------------------------------------------------------------------ + +namespace impl +{ + +ait_impl::ait_impl(xmlNodePtr node, xmlAttrPtr prop) + : xmlnode_(node), xmlattr_(prop), fake_(false) +{ + attr_.set_data(xmlnode_, xmlattr_); +} + + +ait_impl::ait_impl(const char *name, const char *value, bool) + : xmlnode_(0), xmlattr_(0), fake_(true) +{ + // in this constructor and in the functions to follow, the last + // parameter, the bool, is only used to create a unique signature + attr_.set_data(name, value, true); +} + + +ait_impl::ait_impl(const ait_impl& other) + : xmlnode_(other.xmlnode_), xmlattr_(other.xmlattr_), fake_(other.fake_) +{ + if (fake_) + attr_.set_data(other.attr_.get_name(), other.attr_.get_value(), true); + else + attr_.set_data(xmlnode_, xmlattr_); +} + + +ait_impl& ait_impl::operator=(const ait_impl& other) +{ + ait_impl tmp(other); + + std::swap(xmlnode_, tmp.xmlnode_); + std::swap(xmlattr_, tmp.xmlattr_); + std::swap(fake_, tmp.fake_); + attr_.swap(tmp.attr_); + + return *this; +} + + +attributes::attr* ait_impl::get() +{ + return &attr_; +} + + +xmlAttrPtr ait_impl::get_raw_attr() +{ + return xmlattr_; +} + + +ait_impl& ait_impl::operator++() +{ + if (xmlattr_) + xmlattr_ = xmlattr_->next; + else + fake_ = false; + + attr_.set_data(xmlnode_, xmlattr_); + return *this; +} + + +ait_impl ait_impl::operator++(int) +{ + ait_impl tmp(xmlnode_, xmlattr_); + ++(*this); + return tmp; +} + +} // namespace impl + + +// ------------------------------------------------------------------------ +// xml::attributes::iterator +// ------------------------------------------------------------------------ + +attributes::iterator::iterator() +{ + pimpl_ = new ait_impl(0, 0); +} + + +attributes::iterator::iterator(void *node, void *prop) +{ + pimpl_ = new ait_impl(static_cast<xmlNodePtr>(node), static_cast<xmlAttrPtr>(prop)); +} + + +attributes::iterator::iterator(const char *name, const char *value, bool) +{ + pimpl_ = new ait_impl(name, value, true); +} + + +attributes::iterator::iterator (const iterator &other) +{ + pimpl_ = new ait_impl(*other.pimpl_); +} + + +attributes::iterator& attributes::iterator::operator=(const iterator& other) +{ + iterator tmp(other); + swap(tmp); + return *this; +} + + +void attributes::iterator::swap(iterator& other) +{ + std::swap(pimpl_, other.pimpl_); +} + + +attributes::iterator::~iterator() +{ + delete pimpl_; +} + + +void* attributes::iterator::get_raw_attr() +{ + return pimpl_->get_raw_attr(); +} + + +attributes::iterator::reference attributes::iterator::operator*() const +{ + return *(pimpl_->get()); +} + + +attributes::iterator::pointer attributes::iterator::operator->() const +{ + return pimpl_->get(); +} + + +attributes::iterator& attributes::iterator::operator++() +{ + ++(*pimpl_); + return *this; +} + + +attributes::iterator attributes::iterator::operator++(int) +{ + iterator tmp(*this); + ++(*this); + return tmp; +} + + +// ------------------------------------------------------------------------ +// xml::attributes::const_iterator +// ------------------------------------------------------------------------ + +attributes::const_iterator::const_iterator() +{ + pimpl_ = new ait_impl(0, 0); +} + + +attributes::const_iterator::const_iterator(void *node, void *prop) +{ + pimpl_ = new ait_impl(static_cast<xmlNodePtr>(node), static_cast<xmlAttrPtr>(prop)); +} + + +attributes::const_iterator::const_iterator(const char *name, const char *value, bool) +{ + pimpl_ = new ait_impl(name, value, true); +} + + +attributes::const_iterator::const_iterator(const const_iterator& other) +{ + pimpl_ = new ait_impl(*other.pimpl_); +} + + +attributes::const_iterator::const_iterator(const iterator& other) +{ + pimpl_ = new ait_impl(*other.pimpl_); +} + + +attributes::const_iterator& attributes::const_iterator::operator=(const const_iterator& other) +{ + const_iterator tmp(other); + swap(tmp); + return *this; +} + + +void attributes::const_iterator::swap(const_iterator& other) +{ + std::swap(pimpl_, other.pimpl_); +} + + +attributes::const_iterator::~const_iterator() +{ + delete pimpl_; +} + + +void* attributes::const_iterator::get_raw_attr() +{ + return pimpl_->get_raw_attr(); +} + + +attributes::const_iterator::reference attributes::const_iterator::operator*() const +{ + return *(pimpl_->get()); +} + + +attributes::const_iterator::pointer attributes::const_iterator::operator->() const +{ + return pimpl_->get(); +} + + +attributes::const_iterator& attributes::const_iterator::operator++() +{ + ++(*pimpl_); + return *this; +} + + +attributes::const_iterator attributes::const_iterator::operator++(int) +{ + const_iterator tmp(*this); + ++(*this); + return tmp; +} + + +// ------------------------------------------------------------------------ +// xml::attributes::attr +// ------------------------------------------------------------------------ + +attributes::attr::attr() : node_(0), prop_(0) +{ +} + + +attributes::attr::attr(const attr& other) + : node_(other.node_), + prop_(other.prop_), + name_(other.name_), + value_(other.value_) +{ +} + + +attributes::attr& attributes::attr::operator=(const attr& other) +{ + attr tmp(other); + swap(tmp); + return *this; +} + + +void attributes::attr::swap(attr& other) +{ + std::swap(node_, other.node_); + std::swap(prop_, other.prop_); + name_.swap(other.name_); + value_.swap(other.value_); +} + + +void attributes::attr::set_data(void *node, void *prop) +{ + node_ = node; + prop_ = prop; + name_.erase(); + value_.erase(); +} + + +void attributes::attr::set_data(const char *name, const char *value, bool) +{ + node_ = 0; + prop_ = 0; + name_ = name; + value_ = value; +} + + +const char* attributes::attr::get_name() const +{ + if (!name_.empty()) + return name_.c_str(); // we were given a name not a node + + if (!node_ || !prop_) + throw xml::exception("access to invalid attributes::attr object!"); + + return reinterpret_cast<const char*>(static_cast<xmlAttrPtr>(prop_)->name); +} + + +const char* attributes::attr::get_value() const +{ + if (!value_.empty()) + return value_.c_str(); // we were given a value, not a node + + if (!node_ || !prop_) + throw xml::exception("access to invalid attributes::attr object!"); + + xmlChar *tmpstr = xmlNodeListGetString(reinterpret_cast<xmlNodePtr>(node_)->doc, reinterpret_cast<xmlAttrPtr>(prop_)->children, 1); + if (tmpstr == 0) + return ""; + + xmlchar_helper helper(tmpstr); + value_.assign(helper.get()); + return value_.c_str(); +} + +// ------------------------------------------------------------------------ +// helper friend functions and operators +// ------------------------------------------------------------------------ + +bool operator==(const attributes::iterator& lhs, const attributes::iterator& rhs) +{ + return *(lhs.pimpl_) == *(rhs.pimpl_); +} + +bool operator!=(const attributes::iterator& lhs, const attributes::iterator& rhs) +{ + return !(lhs == rhs); +} + +bool operator==(const attributes::const_iterator& lhs, const attributes::const_iterator& rhs) +{ + return *(lhs.pimpl_) == *(rhs.pimpl_); +} + +bool operator!=(const attributes::const_iterator& lhs, const attributes::const_iterator& rhs) +{ + return !(lhs == rhs); +} + + +namespace impl +{ + +xmlAttrPtr find_prop(xmlNodePtr xmlnode, const char *name) +{ + xmlAttrPtr prop = xmlnode->properties; + + for (; prop; prop = prop->next ) + { + if (xmlStrEqual(prop->name, reinterpret_cast<const xmlChar*>(name))) + return prop; + } + + return 0; +} + + +xmlAttributePtr find_default_prop(xmlNodePtr xmlnode, const char *name) +{ + if (xmlnode->doc != 0) + { + xmlAttributePtr dtd_attr=0; + + if (xmlnode->doc->intSubset != 0) + { + dtd_attr = xmlGetDtdAttrDesc(xmlnode->doc->intSubset, xmlnode->name, reinterpret_cast<const xmlChar*>(name)); + } + + if (dtd_attr == 0 && xmlnode->doc->extSubset != 0) + { + dtd_attr = xmlGetDtdAttrDesc(xmlnode->doc->extSubset, xmlnode->name, reinterpret_cast<const xmlChar*>(name)); + } + + if (dtd_attr != 0 && dtd_attr->defaultValue != 0) + return dtd_attr; + } + + return 0; +} + +bool operator==(const ait_impl& lhs, const ait_impl& rhs) +{ + if (lhs.fake_ || rhs.fake_) + return false; + return lhs.xmlattr_ == rhs.xmlattr_; +} + +bool operator!=(const ait_impl& lhs, const ait_impl& rhs) +{ + return !(lhs == rhs); +} + +} // namespace impl + +} // namespace xml Deleted: trunk/src/libxml/ait_impl.cxx =================================================================== --- trunk/src/libxml/ait_impl.cxx 2012-03-19 19:25:15 UTC (rev 194) +++ trunk/src/libxml/ait_impl.cxx 2012-03-19 23:02:47 UTC (rev 195) @@ -1,459 +0,0 @@ -/* - * Copyright (C) 2001-2003 Peter J Jones (pj...@pm...) - * All Rights Reserved - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * 3. Neither the name of the Author nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED - * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A - * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR - * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED - * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -// xmlwrapp includes -#include "ait_impl.h" -#include "utility.h" -#include "xmlwrapp/attributes.h" -#include "xmlwrapp/exception.h" - -// standard includes -#include <algorithm> - -// libxml2 includes -#include <libxml/tree.h> - -namespace xml -{ - -using namespace impl; - -// ------------------------------------------------------------------------ -// xml::impl::ait_impl -// ------------------------------------------------------------------------ - -namespace impl -{ - -ait_impl::ait_impl(xmlNodePtr node, xmlAttrPtr prop) - : xmlnode_(node), xmlattr_(prop), fake_(false) -{ - attr_.set_data(xmlnode_, xmlattr_); -} - - -ait_impl::ait_impl(const char *name, const char *value, bool) - : xmlnode_(0), xmlattr_(0), fake_(true) -{ - // in this constructor and in the functions to follow, the last - // parameter, the bool, is only used to create a unique signature - attr_.set_data(name, value, true); -} - - -ait_impl::ait_impl(const ait_impl& other) - : xmlnode_(other.xmlnode_), xmlattr_(other.xmlattr_), fake_(other.fake_) -{ - if (fake_) - attr_.set_data(other.attr_.get_name(), other.attr_.get_value(), true); - else - attr_.set_data(xmlnode_, xmlattr_); -} - - -ait_impl& ait_impl::operator=(const ait_impl& other) -{ - ait_impl tmp(other); - - std::swap(xmlnode_, tmp.xmlnode_); - std::swap(xmlattr_, tmp.xmlattr_); - std::swap(fake_, tmp.fake_); - attr_.swap(tmp.attr_); - - return *this; -} - - -attributes::attr* ait_impl::get() -{ - return &attr_; -} - - -xmlAttrPtr ait_impl::get_raw_attr() -{ - return xmlattr_; -} - - -ait_impl& ait_impl::operator++() -{ - if (xmlattr_) - xmlattr_ = xmlattr_->next; - else - fake_ = false; - - attr_.set_data(xmlnode_, xmlattr_); - return *this; -} - - -ait_impl ait_impl::operator++(int) -{ - ait_impl tmp(xmlnode_, xmlattr_); - ++(*this); - return tmp; -} - -} // namespace impl - - -// ------------------------------------------------------------------------ -// xml::attributes::iterator -// ------------------------------------------------------------------------ - -attributes::iterator::iterator() -{ - pimpl_ = new ait_impl(0, 0); -} - - -attributes::iterator::iterator(void *node, void *prop) -{ - pimpl_ = new ait_impl(static_cast<xmlNodePtr>(node), static_cast<xmlAttrPtr>(prop)); -} - - -attributes::iterator::iterator(const char *name, const char *value, bool) -{ - pimpl_ = new ait_impl(name, value, true); -} - - -attributes::iterator::iterator (const iterator &other) -{ - pimpl_ = new ait_impl(*other.pimpl_); -} - - -attributes::iterator& attributes::iterator::operator=(const iterator& other) -{ - iterator tmp(other); - swap(tmp); - return *this; -} - - -void attributes::iterator::swap(iterator& other) -{ - std::swap(pimpl_, other.pimpl_); -} - - -attributes::iterator::~iterator() -{ - delete pimpl_; -} - - -void* attributes::iterator::get_raw_attr() -{ - return pimpl_->get_raw_attr(); -} - - -attributes::iterator::reference attributes::iterator::operator*() const -{ - return *(pimpl_->get()); -} - - -attributes::iterator::pointer attributes::iterator::operator->() const -{ - return pimpl_->get(); -} - - -attributes::iterator& attributes::iterator::operator++() -{ - ++(*pimpl_); - return *this; -} - - -attributes::iterator attributes::iterator::operator++(int) -{ - iterator tmp(*this); - ++(*this); - return tmp; -} - - -// ------------------------------------------------------------------------ -// xml::attributes::const_iterator -// ------------------------------------------------------------------------ - -attributes::const_iterator::const_iterator() -{ - pimpl_ = new ait_impl(0, 0); -} - - -attributes::const_iterator::const_iterator(void *node, void *prop) -{ - pimpl_ = new ait_impl(static_cast<xmlNodePtr>(node), static_cast<xmlAttrPtr>(prop)); -} - - -attributes::const_iterator::const_iterator(const char *name, const char *value, bool) -{ - pimpl_ = new ait_impl(name, value, true); -} - - -attributes::const_iterator::const_iterator(const const_iterator& other) -{ - pimpl_ = new ait_impl(*other.pimpl_); -} - - -attributes::const_iterator::const_iterator(const iterator& other) -{ - pimpl_ = new ait_impl(*other.pimpl_); -} - - -attributes::const_iterator& attributes::const_iterator::operator=(const const_iterator& other) -{ - const_iterator tmp(other); - swap(tmp); - return *this; -} - - -void attributes::const_iterator::swap(const_iterator& other) -{ - std::swap(pimpl_, other.pimpl_); -} - - -attributes::const_iterator::~const_iterator() -{ - delete pimpl_; -} - - -void* attributes::const_iterator::get_raw_attr() -{ - return pimpl_->get_raw_attr(); -} - - -attributes::const_iterator::reference attributes::const_iterator::operator*() const -{ - return *(pimpl_->get()); -} - - -attributes::const_iterator::pointer attributes::const_iterator::operator->() const -{ - return pimpl_->get(); -} - - -attributes::const_iterator& attributes::const_iterator::operator++() -{ - ++(*pimpl_); - return *this; -} - - -attributes::const_iterator attributes::const_iterator::operator++(int) -{ - const_iterator tmp(*this); - ++(*this); - return tmp; -} - - -// ------------------------------------------------------------------------ -// xml::attributes::attr -// ------------------------------------------------------------------------ - -attributes::attr::attr() : node_(0), prop_(0) -{ -} - - -attributes::attr::attr(const attr& other) - : node_(other.node_), - prop_(other.prop_), - name_(other.name_), - value_(other.value_) -{ -} - - -attributes::attr& attributes::attr::operator=(const attr& other) -{ - attr tmp(other); - swap(tmp); - return *this; -} - - -void attributes::attr::swap(attr& other) -{ - std::swap(node_, other.node_); - std::swap(prop_, other.prop_); - name_.swap(other.name_); - value_.swap(other.value_); -} - - -void attributes::attr::set_data(void *node, void *prop) -{ - node_ = node; - prop_ = prop; - name_.erase(); - value_.erase(); -} - - -void attributes::attr::set_data(const char *name, const char *value, bool) -{ - node_ = 0; - prop_ = 0; - name_ = name; - value_ = value; -} - - -const char* attributes::attr::get_name() const -{ - if (!name_.empty()) - return name_.c_str(); // we were given a name not a node - - if (!node_ || !prop_) - throw xml::exception("access to invalid attributes::attr object!"); - - return reinterpret_cast<const char*>(static_cast<xmlAttrPtr>(prop_)->name); -} - - -const char* attributes::attr::get_value() const -{ - if (!value_.empty()) - return value_.c_str(); // we were given a value, not a node - - if (!node_ || !prop_) - throw xml::exception("access to invalid attributes::attr object!"); - - xmlChar *tmpstr = xmlNodeListGetString(reinterpret_cast<xmlNodePtr>(node_)->doc, reinterpret_cast<xmlAttrPtr>(prop_)->children, 1); - if (tmpstr == 0) - return ""; - - xmlchar_helper helper(tmpstr); - value_.assign(helper.get()); - return value_.c_str(); -} - -// ------------------------------------------------------------------------ -// helper friend functions and operators -// ------------------------------------------------------------------------ - -bool operator==(const attributes::iterator& lhs, const attributes::iterator& rhs) -{ - return *(lhs.pimpl_) == *(rhs.pimpl_); -} - -bool operator!=(const attributes::iterator& lhs, const attributes::iterator& rhs) -{ - return !(lhs == rhs); -} - -bool operator==(const attributes::const_iterator& lhs, const attributes::const_iterator& rhs) -{ - return *(lhs.pimpl_) == *(rhs.pimpl_); -} - -bool operator!=(const attributes::const_iterator& lhs, const attributes::const_iterator& rhs) -{ - return !(lhs == rhs); -} - - -namespace impl -{ - -xmlAttrPtr find_prop(xmlNodePtr xmlnode, const char *name) -{ - xmlAttrPtr prop = xmlnode->properties; - - for (; prop; prop = prop->next ) - { - if (xmlStrEqual(prop->name, reinterpret_cast<const xmlChar*>(name))) - return prop; - } - - return 0; -} - - -xmlAttributePtr find_default_prop(xmlNodePtr xmlnode, const char *name) -{ - if (xmlnode->doc != 0) - { - xmlAttributePtr dtd_attr=0; - - if (xmlnode->doc->intSubset != 0) - { - dtd_attr = xmlGetDtdAttrDesc(xmlnode->doc->intSubset, xmlnode->name, reinterpret_cast<const xmlChar*>(name)); - } - - if (dtd_attr == 0 && xmlnode->doc->extSubset != 0) - { - dtd_attr = xmlGetDtdAttrDesc(xmlnode->doc->extSubset, xmlnode->name, reinterpret_cast<const xmlChar*>(name)); - } - - if (dtd_attr != 0 && dtd_attr->defaultValue != 0) - return dtd_attr; - } - - return 0; -} - -bool operator==(const ait_impl& lhs, const ait_impl& rhs) -{ - if (lhs.fake_ || rhs.fake_) - return false; - return lhs.xmlattr_ == rhs.xmlattr_; -} - -bool operator!=(const ait_impl& lhs, const ait_impl& rhs) -{ - return !(lhs == rhs); -} - -} // namespace impl - -} // namespace xml Copied: trunk/src/libxml/attributes.cc (from rev 186, trunk/src/libxml/attributes.cxx) =================================================================== --- trunk/src/libxml/attributes.cc (rev 0) +++ trunk/src/libxml/attributes.cc 2012-03-19 23:02:47 UTC (rev 195) @@ -0,0 +1,266 @@ +/* + * Copyright (C) 2001-2003 Peter J Jones (pj...@pm...) + * All Rights Reserved + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name of the Author nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A + * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR + * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +// xmlwrapp includes +#include "xmlwrapp/attributes.h" +#include "ait_impl.h" +#include "pimpl_base.h" + +// standard includes +#include <new> +#include <algorithm> + +// libxml2 includes +#include <libxml/tree.h> + +namespace xml +{ + +using namespace xml::impl; + +// ------------------------------------------------------------------------ +// xml::attributes::pimpl +// ------------------------------------------------------------------------ + +struct attributes::pimpl : public pimpl_base<attributes::pimpl> +{ + pimpl() : owner_(true) + { + xmlnode_ = xmlNewNode(0, reinterpret_cast<const xmlChar*>("blank")); + if (!xmlnode_) + throw std::bad_alloc(); + } + + pimpl(xmlNodePtr node) : xmlnode_(node), owner_(false) {} + + pimpl(const pimpl& other) : owner_(true) + { + xmlnode_ = xmlNewNode(0, reinterpret_cast<const xmlChar*>("blank")); + if (!xmlnode_) + throw std::bad_alloc(); + + xmlAttrPtr i=other.xmlnode_->properties; + xmlAttrPtr copy; + + // work around bug in libxml + for ( ; i != 0; i = i->next ) + { + if ( (copy = xmlCopyProp(0, i)) == 0) + { + xmlFreeNode(xmlnode_); + throw std::bad_alloc(); + } + + copy->prev = 0; + copy->next = 0; + xmlAddChild(xmlnode_, reinterpret_cast<xmlNodePtr>(copy)); + } + } + + ~pimpl() + { + release(); + } + + void release() + { + if (owner_ && xmlnode_) + xmlFreeNode(xmlnode_); + } + + xmlNodePtr xmlnode_; + bool owner_; +}; + + +// ------------------------------------------------------------------------ +// xml::attributes +// ------------------------------------------------------------------------ + +attributes::attributes() +{ + pimpl_ = new pimpl; +} + + +attributes::attributes(int) +{ + pimpl_ = new pimpl(0); +} + + +attributes::attributes(const attributes& other) +{ + pimpl_ = new pimpl(*other.pimpl_); +} + + +attributes& attributes::operator=(const attributes& other) +{ + attributes tmp(other); + swap(tmp); + return *this; +} + + +void attributes::swap(attributes& other) +{ + std::swap(pimpl_, other.pimpl_); +} + + +attributes::~attributes() +{ + delete pimpl_; +} + + +void* attributes::get_data() +{ + return pimpl_->xmlnode_; +} + + +void attributes::set_data(void *node) +{ + xmlNodePtr x = static_cast<xmlNodePtr>(node); + + pimpl_->release(); + pimpl_->owner_ = false; + pimpl_->xmlnode_ = x; +} + + +attributes::iterator attributes::begin() +{ + return iterator(pimpl_->xmlnode_, pimpl_->xmlnode_->properties); +} + + +attributes::const_iterator attributes::begin() const +{ + return const_iterator(pimpl_->xmlnode_, pimpl_->xmlnode_->properties); +} + + +attributes::iterator attributes::end() +{ + return iterator(); +} + + +attributes::const_iterator attributes::end() const +{ + return const_iterator(); +} + + +void attributes::insert(const char *name, const char *value) +{ + xmlSetProp(pimpl_->xmlnode_, + reinterpret_cast<const xmlChar*>(name), + reinterpret_cast<const xmlChar*>(value)); +} + + +attributes::iterator attributes::find(const char *name) +{ + xmlAttrPtr prop = find_prop(pimpl_->xmlnode_, name); + if ( prop != 0 ) + return iterator(pimpl_->xmlnode_, prop); + + xmlAttributePtr dtd_prop = find_default_prop(pimpl_->xmlnode_, name); + if ( dtd_prop != 0 ) + return iterator(name, reinterpret_cast<const char*>(dtd_prop->defaultValue), true); + + return iterator(); +} + + +attributes::const_iterator attributes::find(const char *name) const +{ + xmlAttrPtr prop = find_prop(pimpl_->xmlnode_, name); + if (prop != 0) + return const_iterator(pimpl_->xmlnode_, prop); + + xmlAttributePtr dtd_prop = find_default_prop(pimpl_->xmlnode_, name); + + if (dtd_prop != 0) + { + return const_iterator(name, reinterpret_cast<const char*>(dtd_prop->defaultValue), true); + } + + return const_iterator(); +} + + +attributes::iterator attributes::erase (iterator to_erase) +{ + xmlNodePtr prop = static_cast<xmlNodePtr>(to_erase.get_raw_attr()); + if (prop == 0) + return iterator(); // handle fake and bad iterators + ++to_erase; + + xmlUnlinkNode(prop); + xmlFreeNode(prop); + + return to_erase; +} + + +void attributes::erase(const char *name) +{ + xmlUnsetProp(pimpl_->xmlnode_, reinterpret_cast<const xmlChar*>(name)); +} + + +bool attributes::empty() const +{ + return pimpl_->xmlnode_->properties == 0; +} + + +attributes::size_type attributes::size() const +{ + size_type count = 0; + + xmlAttrPtr prop = pimpl_->xmlnode_->properties; + while (prop != 0) + { + ++count; + prop = prop->next; + } + + return count; +} + +} // namespace xml Deleted: trunk/src/libxml/attributes.cxx =================================================================== --- trunk/src/libxml/attributes.cxx 2012-03-19 19:25:15 UTC (rev 194) +++ trunk/src/libxml/attributes.cxx 2012-03-19 23:02:47 UTC (rev 195) @@ -1,266 +0,0 @@ -/* - * Copyright (C) 2001-2003 Peter J Jones (pj...@pm...) - * All Rights Reserved - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * 3. Neither the name of the Author nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED - * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A - * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR - * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED - * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -// xmlwrapp includes -#include "xmlwrapp/attributes.h" -#include "ait_impl.h" -#include "pimpl_base.h" - -// standard includes -#include <new> -#include <algorithm> - -// libxml2 includes -#include <libxml/tree.h> - -namespace xml -{ - -using namespace xml::impl; - -// ------------------------------------------------------------------------ -// xml::attributes::pimpl -// ------------------------------------------------------------------------ - -struct attributes::pimpl : public pimpl_base<attributes::pimpl> -{ - pimpl() : owner_(true) - { - xmlnode_ = xmlNewNode(0, reinterpret_cast<const xmlChar*>("blank")); - if (!xmlnode_) - throw std::bad_alloc(); - } - - pimpl(xmlNodePtr node) : xmlnode_(node), owner_(false) {} - - pimpl(const pimpl& other) : owner_(true) - { - xmlnode_ = xmlNewNode(0, reinterpret_cast<const xmlChar*>("blank")); - if (!xmlnode_) - throw std::bad_alloc(); - - xmlAttrPtr i=other.xmlnode_->properties; - xmlAttrPtr copy; - - // work around bug in libxml - for ( ; i != 0; i = i->next ) - { - if ( (copy = xmlCopyProp(0, i)) == 0) - { - xmlFreeNode(xmlnode_); - throw std::bad_alloc(); - } - - copy->prev = 0; - copy->next = 0; - xmlAddChild(xmlnode_, reinterpret_cast<xmlNodePtr>(copy)); - } - } - - ~pimpl() - { - release(); - } - - void release() - { - if (owner_ && xmlnode_) - xmlFreeNode(xmlnode_); - } - - xmlNodePtr xmlnode_; - bool owner_; -}; - - -// ------------------------------------------------------------------------ -// xml::attributes -// ------------------------------------------------------------------------ - -attributes::attributes() -{ - pimpl_ = new pimpl; -} - - -attributes::attributes(int) -{ - pimpl_ = new pimpl(0); -} - - -attributes::attributes(const attributes& other) -{ - pimpl_ = new pimpl(*other.pimpl_); -} - - -attributes& attributes::operator=(const attributes& other) -{ - attributes tmp(other); - swap(tmp); - return *this; -} - - -void attributes::swap(attributes& other) -{ - std::swap(pimpl_, other.pimpl_); -} - - -attributes::~attributes() -{ - delete pimpl_; -} - - -void* attributes::get_data() -{ - return pimpl_->xmlnode_; -} - - -void attributes::set_data(void *node) -{ - xmlNodePtr x = static_cast<xmlNodePtr>(node); - - pimpl_->release(); - pimpl_->owner_ = false; - pimpl_->xmlnode_ = x; -} - - -attributes::iterator attributes::begin() -{ - return iterator(pimpl_->xmlnode_, pimpl_->xmlnode_->properties); -} - - -attributes::const_iterator attributes::begin() const -{ - return const_iterator(pimpl_->xmlnode_, pimpl_->xmlnode_->properties); -} - - -attributes::iterator attributes::end() -{ - return iterator(); -} - - -attributes::const_iterator attributes::end() const -{ - return const_iterator(); -} - - -void attributes::insert(const char *name, const char *value) -{ - xmlSetProp(pimpl_->xmlnode_, - reinterpret_cast<const xmlChar*>(name), - reinterpret_cast<const xmlChar*>(value)); -} - - -attributes::iterator attributes::find(const char *name) -{ - xmlAttrPtr prop = find_prop(pimpl_->xmlnode_, name); - if ( prop != 0 ) - return iterator(pimpl_->xmlnode_, prop); - - xmlAttributePtr dtd_prop = find_default_prop(pimpl_->xmlnode_, name); - if ( dtd_prop != 0 ) - return iterator(name, reinterpret_cast<const char*>(dtd_prop->defaultValue), true); - - return iterator(); -} - - -attributes::const_iterator attributes::find(const char *name) const -{ - xmlAttrPtr prop = find_prop(pimpl_->xmlnode_, name); - if (prop != 0) - return const_iterator(pimpl_->xmlnode_, prop); - - xmlAttributePtr dtd_prop = find_default_prop(pimpl_->xmlnode_, name); - - if (dtd_prop != 0) - { - return const_iterator(name, reinterpret_cast<const char*>(dtd_prop->defaultValue), true); - } - - return const_iterator(); -} - - -attributes::iterator attributes::erase (iterator to_erase) -{ - xmlNodePtr prop = static_cast<xmlNodePtr>(to_erase.get_raw_attr()); - if (prop == 0) - return iterator(); // handle fake and bad iterators - ++to_erase; - - xmlUnlinkNode(prop); - xmlFreeNode(prop); - - return to_erase; -} - - -void attributes::erase(const char *name) -{ - xmlUnsetProp(pimpl_->xmlnode_, reinterpret_cast<const xmlChar*>(name)); -} - - -bool attributes::empty() const -{ - return pimpl_->xmlnode_->properties == 0; -} - - -attributes::size_type attributes::size() const -{ - size_type count = 0; - - xmlAttrPtr prop = pimpl_->xmlnode_->properties; - while (prop != 0) - { - ++count; - prop = prop->next; - } - - return count; -} - -} // namespace xml Copied: trunk/src/libxml/document.cc (from rev 186, trunk/src/libxml/document.cxx) =================================================================== --- trunk/src/libxml/document.cc (rev 0) +++ trunk/src/libxml/document.cc 2012-03-19 23:02:47 UTC (rev 195) @@ -0,0 +1,513 @@ +/* + * Copyright (C) 2001-2003 Peter J Jones (pj...@pm...) + * All Rights Reserved + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name of the Author nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A + * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR + * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +// xmlwrapp includes +#include "xmlwrapp/document.h" +#include "xmlwrapp/node.h" +#include "xmlwrapp/exception.h" + +#include "utility.h" +#include "dtd_impl.h" +#include "node_manip.h" + +// standard includes +#include <new> +#include <memory> +#include <iterator> +#include <iostream> +#include <algorithm> +#include <stdexcept> + +// libxml includes +#include <libxml/tree.h> +#include <libxml/xinclude.h> + +// bring in private libxslt stuff (see bug #1927398) +#include "../libxslt/result.h" + +namespace xml +{ + +using namespace impl; + +namespace +{ + const char DEFAULT_ENCODING[] = "ISO-8859-1"; +} + +// ------------------------------------------------------------------------ +// xml::impl::doc_impl +// ------------------------------------------------------------------------ + +namespace impl +{ + +struct doc_impl +{ + doc_impl() + : doc_(0), xslt_result_(0) + { + xmlDocPtr tmpdoc; + if ( (tmpdoc = xmlNewDoc(0)) == 0) + throw std::bad_alloc(); + set_doc_data(tmpdoc, true); + } + + + doc_impl(const char *root_name) + : doc_(0), xslt_result_(0), root_(root_name) + { + xmlDocPtr tmpdoc; + if ( (tmpdoc = xmlNewDoc(0)) == 0) + throw std::bad_alloc(); + set_doc_data(tmpdoc, true); + } + + + doc_impl(const doc_impl& other) + : doc_(0), xslt_result_(0) + { + xmlDocPtr tmpdoc; + if ( (tmpdoc = xmlCopyDoc(other.doc_, 1)) == 0) + throw std::bad_alloc(); + set_doc_data(tmpdoc, false); + } + + + void set_doc_data(xmlDocPtr newdoc, bool root_is_okay) + { + if (doc_) + xmlFreeDoc(doc_); + doc_ = newdoc; + + if (doc_->version) + version_ = reinterpret_cast<const char*>(doc_->version); + if (doc_->encoding) + encoding_ = reinterpret_cast<const char*>(doc_->encoding); + + if (root_is_okay) + { + xmlDocSetRootElement(doc_, static_cast<xmlNodePtr>(root_.release_node_data())); + } + else + { + xmlNodePtr libxml_root_node = xmlDocGetRootElement(doc_); + + if (libxml_root_node) + { + root_.set_node_data(libxml_root_node); + } + else + { + node tmpnode; + root_.swap(tmpnode); + + xmlDocSetRootElement(doc_, static_cast<xmlNodePtr>(root_.release_node_data())); + } + } + } + + + void set_root_node(const node& n) + { + node &non_const_node = const_cast<node&>(n); + xmlNodePtr new_root_node = xmlCopyNode(static_cast<xmlNodePtr>(non_const_node.get_node_data()), 1); + if (!new_root_node) + throw std::bad_alloc(); + + xmlNodePtr old_root_node = xmlDocSetRootElement(doc_, new_root_node); + root_.set_node_data(new_root_node); + if (old_root_node) + xmlFreeNode(old_root_node); + + xslt_result_ = 0; + } + + + ~doc_impl() + { + if (doc_) + xmlFreeDoc(doc_); + delete xslt_result_; + } + + xmlDocPtr doc_; + xslt::impl::result *xslt_result_; + node root_; + std::string version_; + mutable std::string encoding_; +}; + +} // namespace impl + + +// ------------------------------------------------------------------------ +// xml::document +// ------------------------------------------------------------------------ + +document::document() +{ + pimpl_ = new doc_impl; +} + + +document::document(const char *root_name) +{ + pimpl_ = new doc_impl(root_name); +} + + +document::document(const node& n) +{ + std::auto_ptr<doc_impl> ap(pimpl_ = new doc_impl); + pimpl_->set_root_node(n); + ap.release(); +} + + +document::document(const document& other) +{ + pimpl_ = new doc_impl(*(other.pimpl_)); +} + + +document& document::operator=(const document& other) +{ + document tmp(other); + swap(tmp); + return *this; +} + + +void document::swap(document& other) +{ + std::swap(pimpl_, other.pimpl_); +} + + +document::~document() +{ + delete pimpl_; +} + + +const node& document::get_root_node() const +{ + return pimpl_->root_; +} + + +node& document::get_root_node() +{ + return pimpl_->root_; +} + + +void document::set_root_node(const node& n) +{ + pimpl_->set_root_node(n); +} + + +const std::string& document::get_version() const +{ + return pimpl_->version_; +} + + +void document::set_version(const char *version) +{ + const xmlChar *old_version = pimpl_->doc_->version; + if ( (pimpl_->doc_->version = xmlStrdup(reinterpret_cast<const xmlChar*>(version))) == 0) + throw std::bad_alloc(); + + pimpl_->version_ = version; + if (old_version) + xmlFree(const_cast<char*>(reinterpret_cast<const char*>(old_version))); +} + + +const std::string& document::get_encoding() const +{ + if (pimpl_->encoding_.empty()) + pimpl_->encoding_ = DEFAULT_ENCODING; + return pimpl_->encoding_; +} + + +void document::set_encoding(const char *encoding) +{ + pimpl_->encoding_ = encoding; + + if (pimpl_->doc_->encoding) + xmlFree(const_cast<xmlChar*>(pimpl_->doc_->encoding)); + + pimpl_->doc_->encoding = xmlStrdup(reinterpret_cast<const xmlChar*>(encoding)); + + if (!pimpl_->doc_->encoding) + throw std::bad_alloc(); +} + + +bool document::get_is_standalone() const +{ + return pimpl_->doc_->standalone == 1; +} + + +void document::set_is_standalone(bool sa) +{ + pimpl_->doc_->standalone = sa ? 1 : 0; +} + + +bool document::process_xinclude() +{ + // xmlXIncludeProcess does not return what is says it does + return xmlXIncludeProcess(pimpl_->doc_) >= 0; +} + + +bool document::has_internal_subset() const +{ + return pimpl_->doc_->intSubset != 0; +} + + +bool document::has_external_subset() const +{ + return pimpl_->doc_->extSubset != 0; +} + + +bool document::validate() +{ + dtd_impl dtd; + return dtd.validate(pimpl_->doc_); +} + + +bool document::validate(const char *dtdname) +{ + dtd_impl dtd(dtdname); + + if (!dtd.error_.empty()) + return false; + if (!dtd.validate(pimpl_->doc_)) + return false; + + // remove the old DTD + if (pimpl_->doc_->extSubset != 0) + xmlFreeDtd(pimpl_->doc_->extSubset); + + pimpl_->doc_->extSubset = dtd.release(); + + return true; +} + + +document::size_type document::size() const +{ + using namespace std; + return distance(begin(), end()); +} + + +node::iterator document::begin() +{ + return node::iterator(pimpl_->doc_->children); +} + + +node::const_iterator document::begin() const +{ + return node::const_iterator(pimpl_->doc_->children); +} + + +node::iterator document::end() +{ + return node::iterator(0); +} + + +node::const_iterator document::end() const +{ + return node::const_iterator(0); +} + + +void document::push_back(const node& child) +{ + if (child.get_type() == node::type_element) + throw xml::exception("xml::document::push_back can't take element type nodes"); + + impl::node_insert + ( + reinterpret_cast<xmlNodePtr>(pimpl_->doc_), + 0, + static_cast<xmlNodePtr>(const_cast<node&>(child).get_node_data()) + ); +} + + +node::iterator document::insert(const node& n) +{ + if (n.get_type() == node::type_element) + throw xml::exception("xml::document::insert can't take element type nodes"); + + return node::iterator(xml::impl::node_insert(reinterpret_cast<xmlNodePtr>(pimpl_->doc_), 0, static_cast<xmlNodePtr>(const_cast<node&>(n).get_node_data()))); +} + + +node::iterator document::insert(node::iterator position, const node& n) +{ + if (n.get_type() == node::type_element) + throw xml::exception("xml::document::insert can't take element type nodes"); + + return node::iterator(xml::impl::node_insert(reinterpret_cast<xmlNodePtr>(pimpl_->doc_), static_cast<xmlNodePtr>(position.get_raw_node()), static_cast<xmlNodePtr>(const_cast<node&>(n).get_node_data()))); +} + + +node::iterator document::replace(node::iterator old_node, const node& new_node) +{ + if (old_node->get_type() == node::type_element || new_node.get_type() == node::type_element) + { + throw xml::exception("xml::document::replace can't replace element type nodes"); + } + + return node::iterator(xml::impl::node_replace(static_cast<xmlNodePtr>(old_node.get_raw_node()), static_cast<xmlNodePtr>(const_cast<node&>(new_node).get_node_data()))); +} + + +node::iterator document::erase(node::iterator to_erase) +{ + if (to_erase->get_type() == node::type_element) + throw xml::exception("xml::document::erase can't erase element type nodes"); + return node::iterator(xml::impl::node_erase(static_cast<xmlNodePtr>(to_erase.get_raw_node()))); +} + + +node::iterator document::erase(node::iterator first, node::iterator last) +{ + while (first != last) + first = erase(first); + return first; +} + + +void document::save_to_string(std::string& s) const +{ + xmlChar *xml_string; + int xml_string_length; + + if (pimpl_->xslt_result_ != 0) + { + pimpl_->xslt_result_->save_to_string(s); + return; + } + + const char *enc = pimpl_->encoding_.empty() ? 0 : pimpl_->encoding_.c_str(); + xmlDocDumpFormatMemoryEnc(pimpl_->doc_, &xml_string, &xml_string_length, enc, 1); + + xmlchar_helper helper(xml_string); + if (xml_string_length) + s.assign(helper.get(), xml_string_length); +} + + +bool document::save_to_file(const char *filename, int compression_level) const +{ + std::swap(pimpl_->doc_->compression, compression_level); + + if (pimpl_->xslt_result_ != 0) + { + bool rc = pimpl_->xslt_result_->save_to_file(filename, compression_level); + std::swap(pimpl_->doc_->compression, compression_level); + + return rc; + } + + const char *enc = pimpl_->encoding_.empty() ? 0 : pimpl_->encoding_.c_str(); + bool rc = xmlSaveFormatFileEnc(filename, pimpl_->doc_, enc, 1) > 0; + std::swap(pimpl_->doc_->compression, compression_level); + + return rc; +} + + +void document::set_doc_data(void *data) +{ + // we own the doc now, don't free it! + pimpl_->set_doc_data(static_cast<xmlDocPtr>(data), false); + pimpl_->xslt_result_ = 0; +} + + +void document::set_doc_data_from_xslt(void *data, xslt::impl::result *xr) +{ + // this document came from a XSLT transformation + pimpl_->set_doc_data(static_cast<xmlDocPtr>(data), false); + pimpl_->xslt_result_ = xr; +} + + +void* document::get_doc_data() +{ + return pimpl_->doc_; +} + + +void* document::get_doc_data_read_only() const +{ + return pimpl_->doc_; +} + + +void* document::release_doc_data() +{ + xmlDocPtr xmldoc = pimpl_->doc_; + pimpl_->doc_ = 0; + + return xmldoc; +} + + +std::ostream& operator<<(std::ostream& stream, const document& doc) +{ + std::string xmldata; + doc.save_to_string(xmldata); + stream << xmldata; + return stream; +} + +} // namespace xml Deleted: trunk/src/libxml/document.cxx =================================================================== --- trunk/src/libxml/document.cxx 2012-03-19 19:25:15 UTC (rev 194) +++ trunk/src/libxml/document.cxx 2012-03-19 23:02:47 UTC (rev 195) @@ -1,513 +0,0 @@ -/* - * Copyright (C) 2001-2003 Peter J Jones (pj...@pm...) - * All Rights Reserved - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * 3. Neither the name of the Author nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED - * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A - * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR - * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED - * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -// xmlwrapp includes -#include "xmlwrapp/document.h" -#include "xmlwrapp/node.h" -#include "xmlwrapp/exception.h" - -#include "utility.h" -#include "dtd_impl.h" -#include "node_manip.h" - -// standard includes -#include <new> -#include <memory> -#include <iterator> -#include <iostream> -#include <algorithm> -#include <stdexcept> - -// libxml includes -#include <libxml/tree.h> -#include <libxml/xinclude.h> - -// bring in private libxslt stuff (see bug #1927398) -#include "../libxslt/result.h" - -namespace xml -{ - -using namespace impl; - -namespace -{ - const char DEFAULT_ENCODING[] = "ISO-8859-1"; -} - -// ------------------------------------------------------------------------ -// xml::impl::doc_impl -// ------------------------------------------------------------------------ - -namespace impl -{ - -struct doc_impl -{ - doc_impl() - : doc_(0), xslt_result_(0) - { - xmlDocPtr tmpdoc; - if ( (tmpdoc = xmlNewDoc(0)) == 0) - throw std::bad_alloc(); - set_doc_data(tmpdoc, true); - } - - - doc_impl(const char *root_name) - : doc_(0), xslt_result_(0), root_(root_name) - { - xmlDocPtr tmpdoc; - if ( (tmpdoc = xmlNewDoc(0)) == 0) - throw std::bad_alloc(); - set_doc_data(tmpdoc, true); - } - - - doc_impl(const doc_impl& other) - : doc_(0), xslt_result_(0) - { - xmlDocPtr tmpdoc; - if ( (tmpdoc = xmlCopyDoc(other.doc_, 1)) == 0) - throw std::bad_alloc(); - set_doc_data(tmpdoc, false); - } - - - void set_doc_data(xmlDocPtr newdoc, bool root_is_okay) - { - if (doc_) - xmlFreeDoc(doc_); - doc_ = newdoc; - - if (doc_->version) - version_ = reinterpret_cast<const char*>(doc_->version); - if (doc_->encoding) - encoding_ = reinterpret_cast<const char*>(doc_->encoding); - - if (root_is_okay) - { - xmlDocSetRootElement(doc_, static_cast<xmlNodePtr>(root_.release_node_data())); - } - else - { - xmlNodePtr libxml_root_node = xmlDocGetRootElement(doc_); - - if (libxml_root_node) - { - root_.set_node_data(libxml_root_node); - } - else - { - node tmpnode; - root_.swap(tmpnode); - - xmlDocSetRootElement(doc_, static_cast<xmlNodePtr>(root_.release_node_data())); - } - } - } - - - void set_root_node(const node& n) - { - node &non_const_node = const_cast<node&>(n); - xmlNodePtr new_root_node = xmlCopyNode(static_cast<xmlNodePtr>(non_const_node.get_node_data()), 1); - if (!new_root_node) - throw std::bad_alloc(); - - xmlNodePtr old_root_node = xmlDocSetRootElement(doc_, new_root_node); - root_.set_node_data(new_root_node); - if (old_root_node) - xmlFreeNode(old_root_node); - - xslt_result_ = 0; - } - - - ~doc_impl() - { - if (doc_) - xmlFreeDoc(doc_); - delete xslt_result_; - } - - xmlDocPtr doc_; - xslt::impl::result *xslt_result_; - node root_; - std::string version_; - mutable std::string encoding_; -}; - -} // namespace impl - - -// ------------------------------------------------------------------------ -// xml::document -// ------------------------------------------------------------------------ - -document::document() -{ - pimpl_ = new doc_impl; -} - - -document::document(const char *root_name) -{ - pimpl_ = new doc_impl(root_name); -} - - -document::document(const node& n) -{ - std::auto_ptr<doc_impl> ap(pimpl_ = new doc_impl); - pimpl_->set_root_node(n); - ap.release(); -} - - -document::document(const document& other) -{ - pimpl_ = new doc_impl(*(other.pimpl_)); -} - - -document& document::operator=(const document& other) -{ - document tmp(other); - swap(tmp); - return *this; -} - - -void document::swap(document& other) -{ - std::swap(pimpl_, other.pimpl_); -} - - -document::~document() -{ - delete pimpl_; -} - - -const node& document::get_root_node() const -{ - return pimpl_->root_; -} - - -node& document::get_root_node() -{ - return pimpl_->root_; -} - - -void document::set_root_node(const node& n) -{ - pimpl_->set_root_node(n); -} - - -const std::string& document::get_version() const -{ - return pimpl_->version_; -} - - -void document::set_version(const char *version) -{ - const xmlChar *old_version = pimpl_->doc_->version; - if ( (pimpl_->doc_->version = xmlStrdup(reinterpret_cast<const xmlChar*>(version))) == 0) - throw std::bad_alloc(); - - pimpl_->version_ = version; - if (old_version) - xmlFree(const_cast<char*>(reinterpret_cast<const char*>(old_version))); -} - - -const std::string& document::get_encoding() const -{ - if (pimpl_->encoding_.empty()) - pimpl_->encoding_ = DEFAULT_ENCODING; - return pimpl_->encoding_; -} - - -void document::set_encoding(const char *encoding) -{ - pimpl_->encoding_ = encoding; - - if (pimpl_->doc_->encoding) - xmlFree(const_cast<xmlChar*>(pimpl_->doc_->encoding)); - - pimpl_->doc_->encoding = xmlStrdup(reinterpret_cast<const xmlChar*>(encoding)); - - if (!pimpl_->doc_->encoding) - throw std::bad_alloc(); -} - - -bool document::get_is_standalone() const -{ - return pimpl_->doc_->standalone == 1; -} - - -void document::set_is_standalone(bool sa) -{ - pimpl_->doc_->standalone = sa ? 1 : 0; -} - - -bool document::process_xinclude() -{ - // xmlXIncludeProcess does not return what is says it does - return xmlXIncludeProcess(pimpl_->doc_) >= 0; -} - - -bool document::has_internal_subset() const -{ - return pimpl_->doc_->intSubset != 0; -} - - -bool document::has_external_subset() const -{ - return pimpl_->doc_->extSubset != 0; -} - - -bool document::validate() -{ - dtd_impl dtd; - return dtd.validate(pimpl_->doc_); -} - - -bool document::validate(const char *dtdname) -{ - dtd_impl dtd(dtdname); - - if (!dtd.error_.empty()) - return false; - if (!dtd.validate(pimpl_->doc_)) - return false; - - // remove the old DTD - if (pimpl_->doc_->extSubset != 0) - xmlFreeDtd(pimpl_->doc_->extSubset); - - pimpl_->doc_->extSubset = dtd.release(); - - return true; -} - - -document::size_type document::size() const -{ - using namespace std; - return distance(begin(), end()); -} - - -node::iterator document::begin() -{ - return node::iterator(pimpl_->doc_->children); -} - - -node::const_iterator document::begin() const -{ - return node::const_iterator(pimpl_->doc_->children); -} - - -node::iterator document::end() -{ - return node::iterator(0); -} - - -node::const_iterator document::end() const -{ - return node::const_iterator(0); -} - - -void document::push_back(const node& child) -{ - if (child.get_type() == node::type_element) - throw xml::exception("xml::document::push_back can't take element type nodes"); - - impl::node_insert - ( - reinterpret_cast<xmlNodePtr>(pimpl_->doc_), - 0, - static_cast<xmlNodePtr>(const_cast<node&>(child).get_node_data()) - ); -} - - -node::iterator document::insert(const node& n) -{ - if (n.get_type() == node::type_element) - throw xml::exception("xml::document::insert can't take element type nodes"); - - return node::iterator(xml::impl::node_insert(reinterpret_cast<xmlNodePtr>(pimpl_->doc_), 0, static_cast<xmlNodePtr>(const_cast<node&>(n).get_node_data()))); -} - - -node::iterator document::insert(node::iterator position, const node& n) -{ - if (n.get_type() == node::type_element) - throw xml::exception("xml::document::insert can't take element type nodes"); - - return node::iterator(xml::impl::node_insert(reinterpret_cast<xmlNodePtr>(pimpl_->doc_), static_cast<xmlNodePtr>(position.get_raw_node()), static_cast<xmlNodePtr>(const_cast<node&>(n).get_node_data()))); -} - - -node::iterator document::replace(node::iterator old_node, const node& new_node) -{ - if (old_node->get_type() == node::type_element || new_node.get_type() == node::type_element) - { - throw xml::exception("xml::document::replace can't replace element type nodes"); - } - - return node::iterator(xml::impl::node_replace(static_cast<xmlNodePtr>(old_node.get_raw_node()), static_cast<xmlNodePtr>(const_cast<node&>(new_node).get_node_data()))); -} - - -node::iterator document::erase(node::iterator to_erase) -{ - if (to_erase->get_type() == node::type_element) - throw xml::exception("xml::document::erase can't erase element type nodes"); - return node::iterator(xml::impl::node_erase(static_cast<xmlNodePtr>(to_erase.get_raw_node()))); -} - - -n... [truncated message content] |