Create factory allocator
This commit is contained in:
parent
af0d9b895c
commit
cea3710c76
1
.gitignore
vendored
1
.gitignore
vendored
@ -1 +1,2 @@
|
||||
link/
|
||||
.vscode/
|
||||
|
5
command/linux/archive.sh
Executable file
5
command/linux/archive.sh
Executable file
@ -0,0 +1,5 @@
|
||||
F_ROOT=$(readlink -f "$0")
|
||||
D_ROOT=$(dirname "${F_ROOT}")/../../.
|
||||
F_ARCHIVE=/tmp/cpp_launchpad.tar
|
||||
cd ${D_ROOT}
|
||||
git archive --format=tar -o ${F_ARCHIVE} HEAD && echo "Saved archive to ${F_ARCHIVE}"
|
@ -1,10 +1,19 @@
|
||||
#include "controller/root.h"
|
||||
#include "service/window.h"
|
||||
#include "act/root.h"
|
||||
#include "draw/window.h"
|
||||
#include <stdlib.h>
|
||||
root_controller_t::configuration_t::configuration_t(std::vector<root_controller_t::mode_t> modes_p) {
|
||||
modes_m = modes_p;
|
||||
}
|
||||
root_controller_t::root_controller_t(root_controller_t::configuration_t configuration_p) {
|
||||
configuration_m = configuration_p;
|
||||
}
|
||||
root_controller_t root_controller_factory_t::create(root_controller_t::configuration_t configuration_p) {
|
||||
return new root_controller_t(configuration_p);
|
||||
root_controller_t* root_controller_factory_t::create(root_controller_t::configuration_t configuration_p) {
|
||||
void* ptr = malloc(sizeof(root_controller_t));
|
||||
return static_cast<root_controller_t*>(ptr);
|
||||
}
|
||||
factory_t::status_t root_controller_factory_t::dispose(root_controller_t* root_controller_p) {
|
||||
free(root_controller_p);
|
||||
return factory_t::status_t::ok;
|
||||
}
|
||||
controller_t::status_t root_controller_t::on_event(controller_t::event_t event_p) {
|
||||
if (
|
||||
|
@ -1,22 +1,30 @@
|
||||
#ifndef ACT_ROOT
|
||||
#define ACT_ROOT
|
||||
#include "controller/controller.h"
|
||||
#include "act/controller.h"
|
||||
#include "allocate/factory.h"
|
||||
#include <vector>
|
||||
class root_controller_t : public controller_t {
|
||||
public:
|
||||
enum mode_t {
|
||||
cli,
|
||||
app,
|
||||
game
|
||||
};
|
||||
class configuration_t {
|
||||
private:
|
||||
mode_t mode_m;
|
||||
std::vector<mode_t> modes_m;
|
||||
public:
|
||||
configuration_t(mode_t mode_p);
|
||||
configuration_t(std::vector<mode_t> modes_p);
|
||||
};
|
||||
controller_t::status_t on_event(event_t event_p) override;
|
||||
private:
|
||||
configuration_t configuration_m;
|
||||
root_controller_t(configuration_t configuration_p);
|
||||
friend class root_controller_factory_t;
|
||||
};
|
||||
class root_controller_factory_t : public factory_t<root_controller_t::configuration_t, root_controller_t> {
|
||||
public:
|
||||
root_controller_t create(root_controller_t::configuration_t configuration_p) override;
|
||||
root_controller_t* create(root_controller_t::configuration_t* configuration_p) override;
|
||||
factory_t::status_t dispose(root_controller_t* root_controller_p) override;
|
||||
};
|
||||
#endif
|
||||
|
@ -1,6 +1,13 @@
|
||||
#ifndef ALLOCATE_FACTORY
|
||||
#define ALLOCATE_FACTORY
|
||||
template <class I, class O> class factory_t {
|
||||
virtual O* create(I*) = 0;
|
||||
public:
|
||||
enum status_t {
|
||||
ok,
|
||||
error
|
||||
};
|
||||
private:
|
||||
virtual O* create(I* i) = 0;
|
||||
virtual status_t dispose(O* o) = 0;
|
||||
};
|
||||
#endif
|
||||
|
@ -1,8 +1,13 @@
|
||||
#include "controller/controller.h"
|
||||
#include "controller/root.h"
|
||||
#include "act/controller.h"
|
||||
#include "act/root.h"
|
||||
#include <vector>
|
||||
int main(int argc, char *argv[]) {
|
||||
controller_t* controller = new root_controller_t();
|
||||
controller_t::status_t status = controller->on_event(controller_t::event_t::start);
|
||||
delete controller;
|
||||
return status;
|
||||
root_controller_factory_t factory_l;
|
||||
std::vector<root_controller_t::mode_t> modes_l;
|
||||
modes_l.push_back(root_controller_t::mode_t::app);
|
||||
root_controller_t::configuration_t configuration_l(modes_l);
|
||||
root_controller_t* controller_l = factory_l.create(&configuration_l);
|
||||
controller_t::status_t status_l = controller_l->on_event(controller_t::event_t::start);
|
||||
factory_l.dispose(controller_l);
|
||||
return status_l;
|
||||
}
|
||||
|
@ -1,3 +1,3 @@
|
||||
main.cpp
|
||||
controller/root.cpp
|
||||
platform/linux/service/window.cpp
|
||||
act/root.cpp
|
||||
platform/linux/draw/window.cpp
|
||||
|
@ -1,4 +1,4 @@
|
||||
#include "service/window.h"
|
||||
#include "draw/window.h"
|
||||
#include <X11/Xlib.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
Loading…
Reference in New Issue
Block a user