all SAX classes now take both string_type and string_adaptor. everything builds through. tests pass

This commit is contained in:
jez 2007-09-06 18:54:02 +00:00
parent 8e0c0ec4f0
commit bbcf3e1001
11 changed files with 75 additions and 86 deletions

View file

@ -23,17 +23,18 @@ namespace SAX2DOM
template<class stringT,
class string_adaptorT = Arabica::default_string_adaptor<stringT>,
class SAX_parser = Arabica::SAX::XMLReader<stringT, string_adaptorT> >
class Parser : protected Arabica::SAX::DefaultHandler<stringT>
class Parser : protected Arabica::SAX::DefaultHandler<stringT, string_adaptorT>
{
typedef Arabica::SAX::EntityResolver<stringT> EntityResolverT;
typedef Arabica::SAX::ErrorHandler<stringT> ErrorHandlerT;
typedef Arabica::SAX::LexicalHandler<stringT> LexicalHandlerT;
typedef Arabica::SAX::DeclHandler<stringT> DeclHandlerT;
typedef Arabica::SAX::InputSource<stringT> InputSourceT;
typedef Arabica::SAX::Attributes<stringT, string_adaptorT> AttributesT;
typedef Arabica::SAX::EntityResolver<stringT, string_adaptorT> EntityResolverT;
typedef Arabica::SAX::ErrorHandler<stringT, string_adaptorT> ErrorHandlerT;
typedef Arabica::SAX::LexicalHandler<stringT, string_adaptorT> LexicalHandlerT;
typedef Arabica::SAX::DeclHandler<stringT, string_adaptorT> DeclHandlerT;
typedef Arabica::SAX::InputSource<stringT, string_adaptorT> InputSourceT;
typedef Arabica::SimpleDOM::EntityImpl<stringT, string_adaptorT> EntityT;
typedef Arabica::SimpleDOM::NotationImpl<stringT, string_adaptorT> NotationT;
typedef Arabica::SimpleDOM::ElementImpl<stringT, string_adaptorT> ElementT;
typedef typename Arabica::SAX::ErrorHandler<stringT>::SAXParseExceptionT SAXParseExceptionT;
typedef typename ErrorHandlerT::SAXParseExceptionT SAXParseExceptionT;
public:
Parser() :
@ -93,8 +94,8 @@ class Parser : protected Arabica::SAX::DefaultHandler<stringT>
if(entityResolver_)
parser.setEntityResolver(*entityResolver_);
setParserProperty<LexicalHandlerT>(parser, pNames.lexicalHandler);
setParserProperty<DeclHandlerT>(parser, pNames.declHandler);
parser.setLexicalHandler(*this);
parser.setDeclHandler(*this);
setParserFeatures(parser);
@ -156,20 +157,6 @@ class Parser : protected Arabica::SAX::DefaultHandler<stringT>
Arabica::SAX::AttributeTypes<stringT, string_adaptorT> attributeTypes_;
protected:
template<class interfaceT>
void setParserProperty(SAX_parser& parser, const stringT& propertyName)
{
try {
#ifndef __BORLANDC__
// this line causes a crash with BCB 6 => may be a compiler bug
parser.setProperty(propertyName, static_cast<interfaceT&>(*this));
#else
parser.setProperty(propertyName, *(interfaceT*)this);
#endif
} // try
catch(Arabica::SAX::SAXException&) { }
} // setParserProperty
void setParserFeatures(SAX_parser& parser) const
{
for(typename Features::const_iterator f = features_.begin(), e = features_.end(); f != e; ++f)
@ -187,7 +174,7 @@ class Parser : protected Arabica::SAX::DefaultHandler<stringT>
} // endDocument
virtual void startElement(const stringT& namespaceURI, const stringT& localName,
const stringT& qName, const Arabica::SAX::Attributes<stringT>& atts)
const stringT& qName, const AttributesT& atts)
{
if(currentNode_ == 0)
return;

View file

@ -12,24 +12,25 @@ namespace Arabica
namespace SAX
{
template<class string_type, class string_adaptor = Arabica::default_string_adaptor<string_type> >
class NamespaceTracker : public XMLFilterImpl<string_type, string_adaptor>
template<class string_type, class T0 = Arabica::nil_t, class T1 = Arabica::nil_t>
class NamespaceTracker : public XMLFilterImpl<string_type, T0, T1>
{
typedef XMLFilterImpl<string_type, T0, T1> XMLFilterT;
typedef typename XMLFilterT::string_adaptor string_adaptor;
typedef NamespaceSupport<string_type, string_adaptor> NamespaceSupportT;
typedef typename NamespaceSupportT::stringListT stringListT;
typedef XMLFilterImpl<string_type, string_adaptor> XMLFilterT;
public:
typedef XMLReaderInterface<string_type, string_adaptor> XMLReaderT;
typedef XMLReaderInterface<string_type, T0, T1> XMLReaderT;
typedef Attributes<string_type, string_adaptor> AttributesT;
NamespaceTracker() :
XMLFilterImpl<string_type, string_adaptor>()
XMLFilterT()
{
} // NamespaceTracker
NamespaceTracker(XMLReaderT& parent) :
XMLFilterImpl<string_type, string_adaptor>(parent)
XMLFilterT(parent)
{
} // NamespaceTracker

View file

@ -11,18 +11,17 @@ namespace Arabica
namespace SAX
{
template<class string_type, class string_adaptor>
class PYXWriter : public XMLFilterImpl<string_type, string_adaptor>
template<class string_type, class T0 = Arabica::nil_t, class T1 = Arabica::nil_t>
class PYXWriter : public XMLFilterImpl<string_type, T0, T1>
{
public:
typedef string_type stringT;
typedef PYXWriter<string_type, string_adaptor> PYXWriterT;
typedef XMLReaderInterface<string_type, T0, T1> XMLReaderT;
typedef XMLFilterImpl<string_type, T0, T1> XMLFilterT;
typedef typename XMLFilterT::AttributesT AttributesT;
typedef typename XMLFilterT::string_adaptor string_adaptor;
typedef typename string_type::value_type charT;
typedef typename string_type::traits_type traitsT;
typedef std::basic_ostream<charT, traitsT> ostreamT;
typedef XMLReaderInterface<string_type, string_adaptor> XMLReaderT;
typedef XMLFilterImpl<string_type, string_adaptor> XMLFilterT;
typedef typename XMLFilterImpl<string_type, string_adaptor>::AttributesT AttributesT;
typedef Arabica::Unicode<charT> UnicodeT;
private:
using XMLFilterT::getParent;
@ -42,23 +41,23 @@ class PYXWriter : public XMLFilterImpl<string_type, string_adaptor>
public:
// ContentHandler
virtual void startElement(const stringT& namespaceURI, const stringT& localName,
const stringT& qName, const AttributesT& atts);
virtual void endElement(const stringT& namespaceURI, const stringT& localName,
const stringT& qName);
virtual void characters(const stringT& ch);
virtual void processingInstruction(const stringT& target, const stringT& data);
virtual void startElement(const string_type& namespaceURI, const string_type& localName,
const string_type& qName, const AttributesT& atts);
virtual void endElement(const string_type& namespaceURI, const string_type& localName,
const string_type& qName);
virtual void characters(const string_type& ch);
virtual void processingInstruction(const string_type& target, const string_type& data);
private:
void escape(const stringT& ch);
void escape(const string_type& ch);
ostreamT* stream_;
}; // class PYXWriter
template<class string_type, class string_adaptor>>
void PYXWriter<string_type, string_adaptor>::startElement(
const stringT& namespaceURI, const stringT& localName,
const stringT& qName, const AttributesT& atts)
template<class string_type, class T0, class T1>
void PYXWriter<string_type, T0, T1>::startElement(
const string_type& namespaceURI, const string_type& localName,
const string_type& qName, const AttributesT& atts)
{
*stream_ << UnicodeT::LEFT_PARENTHESIS << localName << std::endl;
for(int i = 0; i < atts.getLength(); ++i)
@ -72,18 +71,18 @@ void PYXWriter<string_type, string_adaptor>::startElement(
XMLFilterT::startElement(namespaceURI, localName, qName, atts);
} // startElement
template<class string_type, class string_adaptor>>
void PYXWriter<string_type, string_adaptor>::endElement(
const stringT& namespaceURI, const stringT& localName,
const stringT& qName)
template<class string_type, class T0, class T1>
void PYXWriter<string_type, T0, T1>::endElement(
const string_type& namespaceURI, const string_type& localName,
const string_type& qName)
{
*stream_ << UnicodeT::RIGHT_PARENTHESIS << localName << std::endl;
XMLFilterT::endElement(namespaceURI, localName, qName);
} // endElement
template<class string_type, class string_adaptor>>
void PYXWriter<string_type, string_adaptor>::characters(const stringT& ch)
template<class string_type, class T0, class T1>
void PYXWriter<string_type, T0, T1>::characters(const string_type& ch)
{
*stream_ << UnicodeT::HYPHEN_MINUS;
escape(ch);
@ -92,8 +91,8 @@ void PYXWriter<string_type, string_adaptor>::characters(const stringT& ch)
XMLFilterT::characters(ch);
} // characters
template<class string_type, class string_adaptor>>
void PYXWriter<string_type, string_adaptor>::processingInstruction(const stringT& target, const stringT& data)
template<class string_type, class T0, class T1>
void PYXWriter<string_type, T0, T1>::processingInstruction(const string_type& target, const string_type& data)
{
*stream_ << UnicodeT::QUESTION_MARK << target
<< UnicodeT::SPACE << data
@ -102,10 +101,10 @@ void PYXWriter<string_type, string_adaptor>::processingInstruction(const stringT
XMLFilterT::processingInstruction(target, data);
} // processingInstruction
template<class string_type, class string_adaptor>>
void PYXWriter<string_type, string_adaptor>::escape(const stringT& ch)
template<class string_type, class T0, class T1>
void PYXWriter<string_type, T0, T1>::escape(const string_type& ch)
{
for(typename stringT::const_iterator s = ch.begin(), se = ch.end(); s != se; ++s)
for(typename string_type::const_iterator s = ch.begin(), se = ch.end(); s != se; ++s)
if(*s == UnicodeT::LINE_FEED)
*stream_ << UnicodeT::BACK_SLASH << UnicodeT::LOWERCASE_N;
else

View file

@ -16,13 +16,14 @@ namespace SAX
an issue, and sometimes it makes things a little awkward.
This filter buffers up multiple calls to characters(...) and reports text in a single lump.
*/
template<class string_type, class string_adaptor = Arabica::default_string_adaptor<string_type> >
class TextCoalescer : public XMLFilterImpl<string_type, string_adaptor>
template<class string_type, class T0 = Arabica::nil_t, class T1 = Arabica::nil_t>
class TextCoalescer : public XMLFilterImpl<string_type, T0, T1>
{
typedef XMLFilterImpl<string_type, string_adaptor> XMLFilterT;
typedef XMLFilterImpl<string_type, T0, T1> XMLFilterT;
typedef typename XMLFilterT::string_adaptor string_adaptor;
public:
typedef XMLReaderInterface<string_type, string_adaptor>XMLReaderT;
typedef XMLReaderInterface<string_type, T0, T1> XMLReaderT;
typedef Attributes<string_type, string_adaptor> AttributesT;
TextCoalescer() :

View file

@ -13,7 +13,7 @@ namespace SAX
/**
Strips out everything except startDocument, endDocument and text
*/
template<class string_type, class string_adaptor = Arabica::default_string_adaptor<string_type> >
template<class string_type, class T0 = Arabica::nil_t, class T1 = Arabica::nil_t>
class TextOnly : public XMLFilterImpl<string_type, string_adaptor>
{
typedef XMLFilterImpl<string_type, string_adaptor> XMLFilterT;

View file

@ -10,30 +10,30 @@ namespace Arabica
namespace SAX
{
template<class string_type, class string_adaptor = Arabica::default_string_adaptor<string_type> >
class WhitespaceStripper : public SAX::XMLFilterImpl<string_type, string_adaptor>
template<class string_type, class T0 = Arabica::nil_t, class T1 = Arabica::nil_t>
class WhitespaceStripper : public SAX::XMLFilterImpl<string_type, T0, T1>
{
public:
typedef string_type stringT;
typedef SAX::XMLFilterImpl<string_type, string_adaptor> baseT;
typedef SAX::XMLReader<string_type, string_adaptor> XMLReaderT;
typedef SAX::XMLReader<string_type, T0, T1> XMLReaderT;
typedef SAX::XMLFilterImpl<string_type, T0, T1> XMLFilterT;
typedef typename XMLFilterT::string_adaptor string_adaptor;
WhitespaceStripper() :
baseT()
XMLFilterT()
{
} // WhitespaceStripper
WhitespaceStripper(XMLReaderT& parent) :
baseT(parent)
XMLFilterT(parent)
{
} // WhitespaceStripper
virtual void characters(const stringT& ch)
virtual void characters(const string_type& ch)
{
baseT::characters(Arabica::string::normalize_whitespace<string_type, string_adaptor>(ch));
XMLFilterT::characters(Arabica::string::normalize_whitespace<string_type, string_adaptor>(ch));
} // characters
virtual void ignorableWhitespace(const stringT& ch)
virtual void ignorableWhitespace(const string_type& ch)
{
} // ignorableWhitespace
}; // class WhitespaceStripper

View file

@ -11,26 +11,27 @@ namespace Arabica
namespace SAX
{
template<class string_type, class string_adaptor = Arabica::default_string_adaptor<string_type> >
class XMLBaseTracker : public XMLFilterImpl<string_type, string_adaptor>
template<class string_type, class T0 = Arabica::nil_t, class T1 = Arabica::nil_t>
class XMLBaseTracker : public XMLFilterImpl<string_type, T0, T1>
{
typedef XMLFilterImpl<string_type, T0, T1> XMLFilterT;
typedef typename XMLFilterT::string_adaptor string_adaptor;
typedef XMLBaseSupport<string_type, string_adaptor> XMLBaseSupportT;
typedef XMLFilterImpl<string_type, string_adaptor> XMLFilterT;
public:
typedef XMLReaderInterface<string_type, string_adaptor> XMLReaderT;
typedef XMLReaderInterface<string_type, T0, T1> XMLReaderT;
typedef Locator<string_type, string_adaptor> LocatorT;
typedef Attributes<string_type, string_adaptor> AttributesT;
XMLBaseTracker() :
XMLFilterImpl<string_type, string_adaptor>(),
XMLFilterT(),
locator_(0),
base_set_(false)
{
} // XMLBaseTracker
XMLBaseTracker(XMLReaderT& parent) :
XMLFilterImpl<string_type, string_adaptor>(parent),
XMLFilterT(parent),
locator_(0),
base_set_(false)
{

View file

@ -77,7 +77,7 @@ public:
}
} // startElement
virtual void startPrefixMapping(const stringT& prefix, const stringT& uri)
virtual void startPrefixMapping(const std::string& prefix, const std::string& uri)
{
context_->parentHandler().startPrefixMapping(prefix, uri);
} // startPrefixMapping

View file

@ -305,7 +305,7 @@ private:
int pending_attribute_;
std::string name_;
std::string namespaceURI_;
SAX::AttributesImpl<std::string> atts_;
SAX::AttributesImpl<std::string, Arabica::default_string_adaptor<std::string> > atts_;
std::stringstream buffer_;
bool text_mode_;
NamespaceStack namespaceStack_;

View file

@ -28,8 +28,8 @@ class SAX2DOMTest : public TestCase
std::stringstream ss;
ss << SA::asStdString(str);
Arabica::SAX::InputSource<string_type> is(ss);
Arabica::SAX::CatchErrorHandler<string_type> eh;
Arabica::SAX::InputSource<string_type, string_adaptor> is(ss);
Arabica::SAX::CatchErrorHandler<string_type, string_adaptor> eh;
Arabica::SAX2DOM::Parser<string_type, string_adaptor> parser;
parser.setErrorHandler(eh);
parser.parse(is);

View file

@ -28,8 +28,8 @@ class TreeWalkerTest : public TestCase
std::stringstream ss;
ss << SA::asStdString(str);
Arabica::SAX::InputSource<string_type> is(ss);
Arabica::SAX::CatchErrorHandler<string_type> eh;
Arabica::SAX::InputSource<string_type, string_adaptor> is(ss);
Arabica::SAX::CatchErrorHandler<string_type, string_adaptor> eh;
Arabica::SAX2DOM::Parser<string_type, string_adaptor> parser;
parser.setErrorHandler(eh);
parser.parse(is);