C++ pointer templates

by Jonathan Henckel, Jan 29 1997

The smart pointer template library provides many different pointer templates. Each template is a different combination of features.

COPY SEMANTICS

The most salient feature of the pointer template is how the pointer is copied, (by the assignment operator or copy constructor). The three options are

ARRAY SUPPORT

A pointer may point to only one object, or it may access an array of objects. Various levels of array support are available.

PRIMITIVE TYPES

If the pointer template declares operator->, then the pointer cannot point to primitives, like char, long, double. Therefore this operator is optional.

FORWARD CLASSES

A pointer can point to a class T that is as yet undefined with one condition: the pointer destructor must not be inline. In this case the destructor can be defined in the .cpp after T is defined.

COMPARATOR OPERATORS

It may be useful if the operations <, >, <=, >=, == on the pointer would be delegated to the object. This way the pointers can be kept in a sorted collection of some kind. A macro is supplied to define these operators; they are not class methods.

The following is a list of all the template classes

The templates with "Prim" in the name do not define operator->.

The templates with "Fwd" in the name do not define the destructor. The developer must explicitly define the destructor at the right place in the code using this macro

The DeepCopy_Pointer cannot be Fwd because it needs to make copies of the objects, so the object type must be defined.

The templates with "1" in the name do NOT declare any array operations such as operator[] and length. The templates without "1" in the name do declare the array operations, but they do not define them. The user may define the array operations with one and only one of the following macros

The scope can be either inline or INPGM. The latter defines the array operations non-inline. Note that StackOps requires that the type of the object be defined, not just forward declared.

Support for comparators can be added to any pointer template with the following macro

In conclusion, the library provides 16 basic pointer templates, and 8 of them can have one of three array implementations, and comparators can be added to any template. That makes 64 combinations.


This page hosted by Get your own Free Home Page