mirror of
https://github.com/Relintai/rcpp_framework.git
synced 2024-11-10 00:52:11 +01:00
Added a new Platform class.
This commit is contained in:
parent
d637c2132c
commit
0bca7735e1
22
core/os/platform.cpp
Normal file
22
core/os/platform.cpp
Normal file
@ -0,0 +1,22 @@
|
||||
#include "platform.h"
|
||||
|
||||
#include "core/error_macros.h"
|
||||
|
||||
void Platform::arg_setup(int argc, char **argv, char **envp) {
|
||||
arg_parser.setup(argc, argv, envp);
|
||||
}
|
||||
|
||||
Platform *Platform::get_singleton() {
|
||||
return _self;
|
||||
}
|
||||
|
||||
Platform::Platform() {
|
||||
_self = this;
|
||||
}
|
||||
Platform::~Platform() {
|
||||
if (_self == this) {
|
||||
_self = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
Platform *Platform::_self = nullptr;
|
21
core/os/platform.h
Normal file
21
core/os/platform.h
Normal file
@ -0,0 +1,21 @@
|
||||
#ifndef PLATFORM_H
|
||||
#define PLATFORM_H
|
||||
|
||||
#include "arg_parser.h"
|
||||
|
||||
class Platform {
|
||||
public:
|
||||
virtual void arg_setup(int argc, char **argv, char **envp);
|
||||
|
||||
static Platform *get_singleton();
|
||||
|
||||
Platform();
|
||||
virtual ~Platform();
|
||||
|
||||
ArgParser arg_parser;
|
||||
|
||||
protected:
|
||||
static Platform *_self;
|
||||
};
|
||||
|
||||
#endif
|
8
platform/linux/platform_linux.cpp
Normal file
8
platform/linux/platform_linux.cpp
Normal file
@ -0,0 +1,8 @@
|
||||
#include "platform_linux.h"
|
||||
|
||||
#include "core/error_macros.h"
|
||||
|
||||
PlatformLinux::PlatformLinux() : Platform() {
|
||||
}
|
||||
PlatformLinux::~PlatformLinux() {
|
||||
}
|
14
platform/linux/platform_linux.h
Normal file
14
platform/linux/platform_linux.h
Normal file
@ -0,0 +1,14 @@
|
||||
#ifndef PLATFORM_LINUX_H
|
||||
#define PLATFORM_LINUX_H
|
||||
|
||||
#include "core/os/platform.h"
|
||||
|
||||
class PlatformLinux : public Platform {
|
||||
public:
|
||||
PlatformLinux();
|
||||
virtual ~PlatformLinux();
|
||||
|
||||
protected:
|
||||
};
|
||||
|
||||
#endif
|
@ -4,8 +4,24 @@
|
||||
|
||||
#if PLATFORM_LINUX
|
||||
#include "linux/crash_handler_linux.h"
|
||||
#include "linux/platform_linux.h"
|
||||
#endif
|
||||
|
||||
void PlatformInitializer::allocate_platform() {
|
||||
ERR_FAIL_COND(_platform);
|
||||
|
||||
#if PLATFORM_LINUX
|
||||
_platform = new PlatformLinux();
|
||||
#endif
|
||||
}
|
||||
|
||||
void PlatformInitializer::free_platform() {
|
||||
if (_platform) {
|
||||
delete _platform;
|
||||
_platform = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
void PlatformInitializer::allocate_crash_handler() {
|
||||
ERR_FAIL_COND(_crash_handler);
|
||||
|
||||
@ -23,11 +39,14 @@ void PlatformInitializer::free_crash_handler() {
|
||||
}
|
||||
|
||||
void PlatformInitializer::allocate_all() {
|
||||
allocate_platform();
|
||||
allocate_crash_handler();
|
||||
}
|
||||
|
||||
void PlatformInitializer::free_all() {
|
||||
free_platform();
|
||||
free_crash_handler();
|
||||
}
|
||||
|
||||
CrashHandler *PlatformInitializer::_crash_handler = nullptr;
|
||||
Platform *PlatformInitializer::_platform = nullptr;
|
||||
CrashHandler *PlatformInitializer::_crash_handler = nullptr;
|
||||
|
@ -1,11 +1,15 @@
|
||||
#ifndef PLATFORM_INITIALIZER_H
|
||||
#define PLATFORM_INITIALIZER_H
|
||||
|
||||
#include "core/os/platform.h"
|
||||
#include "core/os/crash_handler.h"
|
||||
|
||||
|
||||
class PlatformInitializer {
|
||||
public:
|
||||
public:
|
||||
static void allocate_platform();
|
||||
static void free_platform();
|
||||
|
||||
static void allocate_crash_handler();
|
||||
static void free_crash_handler();
|
||||
|
||||
@ -14,6 +18,7 @@ public:
|
||||
|
||||
protected:
|
||||
static CrashHandler *_crash_handler;
|
||||
static Platform *_platform;
|
||||
};
|
||||
|
||||
#endif
|
Loading…
Reference in New Issue
Block a user