opencv 2.2.0

- Main Page
- Related Pages
- Namespaces
- Classes
- Files

- Class List
- Class Index
- Class Hierarchy
- Class Members

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Public Member Functions | Protected Attributes | List of all members
cv::Ptr< _Tp > Class Template Reference

`#include <core.hpp>`

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

## Protected Attributes
_Tp * | obj
int * | refcount

## 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()

## Member Function Documentation

template<typename _Tp >

void cv::Ptr< _Tp >::addref | ( |  | ) |
| inline

increments the reference counter

template<>

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

template<>

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

template<>

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

template<>

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

template<>

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

template<>

void cv::Ptr< CvStereoBMState >::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 >

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

template<typename _Tp>

int* cv::Ptr< _Tp >::refcount
| protected

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

- /usr/obj/OpenCV-2.2.0/OpenCV-2.2.0/modules/core/include/opencv2/core/core.hpp
- /usr/obj/OpenCV-2.2.0/OpenCV-2.2.0/modules/core/include/opencv2/core/operations.hpp