Browse Source

Ability to move-construct Context.

Useful in this case:

    std::optional<Platform::Context> 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.
pull/107/head
Vladimír Vondruš 11 years ago
parent
commit
387f3b78d6
  1. 18
      src/Magnum/Context.cpp
  2. 6
      src/Magnum/Context.h

18
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<std::string> Context::shadingLanguageVersionStrings() const {

6
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 */

Loading…
Cancel
Save