]> git.lyx.org Git - lyx.git/blob - sigc++/handle.h
Angus' preference patch
[lyx.git] / sigc++ / handle.h
1 #ifndef SIGCXX_HANDLE_H
2 #define SIGCXX_HANDLE_H
3 #include <sigc++/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
90 #define HANDLE_CTORS(X,T,P)                  \
91 public:                                       \
92   X(T *t):Handle<T,P>(t) {}                    \
93   X(T &t):Handle<T,P>(t) {}                     \
94   template <class T2,class P2>                   \
95     X(const Handle<T2,P2> &h):Handle<T,P>(h) {}   \
96   X& operator =(T *t)                              \
97     {return Handle<T,P>::operator=(t);}             \
98   X& operator =(T &t)                                \
99     {return Handle<T,P>::operator=(t);}               \
100   template <class T2,class P2>                         \
101   X& operator =(const Handle<T2,P2> &t)                 \
102     {return Handle<T,P>::operator=(t);}
103
104 //template <class T>
105 //  class Ref:public Handle<T,Scopes::RefCount>
106 //    {
107 //     HANDLE_CTORS(Ref,T,Scopes::RefCount)
108 //    };
109
110 #ifdef SIGC_CXX_NAMESPACES
111 } // namespace
112 #endif
113
114 #endif