Add (optional) main function to library
This commit is contained in:
parent
5d64b4c239
commit
a626a4bca0
@ -3,4 +3,6 @@
|
||||
#include "Gedeng/Application.h"
|
||||
#include "Gedeng/Logger.h"
|
||||
#include "Gedeng/String.h"
|
||||
#include "Gedeng/Vector.h"
|
||||
#include "Gedeng/Vector.h"
|
||||
|
||||
#include "Gedeng/EntryPoint.h"
|
@ -12,4 +12,7 @@ class Application {
|
||||
void run();
|
||||
};
|
||||
|
||||
// To be defined in client applications
|
||||
Application *create_application();
|
||||
|
||||
} // namespace Gedeng
|
18
include/Gedeng/EntryPoint.h
Normal file
18
include/Gedeng/EntryPoint.h
Normal 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
|
@ -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();
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user