The Battle for Wesnoth  1.19.7+dev
Classes | Public Member Functions | Static Public Member Functions | Static Protected Member Functions | Static Private Attributes | Friends | List of all members
save_blocker Class Reference

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_controllercontroller_ = nullptr
 
static void(play_controller::* callback_ )() = nullptr
 
static SDL_sem * sem_ = SDL_CreateSemaphore(1)
 

Friends

class play_controller
 

Detailed Description

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.

Constructor & Destructor Documentation

◆ save_blocker()

save_blocker::save_blocker ( )

Definition at line 25 of file save_blocker.cpp.

References block().

◆ ~save_blocker()

save_blocker::~save_blocker ( )

Definition at line 29 of file save_blocker.cpp.

References callback_, controller_, e, PLAIN_LOG, and unblock().

Member Function Documentation

◆ block()

void save_blocker::block ( )
staticprotected

Definition at line 56 of file save_blocker.cpp.

References sem_.

Referenced by save_blocker().

◆ on_unblock()

void save_blocker::on_unblock ( play_controller controller,
void(play_controller::*)()  callback 
)
static

Definition at line 42 of file save_blocker.cpp.

References callback_, controller_, try_block(), and unblock().

◆ saves_are_blocked()

bool save_blocker::saves_are_blocked ( )
static

Definition at line 52 of file save_blocker.cpp.

References sem_.

◆ try_block()

bool save_blocker::try_block ( )
staticprotected

Definition at line 60 of file save_blocker.cpp.

References sem_.

Referenced by on_unblock().

◆ unblock()

void save_blocker::unblock ( )
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().

Friends And Related Function Documentation

◆ play_controller

friend class play_controller
friend

Definition at line 53 of file save_blocker.hpp.

Member Data Documentation

◆ callback_

void(play_controller::* save_blocker::callback_)() = nullptr
staticprivate

Definition at line 69 of file save_blocker.hpp.

Referenced by on_unblock(), and ~save_blocker().

◆ controller_

play_controller * save_blocker::controller_ = nullptr
staticprivate

Definition at line 68 of file save_blocker.hpp.

Referenced by on_unblock(), and ~save_blocker().

◆ sem_

SDL_sem * save_blocker::sem_ = SDL_CreateSemaphore(1)
staticprivate

Definition at line 70 of file save_blocker.hpp.

Referenced by block(), saves_are_blocked(), try_block(), and unblock().


The documentation for this class was generated from the following files: