#ifndef SIGCXX_HANDLE_H #define SIGCXX_HANDLE_H #include #ifdef SIGC_CXX_NAMESPACES namespace SigC { #endif // Signiture for Handles template class Handle { protected: Scope_ scope_; public: // access Obj* obj() { return static_cast(scope_.cache()); } Obj* obj() const { return static_cast(scope_.cache()); } bool connected() const {return (scope_.object()!=0);} operator Obj*() {return (obj());} operator Obj*() const {return (obj());} Obj& operator*() const {return *(obj());} Obj* operator->() const {return (obj());} Scope_& scope() {return scope_;} const Scope_& scope() const {return scope_;} void disconnect() {scope_.disconnect(0);} // copy Handle& operator =(Obj* obj) {scope_.set(obj,obj,true); return *this;} Handle& operator =(Obj& obj) {scope_.set(&obj,&obj,false); return *this;} #ifndef SIGC_CXX_TEMPLATE_CCTOR Handle& operator =(const Handle& handle) { Obj *o=handle.obj(); scope_.set(o,o,false); return *this; } #endif template Handle& operator = (const Handle& handle) { Obj *o=handle.obj(); scope_.set(o,o,false); return *this; } // construct Handle():scope_() {} Handle(Obj *obj):scope_() {scope_.set(obj,obj,true);} Handle(Obj &obj):scope_() {scope_.set(&obj,&obj,false);} #ifndef SIGC_CXX_TEMPLATE_CCTOR Handle(const Handle& handle) :scope_() { Obj *o=handle.obj(); scope_.set(o,o,false); } #endif template Handle(const Handle& handle) :scope_() { Obj *o=handle.obj(); scope_.set(o,o,false); } }; #define HANDLE_CTORS(X,T,P) \ public: \ X(T *t):Handle(t) {} \ X(T &t):Handle(t) {} \ template \ X(const Handle &h):Handle(h) {} \ X& operator =(T *t) \ {return Handle::operator=(t);} \ X& operator =(T &t) \ {return Handle::operator=(t);} \ template \ X& operator =(const Handle &t) \ {return Handle::operator=(t);} //template // class Ref:public Handle // { // HANDLE_CTORS(Ref,T,Scopes::RefCount) // }; #ifdef SIGC_CXX_NAMESPACES } // namespace #endif #endif