Commit 6d3fecd4 authored by Leonid Beynenson's avatar Leonid Beynenson

Fixed small bug in cv::Ptr<_Tp> conversion to cv::Ptr<_Tp2>. Now this conversion…

Fixed small bug in cv::Ptr<_Tp> conversion to cv::Ptr<_Tp2>. Now this conversion is made in a more accurate way.
parent a72f4474
...@@ -1249,6 +1249,7 @@ public: ...@@ -1249,6 +1249,7 @@ public:
~Ptr(); ~Ptr();
//! copy constructor. Copies the members and calls addref() //! copy constructor. Copies the members and calls addref()
Ptr(const Ptr& ptr); Ptr(const Ptr& ptr);
template<typename _Tp2> Ptr(const Ptr<_Tp2>& ptr);
//! copy operator. Calls ptr.addref() and release() before copying the members //! copy operator. Calls ptr.addref() and release() before copying the members
Ptr& operator = (const Ptr& ptr); Ptr& operator = (const Ptr& ptr);
//! increments the reference counter //! increments the reference counter
......
...@@ -2642,14 +2642,35 @@ template<typename _Tp> inline Ptr<_Tp>::operator const _Tp*() const { return obj ...@@ -2642,14 +2642,35 @@ template<typename _Tp> inline Ptr<_Tp>::operator const _Tp*() const { return obj
template<typename _Tp> inline bool Ptr<_Tp>::empty() const { return obj == 0; } template<typename _Tp> inline bool Ptr<_Tp>::empty() const { return obj == 0; }
template<typename _Tp> template<typename _Tp2> Ptr<_Tp>::Ptr(const Ptr<_Tp2>& p)
: obj(0), refcount(0)
{
if (p.empty())
return;
_Tp* p_casted = dynamic_cast<_Tp*>(p.obj);
if (!p_casted)
return;
obj = p_casted;
refcount = p.refcount;
addref();
}
template<typename _Tp> template<typename _Tp2> inline Ptr<_Tp2> Ptr<_Tp>::ptr() template<typename _Tp> template<typename _Tp2> inline Ptr<_Tp2> Ptr<_Tp>::ptr()
{ {
Ptr<_Tp2> p; Ptr<_Tp2> p;
if( !obj ) if( !obj )
return p; return p;
_Tp2* obj_casted = dynamic_cast<_Tp2*>(obj);
if (!obj_casted)
return p;
if( refcount ) if( refcount )
CV_XADD(refcount, 1); CV_XADD(refcount, 1);
p.obj = dynamic_cast<_Tp2*>(obj);
p.obj = obj_casted;
p.refcount = refcount; p.refcount = refcount;
return p; return p;
} }
...@@ -2659,9 +2680,15 @@ template<typename _Tp> template<typename _Tp2> inline const Ptr<_Tp2> Ptr<_Tp>:: ...@@ -2659,9 +2680,15 @@ template<typename _Tp> template<typename _Tp2> inline const Ptr<_Tp2> Ptr<_Tp>::
Ptr<_Tp2> p; Ptr<_Tp2> p;
if( !obj ) if( !obj )
return p; return p;
_Tp2* obj_casted = dynamic_cast<_Tp2*>(obj);
if (!obj_casted)
return p;
if( refcount ) if( refcount )
CV_XADD(refcount, 1); CV_XADD(refcount, 1);
p.obj = dynamic_cast<_Tp2*>(obj);
p.obj = obj_casted;
p.refcount = refcount; p.refcount = refcount;
return p; return p;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment