26 #ifndef SMART_POINTER_HPP
27 #define SMART_POINTER_HPP
29 #include "../my_config.h"
46 smart_node(T *arg): ptr(arg), count_ref(0) {
if(arg ==
nullptr)
throw SRC_BUG; };
47 ~
smart_node() {
if(ptr !=
nullptr)
delete ptr;
if(!count_ref.is_zero())
throw SRC_BUG; };
49 void add_ref() { ++count_ref; };
50 void del_ref() {
if(count_ref.is_zero())
throw SRC_BUG; --count_ref;
if(count_ref.is_zero())
delete this; };
51 T & get_val() {
return *ptr; };
88 throw Ememory(
"smart_pointer::smart_pointer");
106 if(ref.ptr !=
nullptr)
134 T &
operator *()
const {
if(ptr ==
nullptr)
throw SRC_BUG;
return ptr->get_val(); };
137 T*
operator ->()
const {
if(ptr ==
nullptr)
throw SRC_BUG;
return &(ptr->get_val()); };
140 bool is_null()
const {
return ptr ==
nullptr; };
T * operator->() const
content-of filed operator (when the pointed to object is a struct or class
smart_pointer(const smart_pointer &ref)
copy constructor
memory_pool * get_pool() const
smart_pointer()
creates a smart_pointer equivalent to a pointer to NULL
exception used when memory has been exhausted
contains all the excetion class thrown by libdar
switch module to limitint (32 ou 64 bits integers) or infinint
const smart_pointer & assign(T *arg)
this is the base class of object that can be allocated on a memory pool
~smart_pointer()
destructor
T & operator*() const
content-of operator
const smart_pointer & operator=(const smart_pointer &ref)
assignment operator
bool is_null() const
return whether the smart_pointer is pointing to nullptr
libdar namespace encapsulate all libdar symbols