Subversion Repositories Kolibri OS

Rev

Go to most recent revision | Blame | Last modification | View Log | RSS feed

  1. #ifndef SIGCXX_HANDLE_H
  2. #define SIGCXX_HANDLE_H
  3. #include <sigc++config.h>
  4.  
  5. #ifdef SIGC_CXX_NAMESPACES
  6. namespace SigC
  7. {
  8. #endif
  9.  
  10. // Signiture for Handles
  11. template <class Obj,class Scope_>
  12.   class Handle
  13.   {
  14.    protected:
  15.      Scope_ scope_;
  16.    public:
  17.      // access
  18.      Obj* obj()
  19.        {
  20.         return static_cast<Obj*>(scope_.cache());
  21.        }
  22.      Obj* obj() const
  23.        {
  24.         return static_cast<Obj*>(scope_.cache());
  25.        }
  26.  
  27.      bool connected() const
  28.        {return  (scope_.object()!=0);}
  29.      operator Obj*()
  30.        {return  (obj());}
  31.      operator Obj*() const
  32.        {return  (obj());}
  33.  
  34.      Obj& operator*() const
  35.        {return *(obj());}
  36.      Obj* operator->() const
  37.        {return  (obj());}
  38.  
  39.      Scope_& scope()
  40.        {return scope_;}
  41.      const Scope_& scope() const
  42.        {return scope_;}
  43.  
  44.      void disconnect()
  45.        {scope_.disconnect(0);}
  46.  
  47.      // copy
  48.      Handle& operator =(Obj* obj)
  49.        {scope_.set(obj,obj,true); return *this;}
  50.      Handle& operator =(Obj& obj)
  51.        {scope_.set(&obj,&obj,false); return *this;}
  52. #ifndef SIGC_CXX_TEMPLATE_CCTOR
  53.      Handle& operator =(const Handle& handle)
  54.        {
  55.         Obj *o=handle.obj();
  56.         scope_.set(o,o,false);
  57.         return *this;
  58.        }
  59. #endif
  60.      template <class Obj2,class Scope2>
  61.        Handle& operator = (const Handle<Obj2,Scope2>& handle)
  62.        {
  63.         Obj *o=handle.obj();
  64.         scope_.set(o,o,false);
  65.         return *this;
  66.        }
  67.  
  68.      // construct
  69.      Handle():scope_()           {}
  70.      Handle(Obj *obj):scope_()   {scope_.set(obj,obj,true);}
  71.      Handle(Obj &obj):scope_()   {scope_.set(&obj,&obj,false);}
  72. #ifndef SIGC_CXX_TEMPLATE_CCTOR
  73.      Handle(const Handle& handle)
  74.        :scope_()
  75.        {
  76.         Obj *o=handle.obj();
  77.         scope_.set(o,o,false);
  78.        }
  79. #endif
  80.      template <class Obj2,class Scope2>
  81.      Handle(const Handle<Obj2,Scope2>& handle)
  82.        :scope_()
  83.        {
  84.         Obj *o=handle.obj();
  85.         scope_.set(o,o,false);
  86.        }
  87.   };
  88.  
  89. #define HANDLE_CTORS(X,T,P)                  \
  90. public:                                       \
  91.   X(T *t):Handle<T,P>(t) {}                    \
  92.   X(T &t):Handle<T,P>(t) {}                     \
  93.   template <class T2,class P2>                   \
  94.     X(const Handle<T2,P2> &h):Handle<T,P>(h) {}   \
  95.   X& operator =(T *t)                              \
  96.     {return Handle<T,P>::operator=(t);}             \
  97.   X& operator =(T &t)                                \
  98.     {return Handle<T,P>::operator=(t);}               \
  99.   template <class T2,class P2>                         \
  100.   X& operator =(const Handle<T2,P2> &t)                 \
  101.     {return Handle<T,P>::operator=(t);}
  102.  
  103. //template <class T>
  104. //  class Ref:public Handle<T,Scopes::RefCount>
  105. //    {
  106. //     HANDLE_CTORS(Ref,T,Scopes::RefCount)
  107. //    };
  108.  
  109. #ifdef SIGC_CXX_NAMESPACES
  110. } // namespace
  111. #endif
  112.  
  113. #endif
  114.