From 387f3b78d6f13bc80c980f517c38e7b4f268ba03 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Mon, 8 Jun 2015 10:37:49 +0200 Subject: [PATCH] Ability to move-construct Context. Useful in this case: std::optional context; context = Platform::Context{}; This was currently possible only with calling context.emplace(), which in my opinion is confusing and looks like a no-op. Move assignment is still not allowed, because having two separate state trackers (and deleting one of them) currently makes no sense. --- src/Magnum/Context.cpp | 18 ++++++++++++++++-- src/Magnum/Context.h | 6 +++--- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/src/Magnum/Context.cpp b/src/Magnum/Context.cpp index 296a8f6e8..458bea2d9 100644 --- a/src/Magnum/Context.cpp +++ b/src/Magnum/Context.cpp @@ -543,10 +543,24 @@ Context::Context(void functionLoader()) { Renderer::initializeContextBasedFunctionality(); } +Context::Context(Context&& other): _version{std::move(other._version)}, + #ifndef MAGNUM_TARGET_WEBGL + _flags{std::move(other._flags)}, + #endif + _extensionRequiredVersion{std::move(other._extensionRequiredVersion)}, + _extensionStatus{std::move(other._extensionStatus)}, + _supportedExtensions{std::move(other._supportedExtensions)}, + _state{std::move(other._state)}, + _detectedDrivers{std::move(other._detectedDrivers)} +{ + other._state = nullptr; + if(_current == &other) _current = this; +} + Context::~Context() { - CORRADE_ASSERT(_current == this, "Context: Cannot destroy context which is not currently active", ); delete _state; - _current = nullptr; + + if(_current == this) _current = nullptr; } std::vector Context::shadingLanguageVersionStrings() const { diff --git a/src/Magnum/Context.h b/src/Magnum/Context.h index 41dc783d8..c4bdfd876 100644 --- a/src/Magnum/Context.h +++ b/src/Magnum/Context.h @@ -210,15 +210,15 @@ class MAGNUM_EXPORT Context { /** @brief Copying is not allowed */ Context(const Context&) = delete; - /** @brief Moving is not allowed */ - Context(Context&&) = delete; + /** @brief Move constructor */ + Context(Context&& other); ~Context(); /** @brief Copying is not allowed */ Context& operator=(const Context&) = delete; - /** @brief Moving is not allowed */ + /** @brief Move assignment is not allowed */ Context& operator=(Context&&) = delete; /** @brief Current context */