OpenCV  2.4.13
Open Source Computer Vision
cv::Ptr< _Tp > Class Template Reference

#include <core.hpp>

Public Member Functions

 Ptr ()
 empty constructor More...
 
 Ptr (_Tp *_obj)
 take ownership of the pointer. The associated reference counter is allocated and set to 1 More...
 
 ~Ptr ()
 calls release() More...
 
 Ptr (const Ptr &ptr)
 copy constructor. Copies the members and calls addref() More...
 
template<typename _Tp2 >
 Ptr (const Ptr< _Tp2 > &ptr)
 
Ptroperator= (const Ptr &ptr)
 copy operator. Calls ptr.addref() and release() before copying the members More...
 
void addref ()
 increments the reference counter More...
 
void release ()
 decrements the reference counter. If it reaches 0, delete_obj() is called More...
 
void delete_obj ()
 deletes the object. Override if needed More...
 
bool empty () const
 returns true iff obj==NULL More...
 
template<typename _Tp2 >
Ptr< _Tp2 > ptr ()
 cast pointer to another type More...
 
template<typename _Tp2 >
const Ptr< _Tp2 > ptr () const
 
_Tp * operator-> ()
 helper operators making "Ptr<T> ptr" use very similar to "T* ptr". More...
 
const _Tp * operator-> () const
 
 operator _Tp * ()
 
 operator const _Tp * () const
 
template<>
void delete_obj ()
 
template<>
void delete_obj ()
 
template<>
void delete_obj ()
 
template<>
void delete_obj ()
 
template<>
void delete_obj ()
 
template<>
void delete_obj ()
 
template<>
void delete_obj ()
 
template<>
void delete_obj ()
 
template<>
void delete_obj ()
 
template<>
void delete_obj ()
 
template<>
void delete_obj ()
 
template<>
void delete_obj ()
 
template<>
void delete_obj ()
 
template<>
void delete_obj ()
 
template<>
void delete_obj ()
 
template<>
void delete_obj ()
 
template<>
void delete_obj ()
 

Public Attributes

_Tp * obj
 
intrefcount
 

Detailed Description

template<typename _Tp>
class cv::Ptr< _Tp >

Smart pointer to dynamically allocated objects.

This is template pointer-wrapping class that stores the associated reference counter along with the object pointer. The class is similar to std::smart_ptr<> from the recent addons to the C++ standard, but is shorter to write :) and self-contained (i.e. does add any dependency on the compiler or an external library).

Basically, you can use "Ptr<MyObjectType> ptr" (or faster "const Ptr<MyObjectType>& ptr" for read-only access) everywhere instead of "MyObjectType* ptr", where MyObjectType is some C structure or a C++ class. To make it all work, you need to specialize Ptr<>::delete_obj(), like:

template<> void Ptr<MyObjectType>::delete_obj() { call_destructor_func(obj); }
Note
{if MyObjectType is a C++ class with a destructor, you do not need to specialize delete_obj(), since the default implementation calls "delete obj;"}
{Another good property of the class is that the operations on the reference counter are atomic, i.e. it is safe to use the class in multi-threaded applications}

Constructor & Destructor Documentation

template<typename _Tp >
cv::Ptr< _Tp >::Ptr ( )
inline

empty constructor

template<typename _Tp>
cv::Ptr< _Tp >::Ptr ( _Tp *  _obj)
inline

take ownership of the pointer. The associated reference counter is allocated and set to 1

template<typename _Tp >
cv::Ptr< _Tp >::~Ptr ( )
inline

calls release()

template<typename _Tp>
cv::Ptr< _Tp >::Ptr ( const Ptr< _Tp > &  ptr)
inline

copy constructor. Copies the members and calls addref()

template<typename _Tp >
template<typename _Tp2 >
cv::Ptr< _Tp >::Ptr ( const Ptr< _Tp2 > &  ptr)

Member Function Documentation

template<typename _Tp >
void cv::Ptr< _Tp >::addref ( )
inline

increments the reference counter

template<>
void cv::Ptr< GlBuffer::Impl >::delete_obj ( )
template<>
void cv::Ptr< GlTexture::Impl >::delete_obj ( )
template<>
void cv::Ptr< CvCapture >::delete_obj ( )
template<>
void cv::Ptr< CvVideoWriter >::delete_obj ( )
template<>
void cv::Ptr< cv::ogl::Buffer::Impl >::delete_obj ( )
template<>
void cv::Ptr< cv::ogl::Texture2D::Impl >::delete_obj ( )
template<>
void cv::Ptr< CvHaarClassifierCascade >::delete_obj ( )
template<>
void cv::Ptr< IplConvKernel >::delete_obj ( )
template<>
void cv::Ptr< CvStereoBMState >::delete_obj ( )
template<>
void cv::Ptr< CvHistogram >::delete_obj ( )
template<typename _Tp >
void cv::Ptr< _Tp >::delete_obj ( )
inline

deletes the object. Override if needed

template<>
void cv::Ptr< CvDTreeSplit >::delete_obj ( )
template<>
void cv::Ptr< CvMat >::delete_obj ( )
template<>
void cv::Ptr< IplImage >::delete_obj ( )
template<>
void cv::Ptr< CvMatND >::delete_obj ( )
template<>
void cv::Ptr< CvSparseMat >::delete_obj ( )
template<>
void cv::Ptr< CvMemStorage >::delete_obj ( )
template<>
void cv::Ptr< CvFileStorage >::delete_obj ( )
template<typename _Tp >
bool cv::Ptr< _Tp >::empty ( ) const
inline

returns true iff obj==NULL

template<typename _Tp >
cv::Ptr< _Tp >::operator _Tp * ( )
inline
template<typename _Tp >
cv::Ptr< _Tp >::operator const _Tp * ( ) const
inline
template<typename _Tp >
_Tp * cv::Ptr< _Tp >::operator-> ( )
inline

helper operators making "Ptr<T> ptr" use very similar to "T* ptr".

template<typename _Tp >
const _Tp * cv::Ptr< _Tp >::operator-> ( ) const
inline
template<typename _Tp >
Ptr< _Tp > & cv::Ptr< _Tp >::operator= ( const Ptr< _Tp > &  ptr)
inline

copy operator. Calls ptr.addref() and release() before copying the members

template<typename _Tp >
template<typename _Tp2 >
Ptr< _Tp2 > cv::Ptr< _Tp >::ptr ( )
inline

cast pointer to another type

template<typename _Tp >
template<typename _Tp2 >
const Ptr< _Tp2 > cv::Ptr< _Tp >::ptr ( ) const
inline
template<typename _Tp >
void cv::Ptr< _Tp >::release ( )
inline

decrements the reference counter. If it reaches 0, delete_obj() is called

Member Data Documentation

template<typename _Tp>
_Tp* cv::Ptr< _Tp >::obj
template<typename _Tp>
int* cv::Ptr< _Tp >::refcount

The documentation for this class was generated from the following files: