Skip to content

Commit

Permalink
Refactor: Unified method for getting a singleton instance
Browse files Browse the repository at this point in the history
The method for getting a singleton instance of a class is now simply
called "get()". This is much cleaner than, say,
"WindowSystem::appWindowSystem()".
  • Loading branch information
skyjake committed Jul 3, 2014
1 parent 0dd5426 commit ebcfab8
Show file tree
Hide file tree
Showing 43 changed files with 79 additions and 76 deletions.
4 changes: 2 additions & 2 deletions doomsday/client/src/clientapp.cpp
Expand Up @@ -186,12 +186,12 @@ DENG2_PIMPL(ClientApp)
{
clientAppSingleton = thisPublic;

LogBuffer::appBuffer().addSink(logAlarm);
LogBuffer::get().addSink(logAlarm);
}

~Instance()
{
LogBuffer::appBuffer().removeSink(logAlarm);
LogBuffer::get().removeSink(logAlarm);

Sys_Shutdown();
DD_Shutdown();
Expand Down
8 changes: 4 additions & 4 deletions doomsday/client/src/dd_main.cpp
Expand Up @@ -336,7 +336,7 @@ static void createPackagesScheme()
filename_t fn;
if(UnixInfo_GetConfigValue("paths", "iwaddir", fn, FILENAME_T_MAXLEN))
{
NativePath path = de::App::app().commandLine().startupPath() / fn;
NativePath path = de::App::commandLine().startupPath() / fn;
scheme.addSearchPath(SearchPath(de::Uri::fromNativeDirPath(path), SearchPath::NoDescend));
LOG_RES_NOTE("Using paths.iwaddir: %s") << path.pretty();
}
Expand Down Expand Up @@ -373,7 +373,7 @@ static void createPackagesScheme()
// Add the path from the DOOMWADDIR environment variable.
if(!CommandLine_Check("-nodoomwaddir") && getenv("DOOMWADDIR"))
{
NativePath path = App::app().commandLine().startupPath() / getenv("DOOMWADDIR");
NativePath path = App::commandLine().startupPath() / getenv("DOOMWADDIR");
scheme.addSearchPath(SearchPath(de::Uri::fromNativeDirPath(path), SearchPath::NoDescend));
LOG_RES_NOTE("Using DOOMWADDIR: %s") << path.pretty();
}
Expand All @@ -390,7 +390,7 @@ static void createPackagesScheme()
QStringList allPaths = QString(getenv("DOOMWADPATH")).split(SEP_CHAR, QString::SkipEmptyParts);
for(int i = allPaths.count(); i--> 0; )
{
NativePath path = App::app().commandLine().startupPath() / allPaths[i];
NativePath path = App::commandLine().startupPath() / allPaths[i];
scheme.addSearchPath(SearchPath(de::Uri::fromNativeDirPath(path), SearchPath::NoDescend));
LOG_RES_NOTE("Using DOOMWADPATH: %s") << path.pretty();
}
Expand Down Expand Up @@ -573,7 +573,7 @@ void App_AbnormalShutdown(char const *message)
/// @todo Get the actual output filename (might be a custom one).
Sys_MessageBoxWithDetailsFromFile(MBT_ERROR, DOOMSDAY_NICENAME, message,
"See Details for complete message log contents.",
de::LogBuffer::appBuffer().outputFile().toUtf8());
de::LogBuffer::get().outputFile().toUtf8());
}

//Sys_Shutdown();
Expand Down
6 changes: 3 additions & 3 deletions doomsday/client/src/network/serverlink.cpp
Expand Up @@ -66,7 +66,7 @@ DENG2_PIMPL(ServerLink)

~Instance()
{
Loop::appLoop().audienceForIteration() -= this;
Loop::get().audienceForIteration() -= this;
}

void notifyDiscoveryUpdate()
Expand Down Expand Up @@ -183,7 +183,7 @@ DENG2_PIMPL(ServerLink)
fetching = true;
N_MAPost(MAC_REQUEST);
N_MAPost(MAC_WAIT);
Loop::appLoop().audienceForIteration() += this;
Loop::get().audienceForIteration() += this;
}

void loopIteration()
Expand All @@ -193,7 +193,7 @@ DENG2_PIMPL(ServerLink)
if(N_MADone())
{
fetching = false;
Loop::appLoop().audienceForIteration() -= this;
Loop::get().audienceForIteration() -= this;

fromMaster.clear();
int const count = N_MasterGet(0, 0);
Expand Down
4 changes: 2 additions & 2 deletions doomsday/client/src/resource/resourcesystem.cpp
Expand Up @@ -2268,7 +2268,7 @@ DENG2_PIMPL(ResourceSystem)
if(convertSavegameTasks.isDone())
{
LOG_AS("ResourceSystem");
Loop::appLoop().audienceForIteration() -= this;
Loop::get().audienceForIteration() -= this;
try
{
// The newly converted savegame(s) should now be somewhere in /home/savegames
Expand All @@ -2283,7 +2283,7 @@ DENG2_PIMPL(ResourceSystem)
{
LOG_AS("ResourceSystem");
LOG_TRACE("Scheduling legacy savegame conversion for %s (gameId:%s)") << sourcePath << gameId;
Loop::appLoop().audienceForIteration() += this;
Loop::get().audienceForIteration() += this;
convertSavegameTasks.start(new ConvertSavegameTask(sourcePath, gameId));
}

Expand Down
2 changes: 1 addition & 1 deletion doomsday/client/src/sys_system.cpp
Expand Up @@ -141,7 +141,7 @@ void Sys_Shutdown(void)
static int showCriticalMessage(const char* msg)
{
// This is going to be the end, I'm afraid.
de::Loop::appLoop().stop();
de::Loop::get().stop();

Sys_MessageBox(MBT_WARNING, DOOMSDAY_NICENAME, msg, 0);
return 0;
Expand Down
6 changes: 3 additions & 3 deletions doomsday/client/src/ui/widgets/savedsessionmenuwidget.cpp
Expand Up @@ -154,7 +154,7 @@ DENG_GUI_PIMPL(SavedSessionMenuWidget)

~Instance()
{
Loop::appLoop().audienceForIteration() -= this;
Loop::get().audienceForIteration() -= this;
App::app().audienceForStartupComplete() -= this;
game::Session::savedIndex().audienceForAvailabilityUpdate() -= this;
}
Expand Down Expand Up @@ -223,12 +223,12 @@ DENG_GUI_PIMPL(SavedSessionMenuWidget)

void deferUpdate()
{
Loop::appLoop().audienceForIteration() += this;
Loop::get().audienceForIteration() += this;
}

void loopIteration()
{
Loop::appLoop().audienceForIteration() -= this;
Loop::get().audienceForIteration() -= this;
updateItemsFromSavedIndex();
}
};
Expand Down
Expand Up @@ -78,7 +78,7 @@ DENG_GUI_PIMPL(SingleplayerSessionMenuWidget)

~Instance()
{
Loop::appLoop().audienceForIteration() -= this;
Loop::get().audienceForIteration() -= this;

App_Games().audienceForAddition() -= this;
App::app().audienceForGameChange() -= this;
Expand All @@ -91,7 +91,7 @@ DENG_GUI_PIMPL(SingleplayerSessionMenuWidget)
pendingGames.put(&game);

// Update from main thread later.
Loop::appLoop().audienceForIteration() += this;
Loop::get().audienceForIteration() += this;
}

void addExistingGames()
Expand All @@ -111,7 +111,7 @@ DENG_GUI_PIMPL(SingleplayerSessionMenuWidget)

void loopIteration()
{
Loop::appLoop().audienceForIteration() -= this;
Loop::get().audienceForIteration() -= this;
addPendingGames();
updateGameAvailability();
}
Expand Down Expand Up @@ -180,7 +180,7 @@ DENG_GUI_PIMPL(SingleplayerSessionMenuWidget)

void currentGameChanged(game::Game const &)
{
Loop::appLoop().audienceForIteration() += this;
Loop::get().audienceForIteration() += this;
}
};

Expand Down
2 changes: 1 addition & 1 deletion doomsday/libappfw/include/de/framework/style.h
Expand Up @@ -74,7 +74,7 @@ class LIBAPPFW_PUBLIC Style
* Returns the current global application UI style.
* @return
*/
static Style &appStyle();
static Style &get();

/**
* Sets the current global application UI style.
Expand Down
2 changes: 1 addition & 1 deletion doomsday/libappfw/include/de/framework/windowsystem.h
Expand Up @@ -119,7 +119,7 @@ class LIBAPPFW_PUBLIC WindowSystem : public System

public:
static void setAppWindowSystem(WindowSystem &winSys);
static WindowSystem &appWindowSystem();
static WindowSystem &get();

protected:
virtual void closingAllWindows();
Expand Down
4 changes: 2 additions & 2 deletions doomsday/libappfw/src/basewindow.cpp
Expand Up @@ -53,7 +53,7 @@ DENG2_PIMPL(BaseWindow)
/// subsystem passes it to window system. -jk

// Pass the event onto the window system.
if(!WindowSystem::appWindowSystem().processEvent(ev))
if(!WindowSystem::get().processEvent(ev))
{
// Maybe the fallback handler has use for this.
self.handleFallbackEvent(ev);
Expand All @@ -72,7 +72,7 @@ DENG2_PIMPL(BaseWindow)
ev.setPos(xf->windowToLogicalCoords(event.pos()).toVector2i());
}

if(!WindowSystem::appWindowSystem().processEvent(ev))
if(!WindowSystem::get().processEvent(ev))
{
// Maybe the fallback handler has use for this.
self.handleFallbackEvent(ev);
Expand Down
4 changes: 2 additions & 2 deletions doomsday/libappfw/src/guirootwidget.cpp
Expand Up @@ -89,7 +89,7 @@ DENG2_PIMPL(GuiRootWidget)
struct StyleImage : public TextureBank::ImageSource {
StyleImage(DotPath const &id) : ImageSource(id) {}
Image load() const {
return Style::appStyle().images().image(id());
return Style::get().images().image(id());
}
};

Expand Down Expand Up @@ -146,7 +146,7 @@ DENG2_PIMPL(GuiRootWidget)
texBank.add(ID_DOT, new TinyDotImage);

// All style images.
Style const &st = Style::appStyle();
Style const &st = Style::get();
ImageBank::Names imageNames;
st.images().allItems(imageNames);
foreach(String const &name, imageNames)
Expand Down
2 changes: 1 addition & 1 deletion doomsday/libappfw/src/guiwidget.cpp
Expand Up @@ -387,7 +387,7 @@ Widget *GuiWidget::parentWidget() const

Style const &GuiWidget::style() const
{
return Style::appStyle();
return Style::get();
}

Font const &GuiWidget::font() const
Expand Down
2 changes: 1 addition & 1 deletion doomsday/libappfw/src/margins.cpp
Expand Up @@ -72,7 +72,7 @@ DENG2_PIMPL(Margins)

void setInput(int side, DotPath const &styleId)
{
setInput(side, Style::appStyle().rules().rule(styleId));
setInput(side, Style::get().rules().rule(styleId));
}

void setInput(int side, Rule const &rule)
Expand Down
2 changes: 1 addition & 1 deletion doomsday/libappfw/src/style.cpp
Expand Up @@ -202,7 +202,7 @@ bool Style::isBlurringAllowed() const

static Style *theAppStyle = 0;

Style &Style::appStyle()
Style &Style::get()
{
DENG2_ASSERT(theAppStyle != 0);
return *theAppStyle;
Expand Down
2 changes: 1 addition & 1 deletion doomsday/libappfw/src/widgets/dialogwidget.cpp
Expand Up @@ -393,7 +393,7 @@ public ChildWidgetOrganizer::IFilter
{
bg = self.infoStyleBackground();
}
else if(Style::appStyle().isBlurringAllowed())
else if(Style::get().isBlurringAllowed())
{
/// @todo Should use the Style for this.
bg.type = Background::BlurredWithBorderGlow;
Expand Down
4 changes: 2 additions & 2 deletions doomsday/libappfw/src/widgets/logwidget.cpp
Expand Up @@ -360,7 +360,7 @@ public Font::RichFormat::IStyle

~Instance()
{
LogBuffer::appBuffer().removeSink(sink);
LogBuffer::get().removeSink(sink);
}

void clear()
Expand Down Expand Up @@ -781,7 +781,7 @@ LogWidget::LogWidget(String const &name)
{
setOrigin(Bottom);

LogBuffer::appBuffer().addSink(d->sink);
LogBuffer::get().addSink(d->sink);
}

void LogWidget::setLogFormatter(LogSink::IFormatter &formatter)
Expand Down
6 changes: 3 additions & 3 deletions doomsday/libappfw/src/windowsystem.cpp
Expand Up @@ -84,13 +84,13 @@ void WindowSystem::addWindow(String const &id, BaseWindow *window)

bool WindowSystem::mainExists() // static
{
return appWindowSystem().d->windows.contains("main");
return get().d->windows.contains("main");
}

BaseWindow &WindowSystem::main() // static
{
DENG2_ASSERT(mainExists());
return **appWindowSystem().d->windows.find("main");
return **get().d->windows.find("main");
}

BaseWindow *WindowSystem::find(String const &id) const
Expand Down Expand Up @@ -170,7 +170,7 @@ void WindowSystem::setAppWindowSystem(WindowSystem &winSys)
theAppWindowSystem = &winSys;
}

WindowSystem &WindowSystem::appWindowSystem() // static
WindowSystem &WindowSystem::get() // static
{
DENG2_ASSERT(theAppWindowSystem != 0);
return *theAppWindowSystem;
Expand Down
2 changes: 1 addition & 1 deletion doomsday/libcore/include/de/core/clock.h
Expand Up @@ -69,7 +69,7 @@ class DENG2_PUBLIC Clock

public:
static void setAppClock(Clock *c);
static Clock &appClock();
static Clock &get();
static Time const &appTime();

private:
Expand Down
4 changes: 2 additions & 2 deletions doomsday/libcore/include/de/core/logbuffer.h
Expand Up @@ -205,10 +205,10 @@ class DENG2_PUBLIC LogBuffer : public QObject, public Lockable, DENG2_OBSERVES(F
*/
static void setAppBuffer(LogBuffer &appBuffer);

static LogBuffer &appBuffer();

static bool appBufferExists();

static LogBuffer &get();

public slots:
/**
* Flushes all unflushed entries to the defined outputs.
Expand Down
2 changes: 1 addition & 1 deletion doomsday/libcore/include/de/core/loop.h
Expand Up @@ -79,7 +79,7 @@ class DENG2_PUBLIC Loop : public QObject
*/
static void timer(TimeDelta const &delay, void (*func)(void));

static Loop &appLoop();
static Loop &get();

public slots:
void nextLoopIteration();
Expand Down
5 changes: 4 additions & 1 deletion doomsday/libcore/include/de/scriptsys/scriptsystem.h
Expand Up @@ -92,9 +92,12 @@ class DENG2_PUBLIC ScriptSystem : public System
*/
File const &findModuleSource(String const &name, String const &localPath = "");

void timeChanged(Clock const &);

public:
static Record &builtInClass(String const &name);

void timeChanged(Clock const &);
static ScriptSystem &get();

private:
DENG2_PRIVATE(d)
Expand Down
8 changes: 4 additions & 4 deletions doomsday/libcore/src/c_wrapper.cpp
Expand Up @@ -50,7 +50,7 @@ static bool checkLogEntryMetadata(unsigned int &metadata)
}

// If this level is not enabled, just ignore.
return de::LogBuffer::appBuffer().isEnabled(metadata);
return de::LogBuffer::get().isEnabled(metadata);
}

static void logFragmentPrinter(duint32 metadata, char const *fragment)
Expand Down Expand Up @@ -183,18 +183,18 @@ void LogBuffer_Flush(void)
{
if(de::LogBuffer::appBufferExists())
{
de::LogBuffer::appBuffer().flush();
de::LogBuffer::get().flush();
}
}

void LogBuffer_Clear(void)
{
de::LogBuffer::appBuffer().clear();
de::LogBuffer::get().clear();
}

void LogBuffer_EnableStandardOutput(int enable)
{
de::LogBuffer::appBuffer().enableStandardOutput(enable != 0);
de::LogBuffer::get().enableStandardOutput(enable != 0);
}

void LogBuffer_Printf(unsigned int metadata, char const *format, ...)
Expand Down
2 changes: 1 addition & 1 deletion doomsday/libcore/src/core/app.cpp
Expand Up @@ -575,7 +575,7 @@ void App::initSubsystems(SubsystemInitFlags flags)
}

// Set up the log buffer.
LogBuffer &logBuf = LogBuffer::appBuffer();
LogBuffer &logBuf = LogBuffer::get();

// Update the log buffer max entry count: number of items to hold in memory.
logBuf.setMaxEntryCount(d->config->getui("log.bufferSize", 1000));
Expand Down

0 comments on commit ebcfab8

Please sign in to comment.