Interface Technology Basics: OPtr< I > Class Template Reference
Author: Steinberg

Interface Technology Basics VST 3.7 SDK for developing VST plug-in

Loading...
Searching...
No Matches
Public Member Functions | List of all members
OPtr< I > Class Template Reference
Basic Interfaces

OPtr - "owning" smart pointer used for newly created FObjects. More...

`#include <smartpointer.h>`

Inheritance diagram for OPtr< I >:

## Public Member Functions
| OPtr (I *p)
| OPtr (const IPtr< I > &p)
| OPtr (const OPtr< I > &p)
| OPtr ()
I * | operator= (I *_ptr)
Public Member Functions inherited from IPtr< I >
| IPtr (I *ptr, bool addRef=true)
| IPtr (const IPtr &)
template<class T>
| IPtr (const IPtr< T > &other)
| IPtr ()
| ~IPtr ()
I * | operator= (I *ptr)
IPtr & | operator= (const IPtr &other)
template<class T>
IPtr & | operator= (const IPtr< T > &other)
| operator I* () const
I * | operator-> () const
I * | get () const
void | reset (I *obj=nullptr)
I * | take () SMTG_NOEXCEPT
template<class I>
| IPtr (const IPtr< I > &other)
template<class I>
IPtr< I > & | operator= (const IPtr< I > &_ptr)

## Additional Inherited Members
Static Public Member Functions inherited from IPtr< I >
template<typename T>
static IPtr< T > | adopt (T *obj) SMTG_NOEXCEPT
Protected Attributes inherited from IPtr< I >
I * | ptr

## Detailed Description

template<class I>
class Steinberg::OPtr< I >

OPtr - "owning" smart pointer used for newly created FObjects.

FUnknown implementations are supposed to have a refCount of 1 right after creation. So using an IPtr on newly created objects would lead to a leak. Instead the OPtr can be used in this case.
Example:

OPtr<IPath> path = FHostCreate (IPath, hostClasses);
// no release is needed...
Steinberg::OPtr::OPtr
OPtr(I *p)
Definition smartpointer.h:213

The assignment operator takes ownership of a new object and releases the old. So its safe to write:

OPtr<IPath> path = FHostCreate (IPath, hostClasses);
path = FHostCreate (IPath, hostClasses);
path = 0;

This is the difference to using an IPtr with addRef=false.

// DONT DO THIS:
IPtr<IPath> path (FHostCreate (IPath, hostClasses), false);
path = FHostCreate (IPath, hostClasses);
path = 0;
Steinberg::IPtr::IPtr
IPtr(I *ptr, bool addRef=true)
Definition smartpointer.h:126

This will lead to a leak!

## Constructor & Destructor Documentation

## ◆ OPtr() [1/4]

template<class I>

OPtr | ( | I * | p | ) |
| inline

## ◆ OPtr() [2/4]

template<class I>

OPtr | ( | const IPtr< I > & | p | ) |
| inline

## ◆ OPtr() [3/4]

template<class I>

OPtr | ( | const OPtr< I > & | p | ) |
| inline

## ◆ OPtr() [4/4]

template<class I>

OPtr | ( |  | ) |
| inline

## Member Function Documentation

## ◆ operator=()

template<class I>

I * operator= | ( | I * | _ptr | ) |
| inline

Empty

Copyright © Steinberg Media Technologies GmbH. All Rights Reserved. This documentation is under this license.