Disk ARchive: libdar::smart_pointer< T > Class Template Reference

| Disk ARchive 2.8.1 Full featured and portable backup and archiving tool

Loading...
Searching...
No Matches
Public Member Functions | Private Attributes | List of all members
libdar::smart_pointer< T > Class Template Reference
Private

smart pointer class to be used to automagically manage multiple time pointed to address More...

`#include <smart_pointer.hpp>`

## Public Member Functions
| smart_pointer ()
| creates a smart_pointer equivalent to a pointer to NULL
| smart_pointer (T *arg)
| creates a smart_pointer pointing to an allocated memory
| smart_pointer (const smart_pointer &ref)
| copy constructor
| smart_pointer (smart_pointer &&ref) noexcept
| move constructor
| ~smart_pointer ()
| destructor
smart_pointer & | operator= (const smart_pointer &ref)
| assignment operator
smart_pointer & | operator= (smart_pointer &&ref)
| move assignment operator
const smart_pointer & | assign (T *arg)
| assignment operator from a base type pointer (not from a smart_pointer)
T & | operator* () const
| content-of operator
T * | operator-> () const
| content-of field operator (when the pointed to object is a struct or class
bool | is_null () const
| return whether the smart_pointer is pointing to nullptr

## Private Attributes
smart_node< T > * | ptr

## Detailed Description

template<class T>
class libdar::smart_pointer< T >

smart pointer class to be used to automagically manage multiple time pointed to address

this class tend to mimic normal pointer with the additional feature of automatically releasing the pointed to object when no more smart_pointer point to it. In consequence:

- it must not be used to point to non dynamically allocated memory using the "new" operator,
- pointed to memory must never be deleted manually, the last smart_pointer will do it at its destruction time
  Note
    IMPORTANT: smart_pointer cannot be shared between different threads, for efficiency, the smart_pointer nor the pointed to object is protected against concurrent access of several threads

Definition at line 78 of file smart_pointer.hpp.

## Constructor & Destructor Documentation

## ◆ smart_pointer() [1/4]

template<class T>

libdar::smart_pointer< T >::smart_pointer | ( |  | ) |
| inline

creates a smart_pointer equivalent to a pointer to NULL

Definition at line 82 of file smart_pointer.hpp.

Referenced by assign(), operator=(), operator=(), smart_pointer(), and smart_pointer().

## ◆ smart_pointer() [2/4]

template<class T>

libdar::smart_pointer< T >::smart_pointer | ( | T * | arg | ) |
| inline

creates a smart_pointer pointing to an allocated memory

Parameters

  [in] | arg | is the address of the allocated memory the smart_pointer must manage, nullptr is allowed and lead to the same behavior as the constructor without argument

Note
  the given pointed to object, passes under the responsibility of the smart_pointer and must not be deleted any further

Definition at line 90 of file smart_pointer.hpp.

## ◆ smart_pointer() [3/4]

template<class T>

libdar::smart_pointer< T >::smart_pointer | ( | const smart_pointer< T > & | ref | ) |
| inline

copy constructor

Definition at line 104 of file smart_pointer.hpp.

References smart_pointer().

## ◆ smart_pointer() [4/4]

template<class T>

libdar::smart_pointer< T >::smart_pointer | ( | smart_pointer< T > && | ref | ) |
| inlinenoexcept

move constructor

Definition at line 107 of file smart_pointer.hpp.

References smart_pointer().

## ◆ ~smart_pointer()

template<class T>

libdar::smart_pointer< T >::~smart_pointer | ( |  | ) |
| inline

destructor

Definition at line 110 of file smart_pointer.hpp.

## Member Function Documentation

## ◆ assign()

template<class T>

const smart_pointer & libdar::smart_pointer< T >::assign | ( | T * | arg | ) |
| inline

assignment operator from a base type pointer (not from a smart_pointer)

Note
  choice has been not to overload/use operator= to avoid risk of error that would lead to create independent smart_pointer sets accidentally

Definition at line 151 of file smart_pointer.hpp.

References smart_pointer().

## ◆ is_null()

template<class T>

bool libdar::smart_pointer< T >::is_null | ( |  | ) | const
| inline

return whether the smart_pointer is pointing to nullptr

Definition at line 165 of file smart_pointer.hpp.

## ◆ operator*()

template<class T>

T & libdar::smart_pointer< T >::operator* | ( |  | ) | const
| inline

content-of operator

Definition at line 159 of file smart_pointer.hpp.

## ◆ operator->()

template<class T>

T * libdar::smart_pointer< T >::operator-> | ( |  | ) | const
| inline

content-of field operator (when the pointed to object is a struct or class

Definition at line 162 of file smart_pointer.hpp.

## ◆ operator=() [1/2]

template<class T>

smart_pointer & libdar::smart_pointer< T >::operator= | ( | const smart_pointer< T > & | ref | ) |
| inline

assignment operator

Definition at line 113 of file smart_pointer.hpp.

References smart_pointer().

## ◆ operator=() [2/2]

template<class T>

smart_pointer & libdar::smart_pointer< T >::operator= | ( | smart_pointer< T > && | ref | ) |
| inline

move assignment operator

Definition at line 134 of file smart_pointer.hpp.

References smart_pointer().

## Member Data Documentation

## ◆ ptr

template<class T>

smart_node<T>* libdar::smart_pointer< T >::ptr
| private

Definition at line 168 of file smart_pointer.hpp.

The documentation for this class was generated from the following file:

- smart_pointer.hpp