001:
002: #ifndef _PANE_EVENT
003: #define _PANE_EVENT
004:
005: #include <vector>
006:
007: namespace Pane
008: {
009: /*
010: ** EventHandler class (4 parameters)
011: */
012: template<typename Return, typename Param1 = void, typename Param2 = void, typename Param3 = void, typename Param4 = void>
013: class EventHandler
014: {
015: public:
016: class EventClass
017: {
018: public:
019: virtual ~EventClass ()
020: {
021: }
022:
023: virtual Return operator () (Param1, Param2, Param3, Param4) = 0;
024: };
025:
026: template<typename Sender = void>
027: class Event : public EventClass
028: {
029: public:
030: typedef Return (Sender::*Method) (Param1, Param2, Param3, Param4);
031:
032: /**/ Event (Sender* sender, Method method) :
033: method (method),
034: sender (sender)
035: {
036: }
037:
038: virtual Return operator () (Param1 param1, Param2 param2, Param3 param3, Param4 param4)
039: {
040: return (this->sender->*method) (param1, param2, param3, param4);
041: }
042:
043: private:
044: Method method;
045: Sender* sender;
046: };
047:
048: /**/ ~EventHandler ();
049:
050: void operator += (EventClass*);
051: bool operator () (Param1, Param2, Param3, Param4);
052:
053: private:
054: typedef std::vector<EventClass*> Events;
055:
056: Events events;
057: };
058:
059: /*
060: ** EventHandler class (3 parameters)
061: */
062: template<typename Return, typename Param1, typename Param2, typename Param3>
063: class EventHandler<Return, Param1, Param2, Param3>
064: {
065: public:
066: class EventClass
067: {
068: public:
069: virtual ~EventClass ()
070: {
071: }
072:
073: virtual Return operator () (Param1, Param2, Param3) = 0;
074: };
075:
076: template<typename Sender = void>
077: class Event : public EventClass
078: {
079: public:
080: typedef Return (Sender::*Method) (Param1, Param2, Param3);
081:
082: /**/ Event (Sender* sender, Method method) :
083: method (method),
084: sender (sender)
085: {
086: }
087:
088: virtual Return operator () (Param1 param1, Param2 param2, Param3 param3)
089: {
090: return (this->sender->*method) (param1, param2, param3);
091: }
092:
093: private:
094: Method method;
095: Sender* sender;
096: };
097:
098: /**/ ~EventHandler ();
099:
100: void operator += (EventClass*);
101: bool operator () (Param1, Param2, Param3);
102:
103: private:
104: typedef std::vector<EventClass*> Events;
105:
106: Events events;
107: };
108:
109: /*
110: ** EventHandler class (2 parameters)
111: */
112: template<typename Return, typename Param1, typename Param2>
113: class EventHandler<Return, Param1, Param2>
114: {
115: public:
116: class EventClass
117: {
118: public:
119: virtual ~EventClass ()
120: {
121: }
122:
123: virtual Return operator () (Param1, Param2) = 0;
124: };
125:
126: template<typename Sender = void>
127: class Event : public EventClass
128: {
129: public:
130: typedef Return (Sender::*Method) (Param1, Param2);
131:
132: /**/ Event (Sender* sender, Method method) :
133: method (method),
134: sender (sender)
135: {
136: }
137:
138: virtual Return operator () (Param1 param1, Param2 param2)
139: {
140: return (this->sender->*method) (param1, param2);
141: }
142:
143: private:
144: Method method;
145: Sender* sender;
146: };
147:
148: /**/ ~EventHandler ();
149:
150: void operator += (EventClass*);
151: bool operator () (Param1, Param2);
152:
153: private:
154: typedef std::vector<EventClass*> Events;
155:
156: Events events;
157: };
158:
159: /*
160: ** EventHandler class (1 parameter)
161: */
162: template<typename Return, typename Param1>
163: class EventHandler<Return, Param1>
164: {
165: public:
166: class EventClass
167: {
168: public:
169: virtual ~EventClass ()
170: {
171: }
172:
173: virtual Return operator () (Param1) = 0;
174: };
175:
176: template<typename Sender = void>
177: class Event : public EventClass
178: {
179: public:
180: typedef Return (Sender::*Method) (Param1);
181:
182: /**/ Event (Sender* sender, Method method) :
183: method (method),
184: sender (sender)
185: {
186: }
187:
188: virtual Return operator () (Param1 param1)
189: {
190: return (this->sender->*method) (param1);
191: }
192:
193: private:
194: Method method;
195: Sender* sender;
196: };
197:
198: /**/ ~EventHandler ();
199:
200: void operator += (EventClass*);
201: bool operator () (Param1);
202:
203: private:
204: typedef std::vector<EventClass*> Events;
205:
206: Events events;
207: };
208:
209: /*
210: ** EventHandler class (0 parameter)
211: */
212: template<typename Return>
213: class EventHandler<Return>
214: {
215: public:
216: class EventClass
217: {
218: public:
219: virtual ~EventClass ()
220: {
221: }
222:
223: virtual Return operator () () = 0;
224: };
225:
226: template<typename Sender = void>
227: class Event : public EventClass
228: {
229: public:
230: typedef Return (Sender::*Method) ();
231:
232: /**/ Event (Sender* sender, Method method) :
233: method (method),
234: sender (sender)
235: {
236: }
237:
238: virtual Return operator () ()
239: {
240: return (this->sender->*method) ();
241: }
242:
243: private:
244: Method method;
245: Sender* sender;
246: };
247:
248: /**/ ~EventHandler ();
249:
250: void operator += (EventClass*);
251: bool operator () ();
252:
253: private:
254: typedef std::vector<EventClass*> Events;
255:
256: Events events;
257: };
258: }
259:
260: #include "eventHandler.hxx"
261:
262: #endif // _PANE_EVENT