Ptex
Public Member Functions | Private Member Functions | Private Attributes | List of all members
PtexPtr< T > Class Template Reference

Smart-pointer for acquiring and releasing API objects. More...

#include <Ptexture.h>

Public Member Functions

 PtexPtr (T *ptr=0)
 Constructor. More...
 
 ~PtexPtr ()
 Destructor, calls ptr->release(). More...
 
 operator T* () const
 Use as pointer value. More...
 
T * operator-> () const
 Access members of pointer. More...
 
T * get () const
 Get pointer value. More...
 
void swap (PtexPtr &p)
 Swap pointer values. More...
 
void reset (T *ptr=0)
 Deallocate object pointed to, and optionally set to new value. More...
 

Private Member Functions

 PtexPtr (const PtexPtr &p)
 Copying prohibited. More...
 
void operator= (PtexPtr &p)
 Assignment prohibited. More...
 

Private Attributes

T * _ptr
 

Detailed Description

template<class T>
class PtexPtr< T >

Smart-pointer for acquiring and releasing API objects.

All public API objects must be released back to the Ptex library via the release() method. This smart-pointer class can wrap any of the Ptex API objects and will automatically release the object when the pointer goes out of scope. Usage of PtexPtr is optional, but recommended.

Note: for efficiency and safety, PtexPtr is noncopyable. However, ownership can be transferred between PtexPtr instances via the PtexPtr::swap member function.

Example:

{
Ptex::String error;
PtexPtr<PtexTexture> inptx(PtexTexture::open(inptxname, error));
if (!inptx) {
std::cerr << error << std::endl;
}
else {
// read some data
inptx->getData(faceid, buffer, stride);
}
}

Definition at line 1045 of file Ptexture.h.

Constructor & Destructor Documentation

◆ PtexPtr() [1/2]

template<class T >
PtexPtr< T >::PtexPtr ( T *  ptr = 0)
inline

Constructor.

Definition at line 1049 of file Ptexture.h.

◆ ~PtexPtr()

template<class T >
PtexPtr< T >::~PtexPtr ( )
inline

Destructor, calls ptr->release().

Definition at line 1052 of file Ptexture.h.

References PtexPtr< T >::_ptr.

◆ PtexPtr() [2/2]

template<class T >
PtexPtr< T >::PtexPtr ( const PtexPtr< T > &  p)
private

Copying prohibited.

Member Function Documentation

◆ get()

template<class T >
T* PtexPtr< T >::get ( ) const
inline

Get pointer value.

Definition at line 1061 of file Ptexture.h.

References PtexPtr< T >::_ptr.

Referenced by PtexReader::getData().

◆ operator T*()

template<class T >
PtexPtr< T >::operator T* ( ) const
inline

Use as pointer value.

Definition at line 1055 of file Ptexture.h.

References PtexPtr< T >::_ptr.

◆ operator->()

template<class T >
T* PtexPtr< T >::operator-> ( ) const
inline

Access members of pointer.

Definition at line 1058 of file Ptexture.h.

References PtexPtr< T >::_ptr.

◆ operator=()

template<class T >
void PtexPtr< T >::operator= ( PtexPtr< T > &  p)
private

Assignment prohibited.

◆ reset()

template<class T >
void PtexPtr< T >::reset ( T *  ptr = 0)
inline

Deallocate object pointed to, and optionally set to new value.

Definition at line 1072 of file Ptexture.h.

References PtexPtr< T >::_ptr.

◆ swap()

template<class T >
void PtexPtr< T >::swap ( PtexPtr< T > &  p)
inline

Swap pointer values.

Definition at line 1064 of file Ptexture.h.

References PtexPtr< T >::_ptr.

Member Data Documentation

◆ _ptr

template<class T >
T* PtexPtr< T >::_ptr
private

The documentation for this class was generated from the following file:
Ptex::String
Memory-managed string.
Definition: Ptexture.h:309
PtexTexture::open
static PtexTexture * open(const char *path, Ptex::String &error, bool premultiply=0)
Open a ptex file for reading.
Definition: PtexReader.cpp:59
PtexPtr
Smart-pointer for acquiring and releasing API objects.
Definition: Ptexture.h:1045