Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
UppHub
Status & Roadmap
FAQ
Authors & License
Forums
Funding U++
Search on this site











SourceForge.net Logo

SourceForge.net Logo

GitHub Logo

Discord Logo

Ptr and Pte

Ptr and Pte class templates provide a smart pointer system that cleared (assigned NULL) when pointed object is destructed. That makes it useful in situations where life-time of object cannot be precisely determined.

While Ptr class template provides smart pointers, Pte is the class which adds necessary functionality to pointed objects. Ptr could only point to objects of Pte-derived type. So to make a class "Ptr-able" you should add Pte as one of class bases, with the derived class as its parameter, e.g.:

struct Foo : Pte<Foo> {....

 

 

Pte

 

template <class T>

class Pte : public PteBase

 

This template class implements the functionality needed in the pointed object.  

T    Type of pointed object.

 

Derived from PteBase

 

 

Ptr

 

template <class T>

class Ptr : public PtrBase, private Moveable< Ptr<T> > 

 

Type specific pointer.

T    Type of pointed object. T class must be derived from Pte<T>.

 

Derived from PtrBase

 

 

Constructor Detail

 

Ptr()

Default constructor.

 


 

Ptr(T *ptr)

Constructs Ptr pointing to specified object ptr.

 


 

Ptr(const Ptr& ptr)

Constructs Ptr pointing to the same object as other Ptr ptr.

 

 

Public Method List

 

T *operator->() const

Returns a C++ pointer to pointed object or NULL if Ptr does not point to any object.

 


 

T *operator~() const

Returns a C++ pointer to pointed object or NULL if Ptr does not point to any object.

 


 

operator T*() const

Returns a C++ pointer to pointed object or NULL if Ptr does not point to any object.

 


 

Ptr& operator=(T *ptr)

Assigns new pointer. Returns *this.

 


 

Ptr& operator=(const Ptr& ptr)

Assigns other Ptr. Returns *this.    

 


 

String ToString() const

Converts all information to string for diagnostic purposes

 

 

Global Operators

 

friend bool operator==(const Ptr& a, const T *b)

friend bool operator==(const T *a, const Ptr& b)

friend bool operator==(const Ptr& a, const Ptr& b)

friend bool operator==(const Ptr& a, T *b)

friend bool operator==(T *a, const Ptr& b)

friend bool operator!=(const Ptr& a, const T *b)

friend bool operator!=(const T *a, const Ptr& b)

friend bool operator!=(const Ptr& a, const Ptr& b)

Comparison operators.

 

 

Do you want to contribute?