1 /**
2  * This System provider returns results of a method call. The method
3  * is passed to the provider at initialisation.
4  */
5 module ashd.fsm.dynamicSystemProvider;
6 
7 import std.conv: to;
8 
9 import ashd.core.system        : System;
10 import ashd.fsm.ISystemProvider: ISystemProvider;
11 
12 
13 public class DynamicSystemProvider: ISystemProvider
14 {
15     private
16     {
17         Object delegate() mMethod;
18         int               mSystemPriority;
19     }
20 
21     /**
22      * Constructor
23      *
24      * @param method The method that returns the System instance;
25      */
26     public this( Object delegate() method_a )
27     {
28         mMethod = method_a;
29     }
30 
31     /**
32      * Used to request a component from this provider
33      *
34      * @return The instance of the System
35      */
36     Object createDynamicInstance( ClassInfo type_a )
37     {
38         return mMethod();
39     }
40 
41     /**
42      * Used to compare this provider with others. Any provider that returns the same component
43      * instance will be regarded as equivalent.
44      *
45      * @return The method used to call the System instances
46      */
47     public hash_t identifier()
48     {
49         return ISystemProvider.toHash( to!string(mMethod.funcptr) );
50     }
51 
52     @property
53     {
54         /**
55          * The priority at which the System should be added to the Engine
56          */
57         public int  priority() { return mSystemPriority; }
58         public void priority( int value_a ) { mSystemPriority = value_a; }
59     }
60 }