From 5c0747359a8c88fb5cdc521ab27644d88ec382aa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sat, 7 Dec 2013 20:10:11 +0100 Subject: [PATCH] Platform: add default argument to createContext(). Somebody would just want to defer context creation after parsing arguments or doing some validations without any particular setup, thus having to write even the {} is annoying. --- src/Platform/AbstractXApplication.cpp | 2 ++ src/Platform/AbstractXApplication.h | 6 ++++++ src/Platform/GlutApplication.cpp | 4 +++- src/Platform/GlutApplication.h | 6 ++++++ src/Platform/NaClApplication.cpp | 4 +++- src/Platform/NaClApplication.h | 6 ++++++ src/Platform/Sdl2Application.cpp | 4 +++- src/Platform/Sdl2Application.h | 6 ++++++ src/Platform/WindowlessGlxApplication.cpp | 4 +++- src/Platform/WindowlessGlxApplication.h | 6 ++++++ src/Platform/WindowlessNaClApplication.cpp | 4 +++- src/Platform/WindowlessNaClApplication.h | 6 ++++++ src/Platform/magnum-info.cpp | 2 +- src/Text/fontconverter.cpp | 2 +- src/TextureTools/distancefieldconverter.cpp | 2 +- 15 files changed, 56 insertions(+), 8 deletions(-) diff --git a/src/Platform/AbstractXApplication.cpp b/src/Platform/AbstractXApplication.cpp index 6ef777eea..b01fbddd9 100644 --- a/src/Platform/AbstractXApplication.cpp +++ b/src/Platform/AbstractXApplication.cpp @@ -44,6 +44,8 @@ AbstractXApplication::AbstractXApplication(Implementation::AbstractContextHandle AbstractXApplication::AbstractXApplication(Implementation::AbstractContextHandler* contextHandler, const Arguments&, std::nullptr_t): contextHandler(contextHandler), c(nullptr), flags(Flag::Redraw) {} +void AbstractXApplication::createContext() { createContext({}); } + void AbstractXApplication::createContext(const Configuration& configuration) { if(!tryCreateContext(configuration)) std::exit(1); } diff --git a/src/Platform/AbstractXApplication.h b/src/Platform/AbstractXApplication.h index 6a3464d2f..a07e6ccb2 100644 --- a/src/Platform/AbstractXApplication.h +++ b/src/Platform/AbstractXApplication.h @@ -88,7 +88,13 @@ class AbstractXApplication { ~AbstractXApplication(); /** @copydoc Sdl2Application::createContext() */ + #ifdef DOXYGEN_GENERATING_OUTPUT + void createContext(const Configuration& configuration = Configuration()); + #else + /* To avoid "invalid use of incomplete type" */ void createContext(const Configuration& configuration); + void createContext(); + #endif /** @copydoc Sdl2Application::tryCreateContext() */ bool tryCreateContext(const Configuration& configuration); diff --git a/src/Platform/GlutApplication.cpp b/src/Platform/GlutApplication.cpp index 394546f98..cce9242c0 100644 --- a/src/Platform/GlutApplication.cpp +++ b/src/Platform/GlutApplication.cpp @@ -42,7 +42,7 @@ GlutApplication::GlutApplication(const Arguments& arguments, const Configuration #ifndef DOXYGEN_GENERATING_OUTPUT GlutApplication::GlutApplication(const Arguments& arguments): c(nullptr) { initialize(arguments.argc, arguments.argv); - createContext({}); + createContext(); } #endif @@ -59,6 +59,8 @@ void GlutApplication::initialize(int& argc, char** argv) { glutSetOption(GLUT_ACTION_ON_WINDOW_CLOSE, GLUT_ACTION_CONTINUE_EXECUTION); } +void GlutApplication::createContext() { createContext({}); } + void GlutApplication::createContext(const Configuration& configuration) { if(!tryCreateContext(configuration)) std::exit(1); } diff --git a/src/Platform/GlutApplication.h b/src/Platform/GlutApplication.h index 6ad4c246a..037ebb1b2 100644 --- a/src/Platform/GlutApplication.h +++ b/src/Platform/GlutApplication.h @@ -114,7 +114,13 @@ class GlutApplication { ~GlutApplication(); /** @copydoc Sdl2Application::createContext() */ + #ifdef DOXYGEN_GENERATING_OUTPUT + void createContext(const Configuration& configuration = Configuration()); + #else + /* To avoid "invalid use of incomplete type" */ void createContext(const Configuration& configuration); + void createContext(); + #endif /** @copydoc Sdl2Application::tryCreateContext() */ bool tryCreateContext(const Configuration& configuration); diff --git a/src/Platform/NaClApplication.cpp b/src/Platform/NaClApplication.cpp index 3b6648ba2..bdb34e5e6 100644 --- a/src/Platform/NaClApplication.cpp +++ b/src/Platform/NaClApplication.cpp @@ -60,7 +60,7 @@ NaClApplication::NaClApplication(const Arguments& arguments, const Configuration #ifndef DOXYGEN_GENERATING_OUTPUT NaClApplication::NaClApplication(const Arguments& arguments): Instance(arguments), Graphics3DClient(this), MouseLock(this), c(nullptr) { debugOutput = new ConsoleDebugOutput(this); - createContext({}); + createContext(); } #endif @@ -68,6 +68,8 @@ NaClApplication::NaClApplication(const Arguments& arguments, std::nullptr_t): In debugOutput = new ConsoleDebugOutput(this); } +void NaClApplication::createContext() { createContext({}); } + void NaClApplication::createContext(const Configuration& configuration) { if(!tryCreateContext(configuration)) std::exit(1); } diff --git a/src/Platform/NaClApplication.h b/src/Platform/NaClApplication.h index 34d8d88b3..6674ab7e8 100644 --- a/src/Platform/NaClApplication.h +++ b/src/Platform/NaClApplication.h @@ -179,7 +179,13 @@ class NaClApplication: public pp::Instance, public pp::Graphics3DClient, public ~NaClApplication(); /** @copydoc Sdl2Application::createContext() */ + #ifdef DOXYGEN_GENERATING_OUTPUT + void createContext(const Configuration& configuration = Configuration()); + #else + /* To avoid "invalid use of incomplete type" */ void createContext(const Configuration& configuration); + void createContext(); + #endif /** @copydoc Sdl2Application::tryCreateContext() */ bool tryCreateContext(const Configuration& configuration); diff --git a/src/Platform/Sdl2Application.cpp b/src/Platform/Sdl2Application.cpp index 4377aaca5..2f5b7785a 100644 --- a/src/Platform/Sdl2Application.cpp +++ b/src/Platform/Sdl2Application.cpp @@ -68,7 +68,7 @@ Sdl2Application::Sdl2Application(const Arguments&, const Configuration& configur #ifndef DOXYGEN_GENERATING_OUTPUT Sdl2Application::Sdl2Application(const Arguments&): context(nullptr), flags(Flag::Redraw) { initialize(); - createContext({}); + createContext(); } #endif @@ -88,6 +88,8 @@ void Sdl2Application::initialize() { } } +void Sdl2Application::createContext() { createContext({}); } + void Sdl2Application::createContext(const Configuration& configuration) { if(!tryCreateContext(configuration)) std::exit(1); } diff --git a/src/Platform/Sdl2Application.h b/src/Platform/Sdl2Application.h index 925f3443b..a9d2a8afc 100644 --- a/src/Platform/Sdl2Application.h +++ b/src/Platform/Sdl2Application.h @@ -182,7 +182,13 @@ class Sdl2Application { * constructor itself. The program exits if the context cannot be * created, see @ref tryCreateContext() for an alternative. */ + #ifdef DOXYGEN_GENERATING_OUTPUT + void createContext(const Configuration& configuration = Configuration()); + #else + /* To avoid "invalid use of incomplete type" */ void createContext(const Configuration& configuration); + void createContext(); + #endif /** * @brief Try to create context with given configuration diff --git a/src/Platform/WindowlessGlxApplication.cpp b/src/Platform/WindowlessGlxApplication.cpp index 1940e704f..e71181530 100644 --- a/src/Platform/WindowlessGlxApplication.cpp +++ b/src/Platform/WindowlessGlxApplication.cpp @@ -41,12 +41,14 @@ WindowlessGlxApplication::WindowlessGlxApplication(const Arguments&, const Confi #ifndef DOXYGEN_GENERATING_OUTPUT WindowlessGlxApplication::WindowlessGlxApplication(const Arguments&): c(nullptr) { - createContext({}); + createContext(); } #endif WindowlessGlxApplication::WindowlessGlxApplication(const Arguments&, std::nullptr_t): c(nullptr) {} +void WindowlessGlxApplication::createContext() { createContext({}); } + void WindowlessGlxApplication::createContext(const Configuration& configuration) { if(!tryCreateContext(configuration)) std::exit(1); } diff --git a/src/Platform/WindowlessGlxApplication.h b/src/Platform/WindowlessGlxApplication.h index 937d7b3fb..bf0855d9c 100644 --- a/src/Platform/WindowlessGlxApplication.h +++ b/src/Platform/WindowlessGlxApplication.h @@ -107,7 +107,13 @@ class WindowlessGlxApplication { ~WindowlessGlxApplication(); /** @copydoc Sdl2Application::createContext() */ + #ifdef DOXYGEN_GENERATING_OUTPUT + void createContext(const Configuration& configuration = Configuration()); + #else + /* To avoid "invalid use of incomplete type" */ void createContext(const Configuration& configuration); + void createContext(); + #endif /** @copydoc Sdl2Application::tryCreateContext() */ bool tryCreateContext(const Configuration& configuration); diff --git a/src/Platform/WindowlessNaClApplication.cpp b/src/Platform/WindowlessNaClApplication.cpp index f28e27e67..22e9eb1d6 100644 --- a/src/Platform/WindowlessNaClApplication.cpp +++ b/src/Platform/WindowlessNaClApplication.cpp @@ -59,7 +59,7 @@ WindowlessNaClApplication::WindowlessNaClApplication(const Arguments& arguments, #ifndef DOXYGEN_GENERATING_OUTPUT WindowlessNaClApplication::WindowlessNaClApplication(const Arguments& arguments): Instance(arguments), Graphics3DClient(this), c(nullptr) { debugOutput = new ConsoleDebugOutput(this); - createContext({}); + createContext(); } #endif @@ -67,6 +67,8 @@ WindowlessNaClApplication::WindowlessNaClApplication(const Arguments& arguments, debugOutput = new ConsoleDebugOutput(this); } +void WindowlessNaClApplication::createContext() { createContext({}); } + void WindowlessNaClApplication::createContext(const Configuration& configuration) { if(!tryCreateContext(configuration)) std::exit(1); } diff --git a/src/Platform/WindowlessNaClApplication.h b/src/Platform/WindowlessNaClApplication.h index 010a6ba41..309f32a16 100644 --- a/src/Platform/WindowlessNaClApplication.h +++ b/src/Platform/WindowlessNaClApplication.h @@ -123,7 +123,13 @@ class WindowlessNaClApplication: public pp::Instance, public pp::Graphics3DClien ~WindowlessNaClApplication(); /** @copydoc Sdl2Application::createContext() */ + #ifdef DOXYGEN_GENERATING_OUTPUT + void createContext(const Configuration& configuration = Configuration()); + #else + /* To avoid "invalid use of incomplete type" */ void createContext(const Configuration& configuration); + void createContext(); + #endif /** @copydoc Sdl2Application::tryCreateContext() */ bool tryCreateContext(const Configuration& configuration); diff --git a/src/Platform/magnum-info.cpp b/src/Platform/magnum-info.cpp index c2e66e982..182a4e28c 100644 --- a/src/Platform/magnum-info.cpp +++ b/src/Platform/magnum-info.cpp @@ -70,7 +70,7 @@ MagnumInfo::MagnumInfo(const Arguments& arguments): Platform::WindowlessApplicat /* Create context after parsing arguments, so the help can be displayed without creating context */ - createContext({}); + createContext(); Context* c = Context::current(); /* Pass debug output as messages to JavaScript */ diff --git a/src/Text/fontconverter.cpp b/src/Text/fontconverter.cpp index 1db6bc542..a944fce6f 100644 --- a/src/Text/fontconverter.cpp +++ b/src/Text/fontconverter.cpp @@ -62,7 +62,7 @@ FontConverter::FontConverter(const Arguments& arguments): Platform::WindowlessAp .setHelp("Converts font to raster one of given atlas size.") .parse(arguments.argc, arguments.argv); - createContext({}); + createContext(); } int FontConverter::exec() { diff --git a/src/TextureTools/distancefieldconverter.cpp b/src/TextureTools/distancefieldconverter.cpp index e61b17e45..8fd096224 100644 --- a/src/TextureTools/distancefieldconverter.cpp +++ b/src/TextureTools/distancefieldconverter.cpp @@ -61,7 +61,7 @@ DistanceFieldConverter::DistanceFieldConverter(const Arguments& arguments): Wind .setHelp("Converts black&white image to distance-field representation.") .parse(arguments.argc, arguments.argv); - createContext({}); + createContext(); } int DistanceFieldConverter::exec() {