Class: TInstanceOf

Declaration: SafePointers.h

Taxonomy Categories:

Member Functions:


Interface Category:

API.

Inherits From:

TPointerTo.

Inherited By:

None.

Purpose:

Contains a pointer to an object, and owns that object. Copying a TInstanceOf also copies the object (if any) to which it points. Destroying a TInstanceOf destroys the object (if any) to which it points. Like all classes derived from TPointerTo, it can be dereferenced (operator * or operator ->) like a regular pointer; but if it contains NIL (0), dereferencing it throws an exception.

Instantiation:

Allocate on the heap or the stack.

Deriving Classes:

You should not derive any classes from TInstanceOf.

Concurrency:

Not multithread safe.

Resource Use:

No special requirements.

Other Considerations:

TInstanceOf can only point to a class whose destructor is public, and which is copyable; that is, there must be a global function CopyPointer(AType*).

Member Function: TInstanceOf::TInstanceOf

  1. TInstanceOf (AType * adopt =NIL)
  2. TInstanceOf (const TInstanceOf < AType > & copy)
  3. TInstanceOf (const TInstanceOf < AType > & copy, TMemoryHeap & whereToCreate)

Interface Category:

API.

Purpose:

  1. Adopts the object (if any) specified. The object is not copied. Use this constructor with care: constructing multiple TInstanceOf objects from the same AType* usually leads to attempting to delete that pointer repeatedly (which is erroneous).
  2. Copies the object (if any) to which the TInstanceOf points, and adopts the copy.
  3. Copies the object (if any) to which the TInstanceOf points into the specified heap, and adopts the copy.

Calling Context:

  1. Call this function directly to initialize this TInstanceOf.
  2. Call this function directly to copy a TInstanceOf.
  3. Call this function directly to copy a TInstanceOf.

Parameters:

Return Value:

None.

Exceptions:

Throws no exceptions, passes all exceptions through.

Concurrency:

Not multithread safe.

Other Considerations:

None.

Member Function: TInstanceOf::~TInstanceOf

~ TInstanceOf ()

Interface Category:

API.

Purpose:

Destructor which destroys both the adopted object and this object.

Calling Context:

Call this function directly to destroy both this object and the object it wraps.

Parameters:

Return Value:

None.

Exceptions:

Throws no exceptions, passes all exceptions through.

Concurrency:

Not multithread safe.

Other Considerations:

None.

Member Function: TInstanceOf::operator=

  1. TInstanceOf < AType > & operator =(AType * adopt)
  2. TInstanceOf < AType > & operator =(const TInstanceOf < AType > & copy)

Interface Category:

API.

Purpose:

  1. Adopts the object specified, and destroys the previously adopted object (if any).
  2. Copies the object (if any) to which the parameter points, adopts the copy, and destroys the previously adopted object (if any).

Calling Context:

  1. Call this function directly to adopt an object.
  2. Call this function directly to copy an object.

Parameters:

Return Value:

A reference to this object.

Exceptions:

Throws no exceptions, passes all exceptions through.

Concurrency:

Not multithread safe.

Other Considerations:

None.

Member Function: TInstanceOf::operator==

  1. bool operator ==(const AType * r) const
  2. bool operator ==(const TInstanceOf < AType > & r) const

Interface Category:

API.

Purpose:

Compare pointers for equality.

Calling Context:

Call this function directly to determine if two pointers are identical.

Parameters:

Return Value:

Returns true if this object and the parameter both point to the same object, or if both contain NIL.

Exceptions:

Throws no exceptions.

Concurrency:

Not multithread safe.

Other Considerations:

true will also be returned if both pointers are NIL.

Member Function: TInstanceOf::operator!=

  1. bool operator != (const AType * r) const
  2. bool operator != (const TInstanceOf < AType > & r) const

Interface Category:

API.

Purpose:

Compare pointers for inequality.

Calling Context:

Call this function directly to determine if two pointers are different.

Parameters:

Return Value:

Returns true if this object and the parameter point to different objects, or if one but not both contain NIL.

Exceptions:

Throws no exceptions.

Concurrency:

Not multithread safe.

Other Considerations:

None.

Member Function: TInstanceOf::Orphan

AType * Orphan ()

Interface Category:

API.

Purpose:

Returns a copy of the pointer contained in this object, and changes this object to contain NIL. The object (if any) to which this object pointed is not affected.

Calling Context:

Call this function directly to release a adopted object.

Parameters:

Return Value:

A copy of the pointer that was contained in this object.

Exceptions:

Throws no exceptions.

Concurrency:

Not multithread safe.

Other Considerations:

None.
Click the icon to mail questions or corrections about this material to Taligent personnel.
Copyright©1995 Taligent,Inc. All rights reserved.