/src/ogre/OgreMain/src/OgreDynLibManager.cpp
Line | Count | Source |
1 | | /* |
2 | | ----------------------------------------------------------------------------- |
3 | | This source file is part of OGRE |
4 | | (Object-oriented Graphics Rendering Engine) |
5 | | For the latest info, see http://www.ogre3d.org/ |
6 | | |
7 | | Copyright (c) 2000-2014 Torus Knot Software Ltd |
8 | | |
9 | | Permission is hereby granted, free of charge, to any person obtaining a copy |
10 | | of this software and associated documentation files (the "Software"), to deal |
11 | | in the Software without restriction, including without limitation the rights |
12 | | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
13 | | copies of the Software, and to permit persons to whom the Software is |
14 | | furnished to do so, subject to the following conditions: |
15 | | |
16 | | The above copyright notice and this permission notice shall be included in |
17 | | all copies or substantial portions of the Software. |
18 | | |
19 | | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
20 | | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
21 | | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
22 | | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
23 | | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
24 | | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
25 | | THE SOFTWARE. |
26 | | ----------------------------------------------------------------------------- |
27 | | */ |
28 | | #include "OgreStableHeaders.h" |
29 | | |
30 | | #include "OgreDynLibManager.h" |
31 | | #include "OgreDynLib.h" |
32 | | |
33 | | namespace Ogre |
34 | | { |
35 | | //----------------------------------------------------------------------- |
36 | | template<> DynLibManager* Singleton<DynLibManager>::msSingleton = 0; |
37 | | DynLibManager* DynLibManager::getSingletonPtr(void) |
38 | 0 | { |
39 | 0 | return msSingleton; |
40 | 0 | } |
41 | | //----------------------------------------------------------------------- |
42 | | DynLibManager& DynLibManager::getSingleton(void) |
43 | 0 | { |
44 | 0 | assert( msSingleton ); return ( *msSingleton ); |
45 | 0 | } |
46 | | //----------------------------------------------------------------------- |
47 | | DynLibManager::DynLibManager() |
48 | 2 | { |
49 | 2 | } |
50 | | //----------------------------------------------------------------------- |
51 | | DynLib* DynLibManager::load( const String& filename) |
52 | 0 | { |
53 | 0 | DynLibList::iterator i = mLibList.find(filename); |
54 | 0 | if (i != mLibList.end()) |
55 | 0 | { |
56 | 0 | return i->second; |
57 | 0 | } |
58 | 0 | else |
59 | 0 | { |
60 | 0 | DynLib* pLib = OGRE_NEW DynLib(filename); |
61 | 0 | pLib->load(); |
62 | 0 | mLibList[filename] = pLib; |
63 | 0 | return pLib; |
64 | 0 | } |
65 | 0 | } |
66 | | //----------------------------------------------------------------------- |
67 | | void DynLibManager::unload(DynLib* lib) |
68 | 0 | { |
69 | 0 | DynLibList::iterator i = mLibList.find(lib->getName()); |
70 | 0 | if (i != mLibList.end()) |
71 | 0 | { |
72 | 0 | mLibList.erase(i); |
73 | 0 | } |
74 | 0 | lib->unload(); |
75 | 0 | OGRE_DELETE lib; |
76 | 0 | } |
77 | | //----------------------------------------------------------------------- |
78 | | DynLibManager::~DynLibManager() |
79 | 1 | { |
80 | | // Unload & delete resources in turn |
81 | 1 | for(auto & it : mLibList) |
82 | 0 | { |
83 | 0 | it.second->unload(); |
84 | 0 | OGRE_DELETE it.second; |
85 | 0 | } |
86 | | |
87 | | // Empty the list |
88 | 1 | mLibList.clear(); |
89 | 1 | } |
90 | | } |