still deciding on structure
This commit is contained in:
31
src/App.cpp
Normal file
31
src/App.cpp
Normal file
@@ -0,0 +1,31 @@
|
||||
#include "App.h"
|
||||
|
||||
App* App::instance = nullptr;
|
||||
|
||||
App::App() {
|
||||
|
||||
if(instance != nullptr) {
|
||||
std::cout << "App already exists\nThere can only be one!\n";
|
||||
std::abort();
|
||||
}
|
||||
|
||||
std::cout << "Initializing...\n";
|
||||
|
||||
instance = this;
|
||||
|
||||
}
|
||||
|
||||
App::~App() {
|
||||
|
||||
std::cout << "\nExiting...";
|
||||
}
|
||||
|
||||
void App::run() {
|
||||
std::cout << "\nTesting...\n";
|
||||
|
||||
// Main loop
|
||||
while (!done) {
|
||||
end();
|
||||
}
|
||||
}
|
||||
|
||||
28
src/App.h
Normal file
28
src/App.h
Normal file
@@ -0,0 +1,28 @@
|
||||
#ifndef APP_H
|
||||
#define APP_H
|
||||
|
||||
#include "pch.hpp"
|
||||
#include "Module.h"
|
||||
#include "GuiModule.h"
|
||||
|
||||
class App {
|
||||
|
||||
private:
|
||||
static App* instance;
|
||||
|
||||
bool done;
|
||||
|
||||
std::vector<Module*> modules;
|
||||
|
||||
public:
|
||||
App();
|
||||
~App();
|
||||
|
||||
static App& Get() { return *instance; }
|
||||
|
||||
void run();
|
||||
|
||||
void end() { done = true; };
|
||||
};
|
||||
|
||||
#endif
|
||||
17
src/GuiModule.h
Normal file
17
src/GuiModule.h
Normal file
@@ -0,0 +1,17 @@
|
||||
#ifndef GUIMODULE_H
|
||||
#define GUIMODULE_H
|
||||
|
||||
#include "Module.h"
|
||||
|
||||
class GuiModule : Module {
|
||||
|
||||
public:
|
||||
typedef GuiModule* create_t();
|
||||
typedef void destroy_t(GuiModule*);
|
||||
|
||||
virtual ~GuiModule() {}
|
||||
virtual void run() = 0;
|
||||
};
|
||||
|
||||
|
||||
#endif
|
||||
18
src/Module.h
Normal file
18
src/Module.h
Normal file
@@ -0,0 +1,18 @@
|
||||
#ifndef MODULE_H
|
||||
#define MODULE_H
|
||||
|
||||
#include "pch.hpp"
|
||||
|
||||
|
||||
class Module {
|
||||
|
||||
public:
|
||||
typedef Module* create_t();
|
||||
typedef void destroy_t(Module*);
|
||||
|
||||
|
||||
virtual ~Module() {}
|
||||
virtual void run() = 0;
|
||||
};
|
||||
|
||||
#endif
|
||||
47
src/core.cpp
47
src/core.cpp
@@ -1,47 +0,0 @@
|
||||
#include "pch.hpp"
|
||||
|
||||
int main(int argc, char* argv[]) {
|
||||
|
||||
for(int i = 0; i < argc; i++) {
|
||||
std::cout << "argument " << i << ": " << argv[i] << std::endl;
|
||||
}
|
||||
|
||||
if(argc > 1) {
|
||||
|
||||
//cli arg flags
|
||||
bool start = false,
|
||||
stop = false,
|
||||
d = false,
|
||||
h = false,
|
||||
gui = false;
|
||||
|
||||
int idx = 1;
|
||||
|
||||
//find and handle cli args
|
||||
if(strcmp(argv[idx], "start") == 0 || argc < idx) {
|
||||
std::cout << "start daemon\n";
|
||||
start = true;
|
||||
idx++;
|
||||
} else if(strcmp(argv[idx], "stop") == 0 && argc >= idx) {
|
||||
std::cout << "stop daemon\n";
|
||||
stop = true;
|
||||
idx++;
|
||||
}
|
||||
|
||||
for(int& i = idx; i < argc; i++) {
|
||||
|
||||
if(!h && strcmp(argv[i], "-h") == 0) {
|
||||
std::cout << "print help\n";
|
||||
h = true;
|
||||
} else if(!d && strcmp(argv[i], "-d") == 0) {
|
||||
std::cout << "init daemon\n";
|
||||
d = true;
|
||||
} else if(!gui && strcmp(argv[i], "-gui") == 0) {
|
||||
std::cout << "init gui\n";
|
||||
gui = true;
|
||||
} else {
|
||||
std::cout << "Argument \"" << argv[i] << "\" at index " << i << " is unknown or duplicated.\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
7
src/main.cpp
Normal file
7
src/main.cpp
Normal file
@@ -0,0 +1,7 @@
|
||||
#include "pch.hpp"
|
||||
#include "App.h"
|
||||
|
||||
int main(int argc, char* argv[]) {
|
||||
App app;
|
||||
app.run();
|
||||
}
|
||||
@@ -3,5 +3,6 @@
|
||||
|
||||
#include <iostream>
|
||||
#include <cstring>
|
||||
#include <vector>
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user