1 /** 2 * Skadi.d Web Framework 3 * 4 * Authors: Faianca 5 * Copyright: Copyright (c) 2015 Faianca 6 * License: MIT License, see LICENSE 7 */ 8 module singleton; 9 10 mixin template Singleton () 11 { 12 mixin .SingletonBase; 13 } 14 15 mixin template Singleton ( alias Ctor ) 16 { 17 mixin .SingletonBase; 18 19 protected this () 20 { 21 static if ( is( typeof( super() ) ) ) { 22 super(); 23 } 24 Ctor(); 25 } 26 27 } 28 29 mixin template Singleton ( string CtorImpl ) 30 { 31 mixin .SingletonBase; 32 33 protected this () 34 { 35 static if ( is( typeof( super() ) ) ) { 36 super(); 37 } 38 mixin( CtorImpl ); 39 } 40 } 41 42 mixin template SingletonBase () 43 { 44 static @property RealClass instance ( this RealClass ) () 45 { 46 static RealClass self; 47 48 if ( self is null ) { 49 self = new RealClass; 50 } 51 return self; 52 } 53 54 alias instance opCall; 55 }