1 module cheetah.socketevent;
2 
3 import cheetah.socketeventargs;
4 
5 /// Represents a socket event.
6 class SocketEvent(T) {
7   private:
8   /// The function pointer to the event handler.
9   void function(SocketEventArgs!T) _f;
10   /// The delegate to the event handler.
11   void delegate(SocketEventArgs!T) _d;
12 
13   public:
14   /**
15   * Creates a new socket event based on a function pointer.
16   * Params:
17   *   f = The function pointer.
18   */
19   this(void function(SocketEventArgs!T) f) {
20     _f = f;
21   }
22 
23   /**
24   * Creates a new socket event based on a delegate.
25   * Params:
26   *   d = The delegate.
27   */
28   this(void delegate(SocketEventArgs!T) d) {
29     _d = d;
30   }
31 
32   /*
33   * Operator overload for calling the class as a function.
34   * Params:
35   *   e = The event args.
36   */
37   void opCall(SocketEventArgs!T e) {
38     if (_f) {
39       _f(e);
40     }
41     else if (_d) {
42       _d(e);
43     }
44   }
45 }