From ea6ae6ad412b1947534f4d96f84028237c465b83 Mon Sep 17 00:00:00 2001 From: Relintai Date: Sat, 5 Feb 2022 19:20:25 +0100 Subject: [PATCH] Now the RCPPFramework singleton is also able to allocate the settings singleton. --- rcpp_framework.cpp | 34 +++++++++++++++++++++++++++++----- rcpp_framework.h | 5 +++++ 2 files changed, 34 insertions(+), 5 deletions(-) diff --git a/rcpp_framework.cpp b/rcpp_framework.cpp index 9c6c9cf..960ca19 100644 --- a/rcpp_framework.cpp +++ b/rcpp_framework.cpp @@ -2,9 +2,13 @@ #include "core/error_macros.h" +#include "core/settings/settings.h" + #if DATABASES_ENABLED #include "database/database_manager.h" #include "database_backends/db_init.h" + +#include "database_modules/db_settings/db_settings.h" #endif #if WEB_ENABLED @@ -54,11 +58,7 @@ void RCPPFramework::initialize(int argc, char **argv, char **envp) { } void RCPPFramework::setup_args(int argc, char **argv, char **envp) { - // Don't use the error macros here, they might not work before initialization - if (!_initialized) { - printf("ERROR! RCPPFramework::set_args: You have to call initialize() first!\n"); - return; - } + ERR_FAIL_COND(!_initialized); PlatformInitializer::arg_setup(argc, argv, envp); } @@ -68,6 +68,9 @@ void RCPPFramework::uninitialize() { } void RCPPFramework::manage_object(Object *obj) { + ERR_FAIL_COND(!_initialized); + ERR_FAIL_COND(obj); + _managed_objects.push_back(obj); } @@ -76,8 +79,11 @@ RCPPFramework::RCPPFramework() { _initialized = false; + allocate_settings_singleton = true; + #if DATABASES_ENABLED allocate_database_manager_singleton = true; + allocate_db_settings_singleton = true; #endif #if WEB_ENABLED @@ -112,6 +118,24 @@ void RCPPFramework::_do_initialize() { PlatformInitializer::allocate_all(); + if (allocate_settings_singleton) { + + Settings *settings = nullptr; + +#if DATABASES_ENABLED + if (allocate_db_settings_singleton) { + settings = new DBSettings(true); + } else { + settings = new Settings(true); + } +#else + settings = new Settings(true); + +#endif + + manage_object(settings); + } + #if DATABASES_ENABLED if (allocate_database_manager_singleton) { DatabaseManager *dbm = new DatabaseManager(); diff --git a/rcpp_framework.h b/rcpp_framework.h index f353d76..bfa9af3 100644 --- a/rcpp_framework.h +++ b/rcpp_framework.h @@ -31,8 +31,13 @@ public: static RCPPFramework *get_singleton(); + bool allocate_settings_singleton; + #if DATABASES_ENABLED bool allocate_database_manager_singleton; + + // TODO Need a define for this + bool allocate_db_settings_singleton; #endif #if WEB_ENABLED