Porting to GCC 2.95.

Changes are required for the old version of libg++ which does not support:
* std::wstring
* locale

Changes include:
* #if/#endif removal of code which won't compile.
* Addition of a xerces_string_adaptor which doesn't need locale.
This commit is contained in:
pwalford 2002-10-08 03:09:56 +00:00
parent f77cfbd71d
commit f4c48fb092
16 changed files with 180 additions and 4 deletions

View file

@ -224,7 +224,9 @@ public:
}; // class Attributes
typedef basic_Attributes<std::string> Attributes;
#if !(__GNUG__ && (__GNUC__ < 3))
typedef basic_Attributes<std::wstring> wAttributes;
#endif // !(__GNUG__ && (__GNUC__ < 3))
}; // namespace SAX

View file

@ -331,7 +331,9 @@ public:
}; // class basic_ContentHandler
typedef basic_ContentHandler<std::string> ContentHandler;
#if !(__GNUG__ && (__GNUC__ < 3))
typedef basic_ContentHandler<std::wstring> wContentHandler;
#endif // !(__GNUG__ && (__GNUC__ < 3))
}; // namespace SAX

View file

@ -118,7 +118,9 @@ public:
}; // class basic_DTDHandler
typedef basic_DTDHandler<std::string> DTDHandler;
#if !(__GNUG__ && (__GNUC__ < 3))
typedef basic_DTDHandler<std::wstring> wDTDHandler;
#endif // !(__GNUG__ && (__GNUC__ < 3))
}; // namespace SAX

View file

@ -107,7 +107,9 @@ public:
}; // class EntityResolver
typedef basic_EntityResolver<std::string> EntityResolver;
#if !(__GNUG__ && (__GNUC__ < 3))
typedef basic_EntityResolver<std::wstring> wEntityResolver;
#endif // !(__GNUG__ && (__GNUC__ < 3))
}; // namespace SAX

View file

@ -302,7 +302,9 @@ void basic_InputSource<charT, traitsT, allocatorT>::setCharacterStream(charStrea
typedef basic_InputSource<std::string> InputSource;
#if !(__GNUG__ && (__GNUC__ < 3))
typedef basic_InputSource<std::wstring> wInputSource;
#endif // !(__GNUG__ && (__GNUC__ < 3))
}; // namespace SAX

View file

@ -121,7 +121,9 @@ public:
}; // class Locator
typedef basic_Locator<std::string> Locator;
#if !(__GNUG__ && (__GNUC__ < 3))
typedef basic_Locator<std::wstring> wLocator;
#endif // !(__GNUG__ && (__GNUC__ < 3))
}; // namespace SAX

View file

@ -153,7 +153,9 @@ private:
}; // class basic_SAXParseException
typedef basic_SAXParseException<std::string> SAXParseException;
#if !(__GNUG__ && (__GNUC__ < 3))
typedef basic_SAXParseException<std::wstring> wSAXParseException;
#endif // !(__GNUG__ && (__GNUC__ < 3))
}; // namespace SAX

View file

@ -62,7 +62,9 @@ public:
}; // class basic_XMLFilter
typedef basic_XMLFilter<std::string> XMLFilter;
#if !(__GNUG__ && (__GNUC__ < 3))
typedef basic_XMLFilter<std::wstring> wXMLFilter;
#endif // !(__GNUG__ && (__GNUC__ < 3))
}; // namespace SAX

View file

@ -126,7 +126,9 @@ public:
}; // class basic_DeclHandler
typedef basic_DeclHandler<std::string> DeclHandler;
#if !(__GNUG__ && (__GNUC__ < 3))
typedef basic_DeclHandler<std::wstring> wDeclHandler;
#endif // !(__GNUG__ && (__GNUC__ < 3))
}; // namespace SAX

View file

@ -268,7 +268,9 @@ private:
}; // class basic_DefaultHandler
typedef basic_DefaultHandler2<std::string> DefaultHandler2;
#if !(__GNUG__ && (__GNUC__ < 3))
typedef basic_DefaultHandler2<std::wstring> wDefaultHandler2;
#endif // !(__GNUG__ && (__GNUC__ < 3))
} // namespace SAX

View file

@ -186,7 +186,9 @@ public:
}; // class basic_LexicalHandler
typedef basic_LexicalHandler<std::string> LexicalHandler;
#if !(__GNUG__ && (__GNUC__ < 3))
typedef basic_LexicalHandler<std::wstring> wLexicalHandler;
#endif // !(__GNUG__ && (__GNUC__ < 3))
}; // namespace SAX

View file

@ -368,7 +368,9 @@ private:
}; // class basic_DefaultHandler
typedef basic_DefaultHandler<std::string> DefaultHandler;
#if !(__GNUG__ && (__GNUC__ < 3))
typedef basic_DefaultHandler<std::wstring> wDefaultHandler;
#endif // !(__GNUG__ && (__GNUC__ < 3))
} // namespace SAX

View file

@ -5,7 +5,11 @@
#pragma warning(disable: 4786)
#include <SAX/helpers/InputSourceResolver.h>
#if !(__GNUG__ && (__GNUC__ < 3))
#include <istream>
#else
#include <istream.h>
#endif // !(__GNUG__ && (__GNUC__ < 3))
#include <fstream>
#include <Utils/socket_stream.h>
@ -111,6 +115,7 @@ namespace
static bool fileReg = InputSourceResolver::registerResolver("file", fileResolver);
#if !(__GNUG__ && (__GNUC__ < 3))
std::istream* httpResolver(const std::string& httpURL)
{
#ifdef _MSC_VER
@ -152,6 +157,7 @@ namespace
} // httpResolver
static bool httpReg = InputSourceResolver::registerResolver("http", httpResolver);
#endif // !(__GNUG__ && (__GNUC__ < 3))
} // namespace
// end of file

View file

@ -26,17 +26,22 @@ public:
// only used to constuct error strings - don't have to be highly efficient!
std::string asStdString(const stringT& str) const;
#if !(__GNUG__ && (__GNUC__ < 3))
std::wstring asStdWString(const stringT& str) const;
#endif // !(__GNUG__ && (__GNUC__ < 3))
}; // class default_string_maker
// specialize for std::string and std::wstring
template<>
class default_string_adaptor<std::string>
{
#if !(__GNUG__ && (__GNUC__ < 3))
private:
typedef basic_iconvertstream<wchar_t, std::char_traits<wchar_t>,
char, std::char_traits<char> > widener;
typedef basic_oconvertstream<wchar_t, std::char_traits<wchar_t>,
char, std::char_traits<char> > narrower;
#endif // !(__GNUG__ && (__GNUC__ < 3))
public:
char makeValueT(char c) const { return c; }
@ -48,6 +53,7 @@ public:
{
return std::string(str, length);
} // makeStringT
#if !(__GNUG__ && (__GNUC__ < 3))
std::string makeStringT(const wchar_t* str) const
{
std::wstring s;
@ -61,39 +67,50 @@ public:
n_.str(std::wstring(str, length));
return n_.str();
} // makeStringT
#endif // !(__GNUG__ && (__GNUC__ < 3))
const std::string& asStdString(const std::string& str) const
{
return str;
} // toStdString
#if !(__GNUG__ && (__GNUC__ < 3))
std::wstring asStdWString(const std::string& str) const
{
w_.str(str);
return w_.str();
} // toStdWString
#endif // !(__GNUG__ && (__GNUC__ < 3))
default_string_adaptor() :
default_string_adaptor()
#if !(__GNUG__ && (__GNUC__ < 3))
#ifndef _MSC_VER
loc_(std::locale(), new utf16utf8_codecvt()),
: loc_(std::locale(), new utf16utf8_codecvt()),
#else
loc_(std::_Addfac(std::locale(), new utf16utf8_codecvt)),
: loc_(std::_Addfac(std::locale(), new utf16utf8_codecvt)),
#endif
n_(),
w_()
#endif // !(__GNUG__ && (__GNUC__ < 3))
{
#if !(__GNUG__ && (__GNUC__ < 3))
n_.imbue(loc_);
w_.imbue(loc_);
#endif // !(__GNUG__ && (__GNUC__ < 3))
} // default_string_adaptor
private:
#if !(__GNUG__ && (__GNUC__ < 3))
std::locale loc_;
mutable narrower n_;
mutable widener w_;
#endif // !(__GNUG__ && (__GNUC__ < 3))
}; // class default_string_adaptor
#if !(__GNUG__ && (__GNUC__ < 3))
template<>
class default_string_adaptor<std::wstring>
{
private:
typedef basic_iconvertstream<wchar_t, std::char_traits<wchar_t>,
char, std::char_traits<char> > widener;
typedef basic_oconvertstream<wchar_t, std::char_traits<wchar_t>,
@ -154,6 +171,7 @@ private:
mutable narrower n_;
mutable widener w_;
}; // class default_string_adaptor
#endif // !(__GNUG__ && (__GNUC__ < 3))
} // namespace SAX

View file

@ -488,7 +488,9 @@ private:
}; // class basic_XMLFilter
typedef basic_XMLFilterImpl<std::string> XMLFilterImpl;
#if !(__GNUG__ && (__GNUC__ < 3))
typedef basic_XMLFilterImpl<std::wstring> wXMLFilterImpl;
#endif // !(__GNUG__ && (__GNUC__ < 3))
}; // namespace SAX

View file

@ -34,6 +34,9 @@
#include <xercesc/sax/SAXParseException.hpp>
#include <xercesc/util/BinInputStream.hpp>
#include <xercesc/sax/InputSource.hpp>
#ifdef (__GNUG__ && (__GNUC__ < 3))
#include <xercesc/util/TransService.hpp>
#endif
namespace SAX
@ -140,18 +143,28 @@ class xerces_wrapper : public SAX::basic_XMLReader<string_type>
///////////////////////////////
// String adaptor for XMLCh
#if !(__GNUG__ && (__GNUC__ < 3))
// * For the null-terminated version, we convert the array of XMLCh to a
// null-terminated vector of wchar_t. We then pass &vector[0] to the
// parent method.
// * For the known length version, we convert the the array of XMLCh to a
// vector of wchar_t. We then pass &vector[0] and length to the parent
// method.
#else
// * For the null-terminated version, we use the Xerces XMLTranscoder
// classes to convert to a null-terminated utf-8 char array. We then
// pass this to the parent method.
// * For the known length version, we copy the array, append a
// null-character and then do the above.
#endif
class xerces_string_adaptor : public string_adaptorT
{
public:
typedef typename stringT::value_type value_type;
typedef string_adaptorT base;
#if !(__GNUG__ && (__GNUC__ < 3))
typedef std::vector<wchar_t> wVector;
stringT makeStringT(const XMLCh* str) const
@ -195,6 +208,99 @@ class xerces_wrapper : public SAX::basic_XMLReader<string_type>
return base::makeStringT("");
}
}
#else
xerces_string_adaptor() : transcoder_(0) { }
~xerces_string_adaptor() { delete transcoder_; }
static const int MAX_BUFFER = 4096;
/* Lazily instantiates a transcoder, but only if
* XMLPlatformUtils::Initialize() has been called.
* @see xerces_initializer */
XMLTranscoder* getTranscoder() const
{
if (!transcoder_)
{
if (xerces_initializer::isInitialized())
{
// NOTE: We are going to assume that result is always "Ok".
::XMLTransService::Codes result;
transcoder_ = ::XMLPlatformUtils::fgTransService->makeNewTranscoderFor(XMLUni::fgUTF8EncodingString, result, MAX_BUFFER);
}
}
return transcoder_;
}
char* transcode(const XMLCh* toTranscode) const
{
if (0 != getTranscoder())
{
vector<XMLByte> final;
vector<XMLByte> toFill(MAX_BUFFER);
unsigned int charsEaten = 1;
while (*toTranscode && charsEaten)
{
unsigned int srcLen = ::XMLString::stringLen(toTranscode);
// Ensure we have enough space.
toFill.resize(MAX_BUFFER);
// Resize to the number of bytes written.
unsigned int size =
getTranscoder()->transcodeTo(toTranscode,
srcLen,
&toFill[0],
MAX_BUFFER,
charsEaten,
::XMLTranscoder::UnRep_RepChar);
toFill.resize(size);
final.insert(final.end(), toFill.begin(), toFill.end());
toTranscode += charsEaten;
}
final.push_back(0);
char *result = new char[final.size()];
memcpy(result, &final[0], final.size()*sizeof(char));
return result;
}
else
{
char *result = ::XMLString::transcode(toTranscode);
return result;
}
}
// Create a string from a zero-terminated array of XMLCh
stringT makeStringT(const XMLCh* str) const
{
if (str)
{
::ArrayJanitor<char> buffer(transcode(str));
return base::makeStringT(&buffer[0]);
}
else
{
return base::makeStringT("");
}
}
// Create a string from a given number of XMLCh within an array
stringT makeStringT(const XMLCh* str, int length) const
{
if (str && length)
{
std::vector<XMLCh> nullTerminated(length+1);
nullTerminated.assign(str, str+length+1);
nullTerminated.push_back(0);
::ArrayJanitor<char> buffer(transcode(&nullTerminated[0]));
return base::makeStringT(&buffer[0]);
}
else
{
return base::makeStringT("");
}
}
#endif
XMLCh* asXMLChString(const stringT& s) const
{
@ -202,6 +308,10 @@ class xerces_wrapper : public SAX::basic_XMLReader<string_type>
return ::XMLString::transcode(str.c_str());
}
#if (__GNUG__ && (__GNUC__ < 3))
private:
mutable XMLTranscoder* transcoder_;
#endif
};
///////////////////////////////
@ -505,6 +615,7 @@ class xerces_wrapper : public SAX::basic_XMLReader<string_type>
typedef void(SAX::ErrorHandler::* ErrorFn)(const SAX::SAXParseException&);
void handleError(const ::SAXParseException& exception, ErrorFn fn)
{
if(!errorHandler_)
return;
@ -791,7 +902,15 @@ void xerces_wrapper<stringT, string_adaptorT>::doSetProperty(const stringT& name
SAX::basic_XMLReader<stringT>::Property<lexicalHandlerT&>* prop = dynamic_cast<SAX::basic_XMLReader<stringT>::Property<lexicalHandlerT&>*>(value.get());
if(!prop)
#if (__GNUG__)
#if (__GNUC__ < 3)
throw std::runtime_error("Property LexicalHandler is wrong type, should be SAX::LexicalHandler&");
#else // (__GNUC__ < 3)
throw std::bad_cast();
#endif // (__GNUC__ < 3)
#else (__GNUG__)
throw std::bad_cast("Property LexicalHandler is wrong type, should be SAX::LexicalHandler&");
#endif (__GNUG__)
lexicalHandlerAdaptor_.setLexicalHandler(prop->get());
return;
@ -801,8 +920,15 @@ void xerces_wrapper<stringT, string_adaptorT>::doSetProperty(const stringT& name
SAX::basic_XMLReader<stringT>::Property<SAX::basic_DeclHandler<stringT>&>* prop = dynamic_cast<SAX::basic_XMLReader<stringT>::Property<SAX::basic_DeclHandler<stringT>&>*>(value.get());
if(!prop)
#if (__GNUG__)
#if (__GNUC__ < 3)
throw std::runtime_error("Property DeclHandler is wrong type, should be SAX::DeclHandler&");
#else // (__GNUC__ < 3)
throw std::bad_cast();
#endif // (__GNUC__ < 3)
#else (__GNUG__)
throw std::bad_cast("Property DeclHandler is wrong type, should be SAX::DeclHandler&");
#endif (__GNUG__)
declHandlerAdaptor_.setDeclHandler(prop->get());
return;
} // if ...