Go to the documentation of this file.
   39 #ifndef CGU_SHARED_PTR_H 
   40 #define CGU_SHARED_PTR_H 
   53 #ifdef CGU_SHARED_LOCK_PTR_USE_MUTEX 
  115   virtual const char* 
what() 
const throw() {
return "SharedPtrError\n";}
 
  128 namespace SharedPtrAllocFail {
 
  168 #ifndef DOXYGEN_PARSING 
  170     unsigned int* ref_count_p;
 
  176     if (!ref_items.ref_count_p) 
return;
 
  177     --(*ref_items.ref_count_p);
 
  178     if (*ref_items.ref_count_p == 0) {
 
  179 #ifdef CGU_USE_GLIB_MEMORY_SLICES_NO_COMPAT 
  180       g_slice_free(
unsigned int, ref_items.ref_count_p);
 
  182       delete ref_items.ref_count_p;
 
  184       delete ref_items.obj_p;
 
  189     if (!ref_items.ref_count_p) 
return;
 
  190     ++(*ref_items.ref_count_p);
 
  213     if ((ref_items.obj_p = ptr)) { 
 
  214 #ifdef CGU_USE_GLIB_MEMORY_SLICES_NO_COMPAT 
  215       ref_items.ref_count_p = g_slice_new(
unsigned int);
 
  216       *ref_items.ref_count_p = 1;
 
  219     ref_items.ref_count_p = 
new unsigned int(1);
 
  229     else ref_items.ref_count_p = 0;
 
  263     if ((ref_items.obj_p = ptr)) { 
 
  264 #ifdef CGU_USE_GLIB_MEMORY_SLICES_NO_COMPAT 
  265       ref_items.ref_count_p = g_slice_new(
unsigned int);
 
  266       *ref_items.ref_count_p = 1;
 
  269     ref_items.ref_count_p = 
new unsigned int(1);
 
  271       catch (std::bad_alloc&) { 
 
  276     else ref_items.ref_count_p = 0;
 
  355     ref_items = sh_ptr.ref_items;
 
  372     ref_items.ref_count_p = sh_ptr.ref_items.ref_count_p;
 
  373     ref_items.obj_p = sh_ptr.ref_items.obj_p;
 
  409   T* 
get()
 const {
return ref_items.obj_p;}
 
  429   unsigned int get_refcount()
 const {
return (ref_items.ref_count_p) ? *ref_items.ref_count_p : 0;}
 
  515 #ifndef DOXYGEN_PARSING 
  517 #ifdef CGU_SHARED_LOCK_PTR_USE_MUTEX 
  519     unsigned int* ref_count_p;
 
  535     if (!ref_items.ref_count_p) 
return;
 
  536 #ifdef CGU_SHARED_LOCK_PTR_USE_MUTEX 
  537     ref_items.mutex_p->
lock();
 
  538     --(*ref_items.ref_count_p);
 
  539     if (*ref_items.ref_count_p == 0) {
 
  540 # ifdef CGU_USE_GLIB_MEMORY_SLICES_NO_COMPAT 
  541       g_slice_free(
unsigned int, ref_items.ref_count_p);
 
  543       delete ref_items.ref_count_p;
 
  545       ref_items.mutex_p->unlock();
 
  546       delete ref_items.mutex_p;
 
  547       delete ref_items.obj_p;
 
  549     else ref_items.mutex_p->unlock();
 
  551     if (g_atomic_int_dec_and_test(ref_items.ref_count_p)) {
 
  552 # ifdef CGU_USE_GLIB_MEMORY_SLICES_NO_COMPAT 
  553       g_slice_free(gint, ref_items.ref_count_p);
 
  555       delete ref_items.ref_count_p;
 
  557       delete ref_items.obj_p;
 
  569     if (!ref_items.ref_count_p) 
return;
 
  570 #ifdef CGU_SHARED_LOCK_PTR_USE_MUTEX 
  572     ++(*ref_items.ref_count_p);
 
  574     g_atomic_int_inc(ref_items.ref_count_p);
 
  607     if ((ref_items.obj_p = ptr)) { 
 
  608 #ifdef CGU_SHARED_LOCK_PTR_USE_MUTEX 
  618 # ifdef CGU_USE_GLIB_MEMORY_SLICES_NO_COMPAT 
  619       ref_items.ref_count_p = g_slice_new(
unsigned int);
 
  620       *ref_items.ref_count_p = 1;
 
  623     ref_items.ref_count_p = 
new unsigned int(1);
 
  626     delete ref_items.mutex_p;
 
  632 # ifdef CGU_USE_GLIB_MEMORY_SLICES_NO_COMPAT 
  633       ref_items.ref_count_p = g_slice_new(gint);
 
  634       *ref_items.ref_count_p = 1;
 
  637     ref_items.ref_count_p = 
new gint(1);
 
  649 #ifdef CGU_SHARED_LOCK_PTR_USE_MUTEX 
  650       ref_items.mutex_p = 0;  
 
  652       ref_items.ref_count_p = 0;
 
  697     if ((ref_items.obj_p = ptr)) { 
 
  698 #ifdef CGU_SHARED_LOCK_PTR_USE_MUTEX 
  702       catch (std::bad_alloc&) { 
 
  708 # ifdef CGU_USE_GLIB_MEMORY_SLICES_NO_COMPAT 
  709       ref_items.ref_count_p = g_slice_new(
unsigned int);
 
  710       *ref_items.ref_count_p = 1;
 
  713     ref_items.ref_count_p = 
new unsigned int(1);
 
  715       catch (std::bad_alloc&) {
 
  716     delete ref_items.mutex_p;
 
  721 # ifdef CGU_USE_GLIB_MEMORY_SLICES_NO_COMPAT 
  722       ref_items.ref_count_p = g_slice_new(gint);
 
  723       *ref_items.ref_count_p = 1;
 
  726     ref_items.ref_count_p = 
new gint(1);
 
  728       catch (std::bad_alloc&) { 
 
  735 #ifdef CGU_SHARED_LOCK_PTR_USE_MUTEX 
  736       ref_items.mutex_p = 0;  
 
  738       ref_items.ref_count_p = 0;
 
  851     ref_items = sh_ptr.ref_items;
 
  868 #ifdef CGU_SHARED_LOCK_PTR_USE_MUTEX 
  869     ref_items.mutex_p = sh_ptr.ref_items.mutex_p;
 
  871     ref_items.obj_p = sh_ptr.ref_items.obj_p;
 
  872     ref_items.ref_count_p = sh_ptr.ref_items.ref_count_p;
 
  908   T* 
get()
 const {
return ref_items.obj_p;}
 
  933     if (!ref_items.ref_count_p) 
return 0;
 
  934 #ifdef CGU_SHARED_LOCK_PTR_USE_MUTEX 
  936     return *ref_items.ref_count_p;
 
  938     return g_atomic_int_get(ref_items.ref_count_p);
 
  949 #if defined(CGU_USE_SMART_PTR_COMPARISON) || defined(DOXYGEN_PARSING) 
  966   return (s1.
get() == s2.
get());
 
 1005   return std::less<T*>()(s1.
get(), s2.
get());
 
 1021   return (s1.
get() == s2.
get());
 
 1055   return std::less<T*>()(s1.
get(), s2.
get());
 
 1058 #endif // CGU_USE_SMART_PTR_COMPARISON 
  
This is an exception struct thrown as an alternative to deleting a managed object when internal memor...
Definition: shared_ptr.h:113
SharedLockPtr & operator=(SharedLockPtr sh_ptr)
Definition: shared_ptr.h:885
SharedPtr & operator=(const SharedPtr< U > &sh_ptr)
Definition: shared_ptr.h:400
Definition: application.h:45
SharedLockPtr(T *ptr, Cgu::SharedPtrAllocFail::Leave tag)
Definition: shared_ptr.h:695
SharedLockPtr(const SharedLockPtr &sh_ptr)
Definition: shared_ptr.h:850
T * get() const
Definition: shared_ptr.h:908
void reset(T *ptr, Cgu::SharedPtrAllocFail::Leave tag)
Definition: shared_ptr.h:841
T * operator->() const
Definition: shared_ptr.h:921
void reset(T *ptr, Cgu::SharedPtrAllocFail::Leave tag)
Definition: shared_ptr.h:345
@ leave
Definition: shared_ptr.h:129
void reset(T *ptr=0)
Definition: shared_ptr.h:783
bool operator!=(const GobjHandle< T > &h1, const GobjHandle< T > &h2)
Definition: gobj_handle.h:618
unsigned int get_refcount() const
Definition: shared_ptr.h:429
SharedPtr(const SharedPtr &sh_ptr)
Definition: shared_ptr.h:354
T * obj
Definition: shared_ptr.h:114
SharedLockPtr & operator=(const SharedLockPtr< U > &sh_ptr)
Definition: shared_ptr.h:899
bool operator<(const GobjHandle< T > &h1, const GobjHandle< T > &h2)
Definition: gobj_handle.h:641
void swap(Cgu::AsyncQueue< T, Container > &q1, Cgu::AsyncQueue< T, Container > &q2)
Definition: async_queue.h:784
~SharedLockPtr()
Definition: shared_ptr.h:946
SharedPtr & operator=(SharedPtr sh_ptr)
Definition: shared_ptr.h:386
This is a smart pointer for managing the lifetime of objects allocated on freestore.
Definition: shared_ptr.h:166
Leave
Definition: shared_ptr.h:129
T * get() const
Definition: shared_ptr.h:409
void reset(T *ptr=0)
Definition: shared_ptr.h:305
SharedPtr(T *ptr=0)
Definition: shared_ptr.h:211
~SharedPtr()
Definition: shared_ptr.h:435
virtual const char * what() const
Definition: shared_ptr.h:115
int lock()
Definition: mutex.h:132
A scoped locking class for exception safe Mutex locking.
Definition: mutex.h:192
friend class SharedLockPtr
Definition: shared_ptr.h:855
SharedLockPtr(T *ptr=0)
Definition: shared_ptr.h:605
T & operator*() const
Definition: shared_ptr.h:415
SharedPtr(T *ptr, Cgu::SharedPtrAllocFail::Leave tag)
Definition: shared_ptr.h:261
Provides wrapper classes for pthread mutexes and condition variables, and scoped locking classes for ...
This is a smart pointer for managing the lifetime of objects allocated on freestore,...
Definition: shared_ptr.h:513
SharedPtr(const SharedPtr< U > &sh_ptr)
Definition: shared_ptr.h:368
bool operator==(const GobjHandle< T > &h1, const GobjHandle< T > &h2)
Definition: gobj_handle.h:602
T & operator*() const
Definition: shared_ptr.h:914
friend class SharedPtr
Definition: shared_ptr.h:359
T * operator->() const
Definition: shared_ptr.h:422
A wrapper class for pthread mutexes.
Definition: mutex.h:109
SharedLockPtr(const SharedLockPtr< U > &sh_ptr)
Definition: shared_ptr.h:864
unsigned int get_refcount() const
Definition: shared_ptr.h:932
SharedPtrError(T *p)
Definition: shared_ptr.h:116