MyGUI 3.4.3
MyGUI_DynLibManager.cpp
Go to the documentation of this file.
1/*
2 * This source file is part of MyGUI. For the latest info, see http://mygui.info/
3 * Distributed under the MIT License
4 * (See accompanying file COPYING.MIT or copy at http://opensource.org/licenses/MIT)
5 */
6
7#include "MyGUI_Precompiled.h"
9#include "MyGUI_Gui.h"
10#include "MyGUI_WidgetManager.h"
11
12namespace MyGUI
13{
14
16
18 mSingletonHolder(this)
19 {
20 }
21
23 {
24 MYGUI_ASSERT(!mIsInitialise, getClassTypeName() << " initialised twice");
25 MYGUI_LOG(Info, "* Initialise: " << getClassTypeName());
26
27 Gui::getInstance().eventFrameStart += newDelegate(this, &DynLibManager::notifyEventFrameStart);
28
29 MYGUI_LOG(Info, getClassTypeName() << " successfully initialized");
30 mIsInitialise = true;
31 }
32
34 {
35 MYGUI_ASSERT(mIsInitialise, getClassTypeName() << " is not initialised");
36 MYGUI_LOG(Info, "* Shutdown: " << getClassTypeName());
37
38 unloadAll();
39
40 Gui::getInstance().eventFrameStart -= newDelegate(this, &DynLibManager::notifyEventFrameStart);
42
43 MYGUI_LOG(Info, getClassTypeName() << " successfully shutdown");
44 mIsInitialise = false;
45 }
46
47 DynLib* DynLibManager::load(std::string_view fileName)
48 {
49 StringDynLibMap::iterator it = mLibsMap.find(fileName);
50
51 if (it != mLibsMap.end())
52 {
53 return it->second;
54 }
55
56 DynLib* pLib = new DynLib(fileName);
57 if (!pLib->load())
58 {
59 delete pLib;
60 return nullptr;
61 }
62
63 mLibsMap[pLib->getName()] = pLib;
64 return pLib;
65 }
66
68 {
69 StringDynLibMap::iterator it = mLibsMap.find(library->getName());
70
71 if (it != mLibsMap.end())
72 mLibsMap.erase(it);
73
74 mDelayDynLib.push_back(library);
75 }
76
78 {
79 // unload and delete resources
80 for (const auto& it : mLibsMap)
81 {
82 mDelayDynLib.push_back(it.second);
83 }
84 // Empty the list
85 mLibsMap.clear();
86 }
87
88 void DynLibManager::notifyEventFrameStart(float _time)
89 {
91 }
92
94 {
95 if (!mDelayDynLib.empty())
96 {
98 if (manager != nullptr)
99 manager->_deleteDelayWidgets();
100
101 for (auto& entry : mDelayDynLib)
102 {
103 entry->unload();
104 delete entry;
105 }
106 mDelayDynLib.clear();
107 }
108 }
109
110} // namespace MyGUI
#define MYGUI_ASSERT(exp, dest)
#define MYGUI_LOG(level, text)
#define MYGUI_SINGLETON_DEFINITION(ClassName)
Resource holding data about a dynamic library.
const std::string & getName() const
Get the name of the library.
Manager of dynamic libraries.
static std::string_view getClassTypeName()
void unload(DynLib *library)
Unload library.
DynLib * load(std::string_view fileName)
Load library.
static Gui & getInstance()
Definition MyGUI_Gui.cpp:34
EventHandle_FrameEventDelegate eventFrameStart
Definition MyGUI_Gui.h:215
static WidgetManager * getInstancePtr()
delegates::DelegateFunction< Args... > * newDelegate(void(*_func)(Args... args))