InDesign SDK  20.5
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
InterfacePtr< IFace > Class Template Reference

#include <InterfacePtr.h>

Public Types

typedef object_type data_type
 

Public Member Functions

 InterfacePtr (IFace *p)
 
 InterfacePtr (const IPMUnknown *p, PMIID iid)
 
 InterfacePtr (const IPMUnknown *p, const UseDefaultIID &)
 
 InterfacePtr (void)
 
template<class OtherType >
 InterfacePtr (const InterfacePtr< OtherType > &p)
 
 InterfacePtr (const InterfacePtr< IFace > &p)
 
 InterfacePtr (InterfacePtr< IFace > &&p) noexcept
 
template<class OtherType >
InterfacePtr< IFace > & operator= (const InterfacePtr< OtherType > &p)
 
InterfacePtr< IFace > & operator= (const InterfacePtr< IFace > &p)
 
InterfacePtr< IFace > & operator= (InterfacePtr< IFace > &&p) noexcept
 
 InterfacePtr (IDataBase *db, UID uid, PMIID iid)
 
 InterfacePtr (IDataBase *db, UID uid, const UseDefaultIID &)
 
 InterfacePtr (const UIDRef &ref, PMIID iid)
 
 InterfacePtr (const UIDRef &ref, const UseDefaultIID &)
 
 operator IFace * () const
 
IFace * operator-> () const
 
bool16 operator! () const
 
IFace * forget ()
 
IFace * get () const
 
void reset (IFace *p=0)
 
void swap (InterfacePtr< IFace > &other) noexcept
 

Detailed Description

template<class IFace>
class InterfacePtr< IFace >

InterfacePtr is a smart pointer class that simplifies the work with interface pointers. It guarantees that Release() will be called on an acquired interface and AddRef() when sharing the ownership.

Member Typedef Documentation

template<class IFace>
typedef object_type InterfacePtr< IFace >::data_type

Allows containment of InterfacePtr in K2Vector.

Constructor & Destructor Documentation

template<class IFace>
InterfacePtr< IFace >::InterfacePtr(IFace * p)
inlineexplicit
This constructor will take ownership of the specified interface. AddRef is NOT called, but

Release will be called in the destructor. This functionality is best described as an Attach(). Most of the time, you do not want to use this constructor, but the ones with two parameters which do call AddRef. Do not use p after this call since it may be invalid after the InterfacePtr goes out of scope. Use this constructor when you've called a function that returns an AddRef'd pointer – e.g., QuerySpread(), QueryApplication(), etc.

Parameters
p[IN] - interface pointer that we attach to.
template<class IFace>
InterfacePtr< IFace >::InterfacePtr(const IPMUnknownp,
PMIID iid 
)
inline
Use this constructor if you have one interface on a boss and want another one. Addref is called

on the boss, so it is still safe to use the p after the InterfacePtr goes out of scope.

Parameters
p[IN] - interface to use for query.
iid[IN] - IID of the interface we want.
template<class IFace>
InterfacePtr< IFace >::InterfacePtr(const IPMUnknownp,
const UseDefaultIID 
)
inline

This constructor is similar to the one directly above. It is more convenient but will only compile if IFace::kDefaultIID is defined

Parameters
p[IN] - interface to use for query.
template<class IFace>
InterfacePtr< IFace >::InterfacePtr(void )
inline

Default constructor: construct a nil InterfacePtr

template<class IFace>
template<class OtherType >
InterfacePtr< IFace >::InterfacePtr(const InterfacePtr< OtherType > & p)
inline

Constructor that enables InterfacePtr<const IFoo> to be constructed from an InterfacePtr<IFoo>.

template<class IFace>
InterfacePtr< IFace >::InterfacePtr(const InterfacePtr< IFace > & p)
inline
Copy constructor. Increments the ref count of p by one. We define this to prevent the

compiler from generating a bitwise copying version (template members do not suffice).

Parameters
p[IN] - InterfacePtr to be copied.
template<class IFace>
InterfacePtr< IFace >::InterfacePtr(IDataBasedb,
UID uid,
PMIID iid 
)
inline
Constructs an InterfacePtr from an object from a database.

Parameters
db[IN] - Database to instantiate from
uid[IN] - UID of the boss.
iid[IN] - IID of the desired interface from the boss.
template<class IFace>
InterfacePtr< IFace >::InterfacePtr(IDataBasedb,
UID uid,
const UseDefaultIID 
)
inline
Constructs an InterfacePtr from an object from a database. This version is more

convenient but will only compile if IFace::kDefaultIID is defined.

Parameters
db[IN] - Database to instantiate from
uid[IN] - UID of the boss.
template<class IFace>
InterfacePtr< IFace >::InterfacePtr(const UIDRefref,
PMIID iid 
)
inline
Constructs an InterfacePtr from an object from a database.

Parameters
ref[IN] - UIDRef of the boss object
iid[IN] - IID of the desired interface from the boss.
template<class IFace>
InterfacePtr< IFace >::InterfacePtr(const UIDRefref,
const UseDefaultIID 
)
inline
Constructs an InterfacePtr from an object from a database.

This version is more convenient but will only compile if IFace::kDefaultIID is defined.

Parameters
ref[IN] - UIDRef of the boss object
iid[IN] - IID of the desired interface from the boss.

Member Function Documentation

template<class IFace>
IFace* InterfacePtr< IFace >::forget ()
inline
Detaches from the owned interface and transfers the ownership to the caller.

Note: The signature of this function makes it error-prone: if the caller doesn't take ownership of the interface (doesn't assign the result) the interface will be leaked.

Returns
the owned interface
template<class IFace>
IFace* InterfacePtr< IFace >::get () const
inline
Accessor for the owned pointer.

Returns
the contained pointer
template<class IFace>
InterfacePtr< IFace >::operator IFace * () const
inline
Implicit conversion operator. Allows implicit conversion between InterfacePtr<IFace> and IFace*.

Returns
the contained pointer.
template<class IFace>
bool16 InterfacePtr< IFace >::operator! () const
inline
Boolean test operator (Null test).

Returns
kTrue if the contained pointer is nil.
template<class IFace>
IFace* InterfacePtr< IFace >::operator-> () const
inline
Indirection operator. If the pointer is nil, it will ASSERT in Debug builds and will

have unspecified behavior in the Release builds.

Returns
the contained pointer
template<class IFace>
template<class OtherType >
InterfacePtr<IFace>& InterfacePtr< IFace >::operator= (const InterfacePtr< OtherType > & p)
inline
Assigment operator. Increments the ref count of p by one.

This one enables InterfacePtr<const IFoo> = InterfacePtr<IFoo>

Parameters
p[IN] - InterfacePtr to be copied.
template<class IFace>
InterfacePtr<IFace>& InterfacePtr< IFace >::operator= (const InterfacePtr< IFace > & p)
inline
Assigment operator. Increments the ref count of p by one.

This one enables copying of InterfacePtr of the same types.

Parameters
p[IN] - InterfacePtr to be copied.
template<class IFace>
void InterfacePtr< IFace >::reset (IFace * p = 0)
inline
Releases the ownership for the current interface and attaches to the new one.

Note: the reference count of p will NOT be changed (AddRef is not called).

Parameters
p[IN] - new interface pointer to take ownership of