From fac7cf88def8586d66cdd650e080eef5e0a9c3e9 Mon Sep 17 00:00:00 2001 From: jez <> Date: Mon, 22 Oct 2007 20:25:35 +0000 Subject: [PATCH] XPathExpressionPtr no longer derives from boost::shared_ptr, it contains it instead --- examples/XPath/xgrep.cpp | 3 --- include/XPath/impl/xpath_expression.hpp | 22 ++++++++++++++-------- include/XPath/impl/xpath_parser.hpp | 2 +- tests/XPath/arithmetic_test.hpp | 4 ---- 4 files changed, 15 insertions(+), 16 deletions(-) diff --git a/examples/XPath/xgrep.cpp b/examples/XPath/xgrep.cpp index 2d78b9d9..a1f2413b 100644 --- a/examples/XPath/xgrep.cpp +++ b/examples/XPath/xgrep.cpp @@ -1,6 +1,3 @@ -// DOMWriter.cpp : Defines the entry point for the application. -// - #ifdef _MSC_VER #pragma warning(disable: 4786 4250 4503) #endif diff --git a/include/XPath/impl/xpath_expression.hpp b/include/XPath/impl/xpath_expression.hpp index 3b2f51f8..fb2fe59a 100644 --- a/include/XPath/impl/xpath_expression.hpp +++ b/include/XPath/impl/xpath_expression.hpp @@ -51,20 +51,26 @@ private: }; // class XPathExpression template > -class XPathExpressionPtr : public boost::shared_ptr > +class XPathExpressionPtr { public: - XPathExpressionPtr() : - boost::shared_ptr >() { } - explicit XPathExpressionPtr(XPathExpression* xp) : - boost::shared_ptr >(xp) { } - XPathExpressionPtr(const XPathExpressionPtr& rhs) : - boost::shared_ptr >(rhs) { } + XPathExpressionPtr() : ptr_() { } + explicit XPathExpressionPtr(XPathExpression* xp) : ptr_(xp) { } + XPathExpressionPtr(const XPathExpressionPtr& rhs) : ptr_(rhs.ptr_) { } XPathExpressionPtr& operator=(const XPathExpressionPtr& rhs) { - boost::shared_ptr >::operator=(rhs); + ptr_ = rhs.ptr_; return *this; } // operator= + + const XPathExpression* get() const { return ptr_.get(); } + const XPathExpression* operator->() const { return ptr_.get(); } + + operator bool() const { return ptr_.get(); } + +private: + typedef boost::shared_ptr > ExpressionPtr; + ExpressionPtr ptr_; }; // class XPathExpressionPtr namespace impl diff --git a/include/XPath/impl/xpath_parser.hpp b/include/XPath/impl/xpath_parser.hpp index 4168108f..c3dd3181 100644 --- a/include/XPath/impl/xpath_parser.hpp +++ b/include/XPath/impl/xpath_parser.hpp @@ -82,7 +82,7 @@ public: std::vector > compile_match(const string_type& xpath) const { XPathExpressionPtr wrapper = do_compile(xpath, &XPath::parse_xpath_match, match_factory()); - return (static_cast*>(wrapper.get()))->matches(); + return (static_cast*>(wrapper.get()))->matches(); } // compile_match XPathValue evaluate(const string_type& xpath, const DOM::Node& context) const diff --git a/tests/XPath/arithmetic_test.hpp b/tests/XPath/arithmetic_test.hpp index 15fed14e..9fe6dade 100644 --- a/tests/XPath/arithmetic_test.hpp +++ b/tests/XPath/arithmetic_test.hpp @@ -26,13 +26,9 @@ public: XPathExpression* p2 = new NumericValue(2); XPathExpressionPtr add(new impl::PlusOperator(p1, p2)); - assertEquals(1, add.use_count()); add->evaluate(dummy_); - assertEquals(3.0, add->evaluateAsNumber(dummy_), 0.0); - - assertEquals(1, add.use_count()); } // test1 void test2()