diff --git a/include/Gedeng.h b/include/Gedeng.h index d75aa1d..21fb816 100644 --- a/include/Gedeng.h +++ b/include/Gedeng.h @@ -3,4 +3,6 @@ #include "Gedeng/Application.h" #include "Gedeng/Logger.h" #include "Gedeng/String.h" -#include "Gedeng/Vector.h" \ No newline at end of file +#include "Gedeng/Vector.h" + +#include "Gedeng/EntryPoint.h" \ No newline at end of file diff --git a/include/Gedeng/Application.h b/include/Gedeng/Application.h index da21645..ce00f3b 100644 --- a/include/Gedeng/Application.h +++ b/include/Gedeng/Application.h @@ -12,4 +12,7 @@ class Application { void run(); }; +// To be defined in client applications +Application *create_application(); + } // namespace Gedeng \ No newline at end of file diff --git a/include/Gedeng/EntryPoint.h b/include/Gedeng/EntryPoint.h new file mode 100644 index 0000000..4060924 --- /dev/null +++ b/include/Gedeng/EntryPoint.h @@ -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 \ No newline at end of file diff --git a/test/test-app/main.cpp b/test/test-app/main.cpp index da731b1..345f10c 100644 --- a/test/test-app/main.cpp +++ b/test/test-app/main.cpp @@ -1,3 +1,4 @@ +#define GEDENG_MAIN #include 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; -} \ No newline at end of file +Gedeng::Application *Gedeng::create_application() { + return new TestApp(); +}