1 /**
2 *   Copyright: © 2012-2014 Anton Gushcha
3 *   License: Subject to the terms of the MIT license, as written in the included LICENSE file.
4 *   Authors:  NCrashed <ncrashed@gmail.com>,
5 *             LeMarwin <lemarwin42@gmail.com>,
6 *             Nazgull09 <nazgull90@gmail.com>
7 */
8 module devol.typemng;
9 
10 import std.stdio;
11 import std.conv;
12 
13 import devol.singleton;
14 
15 public
16 {
17 	import devol.std.typeline;
18 	import devol.std.typevoid;
19 	import devol.std.typescope;
20 }
21 
22 class TypeMng : Singleton!TypeMng
23 {
24 	static this()
25 	{
26 		auto tm = new TypeMng;
27 	}
28 	
29 	this()
30 	{
31 		registerType!(TypeVoid)();
32 		registerType!(TypeLine)();
33 		registerType!(TypeScope)();
34 	}
35 	
36 	void registerType(T)()
37 		if ( __traits(compiles, "Type t = new T()" ) )
38 	{	
39 		Type t = new T();
40 		
41 		if ( t.name in mTypes )
42 			throw new Exception(text("Type ", t.name," already registered!"));
43 		
44 		mTypes[t.name] = t;
45 	}
46 	
47 	
48 	Type getType(string name)
49 	{
50 		if ( name !in mTypes )
51 			throw new Exception(name~" type isn't registered!");
52 			
53 		return mTypes[name];
54 	}
55 		
56 	@property Type[] types()
57 	{
58 		return mTypes.values;
59 	}
60 	 
61 	@property string[] strings()
62 	{
63 		return mTypes.keys;
64 	}
65 	
66     int opApply(int delegate(ref Type) dg)
67     {
68         int result = 0;
69     
70         foreach(type; mTypes)
71         {
72             result = dg(type);
73             if (result) break;
74         }
75         return result;
76     }
77     
78 	protected Type[string] mTypes;
79 }