Shuffled around the Stylesheet class. Stylesheet is now the public face, while CompiledStylesheet is what gets chucked around internally.

This commit is contained in:
jez 2008-11-05 01:33:28 +00:00
parent f74170e268
commit b74514bc58
8 changed files with 99 additions and 102 deletions

View file

@ -1,56 +1,56 @@
#ifndef ARABICA_XPATH_COMPILE_CONTEXT_HPP
#define ARABICA_XPATH_COMPILE_CONTEXT_HPP
namespace Arabica
{
namespace XPath
{
template<class string_type, class string_adaptor> class XPath;
template<class string_type, class string_adaptor> class NamespaceContext;
template<class string_type, class string_adaptor> class FunctionResolver;
namespace impl
{
template<class string_type, class string_adaptor>
class CompilationContext : private NamespaceContext<string_type, string_adaptor>
{
public:
CompilationContext(const XPath<string_type, string_adaptor>& xpathCompiler,
const NamespaceContext<string_type, string_adaptor>& namespaceContext,
const FunctionResolver<string_type, string_adaptor>& functionResolver) :
xpath_(xpathCompiler),
namespaceContext_(namespaceContext),
functionResolver_(functionResolver)
{
} // CompilationContext
const XPath<string_type, string_adaptor>& xpath() const { return xpath_; }
const NamespaceContext<string_type, string_adaptor>& namespaceContext() const { return *this; }
const FunctionResolver<string_type, string_adaptor>& functionResolver() const { return functionResolver_; }
private:
virtual string_type namespaceURI(const string_type& prefix) const
{
string_type uri = namespaceContext_.namespaceURI(prefix);
if(string_adaptor::empty(uri))
throw Arabica::XPath::UnboundNamespacePrefixException(string_adaptor::asStdString(prefix));
return uri;
} // namespaceURI
const XPath<string_type, string_adaptor>& xpath_;
const NamespaceContext<string_type, string_adaptor>& namespaceContext_;
const FunctionResolver<string_type, string_adaptor>& functionResolver_;
CompilationContext(const CompilationContext&);
CompilationContext& operator=(const CompilationContext&);
bool operator==(const CompilationContext&) const;
}; // class CompilationContext
} // namespace impl
} // namespace XPath
} // namespace Arabica
#endif
#ifndef ARABICA_XPATH_COMPILE_CONTEXT_HPP
#define ARABICA_XPATH_COMPILE_CONTEXT_HPP
namespace Arabica
{
namespace XPath
{
template<class string_type, class string_adaptor> class XPath;
template<class string_type, class string_adaptor> class NamespaceContext;
template<class string_type, class string_adaptor> class FunctionResolver;
namespace impl
{
template<class string_type, class string_adaptor>
class CompilationContext : private NamespaceContext<string_type, string_adaptor>
{
public:
CompilationContext(const XPath<string_type, string_adaptor>& xpathCompiler,
const NamespaceContext<string_type, string_adaptor>& namespaceContext,
const FunctionResolver<string_type, string_adaptor>& functionResolver) :
xpath_(xpathCompiler),
namespaceContext_(namespaceContext),
functionResolver_(functionResolver)
{
} // CompilationContext
const XPath<string_type, string_adaptor>& xpath() const { return xpath_; }
const NamespaceContext<string_type, string_adaptor>& namespaceContext() const { return *this; }
const FunctionResolver<string_type, string_adaptor>& functionResolver() const { return functionResolver_; }
private:
virtual string_type namespaceURI(const string_type& prefix) const
{
string_type uri = namespaceContext_.namespaceURI(prefix);
if(string_adaptor::empty(uri))
throw Arabica::XPath::UnboundNamespacePrefixException(string_adaptor::asStdString(prefix));
return uri;
} // namespaceURI
const XPath<string_type, string_adaptor>& xpath_;
const NamespaceContext<string_type, string_adaptor>& namespaceContext_;
const FunctionResolver<string_type, string_adaptor>& functionResolver_;
CompilationContext(const CompilationContext&);
CompilationContext& operator=(const CompilationContext&);
bool operator==(const CompilationContext&) const;
}; // class CompilationContext
} // namespace impl
} // namespace XPath
} // namespace Arabica
#endif

View file

@ -6,7 +6,7 @@
#include <XPath/XPath.hpp>
#include "../xslt_compilation_context.hpp"
#include "../xslt_stylesheet.hpp"
#include "../xslt_compiled_stylesheet.hpp"
#include "xslt_constants.hpp"
namespace Arabica

View file

@ -1,7 +1,7 @@
#ifndef ARABICA_XSLT_APPLY_TEMPLATES_HPP
#define ARABICA_XSLT_APPLY_TEMPLATES_HPP
#include "xslt_stylesheet.hpp"
#include "xslt_compiled_stylesheet.hpp"
#include "xslt_sort.hpp"
#include "xslt_with_param.hpp"

View file

@ -1,7 +1,7 @@
#ifndef ARABICA_XSLT_CALL_TEMPLATE_HPP
#define ARABICA_XSLT_CALL_TEMPLATE_HPP
#include "xslt_stylesheet.hpp"
#include "xslt_compiled_stylesheet.hpp"
#include "xslt_with_param.hpp"
namespace Arabica

View file

@ -14,7 +14,7 @@ namespace Arabica
{
namespace XSLT
{
class Stylesheet;
class CompiledStylesheet;
class ItemContainer;
class CompilationContext :
@ -23,7 +23,7 @@ class CompilationContext :
{
public:
CompilationContext(StylesheetParser& parser,
Stylesheet& stylesheet) :
CompiledStylesheet& stylesheet) :
parser_(parser),
stylesheet_(stylesheet),
autoNs_(1),
@ -56,7 +56,7 @@ public:
return xpath_.compile_match(match);
} // xpath_match
Arabica::XPath::XPathExpressionPtr<std::string> xpath_attribute_value_template(const std::string& expr) const { return xpath_.compile_attribute_value_template(expr); }
Stylesheet& stylesheet() const { return stylesheet_; }
CompiledStylesheet& stylesheet() const { return stylesheet_; }
std::pair<std::string, std::string> processInternalQName(const std::string& qName) const
{
@ -181,7 +181,7 @@ private:
StylesheetParser& parser_;
Arabica::XPath::XPath<std::string> xpath_;
Stylesheet& stylesheet_;
CompiledStylesheet& stylesheet_;
std::stack<SAX::DefaultHandler<std::string>*> handlerStack_;
std::stack<ItemContainer*> parentStack_;
std::map<std::string, Namespace> namespaceRemap_;

View file

@ -1,5 +1,5 @@
#ifndef ARABICA_XSLT_STYLESHEET_HPP
#define ARABICA_XSLT_STYLESHEET_HPP
#ifndef ARABICA_XSLT_COMPILED_STYLESHEET_HPP
#define ARABICA_XSLT_COMPILED_STYLESHEET_HPP
#include <vector>
#include <iostream>
@ -8,13 +8,14 @@
#include "xslt_execution_context.hpp"
#include "xslt_template.hpp"
#include "xslt_top_level_param.hpp"
#include "xslt_stylesheet.hpp"
namespace Arabica
{
namespace XSLT
{
class Stylesheet
class CompiledStylesheet : public Stylesheet
{
typedef Arabica::XPath::BoolValue<std::string, Arabica::default_string_adaptor<std::string> > BoolValue;
typedef Arabica::XPath::NumericValue<std::string, Arabica::default_string_adaptor<std::string> > NumericValue;
@ -22,14 +23,16 @@ class Stylesheet
typedef Arabica::XPath::XPathValuePtr<std::string> ValuePtr;
public:
Stylesheet() :
CompiledStylesheet() :
output_(new StreamSink(std::cout)),
error_output_(&std::cerr)
error_output_(&std::cerr),
current_import_precedence_(0),
total_imports_(0)
{
push_import_precedence();
} // Stylesheet
} // CompiledStylesheet
~Stylesheet()
virtual ~CompiledStylesheet()
{
// let's clean up!
for(ItemStack::const_iterator isi = items_.begin(), ise = items_.end(); isi != ise; ++isi)
@ -39,36 +42,36 @@ public:
delete *pi;
for(TemplateList::const_iterator ti = all_templates_.begin(), te = all_templates_.end(); ti != te; ++ti)
delete *ti;
} // ~Stylesheet
} // ~CompiledStylesheet
void set_parameter(const std::string& name, bool value)
virtual void set_parameter(const std::string& name, bool value)
{
set_parameter(name, ValuePtr(new BoolValue(value)));
} // set_parameter
void set_parameter(const std::string& name, double value)
virtual void set_parameter(const std::string& name, double value)
{
set_parameter(name, ValuePtr(new NumericValue(value)));
} // set_parameter
void set_parameter(const std::string& name, const char* value)
virtual void set_parameter(const std::string& name, const char* value)
{
set_parameter(name, ValuePtr(new StringValue(value)));
} // set_parameter
void set_parameter(const std::string& name, const std::string& value)
virtual void set_parameter(const std::string& name, const std::string& value)
{
set_parameter(name, ValuePtr(new StringValue(value)));
} // set_parameter
void set_output(Sink& sink)
virtual void set_output(Sink& sink)
{
output_.reset(sink);
} // set_output
void set_error_output(std::ostream& os)
virtual void set_error_output(std::ostream& os)
{
error_output_ = &os;
} // set_error_output
void execute(DOM::Node<std::string>& initialNode) const
virtual void execute(const DOM::Node<std::string>& initialNode) const
{
if(initialNode == 0)
throw std::runtime_error("Input document is empty");
@ -318,16 +321,19 @@ private:
ItemStack items_;
ParamList params_;
std::vector<int> current_import_precedence_;
int total_imports_;
mutable std::pair<std::string, std::string> current_mode_;
mutable int current_generation_;
Output::Settings output_settings_;
SinkHolder output_;
mutable std::ostream* error_output_;
}; // class Stylesheet
}; // class CompiledStylesheet
} // namespace XSLT
} // namespace Arabica
#endif // ARABICA_XSLT_STYLESHEET_HPP
#endif // ARABICA_XSLT_COMPILED_STYLESHEET_HPP

View file

@ -10,7 +10,7 @@ namespace Arabica
namespace XSLT
{
class Stylesheet;
class CompiledStylesheet;
class ExecutionContext;
class Variable_declaration
@ -34,7 +34,7 @@ private:
class ExecutionContext
{
public:
ExecutionContext(const Stylesheet& stylesheet,
ExecutionContext(const CompiledStylesheet& stylesheet,
Sink& output,
std::ostream& error_output) :
stylesheet_(stylesheet),
@ -63,7 +63,7 @@ public:
xpathContext_.setLast(rhs.xpathContext().last());
} // ExecutionContext
const Stylesheet& stylesheet() const { return stylesheet_; }
const CompiledStylesheet& stylesheet() const { return stylesheet_; }
Output& sink()
{
@ -104,7 +104,7 @@ private:
void popStackFrame() { stack_.popScope(); }
private:
const Stylesheet& stylesheet_;
const CompiledStylesheet& stylesheet_;
VariableStack stack_;
int variable_precedence_;
Arabica::XPath::ExecutionContext<std::string> xpathContext_;

View file

@ -6,7 +6,7 @@
#include <memory>
#include "xslt_stylesheet_parser.hpp"
#include "xslt_stylesheet.hpp"
#include "xslt_compiled_stylesheet.hpp"
#include "xslt_compilation_context.hpp"
#include "handler/xslt_template_handler.hpp"
#include "handler/xslt_include_handler.hpp"
@ -169,20 +169,19 @@ public:
{
error_ = "";
std::auto_ptr<Stylesheet> stylesheet(new Stylesheet());
std::auto_ptr<CompiledStylesheet> stylesheet(new CompiledStylesheet());
CompilationContext context(parser_,
*stylesheet.get());
StylesheetParser parser;
CompilationContext context(parser, *stylesheet.get());
StylesheetHandler stylesheetHandler(context);
parser_.setContentHandler(stylesheetHandler);
//parser_.setErrorHandler(*this);
parser.setContentHandler(stylesheetHandler);
//parser.setErrorHandler(*this);
//if(entityResolver_)
// parser_.setEntityResolver(*entityResolver_);
// parser.setEntityResolver(*entityResolver_);
try {
parser_.parse(source);
parser.parse(source);
} // try
catch(std::exception& ex)
{
@ -191,7 +190,7 @@ public:
stylesheet.reset();
} // catch
return stylesheet;
return std::auto_ptr<Stylesheet>(stylesheet.release());
} // compile
const std::string& error() const
@ -200,14 +199,6 @@ public:
} // error
private:
virtual void fatalError(const SAX::SAXException& exception)
{
std::cerr << "Error: " << exception.what() << std::endl;
stylesheet_.reset();
} // fatalError
StylesheetParser parser_;
std::auto_ptr<Stylesheet> stylesheet_;
std::string error_;
}; // class StylesheetCompiler