/* === H E A D E R S ======================================================= */
-// include the next line in an attempt to increase stability
-#define ETL_LOCK_REFCOUNTS
-
#include <cassert>
-#ifdef ETL_LOCK_REFCOUNTS
-#include <glibmm/thread.h>
-#endif
/* === M A C R O S ========================================================= */
{
private:
mutable int refcount;
-#ifdef ETL_LOCK_REFCOUNTS
- mutable Glib::Mutex mutex;
-#endif
protected:
shared_object():refcount(0) { }
public:
void ref()const
- {
-#ifdef ETL_LOCK_REFCOUNTS
- Glib::Mutex::Lock lock(mutex);
-#endif
- assert(refcount>=0); refcount++;
- }
+ { assert(refcount>=0); refcount++; }
//! Returns \c false if object needs to be deleted
bool unref()const
{
-#ifdef ETL_LOCK_REFCOUNTS
- Glib::Mutex::Lock lock(mutex);
-#endif
assert(refcount>0);
refcount--;
if(refcount==0) {
#ifdef ETL_SELF_DELETING_SHARED_OBJECT
refcount=-666;
-#ifdef ETL_LOCK_REFCOUNTS
- lock.release();
-#endif
delete this;
#endif
return false;
}
int count()const
- {
-#ifdef ETL_LOCK_REFCOUNTS
- Glib::Mutex::Lock lock(mutex);
-#endif
- return refcount;
- }
+ { return refcount; }
}; // END of class shared_object
// ========================================================================
typedef int size_type;
protected:
+#ifdef _DEBUG
+public:
+#endif
value_type *obj; //!< Pointer to object
public:
operator handle<const value_type>()const
{ return handle<const value_type>(static_cast<const_pointer>(obj)); }
-
//! <tt> static_cast\<\> </tt> wrapper
- template <class U> static
- handle<T> cast_static(const handle<U> &x)
- { return handle<T>(static_cast<T*>(x.get())); }
-
+ template <class U> static handle<T> cast_static (const handle<U> &x) { return handle<T>(static_cast <T*>(x.get())); }
//! <tt> dynamic_cast\<\> </tt> wrapper
- template <class U> static
- handle<T> cast_dynamic(const handle<U> &x)
- { return handle<T>(dynamic_cast<T*>(x.get())); }
-
+ template <class U> static handle<T> cast_dynamic (const handle<U> &x) { return handle<T>(dynamic_cast <T*>(x.get())); }
//! <tt> const_cast\<\> </tt> wrapper
- template <class U> static
- handle<T> cast_const(const handle<U> &x)
- { return handle<T>(const_cast<T*>(x.get())); }
-
+ template <class U> static handle<T> cast_const (const handle<U> &x) { return handle<T>(const_cast <T*>(x.get())); }
//! <tt> reinterpret_cast\<\> </tt> wrapper
- template <class U> static
- handle<T> cast_reinterpret(const handle<U> &x)
- { return handle<T>(reinterpret_cast<T*>(x.get())); }
+ template <class U> static handle<T> cast_reinterpret(const handle<U> &x) { return handle<T>(reinterpret_cast<T*>(x.get())); }
- template<class U> static handle<T> cast_static(const loose_handle<U> &x);
- template<class U> static handle<T> cast_dynamic(const loose_handle<U> &x);
- template<class U> static handle<T> cast_const(const loose_handle<U> &x);
- template<class U> static handle<T> cast_reinterpret(const loose_handle<U> &x);
+ template <class U> static handle<T> cast_static (const loose_handle<U> &x);
+ template <class U> static handle<T> cast_dynamic (const loose_handle<U> &x);
+ template <class U> static handle<T> cast_const (const loose_handle<U> &x);
+ template <class U> static handle<T> cast_reinterpret(const loose_handle<U> &x);
- template<class U> static handle<T> cast_static(const rhandle<U> &x);
- template<class U> static handle<T> cast_dynamic(const rhandle<U> &x);
- template<class U> static handle<T> cast_const(const rhandle<U> &x);
- template<class U> static handle<T> cast_reinterpret(const rhandle<U> &x);
+ template <class U> static handle<T> cast_static (const rhandle<U> &x);
+ template <class U> static handle<T> cast_dynamic (const rhandle<U> &x);
+ template <class U> static handle<T> cast_const (const rhandle<U> &x);
+ template <class U> static handle<T> cast_reinterpret(const rhandle<U> &x);
- template<class U> static handle<T> cast_static(U* x);
- template<class U> static handle<T> cast_dynamic(U* x);
- template<class U> static handle<T> cast_const(U* x);
- template<class U> static handle<T> cast_reinterpret(U* x);
+ template <class U> static handle<T> cast_static (U* x);
+ template <class U> static handle<T> cast_dynamic (U* x);
+ template <class U> static handle<T> cast_const (U* x);
+ template <class U> static handle<T> cast_reinterpret(U* x);
//! Returns pointer to the object that is being wrapped
pointer get()const { return obj; }
void add_to_rlist()
{
-// value_type*& obj(handle<T>::obj); // Required to keep gcc 3.4.2 form barfing
+// value_type*& obj(handle<T>::obj); // Required to keep gcc 3.4.2 from barfing
assert(obj);
obj->rref();
void del_from_rlist()
{
-// value_type*& obj(handle<T>::obj); // Required to keep gcc 3.4.2 form barfing
+// value_type*& obj(handle<T>::obj); // Required to keep gcc 3.4.2 from barfing
assert(obj);
obj->runref();
//! Constructor that constructs from a pointer to new object
rhandle(pointer x):handle<T>(x)
{
-// value_type*& obj(handle<T>::obj); // Required to keep gcc 3.4.2 form barfing
+// value_type*& obj(handle<T>::obj); // Required to keep gcc 3.4.2 from barfing
if(obj)add_to_rlist();
}
rhandle(const handle<value_type> &x):handle<T>(x)
{
-// value_type*& obj(handle<T>::obj); // Required to keep gcc 3.4.2 form barfing
+// value_type*& obj(handle<T>::obj); // Required to keep gcc 3.4.2 from barfing
if(obj)add_to_rlist();
}
//! Default copy constructor
rhandle(const rhandle<value_type> &x):handle<T>(x)
{
-// value_type*& obj(handle<T>::obj); // Required to keep gcc 3.4.2 form barfing
+// value_type*& obj(handle<T>::obj); // Required to keep gcc 3.4.2 from barfing
if(obj)add_to_rlist();
}
rhandle<value_type> &
operator=(const rhandle<value_type> &x)
{
-// value_type*& obj(handle<T>::obj); // Required to keep gcc 3.4.2 form barfing
+// value_type*& obj(handle<T>::obj); // Required to keep gcc 3.4.2 from barfing
if(x.get()==obj)
return *this;
rhandle<value_type>&
operator=(const handle<value_type> &x)
{
-// value_type*& obj(handle<T>::obj); // Required to keep gcc 3.4.2 form barfing
+// value_type*& obj(handle<T>::obj); // Required to keep gcc 3.4.2 from barfing
if(x.get()==obj)
return *this;
rhandle<value_type>&
operator=(value_type* x)
{
-// value_type*& obj(handle<T>::obj); // Required to keep gcc 3.4.2 form barfing
+// value_type*& obj(handle<T>::obj); // Required to keep gcc 3.4.2 from barfing
if(x==obj)
return *this;
void
detach()
{
-// value_type*& obj(handle<T>::obj); // Required to keep gcc 3.4.2 form barfing
+// value_type*& obj(handle<T>::obj); // Required to keep gcc 3.4.2 from barfing
if(obj)del_from_rlist();
handle<value_type>::detach();
obj=0;
count_type
rcount()const
{
-// value_type*const& obj(handle<T>::obj); // Required to keep gcc 3.4.2 form barfing
+// value_type*const& obj(handle<T>::obj); // Required to keep gcc 3.4.2 from barfing
return obj?obj->rcount():0;
}
bool
runique()const
{
-// value_type*& obj(handle<T>::obj); // Required to keep gcc 3.4.2 form barfing
+// value_type*& obj(handle<T>::obj); // Required to keep gcc 3.4.2 from barfing
assert(obj); return obj->front_==obj->back_;
}
//! \writeme
int replace(const handle<value_type> &x)
{
-// value_type*& obj(handle<T>::obj); // Required to keep gcc 3.4.2 form barfing
+// value_type*& obj(handle<T>::obj); // Required to keep gcc 3.4.2 from barfing
assert(obj);
assert(x.get()!=obj);
}; // END of template class rhandle
-
-
-
-
-
// ========================================================================
/*! \class loose_handle _handle.h ETL/handle
** \brief Loose Object Handle
typedef int size_type;
protected:
+#ifdef _DEBUG
+public:
+#endif
value_type *obj; //!< Pointer to object
public:
bool unref() { if(obj && !obj->unref()){ obj=0; return false; } return true; }
}; // END of template class loose_handle
-
-
-
-template<class T> template<class U> handle<T>
-handle<T>::cast_static(const loose_handle<U> &x)
- { return handle<T>(static_cast<T*>(x.get())); }
-
-template <class T> template <class U> handle<T>
-handle<T>::cast_dynamic(const loose_handle<U> &x)
- { return handle<T>(dynamic_cast<T*>(x.get())); }
-
-template <class T> template <class U> handle<T>
-handle<T>::cast_const(const loose_handle<U> &x)
- { return handle<T>(const_cast<T*>(x.get())); }
-
-template <class T> template <class U> handle<T>
-handle<T>::cast_reinterpret(const loose_handle<U> &x)
- { return handle<T>(reinterpret_cast<T*>(x.get())); }
-
-
-
-template <class T> template <class U> handle<T>
-handle<T>::cast_static(const rhandle<U> &x)
- { return handle<T>(static_cast<T*>(x.get())); }
-
-template <class T> template <class U> handle<T>
-handle<T>::cast_dynamic(const rhandle<U> &x)
- { return handle<T>(dynamic_cast<T*>(x.get())); }
-
-template <class T> template <class U> handle<T>
-handle<T>::cast_const(const rhandle<U> &x)
- { return handle<T>(const_cast<T*>(x.get())); }
-
-template <class T> template <class U> handle<T>
-handle<T>::cast_reinterpret(const rhandle<U> &x)
- { return handle<T>(reinterpret_cast<T*>(x.get())); }
-
-
-
-template <class T> template <class U> handle<T>
-handle<T>::cast_static(U* x)
- { return handle<T>(static_cast<T*>(x)); }
-
-template <class T> template <class U> handle<T>
-handle<T>::cast_dynamic(U* x)
- { return handle<T>(dynamic_cast<T*>(x)); }
-
-template <class T> template <class U> handle<T>
-handle<T>::cast_const(U* x)
- { return handle<T>(const_cast<T*>(x)); }
-
-template <class T> template <class U> handle<T>
-handle<T>::cast_reinterpret(U* x)
- { return handle<T>(reinterpret_cast<T*>(x)); }
-
-
-
-
-
-template <class T,class U> bool
-operator==(const handle<T> &lhs,const handle<U> &rhs)
- { return (lhs.get()==rhs.get()); }
-template <class T,class U> bool
-operator==(const loose_handle<T> &lhs,const loose_handle<U> &rhs)
- { return (lhs.get()==rhs.get()); }
-template <class T,class U> bool
-operator==(const handle<T> &lhs,const loose_handle<U> &rhs)
- { return (lhs.get()==rhs.get()); }
-template <class T,class U> bool
-operator==(const loose_handle<T> &lhs,const handle<U> &rhs)
- { return (lhs.get()==rhs.get()); }
-template <class T> bool
-operator==(const handle<T> &lhs,const T *rhs)
- { return (lhs.get()==rhs); }
-template <class T> bool
-operator==(const loose_handle<T> &lhs,const T *rhs)
- { return (lhs.get()==rhs); }
-template <class T> bool
-operator==(const T *lhs,const handle<T> &rhs)
- { return (lhs==rhs.get()); }
-template <class T> bool
-operator==(const T *lhs,const loose_handle<T> &rhs)
- { return (lhs==rhs.get()); }
-
-
-template <class T,class U> bool
-operator!=(const handle<T> &lhs,const handle<U> &rhs)
- { return (lhs.get()!=rhs.get()); }
-template <class T,class U> bool
-operator!=(const loose_handle<T> &lhs,const loose_handle<U> &rhs)
- { return (lhs.get()!=rhs.get()); }
-template <class T,class U> bool
-operator!=(const handle<T> &lhs,const loose_handle<U> &rhs)
- { return (lhs.get()!=rhs.get()); }
-template <class T,class U> bool
-operator!=(const loose_handle<T> &lhs,const handle<U> &rhs)
- { return (lhs.get()!=rhs.get()); }
-template <class T> bool
-operator!=(const handle<T> &lhs,const T *rhs)
- { return (lhs.get()!=rhs); }
-template <class T> bool
-operator!=(const loose_handle<T> &lhs,const T *rhs)
- { return (lhs.get()!=rhs); }
-template <class T> bool
-operator!=(const T *lhs,const handle<T> &rhs)
- { return (lhs!=rhs.get()); }
-template <class T> bool
-operator!=(const T *lhs,const loose_handle<T> &rhs)
- { return (lhs!=rhs.get()); }
-
-
-template <class T,class U> bool
-operator<(const handle<T> &lhs,const handle<U> &rhs)
- { return (lhs.get()<rhs.get()); }
-template <class T,class U> bool
-operator<(const loose_handle<T> &lhs,const loose_handle<U> &rhs)
- { return (lhs.get()<rhs.get()); }
-template <class T,class U> bool
-operator<(const handle<T> &lhs,const loose_handle<U> &rhs)
- { return (lhs.get()<rhs.get()); }
-template <class T,class U> bool
-operator<(const loose_handle<T> &lhs,const handle<U> &rhs)
- { return (lhs.get()<rhs.get()); }
-template <class T> bool
-operator<(const handle<T> &lhs,const T *rhs)
- { return (lhs.get()<rhs); }
-template <class T> bool
-operator<(const loose_handle<T> &lhs,const T *rhs)
- { return (lhs.get()<rhs); }
-template <class T> bool
-operator<(const T *lhs,const handle<T> &rhs)
- { return (lhs<rhs.get()); }
-template <class T> bool
-operator<(const T *lhs,const loose_handle<T> &rhs)
- { return (lhs<rhs.get()); }
+// cast loose_handle<> -> handle<>
+template <class T> template <class U> handle<T> handle<T>::cast_static (const loose_handle<U>& x) { return handle<T>(static_cast <T*>(x.get())); }
+template <class T> template <class U> handle<T> handle<T>::cast_dynamic (const loose_handle<U>& x) { return handle<T>(dynamic_cast <T*>(x.get())); }
+template <class T> template <class U> handle<T> handle<T>::cast_const (const loose_handle<U>& x) { return handle<T>(const_cast <T*>(x.get())); }
+template <class T> template <class U> handle<T> handle<T>::cast_reinterpret(const loose_handle<U>& x) { return handle<T>(reinterpret_cast<T*>(x.get())); }
+
+// cast rhandle_handle<> -> handle<>
+template <class T> template <class U> handle<T> handle<T>::cast_static (const rhandle<U>& x) { return handle<T>(static_cast <T*>(x.get())); }
+template <class T> template <class U> handle<T> handle<T>::cast_dynamic (const rhandle<U>& x) { return handle<T>(dynamic_cast <T*>(x.get())); }
+template <class T> template <class U> handle<T> handle<T>::cast_const (const rhandle<U>& x) { return handle<T>(const_cast <T*>(x.get())); }
+template <class T> template <class U> handle<T> handle<T>::cast_reinterpret(const rhandle<U>& x) { return handle<T>(reinterpret_cast<T*>(x.get())); }
+
+// cast U* -> handle<>
+template <class T> template <class U> handle<T> handle<T>::cast_static (U* x) { return handle<T>(static_cast <T*>(x)); }
+template <class T> template <class U> handle<T> handle<T>::cast_dynamic (U* x) { return handle<T>(dynamic_cast <T*>(x)); }
+template <class T> template <class U> handle<T> handle<T>::cast_const (U* x) { return handle<T>(const_cast <T*>(x)); }
+template <class T> template <class U> handle<T> handle<T>::cast_reinterpret(U* x) { return handle<T>(reinterpret_cast<T*>(x)); }
+
+// operator== for handle<>, loose_handle<> and T*
+template <class T,class U> bool operator==(const handle <T>& lhs,const handle <U>& rhs) { return (lhs.get()==rhs.get()); }
+template <class T,class U> bool operator==(const loose_handle<T>& lhs,const loose_handle<U>& rhs) { return (lhs.get()==rhs.get()); }
+template <class T,class U> bool operator==(const handle <T>& lhs,const loose_handle<U>& rhs) { return (lhs.get()==rhs.get()); }
+template <class T,class U> bool operator==(const loose_handle<T>& lhs,const handle <U>& rhs) { return (lhs.get()==rhs.get()); }
+template <class T> bool operator==(const handle<T>& lhs,const T* rhs) { return (lhs.get()==rhs); }
+template <class T> bool operator==(const loose_handle<T>& lhs,const T* rhs) { return (lhs.get()==rhs); }
+template <class T> bool operator==(const T* lhs,const handle<T>& rhs) { return (lhs ==rhs.get()); }
+template <class T> bool operator==(const T* lhs,const loose_handle<T>& rhs) { return (lhs ==rhs.get()); }
+
+// operator!= for handle<>, loose_handle<> and T*
+template <class T,class U> bool operator!=(const handle <T>& lhs,const handle <U>& rhs) { return (lhs.get()!=rhs.get()); }
+template <class T,class U> bool operator!=(const loose_handle<T>& lhs,const loose_handle<U>& rhs) { return (lhs.get()!=rhs.get()); }
+template <class T,class U> bool operator!=(const handle <T>& lhs,const loose_handle<U>& rhs) { return (lhs.get()!=rhs.get()); }
+template <class T,class U> bool operator!=(const loose_handle<T>& lhs,const handle <U>& rhs) { return (lhs.get()!=rhs.get()); }
+template <class T> bool operator!=(const handle<T>& lhs,const T* rhs) { return (lhs.get()!=rhs); }
+template <class T> bool operator!=(const loose_handle<T>& lhs,const T* rhs) { return (lhs.get()!=rhs); }
+template <class T> bool operator!=(const T* lhs,const handle<T>& rhs) { return (lhs !=rhs.get()); }
+template <class T> bool operator!=(const T* lhs,const loose_handle<T>& rhs) { return (lhs !=rhs.get()); }
+
+// operator< for handle<>, loose_handle<> and T*
+template <class T,class U> bool operator<(const handle<T>& lhs,const handle<U>& rhs) { return (lhs.get()<rhs.get()); }
+template <class T,class U> bool operator<(const loose_handle<T>& lhs,const loose_handle<U>& rhs) { return (lhs.get()<rhs.get()); }
+template <class T,class U> bool operator<(const handle<T>& lhs,const loose_handle<U>& rhs) { return (lhs.get()<rhs.get()); }
+template <class T,class U> bool operator<(const loose_handle<T>& lhs,const handle<U>& rhs) { return (lhs.get()<rhs.get()); }
+template <class T> bool operator<(const handle<T>& lhs,const T* rhs) { return (lhs.get()<rhs); }
+template <class T> bool operator<(const loose_handle<T>& lhs,const T* rhs) { return (lhs.get()<rhs); }
+template <class T> bool operator<(const T* lhs,const handle<T>& rhs) { return (lhs <rhs.get()); }
+template <class T> bool operator<(const T* lhs,const loose_handle<T>& rhs) { return (lhs <rhs.get()); }
_ETL_END_NAMESPACE