From 8d5a08e8d054e9504ca31e0bfbfff7a1018c23c0 Mon Sep 17 00:00:00 2001 From: crupest Date: Sat, 10 Nov 2018 15:53:32 +0800 Subject: Refactor predefine resources. Add check for dead recursion in singletons in debug mode. --- src/application.hpp | 47 ++++++++++++++--------------------------------- 1 file changed, 14 insertions(+), 33 deletions(-) (limited to 'src/application.hpp') diff --git a/src/application.hpp b/src/application.hpp index 0c345328..90a43848 100644 --- a/src/application.hpp +++ b/src/application.hpp @@ -10,6 +10,10 @@ #include "base.hpp" #include "any_map.h" +#ifdef CRU_DEBUG +#include +#endif + namespace cru { class Application; @@ -17,26 +21,8 @@ namespace cru namespace ui { class WindowClass; - class WindowManager; - - namespace animations::details - { - class AnimationManager; - } - } - - namespace graph - { - class GraphManager; } - class TimerManager; - - struct CaretInfo - { - std::chrono::milliseconds caret_blink_duration; - float half_caret_width; - }; class GodWindow : public Object { @@ -101,23 +87,19 @@ namespace cru if (find_result != singleton_map_.cend()) return static_cast(find_result->second); +#ifdef CRU_DEBUG + const auto type_find_result = singleton_type_set_.find(index); + if (type_find_result != singleton_type_set_.cend()) + throw std::logic_error("The singleton of that type is being constructed. This may cause a dead recursion."); + singleton_type_set_.insert(index); +#endif + auto singleton = creator(this); singleton_map_.emplace(index, static_cast(singleton)); singleton_list_.push_back(singleton); return singleton; } - - CaretInfo GetCaretInfo() const - { - return caret_info_; - } - - const AnyMap* GetPredefineResourceMap() const - { - return &predefine_resource_map_; - } - private: HINSTANCE h_instance_; @@ -125,10 +107,9 @@ namespace cru std::unordered_map singleton_map_; std::list singleton_list_; // used for reverse destroy. - - CaretInfo caret_info_; - - AnyMap predefine_resource_map_{}; +#ifdef CRU_DEBUG + std::unordered_set singleton_type_set_; // used for dead recursion. +#endif }; -- cgit v1.2.3