#ifndef ARABICA_XSLT_CREATE_HANDLER_HPP #define ARABICA_XSLT_CREATE_HANDLER_HPP #include #include #include #include "../xslt_compilation_context.hpp" #include "../xslt_compiled_stylesheet.hpp" #include "xslt_constants.hpp" namespace Arabica { namespace XSLT { template SAX::DefaultHandler* CreateHandler(CompilationContext& context) { return new Handler(context); } // create template class NotImplementedYetHandler : public SAX::DefaultHandler { public: NotImplementedYetHandler(CompilationContext& /* context */) { } virtual void startElement(const string_type& /* namespaceURI */, const string_type& /* localName */, const string_type& qName, const SAX::Attributes& /* atts */) { throw SAX::SAXException("Haven't implemented " + string_adaptor::asStdString(qName) + " yet"); } // startElement }; // NotImplementedYetHandler template class ChildElementsBuilder; template class ChildElements { public: typedef SAX::DefaultHandler* (*CreateHandlerPtr)(CompilationContext&); static ChildElementsBuilder add(const string_type name, CreateHandlerPtr creator); ChildElements(const ChildElements& rhs) : elementCreators_(rhs.elementCreators_) { } // ChildElements SAX::DefaultHandler* create(const string_type& name, CompilationContext& context) const { CreatorMapIterator i = elementCreators_.find(name); if(i == elementCreators_.end()) return 0; return i->second(context); } // create private: void put(const string_type name, CreateHandlerPtr creator) { elementCreators_[name] = creator; } // put ChildElements() { } typedef std::map CreatorMap; typedef typename std::map::const_iterator CreatorMapIterator; CreatorMap elementCreators_; friend class ChildElementsBuilder; }; // struct ChildElement template class ChildElementsBuilder { public: typedef SAX::DefaultHandler* (*CreateHandlerPtr)(CompilationContext&); operator ChildElements&() { return elements_; } ChildElementsBuilder& add(const string_type name, CreateHandlerPtr creator) { elements_.put(name, creator); return *this; } // add private: ChildElementsBuilder() : elements_() { } // ChildElementsBuilder ChildElementsBuilder(const ChildElementsBuilder& rhs) : elements_(rhs.elements_) { } // ChildElementsBuilder ChildElements elements_; friend class ChildElements; }; // class ChildElementsBuilder template ChildElementsBuilder ChildElements::add(const string_type name, typename ChildElements::CreateHandlerPtr creator) { ChildElementsBuilder builder; builder.add(name, creator); return builder; } // ChildElementsBuilder } // namespace XSLT } // namespace Arabica #endif // ARABICA_XSLT_CONSTANTS_HPP