Fixed small bug in cv::Ptr<_Tp> conversion to cv::Ptr<_Tp2>. Now this conversion is made in a more accurate way.

pull/2/head
Leonid Beynenson 13 years ago
parent a72f4474b4
commit 6d3fecd490
  1. 1
      modules/core/include/opencv2/core/core.hpp
  2. 31
      modules/core/include/opencv2/core/operations.hpp

@ -1249,6 +1249,7 @@ public:
~Ptr();
//! copy constructor. Copies the members and calls addref()
Ptr(const Ptr& ptr);
template<typename _Tp2> Ptr(const Ptr<_Tp2>& ptr);
//! copy operator. Calls ptr.addref() and release() before copying the members
Ptr& operator = (const Ptr& ptr);
//! 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> 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()
{
Ptr<_Tp2> p;
if( !obj )
return p;
_Tp2* obj_casted = dynamic_cast<_Tp2*>(obj);
if (!obj_casted)
return p;
if( refcount )
CV_XADD(refcount, 1);
p.obj = dynamic_cast<_Tp2*>(obj);
p.obj = obj_casted;
p.refcount = refcount;
return p;
}
@ -2659,9 +2680,15 @@ template<typename _Tp> template<typename _Tp2> inline const Ptr<_Tp2> Ptr<_Tp>::
Ptr<_Tp2> p;
if( !obj )
return p;
_Tp2* obj_casted = dynamic_cast<_Tp2*>(obj);
if (!obj_casted)
return p;
if( refcount )
CV_XADD(refcount, 1);
p.obj = dynamic_cast<_Tp2*>(obj);
p.obj = obj_casted;
p.refcount = refcount;
return p;
}

Loading…
Cancel
Save