inline wxDynamicLibrary* LoadLibrary(const wxString& filename) { Libs::iterator it = s_Libs.find(filename); if (it != s_Libs.end()) { // existing lib./codeblocks it->second.ref++; return it->second.lib; } // new lib it = s_Libs.insert(s_Libs.end(), std::make_pair(filename, RefCountedLib())); it->second.lib = new wxDynamicLibrary; it->second.ref = 1; it->second.lib->Load(filename); return it->second.lib; }
inline void Cleanup() { Libs::iterator it; for (it = s_Libs.begin(); it != s_Libs.end(); ++it) { RefCountedLib& rcl = it->second; // only delete the lib if not shutting down // if we are shutting down, it will be deleted automatically if (!Manager::IsAppShuttingDown()) delete rcl.lib; } s_Libs.clear(); }
inline void RemoveLibrary(wxDynamicLibrary* lib) { Libs::iterator it; for (it = s_Libs.begin(); it != s_Libs.end(); ++it) { RefCountedLib& rcl = it->second; if (rcl.lib == lib) { // found rcl.ref--; if (rcl.ref == 0) { // only delete the lib if not shutting down // if we are shutting down, it will be deleted automatically if (!Manager::IsAppShuttingDown()) delete rcl.lib; s_Libs.erase(it); } return; } } // if we reached here, it's a lib that was not handled by us // (or had wrong refcounting) }