1 module glued.codescan.listener;
2 
3 import std.meta;
4 import std.typecons;
5 
6 import glued.codescan.scannable;
7 
8 interface ScanListener(State) 
9 {
10     void init(State state);
11 
12     void onScannable(alias scannable)() if (isScannable!scannable);
13     
14     void onType(T)();
15     
16     void onBundleModule(string modName)();
17     
18     void onScannerFreeze();
19 }
20 
21 class CompositeListener(State, Listeners...): ScanListener!State  
22 //    if (allSatisfy!(L => is(L: Listener!State) && __traits(compiles, new L()), Listeners)) //todo
23 {
24     private Tuple!(AliasSeq!(Listeners)) listeners;
25 
26     this()
27     {
28         static foreach (i, L; Listeners) 
29         { 
30             listeners[i] = new L();
31         }
32     }
33     
34     void init(State state)
35     {
36         static foreach (i, L; Listeners) 
37         { 
38             listeners[i].init(state);
39         }
40     }
41     
42     void onScannable(alias scannable)() if (isScannable!scannable)
43     {
44         static foreach (i, L; Listeners) 
45         { 
46             listeners[i].onScannable!(scannable)();
47         }
48     }
49     
50     void onType(T)()
51     {
52         static foreach (i, L; Listeners) 
53         { 
54             listeners[i].onType!(T)();
55         }
56     }
57     
58     void onBundleModule(string modName)()
59     {
60         static foreach (i, L; Listeners) 
61         { 
62             listeners[i].onBundleModule!(modName)();
63         }
64     }
65     
66     void onScannerFreeze()
67     {
68         static foreach (i, L; Listeners) 
69         { 
70             listeners[i].onScannerFreeze();
71         }
72     }
73 }