template<class AType> class TPointerTo {
public:
AType*GetAlias() const{return fPointer;}
BooleanIsValid() const{return GetAlias() != NIL;}
voidValidate() const{if ( ! IsValid()) throw TInvalidSafePointer();}
AType*operator->() const{Validate(); return GetAlias();}
AType&operator*() const{return *(operator->());}
protected:
TPointerTo (AType* p = NIL) : fPointer (p) {}
void operator= (AType* p) {fPointer = p;}
~TPointerTo() {} // It's not permitted to delete a TPointerTo<>*.
AType* Orphan();
private:
AType *fPointer;
};
template<class AType> AType*
CopyPointer (const TPointerTo<AType>& from)
{return CopyPointer (from.GetAlias());}
template<class AType> AType*
CopyPointer (const TPointerTo<AType>& from, TMemoryHeap& into)
{return CopyPointer (from.GetAlias(), into);}
template<class AType> AType*
CopyPointer (const TPointerTo<AType>& from, EHeapType t, const void* o)
{return CopyPointer (from.GetAlias(), t, o);}
template<class AType> void
Flatten (const TPointerTo<AType>& from, TStream& into)
{Flatten (from.GetAlias(), into);}
template<class AType> void
StreamOutLengthAndFlatten (const TPointerTo<AType>& from, TStream& into)
{StreamOutLengthAndFlatten (from.GetAlias(), into);}