diff --git a/CMakeLists.txt b/CMakeLists.txt index 37a5b9b4..c59c3b4d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -7,13 +7,13 @@ cmake_minimum_required(VERSION 3.5) project(arabica) -# Enable C++11 support -set(CMAKE_CXX_STANDARD 11) +# Enable C++14 support +set(CMAKE_CXX_STANDARD 14) set(LIB_NAME arabica) -set(ARABICA_MAJOR_VERSION 2016) -set(ARABICA_MINOR_VERSION January) +set(ARABICA_MAJOR_VERSION 2020) +set(ARABICA_MINOR_VERSION April) # # Packaging details @@ -196,8 +196,6 @@ set(PUBLIC_HEADER_FILES include/SAX/helpers/InputSourceResolver.hpp include/SAX/helpers/LocatorImpl.hpp include/SAX/helpers/NamespaceSupport.hpp - include/SAX/helpers/ParserAdaptor.hpp - include/SAX/helpers/PropertyNames.hpp include/SAX/helpers/XMLBaseSupport.hpp include/SAX/helpers/XMLFilterImpl.hpp include/SAX/parsers/saxgarden.hpp @@ -582,4 +580,5 @@ if(BUILD_ARABICA_EXAMPLES) endif() include(CPack) - + + diff --git a/configure.ac b/configure.ac index dad81111..1cbbae2a 100644 --- a/configure.ac +++ b/configure.ac @@ -1,4 +1,4 @@ -AC_INIT([Arabica],[2016-January],[jez@jezuk.co.uk]) +AC_INIT([Arabica],[2020-April],[jez@jezuk.co.uk]) AM_INIT_AUTOMAKE([1.9 tar-ustar dist-bzip2 dist-zip subdir-objects]) @@ -8,6 +8,7 @@ AC_PROG_CXX LT_INIT AC_LANG([C++]) +AX_CXX_COMPILE_STDCXX([14]) ARABICA_SELECT_XML_PARSER ARABICA_HAS_EXPAT diff --git a/examples/SAX/wrapper.cpp b/examples/SAX/wrapper.cpp index 628fe172..60272dfb 100644 --- a/examples/SAX/wrapper.cpp +++ b/examples/SAX/wrapper.cpp @@ -5,7 +5,6 @@ #include "SimpleHandler.hpp" #include #include -#include #include #include @@ -20,7 +19,6 @@ int main(int argc, char* argv[]) SimpleHandler myHandler; Arabica::SAX::FeatureNames fNames; - Arabica::SAX::PropertyNames pNames; for(int i = 1; i < argc; ++i) { diff --git a/examples/XSLT/mangle.cpp b/examples/XSLT/mangle.cpp index 9e99abb6..b3e8d6ec 100755 --- a/examples/XSLT/mangle.cpp +++ b/examples/XSLT/mangle.cpp @@ -25,7 +25,7 @@ int main(int argc, const char* argv[]) try { Arabica::SAX::InputSource source(argv[2]); - std::auto_ptr > stylesheet = compiler.compile(source); + std::unique_ptr > stylesheet = compiler.compile(source); if(stylesheet.get() == 0) { std::cerr << "Couldn't compile stylesheet: " << compiler.error() << std::endl; diff --git a/include/DOM/SAX2DOM/SAX2DOM.hpp b/include/DOM/SAX2DOM/SAX2DOM.hpp index 229b79fc..19152c95 100644 --- a/include/DOM/SAX2DOM/SAX2DOM.hpp +++ b/include/DOM/SAX2DOM/SAX2DOM.hpp @@ -13,7 +13,6 @@ #include #include #include -#include #include namespace Arabica @@ -97,8 +96,6 @@ class Parser : protected Arabica::SAX::DefaultHandler pNames; - DOM::DOMImplementation di = Arabica::SimpleDOM::DOMImplementation::getDOMImplementation(); document_ = di.createDocument(string_adaptorT::construct_from_utf8(""), string_adaptorT::construct_from_utf8(""), 0); currentNode_ = document_; diff --git a/include/DOM/io/Stream.hpp b/include/DOM/io/Stream.hpp index 39369f25..ace6cf90 100644 --- a/include/DOM/io/Stream.hpp +++ b/include/DOM/io/Stream.hpp @@ -173,7 +173,7 @@ int prefix_mapper(std::basic_ostream& stream, { //DOM::Node attr = attrs.getNamedItem(*a); const DOM::Node attr = attrNodes[a]; - if(attr.getNodeName().empty() || + if(string_adaptorT::empty(attr.getNodeName()) || isXmlns(attr.getNodeName()) || isXmlns(attr.getPrefix())) continue; diff --git a/include/Makefile.am b/include/Makefile.am index 24cf28f6..bbe5a96b 100644 --- a/include/Makefile.am +++ b/include/Makefile.am @@ -40,10 +40,8 @@ sax_headers = SAX/SAXParseException.hpp \ SAX/helpers/AttributeTypes.hpp \ SAX/helpers/AttributeDefaults.hpp \ SAX/helpers/LocatorImpl.hpp \ - SAX/helpers/ParserAdaptor.hpp \ SAX/helpers/NamespaceSupport.hpp \ SAX/helpers/XMLFilterImpl.hpp \ - SAX/helpers/PropertyNames.hpp \ SAX/helpers/AttributesImpl.hpp \ SAX/helpers/DefaultHandler.hpp \ SAX/helpers/InputSourceResolver.hpp \ diff --git a/include/SAX/ArabicaConfig.hpp.in b/include/SAX/ArabicaConfig.hpp.in index 1934dc60..f7717a86 100644 --- a/include/SAX/ArabicaConfig.hpp.in +++ b/include/SAX/ArabicaConfig.hpp.in @@ -1,12 +1,94 @@ -#ifndef ARABICA_ARABICA_CONFIG_H -#define ARABICA_ARABICA_CONFIG_H - -#cmakedefine ARABICA_NO_WCHAR_T -#cmakedefine ARABICA_VS6_WORKAROUND -#cmakedefine ARABICA_NO_CODECVT_SPECIALISATIONS -#cmakedefine ARABICA_USE_WINSOCK -#cmakedefine ARABICA_WINDOWS -#cmakedefine ARABICA_HAVE_BOOST -#define ARABICA_@ARABICA_XML_BACKEND@ - -#endif // ARABICA_ARABICA_CONFIG_H +/* include/SAX/ArabicaConfig.hpp.in. Generated from configure.ac by autoheader. */ + +/* define if the Boost library is available */ +#undef HAVE_BOOST + +/* Define to 1 if you have the header file. */ +#undef HAVE_DLFCN_H + +/* define to use the Elephant memory leak detector */ +#undef HAVE_ELEPHANT + +/* Define to 1 if you have the header file. */ +#undef HAVE_INTTYPES_H + +/* Define to 1 if you have the header file. */ +#undef HAVE_MEMORY_H + +/* Define to 1 if you have the header file. */ +#undef HAVE_STDINT_H + +/* Define to 1 if you have the header file. */ +#undef HAVE_STDLIB_H + +/* Define to 1 if you have the header file. */ +#undef HAVE_STRINGS_H + +/* Define to 1 if you have the header file. */ +#undef HAVE_STRING_H + +/* Define to 1 if you have the header file. */ +#undef HAVE_SYS_STAT_H + +/* Define to 1 if you have the header file. */ +#undef HAVE_SYS_TYPES_H + +/* Define to 1 if you have the header file. */ +#undef HAVE_UNISTD_H + +/* Define to the sub-directory where libtool stores uninstalled libraries. */ +#undef LT_OBJDIR + +/* defined if we don't need extra codecvt template specialisations */ +#undef NO_CODECVT_SPECIALISATIONS + +/* no mbstate_t */ +#undef NO_MBSTATE_T + +/* no std::mbstate_t */ +#undef NO_STD_MBSTATE_T + +/* disables wchar_t */ +#undef NO_WCHAR_T + +/* Name of package */ +#undef PACKAGE + +/* Define to the address where bug reports for this package should be sent. */ +#undef PACKAGE_BUGREPORT + +/* Define to the full name of this package. */ +#undef PACKAGE_NAME + +/* Define to the full name and version of this package. */ +#undef PACKAGE_STRING + +/* Define to the one symbol short name of this package. */ +#undef PACKAGE_TARNAME + +/* Define to the home page for this package. */ +#undef PACKAGE_URL + +/* Define to the version of this package. */ +#undef PACKAGE_VERSION + +/* Define to 1 if you have the ANSI C header files. */ +#undef STDC_HEADERS + +/* define to build against Expat */ +#define USE_EXPAT + +/* define to build using Garden */ +#undef USE_GARDEN + +/* define to build against LibXML2 */ +#undef USE_LIBXML2 + +/* defined for Windows builds using Winsock rather than BSD-style sockets */ +#undef USE_WINSOCK + +/* define to build against Xerces */ +#undef USE_XERCES + +/* Version number of package */ +#undef VERSION diff --git a/include/SAX/IStreamHandle.hpp b/include/SAX/IStreamHandle.hpp index 11cdbf8d..ede67a35 100644 --- a/include/SAX/IStreamHandle.hpp +++ b/include/SAX/IStreamHandle.hpp @@ -34,12 +34,12 @@ namespace SAX { * * \par * Ownership of a std::istream is passed to an IStreamHandle via a - * std::auto_ptr. Ownership of a + * std::unique_ptr. Ownership of a * std::istream is passed between IStreamHandle by assignment. * - * \see IStreamHandle(std::auto_ptr) for passing + * \see IStreamHandle(std::unique_ptr) for passing * ownership at construction. - * \see IStreamHandle::operator=(std::auto_ptr) for + * \see IStreamHandle::operator=(std::unique_ptr) for * passing ownership after construction. * \see IStreamHandle(std::istream&) for constructing without * passing ownership @@ -89,7 +89,7 @@ namespace SAX { * * \par * If an IStreamHandle is constructed with or assigned a - * std::auto_ptr, it takes ownership of + * std::unique_ptr, it takes ownership of * the pointee. If an IStreamHandle is constructed with or * assigned a std::istream&, it does not take * ownership of the pointee. @@ -117,9 +117,9 @@ namespace SAX { * * \par * All public API methods of IStreamHandle that take an - * auto_ptr parameter conform to the follow post-conditions. + * unique_ptr parameter conform to the follow post-conditions. * For the purposes of these post-conditions, rhs will represent - * the std::auto_ptr parameter. + * the std::unique_ptr parameter. * - is_ contains the value returned by rhs.release(). * - rhs.get() == 0 (ownership has been transfered). * - owner_ = true @@ -169,8 +169,8 @@ public: * other IStreamHandle objects. * */ - explicit IStreamHandle(std::auto_ptr is); - explicit IStreamHandle(std::auto_ptr is); + explicit IStreamHandle(std::unique_ptr is); + explicit IStreamHandle(std::unique_ptr is); /** Construct an IStreamHandle sharing a std::istream with rhs. * @@ -225,8 +225,8 @@ public: * shared with other IStreamHandle objects. * */ - IStreamHandle& operator=(std::auto_ptr rhs); - IStreamHandle& operator=(std::auto_ptr rhs); + IStreamHandle& operator=(std::unique_ptr rhs); + IStreamHandle& operator=(std::unique_ptr rhs); /** Assign a new std::istream to this. This destroys the * std::istream held by this if this owns @@ -296,7 +296,7 @@ IStreamHandle::IStreamHandle(std::istream& is) } inline -IStreamHandle::IStreamHandle(std::auto_ptr is) +IStreamHandle::IStreamHandle(std::unique_ptr is) : is_(is.release()), counter_(new int(0)), owner_(true) @@ -307,7 +307,7 @@ IStreamHandle::IStreamHandle(std::auto_ptr is) } inline -IStreamHandle::IStreamHandle(std::auto_ptr is) +IStreamHandle::IStreamHandle(std::unique_ptr is) : is_(is.release()), counter_(new int(0)), owner_(true) @@ -352,7 +352,7 @@ IStreamHandle& IStreamHandle::operator=(const IStreamHandle& rhs) } inline -IStreamHandle& IStreamHandle::operator=(std::auto_ptr rhs) +IStreamHandle& IStreamHandle::operator=(std::unique_ptr rhs) { removeRef(); set(rhs.release(), true); @@ -365,7 +365,7 @@ IStreamHandle& IStreamHandle::operator=(std::auto_ptr rhs) } inline -IStreamHandle& IStreamHandle::operator=(std::auto_ptr rhs) +IStreamHandle& IStreamHandle::operator=(std::unique_ptr rhs) { removeRef(); set(rhs.release(), true); diff --git a/include/SAX/InputSource.hpp b/include/SAX/InputSource.hpp index 1933cd7e..cccc8790 100644 --- a/include/SAX/InputSource.hpp +++ b/include/SAX/InputSource.hpp @@ -105,7 +105,7 @@ public: * @param byteStream The raw byte stream containing the document. The * InputSource does not assume ownership of * this byteStream. - * @see #InputSource(std::auto_ptr) + * @see #InputSource(std::unique_ptr) * @see #setPublicId * @see #setSystemId * @see #setEncoding @@ -136,15 +136,15 @@ public: * @see #setEncoding * @see #setByteStream */ - InputSource(std::auto_ptr byteStream) : - byteStream_(byteStream), + InputSource(std::unique_ptr&& byteStream) : + byteStream_(std::move(byteStream)), publicId_(), systemId_(), encoding_() { } - InputSource(std::auto_ptr byteStream) : - byteStream_(byteStream), + InputSource(std::unique_ptr&& byteStream) : + byteStream_(std::move(byteStream)), publicId_(), systemId_(), encoding_() @@ -233,7 +233,7 @@ public: * @param byteStream A byte stream containing an XML document or * other entity. The InputSource does not assume * ownership of byteStream. - * @see #setByteStream(std::auto_ptr) To transfer ownership of + * @see #setByteStream(std::unique_ptr) To transfer ownership of * an std::istream to an InputSource * @see #setEncoding * @see #getByteStream @@ -261,7 +261,7 @@ public: * @see #getByteStream * @see #getEncoding */ - void setByteStream(std::auto_ptr byteStream) + void setByteStream(std::unique_ptr byteStream) { byteStream_ = byteStream; } // setByteStream diff --git a/include/SAX/XMLReader.hpp b/include/SAX/XMLReader.hpp index 159d096d..e7376c9d 100644 --- a/include/SAX/XMLReader.hpp +++ b/include/SAX/XMLReader.hpp @@ -336,106 +336,6 @@ public: * @see #setErrorHandler */ virtual void parse(InputSourceT& input) = 0; - - //////////////////////////////////////////////////// - // property implementation -protected: - class PropertyBase - { - public: - virtual ~PropertyBase() { } - }; // PropertyBase - - template - class Property : public PropertyBase - { - public: - Property(propertyTypeT wrappee) : wrappee_(wrappee) { } - - propertyTypeT get() { return wrappee_; } - - private: - propertyTypeT wrappee_; - }; // class Property - -public: - virtual std::auto_ptr doGetProperty(const string_type& name) = 0; - virtual void doSetProperty(const string_type& name, std::auto_ptr value) = 0; - - /** - * Look up the value of a property. - * - *

The property name is any fully-qualified URI. It is - * possible for an XMLReader to recognize a property name but - * to be unable to return its state; this is especially true - * in the case of an adapter for a SAX1 {@link Parser - * Parser}.

- * - *

XMLReaders are not required to recognize any specific - * property names, though an initial core set is documented for - * SAX2.

- * - *

Some property values may be available only in specific - * contexts, such as before, during, or after a parse.

- * - *

Implementors are free (and encouraged) to invent their own properties, - * using names built on their own URIs.

- * - * @param name The property name, which is a fully-qualified URI. - * @return The current value of the property. - * @exception SAXNotRecognizedException When the - * XMLReader does not recognize the property name. - * @exception SAXNotSupportedException When the - * XMLReader recognizes the property name but - * cannot determine its value at this time. - * @see #setProperty - */ - template - propertyTypeT& getProperty(const string_type& name) const - { - std::auto_ptr pb = doGetProperty(name); - Property* prop = dynamic_cast* >(pb.get()); - - if(!prop) - throw SAX::SAXNotSupportedException("Property " + name + " is wrong type."); - - return prop->get(); - } // getProperty - - /** - * Set the value of a property. - * - *

The property name is any fully-qualified URI. It is - * possible for an XMLReader to recognize a property name but - * to be unable to set its value; this is especially true - * in the case of an adapter for a SAX1 {@link Parser - * Parser}.

- * - *

XMLReaders are not required to recognize setting - * any specific property names, though a core set is provided with - * SAX2.

- * - *

Some property values may be immutable or mutable only - * in specific contexts, such as before, during, or after - * a parse.

- * - *

This method is also the standard mechanism for setting - * extended handlers.

- * - * @param name The property name, which is a fully-qualified URI. - * @param value The requested value for the property. - * @exception SAXNotRecognizedException When the - * XMLReader does not recognize the property name. - * @exception SAXNotSupportedException When the - * XMLReader recognizes the property name but - * cannot set the requested value. - */ - template - void setProperty(const string_type& name, propertyTypeT& value) - { - Property* prop = new Property(value); - doSetProperty(name, std::auto_ptr(prop)); - } // setProperty }; // class XMLReaderInterface } // namespace SAX diff --git a/include/SAX/ext/DeclHandler.hpp b/include/SAX/ext/DeclHandler.hpp index 29125a91..6f433de6 100644 --- a/include/SAX/ext/DeclHandler.hpp +++ b/include/SAX/ext/DeclHandler.hpp @@ -31,13 +31,7 @@ namespace SAX * {@link LexicalHandler#endDTD endDTD} events.

* *

To set the DeclHandler for an XML reader, use the - * {@link XMLReader#setProperty setProperty} method - * with the propertyId "http://xml.org/sax/properties/declaration-handler". - * If the reader does not support declaration events, it will throw a - * {@link SAXNotRecognizedException SAXNotRecognizedException} - * or a - * {@link SAXNotSupportedException SAXNotSupportedException} - * when you attempt to register the handler.

+ * {@link XMLReader#setDeclHandler setDeclHandler}.

* * @since 2.0 * @author Jez Higgins, diff --git a/include/SAX/ext/LexicalHandler.hpp b/include/SAX/ext/LexicalHandler.hpp index 3e57576a..a5feb254 100644 --- a/include/SAX/ext/LexicalHandler.hpp +++ b/include/SAX/ext/LexicalHandler.hpp @@ -28,21 +28,13 @@ namespace SAX * endDocument events.

* *

To set the LexicalHandler for an XML reader, use the - * {@link XMLReader#setProperty setProperty} method - * with the propertyId "http://xml.org/sax/properties/lexical-handler". - * If the reader does not support lexical events, it will throw a - * {@link SAXNotRecognizedException SAXNotRecognizedException} - * or a - * {@link SAXNotSupportedException SAXNotSupportedException} - * when you attempt to register the handler.

+ * {@link XMLReader#setLexicalHandler setLexicalHandler} method.

* * @since 2.0 * @author Jez Higgins, * jez@jezuk.co.uk * @version 1.0 - * @see XMLReader#setProperty - * @see SAXNotRecognizedException - * @see SAXNotSupportedException + * @see XMLReader#setLexicalHandler */ template > class LexicalHandler diff --git a/include/SAX/ext/ProgressiveParser.hpp b/include/SAX/ext/ProgressiveParser.hpp index e33dc8e4..884bccad 100644 --- a/include/SAX/ext/ProgressiveParser.hpp +++ b/include/SAX/ext/ProgressiveParser.hpp @@ -3,8 +3,7 @@ #include #include - -// $Id$ +#include namespace Arabica { @@ -27,16 +26,16 @@ namespace SAX class XMLPScanToken { public: - void setParserData(std::auto_ptr& data) + void setParserData(std::unique_ptr&& data) { - data_ = data; + data_.swap(data); } XMLPScanTokenParserImpl* parserImpl() { return data_.get(); } private: - std::auto_ptr data_; + std::unique_ptr data_; }; // XMLPScanToken template diff --git a/include/SAX/filter/Writer.hpp b/include/SAX/filter/Writer.hpp index aab435e8..213f080c 100644 --- a/include/SAX/filter/Writer.hpp +++ b/include/SAX/filter/Writer.hpp @@ -8,7 +8,6 @@ #include #include #include -#include #include #include #include @@ -42,7 +41,6 @@ class Writer : public XMLFilterImpl typedef LexicalHandler LexicalHandlerT; typedef DeclHandler DeclHandlerT; typedef typename XMLReaderT::InputSourceT InputSourceT; - typedef typename XMLReaderT::PropertyBase PropertyBaseT; using XMLFilterT::getParent; public: @@ -167,8 +165,6 @@ class Writer : public XMLFilterImpl ostreamT* stream_; string_type encoding_; enum { startTag, endTag, docTag } lastTag_; - const SAX::PropertyNames properties_; - }; // class Writer template diff --git a/include/SAX/helpers/ParserAdaptor.hpp b/include/SAX/helpers/ParserAdaptor.hpp deleted file mode 100644 index dbb733db..00000000 --- a/include/SAX/helpers/ParserAdaptor.hpp +++ /dev/null @@ -1,548 +0,0 @@ -#ifndef ARABICA_PARSER_ADAPTOR_H -#define ARABICA_PARSER_ADAPTOR_H - -// ParserAdaptor -// Adapts a SAX1 Parser to a SAX2 XMLReader. -// $Id$ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -namespace Arabica -{ -namespace SAX -{ - -/** - * Adapt a SAX1 Parser as a SAX2 XMLReader. - * - *

This class wraps a SAX1 {@link Parser Parser} - * and makes it act as a SAX2 {@link XMLReader XMLReader}, - * with feature, property, and Namespace support. Note - * that it is not possible to report {@link ContentHandler#skippedEntity - * skippedEntity} events, since SAX1 does not make that information available.

- * - *

This adapter does not test for duplicate Namespace-qualified - * attribute names.

- * - * @since SAX 2.0 - * @author Jez Higgins, - * jez@jezuk.co.uk - * @version 2.0 - * @see XMLReader - * @see Parser - */ -template -class ParserAdaptor : public XMLReaderInterface, - public DocumentHandler -{ -public: - typedef Parser ParserT; - typedef EntityResolver EntityResolverT; - typedef DTDHandler DTDHandlerT; - typedef DocumentHandler DocumentHandlerT; - typedef ContentHandler ContentHandlerT; - typedef InputSource InputSourceT; - typedef Locator LocatorT; - typedef SAXParseException SAXParseExceptionT; - typedef AttributeList AttributeListT; - - ParserAdaptor(ParserT& parser) : - parser_(parser), - parsing_(false), - locator_(0), - namespaces_(true), - prefixes_(false), - entityResolver_(0), - dtdHandler_(0), - contentHandler_(0), - errorHandler_(0) - { - } // ParserAdaptor - - //////////////////////////////// - // implement XMLReader - /** - * Set a feature for the parser. - * - *

The only features supported are namespaces and - * namespace-prefixes.

- * - * @param name The feature name, as a complete URI. - * @param value The requested feature value. - * @exception SAXNotRecognizedException If the feature - * name is not known. - * @exception SAXNotSupportedException If the feature - * state is not supported. - * @see XMLReader#setFeature - */ - virtual void setFeature(const string_type& name, bool value) - { - if(name == NAMESPACES) - { - checkNotParsing("feature", name); - namespaces_ = value; - if(!namespaces_ && !prefixes_) - prefixes_ = true; - } - else if(name == NAMESPACE_PREFIXES) - { - checkNotParsing("feature", name); - prefixes_ = value; - if(!prefixes_ && !namespaces_) - namespaces_ = true; - } - else if(name == VALIDATION || - name == EXTERNAL_GENERAL || - name == EXTERNAL_PARAMETER) - { - throw SAXNotSupportedException("Feature not supported " + makeString(name)); - } - else - { - throw SAXNotRecognizedException("Feature not recognized " + makeString(name)); - } - } // setFeature - - /** - * Check a parser feature. - * - *

The only features supported are namespaces and - * namespace-prefixes.

- * - * @param name The feature name, as a complete URI. - * @return The current feature state. - * @exception SAXNotRecognizedException If the feature - * name is not known. - * @exception SAXNotSupportedException If querying the - * feature state is not supported. - * @see XMLReader#setFeature - */ - virtual bool getFeature(const string_type& name) const - { - if(name == NAMESPACES) - { - return namespaces_; - } - else if(name == NAMESPACE_PREFIXES) - { - return prefixes_; - } - else if(name == VALIDATION || - name == EXTERNAL_GENERAL || - name == EXTERNAL_PARAMETER) - { - throw SAXNotSupportedException("Feature not supported " + makeString(name)); - } - else - { - throw SAXNotRecognizedException("Feature not recognized " + makeString(name)); - } - } // getFeature - -protected: - virtual std::auto_ptr doGetProperty(const string_type& name) - { - throw SAXNotRecognizedException("Property not recognized " + makeString(name)); - } // doGetProperty - - virtual void doSetProperty(const string_type& name, std::auto_ptr value) - { - throw SAXNotRecognizedException("Property not recognized " + makeString(name)); - } // doSetProperty - -public: - /** - * Set the entity resolver. - * - * @param resolver The new entity resolver. - * @see XMLReader#setEntityResolver - */ - virtual void setEntityResolver(EntityResolverT& resolver) { entityResolver_ = &resolver; } - /** - * Return the current entity resolver. - * - * @return The current entity resolver, or null if none was supplied. - * @see XMLReader#getEntityResolver - */ - virtual EntityResolverT* getEntityResolver() const { return entityResolver_; } - - /** - * Set the DTD handler. - * - * @param handler The new DTD handler. - * @see XMLReader#setEntityResolver - */ - virtual void setDTDHandler(DTDHandlerT& handler) { dtdHandler_ = &handler; } - /** - * Return the current DTD handler. - * - * @return The current DTD handler, or null if none was supplied. - * @see XMLReader#getEntityResolver - */ - virtual DTDHandlerT* getDTDHandler() const { return dtdHandler_; } - - /** - * Set the content handler. - * - * @param handler The new content handler. - * @see XMLReader#setEntityResolver - */ - virtual void setContentHandler(ContentHandlerT& handler) { contentHandler_ = &handler; } - /** - * Return the current content handler. - * - * @return The current content handler, or null if none was supplied. - * @see XMLReader#getEntityResolver - */ - virtual ContentHandlerT* getContentHandler() const { return contentHandler_; } - - /** - * Set the error handler. - * - * @param handler The new error handler. - * @see XMLReader#setEntityResolver - */ - virtual void setErrorHandler(ErrorHandler& handler) { errorHandler_ = &handler; } - /** - * Return the current error handler. - * - * @return The current error handler, or null if none was supplied. - * @see XMLReader#getEntityResolver - */ - virtual ErrorHandler* getErrorHandler() const { return errorHandler_; } - - /** - * Parse an XML document. - * - * @param input An input source for the document. - * @see Parser#parse(InputSource&) - */ - virtual void parse(InputSourceT& input) - { - if(parsing_) - throw SAXException("Parser is already in use."); - setupParser(); - parsing_ = true; - try - { - parser_.parse(input); - } - catch(...) - { - parsing_ = false; - throw; - } - parsing_ = false; - } // parse - - ///////////////////////////////////// - // DocumentHandler implementation - /** - * Adapt a SAX1 document locator event. - * - * @param locator A document locator. - * @see ContentHandler#setDocumentLocator - */ - virtual void setDocumentLocator(const LocatorT& locator) - { - locator_ = &locator; - if(contentHandler_) - contentHandler_->setDocumentLocator(locator); - } // setDocumentLocator - - /** - * Adapt a SAX1 start document event. - * - * @see DocumentHandler#startDocument - */ - virtual void startDocument() - { - if(contentHandler_) - contentHandler_->startDocument(); - } // startDocument - - /** - * Adapt a SAX1 end document event. - * - * @see DocumentHandler#endDocument - */ - virtual void endDocument() - { - if(contentHandler_) - contentHandler_->endDocument(); - } // endDocument - - /** - * Adapt a SAX1 startElement event. - * - *

If necessary, perform Namespace processing.

- * - * @param qName The qualified (prefixed) name. - * @param qAtts The XML 1.0 attribute list (with qnames). - */ - virtual void startElement(const string_type& qName, - const AttributeListT& qAtts) - { - if(!namespaces_) - { - if(contentHandler_) - { - attAdaptor_.setAttributeList(qAtts); - contentHandler_->startElement(NULL_STRING, NULL_STRING, qName, attAdaptor_); - } // if(contentHandler_) - return; - } // if(!namespaces) - - // OK we're doing Namespaces - nsSupport_.pushContext(); - bool seenDecl = false; - atts_.clear(); - - // take a first pass and copy all the attributes, noting any declarations - int length = qAtts.getLength(); - for(int i = 0; i < length; ++i) - { - string_type attQName = qAtts.getName(i); - string_type type = qAtts.getType(i); - string_type value = qAtts.getValue(i); - - // declaration? - if(attQName.find(NamespaceSupportT::XMLNS) == 0) - { - string_type prefix; - int n = attQName.find(NamespaceSupportT::COLON); - if(n != string_type::npos()) - prefix = string_type(attQName.begin() + n + 1, attQName.end()); - if(!nsSupport_.declarePrefix(prefix, value)) - reportError("Illegal Namespace prefix " + makeString(prefix)); - if(contentHandler_) - contentHandler_->startPrefixMapping(prefix, value); - if(prefixes_) - atts_.addAttribute(NULL_STRING, NULL_STRING, attQName, type, value); - seenDecl = true; - } - else - { - NamespaceSupportT::Parts attName = processName(attQName, true); - atts_.addAttribute(attName.URI, attName.localName, attName.rawName, type, value); - } - } // for ... - - // if there was a Namespace decl we have to go around again - if(seenDecl) - { - int length = atts_.getLength(); - for(int i = 0; i < length; ++i) - { - string_type attQName = atts_.getQName(i); - if(attQName.find(NamespaceSupportT::XMLNS)) - { - NamespaceSupportT::Parts attName = processName(attQName, true); - atts_.setURI(i, attName.URI); - atts_.setLocalName(i, attName.localName); - } // if ... - } // for ... - } // if(seenDecl) - - // at last! report the event - if(contentHandler_) - { - NamespaceSupportT::Parts name = processName(qName, false); - contentHandler_->startElement(name.URI, name.localName, name.rawName, atts_); - } // if(contentHandler_) - } // startElement - - - /** - * Adapt a SAX1 end element event. - * - * @param qName The qualified (prefixed) name. - * @see DocumentHandler#endElement - */ - void endElement(const string_type& qName) - { - if(!namespaces_) - { - if(contentHandler_) - contentHandler_->endElement(NULL_STRING, NULL_STRING, qName); - return; - } // if(!namespaces_) - - NamespaceSupportT::Parts name = processName(qName, false); - if(contentHandler_) - { - contentHandler_->endElement(name.URI, name.localName, name.rawName); - NamespaceSupportT::stringListT prefixes = nsSupport_.getDeclaredPrefixes(); - for(int i = 0, end = prefixes.size(); i != end; ++i) - contentHandler_->endPrefixMapping(prefixes[i]); - } // if(contentHandler_) - nsSupport_.popContext(); - } // endElement - - /** - * Adapt a SAX1 characters event. - * - * @param ch The characters. - * @see DocumentHandler#characters - */ - virtual void characters(const string_type& ch) - { - if(contentHandler_) - contentHandler_->characters(ch); - } // characters - - /** - * Adapt a SAX1 ignorable whitespace event. - * - * @param ch Thecharacters. - * @see DocumentHandler#ignorableWhitespace - */ - virtual void ignorableWhitespace(const string_type& ch) - { - if(contentHandler_) - contentHandler_->ignorableWhitespace(ch); - } // ignorableWhitespace - - /** - * Adapt a SAX1 processing instruction event. - * - * @param target The processing instruction target. - * @param data The remainder of the processing instruction - * @see DocumentHandler#processingInstruction - */ - virtual void processingInstruction(const string_type& target, const string_type& data) - { - if(contentHandler_) - contentHandler_->processingInstruction(target, data); - } // processingInstruction - -private: - typedef NamespaceSupport NamespaceSupportT; - typedef AttributesImpl AttributesImplT; - - void setupParser() - { - nsSupport_.reset(); - - if(entityResolver_) - parser_.setEntityResolver(*entityResolver_); - if(dtdHandler_) - parser_.setDTDHandler(*dtdHandler_); - if(errorHandler_) - parser_.setErrorHandler(*errorHandler_); - parser_.setDocumentHandler(*this); - locator_ = 0; - } // setupParser - - NamespaceSupportT::Parts processName(const string_type& qName, bool isAttribute) - { - NamespaceSupportT::Parts p = nsSupport_.processName(qName, isAttribute); - if(p.URI == NULL_STRING && p.prefix != NULL_STRING) - reportError("Undeclared prefix " + makeString(qName)); - return p; - } // processName - - void reportError(const std::string& message) - { - if(errorHandler_ == 0) - return; - - if(locator_) - errorHandler_->error(SAXParseExceptionT(message, *locator_)); - else - errorHandler_->error(SAXParseExceptionT(message, NULL_STRING, NULL_STRING, -1, -1)); - } // reportError - - void checkNotParsing(const std::string& type, const string_type& name) - { - if(parsing_) - throw SAXNotSupportedException("Can't change feature while parsing"); - } // checkNotParsing - - std::string makeString(const string_type& str) const - { - return string_adaptor::asStdString(str); - } // makeString - - // This wrapper is used only when Namespace support is disabled. - class AttributesListAdaptor : public Attributes - { - public: - typedef typename ParserAdaptor ParserAdaptorT; - typedef typename AttributeList AttributeListT; - - void setAttributeList(const AttributeListT& attList) - { - attList_ = &attList; - } // setAttributeList - - virtual int getLength() const { return attList_->getLength(); } - virtual string_type getURI(int) const { return string_type(); } - virtual string_type getLocalName(int) const { return string_type(); } - virtual string_type getQName(int i) const { return attList_->getName(i); } - virtual string_type getType(int i) const { return attList_->getType(i); } - virtual string_type getValue(int i) const { return attList_->getValue(i); } - - virtual int getIndex(const string_type&, const string_type&) const { return -1; } - virtual int getIndex(const string_type& qName) const - { - int max = attList_->getLength(); - for(int i = 0; i < max; ++i) - if(attList_->getName(i) == qName) - return i; - return -1; - } // getIndex - virtual string_type getType(const string_type&, const string_type&) const { return string_type(); } - virtual string_type getType(const string_type& qName) const { return attList_->getType(qName); } - virtual string_type getValue(const string_type&, const string_type&) const { return string_type(); } - virtual string_type getValue(const string_type& qName) const { return attList_->getValue(qName); } - - private: - static string_type empty_; - const AttributeListT* attList_; - }; // AttributesListAdaptor - - // member variables - NamespaceSupportT nsSupport_; - AttributesListAdaptor attAdaptor_; - - bool parsing_; - // strings? - ParserT& parser_; - AttributesImplT atts_; - - // features - bool namespaces_; - bool prefixes_; - - // handlers - const LocatorT* locator_; - EntityResolverT* entityResolver_; - DTDHandlerT* dtdHandler_; - ContentHandlerT* contentHandler_; - ErrorHandler* errorHandler_; - -public: - const string_type NULL_STRING; - -private: - ParserAdaptor(); - ParserAdaptor(const ParserAdaptor&); - ParserAdaptor& operator=(const ParserAdaptor&); - bool operator==(const ParserAdaptor&); -}; // ParserAdaptor - -} // namespace SAX -} // namespace Arabica - -#endif diff --git a/include/SAX/helpers/PropertyNames.hpp b/include/SAX/helpers/PropertyNames.hpp deleted file mode 100644 index 2d1f0d9a..00000000 --- a/include/SAX/helpers/PropertyNames.hpp +++ /dev/null @@ -1,53 +0,0 @@ -#ifndef ARABICA_PROPERTY_NAMES_H -#define ARABICA_PROPERTY_NAMES_H -/* - * $Id$ - */ - -#include -#include -#include - -namespace Arabica -{ -namespace SAX -{ - -/** The core SAX 2 parser properties. */ -template > -struct PropertyNames -{ - /** @name SAX 2 Properties - * @{ */ - /** Register a lexical handler. - * - * The Lexical Handler is used to see some syntax events that are essential - * in some applications: comments, CDATA delimiters, selected general - * entity inclusions, and the start and end of the DTD (and declaration of - * document element name). - * - * The value assigned must implement SAX::LexicalHandler. - */ - const string_type lexicalHandler; - /** Register a Declaration Handler. - * - * Used to see most DTD declarations except those treated as lexical - * ("document element name is ...") or which are mandatory for all SAX - * parsers (DTDHandler). - * - * The value assigned must implement SAX::DeclHandler */ - const string_type declHandler; - /** @} */ - - PropertyNames() : - lexicalHandler(string_adaptor_type::construct_from_utf8("http://xml.org/sax/handlers/LexicalHandler")), - declHandler(string_adaptor_type::construct_from_utf8("http://xml.org/sax/handlers/DeclHandler")) - { - } // PropertyNames -}; // struct PropertyNames - -} // namespace SAX -} // namespace Arabica - -#endif -// end of file diff --git a/include/SAX/helpers/XMLFilterImpl.hpp b/include/SAX/helpers/XMLFilterImpl.hpp index 98abec27..b605b122 100644 --- a/include/SAX/helpers/XMLFilterImpl.hpp +++ b/include/SAX/helpers/XMLFilterImpl.hpp @@ -223,29 +223,6 @@ public: parent_->parse(input); } // parse - virtual std::auto_ptr doGetProperty(const string_type& name) - { - if(parent_) - return parent_->doGetProperty(name); - - string_type ex = string_adaptor::construct_from_utf8("Property: "); - string_adaptor::append(ex, name); - throw SAXNotRecognizedException(string_adaptor::asStdString(ex)); - } // doGetProperty - - virtual void doSetProperty(const string_type& name, typename std::auto_ptr value) - { - if(parent_) - { - parent_->doSetProperty(name, value); - return; - } // if(parent_) - - string_type ex = string_adaptor::construct_from_utf8("Property: "); - string_adaptor::append(ex, name); - throw SAXNotRecognizedException(string_adaptor::asStdString(ex)); - } // doSetProperty - public: ////////////////////////////////////////////////// // EntityResolver diff --git a/include/SAX/parsers/saxgarden.hpp b/include/SAX/parsers/saxgarden.hpp index 3708bb42..ae1b5197 100644 --- a/include/SAX/parsers/saxgarden.hpp +++ b/include/SAX/parsers/saxgarden.hpp @@ -48,7 +48,6 @@ public: typedef ErrorHandler ErrorHandlerT; typedef DeclHandler declHandlerT; typedef LexicalHandler lexicalHandlerT; - typedef typename XMLReaderT::PropertyBase PropertyBaseT; Garden(); @@ -70,9 +69,6 @@ public: virtual void parse(InputSourceT& input); - virtual std::auto_ptr doGetProperty(const string_type& name); - virtual void doSetProperty(const string_type& name, std::auto_ptr value); - private: void reportError(const std::string& message, bool fatal = false); @@ -256,20 +252,6 @@ void Garden::setFeature(const string_type& name, bool value throw SAXNotRecognizedException(string_adaptor::asStdString(name)); } // setFeature -/////////////////////////////////////// -// properties -template -std::auto_ptr::PropertyBaseT> Garden::doGetProperty(const string_type& name) -{ - throw SAXNotRecognizedException(string_adaptor::asStdString(name)); -} // doGetProperty - -template -void Garden::doSetProperty(const string_type& name, std::auto_ptr value) -{ - throw SAXNotRecognizedException(string_adaptor::asStdString(name)); -} // doSetProperty - ////////////////////////////////////////// // parse template diff --git a/include/SAX/wrappers/XercesPropertyNames.hpp b/include/SAX/wrappers/XercesPropertyNames.hpp index 1e9b864a..96a82b39 100644 --- a/include/SAX/wrappers/XercesPropertyNames.hpp +++ b/include/SAX/wrappers/XercesPropertyNames.hpp @@ -5,7 +5,6 @@ */ #include -#include namespace Arabica { @@ -13,8 +12,7 @@ namespace SAX { template > - struct XercesPropertyNames : public PropertyNames + struct XercesPropertyNames { /** \name Xerces properties. * @{ */ diff --git a/include/SAX/wrappers/saxexpat.hpp b/include/SAX/wrappers/saxexpat.hpp index ea8a4cd2..a7955500 100644 --- a/include/SAX/wrappers/saxexpat.hpp +++ b/include/SAX/wrappers/saxexpat.hpp @@ -19,7 +19,6 @@ #include #include #include -#include #include #include #include @@ -226,11 +225,6 @@ class expat_wrapper : typedef SAX::NamespaceSupport namespaceSupportT; typedef SAX::ErrorHandler errorHandlerT; typedef SAX::SAXParseException SAXParseExceptionT; - typedef typename XMLReaderT::PropertyBase PropertyBaseT; - typedef typename XMLReaderT::template Property getLexicalHandlerT; - typedef typename XMLReaderT::template Property setLexicalHandlerT; - typedef typename XMLReaderT::template Property getDeclHandlerT; - typedef typename XMLReaderT::template Property setDeclHandlerT; typedef XML::QualifiedName qualifiedNameT; expat_wrapper(); @@ -270,11 +264,6 @@ class expat_wrapper : virtual size_t getLineNumber() const; virtual size_t getColumnNumber() const; - /////////////////////////////////////////////////// - // properties - protected: - virtual std::auto_ptr doGetProperty(const string_type& name); - virtual void doSetProperty(const string_type& name, std::auto_ptr value); private: qualifiedNameT processName(const string_type& qName, bool isAttribute); void reportError(const std::string& message, bool fatal = false); @@ -347,7 +336,6 @@ class expat_wrapper : string_type emptyString_; const SAX::FeatureNames features_; - const SAX::PropertyNames properties_; const SAX::NamespaceConstants nsc_; const SAX::AttributeDefaults attrDefaults_; @@ -520,52 +508,6 @@ bool expat_wrapper::do_parse(inputSourceT& source, XML_Pars return true; } // do_parse -template -std::auto_ptr::PropertyBaseT> expat_wrapper::doGetProperty(const string_type& name) -{ - if(name == properties_.lexicalHandler) - { - getLexicalHandlerT* prop = new getLexicalHandlerT(lexicalHandler_); - return std::auto_ptr(prop); - } - if(name == properties_.declHandler) - { - getDeclHandlerT* prop = new getDeclHandlerT(declHandler_); - return std::auto_ptr(prop); - } - - throw SAX::SAXNotRecognizedException(std::string("Property not recognized ") + SA::asStdString(name)); -} // doGetProperty - -template -void expat_wrapper::doSetProperty(const string_type& name, std::auto_ptr value) -{ - if(name == properties_.lexicalHandler) - { - setLexicalHandlerT* prop = dynamic_cast(value.get()); - - if(!prop) - throw std::bad_cast(); - - lexicalHandler_ = &(prop->get()); - } - else if(name == properties_.declHandler) - { - setDeclHandlerT* prop = dynamic_cast(value.get()); - - if(!prop) - throw std::bad_cast(); - - declHandler_ = &(prop->get()); - } - else - { - std::ostringstream os; - os << "Property not recognized " << SA::asStdString(name); - throw SAX::SAXNotRecognizedException(os.str()); - } -} // doSetProperty - // Locator implementation template string_type expat_wrapper::getPublicId() const diff --git a/include/SAX/wrappers/saxlibxml2.hpp b/include/SAX/wrappers/saxlibxml2.hpp index 76072d83..b693b52e 100644 --- a/include/SAX/wrappers/saxlibxml2.hpp +++ b/include/SAX/wrappers/saxlibxml2.hpp @@ -17,7 +17,6 @@ #include #include -#include #include #include #include @@ -145,11 +144,6 @@ class libxml2_wrapper : typedef SAX::NamespaceSupport namespaceSupportT; typedef SAX::ErrorHandler errorHandlerT; typedef SAX::SAXParseException SAXParseExceptionT; - typedef typename XMLReaderT::PropertyBase PropertyBaseT; - typedef typename XMLReaderT::template Property getLexicalHandlerT; - typedef typename XMLReaderT::template Property setLexicalHandlerT; - typedef typename XMLReaderT::template Property getDeclHandlerT; - typedef typename XMLReaderT::template Property setDeclHandlerT; typedef XML::QualifiedName qualifiedNameT; libxml2_wrapper(); @@ -179,12 +173,6 @@ class libxml2_wrapper : // parsing virtual void parse(inputSourceT& source); - protected: - //////////////////////////////////////////////// - // properties - virtual std::auto_ptr doGetProperty(const string_type& name); - virtual void doSetProperty(const string_type& name, std::auto_ptr value); - public: virtual string_type getPublicId() const; virtual string_type getSystemId() const; @@ -245,7 +233,6 @@ class libxml2_wrapper : string_type emptyString_; const FeatureNames features_; - const PropertyNames properties_; const NamespaceConstants nsc_; const AttributeDefaults attrDefaults_; const AttributeTypes attrTypes_; @@ -354,48 +341,6 @@ void libxml2_wrapper::setFeature(const string_type& name, b } } // setFeature -template -std::auto_ptr::PropertyBaseT> libxml2_wrapper::doGetProperty(const string_type& name) -{ - if(name == properties_.declHandler) - { - getDeclHandlerT* prop = new getDeclHandlerT(declHandler_); - return std::auto_ptr(prop); - } - if(name == properties_.lexicalHandler) - { - getLexicalHandlerT* prop = new getLexicalHandlerT(lexicalHandler_); - return std::auto_ptr(prop); - } - - throw SAX::SAXNotRecognizedException(std::string("Property not recognized ") + string_adaptor::asStdString(name)); -} // doGetProperty - -template -void libxml2_wrapper::doSetProperty(const string_type& name, std::auto_ptr value) -{ - if(name == properties_.declHandler) - { - setDeclHandlerT* prop = dynamic_cast(value.get()); - - if(!prop) - throw std::bad_cast(); - - declHandler_ = &(prop->get()); - } - if(name == properties_.lexicalHandler) - { - setLexicalHandlerT* prop = dynamic_cast(value.get()); - - if(!prop) - throw std::bad_cast(); - - lexicalHandler_ = &(prop->get()); - } - - throw SAX::SAXNotRecognizedException(std::string("Property not recognized ") + string_adaptor::asStdString(name)); -} // doSetProperty - template typename XML::QualifiedName::string_adaptor> libxml2_wrapper::processName(const string_type& qName, bool isAttribute) { diff --git a/include/SAX/wrappers/saxmsxml2.hpp b/include/SAX/wrappers/saxmsxml2.hpp index d3766058..37719106 100644 --- a/include/SAX/wrappers/saxmsxml2.hpp +++ b/include/SAX/wrappers/saxmsxml2.hpp @@ -10,7 +10,6 @@ #include #include #include -#include #include #include #include @@ -118,48 +117,7 @@ class msxml2_wrapper : // Parsing virtual void parse(inputSourceT& input); - protected: - virtual std::auto_ptr doGetProperty(const string_type& name) - { - if(name == properties_.lexicalHandler) - { - Property* prop = new Property(lexicalHandler_.getLexicalHandler()); - return std::auto_ptr(prop); - } - if(name == properties_.declHandler) - { - Property* prop = new Property(declHandler_.getDeclHandler()); - return std::auto_ptr(prop); - } - throw SAX::SAXNotRecognizedException("Property not recognized "); - } // doGetProperty - - virtual void doSetProperty(const string_type& name, std::auto_ptr value) - { - if(name == properties_.lexicalHandler) - { - Property* prop = dynamic_cast*>(value.get()); - - if(!prop) - throw std::runtime_error("bad_cast: Property LexicalHandler is wrong type, should be SAX::LexicalHandler&"); - - lexicalHandler_.setLexicalHandler(prop->get()); - return; - } // if ... - if(name == properties_.declHandler) - { - Property* prop = dynamic_cast*>(value.get()); - - if(!prop) - throw std::runtime_error("bad_cast: Property DeclHandler is wrong type, should be SAX::DeclHandler&"); - - declHandler_.setDeclHandler(prop->get()); - return; - } // if ... - throw SAX::SAXNotRecognizedException("Property not recognized "); - } // doSetProperty - - private: + private: ////////////////////////////////////////////////////// // COM interface -> C++ interface adaptors class LocatorAdaptor : public locatorT @@ -995,7 +953,6 @@ class msxml2_wrapper : DeclHandlerAdaptor declHandler_; ISAXXMLReaderPtr reader_; - SAX::PropertyNames properties_; }; // class msxml template @@ -1006,8 +963,7 @@ msxml2_wrapper::msxml2_wrapper() : contentHandler_(errorHandler_), lexicalHandler_(), declHandler_(), - reader_(), - properties_() + reader_() { reader_.CreateInstance("Msxml2.SAXXMLReader.6.0"); if(reader_.GetInterfacePtr() == 0) diff --git a/include/SAX/wrappers/saxxerces.hpp b/include/SAX/wrappers/saxxerces.hpp index 4d583cb3..9ca6061e 100644 --- a/include/SAX/wrappers/saxxerces.hpp +++ b/include/SAX/wrappers/saxxerces.hpp @@ -4,35 +4,6 @@ // A SAX2 wrapper class for Xerces. //--------------------------------------------------------------------------- -// Debugging code for the doSetProperty and doGetProperty methods. -// Since these methods use runtime casting, it is often helpful to -// know the exact type of a method's arguments to compare with -// what is expected. This is hard, even with current (2003) -// debuggers, so this code can print it out, assuming you've -// compiled with gcc 3.2 -// -// Example usage is given in doSetProperty - -// Use only with GCC 3.2 -#ifdef SAXXERCES_DEBUG - -#include -#include -#include - -// Demangle Run-Time Type Information std::type_info struct. -std::ostream& operator<<(std::ostream& o, const std::type_info& ti) -{ - int status; - char *realname = abi::__cxa_demangle(ti.name(), 0, 0, &status); - if (status != 0) - o.setstate(std::ios_base::failbit); - o << realname; - free(realname); - return o; -} -#endif - #include #include #include @@ -189,10 +160,6 @@ class xerces_wrapper : public ProgressiveParser doGetProperty(const string_type& name); - virtual void doSetProperty(const string_type& name, std::auto_ptr value); - private: /////////////////////////////// // String adaptor for XMLCh @@ -282,7 +249,7 @@ class xerces_wrapper : public ProgressiveParser(bytes), length); } // construct_from_XMLByte - static std::auto_ptr transcoder_; + static std::unique_ptr transcoder_; static void kickoff() { XERCES_CPP_NAMESPACE::XMLTransService::Codes res; @@ -841,7 +808,7 @@ class xerces_wrapper : public ProgressiveParser initializer_; + std::unique_ptr initializer_; XERCES_CPP_NAMESPACE::SAX2XMLReader* xerces_; ContentHandlerAdaptor contentHandlerAdaptor_; EntityResolverAdaptor entityResolverAdaptor_; @@ -858,7 +825,7 @@ class xerces_wrapper : public ProgressiveParser -std::auto_ptr xerces_wrapper::xerces_string_adaptor::transcoder_; +std::unique_ptr xerces_wrapper::xerces_string_adaptor::transcoder_; #endif template @@ -866,8 +833,7 @@ xerces_wrapper::xerces_wrapper() { try { - std::auto_ptr init(new XercesImpl::xerces_initializer()); - initializer_ = init; + initializer_.reset(new XercesImpl::xerces_initializer()); #ifdef ARABICA_NO_WCHAR_T xerces_string_adaptor::kickoff(); #endif @@ -933,143 +899,6 @@ void xerces_wrapper::setFeature(const string_type& name, bo } // catch(SAXNotRecognizedException& e) } // setFeature -template -std::auto_ptr::XMLReaderT::PropertyBase> xerces_wrapper::doGetProperty(const string_type& name) -{ - if(name == properties_.lexicalHandler) - { - typedef typename XMLReaderT::template Property Prop; - Prop *prop = new Prop(lexicalHandlerAdaptor_.getLexicalHandler()); - return std::auto_ptr(prop); - } - if(name == properties_.declHandler) - { - typedef typename XMLReaderT::template Property Prop; - Prop* prop = new Prop(declHandlerAdaptor_.getDeclHandler()); - return std::auto_ptr(prop); - } - if (name == properties_.externalSchemaLocation) - { - typedef typename XMLReaderT::template Property StringPropertyType; - - XMLCh* xercesExternalSchemaLocation = - static_cast(xerces_->getProperty( - XERCES_CPP_NAMESPACE::XMLUni::fgXercesSchemaExternalSchemaLocation)); - - externalSchemaLocation_ = XSA::makeStringT(xercesExternalSchemaLocation); - std::auto_ptr toReturn(new StringPropertyType(externalSchemaLocation_)); -#ifdef SAXXERCES_DEBUG - std::cerr << "Returning " << typeid(toReturn) - << "(*(" << typeid(*toReturn.get()) << ")" - << toReturn.get() << ")" - << " containing value [" << externalSchemaLocation_ << "]" - << std::endl; -#endif - return toReturn; - } - if (name == properties_.externalNoNamespaceSchemaLocation) - { - typedef typename XMLReaderT::template Property StringPropertyType; - - XMLCh* xercesExternalNoNamespaceSchemaLocation = - static_cast(xerces_->getProperty( - XERCES_CPP_NAMESPACE::XMLUni::fgXercesSchemaExternalNoNameSpaceSchemaLocation)); - - externalNoNamespaceSchemaLocation_ = XSA::makeStringT(xercesExternalNoNamespaceSchemaLocation); - return std::auto_ptr(new StringPropertyType(externalNoNamespaceSchemaLocation_)); - } - throw SAX::SAXNotRecognizedException("Property not recognized "); -} // doGetProperty - -template -void xerces_wrapper::doSetProperty(const string_type& name, std::auto_ptr value) -{ - if(name == properties_.lexicalHandler) - { - typedef typename XMLReaderT::template Property Prop; - Prop* prop = dynamic_cast(value.get()); - - if(!prop) - throw std::runtime_error("bad_cast: Property LexicalHandler is wrong type, should be SAX::LexicalHandler&"); - - lexicalHandlerAdaptor_.setLexicalHandler(prop->get()); - return; - } // if ... - - if(name == properties_.declHandler) - { - typedef typename XMLReaderT::template Property Prop; - Prop* prop = dynamic_cast(value.get()); - - if(!prop) - throw std::runtime_error("bad_cast: Property DeclHandler is wrong type, should be SAX::DeclHandler&"); - - declHandlerAdaptor_.setDeclHandler(prop->get()); - return; - } // if ... - - if (name == properties_.externalSchemaLocation) - { - typename XMLReaderT::PropertyBase* propBase = value.get(); -#ifdef SAXXERCES_DEBUG - std::cerr << "doSetProperty(externalSchemaLocation, &(" - << typeid(*propBase) << "))" << std::endl; -#endif - typedef typename XMLReaderT::template Property propertyType; - propertyType* prop = dynamic_cast(propBase); -#ifdef SAXXERCES_DEBUG - std::cerr << " Extracted property to " << typeid(prop) - << "(" << prop << ")" << std::endl; -#endif - if (prop) - { - externalSchemaLocation_ = prop->get(); -#ifdef SAXXERCES_DEBUG - std::cerr << " Setting property to " << externalSchemaLocation_ << std::endl; -#endif - xerces_string_janitor toDelete(XSA::asXMLChString(externalSchemaLocation_)); - xerces_->setProperty(XERCES_CPP_NAMESPACE::XMLUni::fgXercesSchemaExternalSchemaLocation, const_cast(toDelete.get())); - } - else - { - throw SAXNotSupportedException("Property ExternalShemaLocation is wrong type, should be string_type"); - } - return; - } - - if (name == properties_.externalNoNamespaceSchemaLocation) - { - typename XMLReaderT::PropertyBase* propBase = value.get(); - typedef typename XMLReaderT::template Property propertyType; -#ifdef SAXXERCES_DEBUG - std::cerr << "doSetProperty(externalNoNamespaceSchemaLocation, &(" - << typeid(*propBase) << "))" << std::endl; -#endif - propertyType* prop = dynamic_cast(propBase); -#ifdef SAXXERCES_DEBUG - std::cerr << " Extracted property to " << typeid(prop) - << "(" << prop << ")" << std::endl; -#endif - if (prop) - { - externalNoNamespaceSchemaLocation_ = prop->get(); -#ifdef SAXXERCES_DEBUG - std::cerr << " Setting property to " << externalNoNamespaceSchemaLocation_ << std::endl; -#endif - xerces_string_janitor toDelete(XSA::asXMLChString(externalNoNamespaceSchemaLocation_)); - xerces_->setProperty(XERCES_CPP_NAMESPACE::XMLUni::fgXercesSchemaExternalNoNameSpaceSchemaLocation, const_cast(toDelete.get())); - } - else - { - throw SAXNotSupportedException("Property ExternalNoNamespaceSchemaLocation is wrong type, should be string_type"); - } - return; - } - - throw SAX::SAXNotRecognizedException("Property not recognized "); -} - - template void xerces_wrapper::parse(InputSourceT& source) { @@ -1089,7 +918,7 @@ bool xerces_wrapper::parseFirst(InputSourceT& input, XMLPScanToken& toFill) { - std::auto_ptr newToken(new XercesXMLPScanToken); + auto newToken = std::make_unique(); // To store the result from Xerces parseFirst(). bool result = false; if (input.getByteStream() == 0) @@ -1110,9 +939,9 @@ bool xerces_wrapperparseFirst(isAdaptor, newToken->token_); } if (result) { - // We need to explicitly convert to auto_ptr. - std::auto_ptr toSet(newToken.release()); - toFill.setParserData(toSet); + // We need to explicitly convert to unique_ptr. + std::unique_ptr toSet(newToken.release()); + toFill.setParserData(std::move(toSet)); } return result; } // parseFirst diff --git a/include/Taggle/impl/Parser.hpp b/include/Taggle/impl/Parser.hpp index a6630540..41d4b0e1 100644 --- a/include/Taggle/impl/Parser.hpp +++ b/include/Taggle/impl/Parser.hpp @@ -396,90 +396,7 @@ public: CDATAElements = value; } // setFeature - typedef typename XMLReaderInterface::PropertyBase PropertyBaseT; - virtual std::auto_ptr doGetProperty(const string_type& /*name*/) - { - return std::auto_ptr(0); - } // doGetProperty - - virtual void doSetProperty(const string_type& /*name*/, std::auto_ptr /*value*/) - { - } // doSetProperty - - /* - Object getProperty (std::string name) - { - if(name.equals(lexicalHandlerProperty)) - { - return lexicalHandler_ == this ? null : lexicalHandler_; - } - else if(name.equals(scannerProperty)) - { - return scanner_; - } - else if(name.equals(schemaProperty)) - { - return schema_; - } - else if(name.equals(autoDetectorProperty)) - { - return theAutoDetector; - } - else - { - throw new SAXNotRecognizedException("Unknown property " + name); - } - } // getProperty - - void setProperty (std::string name, Object value) - { - if(name.equals(lexicalHandlerProperty)) - { - if(value == null) - { - lexicalHandler_ = this; - } - else if(value instanceof LexicalHandler) - { - lexicalHandler_ = (LexicalHandler)value; - } - else - { - throw new SAXNotSupportedException("Your lexical handler is not a LexicalHandler"); - } - } - else if(name.equals(scannerProperty)) - { - if(value instanceof Scanner) { - scanner_ = (Scanner)value; - } - else { - throw new SAXNotSupportedException("Your scanner is not a Scanner"); - } - } - else if(name.equals(schemaProperty)) { - if(value instanceof Schema) { - schema_ = (Schema)value; - } - else { - throw new SAXNotSupportedException("Your schema is not a Schema"); - } - } - else if(name.equals(autoDetectorProperty)) { - if(value instanceof AutoDetector) { - theAutoDetector = (AutoDetector)value; - } - else { - throw new SAXNotSupportedException("Your auto-detector is not an AutoDetector"); - } - } - else { - throw new SAXNotRecognizedException("Unknown property " + name); - } - } -*/ - - virtual void setEntityResolver(EntityResolverT& resolver) + virtual void setEntityResolver(EntityResolverT& resolver) { entityResolver_ = &resolver; } // setEntityResolver diff --git a/include/XPath/impl/xpath_step.hpp b/include/XPath/impl/xpath_step.hpp index 5550e0e9..3d35a7aa 100644 --- a/include/XPath/impl/xpath_step.hpp +++ b/include/XPath/impl/xpath_step.hpp @@ -219,8 +219,8 @@ public: Axis axis, bool is_attr = false) { - std::auto_ptr > test(getTest(node, end, !is_attr ? axis : ATTRIBUTE, context.namespaceContext())); - std::auto_ptr > thing; + std::unique_ptr > test(getTest(node, end, !is_attr ? axis : ATTRIBUTE, context.namespaceContext())); + std::unique_ptr > thing; if(test.get() == 0) thing.reset(XPath::compile_expression(node++, end, context)); @@ -489,14 +489,14 @@ public: const ExecutionContext& executionContext) const { NodeSet ns; - - NodeSet nodes = expr_->evaluate(context, executionContext).asNodeSet(); - for(typename NodeSet::const_iterator n = nodes.begin(), ne = nodes.end(); n != ne; ++n) - if(context == *n) - { - ns.push_back(context); - break; - } // if ... + + NodeSet nodes = expr_->evaluate(context, executionContext).asNodeSet(); + for(typename NodeSet::const_iterator n = nodes.begin(), ne = nodes.end(); n != ne; ++n) + if(context == *n) + { + ns.push_back(context); + break; + } // if ... return XPathValue(new NodeSetValue(ns)); } // evaluate diff --git a/include/XSLT/impl/xslt_stylesheet_compiler.hpp b/include/XSLT/impl/xslt_stylesheet_compiler.hpp index d94064b6..9077f042 100644 --- a/include/XSLT/impl/xslt_stylesheet_compiler.hpp +++ b/include/XSLT/impl/xslt_stylesheet_compiler.hpp @@ -227,11 +227,11 @@ public: { } // ~StylesheetCompiler - std::auto_ptr > compile(InputSourceT& source) + std::unique_ptr > compile(InputSourceT& source) { error_ = ""; - std::auto_ptr > stylesheet(new CompiledStylesheet()); + auto stylesheet = std::make_unique>(); StylesheetParser parser; CompilationContext context(parser, *stylesheet.get()); @@ -252,7 +252,7 @@ public: stylesheet.reset(); } // catch - return std::auto_ptr >(stylesheet.release()); + return std::unique_ptr >(stylesheet.release()); } // compile const std::string& error() const diff --git a/m4/ax_cxx_compile_stdcxx.m4 b/m4/ax_cxx_compile_stdcxx.m4 new file mode 100644 index 00000000..43087b2e --- /dev/null +++ b/m4/ax_cxx_compile_stdcxx.m4 @@ -0,0 +1,951 @@ +# =========================================================================== +# https://www.gnu.org/software/autoconf-archive/ax_cxx_compile_stdcxx.html +# =========================================================================== +# +# SYNOPSIS +# +# AX_CXX_COMPILE_STDCXX(VERSION, [ext|noext], [mandatory|optional]) +# +# DESCRIPTION +# +# Check for baseline language coverage in the compiler for the specified +# version of the C++ standard. If necessary, add switches to CXX and +# CXXCPP to enable support. VERSION may be '11' (for the C++11 standard) +# or '14' (for the C++14 standard). +# +# The second argument, if specified, indicates whether you insist on an +# extended mode (e.g. -std=gnu++11) or a strict conformance mode (e.g. +# -std=c++11). If neither is specified, you get whatever works, with +# preference for an extended mode. +# +# The third argument, if specified 'mandatory' or if left unspecified, +# indicates that baseline support for the specified C++ standard is +# required and that the macro should error out if no mode with that +# support is found. If specified 'optional', then configuration proceeds +# regardless, after defining HAVE_CXX${VERSION} if and only if a +# supporting mode is found. +# +# LICENSE +# +# Copyright (c) 2008 Benjamin Kosnik +# Copyright (c) 2012 Zack Weinberg +# Copyright (c) 2013 Roy Stogner +# Copyright (c) 2014, 2015 Google Inc.; contributed by Alexey Sokolov +# Copyright (c) 2015 Paul Norman +# Copyright (c) 2015 Moritz Klammler +# Copyright (c) 2016, 2018 Krzesimir Nowak +# Copyright (c) 2019 Enji Cooper +# +# Copying and distribution of this file, with or without modification, are +# permitted in any medium without royalty provided the copyright notice +# and this notice are preserved. This file is offered as-is, without any +# warranty. + +#serial 11 + +dnl This macro is based on the code from the AX_CXX_COMPILE_STDCXX_11 macro +dnl (serial version number 13). + +AC_DEFUN([AX_CXX_COMPILE_STDCXX], [dnl + m4_if([$1], [11], [ax_cxx_compile_alternatives="11 0x"], + [$1], [14], [ax_cxx_compile_alternatives="14 1y"], + [$1], [17], [ax_cxx_compile_alternatives="17 1z"], + [m4_fatal([invalid first argument `$1' to AX_CXX_COMPILE_STDCXX])])dnl + m4_if([$2], [], [], + [$2], [ext], [], + [$2], [noext], [], + [m4_fatal([invalid second argument `$2' to AX_CXX_COMPILE_STDCXX])])dnl + m4_if([$3], [], [ax_cxx_compile_cxx$1_required=true], + [$3], [mandatory], [ax_cxx_compile_cxx$1_required=true], + [$3], [optional], [ax_cxx_compile_cxx$1_required=false], + [m4_fatal([invalid third argument `$3' to AX_CXX_COMPILE_STDCXX])]) + AC_LANG_PUSH([C++])dnl + ac_success=no + + m4_if([$2], [noext], [], [dnl + if test x$ac_success = xno; then + for alternative in ${ax_cxx_compile_alternatives}; do + switch="-std=gnu++${alternative}" + cachevar=AS_TR_SH([ax_cv_cxx_compile_cxx$1_$switch]) + AC_CACHE_CHECK(whether $CXX supports C++$1 features with $switch, + $cachevar, + [ac_save_CXX="$CXX" + CXX="$CXX $switch" + AC_COMPILE_IFELSE([AC_LANG_SOURCE([_AX_CXX_COMPILE_STDCXX_testbody_$1])], + [eval $cachevar=yes], + [eval $cachevar=no]) + CXX="$ac_save_CXX"]) + if eval test x\$$cachevar = xyes; then + CXX="$CXX $switch" + if test -n "$CXXCPP" ; then + CXXCPP="$CXXCPP $switch" + fi + ac_success=yes + break + fi + done + fi]) + + m4_if([$2], [ext], [], [dnl + if test x$ac_success = xno; then + dnl HP's aCC needs +std=c++11 according to: + dnl http://h21007.www2.hp.com/portal/download/files/unprot/aCxx/PDF_Release_Notes/769149-001.pdf + dnl Cray's crayCC needs "-h std=c++11" + for alternative in ${ax_cxx_compile_alternatives}; do + for switch in -std=c++${alternative} +std=c++${alternative} "-h std=c++${alternative}"; do + cachevar=AS_TR_SH([ax_cv_cxx_compile_cxx$1_$switch]) + AC_CACHE_CHECK(whether $CXX supports C++$1 features with $switch, + $cachevar, + [ac_save_CXX="$CXX" + CXX="$CXX $switch" + AC_COMPILE_IFELSE([AC_LANG_SOURCE([_AX_CXX_COMPILE_STDCXX_testbody_$1])], + [eval $cachevar=yes], + [eval $cachevar=no]) + CXX="$ac_save_CXX"]) + if eval test x\$$cachevar = xyes; then + CXX="$CXX $switch" + if test -n "$CXXCPP" ; then + CXXCPP="$CXXCPP $switch" + fi + ac_success=yes + break + fi + done + if test x$ac_success = xyes; then + break + fi + done + fi]) + AC_LANG_POP([C++]) + if test x$ax_cxx_compile_cxx$1_required = xtrue; then + if test x$ac_success = xno; then + AC_MSG_ERROR([*** A compiler with support for C++$1 language features is required.]) + fi + fi + if test x$ac_success = xno; then + HAVE_CXX$1=0 + AC_MSG_NOTICE([No compiler with C++$1 support was found]) + else + HAVE_CXX$1=1 + AC_DEFINE(HAVE_CXX$1,1, + [define if the compiler supports basic C++$1 syntax]) + fi + AC_SUBST(HAVE_CXX$1) +]) + + +dnl Test body for checking C++11 support + +m4_define([_AX_CXX_COMPILE_STDCXX_testbody_11], + _AX_CXX_COMPILE_STDCXX_testbody_new_in_11 +) + + +dnl Test body for checking C++14 support + +m4_define([_AX_CXX_COMPILE_STDCXX_testbody_14], + _AX_CXX_COMPILE_STDCXX_testbody_new_in_11 + _AX_CXX_COMPILE_STDCXX_testbody_new_in_14 +) + +m4_define([_AX_CXX_COMPILE_STDCXX_testbody_17], + _AX_CXX_COMPILE_STDCXX_testbody_new_in_11 + _AX_CXX_COMPILE_STDCXX_testbody_new_in_14 + _AX_CXX_COMPILE_STDCXX_testbody_new_in_17 +) + +dnl Tests for new features in C++11 + +m4_define([_AX_CXX_COMPILE_STDCXX_testbody_new_in_11], [[ + +// If the compiler admits that it is not ready for C++11, why torture it? +// Hopefully, this will speed up the test. + +#ifndef __cplusplus + +#error "This is not a C++ compiler" + +#elif __cplusplus < 201103L + +#error "This is not a C++11 compiler" + +#else + +namespace cxx11 +{ + + namespace test_static_assert + { + + template + struct check + { + static_assert(sizeof(int) <= sizeof(T), "not big enough"); + }; + + } + + namespace test_final_override + { + + struct Base + { + virtual ~Base() {} + virtual void f() {} + }; + + struct Derived : public Base + { + virtual ~Derived() override {} + virtual void f() override {} + }; + + } + + namespace test_double_right_angle_brackets + { + + template < typename T > + struct check {}; + + typedef check single_type; + typedef check> double_type; + typedef check>> triple_type; + typedef check>>> quadruple_type; + + } + + namespace test_decltype + { + + int + f() + { + int a = 1; + decltype(a) b = 2; + return a + b; + } + + } + + namespace test_type_deduction + { + + template < typename T1, typename T2 > + struct is_same + { + static const bool value = false; + }; + + template < typename T > + struct is_same + { + static const bool value = true; + }; + + template < typename T1, typename T2 > + auto + add(T1 a1, T2 a2) -> decltype(a1 + a2) + { + return a1 + a2; + } + + int + test(const int c, volatile int v) + { + static_assert(is_same::value == true, ""); + static_assert(is_same::value == false, ""); + static_assert(is_same::value == false, ""); + auto ac = c; + auto av = v; + auto sumi = ac + av + 'x'; + auto sumf = ac + av + 1.0; + static_assert(is_same::value == true, ""); + static_assert(is_same::value == true, ""); + static_assert(is_same::value == true, ""); + static_assert(is_same::value == false, ""); + static_assert(is_same::value == true, ""); + return (sumf > 0.0) ? sumi : add(c, v); + } + + } + + namespace test_noexcept + { + + int f() { return 0; } + int g() noexcept { return 0; } + + static_assert(noexcept(f()) == false, ""); + static_assert(noexcept(g()) == true, ""); + + } + + namespace test_constexpr + { + + template < typename CharT > + unsigned long constexpr + strlen_c_r(const CharT *const s, const unsigned long acc) noexcept + { + return *s ? strlen_c_r(s + 1, acc + 1) : acc; + } + + template < typename CharT > + unsigned long constexpr + strlen_c(const CharT *const s) noexcept + { + return strlen_c_r(s, 0UL); + } + + static_assert(strlen_c("") == 0UL, ""); + static_assert(strlen_c("1") == 1UL, ""); + static_assert(strlen_c("example") == 7UL, ""); + static_assert(strlen_c("another\0example") == 7UL, ""); + + } + + namespace test_rvalue_references + { + + template < int N > + struct answer + { + static constexpr int value = N; + }; + + answer<1> f(int&) { return answer<1>(); } + answer<2> f(const int&) { return answer<2>(); } + answer<3> f(int&&) { return answer<3>(); } + + void + test() + { + int i = 0; + const int c = 0; + static_assert(decltype(f(i))::value == 1, ""); + static_assert(decltype(f(c))::value == 2, ""); + static_assert(decltype(f(0))::value == 3, ""); + } + + } + + namespace test_uniform_initialization + { + + struct test + { + static const int zero {}; + static const int one {1}; + }; + + static_assert(test::zero == 0, ""); + static_assert(test::one == 1, ""); + + } + + namespace test_lambdas + { + + void + test1() + { + auto lambda1 = [](){}; + auto lambda2 = lambda1; + lambda1(); + lambda2(); + } + + int + test2() + { + auto a = [](int i, int j){ return i + j; }(1, 2); + auto b = []() -> int { return '0'; }(); + auto c = [=](){ return a + b; }(); + auto d = [&](){ return c; }(); + auto e = [a, &b](int x) mutable { + const auto identity = [](int y){ return y; }; + for (auto i = 0; i < a; ++i) + a += b--; + return x + identity(a + b); + }(0); + return a + b + c + d + e; + } + + int + test3() + { + const auto nullary = [](){ return 0; }; + const auto unary = [](int x){ return x; }; + using nullary_t = decltype(nullary); + using unary_t = decltype(unary); + const auto higher1st = [](nullary_t f){ return f(); }; + const auto higher2nd = [unary](nullary_t f1){ + return [unary, f1](unary_t f2){ return f2(unary(f1())); }; + }; + return higher1st(nullary) + higher2nd(nullary)(unary); + } + + } + + namespace test_variadic_templates + { + + template + struct sum; + + template + struct sum + { + static constexpr auto value = N0 + sum::value; + }; + + template <> + struct sum<> + { + static constexpr auto value = 0; + }; + + static_assert(sum<>::value == 0, ""); + static_assert(sum<1>::value == 1, ""); + static_assert(sum<23>::value == 23, ""); + static_assert(sum<1, 2>::value == 3, ""); + static_assert(sum<5, 5, 11>::value == 21, ""); + static_assert(sum<2, 3, 5, 7, 11, 13>::value == 41, ""); + + } + + // http://stackoverflow.com/questions/13728184/template-aliases-and-sfinae + // Clang 3.1 fails with headers of libstd++ 4.8.3 when using std::function + // because of this. + namespace test_template_alias_sfinae + { + + struct foo {}; + + template + using member = typename T::member_type; + + template + void func(...) {} + + template + void func(member*) {} + + void test(); + + void test() { func(0); } + + } + +} // namespace cxx11 + +#endif // __cplusplus >= 201103L + +]]) + + +dnl Tests for new features in C++14 + +m4_define([_AX_CXX_COMPILE_STDCXX_testbody_new_in_14], [[ + +// If the compiler admits that it is not ready for C++14, why torture it? +// Hopefully, this will speed up the test. + +#ifndef __cplusplus + +#error "This is not a C++ compiler" + +#elif __cplusplus < 201402L + +#error "This is not a C++14 compiler" + +#else + +namespace cxx14 +{ + + namespace test_polymorphic_lambdas + { + + int + test() + { + const auto lambda = [](auto&&... args){ + const auto istiny = [](auto x){ + return (sizeof(x) == 1UL) ? 1 : 0; + }; + const int aretiny[] = { istiny(args)... }; + return aretiny[0]; + }; + return lambda(1, 1L, 1.0f, '1'); + } + + } + + namespace test_binary_literals + { + + constexpr auto ivii = 0b0000000000101010; + static_assert(ivii == 42, "wrong value"); + + } + + namespace test_generalized_constexpr + { + + template < typename CharT > + constexpr unsigned long + strlen_c(const CharT *const s) noexcept + { + auto length = 0UL; + for (auto p = s; *p; ++p) + ++length; + return length; + } + + static_assert(strlen_c("") == 0UL, ""); + static_assert(strlen_c("x") == 1UL, ""); + static_assert(strlen_c("test") == 4UL, ""); + static_assert(strlen_c("another\0test") == 7UL, ""); + + } + + namespace test_lambda_init_capture + { + + int + test() + { + auto x = 0; + const auto lambda1 = [a = x](int b){ return a + b; }; + const auto lambda2 = [a = lambda1(x)](){ return a; }; + return lambda2(); + } + + } + + namespace test_digit_separators + { + + constexpr auto ten_million = 100'000'000; + static_assert(ten_million == 100000000, ""); + + } + + namespace test_return_type_deduction + { + + auto f(int& x) { return x; } + decltype(auto) g(int& x) { return x; } + + template < typename T1, typename T2 > + struct is_same + { + static constexpr auto value = false; + }; + + template < typename T > + struct is_same + { + static constexpr auto value = true; + }; + + int + test() + { + auto x = 0; + static_assert(is_same::value, ""); + static_assert(is_same::value, ""); + return x; + } + + } + +} // namespace cxx14 + +#endif // __cplusplus >= 201402L + +]]) + + +dnl Tests for new features in C++17 + +m4_define([_AX_CXX_COMPILE_STDCXX_testbody_new_in_17], [[ + +// If the compiler admits that it is not ready for C++17, why torture it? +// Hopefully, this will speed up the test. + +#ifndef __cplusplus + +#error "This is not a C++ compiler" + +#elif __cplusplus < 201703L + +#error "This is not a C++17 compiler" + +#else + +#include +#include +#include + +namespace cxx17 +{ + + namespace test_constexpr_lambdas + { + + constexpr int foo = [](){return 42;}(); + + } + + namespace test::nested_namespace::definitions + { + + } + + namespace test_fold_expression + { + + template + int multiply(Args... args) + { + return (args * ... * 1); + } + + template + bool all(Args... args) + { + return (args && ...); + } + + } + + namespace test_extended_static_assert + { + + static_assert (true); + + } + + namespace test_auto_brace_init_list + { + + auto foo = {5}; + auto bar {5}; + + static_assert(std::is_same, decltype(foo)>::value); + static_assert(std::is_same::value); + } + + namespace test_typename_in_template_template_parameter + { + + template typename X> struct D; + + } + + namespace test_fallthrough_nodiscard_maybe_unused_attributes + { + + int f1() + { + return 42; + } + + [[nodiscard]] int f2() + { + [[maybe_unused]] auto unused = f1(); + + switch (f1()) + { + case 17: + f1(); + [[fallthrough]]; + case 42: + f1(); + } + return f1(); + } + + } + + namespace test_extended_aggregate_initialization + { + + struct base1 + { + int b1, b2 = 42; + }; + + struct base2 + { + base2() { + b3 = 42; + } + int b3; + }; + + struct derived : base1, base2 + { + int d; + }; + + derived d1 {{1, 2}, {}, 4}; // full initialization + derived d2 {{}, {}, 4}; // value-initialized bases + + } + + namespace test_general_range_based_for_loop + { + + struct iter + { + int i; + + int& operator* () + { + return i; + } + + const int& operator* () const + { + return i; + } + + iter& operator++() + { + ++i; + return *this; + } + }; + + struct sentinel + { + int i; + }; + + bool operator== (const iter& i, const sentinel& s) + { + return i.i == s.i; + } + + bool operator!= (const iter& i, const sentinel& s) + { + return !(i == s); + } + + struct range + { + iter begin() const + { + return {0}; + } + + sentinel end() const + { + return {5}; + } + }; + + void f() + { + range r {}; + + for (auto i : r) + { + [[maybe_unused]] auto v = i; + } + } + + } + + namespace test_lambda_capture_asterisk_this_by_value + { + + struct t + { + int i; + int foo() + { + return [*this]() + { + return i; + }(); + } + }; + + } + + namespace test_enum_class_construction + { + + enum class byte : unsigned char + {}; + + byte foo {42}; + + } + + namespace test_constexpr_if + { + + template + int f () + { + if constexpr(cond) + { + return 13; + } + else + { + return 42; + } + } + + } + + namespace test_selection_statement_with_initializer + { + + int f() + { + return 13; + } + + int f2() + { + if (auto i = f(); i > 0) + { + return 3; + } + + switch (auto i = f(); i + 4) + { + case 17: + return 2; + + default: + return 1; + } + } + + } + + namespace test_template_argument_deduction_for_class_templates + { + + template + struct pair + { + pair (T1 p1, T2 p2) + : m1 {p1}, + m2 {p2} + {} + + T1 m1; + T2 m2; + }; + + void f() + { + [[maybe_unused]] auto p = pair{13, 42u}; + } + + } + + namespace test_non_type_auto_template_parameters + { + + template + struct B + {}; + + B<5> b1; + B<'a'> b2; + + } + + namespace test_structured_bindings + { + + int arr[2] = { 1, 2 }; + std::pair pr = { 1, 2 }; + + auto f1() -> int(&)[2] + { + return arr; + } + + auto f2() -> std::pair& + { + return pr; + } + + struct S + { + int x1 : 2; + volatile double y1; + }; + + S f3() + { + return {}; + } + + auto [ x1, y1 ] = f1(); + auto& [ xr1, yr1 ] = f1(); + auto [ x2, y2 ] = f2(); + auto& [ xr2, yr2 ] = f2(); + const auto [ x3, y3 ] = f3(); + + } + + namespace test_exception_spec_type_system + { + + struct Good {}; + struct Bad {}; + + void g1() noexcept; + void g2(); + + template + Bad + f(T*, T*); + + template + Good + f(T1*, T2*); + + static_assert (std::is_same_v); + + } + + namespace test_inline_variables + { + + template void f(T) + {} + + template inline T g(T) + { + return T{}; + } + + template<> inline void f<>(int) + {} + + template<> int g<>(int) + { + return 5; + } + + } + +} // namespace cxx17 + +#endif // __cplusplus < 201703L + +]]) diff --git a/tests/CppUnit/framework/TestCaller.h b/tests/CppUnit/framework/TestCaller.h index 68813c25..6cbba2a4 100644 --- a/tests/CppUnit/framework/TestCaller.h +++ b/tests/CppUnit/framework/TestCaller.h @@ -56,16 +56,16 @@ public: protected: void runTest () - { (m_fixture.get ()->*m_test)(); } + { (m_fixture.get ()->*m_test)(); } void setUp () - { m_fixture.get ()->setUp (); } + { m_fixture->setUp (); } void tearDown () - { m_fixture.get ()->tearDown (); } + { m_fixture->tearDown (); } private: - std::auto_ptr m_fixture; + std::unique_ptr m_fixture; TestMethod m_test; }; diff --git a/tests/SAX/test_WhitespaceStripper.hpp b/tests/SAX/test_WhitespaceStripper.hpp index aab39930..ab6b8e2e 100644 --- a/tests/SAX/test_WhitespaceStripper.hpp +++ b/tests/SAX/test_WhitespaceStripper.hpp @@ -125,11 +125,11 @@ class WhitespaceStripperTest : public TestCase } // testStrip private: - std::auto_ptr > source(const std::string& str) + std::unique_ptr > source(const std::string& str) { - std::auto_ptr ss(new std::stringstream()); + std::unique_ptr ss(new std::stringstream()); (*ss) << str; - return std::auto_ptr >(new Arabica::SAX::InputSource(ss)); + return std::make_unique>(std::move(ss)); } // source }; // WhitespaceStripperTest diff --git a/tests/Taggle/test_Taggle.hpp b/tests/Taggle/test_Taggle.hpp index 36a40dc3..dbf602ff 100644 --- a/tests/Taggle/test_Taggle.hpp +++ b/tests/Taggle/test_Taggle.hpp @@ -35,11 +35,11 @@ class TaggleTest : public TestCase } // senseTest private: - std::auto_ptr > source(const std::string& str) + std::unique_ptr > source(const std::string& str) { - std::auto_ptr ss(new std::stringstream()); + std::unique_ptr ss(new std::stringstream()); (*ss) << str; - return std::auto_ptr >(new Arabica::SAX::InputSource(ss)); + return std::make_unique>(std::move(ss)); } // source }; // TaggleTest diff --git a/tests/XSLT/xslt_test.hpp b/tests/XSLT/xslt_test.hpp index 9c810942..ee8799f9 100644 --- a/tests/XSLT/xslt_test.hpp +++ b/tests/XSLT/xslt_test.hpp @@ -177,7 +177,7 @@ protected: Arabica::XSLT::StylesheetCompiler compiler; Arabica::SAX::InputSource source(string_adaptor::construct(input_xslt_)); - std::auto_ptr > stylesheet = compiler.compile(source); + std::unique_ptr > stylesheet = compiler.compile(source); if(stylesheet.get() != 0) assertImplementation(false, "Expected " + input_xslt_ + " not to compile. But it did :o"); throw SkipException(reason_ + " : " + compiler.error()); @@ -209,7 +209,7 @@ protected: Arabica::XSLT::StylesheetCompiler compiler; Arabica::SAX::InputSource source(string_adaptor::construct(input_xslt_)); - std::auto_ptr > stylesheet = compiler.compile(source); + std::unique_ptr > stylesheet = compiler.compile(source); if(stylesheet.get() == 0) assertImplementation(false, "Failed to compile " + input_xslt_ + " : " + compiler.error()); @@ -255,7 +255,7 @@ protected: string_type input = string_adaptor::construct(input_xslt_); Arabica::SAX::InputSource source(input); - std::auto_ptr > stylesheet = compiler.compile(source); + std::unique_ptr > stylesheet = compiler.compile(source); if(stylesheet.get() == 0) return; @@ -301,7 +301,7 @@ protected: Arabica::XSLT::StylesheetCompiler compiler; Arabica::SAX::InputSource source(string_adaptor::construct(input_xslt_)); - std::auto_ptr > stylesheet = compiler.compile(source); + std::unique_ptr > stylesheet = compiler.compile(source); if(stylesheet.get() == 0) assertImplementation(false, "Failed to compile " + input_xslt_ + " : " + compiler.error()); @@ -397,7 +397,7 @@ protected: Arabica::XSLT::StylesheetCompiler compiler; Arabica::SAX::InputSource source(string_adaptor::construct(input_xslt_)); - std::auto_ptr > stylesheet = compiler.compile(source); + std::unique_ptr > stylesheet = compiler.compile(source); if(stylesheet.get() == 0) assertImplementation(false, "Failed to compile " + input_xslt_ + " : " + compiler.error()); @@ -498,7 +498,7 @@ protected: Arabica::XSLT::StylesheetCompiler compiler; Arabica::SAX::InputSource source(string_adaptor::construct(input_xslt_)); - std::auto_ptr > stylesheet = compiler.compile(source); + std::unique_ptr > stylesheet = compiler.compile(source); if(stylesheet.get() == 0) assertImplementation(false, "Failed to compile " + input_xslt_ + " : " + compiler.error()); diff --git a/vs10/lib_arabica.vcxproj b/vs10/lib_arabica.vcxproj index c011f6a8..f0fc1695 100644 --- a/vs10/lib_arabica.vcxproj +++ b/vs10/lib_arabica.vcxproj @@ -151,8 +151,6 @@ - - @@ -384,4 +382,4 @@ - \ No newline at end of file + diff --git a/vs2012/lib_arabica.vcxproj b/vs2012/lib_arabica.vcxproj index 84855ee3..9c151d4e 100644 --- a/vs2012/lib_arabica.vcxproj +++ b/vs2012/lib_arabica.vcxproj @@ -153,8 +153,6 @@ - - @@ -386,4 +384,4 @@ - \ No newline at end of file + diff --git a/vs2013+/lib_arabica.vcxproj b/vs2013+/lib_arabica.vcxproj index 1fadd9d2..5cb4dc21 100644 --- a/vs2013+/lib_arabica.vcxproj +++ b/vs2013+/lib_arabica.vcxproj @@ -154,8 +154,6 @@ - - diff --git a/vs2013+/lib_arabica_noboost.vcxproj b/vs2013+/lib_arabica_noboost.vcxproj index 4b3886fe..df24ffc9 100644 --- a/vs2013+/lib_arabica_noboost.vcxproj +++ b/vs2013+/lib_arabica_noboost.vcxproj @@ -154,8 +154,6 @@ - - diff --git a/vs9/lib_arabica.vcproj b/vs9/lib_arabica.vcproj index 291f702b..0151e2da 100644 --- a/vs9/lib_arabica.vcproj +++ b/vs9/lib_arabica.vcproj @@ -354,14 +354,6 @@ RelativePath="..\include\Sax\helpers\NamespaceSupport.hpp" > - - - - diff --git a/vs9/lib_arabica_noboost.vcproj b/vs9/lib_arabica_noboost.vcproj index 2325d7d2..19a39c84 100644 --- a/vs9/lib_arabica_noboost.vcproj +++ b/vs9/lib_arabica_noboost.vcproj @@ -354,14 +354,6 @@ RelativePath="..\include\Sax\helpers\NamespaceSupport.hpp" > - - - -