XPathExpressionPtr no longer derives from boost::shared_ptr, it contains it instead

This commit is contained in:
jez 2007-10-22 20:25:35 +00:00
parent f6b2ed4966
commit fac7cf88de
4 changed files with 15 additions and 16 deletions

View file

@ -1,6 +1,3 @@
// DOMWriter.cpp : Defines the entry point for the application.
//
#ifdef _MSC_VER
#pragma warning(disable: 4786 4250 4503)
#endif

View file

@ -51,20 +51,26 @@ private:
}; // class XPathExpression
template<class string_type, class string_adaptor = Arabica::default_string_adaptor<string_type> >
class XPathExpressionPtr : public boost::shared_ptr<XPathExpression<string_type, string_adaptor> >
class XPathExpressionPtr
{
public:
XPathExpressionPtr() :
boost::shared_ptr<XPathExpression<string_type, string_adaptor> >() { }
explicit XPathExpressionPtr(XPathExpression<string_type, string_adaptor>* xp) :
boost::shared_ptr<XPathExpression<string_type, string_adaptor> >(xp) { }
XPathExpressionPtr(const XPathExpressionPtr& rhs) :
boost::shared_ptr<XPathExpression<string_type, string_adaptor> >(rhs) { }
XPathExpressionPtr() : ptr_() { }
explicit XPathExpressionPtr(XPathExpression<string_type, string_adaptor>* xp) : ptr_(xp) { }
XPathExpressionPtr(const XPathExpressionPtr& rhs) : ptr_(rhs.ptr_) { }
XPathExpressionPtr& operator=(const XPathExpressionPtr& rhs)
{
boost::shared_ptr<XPathExpression<string_type, string_adaptor> >::operator=(rhs);
ptr_ = rhs.ptr_;
return *this;
} // operator=
const XPathExpression<string_type, string_adaptor>* get() const { return ptr_.get(); }
const XPathExpression<string_type, string_adaptor>* operator->() const { return ptr_.get(); }
operator bool() const { return ptr_.get(); }
private:
typedef boost::shared_ptr<const XPathExpression<string_type, string_adaptor> > ExpressionPtr;
ExpressionPtr ptr_;
}; // class XPathExpressionPtr
namespace impl

View file

@ -82,7 +82,7 @@ public:
std::vector<MatchExpr<string_type, string_adaptor> > compile_match(const string_type& xpath) const
{
XPathExpressionPtr<string_type, string_adaptor> wrapper = do_compile(xpath, &XPath::parse_xpath_match, match_factory());
return (static_cast<impl::MatchExpressionWrapper<string_type, string_adaptor>*>(wrapper.get()))->matches();
return (static_cast<const impl::MatchExpressionWrapper<string_type, string_adaptor>*>(wrapper.get()))->matches();
} // compile_match
XPathValue<string_type, string_adaptor> evaluate(const string_type& xpath, const DOM::Node<string_type, string_adaptor>& context) const

View file

@ -26,13 +26,9 @@ public:
XPathExpression<string_type, string_adaptor>* p2 = new NumericValue<string_type, string_adaptor>(2);
XPathExpressionPtr<string_type, string_adaptor> add(new impl::PlusOperator<string_type, string_adaptor>(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()