Subversion Repositories Kolibri OS

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
4973 right-hear 1
#ifndef SIGCXX_HANDLE_H
2
#define SIGCXX_HANDLE_H
3
#include 
4
 
5
#ifdef SIGC_CXX_NAMESPACES
6
namespace SigC
7
{
8
#endif
9
 
10
// Signiture for Handles
11
template 
12
  class Handle
13
  {
14
   protected:
15
     Scope_ scope_;
16
   public:
17
     // access
18
     Obj* obj()
19
       {
20
        return static_cast(scope_.cache());
21
       }
22
     Obj* obj() const
23
       {
24
        return static_cast(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 
61
       Handle& operator = (const Handle& 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 
81
     Handle(const Handle& 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) {}                    \
92
  X(T &t):Handle(t) {}                     \
93
  template                    \
94
    X(const Handle &h):Handle(h) {}   \
95
  X& operator =(T *t)                              \
96
    {return Handle::operator=(t);}             \
97
  X& operator =(T &t)                                \
98
    {return Handle::operator=(t);}               \
99
  template                          \
100
  X& operator =(const Handle &t)                 \
101
    {return Handle::operator=(t);}
102
 
103
//template 
104
//  class Ref:public Handle
105
//    {
106
//     HANDLE_CTORS(Ref,T,Scopes::RefCount)
107
//    };
108
 
109
#ifdef SIGC_CXX_NAMESPACES
110
} // namespace
111
#endif
112
 
113
#endif