mirror of
https://github.com/opencv/opencv.git
synced 2025-08-06 14:36:36 +08:00
Fixed small bug in cv::Ptr<_Tp> conversion to cv::Ptr<_Tp2>. Now this conversion is made in a more accurate way.
This commit is contained in:
parent
a72f4474b4
commit
6d3fecd490
@ -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
|
|||||||
|
|
||||||
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>::
|
|||||||
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;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user