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 
12 import devol.singleton;
13 
14 public
15 {
16 	import devol.std.typeline;
17 	import devol.std.typevoid;
18 	import devol.std.typescope;
19 }
20 
21 class TypeMng : Singleton!TypeMng
22 {
23 	static this()
24 	{
25 		auto tm = new TypeMng;
26 	}
27 	
28 	this()
29 	{
30 		registerType!(TypeVoid)();
31 		registerType!(TypeLine)();
32 		registerType!(TypeScope)();
33 	}
34 	
35 	void registerType(T)()
36 		if ( __traits(compiles, "Type t = new T()" ) )
37 	{	
38 		Type t = new T();
39 		
40 		if ( t.name in mTypes )
41 			throw new Exception("This type already registered!");
42 		
43 		mTypes[t.name] = t;
44 	}
45 	
46 	
47 	Type getType(string name)
48 	{
49 		if ( name !in mTypes )
50 			throw new Exception(name~" type isn't registered!");
51 			
52 		return mTypes[name];
53 	}
54 		
55 	@property Type[] types()
56 	{
57 		return mTypes.values;
58 	}
59 	 
60 	@property string[] strings()
61 	{
62 		return mTypes.keys;
63 	}
64 	
65 	protected Type[string] mTypes;
66 }