1 /**
2  * This System provider always returns the same instance of the System. The instance
3  * is created when first required and is of the type passed in to the constructor.
4  */
5 module ashd.fsm.systemSingletonProvider;
6 
7 
8 import ashd.core.system        : System;
9 import ashd.fsm.ISystemProvider: ISystemProvider;
10 
11 
12 
13 public class SystemSingletonProvider: ISystemProvider
14 {
15     private
16     {
17         ClassInfo mSystemType;
18         Object    mInstance;
19         int       mSystemPriority;
20     }
21 
22     /**
23      * Constructor
24      *
25      * @param type The type of the single System instance
26      */
27     public this( ClassInfo type_a )
28     {
29         mSystemType = type_a;
30     }
31 
32     /**
33      * Used to request a System from this provider
34      *
35      * @return The single instance
36      */
37     protected Object createDynamicInstance( ClassInfo type_a )
38     {
39         if ( !mInstance )
40         {
41             mInstance = type_a.create();
42         }
43         return mInstance;
44     }
45 
46     /**
47      * Used to compare this provider with others. Any provider that returns the same single
48      * instance will be regarded as equivalent.
49      *
50      * @return The single instance
51      */
52     public hash_t identifier()
53     {
54         if (!mInstance)
55         {
56             mInstance = mSystemType.create();
57         }
58         return mInstance.toHash();
59     }
60 
61     @property
62     {
63         /**
64          * The priority at which the System should be added to the Engine
65          */
66         public int  priority() { return mSystemPriority; }
67         public void priority( int value_a ) { mSystemPriority = value_a; }
68     }
69 }