Add (optional) main function to library

This commit is contained in:
karl 2021-03-20 16:07:07 +01:00
parent 5d64b4c239
commit a626a4bca0
4 changed files with 28 additions and 8 deletions

View File

@ -4,3 +4,5 @@
#include "Gedeng/Logger.h"
#include "Gedeng/String.h"
#include "Gedeng/Vector.h"
#include "Gedeng/EntryPoint.h"

View File

@ -12,4 +12,7 @@ class Application {
void run();
};
// To be defined in client applications
Application *create_application();
} // namespace Gedeng

View File

@ -0,0 +1,18 @@
#pragma once
#include "Gedeng/Application.h"
extern Gedeng::Application *Gedeng::create_application();
// If the user program defines GEDENG_MAIN, supply this main function
#ifdef GEDENG_MAIN
int main() {
Gedeng::Application *app = Gedeng::create_application();
app->run();
delete app;
return 0;
}
#endif

View File

@ -1,3 +1,4 @@
#define GEDENG_MAIN
#include <Gedeng.h>
class TestApp : public Gedeng::Application {
@ -7,10 +8,6 @@ class TestApp : public Gedeng::Application {
~TestApp() = default;
};
int main() {
TestApp *app = new TestApp();
app->run();
delete app;
Gedeng::Application *Gedeng::create_application() {
return new TestApp();
}