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.
pull/1281/head
Roman Donchenko 11 years ago
parent 461c98fa86
commit 8200a95ced
  1. 12
      modules/core/include/opencv2/core/core_c.h
  2. 6
      modules/core/include/opencv2/core/gpu.hpp
  3. 6
      modules/core/include/opencv2/core/opengl.hpp
  4. 4
      modules/core/include/opencv2/core/operations.hpp
  5. 6
      modules/core/include/opencv2/core/persistence.hpp
  6. 4
      modules/core/src/algorithm.cpp
  7. 12
      modules/core/src/array.cpp
  8. 15
      modules/core/src/gpu_stream.cpp
  9. 8
      modules/core/src/opengl.cpp
  10. 24
      modules/core/src/out.cpp
  11. 16
      modules/core/src/persistence.cpp
  12. 16
      modules/core/test/test_ds.cpp
  13. 12
      modules/core/test/test_io.cpp
  14. 4
      modules/core/test/test_mat.cpp

@ -1882,13 +1882,13 @@ CV_EXPORTS void insertImageCOI(InputArray coiimg, CvArr* arr, int coi=-1);
//////// specializied implementations of Ptr::delete_obj() for classic OpenCV types ////////
////// specialized implementations of DefaultDeleter::operator() for classic OpenCV types //////
template<> CV_EXPORTS void Ptr<CvMat>::delete_obj();
template<> CV_EXPORTS void Ptr<IplImage>::delete_obj();
template<> CV_EXPORTS void Ptr<CvMatND>::delete_obj();
template<> CV_EXPORTS void Ptr<CvSparseMat>::delete_obj();
template<> CV_EXPORTS void Ptr<CvMemStorage>::delete_obj();
template<> CV_EXPORTS void DefaultDeleter<CvMat>::operator ()(CvMat* obj) const;
template<> CV_EXPORTS void DefaultDeleter<IplImage>::operator ()(IplImage* obj) const;
template<> CV_EXPORTS void DefaultDeleter<CvMatND>::operator ()(CvMatND* obj) const;
template<> CV_EXPORTS void DefaultDeleter<CvSparseMat>::operator ()(CvSparseMat* obj) const;
template<> CV_EXPORTS void DefaultDeleter<CvMemStorage>::operator ()(CvMemStorage* obj) const;
////////////// convenient wrappers for operating old-style dynamic structures //////////////

@ -666,12 +666,6 @@ CV_EXPORTS void printShortCudaDeviceInfo(int device);
}} // namespace cv { namespace gpu {
namespace cv {
template <> CV_EXPORTS void Ptr<cv::gpu::Stream::Impl>::delete_obj();
template <> CV_EXPORTS void Ptr<cv::gpu::Event::Impl>::delete_obj();
}
#include "opencv2/core/gpu.inl.hpp"

@ -283,12 +283,6 @@ CV_EXPORTS void setGlDevice(int device = 0);
}}
namespace cv {
template <> CV_EXPORTS void Ptr<cv::ogl::Buffer::Impl>::delete_obj();
template <> CV_EXPORTS void Ptr<cv::ogl::Texture2D::Impl>::delete_obj();
}
////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////

@ -452,7 +452,7 @@ template<typename _Tp> inline
void Algorithm::set(const char* _name, const Ptr<_Tp>& value)
{
Ptr<Algorithm> algo_ptr = value. template ptr<cv::Algorithm>();
if (algo_ptr.empty()) {
if (!algo_ptr) {
CV_Error( Error::StsUnsupportedFormat, "unknown/unsupported Ptr type of the second parameter of the method Algorithm::set");
}
info()->set(this, _name, ParamType<Algorithm>::type, &algo_ptr);
@ -468,7 +468,7 @@ template<typename _Tp> inline
void Algorithm::setAlgorithm(const char* _name, const Ptr<_Tp>& value)
{
Ptr<Algorithm> algo_ptr = value. template ptr<cv::Algorithm>();
if (algo_ptr.empty()) {
if (!algo_ptr) {
CV_Error( Error::StsUnsupportedFormat, "unknown/unsupported Ptr type of the second parameter of the method Algorithm::set");
}
info()->set(this, _name, ParamType<Algorithm>::type, &algo_ptr);

@ -209,9 +209,9 @@ public:
CV_WRAP FileNode operator[](const char* nodename) const;
//! returns pointer to the underlying C FileStorage structure
CvFileStorage* operator *() { return fs; }
CvFileStorage* operator *() { return fs.get(); }
//! returns pointer to the underlying C FileStorage structure
const CvFileStorage* operator *() const { return fs; }
const CvFileStorage* operator *() const { return fs.get(); }
//! writes one or more numbers of the specified format to the currently written structure
void writeRaw( const String& fmt, const uchar* vec, size_t len );
//! writes the registered C structure (CvMat, CvMatND, CvSeq). See cvWrite()
@ -226,7 +226,7 @@ public:
int state; //!< the writer state
};
template<> CV_EXPORTS void Ptr<CvFileStorage>::delete_obj();
template<> CV_EXPORTS void DefaultDeleter<CvFileStorage>::operator ()(CvFileStorage* obj) const;
/*!
File Storage Node class

@ -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

@ -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);
}

@ -358,8 +358,6 @@ Core_DynStructBaseTest::Core_DynStructBaseTest()
iterations = max_struct_size*2;
gen = struct_idx = iter = -1;
test_progress = -1;
storage = 0;
}
@ -999,7 +997,7 @@ void Core_SeqBaseTest::run( int )
{
t = cvtest::randReal(rng)*(max_log_storage_block_size - min_log_storage_block_size)
+ min_log_storage_block_size;
storage = cvCreateMemStorage( cvRound( exp(t * CV_LOG2) ) );
storage.reset(cvCreateMemStorage( cvRound( exp(t * CV_LOG2) ) ));
}
iter = struct_idx = -1;
@ -1083,11 +1081,11 @@ void Core_SeqSortInvTest::run( int )
{
struct_idx = iter = -1;
if( storage.empty() )
if( !storage )
{
t = cvtest::randReal(rng)*(max_log_storage_block_size - min_log_storage_block_size)
+ min_log_storage_block_size;
storage = cvCreateMemStorage( cvRound( exp(t * CV_LOG2) ) );
storage.reset(cvCreateMemStorage( cvRound( exp(t * CV_LOG2) ) ));
}
for( iter = 0; iter < iterations/10; iter++ )
@ -1384,7 +1382,7 @@ void Core_SetTest::run( int )
{
struct_idx = iter = -1;
t = cvtest::randReal(rng)*(max_log_storage_block_size - min_log_storage_block_size) + min_log_storage_block_size;
storage = cvCreateMemStorage( cvRound( exp(t * CV_LOG2) ) );
storage.reset(cvCreateMemStorage( cvRound( exp(t * CV_LOG2) ) ));
for( int i = 0; i < struct_count; i++ )
{
@ -1398,7 +1396,7 @@ void Core_SetTest::run( int )
cvTsReleaseSimpleSet( (CvTsSimpleSet**)&simple_struct[i] );
simple_struct[i] = cvTsCreateSimpleSet( max_struct_size, pure_elem_size );
cxcore_struct[i] = cvCreateSet( 0, sizeof(CvSet), elem_size, storage );
cxcore_struct[i] = cvCreateSet( 0, sizeof(CvSet), elem_size, storage );
}
if( test_set_ops( iterations*100 ) < 0 )
@ -1811,7 +1809,7 @@ void Core_GraphTest::run( int )
int block_size = cvRound( exp(t * CV_LOG2) );
block_size = MAX(block_size, (int)(sizeof(CvGraph) + sizeof(CvMemBlock) + sizeof(CvSeqBlock)));
storage = cvCreateMemStorage(block_size);
storage.reset(cvCreateMemStorage(block_size));
for( i = 0; i < struct_count; i++ )
{
@ -1929,7 +1927,7 @@ void Core_GraphScanTest::run( int )
storage_blocksize = MAX(storage_blocksize, (int)(sizeof(CvGraph) + sizeof(CvMemBlock) + sizeof(CvSeqBlock)));
storage_blocksize = MAX(storage_blocksize, (int)(sizeof(CvGraphEdge) + sizeof(CvMemBlock) + sizeof(CvSeqBlock)));
storage_blocksize = MAX(storage_blocksize, (int)(sizeof(CvGraphVtx) + sizeof(CvMemBlock) + sizeof(CvSeqBlock)));
storage = cvCreateMemStorage(storage_blocksize);
storage.reset(cvCreateMemStorage(storage_blocksize));
if( gen == 0 )
{

@ -270,16 +270,16 @@ protected:
cvRelease((void**)&m_nd);
Ptr<CvSparseMat> m_s = (CvSparseMat*)fs["test_sparse_mat"].readObj();
Ptr<CvSparseMat> _test_sparse_ = cvCreateSparseMat(test_sparse_mat);
Ptr<CvSparseMat> _test_sparse = (CvSparseMat*)cvClone(_test_sparse_);
Ptr<CvSparseMat> m_s((CvSparseMat*)fs["test_sparse_mat"].readObj());
Ptr<CvSparseMat> _test_sparse_(cvCreateSparseMat(test_sparse_mat));
Ptr<CvSparseMat> _test_sparse((CvSparseMat*)cvClone(_test_sparse_));
SparseMat m_s2;
fs["test_sparse_mat"] >> m_s2;
Ptr<CvSparseMat> _m_s2 = cvCreateSparseMat(m_s2);
Ptr<CvSparseMat> _m_s2(cvCreateSparseMat(m_s2));
if( !m_s || !CV_IS_SPARSE_MAT(m_s) ||
!cvTsCheckSparse(m_s, _test_sparse,0) ||
!cvTsCheckSparse(_m_s2, _test_sparse,0))
!cvTsCheckSparse(m_s, _test_sparse, 0) ||
!cvTsCheckSparse(_m_s2, _test_sparse, 0))
{
ts->printf( cvtest::TS::LOG, "the read sparse matrix is not correct\n" );
ts->set_failed_test_info( cvtest::TS::FAIL_INVALID_OUTPUT );

@ -669,7 +669,7 @@ void Core_ArrayOpTest::run( int /* start_from */)
cvSetReal3D(&matA, idx1[0], idx1[1], idx1[2], -val0);
cvSetND(&matB, idx0, val1);
cvSet3D(&matB, idx1[0], idx1[1], idx1[2], -val1);
Ptr<CvMatND> matC = cvCloneMatND(&matB);
Ptr<CvMatND> matC(cvCloneMatND(&matB));
if( A.at<float>(idx0[0], idx0[1], idx0[2]) != val0 ||
A.at<float>(idx1[0], idx1[1], idx1[2]) != -val0 ||
@ -762,7 +762,7 @@ void Core_ArrayOpTest::run( int /* start_from */)
}
}
Ptr<CvSparseMat> M2 = cvCreateSparseMat(M);
Ptr<CvSparseMat> M2(cvCreateSparseMat(M));
MatND Md;
M.copyTo(Md);
SparseMat M3; SparseMat(Md).convertTo(M3, Md.type(), 2);

Loading…
Cancel
Save