mirror of
https://github.com/Relintai/rcpp_framework.git
synced 2024-11-14 04:57:21 +01:00
Rework the RCPPFramework class to be a bit more user friendly.
This commit is contained in:
parent
3757114a21
commit
b833a3ee3a
@ -11,32 +11,49 @@
|
|||||||
// Backends
|
// Backends
|
||||||
#include "crypto_backends/hash_hashlib/setup.h"
|
#include "crypto_backends/hash_hashlib/setup.h"
|
||||||
|
|
||||||
void RCPPFramework::initialize() {
|
void RCPPFramework::create() {
|
||||||
if (get_singleton() != nullptr) {
|
|
||||||
RLOG_ERR("RCPPFramework: has already beed initialized!");
|
|
||||||
}
|
|
||||||
|
|
||||||
new RCPPFramework();
|
new RCPPFramework();
|
||||||
|
}
|
||||||
#if DATABASES_ENABLED
|
void RCPPFramework::destroy() {
|
||||||
initialize_database_backends();
|
delete _instance;
|
||||||
#endif
|
|
||||||
|
|
||||||
backend_hash_hashlib_install_providers();
|
|
||||||
|
|
||||||
PlatformInitializer::allocate_all();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void RCPPFramework::initialize(int argc, char **argv, char **envp) {
|
void RCPPFramework::create_and_init() {
|
||||||
initialize();
|
new RCPPFramework();
|
||||||
|
|
||||||
|
RCPPFramework::get_singleton()->initialize();
|
||||||
|
}
|
||||||
|
|
||||||
|
void RCPPFramework::create_and_init(int argc, char **argv, char **envp) {
|
||||||
|
new RCPPFramework();
|
||||||
|
|
||||||
|
RCPPFramework::get_singleton()->initialize();
|
||||||
|
RCPPFramework::get_singleton()->setup_args(argc, argv, envp);
|
||||||
|
}
|
||||||
|
|
||||||
|
void RCPPFramework::initialize() {
|
||||||
|
if (_initialized) {
|
||||||
|
RLOG_ERR("RCPPFramework: has already beed initialized!");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
_initialized = true;
|
||||||
|
|
||||||
|
_do_initialize();
|
||||||
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
PlatformInitializer::arg_setup(argc, argv, envp);
|
PlatformInitializer::arg_setup(argc, argv, envp);
|
||||||
}
|
}
|
||||||
|
|
||||||
void RCPPFramework::uninitialize() {
|
void RCPPFramework::uninitialize() {
|
||||||
delete _instance;
|
delete _instance;
|
||||||
|
|
||||||
PlatformInitializer::free_all();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void RCPPFramework::manage_object(Object *obj) {
|
void RCPPFramework::manage_object(Object *obj) {
|
||||||
@ -45,10 +62,12 @@ void RCPPFramework::manage_object(Object *obj) {
|
|||||||
|
|
||||||
RCPPFramework::RCPPFramework() {
|
RCPPFramework::RCPPFramework() {
|
||||||
_instance = this;
|
_instance = this;
|
||||||
|
|
||||||
|
_initialized = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
RCPPFramework::~RCPPFramework() {
|
RCPPFramework::~RCPPFramework() {
|
||||||
//delete in reverse order added
|
// delete in reverse order added
|
||||||
for (int i = _managed_objects.size() - 1; i >= 0; --i) {
|
for (int i = _managed_objects.size() - 1; i >= 0; --i) {
|
||||||
delete _managed_objects[i];
|
delete _managed_objects[i];
|
||||||
}
|
}
|
||||||
@ -63,3 +82,17 @@ RCPPFramework *RCPPFramework::get_singleton() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
RCPPFramework *RCPPFramework::_instance = nullptr;
|
RCPPFramework *RCPPFramework::_instance = nullptr;
|
||||||
|
|
||||||
|
void RCPPFramework::_do_initialize() {
|
||||||
|
#if DATABASES_ENABLED
|
||||||
|
initialize_database_backends();
|
||||||
|
#endif
|
||||||
|
|
||||||
|
backend_hash_hashlib_install_providers();
|
||||||
|
|
||||||
|
PlatformInitializer::allocate_all();
|
||||||
|
}
|
||||||
|
|
||||||
|
void RCPPFramework::_do_uninitialize() {
|
||||||
|
PlatformInitializer::free_all();
|
||||||
|
}
|
@ -10,9 +10,18 @@ class RCPPFramework : Object {
|
|||||||
RCPP_OBJECT(RCPPFramework, Object);
|
RCPP_OBJECT(RCPPFramework, Object);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
static void initialize();
|
// Helper methods to allocate and destroy the singleton.
|
||||||
static void initialize(int argc, char **argv, char **envp);
|
// Note that creating / deleting an instance manually in your app will also work.
|
||||||
static void uninitialize();
|
static void create();
|
||||||
|
static void destroy();
|
||||||
|
//Usie these if you don't want to mess with the default settings.
|
||||||
|
static void create_and_init();
|
||||||
|
static void create_and_init(int argc, char **argv, char **envp);
|
||||||
|
|
||||||
|
void initialize();
|
||||||
|
void uninitialize();
|
||||||
|
|
||||||
|
void setup_args(int argc, char **argv, char **envp);
|
||||||
|
|
||||||
void manage_object(Object* obj);
|
void manage_object(Object* obj);
|
||||||
|
|
||||||
@ -22,6 +31,11 @@ public:
|
|||||||
static RCPPFramework *get_singleton();
|
static RCPPFramework *get_singleton();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
virtual void _do_initialize();
|
||||||
|
virtual void _do_uninitialize();
|
||||||
|
|
||||||
|
bool _initialized;
|
||||||
|
|
||||||
Vector<Object *> _managed_objects;
|
Vector<Object *> _managed_objects;
|
||||||
|
|
||||||
static RCPPFramework *_instance;
|
static RCPPFramework *_instance;
|
||||||
|
Loading…
Reference in New Issue
Block a user