|
Rapicorn - Experimental UI Toolkit - Source Code 10.08.1
|
00001 /* RapicornSignal 00002 * Copyright (C) 2005 Tim Janik 00003 * 00004 * This library is free software; you can redistribute it and/or 00005 * modify it under the terms of the GNU Lesser General Public 00006 * License as published by the Free Software Foundation; either 00007 * version 2.1 of the License, or (at your option) any later version. 00008 * 00009 * This library is distributed in the hope that it will be useful, 00010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00012 * Lesser General Public License for more details. 00013 * 00014 * A copy of the GNU Lesser General Public License should ship along 00015 * with this library; if not, see http://www.gnu.org/copyleft/. 00016 */ 00017 00018 /* this file is used to generate rapicornsignalvariants.hh by mksignals.sh. 00019 * therein, certain phrases like "typename A1, typename A2, typename A3" are 00020 * rewritten into 0, 1, 2, ... 16 argument variants. so make sure all phrases 00021 * involving the signal argument count match those from mksignals.sh. 00022 */ 00023 00024 /* --- Trampoline (basis signature) --- */ 00025 template<typename R0, typename A1, typename A2, typename A3> 00026 struct Trampoline3 : public TrampolineLink { 00027 /* signature type for all signal trampolines, used for trampoline invocations by Emission */ 00028 virtual R0 operator() (A1 a1, A2 a2, A3 a3) = 0; 00029 }; 00030 00031 /* --- Trampoline (plain) --- */ 00032 template<typename R0, typename A1, typename A2, typename A3> 00033 class FunctionTrampoline3 : public Trampoline3 <R0, A1, A2, A3> { 00034 typedef R0 (*Callback) (A1, A2, A3); 00035 Callback callback; 00036 virtual R0 operator() (A1 a1, A2 a2, A3 a3) 00037 { return callback (a1, a2, a3); } 00038 virtual ~FunctionTrampoline3() {} 00039 virtual bool operator== (const TrampolineLink &bother) const { 00040 const FunctionTrampoline3 *other = dynamic_cast<const FunctionTrampoline3*> (&bother); 00041 return other and other->callback == callback; } 00042 public: 00043 FunctionTrampoline3 (Callback c) : 00044 callback (c) 00045 {} 00046 }; 00047 template<class Class, typename R0, typename A1, typename A2, typename A3> 00048 class MethodTrampoline3 : public Trampoline3 <R0, A1, A2, A3>, public virtual Deletable::DeletionHook { 00049 typedef R0 (Class::*Method) (A1, A2, A3); 00050 Class *instance; 00051 Method method; 00052 virtual R0 operator() (A1 a1, A2 a2, A3 a3) 00053 { return (instance->*method) (a1, a2, a3); } 00054 virtual bool operator== (const TrampolineLink &bother) const { 00055 const MethodTrampoline3 *other = dynamic_cast<const MethodTrampoline3*> (&bother); 00056 return other and other->instance == instance and other->method == method; } 00057 virtual ~MethodTrampoline3 () { deletable_remove_hook (instance); } 00058 virtual void monitoring_deletable (Deletable &deletable) { /* deletable == instance */ } 00059 virtual void dismiss_deletable () { instance = NULL; this->unlink(); } 00060 public: 00061 MethodTrampoline3 (Class &obj, Method m) : 00062 instance (&obj), method (m) { deletable_add_hook (instance); } 00063 }; 00064 00065 /* --- Trampoline with Data --- */ 00066 template<typename R0, typename A1, typename A2, typename A3, typename Data> 00067 class DataFunctionTrampoline3 : public Trampoline3 <R0, A1, A2, A3> { 00068 typedef R0 (*Callback) (A1, A2, A3, Data); 00069 Callback callback; Data data; 00070 virtual R0 operator() (A1 a1, A2 a2, A3 a3) 00071 { return callback (a1, a2, a3, data); } 00072 virtual ~DataFunctionTrampoline3() {} 00073 virtual bool operator== (const TrampolineLink &bother) const { 00074 const DataFunctionTrampoline3 *other = dynamic_cast<const DataFunctionTrampoline3*> (&bother); 00075 return other and other->callback == callback and other->data == data; } 00076 public: 00077 DataFunctionTrampoline3 (Callback c, Data d) : 00078 callback (c), data (d) 00079 {} 00080 }; 00081 template<class Class, typename R0, typename A1, typename A2, typename A3, typename Data> 00082 class DataMethodTrampoline3 : public Trampoline3 <R0, A1, A2, A3>, public virtual Deletable::DeletionHook { 00083 typedef R0 (Class::*Method) (A1, A2, A3, Data); 00084 Class *instance; Method method; Data data; 00085 virtual R0 operator() (A1 a1, A2 a2, A3 a3) 00086 { return (instance->*method) (a1, a2, a3, data); } 00087 virtual bool operator== (const TrampolineLink &bother) const { 00088 const DataMethodTrampoline3 *other = dynamic_cast<const DataMethodTrampoline3*> (&bother); 00089 return other and other->instance == instance and other->method == method and other->data == data; } 00090 virtual ~DataMethodTrampoline3 () { deletable_remove_hook (instance); } 00091 virtual void monitoring_deletable (Deletable &deletable) { /* deletable == instance */ } 00092 virtual void dismiss_deletable () { instance = NULL; this->unlink(); } 00093 public: 00094 DataMethodTrampoline3 (Class &obj, Method m, Data d) : 00095 instance (&obj), method (m), data (d) { deletable_add_hook (instance); } 00096 }; 00097 00098 /* --- Slots (Trampoline wrappers) --- */ 00099 template<typename R0, typename A1, typename A2, typename A3, class Emitter = void> 00100 struct Slot3 : SlotBase { 00101 explicit Slot3 (Trampoline3<R0, A1, A2, A3> *trampoline) : SlotBase (trampoline) {} 00102 Trampoline3<R0, A1, A2, A3>* get_trampoline() const 00103 { return trampoline_cast< Trampoline3<R0, A1, A2, A3>* > (get_trampoline_link()); } 00104 Slot3 (R0 (*callback) (A1, A2, A3)) : SlotBase (new FunctionTrampoline3<R0, A1, A2, A3> (callback)) {} 00105 }; 00106 /* slot constructors */ 00107 template<typename R0, typename A1, typename A2, typename A3> Slot3<R0, A1, A2, A3> 00108 slot (R0 (*callback) (A1, A2, A3)) 00109 { 00110 return Slot3<R0, A1, A2, A3> (new FunctionTrampoline3<R0, A1, A2, A3> (callback)); 00111 } 00112 template<typename R0, typename A1, typename A2, typename A3, typename Data> Slot3<R0, A1, A2, A3> 00113 slot (R0 (*callback) (A1, A2, A3, Data), Data data) 00114 { 00115 return Slot3<R0, A1, A2, A3> (new DataFunctionTrampoline3<R0, A1, A2, A3, Data> (callback, data)); 00116 } 00117 template<typename R0, typename A1, typename A2, typename A3, typename Data> Slot3<R0, A1, A2, A3> 00118 slot (R0 (*callback) (A1, A2, A3, Data&), Data &data) 00119 { 00120 return Slot3<R0, A1, A2, A3> (new DataFunctionTrampoline3<R0, A1, A2, A3, Data&> (callback, data)); 00121 } 00122 template<class Class, typename R0, typename A1, typename A2, typename A3> Slot3<R0, A1, A2, A3> 00123 slot (Class &obj, R0 (Class::*method) (A1, A2, A3)) 00124 { 00125 return Slot3<R0, A1, A2, A3> (new MethodTrampoline3<Class, R0, A1, A2, A3> (obj, method)); 00126 } 00127 template<class Class, typename R0, typename A1, typename A2, typename A3, typename Data> Slot3<R0, A1, A2, A3> 00128 slot (Class &obj, R0 (Class::*method) (A1, A2, A3, Data), Data data) 00129 { 00130 return Slot3<R0, A1, A2, A3> (new DataMethodTrampoline3<Class, R0, A1, A2, A3, Data> (obj, method, data)); 00131 } 00132 template<class Class, typename R0, typename A1, typename A2, typename A3, typename Data> Slot3<R0, A1, A2, A3> 00133 slot (Class &obj, R0 (Class::*method) (A1, A2, A3, Data&), Data &data) 00134 { 00135 return Slot3<R0, A1, A2, A3> (new DataMethodTrampoline3<Class, R0, A1, A2, A3, Data&> (obj, method, data)); 00136 } 00137 template<typename Obj, typename R0, typename A1, typename A2, typename A3> Slot3<R0, A1, A2, A3> 00138 slot (Signal<Obj, R0 (A1, A2, A3)> &sigref) 00139 { 00140 typedef Signal<Obj, R0 (A1, A2, A3)> CustomSignal; 00141 return Slot3<R0, A1, A2, A3> (new MethodTrampoline3<CustomSignal, R0, A1, A2, A3> (sigref, &CustomSignal::emit)); 00142 }
1.7.4