Added a new UserInitializer helper class.

This commit is contained in:
Relintai 2021-11-10 15:16:44 +01:00
parent adf8475804
commit 60e22942e4
2 changed files with 60 additions and 0 deletions

View File

@ -0,0 +1,37 @@
#include "user_initializer.h"
void UserInitializer::allocate_controller() {
ERR_FAIL_COND(_controller);
_controller = new UserController();
}
void UserInitializer::free_controller() {
if (_controller) {
delete _controller;
_controller = nullptr;
}
}
void UserInitializer::allocate_model() {
ERR_FAIL_COND(_model);
_model = new UserModel();
}
void UserInitializer::free_model() {
if (_model) {
delete _model;
_model = nullptr;
}
}
void UserInitializer::allocate_all() {
allocate_model();
allocate_controller();
}
void UserInitializer::free_all() {
free_controller();
free_model();
}
UserController *UserInitializer::_controller = nullptr;
UserModel *UserInitializer::_model = nullptr;

View File

@ -0,0 +1,23 @@
#ifndef USER_INITIALIZER_H
#define USER_INITIALIZER_H
#include "user_model.h"
#include "user_controller.h"
class UserInitializer {
public:
static void allocate_controller();
static void free_controller();
static void allocate_model();
static void free_model();
static void allocate_all();
static void free_all();
protected:
static UserController *_controller;
static UserModel *_model;
};
#endif