[4838] | 1 | /*! |
---|
[7779] | 2 | * @file signal_connector.h |
---|
[7855] | 3 | * @brief Definition of a SignalConnector class |
---|
[3245] | 4 | */ |
---|
[1853] | 5 | |
---|
[7779] | 6 | #ifndef _SIGNAL_CONNECTOR_H |
---|
| 7 | #define _SIGNAL_CONNECTOR_H |
---|
[1853] | 8 | |
---|
[7779] | 9 | #include "executor/executor.h" |
---|
[1853] | 10 | |
---|
[7779] | 11 | namespace OrxGui |
---|
| 12 | { |
---|
[7919] | 13 | |
---|
[8035] | 14 | //////////////// TO BE IGNORED BY YOU ///// |
---|
| 15 | #define DeclareSignalBegin(SignalName) \ |
---|
[7919] | 16 | public: \ |
---|
[8035] | 17 | void signal_ ## connect ## SignalName(const SignalConnector& connector) { \ |
---|
| 18 | SignalName ## connected.push_back(connector); \ |
---|
| 19 | }\ |
---|
| 20 | Signal& getSignalVector_##SignalName () { return this->SignalName ## connected; }; \ |
---|
| 21 | private: |
---|
| 22 | |
---|
| 23 | #define DeclareSignalEnd(SignalName) \ |
---|
| 24 | Signal SignalName ## connected |
---|
| 25 | ///////////////////////////////////////////// |
---|
| 26 | |
---|
| 27 | |
---|
| 28 | /** |
---|
| 29 | * @brief declares a new Signal. |
---|
| 30 | * @param SignalName the Name of the Signal. |
---|
| 31 | */ |
---|
| 32 | #define DeclareSignal0(SignalName) \ |
---|
| 33 | DeclareSignalBegin(SignalName) \ |
---|
| 34 | void SignalName () { \ |
---|
| 35 | for (unsigned int i = 0; i < SignalName ## connected .size(); i++) \ |
---|
| 36 | SignalName ## connected[i] (); \ |
---|
[7919] | 37 | }\ |
---|
[8035] | 38 | DeclareSignalEnd(SignalName) |
---|
[7919] | 39 | |
---|
[8035] | 40 | |
---|
| 41 | /** |
---|
| 42 | * @brief declares a new Signal. |
---|
| 43 | * @param SignalName the Name of the Signal. |
---|
| 44 | * @param param0 the first Parameter the Function takes |
---|
| 45 | */ |
---|
| 46 | #define DeclareSignal1(SignalName, param0) \ |
---|
| 47 | DeclareSignalBegin(SignalName) \ |
---|
| 48 | void SignalName (param0 val0) { \ |
---|
| 49 | for (unsigned int i = 0; i < SignalName ## connected .size(); i++) \ |
---|
| 50 | SignalName ## connected[i] (val0); \ |
---|
| 51 | }\ |
---|
| 52 | DeclareSignalEnd(SignalName) |
---|
| 53 | |
---|
| 54 | /** |
---|
| 55 | * @brief declares a new Signal. |
---|
| 56 | * @param SignalName the Name of the Signal. |
---|
| 57 | * @param param0 the first Parameter the Function takes |
---|
| 58 | * @param param1 the second Parameter the Function takes |
---|
| 59 | */ |
---|
| 60 | #define DeclareSignal2(SignalName, param0, param1) \ |
---|
| 61 | DeclareSignalBegin(SignalName) \ |
---|
| 62 | void SignalName (param0 val0, param1 val1) { \ |
---|
| 63 | for (unsigned int i = 0; i < SignalName ## connected .size(); i++) \ |
---|
| 64 | SignalName ## connected[i] (val0, val1); \ |
---|
| 65 | }\ |
---|
| 66 | DeclareSignalEnd(SignalName) |
---|
| 67 | |
---|
| 68 | |
---|
| 69 | |
---|
| 70 | /** |
---|
| 71 | * @brief declares a new Signal. |
---|
| 72 | * @param SignalName the Name of the Signal. |
---|
| 73 | * @param param0 the first Parameter the Function takes |
---|
| 74 | * @param param1 the second Parameter the Function takes |
---|
| 75 | * @param param2 the third Parameter the Function takes |
---|
| 76 | */ |
---|
| 77 | #define DeclareSignal3(SignalName, param0, param1, param2) \ |
---|
| 78 | DeclareSignalBegin(SignalName) \ |
---|
| 79 | void SignalName (param0 val0, param1 val1, param2 val2) { \ |
---|
| 80 | for (unsigned int i = 0; i < SignalName ## connected .size(); i++) \ |
---|
| 81 | SignalName ## connected[i] (val0, val1, val2); \ |
---|
| 82 | }\ |
---|
| 83 | DeclareSignalEnd(SignalName) |
---|
| 84 | |
---|
| 85 | /** |
---|
| 86 | * @brief declares a new Signal. |
---|
| 87 | * @param SignalName the Name of the Signal. |
---|
| 88 | * @param param0 the first Parameter the Function takes |
---|
| 89 | * @param param1 the second Parameter the Function takes |
---|
| 90 | * @param param2 the third Parameter the Function takes |
---|
| 91 | * @param param3 the fourth Parameter the Function takes |
---|
| 92 | */ |
---|
| 93 | #define DeclareSignal4(SignalName, param0, param1, param2, param3) \ |
---|
| 94 | DeclareSignalBegin(SignalName) \ |
---|
| 95 | void SignalName (param0 val0, param1 val1, param2 val2, param3 val3) { \ |
---|
| 96 | for (unsigned int i = 0; i < SignalName ## connected .size(); i++) \ |
---|
| 97 | SignalName ## connected[i] (val0, val1, val2, val3); \ |
---|
| 98 | }\ |
---|
| 99 | DeclareSignalEnd(SignalName) |
---|
| 100 | |
---|
| 101 | |
---|
| 102 | /** |
---|
| 103 | * @brief declares a new Signal. |
---|
| 104 | * @param SignalName the Name of the Signal. |
---|
| 105 | * @param param0 the first Parameter the Function takes |
---|
| 106 | * @param param1 the second Parameter the Function takes |
---|
| 107 | * @param param2 the third Parameter the Function takes |
---|
| 108 | * @param param4 the fifth Parameter the Function takes |
---|
| 109 | */ |
---|
| 110 | #define DeclareSignal5(SignalName, param0, param1, param2, param3, param4) \ |
---|
| 111 | DeclareSignalBegin(SignalName) \ |
---|
| 112 | void SignalName (param0 val0, param1 val1, param2 val2, param3 val3, param4 val4) { \ |
---|
| 113 | for (unsigned int i = 0; i < SignalName ## connected .size(); i++) \ |
---|
| 114 | SignalName ## connected[i] (val0, val1, val2, val3, val4); \ |
---|
| 115 | }\ |
---|
| 116 | DeclareSignalEnd(SignalName) |
---|
| 117 | |
---|
| 118 | |
---|
| 119 | /** |
---|
| 120 | * @brief selects a Signal. |
---|
| 121 | * @param SignalName the Signal to be retrieved. |
---|
| 122 | */ |
---|
| 123 | #define SIGNAL(Object, SignalName) \ |
---|
| 124 | Object->getSignalVector_##SignalName() |
---|
| 125 | |
---|
| 126 | /** |
---|
| 127 | * @brief defines a Slot, the sink of a Signal. |
---|
| 128 | * @param Class the Class the Slot belongs to. |
---|
| 129 | * @param function the Function to Connect to. |
---|
| 130 | */ |
---|
| 131 | #define SLOT(Class, function) \ |
---|
| 132 | createExecutor<Class>(&Class::function) |
---|
| 133 | |
---|
| 134 | /** |
---|
| 135 | * @brief emits function |
---|
| 136 | */ |
---|
| 137 | #define emit(function) function |
---|
| 138 | |
---|
| 139 | //! A class for Conncting Signals to Objects, inside of the Graphical user interface. |
---|
| 140 | /** |
---|
| 141 | * The SignalConnector binds an Object to a Functional (Executor) |
---|
| 142 | * The Usage is quite easy in the Widget for this: |
---|
| 143 | * |
---|
| 144 | * int the header (Class Definition) you can add a definition of a Signal with: |
---|
| 145 | * @verbatim DeclareSignal3(my_signal, int, int, float) |
---|
| 146 | * and a Signal with the the Parameters int,int and float will be created. |
---|
| 147 | * |
---|
| 148 | * now you can use the connect function of GLWidget to connect this Signal to a Slot. |
---|
| 149 | * @see GLGuiWidget::connect |
---|
| 150 | */ |
---|
[7779] | 151 | class SignalConnector |
---|
| 152 | { |
---|
| 153 | public: |
---|
[7855] | 154 | SignalConnector(); |
---|
[7779] | 155 | SignalConnector(BaseObject* object, const Executor* exec); |
---|
| 156 | SignalConnector(const SignalConnector& signalConnector); |
---|
[7855] | 157 | ~SignalConnector(); |
---|
[3543] | 158 | |
---|
[7779] | 159 | SignalConnector& operator=(const SignalConnector& signalConnector); |
---|
[8035] | 160 | bool operator==(const SignalConnector& signalConnector) const; |
---|
[3543] | 161 | |
---|
[8035] | 162 | void operator()() const; |
---|
| 163 | void operator()(const MultiType& value0) const; |
---|
| 164 | void operator()(const MultiType& value0, const MultiType& value1) const; |
---|
| 165 | void operator()(const MultiType& value0, const MultiType& value1, const MultiType& value2) const; |
---|
| 166 | void operator()(const MultiType& value0, const MultiType& value1, const MultiType& value2, const MultiType& value3) const; |
---|
| 167 | void operator()(const MultiType& value0, const MultiType& value1, const MultiType& value2, const MultiType& value3, const MultiType& value4) const; |
---|
[7855] | 168 | |
---|
[8035] | 169 | /** checks wether the SignalConnector is valid @return true on valid. */ |
---|
| 170 | bool isValid() const { return (this->object && this->exec); }; |
---|
| 171 | /** @brief checks if the SignalConnector is clean, invalid @returns true if invalid */ |
---|
[7855] | 172 | bool isClean() const { return (this->object == NULL || this->exec == NULL); } |
---|
| 173 | |
---|
| 174 | |
---|
[7779] | 175 | private: |
---|
[7855] | 176 | BaseObject* object; //!< The object to call. |
---|
| 177 | const Executor* exec; //!< The Executor, that will be called, on object. |
---|
[7779] | 178 | }; |
---|
[8035] | 179 | |
---|
| 180 | //! TypeDefinition for SignalLists |
---|
| 181 | typedef std::vector<SignalConnector> Signal; |
---|
| 182 | //! TypeDefinition for a Slot. |
---|
| 183 | typedef Executor* Slot; |
---|
| 184 | |
---|
[7779] | 185 | } |
---|
| 186 | #endif /* _SIGNAL_CONNECTOR_H */ |
---|