ManagedServices::sealed< T, DestructorPolicy > Class Template Reference


Detailed Description

template<typename T, typename DestructorPolicy = DeletePolicy>
class ManagedServices::sealed< T, DestructorPolicy >

Native resource guard providing automatic clean up of native pointer types inside managed code.

This is modeled after the C++ standard library autoptr, but intended for use in managed code. When a NativeAutoPointer instance is Reset, Disposed, or cleaned up by the garbage collector, it will destroy its pointer.

A NativeAutoPointer will clean up its pointer using the DestructorPolicy template parameter.

Template Parameters:
T Type of the held pointer.
DestructorPolicy Policy template parameter responsible for cleaning up the pointer. This must be matched to the pointer type's expected destruction method. Defaults to DeletePolicy.

List of all members.

Public Types

typedef T  NativeType

Public Member Functions

  NativeAutoPointer ()
  Construct an empty NativeAutoPointer.
  NativeAutoPointer (NativeType *pointer)
  Construct a NativeAutoPointer holding the given pointer.
  ~NativeAutoPointer ()
  Destructor.
  !NativeAutoPointer ()
  Finalizer.
NativeType Dereference ()
  Access and dereference the held pointer.
NativeType Get ()
  Get the held pointer.
NativeType Release ()
  Release the held pointer.
void  Reset (NativeType *pointer)
  Clean up the held pointer and take ownership of a new pointer.
bool  IsNull ()
  Is the held pointer null?

Member Typedef Documentation

template<typename T , typename DestructorPolicy = DeletePolicy>
typedef T ManagedServices::sealed< T, DestructorPolicy >::NativeType

Constructor & Destructor Documentation

template<typename T , typename DestructorPolicy = DeletePolicy>
ManagedServices::sealed< T, DestructorPolicy >::~NativeAutoPointer ( ) [inline]

Destructor.

Destroys the held pointer.

template<typename T , typename DestructorPolicy = DeletePolicy>
ManagedServices::sealed< T, DestructorPolicy >::!NativeAutoPointer ( ) [inline]

Finalizer.

Destroys the held pointer.


Member Function Documentation

template<typename T , typename DestructorPolicy = DeletePolicy>
ManagedServices::sealed< T, DestructorPolicy >::NativeAutoPointer ( ) [inline]

Construct an empty NativeAutoPointer.

template<typename T , typename DestructorPolicy = DeletePolicy>
ManagedServices::sealed< T, DestructorPolicy >::NativeAutoPointer ( NativeType pointer ) [inline]

Construct a NativeAutoPointer holding the given pointer.

Parameters:
pointer Pointer to manage
template<typename T , typename DestructorPolicy = DeletePolicy>
NativeType& ManagedServices::sealed< T, DestructorPolicy >::Dereference ( ) [inline]

Access and dereference the held pointer.

Returns:
A reference to the held pointer's target object instance.
template<typename T , typename DestructorPolicy = DeletePolicy>
NativeType* ManagedServices::sealed< T, DestructorPolicy >::Get ( ) [inline]

Get the held pointer.

This NativeAutoPointer will still own the held pointer.

Returns:
The held pointer.
template<typename T , typename DestructorPolicy = DeletePolicy>
NativeType* ManagedServices::sealed< T, DestructorPolicy >::Release ( ) [inline]

Release the held pointer.

This NativeAutoPointer will no longer be responsible for cleaning up the pointer.

Sets the held pointer to null.

Returns:
The formerly held, now released, pointer.
template<typename T , typename DestructorPolicy = DeletePolicy>
void ManagedServices::sealed< T, DestructorPolicy >::Reset ( NativeType pointer ) [inline]

Clean up the held pointer and take ownership of a new pointer.

Cleans up the held pointer using the DestructorPolicy.

<param name="pointer>The new pointer of which this NativeAutoPointer will assume responsibility.

template<typename T , typename DestructorPolicy = DeletePolicy>
bool ManagedServices::sealed< T, DestructorPolicy >::IsNull ( ) [inline]

Is the held pointer null?

Returns:
true if the held pointer is null, false otherwise.