X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=ETL%2Ftrunk%2FETL%2F_handle.h;h=862c9146462a8565ca2649a4c600eddf1c6c9379;hb=9fc439081f4226774682129daa12d25f5ae3dfcb;hp=13af09b2fbc5786236ac915939d740c68f0f4a98;hpb=ed5137b5f3a34d83207e80d9c96087eddab14379;p=synfig.git diff --git a/ETL/trunk/ETL/_handle.h b/ETL/trunk/ETL/_handle.h index 13af09b..862c914 100644 --- a/ETL/trunk/ETL/_handle.h +++ b/ETL/trunk/ETL/_handle.h @@ -6,6 +6,7 @@ ** ** \legal ** Copyright (c) 2002 Robert B. Quattlebaum Jr. +** Copyright (c) 2007 Chris Moore ** ** This package is free software; you can redistribute it and/or ** modify it under the terms of the GNU General Public License as @@ -35,8 +36,9 @@ #define ETL_LOCK_REFCOUNTS #include + #ifdef ETL_LOCK_REFCOUNTS -#include +# include "_mutex_simple.h" #endif /* === M A C R O S ========================================================= */ @@ -73,7 +75,7 @@ class shared_object private: mutable int refcount; #ifdef ETL_LOCK_REFCOUNTS - mutable synfig::Mutex mutex; + mutable etl::mutex mtx; #endif protected: @@ -89,42 +91,41 @@ public: void ref()const { #ifdef ETL_LOCK_REFCOUNTS - synfig::Mutex::Lock lock(mutex); + etl::mutex::lock lock(mtx); #endif - assert(refcount>=0); refcount++; + assert(refcount>=0); + refcount++; } //! Returns \c false if object needs to be deleted bool unref()const { + bool ret = true; + { #ifdef ETL_LOCK_REFCOUNTS - synfig::Mutex::Lock lock(mutex); + etl::mutex::lock lock(mtx); #endif - assert(refcount>0); + assert(refcount>0); - refcount--; + refcount--; - if(refcount==0) { + if(refcount==0) { + ret = false; #ifdef ETL_SELF_DELETING_SHARED_OBJECT - refcount=-666; -#ifdef ETL_LOCK_REFCOUNTS - mutex.unlock(); -#endif - delete this; + refcount=-666; #endif - return false; + } } - return true; - } - - int count()const - { -#ifdef ETL_LOCK_REFCOUNTS - synfig::Mutex::Lock lock(mutex); +#ifdef ETL_SELF_DELETING_SHARED_OBJECT + if (!ret) + delete this; #endif - return refcount; + return ret; } + + int count()const { return refcount; } + }; // END of class shared_object // ======================================================================== @@ -165,6 +166,9 @@ public: typedef int size_type; protected: +#ifdef _DEBUG +public: +#endif value_type *obj; //!< Pointer to object public: @@ -289,41 +293,29 @@ public: operator handle()const { return handle(static_cast(obj)); } - //! static_cast\<\> wrapper - template static - handle cast_static(const handle &x) - { return handle(static_cast(x.get())); } - + template static handle cast_static (const handle &x) { return handle(static_cast (x.get())); } //! dynamic_cast\<\> wrapper - template static - handle cast_dynamic(const handle &x) - { return handle(dynamic_cast(x.get())); } - + template static handle cast_dynamic (const handle &x) { return handle(dynamic_cast (x.get())); } //! const_cast\<\> wrapper - template static - handle cast_const(const handle &x) - { return handle(const_cast(x.get())); } - + template static handle cast_const (const handle &x) { return handle(const_cast (x.get())); } //! reinterpret_cast\<\> wrapper - template static - handle cast_reinterpret(const handle &x) - { return handle(reinterpret_cast(x.get())); } + template static handle cast_reinterpret(const handle &x) { return handle(reinterpret_cast(x.get())); } - template static handle cast_static(const loose_handle &x); - template static handle cast_dynamic(const loose_handle &x); - template static handle cast_const(const loose_handle &x); - template static handle cast_reinterpret(const loose_handle &x); + template static handle cast_static (const loose_handle &x); + template static handle cast_dynamic (const loose_handle &x); + template static handle cast_const (const loose_handle &x); + template static handle cast_reinterpret(const loose_handle &x); - template static handle cast_static(const rhandle &x); - template static handle cast_dynamic(const rhandle &x); - template static handle cast_const(const rhandle &x); - template static handle cast_reinterpret(const rhandle &x); + template static handle cast_static (const rhandle &x); + template static handle cast_dynamic (const rhandle &x); + template static handle cast_const (const rhandle &x); + template static handle cast_reinterpret(const rhandle &x); - template static handle cast_static(U* x); - template static handle cast_dynamic(U* x); - template static handle cast_const(U* x); - template static handle cast_reinterpret(U* x); + template static handle cast_static (U* x); + template static handle cast_dynamic (U* x); + template static handle cast_const (U* x); + template static handle cast_reinterpret(U* x); //! Returns pointer to the object that is being wrapped pointer get()const { return obj; } @@ -395,8 +387,8 @@ public: using handle::unique; using handle::operator bool; using handle::get; - using handle::operator *; - using handle::operator ->; + using handle::operator*; + using handle::operator->; /* operator const handle&()const @@ -411,7 +403,7 @@ private: void add_to_rlist() { -// value_type*& obj(handle::obj); // Required to keep gcc 3.4.2 form barfing +// value_type*& obj(handle::obj); // Required to keep gcc 3.4.2 from barfing assert(obj); obj->rref(); @@ -432,7 +424,7 @@ private: void del_from_rlist() { -// value_type*& obj(handle::obj); // Required to keep gcc 3.4.2 form barfing +// value_type*& obj(handle::obj); // Required to keep gcc 3.4.2 from barfing assert(obj); obj->runref(); @@ -463,20 +455,20 @@ public: //! Constructor that constructs from a pointer to new object rhandle(pointer x):handle(x) { -// value_type*& obj(handle::obj); // Required to keep gcc 3.4.2 form barfing +// value_type*& obj(handle::obj); // Required to keep gcc 3.4.2 from barfing if(obj)add_to_rlist(); } rhandle(const handle &x):handle(x) { -// value_type*& obj(handle::obj); // Required to keep gcc 3.4.2 form barfing +// value_type*& obj(handle::obj); // Required to keep gcc 3.4.2 from barfing if(obj)add_to_rlist(); } //! Default copy constructor rhandle(const rhandle &x):handle(x) { -// value_type*& obj(handle::obj); // Required to keep gcc 3.4.2 form barfing +// value_type*& obj(handle::obj); // Required to keep gcc 3.4.2 from barfing if(obj)add_to_rlist(); } @@ -510,7 +502,7 @@ public: rhandle & operator=(const rhandle &x) { -// value_type*& obj(handle::obj); // Required to keep gcc 3.4.2 form barfing +// value_type*& obj(handle::obj); // Required to keep gcc 3.4.2 from barfing if(x.get()==obj) return *this; @@ -528,7 +520,7 @@ public: rhandle& operator=(const handle &x) { -// value_type*& obj(handle::obj); // Required to keep gcc 3.4.2 form barfing +// value_type*& obj(handle::obj); // Required to keep gcc 3.4.2 from barfing if(x.get()==obj) return *this; @@ -546,7 +538,7 @@ public: rhandle& operator=(value_type* x) { -// value_type*& obj(handle::obj); // Required to keep gcc 3.4.2 form barfing +// value_type*& obj(handle::obj); // Required to keep gcc 3.4.2 from barfing if(x==obj) return *this; @@ -566,7 +558,7 @@ public: void detach() { -// value_type*& obj(handle::obj); // Required to keep gcc 3.4.2 form barfing +// value_type*& obj(handle::obj); // Required to keep gcc 3.4.2 from barfing if(obj)del_from_rlist(); handle::detach(); obj=0; @@ -585,7 +577,7 @@ public: count_type rcount()const { -// value_type*const& obj(handle::obj); // Required to keep gcc 3.4.2 form barfing +// value_type*const& obj(handle::obj); // Required to keep gcc 3.4.2 from barfing return obj?obj->rcount():0; } @@ -593,14 +585,14 @@ public: bool runique()const { -// value_type*& obj(handle::obj); // Required to keep gcc 3.4.2 form barfing +// value_type*& obj(handle::obj); // Required to keep gcc 3.4.2 from barfing assert(obj); return obj->front_==obj->back_; } //! \writeme int replace(const handle &x) { -// value_type*& obj(handle::obj); // Required to keep gcc 3.4.2 form barfing +// value_type*& obj(handle::obj); // Required to keep gcc 3.4.2 from barfing assert(obj); assert(x.get()!=obj); @@ -648,11 +640,6 @@ public: }; // END of template class rhandle - - - - - // ======================================================================== /*! \class loose_handle _handle.h ETL/handle ** \brief Loose Object Handle @@ -673,6 +660,9 @@ public: typedef int size_type; protected: +#ifdef _DEBUG +public: +#endif value_type *obj; //!< Pointer to object public: @@ -788,141 +778,53 @@ public: bool unref() { if(obj && !obj->unref()){ obj=0; return false; } return true; } }; // END of template class loose_handle - - - -template template handle -handle::cast_static(const loose_handle &x) - { return handle(static_cast(x.get())); } - -template template handle -handle::cast_dynamic(const loose_handle &x) - { return handle(dynamic_cast(x.get())); } - -template template handle -handle::cast_const(const loose_handle &x) - { return handle(const_cast(x.get())); } - -template template handle -handle::cast_reinterpret(const loose_handle &x) - { return handle(reinterpret_cast(x.get())); } - - - -template template handle -handle::cast_static(const rhandle &x) - { return handle(static_cast(x.get())); } - -template template handle -handle::cast_dynamic(const rhandle &x) - { return handle(dynamic_cast(x.get())); } - -template template handle -handle::cast_const(const rhandle &x) - { return handle(const_cast(x.get())); } - -template template handle -handle::cast_reinterpret(const rhandle &x) - { return handle(reinterpret_cast(x.get())); } - - - -template template handle -handle::cast_static(U* x) - { return handle(static_cast(x)); } - -template template handle -handle::cast_dynamic(U* x) - { return handle(dynamic_cast(x)); } - -template template handle -handle::cast_const(U* x) - { return handle(const_cast(x)); } - -template template handle -handle::cast_reinterpret(U* x) - { return handle(reinterpret_cast(x)); } - - - - - -template bool -operator==(const handle &lhs,const handle &rhs) - { return (lhs.get()==rhs.get()); } -template bool -operator==(const loose_handle &lhs,const loose_handle &rhs) - { return (lhs.get()==rhs.get()); } -template bool -operator==(const handle &lhs,const loose_handle &rhs) - { return (lhs.get()==rhs.get()); } -template bool -operator==(const loose_handle &lhs,const handle &rhs) - { return (lhs.get()==rhs.get()); } -template bool -operator==(const handle &lhs,const T *rhs) - { return (lhs.get()==rhs); } -template bool -operator==(const loose_handle &lhs,const T *rhs) - { return (lhs.get()==rhs); } -template bool -operator==(const T *lhs,const handle &rhs) - { return (lhs==rhs.get()); } -template bool -operator==(const T *lhs,const loose_handle &rhs) - { return (lhs==rhs.get()); } - - -template bool -operator!=(const handle &lhs,const handle &rhs) - { return (lhs.get()!=rhs.get()); } -template bool -operator!=(const loose_handle &lhs,const loose_handle &rhs) - { return (lhs.get()!=rhs.get()); } -template bool -operator!=(const handle &lhs,const loose_handle &rhs) - { return (lhs.get()!=rhs.get()); } -template bool -operator!=(const loose_handle &lhs,const handle &rhs) - { return (lhs.get()!=rhs.get()); } -template bool -operator!=(const handle &lhs,const T *rhs) - { return (lhs.get()!=rhs); } -template bool -operator!=(const loose_handle &lhs,const T *rhs) - { return (lhs.get()!=rhs); } -template bool -operator!=(const T *lhs,const handle &rhs) - { return (lhs!=rhs.get()); } -template bool -operator!=(const T *lhs,const loose_handle &rhs) - { return (lhs!=rhs.get()); } - - -template bool -operator<(const handle &lhs,const handle &rhs) - { return (lhs.get() bool -operator<(const loose_handle &lhs,const loose_handle &rhs) - { return (lhs.get() bool -operator<(const handle &lhs,const loose_handle &rhs) - { return (lhs.get() bool -operator<(const loose_handle &lhs,const handle &rhs) - { return (lhs.get() bool -operator<(const handle &lhs,const T *rhs) - { return (lhs.get() bool -operator<(const loose_handle &lhs,const T *rhs) - { return (lhs.get() bool -operator<(const T *lhs,const handle &rhs) - { return (lhs bool -operator<(const T *lhs,const loose_handle &rhs) - { return (lhs -> handle<> +template template handle handle::cast_static (const loose_handle& x) { return handle(static_cast (x.get())); } +template template handle handle::cast_dynamic (const loose_handle& x) { return handle(dynamic_cast (x.get())); } +template template handle handle::cast_const (const loose_handle& x) { return handle(const_cast (x.get())); } +template template handle handle::cast_reinterpret(const loose_handle& x) { return handle(reinterpret_cast(x.get())); } + +// cast rhandle_handle<> -> handle<> +template template handle handle::cast_static (const rhandle& x) { return handle(static_cast (x.get())); } +template template handle handle::cast_dynamic (const rhandle& x) { return handle(dynamic_cast (x.get())); } +template template handle handle::cast_const (const rhandle& x) { return handle(const_cast (x.get())); } +template template handle handle::cast_reinterpret(const rhandle& x) { return handle(reinterpret_cast(x.get())); } + +// cast U* -> handle<> +template template handle handle::cast_static (U* x) { return handle(static_cast (x)); } +template template handle handle::cast_dynamic (U* x) { return handle(dynamic_cast (x)); } +template template handle handle::cast_const (U* x) { return handle(const_cast (x)); } +template template handle handle::cast_reinterpret(U* x) { return handle(reinterpret_cast(x)); } + +// operator== for handle<>, loose_handle<> and T* +template bool operator==(const handle & lhs,const handle & rhs) { return (lhs.get()==rhs.get()); } +template bool operator==(const loose_handle& lhs,const loose_handle& rhs) { return (lhs.get()==rhs.get()); } +template bool operator==(const handle & lhs,const loose_handle& rhs) { return (lhs.get()==rhs.get()); } +template bool operator==(const loose_handle& lhs,const handle & rhs) { return (lhs.get()==rhs.get()); } +template bool operator==(const handle& lhs,const T* rhs) { return (lhs.get()==rhs); } +template bool operator==(const loose_handle& lhs,const T* rhs) { return (lhs.get()==rhs); } +template bool operator==(const T* lhs,const handle& rhs) { return (lhs ==rhs.get()); } +template bool operator==(const T* lhs,const loose_handle& rhs) { return (lhs ==rhs.get()); } + +// operator!= for handle<>, loose_handle<> and T* +template bool operator!=(const handle & lhs,const handle & rhs) { return (lhs.get()!=rhs.get()); } +template bool operator!=(const loose_handle& lhs,const loose_handle& rhs) { return (lhs.get()!=rhs.get()); } +template bool operator!=(const handle & lhs,const loose_handle& rhs) { return (lhs.get()!=rhs.get()); } +template bool operator!=(const loose_handle& lhs,const handle & rhs) { return (lhs.get()!=rhs.get()); } +template bool operator!=(const handle& lhs,const T* rhs) { return (lhs.get()!=rhs); } +template bool operator!=(const loose_handle& lhs,const T* rhs) { return (lhs.get()!=rhs); } +template bool operator!=(const T* lhs,const handle& rhs) { return (lhs !=rhs.get()); } +template bool operator!=(const T* lhs,const loose_handle& rhs) { return (lhs !=rhs.get()); } + +// operator< for handle<>, loose_handle<> and T* +template bool operator<(const handle& lhs,const handle& rhs) { return (lhs.get() bool operator<(const loose_handle& lhs,const loose_handle& rhs) { return (lhs.get() bool operator<(const handle& lhs,const loose_handle& rhs) { return (lhs.get() bool operator<(const loose_handle& lhs,const handle& rhs) { return (lhs.get() bool operator<(const handle& lhs,const T* rhs) { return (lhs.get() bool operator<(const loose_handle& lhs,const T* rhs) { return (lhs.get() bool operator<(const T* lhs,const handle& rhs) { return (lhs bool operator<(const T* lhs,const loose_handle& rhs) { return (lhs