From 9ef75fe91837394620edb91f332065a4f34a0281 Mon Sep 17 00:00:00 2001 From: crupest Date: Fri, 9 Nov 2018 20:57:29 +0800 Subject: Add singleton system. --- src/graph/graph.cpp | 5 ++++- src/graph/graph.hpp | 15 ++++++++------- 2 files changed, 12 insertions(+), 8 deletions(-) (limited to 'src/graph') diff --git a/src/graph/graph.cpp b/src/graph/graph.cpp index febb7fee..d37b5e2d 100644 --- a/src/graph/graph.cpp +++ b/src/graph/graph.cpp @@ -116,7 +116,10 @@ namespace cru::graph GraphManager* GraphManager::GetInstance() { - return Application::GetInstance()->GetGraphManager(); + return Application::GetInstance()->ResolveSingleton([](auto) + { + return new GraphManager{}; + }); } GraphManager::GraphManager() diff --git a/src/graph/graph.hpp b/src/graph/graph.hpp index 9ef2e4b8..b98db5f4 100644 --- a/src/graph/graph.hpp +++ b/src/graph/graph.hpp @@ -2,9 +2,9 @@ #include "system_headers.hpp" #include +#include #include "base.hpp" -#include "application.hpp" namespace cru::graph @@ -62,13 +62,14 @@ namespace cru::graph float y; }; - class GraphManager : public Object + class GraphManager final : public Object { public: static GraphManager* GetInstance(); - public: + private: GraphManager(); + public: GraphManager(const GraphManager& other) = delete; GraphManager(GraphManager&& other) = delete; GraphManager& operator=(const GraphManager& other) = delete; @@ -135,12 +136,12 @@ namespace cru::graph inline int DipToPixelX(const float dip_x) { - return DipToPixelInternal(dip_x, Application::GetInstance()->GetGraphManager()->GetDpi().x); + return DipToPixelInternal(dip_x, GraphManager::GetInstance()->GetDpi().x); } inline int DipToPixelY(const float dip_y) { - return DipToPixelInternal(dip_y, Application::GetInstance()->GetGraphManager()->GetDpi().y); + return DipToPixelInternal(dip_y, GraphManager::GetInstance()->GetDpi().y); } inline float DipToPixelInternal(const int pixel, const float dpi) @@ -150,12 +151,12 @@ namespace cru::graph inline float PixelToDipX(const int pixel_x) { - return DipToPixelInternal(pixel_x, Application::GetInstance()->GetGraphManager()->GetDpi().x); + return DipToPixelInternal(pixel_x, GraphManager::GetInstance()->GetDpi().x); } inline float PixelToDipY(const int pixel_y) { - return DipToPixelInternal(pixel_y, Application::GetInstance()->GetGraphManager()->GetDpi().y); + return DipToPixelInternal(pixel_y, GraphManager::GetInstance()->GetDpi().y); } Microsoft::WRL::ComPtr WindowRenderTarget::GetD2DDeviceContext() const -- cgit v1.2.3