28#ifndef SMART_POINTER_HPP
29#define SMART_POINTER_HPP
50 smart_node(T *arg): ptr(arg), count_ref(0) {
if(arg ==
nullptr)
throw SRC_BUG; };
55 ~smart_node() noexcept(false) {
if(ptr !=
nullptr)
delete ptr;
if(!count_ref.
is_zero())
throw SRC_BUG; };
57 void add_ref() { ++count_ref; };
58 void del_ref() {
if(count_ref.
is_zero())
throw SRC_BUG; --count_ref;
if(count_ref.
is_zero())
delete this; };
59 T & get_val() {
return *ptr; };
96 throw Ememory(
"smart_pointer::smart_pointer");
117 if(ref.ptr !=
nullptr)
159 T &
operator *()
const {
if(ptr ==
nullptr)
throw SRC_BUG;
return ptr->get_val(); };
162 T*
operator ->()
const {
if(ptr ==
nullptr)
throw SRC_BUG;
return &(ptr->get_val()); };
165 bool is_null()
const {
return ptr ==
nullptr; };
exception used when memory has been exhausted
class which holds the address of the allocated memory for many smart_pointers
smart pointer class to be used to automagically manage multiple time pointed to address
smart_pointer & operator=(const smart_pointer &ref)
assignment operator
bool is_null() const
return whether the smart_pointer is pointing to nullptr
smart_pointer(T *arg)
creates a smart_pointer pointing to an allocated memory
T & operator*() const
content-of operator
const smart_pointer & assign(T *arg)
assignment operator from a base type pointer (not from a smart_pointer)
smart_pointer(smart_pointer &&ref) noexcept
move constructor
smart_pointer(const smart_pointer &ref)
copy constructor
T * operator->() const
content-of field operator (when the pointed to object is a struct or class
smart_pointer()
creates a smart_pointer equivalent to a pointer to NULL
~smart_pointer()
destructor
contains all the excetion class thrown by libdar
switch module to limitint (32 ou 64 bits integers) or infinint
include macro defined by the configure script and some specific additional ones
libdar namespace encapsulate all libdar symbols