MyGUI  3.0.1
MyGUI_DynLibManager.cpp
Go to the documentation of this file.
1 
7 /*
8  This file is part of MyGUI.
9 
10  MyGUI is free software: you can redistribute it and/or modify
11  it under the terms of the GNU Lesser General Public License as published by
12  the Free Software Foundation, either version 3 of the License, or
13  (at your option) any later version.
14 
15  MyGUI is distributed in the hope that it will be useful,
16  but WITHOUT ANY WARRANTY; without even the implied warranty of
17  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  GNU Lesser General Public License for more details.
19 
20  You should have received a copy of the GNU Lesser General Public License
21  along with MyGUI. If not, see <http://www.gnu.org/licenses/>.
22 */
23 #include "MyGUI_Precompiled.h"
24 #include "MyGUI_DynLibManager.h"
25 
26 namespace MyGUI
27 {
28 
29  MYGUI_INSTANCE_IMPLEMENT( DynLibManager )
30 
31  void DynLibManager::initialise()
32  {
33  MYGUI_ASSERT(!mIsInitialise, INSTANCE_TYPE_NAME << " initialised twice");
34  MYGUI_LOG(Info, "* Initialise: " << INSTANCE_TYPE_NAME);
35 
36  MYGUI_LOG(Info, INSTANCE_TYPE_NAME << " successfully initialized");
37  mIsInitialise = true;
38  }
39 
41  {
42  if (!mIsInitialise) return;
43  MYGUI_LOG(Info, "* Shutdown: " << INSTANCE_TYPE_NAME);
44 
45  StringDynLibMap::iterator it;
46 
47  // unload and delete resources
48  for (it = mLibsMap.begin(); it != mLibsMap.end(); ++it)
49  {
50  it->second->unload();
51  delete it->second;
52  }
53 
54  // Empty the list
55  mLibsMap.clear();
56 
57  MYGUI_LOG(Info, INSTANCE_TYPE_NAME << " successfully shutdown");
58  mIsInitialise = false;
59  }
60 
61  DynLib* DynLibManager::load(const std::string &fileName)
62  {
63  StringDynLibMap::iterator it = mLibsMap.find(fileName);
64 
65  if (it != mLibsMap.end())
66  {
67  return it->second;
68  }
69 
70  DynLib *pLib = new DynLib(fileName);
71  if (!pLib->load())
72  {
73  delete pLib;
74  return 0;
75  }
76 
77  mLibsMap[fileName] = pLib;
78  return pLib;
79  }
80 
82  {
83  StringDynLibMap::iterator it = mLibsMap.find(library->getName());
84 
85  if (it != mLibsMap.end())
86  mLibsMap.erase(it);
87 
88  library->unload();
89  delete library;
90  }
91 }