1 /**
2 * Copyright © Webd 2018
3 * License: MIT (https://github.com/DiamondMVC/Webd/blob/master/LICENSE)
4 * Author: Jacob Jensen (bausshf)
5 */
6 module webd.modules.moduleaction;
7 
8 /// Interface for a module action.
9 interface IModuleAction { }
10 
11 /// Wrapper around a module action.
12 final class ModuleAction(T) : IModuleAction
13 {
14     private:
15     /// The associated delegate.
16     void delegate(T) _delegate;
17 
18     /// The associated function pointer.
19     void function(T) _functionPointer;
20 
21     public:
22     /**
23     *   Creates a new module action.
24     *   Params:
25     *       d = The delegate.
26     */
27     this(void delegate(T) d)
28     {
29         _delegate = d;
30     }
31 
32     /**
33     *   Creates a new module action.
34     *   Params:
35     *       f = The function pointer..
36     */
37     this(void function(T) f)
38     {
39         _functionPointer = f;
40     }
41 
42     /**
43     *   Operator overload for using the wrapper as a call.
44     */
45     void opCall(T args)
46     {
47         if (_delegate)
48         {
49           _delegate(args);
50         }
51         else if (_functionPointer)
52         {
53           _functionPointer(args);
54         }
55     }
56 }