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; };
memory_pool * get_pool() const
T & operator*() const
content-of operator
smart_pointer(const smart_pointer &ref)
copy constructor
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
bool is_null() const
return whether the smart_pointer is pointing to nullptr
const smart_pointer & assign(T *arg)
T * operator->() const
content-of filed operator (when the pointed to object is a struct or class
this is the base class of object that can be allocated on a memory pool
~smart_pointer()
destructor
const smart_pointer & operator=(const smart_pointer &ref)
assignment operator
libdar namespace encapsulate all libdar symbols