1 /*
2                                     __
3                                    / _|
4   __ _ _   _ _ __ ___  _ __ __ _  | |_ ___  ___ ___
5  / _` | | | | '__/ _ \| '__/ _` | |  _/ _ \/ __/ __|
6 | (_| | |_| | | | (_) | | | (_| | | || (_) \__ \__ \
7  \__,_|\__,_|_|  \___/|_|  \__,_| |_| \___/|___/___/
8 
9 Copyright (C) 2019 Aurora Free Open Source Software.
10 Copyright (C) 2019 João Lourenço <joao@aurorafoss.org>
11 
12 This file is part of the Aurora Free Open Source Software. This
13 organization promote free and open source software that you can
14 redistribute and/or modify under the terms of the GNU Lesser General
15 Public License Version 3 as published by the Free Software Foundation or
16 (at your option) any later version approved by the Aurora Free Open Source
17 Software Organization. The license is available in the package root path
18 as 'LICENSE' file. Please review the following information to ensure the
19 GNU Lesser General Public License version 3 requirements will be met:
20 https://www.gnu.org/licenses/lgpl.html .
21 
22 Alternatively, this file may be used under the terms of the GNU General
23 Public License version 3 or later as published by the Free Software
24 Foundation. Please review the following information to ensure the GNU
25 General Public License requirements will be met:
26 https://www.gnu.org/licenses/gpl-3.0.html.
27 
28 NOTE: All products, services or anything associated to trademarks and
29 service marks used or referenced on this file are the property of their
30 respective companies/owners or its subsidiaries. Other names and brands
31 may be claimed as the property of others.
32 
33 For more info about intellectual property visit: aurorafoss.org or
34 directly send an email to: contact (at) aurorafoss.org .
35 */
36 
37 module aurorafw.entity.componentmanager;
38 
39 import aurorafw.entity.icomponent;
40 import aurorafw.entity.world;
41 
42 version(unittest) import aurorafw.unit.assertion;
43 
44 import std.exception;
45 import std.traits : fullyQualifiedName;
46 
47 
48 final class ComponentHandlingException : Exception
49 {
50 	mixin basicExceptionCtors;
51 }
52 
53 
54 final class ComponentManager
55 {
56 	/**
57 	 * idOf
58 	 *
59 	 * Returns: the id of a given component
60 	 *
61 	 * Examples:
62 	 * --------------------
63 	 * world.component.idOf!Foo;
64 	 * --------------------
65 	 */
66 	@safe pure
67 	static public string idOf(C : IComponent)()
68 	{
69 		return fullyQualifiedName!C;
70 	}
71 
72 
73 	/// ditto
74 	@safe pure
75 	static public string idOf(C : IComponent)(C component)
76 	{
77 		return fullyQualifiedName!C;
78 	}
79 }
80 
81 
82 version(unittest)
83 	private final class unittest_FooComponent : IComponent { int var; }
84 
85 
86 ///
87 @safe pure
88 @("Component Manager: Component id")
89 unittest
90 {
91 	ComponentManager manager = new ComponentManager();
92 
93 	assertEquals("aurorafw.entity.componentmanager.unittest_FooComponent",
94 				manager.idOf!unittest_FooComponent);
95 }