Merge pull request #2994 from adamreichold/improve-singletons
Continue to simplify and improve singletons
This commit is contained in:
@@ -30,18 +30,8 @@
|
||||
CacheManager*
|
||||
CacheManager::getInstance(void)
|
||||
{
|
||||
static CacheManager* instance_ = 0;
|
||||
|
||||
if ( instance_ == 0 ) {
|
||||
static MyMutex smutex_;
|
||||
MyMutex::MyLock lock(smutex_);
|
||||
|
||||
if ( instance_ == 0 ) {
|
||||
instance_ = new CacheManager();
|
||||
}
|
||||
}
|
||||
|
||||
return instance_;
|
||||
static CacheManager instance_;
|
||||
return &instance_;
|
||||
}
|
||||
|
||||
void CacheManager::init ()
|
||||
|
@@ -24,8 +24,6 @@
|
||||
#include "rtimage.h"
|
||||
#include "threadutils.h"
|
||||
|
||||
static EditWindow* editWnd = NULL;
|
||||
|
||||
// Check if the system has more than one display and option is set
|
||||
bool EditWindow::isMultiDisplayEnabled()
|
||||
{
|
||||
@@ -35,29 +33,26 @@ bool EditWindow::isMultiDisplayEnabled()
|
||||
// Should only be created once, auto-creates window on correct display
|
||||
EditWindow* EditWindow::getInstance(RTWindow* p)
|
||||
{
|
||||
struct EditWindowInstance
|
||||
{
|
||||
EditWindow editWnd;
|
||||
|
||||
if (editWnd == NULL) {
|
||||
static MyMutex smutex_;
|
||||
MyMutex::MyLock lock(smutex_);
|
||||
|
||||
if ( editWnd == 0 ) {
|
||||
editWnd = new EditWindow(p);
|
||||
|
||||
EditWindowInstance(RTWindow* p) : editWnd(p)
|
||||
{
|
||||
// Determine the other display and maximize the window on that
|
||||
const Glib::RefPtr< Gdk::Window >& wnd = p->get_window();
|
||||
int monNo = p->get_screen()->get_monitor_at_window (wnd);
|
||||
|
||||
Gdk::Rectangle lMonitorRect;
|
||||
editWnd->get_screen()->get_monitor_geometry(isMultiDisplayEnabled() ? (monNo == 0 ? 1 : 0) : monNo, lMonitorRect);
|
||||
editWnd->move(lMonitorRect.get_x(), lMonitorRect.get_y());
|
||||
editWnd->maximize();
|
||||
editWnd->show();
|
||||
} else {
|
||||
editWnd->show_all();
|
||||
editWnd.get_screen()->get_monitor_geometry(isMultiDisplayEnabled() ? (monNo == 0 ? 1 : 0) : monNo, lMonitorRect);
|
||||
editWnd.move(lMonitorRect.get_x(), lMonitorRect.get_y());
|
||||
editWnd.maximize();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
return editWnd;
|
||||
static EditWindowInstance instance_(p);
|
||||
instance_.editWnd.show_all();
|
||||
return &instance_.editWnd;
|
||||
}
|
||||
|
||||
EditWindow::EditWindow (RTWindow* p) : parent(p) , isFullscreen(false)
|
||||
|
@@ -74,18 +74,8 @@ bool ExtProgAction::Execute(std::vector<Glib::ustring> fileNames)
|
||||
// Generates as singleton
|
||||
ExtProgStore* ExtProgStore::getInstance()
|
||||
{
|
||||
static ExtProgStore* instance_ = 0;
|
||||
|
||||
if ( instance_ == 0 ) {
|
||||
static MyMutex smutex_;
|
||||
MyMutex::MyLock lock(smutex_);
|
||||
|
||||
if ( instance_ == 0 ) {
|
||||
instance_ = new ExtProgStore();
|
||||
}
|
||||
}
|
||||
|
||||
return instance_;
|
||||
static ExtProgStore instance_;
|
||||
return &instance_;
|
||||
}
|
||||
|
||||
ExtProgStore::~ExtProgStore()
|
||||
|
@@ -168,19 +168,8 @@ PreviewLoader::PreviewLoader():
|
||||
|
||||
PreviewLoader* PreviewLoader::getInstance(void)
|
||||
{
|
||||
// this will not be deleted...
|
||||
static PreviewLoader* instance_ = NULL;
|
||||
|
||||
if ( instance_ == NULL ) {
|
||||
static MyMutex smutex_;
|
||||
MyMutex::MyLock lock(smutex_);
|
||||
|
||||
if ( instance_ == NULL ) {
|
||||
instance_ = new PreviewLoader();
|
||||
}
|
||||
}
|
||||
|
||||
return instance_;
|
||||
static PreviewLoader instance_;
|
||||
return &instance_;
|
||||
}
|
||||
|
||||
void PreviewLoader::add(int dir_id, const Glib::ustring& dir_entry, PreviewLoaderListener* l)
|
||||
|
@@ -192,14 +192,8 @@ public:
|
||||
ThumbImageUpdater*
|
||||
ThumbImageUpdater::getInstance(void)
|
||||
{
|
||||
// this will not be deleted...
|
||||
static ThumbImageUpdater* instance_ = 0;
|
||||
|
||||
if ( instance_ == 0 ) {
|
||||
instance_ = new ThumbImageUpdater();
|
||||
}
|
||||
|
||||
return instance_;
|
||||
static ThumbImageUpdater instance_;
|
||||
return &instance_;
|
||||
}
|
||||
|
||||
ThumbImageUpdater::ThumbImageUpdater():
|
||||
|
Reference in New Issue
Block a user