annotate src/common/Module.cpp @ 1448:108ee2e81f65 default tip

Fix a case typo, imageData.h -> ImageData.h
author Radomir Dopieralski <sheep-devel@sheep.art.pl>
date Sat, 18 Jan 2014 13:57:44 +0100
parents b7f097053d74
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1117
3c6206da8bcf Add Module::registerInstance() and Module::getInstance().
vrld <vrld@vrld.org>
parents:
diff changeset
1 /**
1282
b7f097053d74 Updated copyright text for the new year
Alex Szpakowski <slime73@gmail.com>
parents: 1125
diff changeset
2 * Copyright (c) 2006-2013 LOVE Development Team
1117
3c6206da8bcf Add Module::registerInstance() and Module::getInstance().
vrld <vrld@vrld.org>
parents:
diff changeset
3 *
3c6206da8bcf Add Module::registerInstance() and Module::getInstance().
vrld <vrld@vrld.org>
parents:
diff changeset
4 * This software is provided 'as-is', without any express or implied
3c6206da8bcf Add Module::registerInstance() and Module::getInstance().
vrld <vrld@vrld.org>
parents:
diff changeset
5 * warranty. In no event will the authors be held liable for any damages
3c6206da8bcf Add Module::registerInstance() and Module::getInstance().
vrld <vrld@vrld.org>
parents:
diff changeset
6 * arising from the use of this software.
3c6206da8bcf Add Module::registerInstance() and Module::getInstance().
vrld <vrld@vrld.org>
parents:
diff changeset
7 *
3c6206da8bcf Add Module::registerInstance() and Module::getInstance().
vrld <vrld@vrld.org>
parents:
diff changeset
8 * Permission is granted to anyone to use this software for any purpose,
3c6206da8bcf Add Module::registerInstance() and Module::getInstance().
vrld <vrld@vrld.org>
parents:
diff changeset
9 * including commercial applications, and to alter it and redistribute it
3c6206da8bcf Add Module::registerInstance() and Module::getInstance().
vrld <vrld@vrld.org>
parents:
diff changeset
10 * freely, subject to the following restrictions:
3c6206da8bcf Add Module::registerInstance() and Module::getInstance().
vrld <vrld@vrld.org>
parents:
diff changeset
11 *
3c6206da8bcf Add Module::registerInstance() and Module::getInstance().
vrld <vrld@vrld.org>
parents:
diff changeset
12 * 1. The origin of this software must not be misrepresented; you must not
3c6206da8bcf Add Module::registerInstance() and Module::getInstance().
vrld <vrld@vrld.org>
parents:
diff changeset
13 * claim that you wrote the original software. If you use this software
3c6206da8bcf Add Module::registerInstance() and Module::getInstance().
vrld <vrld@vrld.org>
parents:
diff changeset
14 * in a product, an acknowledgment in the product documentation would be
3c6206da8bcf Add Module::registerInstance() and Module::getInstance().
vrld <vrld@vrld.org>
parents:
diff changeset
15 * appreciated but is not required.
3c6206da8bcf Add Module::registerInstance() and Module::getInstance().
vrld <vrld@vrld.org>
parents:
diff changeset
16 * 2. Altered source versions must be plainly marked as such, and must not be
3c6206da8bcf Add Module::registerInstance() and Module::getInstance().
vrld <vrld@vrld.org>
parents:
diff changeset
17 * misrepresented as being the original software.
3c6206da8bcf Add Module::registerInstance() and Module::getInstance().
vrld <vrld@vrld.org>
parents:
diff changeset
18 * 3. This notice may not be removed or altered from any source distribution.
3c6206da8bcf Add Module::registerInstance() and Module::getInstance().
vrld <vrld@vrld.org>
parents:
diff changeset
19 **/
3c6206da8bcf Add Module::registerInstance() and Module::getInstance().
vrld <vrld@vrld.org>
parents:
diff changeset
20
3c6206da8bcf Add Module::registerInstance() and Module::getInstance().
vrld <vrld@vrld.org>
parents:
diff changeset
21 // LOVE
3c6206da8bcf Add Module::registerInstance() and Module::getInstance().
vrld <vrld@vrld.org>
parents:
diff changeset
22 #include "Module.h"
3c6206da8bcf Add Module::registerInstance() and Module::getInstance().
vrld <vrld@vrld.org>
parents:
diff changeset
23 #include "Exception.h"
3c6206da8bcf Add Module::registerInstance() and Module::getInstance().
vrld <vrld@vrld.org>
parents:
diff changeset
24
3c6206da8bcf Add Module::registerInstance() and Module::getInstance().
vrld <vrld@vrld.org>
parents:
diff changeset
25 // std
3c6206da8bcf Add Module::registerInstance() and Module::getInstance().
vrld <vrld@vrld.org>
parents:
diff changeset
26 #include <map>
3c6206da8bcf Add Module::registerInstance() and Module::getInstance().
vrld <vrld@vrld.org>
parents:
diff changeset
27 #include <utility>
3c6206da8bcf Add Module::registerInstance() and Module::getInstance().
vrld <vrld@vrld.org>
parents:
diff changeset
28 #include <string>
3c6206da8bcf Add Module::registerInstance() and Module::getInstance().
vrld <vrld@vrld.org>
parents:
diff changeset
29
3c6206da8bcf Add Module::registerInstance() and Module::getInstance().
vrld <vrld@vrld.org>
parents:
diff changeset
30 namespace
3c6206da8bcf Add Module::registerInstance() and Module::getInstance().
vrld <vrld@vrld.org>
parents:
diff changeset
31 {
3c6206da8bcf Add Module::registerInstance() and Module::getInstance().
vrld <vrld@vrld.org>
parents:
diff changeset
32 std::map<std::string, love::Module*> registry;
3c6206da8bcf Add Module::registerInstance() and Module::getInstance().
vrld <vrld@vrld.org>
parents:
diff changeset
33 } // anonymous namespace
3c6206da8bcf Add Module::registerInstance() and Module::getInstance().
vrld <vrld@vrld.org>
parents:
diff changeset
34
3c6206da8bcf Add Module::registerInstance() and Module::getInstance().
vrld <vrld@vrld.org>
parents:
diff changeset
35 namespace love
3c6206da8bcf Add Module::registerInstance() and Module::getInstance().
vrld <vrld@vrld.org>
parents:
diff changeset
36 {
3c6206da8bcf Add Module::registerInstance() and Module::getInstance().
vrld <vrld@vrld.org>
parents:
diff changeset
37 void Module::registerInstance(Module *instance)
3c6206da8bcf Add Module::registerInstance() and Module::getInstance().
vrld <vrld@vrld.org>
parents:
diff changeset
38 {
3c6206da8bcf Add Module::registerInstance() and Module::getInstance().
vrld <vrld@vrld.org>
parents:
diff changeset
39 if (instance == NULL)
3c6206da8bcf Add Module::registerInstance() and Module::getInstance().
vrld <vrld@vrld.org>
parents:
diff changeset
40 throw Exception("Module instance is NULL");
3c6206da8bcf Add Module::registerInstance() and Module::getInstance().
vrld <vrld@vrld.org>
parents:
diff changeset
41
3c6206da8bcf Add Module::registerInstance() and Module::getInstance().
vrld <vrld@vrld.org>
parents:
diff changeset
42 std::string name(instance->getName());
3c6206da8bcf Add Module::registerInstance() and Module::getInstance().
vrld <vrld@vrld.org>
parents:
diff changeset
43
3c6206da8bcf Add Module::registerInstance() and Module::getInstance().
vrld <vrld@vrld.org>
parents:
diff changeset
44 std::map<std::string, Module*>::iterator it = registry.find(name);
1125
05f0d0e44cd5 Don't throw exception when loading module in thread.
vrld <vrld@vrld.org>
parents: 1117
diff changeset
45
1117
3c6206da8bcf Add Module::registerInstance() and Module::getInstance().
vrld <vrld@vrld.org>
parents:
diff changeset
46 if (registry.end() != it)
1125
05f0d0e44cd5 Don't throw exception when loading module in thread.
vrld <vrld@vrld.org>
parents: 1117
diff changeset
47 {
05f0d0e44cd5 Don't throw exception when loading module in thread.
vrld <vrld@vrld.org>
parents: 1117
diff changeset
48 if (it->second == instance)
05f0d0e44cd5 Don't throw exception when loading module in thread.
vrld <vrld@vrld.org>
parents: 1117
diff changeset
49 return;
1117
3c6206da8bcf Add Module::registerInstance() and Module::getInstance().
vrld <vrld@vrld.org>
parents:
diff changeset
50 throw Exception("Module %s already registered!", instance->getName());
1125
05f0d0e44cd5 Don't throw exception when loading module in thread.
vrld <vrld@vrld.org>
parents: 1117
diff changeset
51 }
1117
3c6206da8bcf Add Module::registerInstance() and Module::getInstance().
vrld <vrld@vrld.org>
parents:
diff changeset
52
3c6206da8bcf Add Module::registerInstance() and Module::getInstance().
vrld <vrld@vrld.org>
parents:
diff changeset
53 registry.insert(make_pair(name, instance));
3c6206da8bcf Add Module::registerInstance() and Module::getInstance().
vrld <vrld@vrld.org>
parents:
diff changeset
54 }
3c6206da8bcf Add Module::registerInstance() and Module::getInstance().
vrld <vrld@vrld.org>
parents:
diff changeset
55
3c6206da8bcf Add Module::registerInstance() and Module::getInstance().
vrld <vrld@vrld.org>
parents:
diff changeset
56 Module *Module::getInstance(const char *name)
3c6206da8bcf Add Module::registerInstance() and Module::getInstance().
vrld <vrld@vrld.org>
parents:
diff changeset
57 {
3c6206da8bcf Add Module::registerInstance() and Module::getInstance().
vrld <vrld@vrld.org>
parents:
diff changeset
58 std::map<std::string, Module*>::iterator it = registry.find(std::string(name));
3c6206da8bcf Add Module::registerInstance() and Module::getInstance().
vrld <vrld@vrld.org>
parents:
diff changeset
59
3c6206da8bcf Add Module::registerInstance() and Module::getInstance().
vrld <vrld@vrld.org>
parents:
diff changeset
60 if (registry.end() == it)
3c6206da8bcf Add Module::registerInstance() and Module::getInstance().
vrld <vrld@vrld.org>
parents:
diff changeset
61 return NULL;
3c6206da8bcf Add Module::registerInstance() and Module::getInstance().
vrld <vrld@vrld.org>
parents:
diff changeset
62
3c6206da8bcf Add Module::registerInstance() and Module::getInstance().
vrld <vrld@vrld.org>
parents:
diff changeset
63 return it->second;
3c6206da8bcf Add Module::registerInstance() and Module::getInstance().
vrld <vrld@vrld.org>
parents:
diff changeset
64 }
3c6206da8bcf Add Module::registerInstance() and Module::getInstance().
vrld <vrld@vrld.org>
parents:
diff changeset
65 } // namespace love