diff --git a/SAX/Makefile b/SAX/Makefile index b887a3a0..9a89cf2c 100644 --- a/SAX/Makefile +++ b/SAX/Makefile @@ -36,6 +36,7 @@ SRCS = saxlib.cpp \ ../Utils/utf8iso88591codecvt.cpp \ ../Utils/impl/iso88591_utf8.cpp \ ../Utils/utf16utf8codecvt.cpp \ + ../Utils/ucs2utf8codecvt.cpp \ ../Utils/base64codecvt.cpp \ ../Utils/impl/codecvt_specialisations.cpp \ ../XML/XMLCharacterClasses.cpp diff --git a/SAX/ParserConfig.S b/SAX/ParserConfig.S index 1439c773..d8e2ba13 100644 --- a/SAX/ParserConfig.S +++ b/SAX/ParserConfig.S @@ -77,8 +77,8 @@ ifndef NO_DEFAULT_PARSER ifdef DEF_SAX_P namespace SAX { - template > - class XMLReader : public DEF_SAX_P { }; + template + class XMLReader : public DEF_SAX_P { }; } // namespace SAX else error "No default parser defined." diff --git a/SAX/SAX.vcproj b/SAX/SAX.vcproj index 41183f12..9accd77c 100644 --- a/SAX/SAX.vcproj +++ b/SAX/SAX.vcproj @@ -27,7 +27,9 @@ PreprocessorDefinitions="WIN32,_DEBUG,_LIB" BasicRuntimeChecks="3" RuntimeLibrary="3" + DisableLanguageExtensions="FALSE" TreatWChar_tAsBuiltInType="TRUE" + ForceConformanceInForLoopScope="TRUE" RuntimeTypeInfo="TRUE" UsePrecompiledHeader="0" PrecompiledHeaderFile="" @@ -360,6 +362,9 @@ + + @@ -378,6 +383,15 @@ + + + + + + diff --git a/SAX/wrappers/saxexpat.h b/SAX/wrappers/saxexpat.h index 9dafb41f..48686a8d 100644 --- a/SAX/wrappers/saxexpat.h +++ b/SAX/wrappers/saxexpat.h @@ -26,6 +26,7 @@ #include #include #include +#include namespace SAX { @@ -196,13 +197,19 @@ private: * @version $Id$ * @see SAX::basic_XMLReader */ -template > +template class expat_wrapper : public SAX::basic_XMLReader, public SAX::basic_Locator, public expat_wrapper_impl_mumbojumbo::expat2base { public: typedef string_type stringT; + typedef typename Arabica::get_param, + T0, + T1>::type string_adaptor_type; typedef string_adaptor_type string_adaptorT; typedef string_adaptor_type SA; typedef SAX::basic_EntityResolver entityResolverT; @@ -339,8 +346,8 @@ class expat_wrapper : public SAX::basic_XMLReader, ////////////////////////////////////////////////////////////////// // expat wrapper definition -template -expat_wrapper::expat_wrapper() : +template +expat_wrapper::expat_wrapper() : entityResolver_(0), dtdHandler_(0), contentHandler_(0), @@ -367,14 +374,14 @@ expat_wrapper::expat_wrapper() : XML_SetProcessingInstructionHandler(parser_, expat_wrapper_impl_mumbojumbo::ewim_processingInstruction); } // expat -template -expat_wrapper::~expat_wrapper() +template +expat_wrapper::~expat_wrapper() { XML_ParserFree(parser_); } // ~expat -template -void expat_wrapper::setFeature(const stringT& name, bool value) +template +void expat_wrapper::setFeature(const stringT& name, bool value) { if(name == features_.namespaces) { @@ -415,8 +422,8 @@ void expat_wrapper::setFeature(const stringT& name, bo } } // setFeature -template -bool expat_wrapper::getFeature(const stringT& name) const +template +bool expat_wrapper::getFeature(const stringT& name) const { if(name == features_.namespaces) return namespaces_; @@ -433,8 +440,8 @@ bool expat_wrapper::getFeature(const stringT& name) co throw SAX::SAXNotRecognizedException(std::string("Feature not recognized ") + SA::asStdString(name)); } // getFeature -template -void expat_wrapper::parse(inputSourceT& source) +template +void expat_wrapper::parse(inputSourceT& source) { publicId_ = source.getPublicId(); systemId_ = source.getSystemId(); @@ -457,8 +464,8 @@ void expat_wrapper::parse(inputSourceT& source) parsing_ = false; } // parse -template -bool expat_wrapper::do_parse(inputSourceT& source, XML_Parser parser) +template +bool expat_wrapper::do_parse(inputSourceT& source, XML_Parser parser) { InputSourceResolver is(source, string_adaptorT()); if(is.resolve() == 0) @@ -489,11 +496,11 @@ bool expat_wrapper::do_parse(inputSourceT& source, XML return true; } // do_parse -template +template #ifndef ARABICA_VS6_WORKAROUND -std::auto_ptr::PropertyBaseT> expat_wrapper::doGetProperty(const stringT& name) +std::auto_ptr::PropertyBaseT> expat_wrapper::doGetProperty(const stringT& name) #else -std::auto_ptr::PropertyBaseT> expat_wrapper::doGetProperty(const stringT& name) +std::auto_ptr::PropertyBaseT> expat_wrapper::doGetProperty(const stringT& name) #endif { if(name == properties_.lexicalHandler) @@ -510,8 +517,8 @@ std::auto_ptr::PropertyBaseT> expat_wrap throw SAX::SAXNotRecognizedException(std::string("Property not recognized ") + SA::asStdString(name)); } // doGetProperty -template -void expat_wrapper::doSetProperty(const stringT& name, std::auto_ptr value) +template +void expat_wrapper::doSetProperty(const stringT& name, std::auto_ptr value) { if(name == properties_.lexicalHandler) { @@ -540,32 +547,32 @@ void expat_wrapper::doSetProperty(const stringT& name, } // doSetProperty // Locator implementation -template -stringT expat_wrapper::getPublicId() const +template +stringT expat_wrapper::getPublicId() const { return publicId_; } // getPublicId -template -stringT expat_wrapper::getSystemId() const +template +stringT expat_wrapper::getSystemId() const { return systemId_; } // getSystemId -template -int expat_wrapper::getLineNumber() const +template +int expat_wrapper::getLineNumber() const { return XML_GetCurrentLineNumber(parser_); } // getLineNumber -template -int expat_wrapper::getColumnNumber() const +template +int expat_wrapper::getColumnNumber() const { return XML_GetCurrentColumnNumber(parser_); } // getColumnNumber -template -typename SAX::basic_NamespaceSupport::Parts expat_wrapper::processName(const stringT& qName, bool isAttribute) +template +typename SAX::basic_NamespaceSupport::string_adaptorT>::Parts expat_wrapper::processName(const stringT& qName, bool isAttribute) { typename namespaceSupportT::Parts p = nsSupport_.processName(qName, isAttribute); if(SA::empty(p.URI) && !SA::empty(p.prefix)) @@ -573,8 +580,8 @@ typename SAX::basic_NamespaceSupport::Parts expat_wrap return p; } // processName -template -void expat_wrapper::reportError(const std::string& message, bool fatal) +template +void expat_wrapper::reportError(const std::string& message, bool fatal) { if(!errorHandler_) return; @@ -590,8 +597,8 @@ void expat_wrapper::reportError(const std::string& mes errorHandler_->error(e); } // reportError -template -void expat_wrapper::checkNotParsing(const stringT& type, const stringT& name) const +template +void expat_wrapper::checkNotParsing(const stringT& type, const stringT& name) const { if(parsing_) { @@ -601,16 +608,16 @@ void expat_wrapper::checkNotParsing(const stringT& typ } // if(parsing_) } // checkNotParsing -template -void expat_wrapper::charHandler(const char* txt, int txtlen) +template +void expat_wrapper::charHandler(const char* txt, int txtlen) { if(!contentHandler_) return; contentHandler_->characters(SA::construct_from_utf8(txt, txtlen)); } // charHandler -template -void expat_wrapper::startElement(const char* qName, const char** atts) +template +void expat_wrapper::startElement(const char* qName, const char** atts) { if(!contentHandler_) return; @@ -672,8 +679,8 @@ void expat_wrapper::startElement(const char* qName, co contentHandler_->startElement(name.URI, name.localName, name.rawName, attributes); } // startElement -template -void expat_wrapper::startElementNoNS(const char* qName, const char** atts) +template +void expat_wrapper::startElementNoNS(const char* qName, const char** atts) { SAX::basic_AttributesImpl attributes; @@ -691,8 +698,8 @@ void expat_wrapper::startElementNoNS(const char* qName contentHandler_->startElement(emptyString_, emptyString_, SA::construct_from_utf8(qName), attributes); } // startElementNoNS -template -void expat_wrapper::endElement(const char* qName) +template +void expat_wrapper::endElement(const char* qName) { if(!contentHandler_) return; @@ -711,22 +718,22 @@ void expat_wrapper::endElement(const char* qName) nsSupport_.popContext(); } // endElement -template -void expat_wrapper::endElementNoNS(const char* qName) +template +void expat_wrapper::endElementNoNS(const char* qName) { if(contentHandler_) contentHandler_->endElement(emptyString_, emptyString_, SA::construct_from_utf8(qName)); } // endElementNoNS -template -void expat_wrapper::processingInstruction(const char* target, const char* data) +template +void expat_wrapper::processingInstruction(const char* target, const char* data) { if(contentHandler_) contentHandler_->processingInstruction(SA::construct_from_utf8(target), SA::construct_from_utf8(data)); } // processingInstruction -template -void expat_wrapper::elementDeclaration(const XML_Char* name, +template +void expat_wrapper::elementDeclaration(const XML_Char* name, const XML_Content* model) { if(!declHandler_) @@ -737,8 +744,8 @@ void expat_wrapper::elementDeclaration(const XML_Char* declHandler_->elementDecl(SA::construct_from_utf8(name), SA::construct_from_utf8(os.str().c_str())); } // elementDeclaration -template -void expat_wrapper::convertXML_Content(std::ostream& os, const XML_Content* model, bool isChild) +template +void expat_wrapper::convertXML_Content(std::ostream& os, const XML_Content* model, bool isChild) { /* enum XML_Content_Type { @@ -847,8 +854,8 @@ struct XML_cp { } // switch } // convertXML_Content -template -void expat_wrapper::attListDeclaration(const XML_Char* elname, +template +void expat_wrapper::attListDeclaration(const XML_Char* elname, const XML_Char* attname, const XML_Char* att_type, const XML_Char* dflt, @@ -874,8 +881,8 @@ void expat_wrapper::attListDeclaration(const XML_Char* } } // attListDeclaration -template -void expat_wrapper::entityDeclaration(const XML_Char* entityName, +template +void expat_wrapper::entityDeclaration(const XML_Char* entityName, int is_parameter_entity, const XML_Char* value, int value_length, @@ -920,8 +927,8 @@ void expat_wrapper::entityDeclaration(const XML_Char* } } // entityDeclaration -template -void expat_wrapper::notationDeclaration(const XML_Char* notationName, +template +void expat_wrapper::notationDeclaration(const XML_Char* notationName, const XML_Char* base, const XML_Char* systemId, const XML_Char* publicId) @@ -933,8 +940,8 @@ void expat_wrapper::notationDeclaration(const XML_Char SA::construct_from_utf8(systemId)); } // notationDeclaration -template -void expat_wrapper::startDoctypeDecl(const XML_Char *doctypeName, +template +void expat_wrapper::startDoctypeDecl(const XML_Char *doctypeName, const XML_Char *systemId, const XML_Char *publicId, int has_internal_subset) @@ -952,36 +959,36 @@ void expat_wrapper::startDoctypeDecl(const XML_Char *d s_systemId); } // startDoctypeDecl -template -void expat_wrapper::endDoctypeDecl() +template +void expat_wrapper::endDoctypeDecl() { if(lexicalHandler_) lexicalHandler_->endDTD(); } // endDoctypeDecl -template -void expat_wrapper::startCdataSection() +template +void expat_wrapper::startCdataSection() { if(lexicalHandler_) lexicalHandler_->startCDATA(); } // startCdataSection -template -void expat_wrapper::endCdataSection() +template +void expat_wrapper::endCdataSection() { if(lexicalHandler_) lexicalHandler_->endCDATA(); } // endCdataSection -template -void expat_wrapper::commentHandler(const XML_Char *data) +template +void expat_wrapper::commentHandler(const XML_Char *data) { if(lexicalHandler_) lexicalHandler_->comment(SA::construct_from_utf8(data)); } // commentHandler -template -int expat_wrapper::externalEntityRefHandler(XML_Parser parser, +template +int expat_wrapper::externalEntityRefHandler(XML_Parser parser, const XML_Char* context, const XML_Char* base, const XML_Char* systemId, diff --git a/SAX/wrappers/saxlibxml2.h b/SAX/wrappers/saxlibxml2.h index db744fed..c5992a1e 100644 --- a/SAX/wrappers/saxlibxml2.h +++ b/SAX/wrappers/saxlibxml2.h @@ -27,6 +27,7 @@ #include #include #include +#include namespace SAX { @@ -108,13 +109,19 @@ xmlSAXHandler* lwit_SaxHandler(); } // namespace libxml2_wrapper_impl_tiddle -template > +template class libxml2_wrapper : public basic_XMLReader, public basic_Locator, protected libxml2_wrapper_impl_tiddle::libxml2_base { public: typedef string_type stringT; + typedef typename Arabica::get_param, + T0, + T1>::type string_adaptor_type; typedef string_adaptor_type string_adaptorT; typedef SAX::basic_EntityResolver entityResolverT; typedef SAX::basic_DTDHandler dtdHandlerT; @@ -219,8 +226,8 @@ class libxml2_wrapper : public basic_XMLReader, const AttributeTypes attrTypes_; }; // class libxml2_wrapper -template -libxml2_wrapper::libxml2_wrapper() : +template +libxml2_wrapper::libxml2_wrapper() : entityResolver_(0), dtdHandler_(0), contentHandler_(0), @@ -239,14 +246,14 @@ libxml2_wrapper::libxml2_wrapper() : xmlCtxtUseOptions(context_, XML_PARSE_DTDLOAD + XML_PARSE_DTDVALID + XML_PARSE_NOBLANKS); } // libxml2_wrapper -template -libxml2_wrapper::~libxml2_wrapper() +template +libxml2_wrapper::~libxml2_wrapper() { xmlFreeParserCtxt(context_); } // ~libxml2_wrapper -template -bool libxml2_wrapper::getFeature(const stringT& name) const +template +bool libxml2_wrapper::getFeature(const stringT& name) const { if(name == features_.namespaces) return namespaces_; @@ -270,8 +277,8 @@ bool libxml2_wrapper::getFeature(const stringT& name) } } // getFeature -template -void libxml2_wrapper::setFeature(const stringT& name, bool value) +template +void libxml2_wrapper::setFeature(const stringT& name, bool value) { if(name == features_.namespaces) { @@ -317,11 +324,11 @@ void libxml2_wrapper::setFeature(const stringT& name, } } // setFeature -template +template #ifndef ARABICA_VS6_WORKAROUND -std::auto_ptr::PropertyBaseT> libxml2_wrapper::doGetProperty(const stringT& name) +std::auto_ptr::PropertyBaseT> libxml2_wrapper::doGetProperty(const stringT& name) #else -std::auto_ptr::PropertyBaseT> libxml2_wrapper::doGetProperty(const stringT& name) +std::auto_ptr::PropertyBaseT> libxml2_wrapper::doGetProperty(const stringT& name) #endif { if(name == properties_.declHandler) @@ -335,8 +342,8 @@ std::auto_ptr::PropertyBaseT> libxml2_ throw SAX::SAXNotRecognizedException(std::string("Property not recognized ") + string_adaptorT::asStdString(name)); } // doGetProperty -template -void libxml2_wrapper::doSetProperty(const stringT& name, std::auto_ptr value) +template +void libxml2_wrapper::doSetProperty(const stringT& name, std::auto_ptr value) { if(name == properties_.declHandler) { @@ -353,8 +360,8 @@ void libxml2_wrapper::doSetProperty(const stringT& nam throw SAX::SAXNotRecognizedException(std::string("Property not recognized ") + string_adaptorT::asStdString(name)); } // doSetProperty -template -typename basic_NamespaceSupport::Parts libxml2_wrapper::processName(const stringT& qName, bool isAttribute) +template +typename SAX::basic_NamespaceSupport::string_adaptorT>::Parts libxml2_wrapper::processName(const stringT& qName, bool isAttribute) { typename basic_NamespaceSupport::Parts p = nsSupport_.processName(qName, isAttribute); @@ -363,8 +370,8 @@ typename basic_NamespaceSupport::Parts libxml2_wrapper return p; } // processName -template -void libxml2_wrapper::reportError(const std::string& message, bool fatal) +template +void libxml2_wrapper::reportError(const std::string& message, bool fatal) { if(!errorHandler_) return; @@ -376,8 +383,8 @@ void libxml2_wrapper::reportError(const std::string& m errorHandler_->error(e); } // reportError -template -void libxml2_wrapper::checkNotParsing(const stringT& type, const stringT& name) const +template +void libxml2_wrapper::checkNotParsing(const stringT& type, const stringT& name) const { if(parsing_) { @@ -387,40 +394,40 @@ void libxml2_wrapper::checkNotParsing(const stringT& t } // if(parsing_) } // checkNotParsing -template -stringT libxml2_wrapper::getPublicId() const +template +stringT libxml2_wrapper::getPublicId() const { if(locator_) return string_adaptorT::construct_from_utf8(reinterpret_cast(locator_->getPublicId(context_))); return stringT(); } // getPublicId -template -stringT libxml2_wrapper::getSystemId() const +template +stringT libxml2_wrapper::getSystemId() const { if(locator_) return string_adaptorT::construct_from_utf8(reinterpret_cast(locator_->getSystemId(context_))); return stringT(); } // getSystemId -template -int libxml2_wrapper::getLineNumber() const +template +int libxml2_wrapper::getLineNumber() const { if(locator_) return locator_->getLineNumber(context_); return -1; } // getLineNumber -template -int libxml2_wrapper::getColumnNumber() const +template +int libxml2_wrapper::getColumnNumber() const { if(locator_) return locator_->getColumnNumber(context_); return -1; } // getColumnNumber -template -void libxml2_wrapper::parse(basic_InputSource& source) +template +void libxml2_wrapper::parse(basic_InputSource& source) { if(contentHandler_) contentHandler_->setDocumentLocator(*this); @@ -441,65 +448,65 @@ void libxml2_wrapper::parse(basic_InputSource parsing_ = false; } // parse -template -void libxml2_wrapper::SAXstartDocument() +template +void libxml2_wrapper::SAXstartDocument() { if(contentHandler_) contentHandler_->startDocument(); } // SAXstartDocument -template -void libxml2_wrapper::SAXendDocument() +template +void libxml2_wrapper::SAXendDocument() { if(contentHandler_) contentHandler_->endDocument(); } // SAXendDocument -template -void libxml2_wrapper::SAXcharacters(const xmlChar* ch, int len) +template +void libxml2_wrapper::SAXcharacters(const xmlChar* ch, int len) { if(contentHandler_) contentHandler_->characters(string_adaptorT::construct_from_utf8(reinterpret_cast(ch), len)); } // SAXcharacters -template -void libxml2_wrapper::SAXignorableWhitespace(const xmlChar* ch, int len) +template +void libxml2_wrapper::SAXignorableWhitespace(const xmlChar* ch, int len) { if(contentHandler_) contentHandler_->ignorableWhitespace(string_adaptorT::construct_from_utf8(reinterpret_cast(ch), len)); } // SAXignorableWhitespace -template -void libxml2_wrapper::SAXwarning(const std::string& warning) +template +void libxml2_wrapper::SAXwarning(const std::string& warning) { if(errorHandler_) errorHandler_->warning(basic_SAXParseException(warning, *this)); } // warning -template -void libxml2_wrapper::SAXerror(const std::string& error) +template +void libxml2_wrapper::SAXerror(const std::string& error) { if(errorHandler_) errorHandler_->error(basic_SAXParseException(error, *this)); } // error -template -void libxml2_wrapper::SAXfatalError(const std::string& fatal) +template +void libxml2_wrapper::SAXfatalError(const std::string& fatal) { if(errorHandler_) errorHandler_->fatalError(basic_SAXParseException(fatal, *this)); } // fatal -template -void libxml2_wrapper::SAXprocessingInstruction(const xmlChar* target, const xmlChar* data) +template +void libxml2_wrapper::SAXprocessingInstruction(const xmlChar* target, const xmlChar* data) { if(contentHandler_) contentHandler_->processingInstruction(string_adaptorT::construct_from_utf8(reinterpret_cast(target)), string_adaptorT::construct_from_utf8(reinterpret_cast(data))); } // SAXprocessingInstruction -template -void libxml2_wrapper::SAXstartElement(const xmlChar* qName, const xmlChar** atts) +template +void libxml2_wrapper::SAXstartElement(const xmlChar* qName, const xmlChar** atts) { if(!contentHandler_) return; @@ -561,8 +568,8 @@ void libxml2_wrapper::SAXstartElement(const xmlChar* q contentHandler_->startElement(name.URI, name.localName, name.rawName, attributes); } // SAXstartElement -template -void libxml2_wrapper::SAXstartElementNoNS(const xmlChar* qName, const xmlChar** atts) +template +void libxml2_wrapper::SAXstartElementNoNS(const xmlChar* qName, const xmlChar** atts) { SAX::basic_AttributesImpl attributes; @@ -580,8 +587,8 @@ void libxml2_wrapper::SAXstartElementNoNS(const xmlCha contentHandler_->startElement(emptyString_, emptyString_, string_adaptorT::construct_from_utf8((reinterpret_cast(qName))), attributes); } // SAXstartElementNoNS -template -void libxml2_wrapper::SAXendElement(const xmlChar* qName) +template +void libxml2_wrapper::SAXendElement(const xmlChar* qName) { if(!contentHandler_) return; @@ -600,15 +607,15 @@ void libxml2_wrapper::SAXendElement(const xmlChar* qNa nsSupport_.popContext(); } // SAXendElement -template -void libxml2_wrapper::SAXendElementNoNS(const xmlChar* qName) +template +void libxml2_wrapper::SAXendElementNoNS(const xmlChar* qName) { if(contentHandler_) contentHandler_->endElement(emptyString_, emptyString_, string_adaptorT::construct_from_utf8(reinterpret_cast(qName))); } // SAXendElementNoNS -template -void libxml2_wrapper::SAXnotationDecl(const xmlChar *name, const xmlChar *publicId, const xmlChar *systemId) +template +void libxml2_wrapper::SAXnotationDecl(const xmlChar *name, const xmlChar *publicId, const xmlChar *systemId) { if(dtdHandler_) dtdHandler_->notationDecl(string_adaptorT::construct_from_utf8(reinterpret_cast(name)), @@ -616,8 +623,8 @@ void libxml2_wrapper::SAXnotationDecl(const xmlChar *n string_adaptorT::construct_from_utf8(reinterpret_cast(systemId))); } // SAXnotationDecl -template -void libxml2_wrapper::SAXunparsedEntityDecl(const xmlChar *name, const xmlChar *publicId, const xmlChar *systemId, const xmlChar *notationName) +template +void libxml2_wrapper::SAXunparsedEntityDecl(const xmlChar *name, const xmlChar *publicId, const xmlChar *systemId, const xmlChar *notationName) { if(dtdHandler_) dtdHandler_->unparsedEntityDecl(string_adaptorT::construct_from_utf8(reinterpret_cast(name)), @@ -626,8 +633,8 @@ void libxml2_wrapper::SAXunparsedEntityDecl(const xmlC string_adaptorT::construct_from_utf8(reinterpret_cast(notationName))); } // SAXunparsedEntityDecl -template -void libxml2_wrapper::SAXelementDecl(const xmlChar* name, int type, xmlElementContentPtr content) +template +void libxml2_wrapper::SAXelementDecl(const xmlChar* name, int type, xmlElementContentPtr content) { if(!declHandler_) return; @@ -637,8 +644,8 @@ void libxml2_wrapper::SAXelementDecl(const xmlChar* na declHandler_->elementDecl(string_adaptorT::construct_from_utf8(reinterpret_cast(name)), string_adaptorT::construct_from_utf8(os.str().c_str())); } // elementDeclaration -template -void libxml2_wrapper::convertXML_Content(std::ostream& os, int type, xmlElementContentPtr model, bool isChild) const +template +void libxml2_wrapper::convertXML_Content(std::ostream& os, int type, xmlElementContentPtr model, bool isChild) const { char concatenator = ' '; @@ -710,8 +717,8 @@ void libxml2_wrapper::convertXML_Content(std::ostream& } // switch } // convertXML_Content -template -void libxml2_wrapper::SAXattributeDecl(const xmlChar *elem, const xmlChar *fullname, int type, int def, const xmlChar *defaultValue, xmlEnumerationPtr tree) +template +void libxml2_wrapper::SAXattributeDecl(const xmlChar *elem, const xmlChar *fullname, int type, int def, const xmlChar *defaultValue, xmlEnumerationPtr tree) { if(!declHandler_) return; @@ -763,8 +770,8 @@ void libxml2_wrapper::SAXattributeDecl(const xmlChar * string_adaptorT::construct_from_utf8(reinterpret_cast(defaultValue))); } // SAXattributeDecl -template -stringT libxml2_wrapper::stringAttrEnum(xmlEnumerationPtr tree, bool leadingSpace) const +template +stringT libxml2_wrapper::stringAttrEnum(xmlEnumerationPtr tree, bool leadingSpace) const { std::ostringstream os; if(leadingSpace) @@ -782,8 +789,8 @@ stringT libxml2_wrapper::stringAttrEnum(xmlEnumeratio return string_adaptorT::construct_from_utf8(os.str().c_str()); } // stringAttrEnum -template -void libxml2_wrapper::SAXentityDecl(const xmlChar *name, int type, const xmlChar *publicId, const xmlChar *systemId, xmlChar *content) +template +void libxml2_wrapper::SAXentityDecl(const xmlChar *name, int type, const xmlChar *publicId, const xmlChar *systemId, xmlChar *content) { if(!declHandler_) return; @@ -802,8 +809,8 @@ void libxml2_wrapper::SAXentityDecl(const xmlChar *nam } // switch } // SAXentityDecl -template -xmlParserInputPtr libxml2_wrapper::SAXresolveEntity(const xmlChar* publicId, const xmlChar* systemId) +template +xmlParserInputPtr libxml2_wrapper::SAXresolveEntity(const xmlChar* publicId, const xmlChar* systemId) { if(!entityResolver_) return xmlLoadExternalEntity(reinterpret_cast(systemId), diff --git a/SAX/wrappers/saxmsxml2.h b/SAX/wrappers/saxmsxml2.h index a7dd2ea3..3b557cb4 100644 --- a/SAX/wrappers/saxmsxml2.h +++ b/SAX/wrappers/saxmsxml2.h @@ -33,6 +33,7 @@ #include #include #include +#include // Include the MSXML definitions. #include @@ -45,18 +46,20 @@ _COM_SMARTPTR_TYPEDEF(ISAXXMLReader, __uuidof(ISAXXMLReader)); namespace SAX { +struct COMInitializer_tag { }; + /** * use this as COMInitializer_type if you call * CoInitialize/CoInitializeEx in your own code */ -class COMExternalInitializer +class COMExternalInitializer : public COMInitializer_tag { public: COMExternalInitializer() { } ~COMExternalInitializer() { } }; // COMExternalInitializer -class COMSingleThreadInitializer +class COMSingleThreadInitializer : public COMInitializer_tag { public: COMSingleThreadInitializer() { ::CoInitialize(NULL); } @@ -64,7 +67,7 @@ class COMSingleThreadInitializer }; // COMSingleThreadInitializer #if(_WIN32_WINNT >= 0x0400 ) || defined(_WIN32_DCOM) -class COMMultiThreadInitializer +class COMMultiThreadInitializer : public COMInitializer_tag { public: COMMultiThreadInitializer() { ::CoInitializeEx(NULL, COINIT_MULTITHREADED); } @@ -73,10 +76,13 @@ class COMMultiThreadInitializer #endif template > + class T0 = Arabica::nil_t, + class T1 = Arabica::nil_t> class msxml2_wrapper : public SAX::basic_XMLReader { + typedef typename Arabica::get_param::type COMInitializer_type; + typedef typename Arabica::get_param, T0, T1>::type string_adaptor_type; + public: typedef string_type stringT; typedef string_adaptor_type string_adaptorT; diff --git a/SAX/wrappers/saxxerces.h b/SAX/wrappers/saxxerces.h index 37a57579..b6c3d7ae 100644 --- a/SAX/wrappers/saxxerces.h +++ b/SAX/wrappers/saxxerces.h @@ -52,6 +52,7 @@ std::ostream& operator<<(std::ostream& o, const std::type_info& ti) #include #include #include +#include // Xerces Includes #include @@ -116,10 +117,16 @@ namespace XercesImpl }; // class xerces_initializer } // namespace XercesImpl -template > +template class xerces_wrapper : public SAX::basic_ProgressiveParser { private: + typedef typename Arabica::get_param, + T0, + T1>::type string_adaptor_type; typedef string_adaptor_type string_adaptorT; protected: @@ -847,8 +854,8 @@ class xerces_wrapper : public SAX::basic_ProgressiveParser string_type externalNoNamespaceSchemaLocation_; }; // class xerces_wrapper -template -xerces_wrapper::xerces_wrapper() +template +xerces_wrapper::xerces_wrapper() { try { @@ -871,14 +878,14 @@ xerces_wrapper::xerces_wrapper() xerces_->setDeclarationHandler(&declHandlerAdaptor_); } // xerces_wrapper -template -xerces_wrapper::~xerces_wrapper() +template +xerces_wrapper::~xerces_wrapper() { delete xerces_; } // ~xerces_wrapper -template -bool xerces_wrapper::getFeature(const string_type& name) const +template +bool xerces_wrapper::getFeature(const string_type& name) const { try { @@ -895,8 +902,8 @@ bool xerces_wrapper::getFeature(const string_type& } // catch(SAXNotRecognizedException& e) } // getFeature -template -void xerces_wrapper::setFeature(const string_type& name, bool value) +template +void xerces_wrapper::setFeature(const string_type& name, bool value) { try { @@ -913,11 +920,11 @@ void xerces_wrapper::setFeature(const string_type& } // catch(SAXNotRecognizedException& e) } // setFeature -template +template #ifndef ARABICA_VS6_WORKAROUND -std::auto_ptr::PropertyBase> xerces_wrapper::doGetProperty(const string_type& name) +std::auto_ptr::PropertyBase> xerces_wrapper::doGetProperty(const string_type& name) #else -std::auto_ptr::PropertyBase> xerces_wrapper::doGetProperty(const string_type& name) +std::auto_ptr::PropertyBase> xerces_wrapper::doGetProperty(const string_type& name) #endif { if(name == properties_.lexicalHandler) @@ -981,11 +988,11 @@ std::auto_ptr::PropertyBase> xerces_wrapper +template #ifndef ARABICA_VS6_WORKAROUND -void xerces_wrapper::doSetProperty(const string_type& name, std::auto_ptr value) +void xerces_wrapper::doSetProperty(const string_type& name, std::auto_ptr value) #else -void xerces_wrapper::doSetProperty(const string_type& name, std::auto_ptr value) +void xerces_wrapper::doSetProperty(const string_type& name, std::auto_ptr value) #endif { if(name == properties_.lexicalHandler) @@ -1072,8 +1079,8 @@ void xerces_wrapper::doSetProperty(const string_ty } -template -void xerces_wrapper::parse(InputSourceT& source) +template +void xerces_wrapper::parse(InputSourceT& source) { // if no stream is open, let Xerces deal with it if(source.getByteStream() == 0) @@ -1086,10 +1093,10 @@ void xerces_wrapper::parse(InputSourceT& source) } // if ... } // parse -template +template bool xerces_wrapper::parseFirst(InputSourceT& input, - XMLPScanToken& toFill) + T0, T1>::parseFirst(InputSourceT& input, + XMLPScanToken& toFill) { std::auto_ptr newToken(new XercesXMLPScanToken); // To store the result from Xerces parseFirst(). @@ -1119,8 +1126,8 @@ bool xerces_wrapper -bool xerces_wrapper::parseNext(XMLPScanToken& token) +template +bool xerces_wrapper::parseNext(XMLPScanToken& token) { // Extract the XercesXMLPScanToken from within token. XercesXMLPScanToken* xercesToken = @@ -1138,8 +1145,8 @@ bool xerces_wrapper::parseNext(XMLPScanToken& toke } } // parseNext -template -void xerces_wrapper::parseReset(XMLPScanToken& token) +template +void xerces_wrapper::parseReset(XMLPScanToken& token) { // Extract the XercesXMLPScanToken from within token. XercesXMLPScanToken* xercesToken = diff --git a/Utils/StringAdaptor.h b/Utils/StringAdaptor.h index bbed7907..d59a9387 100644 --- a/Utils/StringAdaptor.h +++ b/Utils/StringAdaptor.h @@ -8,17 +8,12 @@ #include #include #include - +#include namespace Arabica { -//forward decl -template -class default_string_adaptor -{ -}; - +template class default_string_adaptor; template class default_string_adaptor_base @@ -98,12 +93,11 @@ public: }; // class default_string_adaptor_base - - - // specialize for std::string and std::wstring template<> -class default_string_adaptor : public default_string_adaptor_base +class default_string_adaptor : + public string_adaptor_tag, + public default_string_adaptor_base { public: @@ -112,32 +106,17 @@ public: static std::string construct_from_utf8(const char* str) { return str ? std::string(str) : std::string(); - } // makeStringT + } // construct_from_utf8 static std::string construct_from_utf8(const char* str, int length) { return std::string(str, length); - } // makeStringT + } // construct_from_utf8 static const std::string& asStdString(const std::string& str) { return str; - } // toStdString - - static string_type makeStringT(const const_iterator& first, const const_iterator& last) - { - return string_type(first, last); - } - - static string_type makeStringT(const char* str) - { - return construct_from_utf8(str); - } - - static string_type makeStringT(const char* str, int len) - { - return construct_from_utf8(str, len); - } + } // asStdString #ifndef ARABICA_NO_WCHAR_T static std::string construct_from_utf16(const wchar_t* str) @@ -174,7 +153,9 @@ public: #ifndef ARABICA_NO_WCHAR_T template<> -class default_string_adaptor : public default_string_adaptor_base +class default_string_adaptor : + public string_adaptor_tag, + public default_string_adaptor_base { public: @@ -209,21 +190,6 @@ public: return std::wstring(str, length); } - static string_type makeStringT(const const_iterator& first, const const_iterator& last) - { - return string_type(first, last); - } - - static string_type makeStringT(const char* str) - { - return construct_from_utf8(str); - } - - static string_type makeStringT(const char* str, int len) - { - return construct_from_utf8(str, len); - } - static std::string asStdString(const std::wstring& str) { narrower_t n; diff --git a/Utils/getparam.hpp b/Utils/getparam.hpp new file mode 100644 index 00000000..1bec885a --- /dev/null +++ b/Utils/getparam.hpp @@ -0,0 +1,29 @@ +#ifndef ARABICA_UTILS_GET_PARAM_HPP +#define ARABICA_UTILS_GET_PARAM_HPP + +#include +#include + +namespace Arabica +{ + +struct nil_t { }; + +template +struct get_param +{ + typedef typename boost::mpl::if_< + boost::is_base_and_derived + , T0 + , typename boost::mpl::if_< + boost::is_base_and_derived + , T1 + , DefaultT + >::type + >::type type; +}; // get_param + +} // namespace Arabica + +#endif + diff --git a/Utils/stringadaptortag.hpp b/Utils/stringadaptortag.hpp new file mode 100644 index 00000000..28bee614 --- /dev/null +++ b/Utils/stringadaptortag.hpp @@ -0,0 +1,11 @@ +#ifndef ARABICA_STRING_ADAPTOR_TAG_HPP +#define ARABICA_STRING_ADAPTOR_TAG_HPP + +namespace Arabica +{ + +struct string_adaptor_tag { }; + +} // namespace Arabica + +#endif diff --git a/test/silly_string/silly_string.cpp b/test/silly_string/silly_string.cpp index e38ba2d7..1c94502d 100644 --- a/test/silly_string/silly_string.cpp +++ b/test/silly_string/silly_string.cpp @@ -2,6 +2,7 @@ #include #include +#include silly_string::silly_string() { @@ -127,3 +128,12 @@ std::string silly_string_adaptor::asStdString(const silly_string& str) { return str.s_; } // asStdString + +std::wstring silly_string_adaptor::asStdWString(const silly_string& str) +{ + Arabica::convert::basic_oconvertstream, + wchar_t, std::char_traits > widener; + widener.imbue(std::locale(widener.getloc(), new Arabica::convert::ucs2utf8codecvt())); + widener.str(str.s_); + return widener.str(); +} // asStdWString diff --git a/test/silly_string/silly_string.hpp b/test/silly_string/silly_string.hpp index e60f9d31..5cde236f 100644 --- a/test/silly_string/silly_string.hpp +++ b/test/silly_string/silly_string.hpp @@ -3,6 +3,7 @@ #include #include +#include // testing purposes only // a string with as minimal interface as possible @@ -24,7 +25,7 @@ private: friend class silly_string_adaptor; }; // class silly_string -class silly_string_adaptor +class silly_string_adaptor : public Arabica::string_adaptor_tag { public: typedef silly_string string_type; @@ -72,8 +73,9 @@ public: static const_iterator end(const silly_string& str) { return str.s_.end(); } static mutable_iterator end(silly_string& str) { return str.s_.end(); } - // only used to constuct error strings - don't have to be highly efficient! + // mainly used to constuct error strings - don't have to be highly efficient! static std::string asStdString(const silly_string& str); + static std::wstring asStdWString(const silly_string& str); }; // class silly_string_adaptor template