Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/trunk/src/lib/gui/gl/signal_connector.h @ 8145

Last change on this file since 8145 was 8145, checked in by bensch, 18 years ago

trunk: merged the gui back
merged with command:
svn merge -r8114:HEAD https://svn.orxonox.net/orxonox/branches/gui .
→ no conflicts

File size: 6.4 KB
Line 
1/*!
2 * @file signal_connector.h
3 * @brief Definition of a SignalConnector class
4*/
5
6#ifndef _SIGNAL_CONNECTOR_H
7#define _SIGNAL_CONNECTOR_H
8
9#include "executor/executor.h"
10
11namespace OrxGui
12{
13
14  //////////////// TO BE IGNORED BY YOU /////
15#define DeclareSignalBegin(SignalName) \
16  public: \
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] (); \
37   }\
38     DeclareSignalEnd(SignalName)
39
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   */
151  class SignalConnector
152  {
153  public:
154    SignalConnector();
155    SignalConnector(BaseObject* object, const Executor* exec);
156    SignalConnector(const SignalConnector& signalConnector);
157    ~SignalConnector();
158
159    SignalConnector& operator=(const SignalConnector& signalConnector);
160    bool operator==(const SignalConnector& signalConnector) const;
161
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;
168
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 */
172    bool isClean() const { return (this->object == NULL || this->exec == NULL); }
173
174
175  private:
176    BaseObject*          object;         //!< The object to call.
177    const Executor*      exec;           //!< The Executor, that will be called, on object.
178  };
179
180  //! TypeDefinition for SignalLists
181  typedef std::vector<SignalConnector> Signal;
182  //! TypeDefinition for a Slot.
183  typedef Executor*                    Slot;
184
185}
186#endif /* _SIGNAL_CONNECTOR_H */
Note: See TracBrowser for help on using the repository browser.