Multiplatform design patterns rev 1
This commit is contained in:
parent
41b22dd9a7
commit
af0d9b895c
1
.gitignore
vendored
1
.gitignore
vendored
@ -0,0 +1 @@
|
||||
link/
|
15
compile/act/controller.h
Normal file
15
compile/act/controller.h
Normal file
@ -0,0 +1,15 @@
|
||||
#ifndef ACT_CONTROLLER
|
||||
#define ACT_CONTROLLER
|
||||
class controller_t {
|
||||
public:
|
||||
enum event_t {
|
||||
start,
|
||||
stop
|
||||
};
|
||||
enum status_t {
|
||||
ok,
|
||||
error
|
||||
};
|
||||
virtual status_t on_event(event_t event_p) = 0;
|
||||
};
|
||||
#endif
|
24
compile/act/root.cpp
Normal file
24
compile/act/root.cpp
Normal file
@ -0,0 +1,24 @@
|
||||
#include "controller/root.h"
|
||||
#include "service/window.h"
|
||||
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);
|
||||
}
|
||||
controller_t::status_t root_controller_t::on_event(controller_t::event_t event_p) {
|
||||
if (
|
||||
window_service_t* window_service = new window_service_t();
|
||||
window_service_t::status_t window_status = window_service->create_window();
|
||||
controller_t::status_t controller_status;
|
||||
switch (window_status) {
|
||||
case window_service_t::status_t::ok:
|
||||
controller_status = controller_t::status_t::ok;
|
||||
break;
|
||||
case window_service_t::status_t::error:
|
||||
default:
|
||||
controller_status = controller_t::status_t::error;
|
||||
break;
|
||||
}
|
||||
return controller_status;
|
||||
}
|
22
compile/act/root.h
Normal file
22
compile/act/root.h
Normal file
@ -0,0 +1,22 @@
|
||||
#ifndef ACT_ROOT
|
||||
#define ACT_ROOT
|
||||
#include "controller/controller.h"
|
||||
#include "allocate/factory.h"
|
||||
class root_controller_t : public controller_t {
|
||||
public:
|
||||
class configuration_t {
|
||||
private:
|
||||
mode_t mode_m;
|
||||
public:
|
||||
configuration_t(mode_t mode_p);
|
||||
};
|
||||
controller_t::status_t on_event(event_t event_p) override;
|
||||
private:
|
||||
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;
|
||||
};
|
||||
#endif
|
6
compile/allocate/factory.h
Normal file
6
compile/allocate/factory.h
Normal file
@ -0,0 +1,6 @@
|
||||
#ifndef ALLOCATE_FACTORY
|
||||
#define ALLOCATE_FACTORY
|
||||
template <class I, class O> class factory_t {
|
||||
virtual O* create(I*) = 0;
|
||||
};
|
||||
#endif
|
@ -1,7 +0,0 @@
|
||||
#ifndef CONTROLLER_EVENT
|
||||
#define CONTROLLER_EVENT
|
||||
enum controller_event_t {
|
||||
start,
|
||||
stop
|
||||
};
|
||||
#endif
|
@ -1,11 +0,0 @@
|
||||
#ifndef CONTROLLER_ROOT
|
||||
#define CONTROLLER_ROOT
|
||||
#include "controller/status.h"
|
||||
#include "controller/event.h"
|
||||
|
||||
class root_controller_t {
|
||||
public:
|
||||
|
||||
controller_status_t on_event(controller_event_t event);
|
||||
};
|
||||
#endif
|
@ -1,7 +0,0 @@
|
||||
#ifndef CONTROLLER_STATUS
|
||||
#define CONTROLLER_STATUS
|
||||
enum controller_status_t {
|
||||
ok,
|
||||
error
|
||||
};
|
||||
#endif
|
11
compile/draw/window.h
Normal file
11
compile/draw/window.h
Normal file
@ -0,0 +1,11 @@
|
||||
#ifndef SERVICE_WINDOW
|
||||
#define SERVICE_WINDOW
|
||||
class window_service_t {
|
||||
public:
|
||||
enum status_t {
|
||||
ok,
|
||||
error
|
||||
};
|
||||
status_t create_window();
|
||||
};
|
||||
#endif
|
@ -1,8 +1,8 @@
|
||||
#include "controller/controller.h"
|
||||
#include "controller/root.h"
|
||||
#include "controller/status.h"
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
root_controller_t* controller = new root_controller_t();
|
||||
controller_status_t status = controller->on_event(controller_event_t::start);
|
||||
controller_t* controller = new root_controller_t();
|
||||
controller_t::status_t status = controller->on_event(controller_t::event_t::start);
|
||||
delete controller;
|
||||
return status;
|
||||
}
|
||||
|
@ -1,2 +1,3 @@
|
||||
main.cpp
|
||||
controller/root.cpp
|
||||
platform/linux/service/window.cpp
|
||||
|
@ -1,26 +1,22 @@
|
||||
#include "controller/root.h"
|
||||
#include "service/window.h"
|
||||
#include <X11/Xlib.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
controller_status_t root_controller_t::on_event(controller_event_t event) {
|
||||
window_service_t::status_t window_service_t::create_window() {
|
||||
Display *d;
|
||||
Window w;
|
||||
XEvent e;
|
||||
const char *msg = "Hello, World!";
|
||||
int s;
|
||||
|
||||
d = XOpenDisplay(NULL);
|
||||
if (d == NULL) {
|
||||
return controller_status_t::error;
|
||||
return window_service_t::status_t::error;
|
||||
}
|
||||
|
||||
s = DefaultScreen(d);
|
||||
w = XCreateSimpleWindow(d, RootWindow(d, s), 10, 10, 100, 100, 1, BlackPixel(d, s), WhitePixel(d, s));
|
||||
XSelectInput(d, w, ExposureMask | KeyPressMask);
|
||||
XMapWindow(d, w);
|
||||
|
||||
while (true) {
|
||||
XNextEvent(d, &e);
|
||||
if (e.type == Expose) {
|
||||
@ -30,7 +26,6 @@ controller_status_t root_controller_t::on_event(controller_event_t event) {
|
||||
if (e.type == KeyPress)
|
||||
break;
|
||||
}
|
||||
|
||||
XCloseDisplay(d);
|
||||
return controller_status_t::ok;
|
||||
return window_service_t::status_t::ok;
|
||||
}
|
BIN
earn/executable
BIN
earn/executable
Binary file not shown.
Binary file not shown.
@ -1,2 +0,0 @@
|
||||
|
||||
-lX11
|
BIN
link/main.cpp.o
BIN
link/main.cpp.o
Binary file not shown.
@ -1,3 +0,0 @@
|
||||
|
||||
/home/cogentleman/main/art/cpp_launchpad/command/linux/../.././link/main.cpp.o
|
||||
/home/cogentleman/main/art/cpp_launchpad/command/linux/../.././link/controller/root.cpp.o
|
Loading…
Reference in New Issue
Block a user