mirror of
https://github.com/opencv/opencv.git
synced 2026-07-30 15:53:03 +04:00
Boring changes - core.
This and several following commits contain the "boring" changes required to support the new Ptr. These are changes like: * new T -> makePtr<T> or .reset(new T) or Ptr<T>(new T) (depending on the situation) * p.empty() -> !p * delete_obj -> DefaultDeleter::operator() and similar changes that are numerous, but primitive.
This commit is contained in:
@@ -163,7 +163,7 @@ Ptr<Algorithm> Algorithm::_create(const String& name)
|
||||
Algorithm::Constructor c = 0;
|
||||
if( !alglist().find(name, c) )
|
||||
return Ptr<Algorithm>();
|
||||
return c();
|
||||
return Ptr<Algorithm>(c());
|
||||
}
|
||||
|
||||
Algorithm::Algorithm()
|
||||
@@ -490,7 +490,7 @@ void AlgorithmInfo::read(Algorithm* algo, const FileNode& fn) const
|
||||
else if( p.type == Param::ALGORITHM )
|
||||
{
|
||||
Ptr<Algorithm> nestedAlgo = Algorithm::_create((String)n["name"]);
|
||||
CV_Assert( !nestedAlgo.empty() );
|
||||
CV_Assert( nestedAlgo );
|
||||
nestedAlgo->read(n);
|
||||
info->set(algo, pname.c_str(), p.type, &nestedAlgo, true);
|
||||
}
|
||||
|
||||
@@ -3190,22 +3190,22 @@ cvCheckTermCriteria( CvTermCriteria criteria, double default_eps,
|
||||
namespace cv
|
||||
{
|
||||
|
||||
template<> void Ptr<CvMat>::delete_obj()
|
||||
template<> void DefaultDeleter<CvMat>::operator ()(CvMat* obj) const
|
||||
{ cvReleaseMat(&obj); }
|
||||
|
||||
template<> void Ptr<IplImage>::delete_obj()
|
||||
template<> void DefaultDeleter<IplImage>::operator ()(IplImage* obj) const
|
||||
{ cvReleaseImage(&obj); }
|
||||
|
||||
template<> void Ptr<CvMatND>::delete_obj()
|
||||
template<> void DefaultDeleter<CvMatND>::operator ()(CvMatND* obj) const
|
||||
{ cvReleaseMatND(&obj); }
|
||||
|
||||
template<> void Ptr<CvSparseMat>::delete_obj()
|
||||
template<> void DefaultDeleter<CvSparseMat>::operator ()(CvSparseMat* obj) const
|
||||
{ cvReleaseSparseMat(&obj); }
|
||||
|
||||
template<> void Ptr<CvMemStorage>::delete_obj()
|
||||
template<> void DefaultDeleter<CvMemStorage>::operator ()(CvMemStorage* obj) const
|
||||
{ cvReleaseMemStorage(&obj); }
|
||||
|
||||
template<> void Ptr<CvFileStorage>::delete_obj()
|
||||
template<> void DefaultDeleter<CvFileStorage>::operator ()(CvFileStorage* obj) const
|
||||
{ cvReleaseFileStorage(&obj); }
|
||||
|
||||
}
|
||||
|
||||
@@ -100,7 +100,7 @@ cv::gpu::Stream::Stream()
|
||||
#ifndef HAVE_CUDA
|
||||
throw_no_cuda();
|
||||
#else
|
||||
impl_ = new Impl;
|
||||
impl_ = makePtr<Impl>();
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -182,7 +182,7 @@ void cv::gpu::Stream::enqueueHostCallback(StreamCallback callback, void* userDat
|
||||
|
||||
Stream& cv::gpu::Stream::Null()
|
||||
{
|
||||
static Stream s(new Impl(0));
|
||||
static Stream s(Ptr<Impl>(new Impl(0)));
|
||||
return s;
|
||||
}
|
||||
|
||||
@@ -195,10 +195,6 @@ cv::gpu::Stream::operator bool_type() const
|
||||
#endif
|
||||
}
|
||||
|
||||
template <> void cv::Ptr<Stream::Impl>::delete_obj()
|
||||
{
|
||||
if (obj) delete obj;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////
|
||||
// Stream
|
||||
@@ -249,7 +245,7 @@ cv::gpu::Event::Event(CreateFlags flags)
|
||||
(void) flags;
|
||||
throw_no_cuda();
|
||||
#else
|
||||
impl_ = new Impl(flags);
|
||||
impl_ = makePtr<Impl>(flags);
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -301,8 +297,3 @@ float cv::gpu::Event::elapsedTime(const Event& start, const Event& end)
|
||||
return ms;
|
||||
#endif
|
||||
}
|
||||
|
||||
template <> void cv::Ptr<Event::Impl>::delete_obj()
|
||||
{
|
||||
if (obj) delete obj;
|
||||
}
|
||||
|
||||
@@ -836,10 +836,6 @@ unsigned int cv::ogl::Buffer::bufId() const
|
||||
#endif
|
||||
}
|
||||
|
||||
template <> void cv::Ptr<cv::ogl::Buffer::Impl>::delete_obj()
|
||||
{
|
||||
if (obj) delete obj;
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////
|
||||
// ogl::Texture
|
||||
@@ -1243,10 +1239,6 @@ unsigned int cv::ogl::Texture2D::texId() const
|
||||
#endif
|
||||
}
|
||||
|
||||
template <> void cv::Ptr<cv::ogl::Texture2D::Impl>::delete_obj()
|
||||
{
|
||||
if (obj) delete obj;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
// ogl::Arrays
|
||||
|
||||
+13
-11
@@ -256,7 +256,7 @@ namespace
|
||||
cv::Ptr<cv::Formatted> format(const cv::Mat& mtx) const
|
||||
{
|
||||
char braces[5] = {'\0', '\0', ';', '\0', '\0'};
|
||||
return new FormattedImpl("[", "]", mtx, braces,
|
||||
return cv::makePtr<FormattedImpl>("[", "]", mtx, &*braces,
|
||||
mtx.cols == 1 || !multiline, mtx.depth() == CV_64F ? prec64f : prec32f );
|
||||
}
|
||||
};
|
||||
@@ -270,7 +270,7 @@ namespace
|
||||
char braces[5] = {'[', ']', '\0', '[', ']'};
|
||||
if (mtx.cols == 1)
|
||||
braces[0] = braces[1] = '\0';
|
||||
return new FormattedImpl("[", "]", mtx, braces,
|
||||
return cv::makePtr<FormattedImpl>("[", "]", mtx, &*braces,
|
||||
mtx.cols*mtx.channels() == 1 || !multiline, mtx.depth() == CV_64F ? prec64f : prec32f );
|
||||
}
|
||||
};
|
||||
@@ -288,7 +288,8 @@ namespace
|
||||
char braces[5] = {'[', ']', '\0', '[', ']'};
|
||||
if (mtx.cols == 1)
|
||||
braces[0] = braces[1] = '\0';
|
||||
return new FormattedImpl("array([", cv::format("], type='%s')", numpyTypes[mtx.depth()]), mtx, braces,
|
||||
return cv::makePtr<FormattedImpl>("array([",
|
||||
cv::format("], type='%s')", numpyTypes[mtx.depth()]), mtx, &*braces,
|
||||
mtx.cols*mtx.channels() == 1 || !multiline, mtx.depth() == CV_64F ? prec64f : prec32f );
|
||||
}
|
||||
};
|
||||
@@ -300,7 +301,8 @@ namespace
|
||||
cv::Ptr<cv::Formatted> format(const cv::Mat& mtx) const
|
||||
{
|
||||
char braces[5] = {'\0', '\0', '\0', '\0', '\0'};
|
||||
return new FormattedImpl(cv::String(), mtx.rows > 1 ? cv::String("\n") : cv::String(), mtx, braces,
|
||||
return cv::makePtr<FormattedImpl>(cv::String(),
|
||||
mtx.rows > 1 ? cv::String("\n") : cv::String(), mtx, &*braces,
|
||||
mtx.cols*mtx.channels() == 1 || !multiline, mtx.depth() == CV_64F ? prec64f : prec32f );
|
||||
}
|
||||
};
|
||||
@@ -312,7 +314,7 @@ namespace
|
||||
cv::Ptr<cv::Formatted> format(const cv::Mat& mtx) const
|
||||
{
|
||||
char braces[5] = {'\0', '\0', ',', '\0', '\0'};
|
||||
return new FormattedImpl("{", "}", mtx, braces,
|
||||
return cv::makePtr<FormattedImpl>("{", "}", mtx, &*braces,
|
||||
mtx.cols == 1 || !multiline, mtx.depth() == CV_64F ? prec64f : prec32f );
|
||||
}
|
||||
};
|
||||
@@ -330,16 +332,16 @@ namespace cv
|
||||
switch(fmt)
|
||||
{
|
||||
case FMT_MATLAB:
|
||||
return new MatlabFormatter();
|
||||
return makePtr<MatlabFormatter>();
|
||||
case FMT_CSV:
|
||||
return new CSVFormatter();
|
||||
return makePtr<CSVFormatter>();
|
||||
case FMT_PYTHON:
|
||||
return new PythonFormatter();
|
||||
return makePtr<PythonFormatter>();
|
||||
case FMT_NUMPY:
|
||||
return new NumpyFormatter();
|
||||
return makePtr<NumpyFormatter>();
|
||||
case FMT_C:
|
||||
return new CFormatter();
|
||||
return makePtr<CFormatter>();
|
||||
}
|
||||
return new MatlabFormatter();
|
||||
return makePtr<MatlabFormatter>();
|
||||
}
|
||||
} // cv
|
||||
|
||||
@@ -5147,8 +5147,8 @@ FileStorage::~FileStorage()
|
||||
bool FileStorage::open(const String& filename, int flags, const String& encoding)
|
||||
{
|
||||
release();
|
||||
fs = Ptr<CvFileStorage>(cvOpenFileStorage( filename.c_str(), 0, flags,
|
||||
!encoding.empty() ? encoding.c_str() : 0));
|
||||
fs.reset(cvOpenFileStorage( filename.c_str(), 0, flags,
|
||||
!encoding.empty() ? encoding.c_str() : 0));
|
||||
bool ok = isOpened();
|
||||
state = ok ? NAME_EXPECTED + INSIDE_MAP : UNDEFINED;
|
||||
return ok;
|
||||
@@ -5156,7 +5156,7 @@ bool FileStorage::open(const String& filename, int flags, const String& encoding
|
||||
|
||||
bool FileStorage::isOpened() const
|
||||
{
|
||||
return !fs.empty() && fs.obj->is_opened;
|
||||
return fs && fs->is_opened;
|
||||
}
|
||||
|
||||
void FileStorage::release()
|
||||
@@ -5169,8 +5169,8 @@ void FileStorage::release()
|
||||
String FileStorage::releaseAndGetString()
|
||||
{
|
||||
String buf;
|
||||
if( fs.obj && fs.obj->outbuf )
|
||||
icvClose(fs.obj, &buf);
|
||||
if( fs && fs->outbuf )
|
||||
icvClose(fs, &buf);
|
||||
|
||||
release();
|
||||
return buf;
|
||||
@@ -5479,7 +5479,7 @@ void write( FileStorage& fs, const String& name, const Mat& value )
|
||||
// TODO: the 4 functions below need to be implemented more efficiently
|
||||
void write( FileStorage& fs, const String& name, const SparseMat& value )
|
||||
{
|
||||
Ptr<CvSparseMat> mat = cvCreateSparseMat(value);
|
||||
Ptr<CvSparseMat> mat(cvCreateSparseMat(value));
|
||||
cvWrite( *fs, name.size() ? name.c_str() : 0, mat );
|
||||
}
|
||||
|
||||
@@ -5529,8 +5529,8 @@ void read( const FileNode& node, SparseMat& mat, const SparseMat& default_mat )
|
||||
default_mat.copyTo(mat);
|
||||
return;
|
||||
}
|
||||
Ptr<CvSparseMat> m = (CvSparseMat*)cvRead((CvFileStorage*)node.fs, (CvFileNode*)*node);
|
||||
CV_Assert(CV_IS_SPARSE_MAT(m.obj));
|
||||
Ptr<CvSparseMat> m((CvSparseMat*)cvRead((CvFileStorage*)node.fs, (CvFileNode*)*node));
|
||||
CV_Assert(CV_IS_SPARSE_MAT(m));
|
||||
m->copyToSparseMat(mat);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user