Added third template parameter to wrappers, together with a bit of

meta-programming magic so that everything builds through with MSXML.

See http://www.jezuk.co.uk/cgi-bin/view/SAX/news?id=2713 for details of
the problem.

This may break VC6, but I haven't checked
This commit is contained in:
jez_higgins 2005-12-07 10:51:00 +00:00
parent a36a7adde7
commit 35acd2eea7
12 changed files with 274 additions and 214 deletions

View file

@ -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

View file

@ -77,8 +77,8 @@ ifndef NO_DEFAULT_PARSER
ifdef DEF_SAX_P
namespace SAX
{
template<class string_type, class string_adaptor = Arabica::default_string_adaptor<string_type> >
class XMLReader : public DEF_SAX_P<string_type, string_adaptor> { };
template<class string_type, class T0 = Arabica::nil_t, class T1 = Arabica::nil_t>
class XMLReader : public DEF_SAX_P<string_type, T0, T1> { };
} // namespace SAX
else
error "No default parser defined."

View file

@ -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 @@
<File
RelativePath="..\Utils\convertstream.h">
</File>
<File
RelativePath=".\Utils\getparam.hpp">
</File>
<File
RelativePath="..\Utils\iso88591utf8codecvt.cpp">
</File>
@ -378,6 +383,15 @@
<File
RelativePath="..\Utils\StringAdaptor.h">
</File>
<File
RelativePath="..\Utils\stringadaptortag.hpp">
</File>
<File
RelativePath="..\Utils\ucs2utf8codecvt.cpp">
</File>
<File
RelativePath="..\Utils\ucs2utf8codecvt.hpp">
</File>
<File
RelativePath="..\XML\UnicodeCharacters.h">
</File>

View file

@ -26,6 +26,7 @@
#include <SAX/helpers/AttributeDefaults.h>
#include <typeinfo>
#include <map>
#include <Utils/getparam.hpp>
namespace SAX
{
@ -196,13 +197,19 @@ private:
* @version $Id$
* @see SAX::basic_XMLReader
*/
template<class string_type, class string_adaptor_type = Arabica::default_string_adaptor<string_type> >
template<class string_type,
class T0 = Arabica::nil_t,
class T1 = Arabica::nil_t>
class expat_wrapper : public SAX::basic_XMLReader<string_type>,
public SAX::basic_Locator<string_type>,
public expat_wrapper_impl_mumbojumbo::expat2base
{
public:
typedef string_type stringT;
typedef typename Arabica::get_param<Arabica::string_adaptor_tag,
Arabica::default_string_adaptor<string_type>,
T0,
T1>::type string_adaptor_type;
typedef string_adaptor_type string_adaptorT;
typedef string_adaptor_type SA;
typedef SAX::basic_EntityResolver<stringT> entityResolverT;
@ -339,8 +346,8 @@ class expat_wrapper : public SAX::basic_XMLReader<string_type>,
//////////////////////////////////////////////////////////////////
// expat wrapper definition
template<class stringT, class string_adaptorT>
expat_wrapper<stringT, string_adaptorT>::expat_wrapper() :
template<class stringT, class T0, class T1>
expat_wrapper<stringT, T0, T1>::expat_wrapper() :
entityResolver_(0),
dtdHandler_(0),
contentHandler_(0),
@ -367,14 +374,14 @@ expat_wrapper<stringT, string_adaptorT>::expat_wrapper() :
XML_SetProcessingInstructionHandler(parser_, expat_wrapper_impl_mumbojumbo::ewim_processingInstruction);
} // expat
template<class stringT, class string_adaptorT>
expat_wrapper<stringT, string_adaptorT>::~expat_wrapper()
template<class stringT, class T0, class T1>
expat_wrapper<stringT, T0, T1>::~expat_wrapper()
{
XML_ParserFree(parser_);
} // ~expat
template<class stringT, class string_adaptorT>
void expat_wrapper<stringT, string_adaptorT>::setFeature(const stringT& name, bool value)
template<class stringT, class T0, class T1>
void expat_wrapper<stringT, T0, T1>::setFeature(const stringT& name, bool value)
{
if(name == features_.namespaces)
{
@ -415,8 +422,8 @@ void expat_wrapper<stringT, string_adaptorT>::setFeature(const stringT& name, bo
}
} // setFeature
template<class stringT, class string_adaptorT>
bool expat_wrapper<stringT, string_adaptorT>::getFeature(const stringT& name) const
template<class stringT, class T0, class T1>
bool expat_wrapper<stringT, T0, T1>::getFeature(const stringT& name) const
{
if(name == features_.namespaces)
return namespaces_;
@ -433,8 +440,8 @@ bool expat_wrapper<stringT, string_adaptorT>::getFeature(const stringT& name) co
throw SAX::SAXNotRecognizedException(std::string("Feature not recognized ") + SA::asStdString(name));
} // getFeature
template<class stringT, class string_adaptorT>
void expat_wrapper<stringT, string_adaptorT>::parse(inputSourceT& source)
template<class stringT, class T0, class T1>
void expat_wrapper<stringT, T0, T1>::parse(inputSourceT& source)
{
publicId_ = source.getPublicId();
systemId_ = source.getSystemId();
@ -457,8 +464,8 @@ void expat_wrapper<stringT, string_adaptorT>::parse(inputSourceT& source)
parsing_ = false;
} // parse
template<class stringT, class string_adaptorT>
bool expat_wrapper<stringT, string_adaptorT>::do_parse(inputSourceT& source, XML_Parser parser)
template<class stringT, class T0, class T1>
bool expat_wrapper<stringT, T0, T1>::do_parse(inputSourceT& source, XML_Parser parser)
{
InputSourceResolver is(source, string_adaptorT());
if(is.resolve() == 0)
@ -489,11 +496,11 @@ bool expat_wrapper<stringT, string_adaptorT>::do_parse(inputSourceT& source, XML
return true;
} // do_parse
template<class stringT, class string_adaptorT>
template<class stringT, class T0, class T1>
#ifndef ARABICA_VS6_WORKAROUND
std::auto_ptr<typename expat_wrapper<stringT, string_adaptorT>::PropertyBaseT> expat_wrapper<stringT, string_adaptorT>::doGetProperty(const stringT& name)
std::auto_ptr<typename expat_wrapper<stringT, T0, T1>::PropertyBaseT> expat_wrapper<stringT, T0, T1>::doGetProperty(const stringT& name)
#else
std::auto_ptr<expat_wrapper<stringT, string_adaptorT>::PropertyBaseT> expat_wrapper<stringT, string_adaptorT>::doGetProperty(const stringT& name)
std::auto_ptr<expat_wrapper<stringT, T0, T1>::PropertyBaseT> expat_wrapper<stringT, T0, T1>::doGetProperty(const stringT& name)
#endif
{
if(name == properties_.lexicalHandler)
@ -510,8 +517,8 @@ std::auto_ptr<expat_wrapper<stringT, string_adaptorT>::PropertyBaseT> expat_wrap
throw SAX::SAXNotRecognizedException(std::string("Property not recognized ") + SA::asStdString(name));
} // doGetProperty
template<class stringT, class string_adaptorT>
void expat_wrapper<stringT, string_adaptorT>::doSetProperty(const stringT& name, std::auto_ptr<PropertyBaseT> value)
template<class stringT, class T0, class T1>
void expat_wrapper<stringT, T0, T1>::doSetProperty(const stringT& name, std::auto_ptr<PropertyBaseT> value)
{
if(name == properties_.lexicalHandler)
{
@ -540,32 +547,32 @@ void expat_wrapper<stringT, string_adaptorT>::doSetProperty(const stringT& name,
} // doSetProperty
// Locator implementation
template<class stringT, class string_adaptorT>
stringT expat_wrapper<stringT, string_adaptorT>::getPublicId() const
template<class stringT, class T0, class T1>
stringT expat_wrapper<stringT, T0, T1>::getPublicId() const
{
return publicId_;
} // getPublicId
template<class stringT, class string_adaptorT>
stringT expat_wrapper<stringT, string_adaptorT>::getSystemId() const
template<class stringT, class T0, class T1>
stringT expat_wrapper<stringT, T0, T1>::getSystemId() const
{
return systemId_;
} // getSystemId
template<class stringT, class string_adaptorT>
int expat_wrapper<stringT, string_adaptorT>::getLineNumber() const
template<class stringT, class T0, class T1>
int expat_wrapper<stringT, T0, T1>::getLineNumber() const
{
return XML_GetCurrentLineNumber(parser_);
} // getLineNumber
template<class stringT, class string_adaptorT>
int expat_wrapper<stringT, string_adaptorT>::getColumnNumber() const
template<class stringT, class T0, class T1>
int expat_wrapper<stringT, T0, T1>::getColumnNumber() const
{
return XML_GetCurrentColumnNumber(parser_);
} // getColumnNumber
template<class stringT, class string_adaptorT>
typename SAX::basic_NamespaceSupport<stringT, string_adaptorT>::Parts expat_wrapper<stringT, string_adaptorT>::processName(const stringT& qName, bool isAttribute)
template<class stringT, class T0, class T1>
typename SAX::basic_NamespaceSupport<stringT, typename expat_wrapper<stringT, T0, T1>::string_adaptorT>::Parts expat_wrapper<stringT, T0, T1>::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<stringT, string_adaptorT>::Parts expat_wrap
return p;
} // processName
template<class stringT, class string_adaptorT>
void expat_wrapper<stringT, string_adaptorT>::reportError(const std::string& message, bool fatal)
template<class stringT, class T0, class T1>
void expat_wrapper<stringT, T0, T1>::reportError(const std::string& message, bool fatal)
{
if(!errorHandler_)
return;
@ -590,8 +597,8 @@ void expat_wrapper<stringT, string_adaptorT>::reportError(const std::string& mes
errorHandler_->error(e);
} // reportError
template<class stringT, class string_adaptorT>
void expat_wrapper<stringT, string_adaptorT>::checkNotParsing(const stringT& type, const stringT& name) const
template<class stringT, class T0, class T1>
void expat_wrapper<stringT, T0, T1>::checkNotParsing(const stringT& type, const stringT& name) const
{
if(parsing_)
{
@ -601,16 +608,16 @@ void expat_wrapper<stringT, string_adaptorT>::checkNotParsing(const stringT& typ
} // if(parsing_)
} // checkNotParsing
template<class stringT, class string_adaptorT>
void expat_wrapper<stringT, string_adaptorT>::charHandler(const char* txt, int txtlen)
template<class stringT, class T0, class T1>
void expat_wrapper<stringT, T0, T1>::charHandler(const char* txt, int txtlen)
{
if(!contentHandler_)
return;
contentHandler_->characters(SA::construct_from_utf8(txt, txtlen));
} // charHandler
template<class stringT, class string_adaptorT>
void expat_wrapper<stringT, string_adaptorT>::startElement(const char* qName, const char** atts)
template<class stringT, class T0, class T1>
void expat_wrapper<stringT, T0, T1>::startElement(const char* qName, const char** atts)
{
if(!contentHandler_)
return;
@ -672,8 +679,8 @@ void expat_wrapper<stringT, string_adaptorT>::startElement(const char* qName, co
contentHandler_->startElement(name.URI, name.localName, name.rawName, attributes);
} // startElement
template<class stringT, class string_adaptorT>
void expat_wrapper<stringT, string_adaptorT>::startElementNoNS(const char* qName, const char** atts)
template<class stringT, class T0, class T1>
void expat_wrapper<stringT, T0, T1>::startElementNoNS(const char* qName, const char** atts)
{
SAX::basic_AttributesImpl<stringT> attributes;
@ -691,8 +698,8 @@ void expat_wrapper<stringT, string_adaptorT>::startElementNoNS(const char* qName
contentHandler_->startElement(emptyString_, emptyString_, SA::construct_from_utf8(qName), attributes);
} // startElementNoNS
template<class stringT, class string_adaptorT>
void expat_wrapper<stringT, string_adaptorT>::endElement(const char* qName)
template<class stringT, class T0, class T1>
void expat_wrapper<stringT, T0, T1>::endElement(const char* qName)
{
if(!contentHandler_)
return;
@ -711,22 +718,22 @@ void expat_wrapper<stringT, string_adaptorT>::endElement(const char* qName)
nsSupport_.popContext();
} // endElement
template<class stringT, class string_adaptorT>
void expat_wrapper<stringT, string_adaptorT>::endElementNoNS(const char* qName)
template<class stringT, class T0, class T1>
void expat_wrapper<stringT, T0, T1>::endElementNoNS(const char* qName)
{
if(contentHandler_)
contentHandler_->endElement(emptyString_, emptyString_, SA::construct_from_utf8(qName));
} // endElementNoNS
template<class stringT, class string_adaptorT>
void expat_wrapper<stringT, string_adaptorT>::processingInstruction(const char* target, const char* data)
template<class stringT, class T0, class T1>
void expat_wrapper<stringT, T0, T1>::processingInstruction(const char* target, const char* data)
{
if(contentHandler_)
contentHandler_->processingInstruction(SA::construct_from_utf8(target), SA::construct_from_utf8(data));
} // processingInstruction
template<class stringT, class string_adaptorT>
void expat_wrapper<stringT, string_adaptorT>::elementDeclaration(const XML_Char* name,
template<class stringT, class T0, class T1>
void expat_wrapper<stringT, T0, T1>::elementDeclaration(const XML_Char* name,
const XML_Content* model)
{
if(!declHandler_)
@ -737,8 +744,8 @@ void expat_wrapper<stringT, string_adaptorT>::elementDeclaration(const XML_Char*
declHandler_->elementDecl(SA::construct_from_utf8(name), SA::construct_from_utf8(os.str().c_str()));
} // elementDeclaration
template<class stringT, class string_adaptorT>
void expat_wrapper<stringT, string_adaptorT>::convertXML_Content(std::ostream& os, const XML_Content* model, bool isChild)
template<class stringT, class T0, class T1>
void expat_wrapper<stringT, T0, T1>::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<class stringT, class string_adaptorT>
void expat_wrapper<stringT, string_adaptorT>::attListDeclaration(const XML_Char* elname,
template<class stringT, class T0, class T1>
void expat_wrapper<stringT, T0, T1>::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<stringT, string_adaptorT>::attListDeclaration(const XML_Char*
}
} // attListDeclaration
template<class stringT, class string_adaptorT>
void expat_wrapper<stringT, string_adaptorT>::entityDeclaration(const XML_Char* entityName,
template<class stringT, class T0, class T1>
void expat_wrapper<stringT, T0, T1>::entityDeclaration(const XML_Char* entityName,
int is_parameter_entity,
const XML_Char* value,
int value_length,
@ -920,8 +927,8 @@ void expat_wrapper<stringT, string_adaptorT>::entityDeclaration(const XML_Char*
}
} // entityDeclaration
template<class stringT, class string_adaptorT>
void expat_wrapper<stringT, string_adaptorT>::notationDeclaration(const XML_Char* notationName,
template<class stringT, class T0, class T1>
void expat_wrapper<stringT, T0, T1>::notationDeclaration(const XML_Char* notationName,
const XML_Char* base,
const XML_Char* systemId,
const XML_Char* publicId)
@ -933,8 +940,8 @@ void expat_wrapper<stringT, string_adaptorT>::notationDeclaration(const XML_Char
SA::construct_from_utf8(systemId));
} // notationDeclaration
template<class stringT, class string_adaptorT>
void expat_wrapper<stringT, string_adaptorT>::startDoctypeDecl(const XML_Char *doctypeName,
template<class stringT, class T0, class T1>
void expat_wrapper<stringT, T0, T1>::startDoctypeDecl(const XML_Char *doctypeName,
const XML_Char *systemId,
const XML_Char *publicId,
int has_internal_subset)
@ -952,36 +959,36 @@ void expat_wrapper<stringT, string_adaptorT>::startDoctypeDecl(const XML_Char *d
s_systemId);
} // startDoctypeDecl
template<class stringT, class string_adaptorT>
void expat_wrapper<stringT, string_adaptorT>::endDoctypeDecl()
template<class stringT, class T0, class T1>
void expat_wrapper<stringT, T0, T1>::endDoctypeDecl()
{
if(lexicalHandler_)
lexicalHandler_->endDTD();
} // endDoctypeDecl
template<class stringT, class string_adaptorT>
void expat_wrapper<stringT, string_adaptorT>::startCdataSection()
template<class stringT, class T0, class T1>
void expat_wrapper<stringT, T0, T1>::startCdataSection()
{
if(lexicalHandler_)
lexicalHandler_->startCDATA();
} // startCdataSection
template<class stringT, class string_adaptorT>
void expat_wrapper<stringT, string_adaptorT>::endCdataSection()
template<class stringT, class T0, class T1>
void expat_wrapper<stringT, T0, T1>::endCdataSection()
{
if(lexicalHandler_)
lexicalHandler_->endCDATA();
} // endCdataSection
template<class stringT, class string_adaptorT>
void expat_wrapper<stringT, string_adaptorT>::commentHandler(const XML_Char *data)
template<class stringT, class T0, class T1>
void expat_wrapper<stringT, T0, T1>::commentHandler(const XML_Char *data)
{
if(lexicalHandler_)
lexicalHandler_->comment(SA::construct_from_utf8(data));
} // commentHandler
template<class stringT, class string_adaptorT>
int expat_wrapper<stringT, string_adaptorT>::externalEntityRefHandler(XML_Parser parser,
template<class stringT, class T0, class T1>
int expat_wrapper<stringT, T0, T1>::externalEntityRefHandler(XML_Parser parser,
const XML_Char* context,
const XML_Char* base,
const XML_Char* systemId,

View file

@ -27,6 +27,7 @@
#include <SAX/helpers/AttributeTypes.h>
#include <SAX/helpers/InputSourceResolver.h>
#include <SAX/helpers/AttributesImpl.h>
#include <Utils/getparam.hpp>
namespace SAX
{
@ -108,13 +109,19 @@ xmlSAXHandler* lwit_SaxHandler();
} // namespace libxml2_wrapper_impl_tiddle
template<class string_type, class string_adaptor_type = Arabica::default_string_adaptor<string_type> >
template<class string_type,
class T0 = Arabica::nil_t,
class T1 = Arabica::nil_t>
class libxml2_wrapper : public basic_XMLReader<string_type>,
public basic_Locator<string_type>,
protected libxml2_wrapper_impl_tiddle::libxml2_base
{
public:
typedef string_type stringT;
typedef typename Arabica::get_param<Arabica::string_adaptor_tag,
Arabica::default_string_adaptor<string_type>,
T0,
T1>::type string_adaptor_type;
typedef string_adaptor_type string_adaptorT;
typedef SAX::basic_EntityResolver<stringT> entityResolverT;
typedef SAX::basic_DTDHandler<stringT> dtdHandlerT;
@ -219,8 +226,8 @@ class libxml2_wrapper : public basic_XMLReader<string_type>,
const AttributeTypes<stringT, string_adaptorT> attrTypes_;
}; // class libxml2_wrapper
template<class stringT, class string_adaptorT>
libxml2_wrapper<stringT, string_adaptorT>::libxml2_wrapper() :
template<class stringT, class T0, class T1>
libxml2_wrapper<stringT, T0, T1>::libxml2_wrapper() :
entityResolver_(0),
dtdHandler_(0),
contentHandler_(0),
@ -239,14 +246,14 @@ libxml2_wrapper<stringT, string_adaptorT>::libxml2_wrapper() :
xmlCtxtUseOptions(context_, XML_PARSE_DTDLOAD + XML_PARSE_DTDVALID + XML_PARSE_NOBLANKS);
} // libxml2_wrapper
template<class stringT, class string_adaptorT>
libxml2_wrapper<stringT, string_adaptorT>::~libxml2_wrapper()
template<class stringT, class T0, class T1>
libxml2_wrapper<stringT, T0, T1>::~libxml2_wrapper()
{
xmlFreeParserCtxt(context_);
} // ~libxml2_wrapper
template<class stringT, class string_adaptorT>
bool libxml2_wrapper<stringT, string_adaptorT>::getFeature(const stringT& name) const
template<class stringT, class T0, class T1>
bool libxml2_wrapper<stringT, T0, T1>::getFeature(const stringT& name) const
{
if(name == features_.namespaces)
return namespaces_;
@ -270,8 +277,8 @@ bool libxml2_wrapper<stringT, string_adaptorT>::getFeature(const stringT& name)
}
} // getFeature
template<class stringT, class string_adaptorT>
void libxml2_wrapper<stringT, string_adaptorT>::setFeature(const stringT& name, bool value)
template<class stringT, class T0, class T1>
void libxml2_wrapper<stringT, T0, T1>::setFeature(const stringT& name, bool value)
{
if(name == features_.namespaces)
{
@ -317,11 +324,11 @@ void libxml2_wrapper<stringT, string_adaptorT>::setFeature(const stringT& name,
}
} // setFeature
template<class stringT, class string_adaptorT>
template<class stringT, class T0, class T1>
#ifndef ARABICA_VS6_WORKAROUND
std::auto_ptr<typename libxml2_wrapper<stringT, string_adaptorT>::PropertyBaseT> libxml2_wrapper<stringT, string_adaptorT>::doGetProperty(const stringT& name)
std::auto_ptr<typename libxml2_wrapper<stringT, T0, T1>::PropertyBaseT> libxml2_wrapper<stringT, T0, T1>::doGetProperty(const stringT& name)
#else
std::auto_ptr<libxml2_wrapper<stringT, string_adaptorT>::PropertyBaseT> libxml2_wrapper<stringT, string_adaptorT>::doGetProperty(const stringT& name)
std::auto_ptr<libxml2_wrapper<stringT, T0, T1>::PropertyBaseT> libxml2_wrapper<stringT, T0, T1>::doGetProperty(const stringT& name)
#endif
{
if(name == properties_.declHandler)
@ -335,8 +342,8 @@ std::auto_ptr<libxml2_wrapper<stringT, string_adaptorT>::PropertyBaseT> libxml2_
throw SAX::SAXNotRecognizedException(std::string("Property not recognized ") + string_adaptorT::asStdString(name));
} // doGetProperty
template<class stringT, class string_adaptorT>
void libxml2_wrapper<stringT, string_adaptorT>::doSetProperty(const stringT& name, std::auto_ptr<PropertyBaseT> value)
template<class stringT, class T0, class T1>
void libxml2_wrapper<stringT, T0, T1>::doSetProperty(const stringT& name, std::auto_ptr<PropertyBaseT> value)
{
if(name == properties_.declHandler)
{
@ -353,8 +360,8 @@ void libxml2_wrapper<stringT, string_adaptorT>::doSetProperty(const stringT& nam
throw SAX::SAXNotRecognizedException(std::string("Property not recognized ") + string_adaptorT::asStdString(name));
} // doSetProperty
template<class stringT, class string_adaptorT>
typename basic_NamespaceSupport<stringT, string_adaptorT>::Parts libxml2_wrapper<stringT, string_adaptorT>::processName(const stringT& qName, bool isAttribute)
template<class stringT, class T0, class T1>
typename SAX::basic_NamespaceSupport<stringT, typename libxml2_wrapper<stringT, T0, T1>::string_adaptorT>::Parts libxml2_wrapper<stringT, T0, T1>::processName(const stringT& qName, bool isAttribute)
{
typename basic_NamespaceSupport<stringT, string_adaptorT>::Parts p =
nsSupport_.processName(qName, isAttribute);
@ -363,8 +370,8 @@ typename basic_NamespaceSupport<stringT, string_adaptorT>::Parts libxml2_wrapper
return p;
} // processName
template<class stringT, class string_adaptorT>
void libxml2_wrapper<stringT, string_adaptorT>::reportError(const std::string& message, bool fatal)
template<class stringT, class T0, class T1>
void libxml2_wrapper<stringT, T0, T1>::reportError(const std::string& message, bool fatal)
{
if(!errorHandler_)
return;
@ -376,8 +383,8 @@ void libxml2_wrapper<stringT, string_adaptorT>::reportError(const std::string& m
errorHandler_->error(e);
} // reportError
template<class stringT, class string_adaptorT>
void libxml2_wrapper<stringT, string_adaptorT>::checkNotParsing(const stringT& type, const stringT& name) const
template<class stringT, class T0, class T1>
void libxml2_wrapper<stringT, T0, T1>::checkNotParsing(const stringT& type, const stringT& name) const
{
if(parsing_)
{
@ -387,40 +394,40 @@ void libxml2_wrapper<stringT, string_adaptorT>::checkNotParsing(const stringT& t
} // if(parsing_)
} // checkNotParsing
template<class stringT, class string_adaptorT>
stringT libxml2_wrapper<stringT, string_adaptorT>::getPublicId() const
template<class stringT, class T0, class T1>
stringT libxml2_wrapper<stringT, T0, T1>::getPublicId() const
{
if(locator_)
return string_adaptorT::construct_from_utf8(reinterpret_cast<const char*>(locator_->getPublicId(context_)));
return stringT();
} // getPublicId
template<class stringT, class string_adaptorT>
stringT libxml2_wrapper<stringT, string_adaptorT>::getSystemId() const
template<class stringT, class T0, class T1>
stringT libxml2_wrapper<stringT, T0, T1>::getSystemId() const
{
if(locator_)
return string_adaptorT::construct_from_utf8(reinterpret_cast<const char*>(locator_->getSystemId(context_)));
return stringT();
} // getSystemId
template<class stringT, class string_adaptorT>
int libxml2_wrapper<stringT, string_adaptorT>::getLineNumber() const
template<class stringT, class T0, class T1>
int libxml2_wrapper<stringT, T0, T1>::getLineNumber() const
{
if(locator_)
return locator_->getLineNumber(context_);
return -1;
} // getLineNumber
template<class stringT, class string_adaptorT>
int libxml2_wrapper<stringT, string_adaptorT>::getColumnNumber() const
template<class stringT, class T0, class T1>
int libxml2_wrapper<stringT, T0, T1>::getColumnNumber() const
{
if(locator_)
return locator_->getColumnNumber(context_);
return -1;
} // getColumnNumber
template<class stringT, class string_adaptorT>
void libxml2_wrapper<stringT, string_adaptorT>::parse(basic_InputSource<stringT>& source)
template<class stringT, class T0, class T1>
void libxml2_wrapper<stringT, T0, T1>::parse(basic_InputSource<stringT>& source)
{
if(contentHandler_)
contentHandler_->setDocumentLocator(*this);
@ -441,65 +448,65 @@ void libxml2_wrapper<stringT, string_adaptorT>::parse(basic_InputSource<stringT>
parsing_ = false;
} // parse
template<class stringT, class string_adaptorT>
void libxml2_wrapper<stringT, string_adaptorT>::SAXstartDocument()
template<class stringT, class T0, class T1>
void libxml2_wrapper<stringT, T0, T1>::SAXstartDocument()
{
if(contentHandler_)
contentHandler_->startDocument();
} // SAXstartDocument
template<class stringT, class string_adaptorT>
void libxml2_wrapper<stringT, string_adaptorT>::SAXendDocument()
template<class stringT, class T0, class T1>
void libxml2_wrapper<stringT, T0, T1>::SAXendDocument()
{
if(contentHandler_)
contentHandler_->endDocument();
} // SAXendDocument
template<class stringT, class string_adaptorT>
void libxml2_wrapper<stringT, string_adaptorT>::SAXcharacters(const xmlChar* ch, int len)
template<class stringT, class T0, class T1>
void libxml2_wrapper<stringT, T0, T1>::SAXcharacters(const xmlChar* ch, int len)
{
if(contentHandler_)
contentHandler_->characters(string_adaptorT::construct_from_utf8(reinterpret_cast<const char*>(ch), len));
} // SAXcharacters
template<class stringT, class string_adaptorT>
void libxml2_wrapper<stringT, string_adaptorT>::SAXignorableWhitespace(const xmlChar* ch, int len)
template<class stringT, class T0, class T1>
void libxml2_wrapper<stringT, T0, T1>::SAXignorableWhitespace(const xmlChar* ch, int len)
{
if(contentHandler_)
contentHandler_->ignorableWhitespace(string_adaptorT::construct_from_utf8(reinterpret_cast<const char*>(ch), len));
} // SAXignorableWhitespace
template<class stringT, class string_adaptorT>
void libxml2_wrapper<stringT, string_adaptorT>::SAXwarning(const std::string& warning)
template<class stringT, class T0, class T1>
void libxml2_wrapper<stringT, T0, T1>::SAXwarning(const std::string& warning)
{
if(errorHandler_)
errorHandler_->warning(basic_SAXParseException<stringT>(warning, *this));
} // warning
template<class stringT, class string_adaptorT>
void libxml2_wrapper<stringT, string_adaptorT>::SAXerror(const std::string& error)
template<class stringT, class T0, class T1>
void libxml2_wrapper<stringT, T0, T1>::SAXerror(const std::string& error)
{
if(errorHandler_)
errorHandler_->error(basic_SAXParseException<stringT>(error, *this));
} // error
template<class stringT, class string_adaptorT>
void libxml2_wrapper<stringT, string_adaptorT>::SAXfatalError(const std::string& fatal)
template<class stringT, class T0, class T1>
void libxml2_wrapper<stringT, T0, T1>::SAXfatalError(const std::string& fatal)
{
if(errorHandler_)
errorHandler_->fatalError(basic_SAXParseException<stringT>(fatal, *this));
} // fatal
template<class stringT, class string_adaptorT>
void libxml2_wrapper<stringT, string_adaptorT>::SAXprocessingInstruction(const xmlChar* target, const xmlChar* data)
template<class stringT, class T0, class T1>
void libxml2_wrapper<stringT, T0, T1>::SAXprocessingInstruction(const xmlChar* target, const xmlChar* data)
{
if(contentHandler_)
contentHandler_->processingInstruction(string_adaptorT::construct_from_utf8(reinterpret_cast<const char*>(target)),
string_adaptorT::construct_from_utf8(reinterpret_cast<const char*>(data)));
} // SAXprocessingInstruction
template<class stringT, class string_adaptorT>
void libxml2_wrapper<stringT, string_adaptorT>::SAXstartElement(const xmlChar* qName, const xmlChar** atts)
template<class stringT, class T0, class T1>
void libxml2_wrapper<stringT, T0, T1>::SAXstartElement(const xmlChar* qName, const xmlChar** atts)
{
if(!contentHandler_)
return;
@ -561,8 +568,8 @@ void libxml2_wrapper<stringT, string_adaptorT>::SAXstartElement(const xmlChar* q
contentHandler_->startElement(name.URI, name.localName, name.rawName, attributes);
} // SAXstartElement
template<class stringT, class string_adaptorT>
void libxml2_wrapper<stringT, string_adaptorT>::SAXstartElementNoNS(const xmlChar* qName, const xmlChar** atts)
template<class stringT, class T0, class T1>
void libxml2_wrapper<stringT, T0, T1>::SAXstartElementNoNS(const xmlChar* qName, const xmlChar** atts)
{
SAX::basic_AttributesImpl<stringT> attributes;
@ -580,8 +587,8 @@ void libxml2_wrapper<stringT, string_adaptorT>::SAXstartElementNoNS(const xmlCha
contentHandler_->startElement(emptyString_, emptyString_, string_adaptorT::construct_from_utf8((reinterpret_cast<const char*>(qName))), attributes);
} // SAXstartElementNoNS
template<class stringT, class string_adaptorT>
void libxml2_wrapper<stringT, string_adaptorT>::SAXendElement(const xmlChar* qName)
template<class stringT, class T0, class T1>
void libxml2_wrapper<stringT, T0, T1>::SAXendElement(const xmlChar* qName)
{
if(!contentHandler_)
return;
@ -600,15 +607,15 @@ void libxml2_wrapper<stringT, string_adaptorT>::SAXendElement(const xmlChar* qNa
nsSupport_.popContext();
} // SAXendElement
template<class stringT, class string_adaptorT>
void libxml2_wrapper<stringT, string_adaptorT>::SAXendElementNoNS(const xmlChar* qName)
template<class stringT, class T0, class T1>
void libxml2_wrapper<stringT, T0, T1>::SAXendElementNoNS(const xmlChar* qName)
{
if(contentHandler_)
contentHandler_->endElement(emptyString_, emptyString_, string_adaptorT::construct_from_utf8(reinterpret_cast<const char*>(qName)));
} // SAXendElementNoNS
template<class stringT, class string_adaptorT>
void libxml2_wrapper<stringT, string_adaptorT>::SAXnotationDecl(const xmlChar *name, const xmlChar *publicId, const xmlChar *systemId)
template<class stringT, class T0, class T1>
void libxml2_wrapper<stringT, T0, T1>::SAXnotationDecl(const xmlChar *name, const xmlChar *publicId, const xmlChar *systemId)
{
if(dtdHandler_)
dtdHandler_->notationDecl(string_adaptorT::construct_from_utf8(reinterpret_cast<const char*>(name)),
@ -616,8 +623,8 @@ void libxml2_wrapper<stringT, string_adaptorT>::SAXnotationDecl(const xmlChar *n
string_adaptorT::construct_from_utf8(reinterpret_cast<const char*>(systemId)));
} // SAXnotationDecl
template<class stringT, class string_adaptorT>
void libxml2_wrapper<stringT, string_adaptorT>::SAXunparsedEntityDecl(const xmlChar *name, const xmlChar *publicId, const xmlChar *systemId, const xmlChar *notationName)
template<class stringT, class T0, class T1>
void libxml2_wrapper<stringT, T0, T1>::SAXunparsedEntityDecl(const xmlChar *name, const xmlChar *publicId, const xmlChar *systemId, const xmlChar *notationName)
{
if(dtdHandler_)
dtdHandler_->unparsedEntityDecl(string_adaptorT::construct_from_utf8(reinterpret_cast<const char*>(name)),
@ -626,8 +633,8 @@ void libxml2_wrapper<stringT, string_adaptorT>::SAXunparsedEntityDecl(const xmlC
string_adaptorT::construct_from_utf8(reinterpret_cast<const char*>(notationName)));
} // SAXunparsedEntityDecl
template<class stringT, class string_adaptorT>
void libxml2_wrapper<stringT, string_adaptorT>::SAXelementDecl(const xmlChar* name, int type, xmlElementContentPtr content)
template<class stringT, class T0, class T1>
void libxml2_wrapper<stringT, T0, T1>::SAXelementDecl(const xmlChar* name, int type, xmlElementContentPtr content)
{
if(!declHandler_)
return;
@ -637,8 +644,8 @@ void libxml2_wrapper<stringT, string_adaptorT>::SAXelementDecl(const xmlChar* na
declHandler_->elementDecl(string_adaptorT::construct_from_utf8(reinterpret_cast<const char*>(name)), string_adaptorT::construct_from_utf8(os.str().c_str()));
} // elementDeclaration
template<class stringT, class string_adaptorT>
void libxml2_wrapper<stringT, string_adaptorT>::convertXML_Content(std::ostream& os, int type, xmlElementContentPtr model, bool isChild) const
template<class stringT, class T0, class T1>
void libxml2_wrapper<stringT, T0, T1>::convertXML_Content(std::ostream& os, int type, xmlElementContentPtr model, bool isChild) const
{
char concatenator = ' ';
@ -710,8 +717,8 @@ void libxml2_wrapper<stringT, string_adaptorT>::convertXML_Content(std::ostream&
} // switch
} // convertXML_Content
template<class stringT, class string_adaptorT>
void libxml2_wrapper<stringT, string_adaptorT>::SAXattributeDecl(const xmlChar *elem, const xmlChar *fullname, int type, int def, const xmlChar *defaultValue, xmlEnumerationPtr tree)
template<class stringT, class T0, class T1>
void libxml2_wrapper<stringT, T0, T1>::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<stringT, string_adaptorT>::SAXattributeDecl(const xmlChar *
string_adaptorT::construct_from_utf8(reinterpret_cast<const char*>(defaultValue)));
} // SAXattributeDecl
template<class stringT, class string_adaptorT>
stringT libxml2_wrapper<stringT, string_adaptorT>::stringAttrEnum(xmlEnumerationPtr tree, bool leadingSpace) const
template<class stringT, class T0, class T1>
stringT libxml2_wrapper<stringT, T0, T1>::stringAttrEnum(xmlEnumerationPtr tree, bool leadingSpace) const
{
std::ostringstream os;
if(leadingSpace)
@ -782,8 +789,8 @@ stringT libxml2_wrapper<stringT, string_adaptorT>::stringAttrEnum(xmlEnumeratio
return string_adaptorT::construct_from_utf8(os.str().c_str());
} // stringAttrEnum
template<class stringT, class string_adaptorT>
void libxml2_wrapper<stringT, string_adaptorT>::SAXentityDecl(const xmlChar *name, int type, const xmlChar *publicId, const xmlChar *systemId, xmlChar *content)
template<class stringT, class T0, class T1>
void libxml2_wrapper<stringT, T0, T1>::SAXentityDecl(const xmlChar *name, int type, const xmlChar *publicId, const xmlChar *systemId, xmlChar *content)
{
if(!declHandler_)
return;
@ -802,8 +809,8 @@ void libxml2_wrapper<stringT, string_adaptorT>::SAXentityDecl(const xmlChar *nam
} // switch
} // SAXentityDecl
template<class stringT, class string_adaptorT>
xmlParserInputPtr libxml2_wrapper<stringT, string_adaptorT>::SAXresolveEntity(const xmlChar* publicId, const xmlChar* systemId)
template<class stringT, class T0, class T1>
xmlParserInputPtr libxml2_wrapper<stringT, T0, T1>::SAXresolveEntity(const xmlChar* publicId, const xmlChar* systemId)
{
if(!entityResolver_)
return xmlLoadExternalEntity(reinterpret_cast<const char*>(systemId),

View file

@ -33,6 +33,7 @@
#include <SAX/helpers/PropertyNames.h>
#include <Utils/StringAdaptor.h>
#include <iostream>
#include <Utils/getparam.hpp>
// Include the MSXML definitions.
#include <msxml2.h>
@ -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 string_type,
class COMInitializer_type = COMSingleThreadInitializer,
class string_adaptor_type = Arabica::default_string_adaptor<string_type> >
class T0 = Arabica::nil_t,
class T1 = Arabica::nil_t>
class msxml2_wrapper : public SAX::basic_XMLReader<string_type>
{
typedef typename Arabica::get_param<COMInitializer_tag, COMSingleThreadInitializer, T0, T1>::type COMInitializer_type;
typedef typename Arabica::get_param<Arabica::string_adaptor_tag, Arabica::default_string_adaptor<string_type>, T0, T1>::type string_adaptor_type;
public:
typedef string_type stringT;
typedef string_adaptor_type string_adaptorT;

View file

@ -52,6 +52,7 @@ std::ostream& operator<<(std::ostream& o, const std::type_info& ti)
#include <SAX/IStreamHandle.h>
#include <SAX/wrappers/XercesPropertyNames.h>
#include <SAX/wrappers/XercesFeatureNames.h>
#include <Utils/getparam.hpp>
// Xerces Includes
#include <xercesc/util/PlatformUtils.hpp>
@ -116,10 +117,16 @@ namespace XercesImpl
}; // class xerces_initializer
} // namespace XercesImpl
template<class string_type, class string_adaptor_type = Arabica::default_string_adaptor<string_type> >
template<class string_type,
class T0 = Arabica::nil_t,
class T1 = Arabica::nil_t>
class xerces_wrapper : public SAX::basic_ProgressiveParser<string_type>
{
private:
typedef typename Arabica::get_param<Arabica::string_adaptor_tag,
Arabica::default_string_adaptor<string_type>,
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>
string_type externalNoNamespaceSchemaLocation_;
}; // class xerces_wrapper
template<class string_type, class string_adaptorT>
xerces_wrapper<string_type, string_adaptorT>::xerces_wrapper()
template<class string_type, class T0, class T1>
xerces_wrapper<string_type, T0, T1>::xerces_wrapper()
{
try
{
@ -871,14 +878,14 @@ xerces_wrapper<string_type, string_adaptorT>::xerces_wrapper()
xerces_->setDeclarationHandler(&declHandlerAdaptor_);
} // xerces_wrapper
template<class string_type, class string_adaptorT>
xerces_wrapper<string_type, string_adaptorT>::~xerces_wrapper()
template<class string_type, class T0, class T1>
xerces_wrapper<string_type, T0, T1>::~xerces_wrapper()
{
delete xerces_;
} // ~xerces_wrapper
template<class string_type, class string_adaptorT>
bool xerces_wrapper<string_type, string_adaptorT>::getFeature(const string_type& name) const
template<class string_type, class T0, class T1>
bool xerces_wrapper<string_type, T0, T1>::getFeature(const string_type& name) const
{
try
{
@ -895,8 +902,8 @@ bool xerces_wrapper<string_type, string_adaptorT>::getFeature(const string_type&
} // catch(SAXNotRecognizedException& e)
} // getFeature
template<class string_type, class string_adaptorT>
void xerces_wrapper<string_type, string_adaptorT>::setFeature(const string_type& name, bool value)
template<class string_type, class T0, class T1>
void xerces_wrapper<string_type, T0, T1>::setFeature(const string_type& name, bool value)
{
try
{
@ -913,11 +920,11 @@ void xerces_wrapper<string_type, string_adaptorT>::setFeature(const string_type&
} // catch(SAXNotRecognizedException& e)
} // setFeature
template<class string_type, class string_adaptorT>
template<class string_type, class T0, class T1>
#ifndef ARABICA_VS6_WORKAROUND
std::auto_ptr<typename SAX::basic_XMLReader<string_type>::PropertyBase> xerces_wrapper<string_type, string_adaptorT>::doGetProperty(const string_type& name)
std::auto_ptr<typename SAX::basic_XMLReader<string_type>::PropertyBase> xerces_wrapper<string_type, T0, T1>::doGetProperty(const string_type& name)
#else
std::auto_ptr<SAX::basic_XMLReader<string_type>::PropertyBase> xerces_wrapper<string_type, string_adaptorT>::doGetProperty(const string_type& name)
std::auto_ptr<SAX::basic_XMLReader<string_type>::PropertyBase> xerces_wrapper<string_type, T0, T1>::doGetProperty(const string_type& name)
#endif
{
if(name == properties_.lexicalHandler)
@ -981,11 +988,11 @@ std::auto_ptr<SAX::basic_XMLReader<string_type>::PropertyBase> xerces_wrapper<st
throw SAX::SAXNotRecognizedException("Property not recognized ");
} // doGetProperty
template<class string_type, class string_adaptorT>
template<class string_type, class T0, class T1>
#ifndef ARABICA_VS6_WORKAROUND
void xerces_wrapper<string_type, string_adaptorT>::doSetProperty(const string_type& name, std::auto_ptr<typename base::PropertyBase> value)
void xerces_wrapper<string_type, T0, T1>::doSetProperty(const string_type& name, std::auto_ptr<typename base::PropertyBase> value)
#else
void xerces_wrapper<string_type, string_adaptorT>::doSetProperty(const string_type& name, std::auto_ptr<base::PropertyBase> value)
void xerces_wrapper<string_type, T0, T1>::doSetProperty(const string_type& name, std::auto_ptr<base::PropertyBase> value)
#endif
{
if(name == properties_.lexicalHandler)
@ -1072,8 +1079,8 @@ void xerces_wrapper<string_type, string_adaptorT>::doSetProperty(const string_ty
}
template<class string_type, class string_adaptorT>
void xerces_wrapper<string_type, string_adaptorT>::parse(InputSourceT& source)
template<class string_type, class T0, class T1>
void xerces_wrapper<string_type, T0, T1>::parse(InputSourceT& source)
{
// if no stream is open, let Xerces deal with it
if(source.getByteStream() == 0)
@ -1086,10 +1093,10 @@ void xerces_wrapper<string_type, string_adaptorT>::parse(InputSourceT& source)
} // if ...
} // parse
template<class string_type, class string_adaptorT>
template<class string_type, class T0, class T1>
bool xerces_wrapper<string_type,
string_adaptorT>::parseFirst(InputSourceT& input,
XMLPScanToken& toFill)
T0, T1>::parseFirst(InputSourceT& input,
XMLPScanToken& toFill)
{
std::auto_ptr<XercesXMLPScanToken> newToken(new XercesXMLPScanToken);
// To store the result from Xerces parseFirst().
@ -1119,8 +1126,8 @@ bool xerces_wrapper<string_type,
return result;
} // parseFirst
template<class string_type, class string_adaptorT>
bool xerces_wrapper<string_type, string_adaptorT>::parseNext(XMLPScanToken& token)
template<class string_type, class T0, class T1>
bool xerces_wrapper<string_type, T0, T1>::parseNext(XMLPScanToken& token)
{
// Extract the XercesXMLPScanToken from within token.
XercesXMLPScanToken* xercesToken =
@ -1138,8 +1145,8 @@ bool xerces_wrapper<string_type, string_adaptorT>::parseNext(XMLPScanToken& toke
}
} // parseNext
template<class string_type, class string_adaptorT>
void xerces_wrapper<string_type, string_adaptorT>::parseReset(XMLPScanToken& token)
template<class string_type, class T0, class T1>
void xerces_wrapper<string_type, T0, T1>::parseReset(XMLPScanToken& token)
{
// Extract the XercesXMLPScanToken from within token.
XercesXMLPScanToken* xercesToken =

View file

@ -8,17 +8,12 @@
#include <string>
#include <Utils/convertstream.h>
#include <Utils/utf8ucs2codecvt.h>
#include <Utils/stringadaptortag.hpp>
namespace Arabica
{
//forward decl
template<class stringT>
class default_string_adaptor
{
};
template<class stringT> class default_string_adaptor;
template<class stringT>
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<std::string> : public default_string_adaptor_base<std::string>
class default_string_adaptor<std::string> :
public string_adaptor_tag,
public default_string_adaptor_base<std::string>
{
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<std::wstring> : public default_string_adaptor_base<std::wstring>
class default_string_adaptor<std::wstring> :
public string_adaptor_tag,
public default_string_adaptor_base<std::wstring>
{
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;

29
Utils/getparam.hpp Normal file
View file

@ -0,0 +1,29 @@
#ifndef ARABICA_UTILS_GET_PARAM_HPP
#define ARABICA_UTILS_GET_PARAM_HPP
#include <boost/mpl/if.hpp>
#include <boost/type_traits/is_base_and_derived.hpp>
namespace Arabica
{
struct nil_t { };
template <typename BaseT, typename DefaultT, typename T0, typename T1>
struct get_param
{
typedef typename boost::mpl::if_<
boost::is_base_and_derived<BaseT, T0>
, T0
, typename boost::mpl::if_<
boost::is_base_and_derived<BaseT, T1>
, T1
, DefaultT
>::type
>::type type;
}; // get_param
} // namespace Arabica
#endif

View file

@ -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

View file

@ -2,6 +2,7 @@
#include <Utils/convertstream.h>
#include <Utils/utf8ucs2codecvt.h>
#include <Utils/ucs2utf8codecvt.hpp>
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<char, std::char_traits<char>,
wchar_t, std::char_traits<wchar_t> > widener;
widener.imbue(std::locale(widener.getloc(), new Arabica::convert::ucs2utf8codecvt()));
widener.str(str.s_);
return widener.str();
} // asStdWString

View file

@ -3,6 +3,7 @@
#include <string>
#include <functional>
#include <Utils/stringadaptortag.hpp>
// 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<class CharType, class Traits>