OpenCV  2.4.13.2
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

§ Ptr() [1/4]

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

empty constructor

§ Ptr() [2/4]

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

§ ~Ptr()

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

calls release()

§ Ptr() [3/4]

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

copy constructor. Copies the members and calls addref()

§ Ptr() [4/4]

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

Member Function Documentation

§ addref()

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

increments the reference counter

§ delete_obj() [1/18]

template<>
void cv::Ptr< GlBuffer::Impl >::delete_obj ( )

§ delete_obj() [2/18]

template<>
void cv::Ptr< GlTexture::Impl >::delete_obj ( )

§ delete_obj() [3/18]

template<>
void cv::Ptr< CvCapture >::delete_obj ( )

§ delete_obj() [4/18]

template<>
void cv::Ptr< CvVideoWriter >::delete_obj ( )

§ delete_obj() [5/18]

template<>
void cv::Ptr< cv::ogl::Buffer::Impl >::delete_obj ( )

§ delete_obj() [6/18]

template<>
void cv::Ptr< cv::ogl::Texture2D::Impl >::delete_obj ( )

§ delete_obj() [7/18]

template<>
void cv::Ptr< CvHaarClassifierCascade >::delete_obj ( )

§ delete_obj() [8/18]

template<>
void cv::Ptr< IplConvKernel >::delete_obj ( )

§ delete_obj() [9/18]

template<>
void cv::Ptr< CvStereoBMState >::delete_obj ( )

§ delete_obj() [10/18]

template<>
void cv::Ptr< CvHistogram >::delete_obj ( )

§ delete_obj() [11/18]

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

deletes the object. Override if needed

§ delete_obj() [12/18]

template<>
void cv::Ptr< CvDTreeSplit >::delete_obj ( )

§ delete_obj() [13/18]

template<>
void cv::Ptr< CvMat >::delete_obj ( )

§ delete_obj() [14/18]

template<>
void cv::Ptr< IplImage >::delete_obj ( )

§ delete_obj() [15/18]

template<>
void cv::Ptr< CvMatND >::delete_obj ( )

§ delete_obj() [16/18]

template<>
void cv::Ptr< CvSparseMat >::delete_obj ( )

§ delete_obj() [17/18]

template<>
void cv::Ptr< CvMemStorage >::delete_obj ( )

§ delete_obj() [18/18]

template<>
void cv::Ptr< CvFileStorage >::delete_obj ( )

§ empty()

template<typename _Tp >
bool cv::Ptr< _Tp >::empty ( ) const
inline

returns true iff obj==NULL

§ operator _Tp *()

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

§ operator const _Tp *()

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

§ operator->() [1/2]

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

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

§ operator->() [2/2]

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

§ operator=()

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

§ ptr() [1/2]

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

cast pointer to another type

§ ptr() [2/2]

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

§ release()

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

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

Member Data Documentation

§ obj

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

§ refcount

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

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