From: <vac...@us...> - 2008-11-16 02:22:07
|
Revision: 88 http://xmlwrapp.svn.sourceforge.net/xmlwrapp/?rev=88&view=rev Author: vaclavslavik Date: 2008-11-16 01:32:26 +0000 (Sun, 16 Nov 2008) Log Message: ----------- removed text/tree_reader.* files, they were never finished and didn't contain working (or compilable) code Removed Paths: ------------- trunk/include/xmlwrapp/text_reader.h trunk/src/libxml/text_reader.cxx Deleted: trunk/include/xmlwrapp/text_reader.h =================================================================== --- trunk/include/xmlwrapp/text_reader.h 2008-11-16 01:30:21 UTC (rev 87) +++ trunk/include/xmlwrapp/text_reader.h 2008-11-16 01:32:26 UTC (rev 88) @@ -1,179 +0,0 @@ -/* - * Copyright (C) 2005 Thomas M. Browder, Jr. - * <tbr...@us...> - * 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. - */ - -/** @file - * This file contains the definition of the xml::tree_reader class. -**/ - -#ifndef _xmlwrapp_tree_reader_h_ -#define _xmlwrapp_tree_reader_h_ - -// standard includes -#include <cstddef> -#include <string> - -namespace xml { - - // forward declarations - struct tree_impl; - class document; - - /** - * The xml::tree_reader class is used to parse an XML document and generate - * a tree like structure of xml::node objects. After constructing a - * tree_reader, with either a file to parse or some in memory data to parse, - * you can walk the tree using the xml::node interface. - **/ - class tree_reader { - public: - typedef std::size_t size_type; - - //#################################################################### - /** - * xml::tree_reader class constructor. Given the name of a file, this - * constructor will parse that file. - * - * There are two options for dealing with XML parsing errors. The - * default it to throw an exception (std::runtime_error). The other - * option is to pass false for the allow_exceptions flag. This will - * prevent an exception from being thrown, instead, a flag will be set - * that you can test with the operator! member function. - * - * No matter what option you choose, this constructor may still throw - * exceptions for memory failure or other non-parsing related failures. - * - * @param filename The name of the file to parse. - * @param allow_exceptions Whether or not you want an exception for parsing errors. - * @author Peter Jones - **/ - //#################################################################### - tree_reader (const char *filename, bool allow_exceptions=true); - - //#################################################################### - /** - * xml::tree_reader class constructor. Given some data and the size of - * that data, parse that data as XML. To see if the data was parsed - * successfully use operator!. - * - * @param data The XML data to parse. - * @param size The size of the XML data to parse. - * @param allow_exceptions Whether or not you want an exception for parsing errors. - * @author Peter Jones - **/ - //#################################################################### - tree_reader (const char *data, size_type size, bool allow_exceptions=true); - - //#################################################################### - /** - * xml::tree_reader class destructor. - * - * @author Peter Jones - **/ - //#################################################################### - ~tree_reader (void); - - //#################################################################### - /** - * Check to see if a xml::tree_reader class is vaild. That is, check to - * see if parsing XML data was successful and the tree_reader holds a - * good XML node tree. - * - * @return True if the tree_reader is NOT VAILD; false if it is vaild. - * @author Peter Jones - **/ - //#################################################################### - bool operator! (void) const; - - //#################################################################### - /** - * If operator! indicates that there was an error parsing your XML data, - * you can use this member function to get the error message that was - * generated durring parsing. - * - * @return The error message generated durring XML parsing. - * @author Peter Jones - **/ - //#################################################################### - const std::string& get_error_message (void) const; - - //#################################################################### - /** - * Check to see if there were any warnings from the parser while - * processing the given XML data. If there were, you may want to send - * the same document through xmllint or the event_parser to catch and - * review the warning messages. - * - * @return True if there were any warnings. - * @return False if there were no warnings. - * @author Peter Jones - **/ - //#################################################################### - bool had_warnings (void) const; - - //#################################################################### - /** - * Get a reference to the xml::document that was generated during the - * XML parsing. You should make sure to only use a reference to the - * document to avoid a deep copy. - * - * @return A reference to the xml::document. - * @author Peter Jones - **/ - //#################################################################### - xml::document& get_document (void); - - //#################################################################### - /** - * Get a const reference to the xml::document that was generated during - * the XML parsing. You should make sure to only use a reference to the - * document to avoid a deep copy. - * - * @return A const reference to the xml::document. - * @author Peter Jones - **/ - //#################################################################### - const xml::document& get_document (void) const; - private: - tree_impl *pimpl_; // private implementation - - /* - * Don't allow anyone to copy construct a xml::tree_reader or allow the - * assignment operator to be called. It is not very useful to copy a - * parser that has already parsed half a document. - */ - tree_reader (const tree_reader&); - tree_reader& operator= (const tree_reader&); - }; // end xml::tree_reader class - -} // end xml namespace -#endif Deleted: trunk/src/libxml/text_reader.cxx =================================================================== --- trunk/src/libxml/text_reader.cxx 2008-11-16 01:30:21 UTC (rev 87) +++ trunk/src/libxml/text_reader.cxx 2008-11-16 01:32:26 UTC (rev 88) @@ -1,198 +0,0 @@ -/* - * Copyright (C) 2005 Thomas M. Browder, Jr. - * <tbr...@us...> - * 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. - */ - -/** @file - * This file contains the implementation of the xml::tree_reader class for - * the libxml2 XML parser. -**/ - -// xmlwrapp includes -#include "xmlwrapp/tree_reader.h" -#include "xmlwrapp/document.h" -#include "utility.h" - -// libxml includes -#include <libxml/parser.h> -#include <libxml/parserInternals.h> -#include <libxml/SAX.h> -#include <libxml/xmlversion.h> - -// standard includes -#include <stdexcept> -#include <cstring> -#include <string> -#include <memory> - -//#################################################################### -namespace { - const char const_default_error[] = "unknown XML parsing error"; - - extern "C" void cb_tree_error (void *v, const char *message, ...); - extern "C" void cb_tree_warning (void *v, const char *, ...); - extern "C" void cb_tree_ignore (void*, const xmlChar*, int); -} -//#################################################################### -struct xml::tree_impl { - tree_impl (void) : last_error_(const_default_error), warnings_(false), okay_(false) { - std::memset(&sax_, 0, sizeof(sax_)); - initxmlDefaultSAXHandler(&sax_, 0); - - sax_.warning = cb_tree_warning; - sax_.error = cb_tree_error; - sax_.fatalError = cb_tree_error; - - if (xmlKeepBlanksDefaultValue == 0) sax_.ignorableWhitespace = cb_tree_ignore; - } - - document doc_; - xmlSAXHandler sax_; - std::string last_error_; - bool warnings_; - bool okay_; -}; - -//#################################################################### -xml::tree_reader::tree_reader (const char *name, bool allow_exceptions) { - std::auto_ptr<tree_impl> ap(pimpl_ = new tree_impl); - - xmlDocPtr tmpdoc = xmlSAXParseFileWithData(&(pimpl_->sax_), name, 0, pimpl_); - if (allow_exceptions && !tmpdoc) throw std::runtime_error(pimpl_->last_error_); - - if (tmpdoc) { - pimpl_->doc_.set_doc_data(tmpdoc); - pimpl_->okay_ = true; - } - - ap.release(); -} -//#################################################################### -xml::tree_reader::tree_reader (const char *data, size_type size, bool allow_exceptions) { - std::auto_ptr<tree_impl> ap(pimpl_ = new tree_impl); - xmlParserCtxtPtr ctxt; - - if ( (ctxt = xmlCreateMemoryParserCtxt(data, size)) == 0) { - throw std::bad_alloc(); - } - - if (ctxt->sax) xmlFree(ctxt->sax); - ctxt->sax = &(pimpl_->sax_); - - ctxt->_private = pimpl_; - - xmlParseDocument(ctxt); - - if (!ctxt->wellFormed) { - xmlFreeDoc(ctxt->myDoc); - ctxt->myDoc = 0; - ctxt->sax = 0; - xmlFreeParserCtxt(ctxt); - - if (allow_exceptions) throw std::runtime_error(pimpl_->last_error_); - ap.release(); return; // handle non-exception case - } - - pimpl_->doc_.set_doc_data(ctxt->myDoc); - pimpl_->okay_ = true; - ctxt->sax = 0; - - xmlFreeParserCtxt(ctxt); - ap.release(); -} - -//#################################################################### -xml::tree_reader::~tree_reader (void) { - delete pimpl_; -} - -//#################################################################### -bool xml::tree_reader::operator! (void) const { - return !pimpl_->okay_; -} - -//#################################################################### -const std::string& xml::tree_reader::get_error_message (void) const { - return pimpl_->last_error_; -} - -//#################################################################### -bool xml::tree_reader::had_warnings (void) const { - return pimpl_->warnings_; -} - -//#################################################################### -xml::document& xml::tree_reader::get_document (void) { - return pimpl_->doc_; -} - -//#################################################################### -const xml::document& xml::tree_reader::get_document (void) const { - return pimpl_->doc_; -} - -//#################################################################### -namespace { - //#################################################################### - extern "C" void cb_tree_error (void *v, const char *message, ...) { - try { - - xmlParserCtxtPtr ctxt = static_cast<xmlParserCtxtPtr>(v); - xml::tree_impl *p = static_cast<xml::tree_impl*>(ctxt->_private); - if (!p) return; // handle bug in older versions of libxml - - va_list ap; - va_start(ap, message); - xml::printf2string(p->last_error_, message, ap); - va_end(ap); - - xmlStopParser(ctxt); - } catch (...) { } - } - //#################################################################### - extern "C" void cb_tree_warning (void *v, const char *, ...) { - try { - - xmlParserCtxtPtr ctxt = static_cast<xmlParserCtxtPtr>(v); - xml::tree_impl *p = static_cast<xml::tree_impl*>(ctxt->_private); - if (!p) return; // handle bug in older versions of libxml - - p->warnings_ = true; - - } catch (...) { } - } - //#################################################################### - extern "C" void cb_tree_ignore (void*, const xmlChar*, int) { - return; - } - //#################################################################### -} -//#################################################################### This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |