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 erorr. If the destructor throws exceptions, it will cause memory leaks and crashes. http://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 23 of file save_blocker.cpp.
References block().
save_blocker::~save_blocker | ( | ) |
Definition at line 27 of file save_blocker.cpp.
References callback_, controller_, e, and unblock().
|
staticprotected |
|
static |
Definition at line 40 of file save_blocker.cpp.
References callback_, controller_, try_block(), and unblock().
Referenced by play_controller::save_game(), play_controller::save_map(), and play_controller::save_replay().
|
static |
Definition at line 50 of file save_blocker.cpp.
References sem_.
|
staticprotected |
Definition at line 58 of file save_blocker.cpp.
References sem_.
Referenced by on_unblock(), play_controller::save_game(), play_controller::save_game_auto(), play_controller::save_map(), play_controller::save_replay(), and play_controller::save_replay_auto().
|
staticprotected |
Definition at line 62 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().