From dfdec44b01580bddd7389d3a62cfbc6efa1ace8c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Mon, 1 Apr 2013 13:43:27 +0200 Subject: [PATCH] Platform: portable application arguments specification. Last PITA when porting to NaCl removed. Yay! --- doc/platform.dox | 8 ++++---- doc/portability.dox | 2 +- src/Platform/AbstractXApplication.cpp | 4 ++-- src/Platform/AbstractXApplication.h | 13 +++++++------ src/Platform/GlutApplication.cpp | 8 ++++---- src/Platform/GlutApplication.h | 17 +++++++++-------- src/Platform/GlxApplication.h | 12 ++++++------ src/Platform/NaClApplication.cpp | 4 ++-- src/Platform/NaClApplication.h | 11 +++++++---- src/Platform/Sdl2Application.cpp | 4 ++-- src/Platform/Sdl2Application.h | 15 +++++++++------ src/Platform/WindowlessGlxApplication.cpp | 4 ++-- src/Platform/WindowlessGlxApplication.h | 16 ++++++++++------ src/Platform/XEglApplication.h | 12 ++++++------ src/Platform/magnum-info.cpp | 4 ++-- 15 files changed, 73 insertions(+), 61 deletions(-) diff --git a/doc/platform.dox b/doc/platform.dox index e74aaaeb3..3f82bb0db 100644 --- a/doc/platform.dox +++ b/doc/platform.dox @@ -58,13 +58,13 @@ using namespace Magnum; class MyApplication: public Platform::GlutApplication { public: - MyApplication(int& argc, char** argv); + MyApplication(const Arguments& arguments); void viewportEvent(const Vector2i& viewport) override; void drawEvent() override; }; -MyApplication::MyApplication(int& argc, char** argv): Platform::GlutApplication(argc, argv) { +MyApplication::MyApplication(const Arguments& arguments): Platform::GlutApplication(arguments) { // Set clear color to dark blue Renderer::setClearColor({0.0f, 0.0f, 0.4f}); } @@ -104,12 +104,12 @@ using namespace Magnum; class MyApplication: public Platform::WindowlessGlxApplication { public: - MyApplication(int& argc, char** argv); + MyApplication(const Arguments& arguments); int exec() override; }; -MyApplication::MyApplication(int& argc, char** argv): Platform::WindowlessGlxApplication(argc, argv) {} +MyApplication::MyApplication(const Arguments& arguments): Platform::WindowlessGlxApplication(arguments) {} int MyApplication::exec() { Debug() << "OpenGL version:" << Context::current()->versionString(); diff --git a/doc/portability.dox b/doc/portability.dox index 335b70259..ac8e74a70 100644 --- a/doc/portability.dox +++ b/doc/portability.dox @@ -185,7 +185,7 @@ particular *Event class implementations: class MyApplication: public Platform::Application { public: - MyApplication(int& argc, char** argv): Platform::Application(argc, argv, "My Application"); + MyApplication(const Arguments& arguments); protected: void viewportEvent(const Vector2i& size) override; diff --git a/src/Platform/AbstractXApplication.cpp b/src/Platform/AbstractXApplication.cpp index 6275abdd6..153429d13 100644 --- a/src/Platform/AbstractXApplication.cpp +++ b/src/Platform/AbstractXApplication.cpp @@ -36,11 +36,11 @@ namespace Magnum { namespace Platform { -AbstractXApplication::AbstractXApplication(AbstractContextHandler* contextHandler, int&, char**): contextHandler(contextHandler), c(nullptr), flags(Flag::Redraw) { +AbstractXApplication::AbstractXApplication(AbstractContextHandler* contextHandler, const Arguments&): contextHandler(contextHandler), c(nullptr), flags(Flag::Redraw) { createContext(new Configuration); } -AbstractXApplication::AbstractXApplication(AbstractContextHandler* contextHandler, int&, char**, Configuration* configuration): contextHandler(contextHandler), c(nullptr), flags(Flag::Redraw) { +AbstractXApplication::AbstractXApplication(AbstractContextHandler* contextHandler, const Arguments&, Configuration* configuration): contextHandler(contextHandler), c(nullptr), flags(Flag::Redraw) { if(configuration) createContext(configuration); } diff --git a/src/Platform/AbstractXApplication.h b/src/Platform/AbstractXApplication.h index f3af833a1..3afdd40c2 100644 --- a/src/Platform/AbstractXApplication.h +++ b/src/Platform/AbstractXApplication.h @@ -55,6 +55,9 @@ Supports keyboard and mouse handling. See @ref platform for brief introduction. */ class AbstractXApplication { public: + /** @brief Application arguments */ + typedef std::pair Arguments; + class Configuration; class InputEvent; class KeyEvent; @@ -64,26 +67,24 @@ class AbstractXApplication { /** * @brief Default constructor * @param contextHandler OpenGL context handler - * @param argc Count of arguments of `main()` function - * @param argv Arguments of `main()` function + * @param arguments Application arguments * * Creates application with default configuration. See Configuration * for more information. */ - explicit AbstractXApplication(AbstractContextHandler* contextHandler, int& argc, char** argv); + explicit AbstractXApplication(AbstractContextHandler* contextHandler, const Arguments& arguments); /** * @brief Constructor * @param contextHandler OpenGL context handler - * @param argc Count of arguments of `main()` function - * @param argv Arguments of `main()` function + * @param arguments Application arguments * @param configuration Configuration * * The @p configuration is deleted afterwards. If `nullptr` is passed * as @p configuration, the context is not created and must be created * with createContext(). */ - explicit AbstractXApplication(AbstractContextHandler* contextHandler, int& argc, char** argv, Configuration* configuration); + explicit AbstractXApplication(AbstractContextHandler* contextHandler, const Arguments& arguments, Configuration* configuration); /** * @brief Destructor diff --git a/src/Platform/GlutApplication.cpp b/src/Platform/GlutApplication.cpp index 3571c8a67..ca9765030 100644 --- a/src/Platform/GlutApplication.cpp +++ b/src/Platform/GlutApplication.cpp @@ -31,13 +31,13 @@ namespace Magnum { namespace Platform { GlutApplication* GlutApplication::instance = nullptr; -GlutApplication::GlutApplication(int& argc, char** argv): c(nullptr) { - initialize(argc, argv); +GlutApplication::GlutApplication(const Arguments& arguments): c(nullptr) { + initialize(arguments.first, arguments.second); createContext(new Configuration); } -GlutApplication::GlutApplication(int& argc, char** argv, Configuration* configuration): c(nullptr) { - initialize(argc, argv); +GlutApplication::GlutApplication(const Arguments& arguments, Configuration* configuration): c(nullptr) { + initialize(arguments.first, arguments.second); if(configuration) createContext(configuration); } diff --git a/src/Platform/GlutApplication.h b/src/Platform/GlutApplication.h index 6dd8281a3..ce141930b 100644 --- a/src/Platform/GlutApplication.h +++ b/src/Platform/GlutApplication.h @@ -67,6 +67,9 @@ to simplify porting. */ class GlutApplication { public: + /** @brief Application arguments */ + typedef std::pair Arguments; + class Configuration; class InputEvent; class KeyEvent; @@ -75,25 +78,23 @@ class GlutApplication { /** * @brief Default constructor - * @param argc Count of arguments of `main()` function - * @param argv Arguments of `main()` function + * @param arguments Application arguments * * Creates application with default configuration. See Configuration * for more information. */ - explicit GlutApplication(int& argc, char** argv); + explicit GlutApplication(const Arguments& arguments); /** * @brief Constructor - * @param argc Count of arguments of `main()` function - * @param argv Arguments of `main()` function + * @param arguments Application arguments * @param configuration Configuration * * The @p configuration is deleted afterwards. If `nullptr` is passed * as @p configuration, the context is not created and must be created * with createContext(). */ - explicit GlutApplication(int& argc, char** argv, Configuration* configuration); + explicit GlutApplication(const Arguments& arguments, Configuration* configuration); virtual ~GlutApplication(); @@ -465,7 +466,7 @@ code to achieve better portability, see @ref portability-applications for more information. @code int main(int argc, char** argv) { - className app(argc, argv); + className app({argc, argv}); return app.exec(); } @endcode @@ -474,7 +475,7 @@ When no other application header is included this macro is also aliased to */ #define MAGNUM_GLUTAPPLICATION_MAIN(className) \ int main(int argc, char** argv) { \ - className app(argc, argv); \ + className app({argc, argv}); \ return app.exec(); \ } diff --git a/src/Platform/GlxApplication.h b/src/Platform/GlxApplication.h index c5a28ac71..d7a0dee80 100644 --- a/src/Platform/GlxApplication.h +++ b/src/Platform/GlxApplication.h @@ -56,11 +56,11 @@ to simplify porting. */ class GlxApplication: public AbstractXApplication { public: - /** @copydoc GlutApplication::GlutApplication(int&, char**) */ - inline explicit GlxApplication(int& argc, char** argv): AbstractXApplication(new GlxContextHandler, argc, argv) {} + /** @copydoc GlutApplication::GlutApplication(const Arguments&) */ + inline explicit GlxApplication(const Arguments& arguments): AbstractXApplication(new GlxContextHandler, arguments) {} - /** @copydoc GlutApplication::GlutApplication(int&, char**, Configuration*) */ - inline explicit GlxApplication(int& argc, char** argv, Configuration* configuration): AbstractXApplication(new GlxContextHandler, argc, argv, configuration) {} + /** @copydoc GlutApplication::GlutApplication(const Arguments&, Configuration*) */ + inline explicit GlxApplication(const Arguments& arguments, Configuration* configuration): AbstractXApplication(new GlxContextHandler, arguments, configuration) {} }; /** @hideinitializer @@ -72,7 +72,7 @@ to achieve better portability, see @ref portability-applications for more information. @code int main(int argc, char** argv) { - className app(argc, argv); + className app({argc, argv}); return app.exec(); } @endcode @@ -81,7 +81,7 @@ When no other application header is included this macro is also aliased to */ #define MAGNUM_GLXAPPLICATION_MAIN(className) \ int main(int argc, char** argv) { \ - className app(argc, argv); \ + className app({argc, argv}); \ return app.exec(); \ } diff --git a/src/Platform/NaClApplication.cpp b/src/Platform/NaClApplication.cpp index d746f1aa1..6e7509b2d 100644 --- a/src/Platform/NaClApplication.cpp +++ b/src/Platform/NaClApplication.cpp @@ -32,11 +32,11 @@ namespace Magnum { namespace Platform { -NaClApplication::NaClApplication(PP_Instance instance): Instance(instance), Graphics3DClient(this), MouseLock(this), c(nullptr) { +NaClApplication::NaClApplication(const Arguments& arguments): Instance(arguments), Graphics3DClient(this), MouseLock(this), c(nullptr) { createContext(new Configuration); } -NaClApplication::NaClApplication(PP_Instance instance, Configuration* configuration): Instance(instance), Graphics3DClient(this), MouseLock(this), c(nullptr) { +NaClApplication::NaClApplication(const Arguments& arguments, Configuration* configuration): Instance(arguments), Graphics3DClient(this), MouseLock(this), c(nullptr) { if(configuration) createContext(configuration); } diff --git a/src/Platform/NaClApplication.h b/src/Platform/NaClApplication.h index 2772bee12..f44ff896e 100644 --- a/src/Platform/NaClApplication.h +++ b/src/Platform/NaClApplication.h @@ -73,6 +73,9 @@ to simplify porting. */ class NaClApplication: public pp::Instance, public pp::Graphics3DClient, public pp::MouseLock { public: + /** @brief Application arguments */ + typedef PP_Instance Arguments; + class Configuration; class InputEvent; class KeyEvent; @@ -81,23 +84,23 @@ class NaClApplication: public pp::Instance, public pp::Graphics3DClient, public /** * @brief Default constructor - * @param instance Module instance + * @param arguments Application arguments * * Creates application with default configuration. See Configuration * for more information. */ - explicit NaClApplication(PP_Instance instance); + explicit NaClApplication(const Arguments& arguments); /** * @brief Constructor - * @param instance Module instance + * @param arguments Application arguments * @param configuration Configuration * * The @p configuration is deleted afterwards. If `nullptr` is passed * as @p configuration, the context is not created and must be created * with createContext(). */ - explicit NaClApplication(PP_Instance instance, Configuration* configuration); + explicit NaClApplication(const Arguments& arguments, Configuration* configuration); ~NaClApplication(); diff --git a/src/Platform/Sdl2Application.cpp b/src/Platform/Sdl2Application.cpp index 881ec5aab..164f4601e 100644 --- a/src/Platform/Sdl2Application.cpp +++ b/src/Platform/Sdl2Application.cpp @@ -49,11 +49,11 @@ Sdl2Application::InputEvent::Modifiers fixedModifiers(Uint16 mod) { } -Sdl2Application::Sdl2Application(int&, char**): context(nullptr), flags(Flag::Redraw) { +Sdl2Application::Sdl2Application(const Arguments&): context(nullptr), flags(Flag::Redraw) { createContext(new Configuration); } -Sdl2Application::Sdl2Application(int&, char**, Configuration* configuration): context(nullptr), flags(Flag::Redraw) { +Sdl2Application::Sdl2Application(const Arguments&, Configuration* configuration): context(nullptr), flags(Flag::Redraw) { if(configuration) createContext(configuration); } diff --git a/src/Platform/Sdl2Application.h b/src/Platform/Sdl2Application.h index 860feda8f..fb9a5f0e7 100644 --- a/src/Platform/Sdl2Application.h +++ b/src/Platform/Sdl2Application.h @@ -68,17 +68,20 @@ to simplify porting. */ class Sdl2Application { public: + /** @brief Application arguments */ + typedef std::pair Arguments; + class Configuration; class InputEvent; class KeyEvent; class MouseEvent; class MouseMoveEvent; - /** @copydoc GlutApplication::GlutApplication(int&, char**) */ - explicit Sdl2Application(int& argc, char** argv); + /** @copydoc GlutApplication::GlutApplication(const Arguments&) */ + explicit Sdl2Application(const Arguments& arguments); - /** @copydoc GlutApplication::GlutApplication(int&, char**, Configuration*) */ - explicit Sdl2Application(int& argc, char** argv, Configuration* configuration); + /** @copydoc GlutApplication::GlutApplication(const Arguments&, Configuration*) */ + explicit Sdl2Application(const Arguments& arguments, Configuration* configuration); virtual ~Sdl2Application(); @@ -481,7 +484,7 @@ code to achieve better portability, see @ref portability-applications for more information. @code int main(int argc, char** argv) { - className app(argc, argv); + className app({argc, argv}); return app.exec(); } @endcode @@ -490,7 +493,7 @@ When no other application header is included this macro is also aliased to */ #define MAGNUM_SDL2APPLICATION_MAIN(className) \ int main(int argc, char** argv) { \ - className app(argc, argv); \ + className app({argc, argv}); \ return app.exec(); \ } diff --git a/src/Platform/WindowlessGlxApplication.cpp b/src/Platform/WindowlessGlxApplication.cpp index 12429ab20..39f934f60 100644 --- a/src/Platform/WindowlessGlxApplication.cpp +++ b/src/Platform/WindowlessGlxApplication.cpp @@ -33,11 +33,11 @@ namespace Magnum { namespace Platform { -WindowlessGlxApplication::WindowlessGlxApplication(int&, char**) { +WindowlessGlxApplication::WindowlessGlxApplication(const Arguments&) { createContext(new Configuration); } -WindowlessGlxApplication::WindowlessGlxApplication(int&, char**, Configuration* configuration) { +WindowlessGlxApplication::WindowlessGlxApplication(const Arguments&, Configuration* configuration) { if(configuration) createContext(configuration); } diff --git a/src/Platform/WindowlessGlxApplication.h b/src/Platform/WindowlessGlxApplication.h index 4e0762ccc..b7c8d940a 100644 --- a/src/Platform/WindowlessGlxApplication.h +++ b/src/Platform/WindowlessGlxApplication.h @@ -28,6 +28,7 @@ * @brief Class Magnum::Platform::WindowlessGlxApplication */ +#include #include "OpenGL.h" #include #include @@ -64,13 +65,16 @@ If no other application header is included this class is also aliased to */ class WindowlessGlxApplication { public: + /** @brief Application arguments */ + typedef std::pair Arguments; + class Configuration; - /** @copydoc GlutApplication::GlutApplication(int&, char**) */ - explicit WindowlessGlxApplication(int& argc, char** argv); + /** @copydoc GlutApplication::GlutApplication(const Arguments&) */ + explicit WindowlessGlxApplication(const Arguments& arguments); - /** @copydoc GlutApplication::GlutApplication(int&, char**, Configuration*) */ - explicit WindowlessGlxApplication(int& argc, char** argv, Configuration* configuration); + /** @copydoc GlutApplication::GlutApplication(const Arguments&, Configuration*) */ + explicit WindowlessGlxApplication(const Arguments& arguments, Configuration* configuration); ~WindowlessGlxApplication(); @@ -116,7 +120,7 @@ Can be used as equivalent to the following code to achieve better portability, see @ref portability-applications for more information. @code int main(int argc, char** argv) { - className app(argc, argv); + className app({argc, argv}); return app.exec(); } @endcode @@ -125,7 +129,7 @@ aliased to `MAGNUM_WINDOWLESSAPPLICATION_MAIN()`. */ #define MAGNUM_WINDOWLESSGLXAPPLICATION_MAIN(className) \ int main(int argc, char** argv) { \ - className app(argc, argv); \ + className app({argc, argv}); \ return app.exec(); \ } diff --git a/src/Platform/XEglApplication.h b/src/Platform/XEglApplication.h index f9c716b27..2e4c07d98 100644 --- a/src/Platform/XEglApplication.h +++ b/src/Platform/XEglApplication.h @@ -56,11 +56,11 @@ to simplify porting. */ class XEglApplication: public AbstractXApplication { public: - /** @copydoc GlutApplication::GlutApplication(int&, char**) */ - inline explicit XEglApplication(int& argc, char** argv): AbstractXApplication(new EglContextHandler, argc, argv) {} + /** @copydoc GlutApplication::GlutApplication(const Arguments&) */ + inline explicit XEglApplication(const Arguments& arguments): AbstractXApplication(new EglContextHandler, arguments) {} - /** @copydoc GlutApplication::GlutApplication(int&, char**, Configuration*) */ - inline explicit XEglApplication(int& argc, char** argv, Configuration* configuration): AbstractXApplication(new EglContextHandler, argc, argv, configuration) {} + /** @copydoc GlutApplication::GlutApplication(const Arguments&, Configuration*) */ + inline explicit XEglApplication(const Arguments& arguments, Configuration* configuration): AbstractXApplication(new EglContextHandler, arguments, configuration) {} }; /** @hideinitializer @@ -72,7 +72,7 @@ to achieve better portability, see @ref portability-applications for more information. @code int main(int argc, char** argv) { - className app(argc, argv); + className app({argc, argv}); return app.exec(); } @endcode @@ -81,7 +81,7 @@ When no other application header is included this macro is also aliased to */ #define MAGNUM_XEGLAPPLICATION_MAIN(className) \ int main(int argc, char** argv) { \ - className app(argc, argv); \ + className app({argc, argv}); \ return app.exec(); \ } diff --git a/src/Platform/magnum-info.cpp b/src/Platform/magnum-info.cpp index 5dfa7bd7e..f975e0f5c 100644 --- a/src/Platform/magnum-info.cpp +++ b/src/Platform/magnum-info.cpp @@ -32,12 +32,12 @@ namespace Magnum { class MagnumInfo: public Platform::WindowlessGlxApplication { public: - MagnumInfo(int& argc, char** argv); + explicit MagnumInfo(const Arguments& arguments); inline int exec() override { return 0; } }; -MagnumInfo::MagnumInfo(int& argc, char** argv): WindowlessGlxApplication(argc, argv) { +MagnumInfo::MagnumInfo(const Arguments& arguments): WindowlessGlxApplication(arguments) { Context* c = Context::current(); Debug() << "";