diff --git a/include/XPath/impl/xpath_arithmetic.hpp b/include/XPath/impl/xpath_arithmetic.hpp index d55b5bc4..89b2d3a4 100644 --- a/include/XPath/impl/xpath_arithmetic.hpp +++ b/include/XPath/impl/xpath_arithmetic.hpp @@ -19,6 +19,8 @@ public: PlusOperator(XPathExpression_impl* lhs, XPathExpression_impl* rhs) : BinaryExpression(lhs, rhs) { } + virtual ValueType type() const { return NUMBER; } + virtual XPathValue evaluate(const DOM::Node& context, const ExecutionContext& executionContext) const { @@ -35,6 +37,8 @@ public: MinusOperator(XPathExpression_impl* lhs, XPathExpression_impl* rhs) : BinaryExpression(lhs, rhs) { } + virtual ValueType type() const { return NUMBER; } + virtual XPathValue evaluate(const DOM::Node& context, const ExecutionContext& executionContext) const { @@ -51,6 +55,8 @@ public: MultiplyOperator(XPathExpression_impl* lhs, XPathExpression_impl* rhs) : BinaryExpression(lhs, rhs) { } + virtual ValueType type() const { return NUMBER; } + virtual XPathValue evaluate(const DOM::Node& context, const ExecutionContext& executionContext) const { @@ -67,6 +73,8 @@ public: DivideOperator(XPathExpression_impl* lhs, XPathExpression_impl* rhs) : BinaryExpression(lhs, rhs) { } + virtual ValueType type() const { return NUMBER; } + virtual XPathValue evaluate(const DOM::Node& context, const ExecutionContext& executionContext) const { @@ -83,6 +91,8 @@ public: ModOperator(XPathExpression_impl* lhs, XPathExpression_impl* rhs) : BinaryExpression(lhs, rhs) { } + virtual ValueType type() const { return NUMBER; } + virtual XPathValue evaluate(const DOM::Node& context, const ExecutionContext& executionContext) const { @@ -104,6 +114,8 @@ public: UnaryNegative(XPathExpression_impl* expr) : UnaryExpression(expr) { } + virtual ValueType type() const { return NUMBER; } + virtual XPathValue evaluate(const DOM::Node& context, const ExecutionContext& executionContext) const { diff --git a/include/XPath/impl/xpath_expression.hpp b/include/XPath/impl/xpath_expression.hpp index 7210f5a3..6b04b57f 100644 --- a/include/XPath/impl/xpath_expression.hpp +++ b/include/XPath/impl/xpath_expression.hpp @@ -20,6 +20,8 @@ protected: public: virtual ~XPathExpression_impl() { } + virtual ValueType type() const = 0; + XPathValue evaluate(const DOM::Node& context) const { ExecutionContext executionContext; @@ -65,6 +67,8 @@ public: return *this; } // operator= + ValueType type() const { return ptr_->type(); } + const XPathExpression_impl* get() const { return ptr_.get(); } operator bool() const { return ptr_.get(); } diff --git a/include/XPath/impl/xpath_function.hpp b/include/XPath/impl/xpath_function.hpp index 005c6291..77d3b4c1 100644 --- a/include/XPath/impl/xpath_function.hpp +++ b/include/XPath/impl/xpath_function.hpp @@ -29,6 +29,8 @@ protected: public: virtual ~XPathFunction() { } + virtual ValueType type() const = 0; + virtual XPathValue_impl* evaluate(const DOM::Node& context, const ExecutionContext& executionContext) const = 0; @@ -85,6 +87,8 @@ class LastFn : public XPathFunction public: LastFn(const std::vector >& args) : XPathFunction(0, 0, args) { } + virtual ValueType type() const { return NUMBER; } + virtual XPathValue_impl* evaluate(const DOM::Node& context, const ExecutionContext& executionContext) const { @@ -99,6 +103,8 @@ class PositionFn : public XPathFunction public: PositionFn(const std::vector >& args) : XPathFunction(0, 0, args) { } + virtual ValueType type() const { return NUMBER; } + virtual XPathValue_impl* evaluate(const DOM::Node& context, const ExecutionContext& executionContext) const { @@ -114,6 +120,8 @@ class CountFn : public XPathFunction public: CountFn(const std::vector >& args) : XPathFunction(1, 1, args) { } + virtual ValueType type() const { return NUMBER; } + virtual XPathValue_impl* evaluate(const DOM::Node& context, const ExecutionContext& executionContext) const { @@ -130,6 +138,8 @@ class LocalNameFn : public XPathFunction public: LocalNameFn(const std::vector >& args) : XPathFunction(0, 1, args) { } + virtual ValueType type() const { return STRING; } + virtual XPathValue_impl* evaluate(const DOM::Node& context, const ExecutionContext& executionContext) const { @@ -166,6 +176,8 @@ class NamespaceURIFn : public XPathFunction public: NamespaceURIFn(const std::vector >& args) : XPathFunction(0, 1, args) { } + virtual ValueType type() const { return STRING; } + virtual XPathValue_impl* evaluate(const DOM::Node& context, const ExecutionContext& executionContext) const { @@ -200,6 +212,8 @@ class NameFn : public XPathFunction public: NameFn(const std::vector >& args) : XPathFunction(0, 1, args) { } + virtual ValueType type() const { return STRING; } + virtual XPathValue_impl* evaluate(const DOM::Node& context, const ExecutionContext& executionContext) const { @@ -239,6 +253,8 @@ class StringFn : public XPathFunction public: StringFn(const std::vector >& args) : XPathFunction(0, 1, args) { } + virtual ValueType type() const { return STRING; } + virtual XPathValue_impl* evaluate(const DOM::Node& context, const ExecutionContext& executionContext) const { @@ -254,6 +270,8 @@ class ConcatFn : public XPathFunction public: ConcatFn(const std::vector >& args) : XPathFunction(2, -1, args) { } + virtual ValueType type() const { return STRING; } + virtual XPathValue_impl* evaluate(const DOM::Node& context, const ExecutionContext& executionContext) const { @@ -272,6 +290,8 @@ class StartsWithFn : public XPathFunction public: StartsWithFn(const std::vector >& args) : XPathFunction(2, 2, args) { } + virtual ValueType type() const { return BOOL; } + virtual XPathValue_impl* evaluate(const DOM::Node& context, const ExecutionContext& executionContext) const { @@ -300,6 +320,8 @@ class ContainsFn : public XPathFunction public: ContainsFn(const std::vector >& args) : XPathFunction(2, 2, args) { } + virtual ValueType type() const { return BOOL; } + virtual XPathValue_impl* evaluate(const DOM::Node& context, const ExecutionContext& executionContext) const { @@ -316,6 +338,8 @@ class SubstringBeforeFn : public XPathFunction public: SubstringBeforeFn(const std::vector >& args) : XPathFunction(2, 2, args) { } + virtual ValueType type() const { return STRING; } + virtual XPathValue_impl* evaluate(const DOM::Node& context, const ExecutionContext& executionContext) const { @@ -337,6 +361,8 @@ class SubstringAfterFn : public XPathFunction public: SubstringAfterFn(const std::vector >& args) : XPathFunction(2, 2, args) { } + virtual ValueType type() const { return STRING; } + virtual XPathValue_impl* evaluate(const DOM::Node& context, const ExecutionContext& executionContext) const { @@ -359,6 +385,8 @@ class SubstringFn : public XPathFunction public: SubstringFn(const std::vector >& args) : XPathFunction(2, 3, args) { } + virtual ValueType type() const { return STRING; } + virtual XPathValue_impl* evaluate(const DOM::Node& context, const ExecutionContext& executionContext) const { @@ -389,6 +417,8 @@ class StringLengthFn : public XPathFunction public: StringLengthFn(const std::vector >& args) : XPathFunction(0, 1, args) { } + virtual ValueType type() const { return NUMBER; } + virtual XPathValue_impl* evaluate(const DOM::Node& context, const ExecutionContext& executionContext) const { @@ -405,6 +435,8 @@ class NormalizeSpaceFn : public XPathFunction public: NormalizeSpaceFn(const std::vector >& args) : XPathFunction(0, 1, args) { } + virtual ValueType type() const { return STRING; } + virtual XPathValue_impl* evaluate(const DOM::Node& context, const ExecutionContext& executionContext) const { @@ -422,6 +454,8 @@ class TranslateFn : public XPathFunction public: TranslateFn(const std::vector >& args) : XPathFunction(3, 3, args) { } + virtual ValueType type() const { return STRING; } + virtual XPathValue_impl* evaluate(const DOM::Node& context, const ExecutionContext& executionContext) const { @@ -456,6 +490,8 @@ class BooleanFn : public XPathFunction public: BooleanFn(const std::vector >& args) : XPathFunction(1, 1, args) { } + virtual ValueType type() const { return BOOL; } + virtual XPathValue_impl* evaluate(const DOM::Node& context, const ExecutionContext& executionContext) const { @@ -471,6 +507,8 @@ class NotFn : public XPathFunction public: NotFn(const std::vector >& args) : XPathFunction(1, 1, args) { } + virtual ValueType type() const { return BOOL; } + virtual XPathValue_impl* evaluate(const DOM::Node& context, const ExecutionContext& executionContext) const { @@ -485,6 +523,8 @@ class TrueFn : public XPathFunction public: TrueFn(const std::vector >& args) : XPathFunction(0, 0, args) { } + virtual ValueType type() const { return BOOL; } + virtual XPathValue_impl* evaluate(const DOM::Node& context, const ExecutionContext& executionContext) const { @@ -499,6 +539,8 @@ class FalseFn : public XPathFunction public: FalseFn(const std::vector >& args) : XPathFunction(0, 0, args) { } + virtual ValueType type() const { return BOOL; } + virtual XPathValue_impl* evaluate(const DOM::Node& context, const ExecutionContext& executionContext) const { @@ -519,6 +561,8 @@ class NumberFn : public XPathFunction public: NumberFn(const std::vector >& args) : XPathFunction(0, 1, args) { } + virtual ValueType type() const { return NUMBER; } + virtual XPathValue_impl* evaluate(const DOM::Node& context, const ExecutionContext& executionContext) const { @@ -536,6 +580,8 @@ class SumFn : public XPathFunction public: SumFn(const std::vector >& args) : XPathFunction(1, 1, args) { } + virtual ValueType type() const { return NUMBER; } + virtual XPathValue_impl* evaluate(const DOM::Node& context, const ExecutionContext& executionContext) const { @@ -555,6 +601,8 @@ class FloorFn : public XPathFunction public: FloorFn(const std::vector >& args) : XPathFunction(1, 1, args) { } + virtual ValueType type() const { return NUMBER; } + virtual XPathValue_impl* evaluate(const DOM::Node& context, const ExecutionContext& executionContext) const { @@ -570,6 +618,8 @@ class CeilingFn : public XPathFunction public: CeilingFn(const std::vector >& args) : XPathFunction(1, 1, args) { } + virtual ValueType type() const { return NUMBER; } + virtual XPathValue_impl* evaluate(const DOM::Node& context, const ExecutionContext& executionContext) const { @@ -585,6 +635,8 @@ class RoundFn : public XPathFunction public: RoundFn(const std::vector >& args) : XPathFunction(1, 1, args) { } + virtual ValueType type() const { return NUMBER; } + virtual XPathValue_impl* evaluate(const DOM::Node& context, const ExecutionContext& executionContext) const { diff --git a/include/XPath/impl/xpath_function_holder.hpp b/include/XPath/impl/xpath_function_holder.hpp index 317daf5b..45b2131a 100644 --- a/include/XPath/impl/xpath_function_holder.hpp +++ b/include/XPath/impl/xpath_function_holder.hpp @@ -29,6 +29,8 @@ public: delete func_; } // ~FunctionHolder + virtual ValueType type() const { return func_->type(); } + virtual XPathValue evaluate(const DOM::Node& context, const ExecutionContext& executionContext) const { diff --git a/include/XPath/impl/xpath_logical.hpp b/include/XPath/impl/xpath_logical.hpp index 345a43d8..b08215a8 100644 --- a/include/XPath/impl/xpath_logical.hpp +++ b/include/XPath/impl/xpath_logical.hpp @@ -20,6 +20,8 @@ public: XPathExpression_impl* rhs) : BinaryExpression(lhs, rhs) { } + virtual ValueType type() const { return BOOL; } + virtual XPathValue evaluate(const DOM::Node& context, const ExecutionContext& executionContext) const { @@ -44,6 +46,8 @@ public: XPathExpression_impl* rhs) : BinaryExpression(lhs, rhs) { } + virtual ValueType type() const { return BOOL; } + virtual XPathValue evaluate(const DOM::Node& context, const ExecutionContext& executionContext) const { diff --git a/include/XPath/impl/xpath_match.hpp b/include/XPath/impl/xpath_match.hpp index f42b877a..5aee6390 100644 --- a/include/XPath/impl/xpath_match.hpp +++ b/include/XPath/impl/xpath_match.hpp @@ -21,7 +21,7 @@ public: MatchExpr& operator=(const MatchExpr& rhs) { match_ = rhs.match_; priority_ = rhs.priority_; return *this; } - double priority() const { return priority_; } + double priority() const { return priority_; } bool evaluate(const DOM::Node& context, const ExecutionContext& executionContext) const { @@ -52,6 +52,8 @@ public: add_matches(expr); } // MatchExpressionWrapper + virtual ValueType type() const { return BOOL; } + virtual XPathValue evaluate(const DOM::Node& context, const ExecutionContext& executionContext) const { diff --git a/include/XPath/impl/xpath_relational.hpp b/include/XPath/impl/xpath_relational.hpp index 537863ca..b03e9290 100644 --- a/include/XPath/impl/xpath_relational.hpp +++ b/include/XPath/impl/xpath_relational.hpp @@ -20,6 +20,8 @@ public: XPathExpression_impl* rhs) : BinaryExpression(lhs, rhs) { } + virtual ValueType type() const { return BOOL; } + virtual XPathValue evaluate(const DOM::Node& context, const ExecutionContext& executionContext) const { @@ -38,6 +40,8 @@ public: XPathExpression_impl* rhs) : BinaryExpression(lhs, rhs) { } + virtual ValueType type() const { return BOOL; } + virtual XPathValue evaluate(const DOM::Node& context, const ExecutionContext& executionContext) const { @@ -56,6 +60,8 @@ public: XPathExpression_impl* rhs) : BinaryExpression(lhs, rhs) { } + virtual ValueType type() const { return BOOL; } + virtual XPathValue evaluate(const DOM::Node& context, const ExecutionContext& executionContext) const { @@ -74,6 +80,8 @@ public: XPathExpression_impl* rhs) : BinaryExpression(lhs, rhs) { } + virtual ValueType type() const { return BOOL; } + virtual XPathValue evaluate(const DOM::Node& context, const ExecutionContext& executionContext) const { @@ -92,6 +100,8 @@ public: XPathExpression_impl* rhs) : BinaryExpression(lhs, rhs) { } + virtual ValueType type() const { return BOOL; } + virtual XPathValue evaluate(const DOM::Node& context, const ExecutionContext& executionContext) const { @@ -110,6 +120,8 @@ public: XPathExpression_impl* rhs) : BinaryExpression(lhs, rhs) { } + virtual ValueType type() const { return BOOL; } + virtual XPathValue evaluate(const DOM::Node& context, const ExecutionContext& executionContext) const { diff --git a/include/XPath/impl/xpath_step.hpp b/include/XPath/impl/xpath_step.hpp index c3368bca..353c7fba 100644 --- a/include/XPath/impl/xpath_step.hpp +++ b/include/XPath/impl/xpath_step.hpp @@ -32,6 +32,8 @@ public: delete *p; } // ~StepExpression + virtual ValueType type() const { return NODE_SET; } + virtual XPathValue evaluate(const DOM::Node& context, const ExecutionContext& executionContext) const = 0; virtual XPathValue evaluate(NodeSet& context, const ExecutionContext& executionContext) const = 0; @@ -453,6 +455,8 @@ public: delete *i; } // ~RelativeLocationPath + virtual ValueType type() const { return NODE_SET; } + virtual XPathValue evaluate(const DOM::Node& context, const ExecutionContext& executionContext) const { NodeSet nodes; diff --git a/include/XPath/impl/xpath_union.hpp b/include/XPath/impl/xpath_union.hpp index f3951bee..b5bd3ff2 100644 --- a/include/XPath/impl/xpath_union.hpp +++ b/include/XPath/impl/xpath_union.hpp @@ -21,6 +21,8 @@ public: XPathExpression_impl* rhs) : BinaryExpression(lhs, rhs) { } + virtual ValueType type() const { return NODE_SET; } + virtual XPathValue evaluate(const DOM::Node& context, const ExecutionContext& executionContext) const { diff --git a/include/XPath/impl/xpath_variable.hpp b/include/XPath/impl/xpath_variable.hpp index 608afd0a..5227e409 100644 --- a/include/XPath/impl/xpath_variable.hpp +++ b/include/XPath/impl/xpath_variable.hpp @@ -21,6 +21,8 @@ public: { } // Variable + virtual ValueType type() const { return ANY; } + virtual XPathValue evaluate(const DOM::Node& context, const ExecutionContext& executionContext) const { diff --git a/include/XSLT/impl/xslt_functions.hpp b/include/XSLT/impl/xslt_functions.hpp index 8d0d2f98..201ffc3d 100644 --- a/include/XSLT/impl/xslt_functions.hpp +++ b/include/XSLT/impl/xslt_functions.hpp @@ -18,6 +18,8 @@ public: CurrentFunction(const std::vector >& args) : Arabica::XPath::XPathFunction(0, 0, args) { } + virtual Arabica::XPath::ValueType type() const { return Arabica::XPath::NODE_SET; } + virtual Arabica::XPath::XPathValue_impl* evaluate(const DOM::Node& context, const Arabica::XPath::ExecutionContext& executionContext) const { @@ -39,6 +41,8 @@ public: baseURI_(currentBase) { } + virtual Arabica::XPath::ValueType type() const { return Arabica::XPath::NODE_SET; } + virtual Arabica::XPath::XPathValue_impl* evaluate(const DOM::Node& context, const Arabica::XPath::ExecutionContext& executionContext) const { @@ -84,6 +88,8 @@ public: SystemPropertyFunction (const std::vector >& args) : Arabica::XPath::XPathFunction(1, 1, args) { } + virtual Arabica::XPath::ValueType type() const { return Arabica::XPath::STRING; } + virtual Arabica::XPath::XPathValue_impl* evaluate(const DOM::Node& context, const Arabica::XPath::ExecutionContext& executionContext) const { diff --git a/tests/XPath/execute_test.hpp b/tests/XPath/execute_test.hpp index 4376e2a6..3633b36f 100644 --- a/tests/XPath/execute_test.hpp +++ b/tests/XPath/execute_test.hpp @@ -65,6 +65,8 @@ public: TestFunction(const std::vector >& args) : Arabica::XPath::XPathFunction(0, 0, args) { } + virtual Arabica::XPath::ValueType type() const { return Arabica::XPath::STRING; } + virtual Arabica::XPath::XPathValue_impl* evaluate(const Arabica::DOM::Node& context, const Arabica::XPath::ExecutionContext& executionContext) const { @@ -178,6 +180,7 @@ public: using namespace Arabica::XPath; XPathExpression xpath; xpath = parser.compile(SA::construct_from_utf8("root")); + assertValuesEqual(NODE_SET, xpath.type()); XPathValue result = xpath.evaluate(document_); assertValuesEqual(NODE_SET, result.type()); @@ -190,6 +193,7 @@ public: { using namespace Arabica::XPath; XPathExpression xpath = parser.compile(SA::construct_from_utf8("root/child2")); + assertValuesEqual(NODE_SET, xpath.type()); XPathValue result = xpath.evaluate(document_); assertValuesEqual(NODE_SET, result.type()); @@ -202,6 +206,7 @@ public: { using namespace Arabica::XPath; XPathExpression xpath = parser.compile(SA::construct_from_utf8("root/*")); + assertValuesEqual(NODE_SET, xpath.type()); XPathValue result = xpath.evaluate(document_); assertValuesEqual(NODE_SET, result.type()); @@ -215,6 +220,7 @@ public: { using namespace Arabica::XPath; XPathExpression xpath = parser.compile(SA::construct_from_utf8("root/*/text()")); + assertValuesEqual(NODE_SET, xpath.type()); XPathValue result = xpath.evaluate(document_); assertValuesEqual(NODE_SET, result.type()); @@ -234,6 +240,7 @@ public: { using namespace Arabica::XPath; XPathExpression xpath = parser.compile(SA::construct_from_utf8("*")); + assertValuesEqual(NODE_SET, xpath.type()); XPathValue result = xpath.evaluate(document_); assertValuesEqual(NODE_SET, result.type()); @@ -283,6 +290,7 @@ public: nsContext.addNamespaceDeclaration(SA::construct_from_utf8("urn:something:or:other"), SA::construct_from_utf8("ns")); parser.setNamespaceContext(nsContext); XPathExpression xpath = parser.compile(SA::construct_from_utf8("/ns:root")); + assertValuesEqual(NODE_SET, xpath.type()); parser.resetNamespaceContext(); XPathValue result = xpath.evaluate(document_);