While any instance of this class exists, attempts to save the game via any call to play_controller will be temporarily postponed: the call will return immediately without performing the save, but the save method will then be reinvoked from this class's destructor. More...
#include <save_blocker.hpp>
Classes | |
class | save_unblocker |
An exception-safe means of making sure that unblock() gets called after try_block(). More... | |
Public Member Functions | |
save_blocker () | |
~save_blocker () | |
Static Public Member Functions | |
static bool | saves_are_blocked () |
static void | on_unblock (play_controller *controller, void(play_controller::*callback)()) |
Static Protected Member Functions | |
static void | block () |
static bool | try_block () |
static void | unblock () |
Static Private Attributes | |
static play_controller * | controller_ = nullptr |
static void(play_controller::* | callback_ )() = nullptr |
static SDL_sem * | sem_ = SDL_CreateSemaphore(1) |
Friends | |
class | play_controller |
While any instance of this class exists, attempts to save the game via any call to play_controller will be temporarily postponed: the call will return immediately without performing the save, but the save method will then be reinvoked from this class's destructor.
If multiple save attempts are performed, only the last will be carried out. NOTE: This class is broken and you probably shouldn't use it. Calling a save game dialog from the destructor of a class is a bad idea, because those functions throw exceptions. For example if the user decides to quit the game, or there is a filesystem error. If the destructor throws exceptions, it will cause memory leaks and crashes. https://wiki.wesnoth.org/CodingStandards#Destructors_must_not_throw_exceptions
As a temporary fix the destructor has been changed to swallow all exceptions. However this means that if the user attempts to quit the game from the savegame dialog, or any filesystem error occurs, it will be suppressed instead of being handled normally. So you should avoid using this class and it may be removed.
Definition at line 45 of file save_blocker.hpp.
save_blocker::save_blocker | ( | ) |
Definition at line 25 of file save_blocker.cpp.
References block().
save_blocker::~save_blocker | ( | ) |
Definition at line 29 of file save_blocker.cpp.
References callback_, controller_, e, PLAIN_LOG, and unblock().
|
staticprotected |
|
static |
Definition at line 42 of file save_blocker.cpp.
References callback_, controller_, try_block(), and unblock().
|
static |
Definition at line 52 of file save_blocker.cpp.
References sem_.
|
staticprotected |
|
staticprotected |
Definition at line 64 of file save_blocker.cpp.
References sem_.
Referenced by on_unblock(), ~save_blocker(), and save_blocker::save_unblocker::~save_unblocker().
|
friend |
Definition at line 53 of file save_blocker.hpp.
|
staticprivate |
Definition at line 69 of file save_blocker.hpp.
Referenced by on_unblock(), and ~save_blocker().
|
staticprivate |
Definition at line 68 of file save_blocker.hpp.
Referenced by on_unblock(), and ~save_blocker().
|
staticprivate |
Definition at line 70 of file save_blocker.hpp.
Referenced by block(), saves_are_blocked(), try_block(), and unblock().