The Battle for Wesnoth  1.13.4+dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
save_blocker.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2009 - 2016 by Daniel Franke.
3  Part of the Battle for Wesnoth Project http://www.wesnoth.org/
4 
5  This program is free software; you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation; either version 2 of the License, or
8  (at your option) any later version.
9  This program is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY.
11 
12  See the COPYING file for more details.
13 */
14 
15 #ifndef SAVE_BLOCKER_H_INCLUDED
16 #define SAVE_BLOCKER_H_INCLUDED
17 
18 #include <SDL_mutex.h>
19 
20 #include <cassert>
21 
22 class play_controller;
23 
24 /** While any instance of this class exists, attempts to save the game via
25  * any call to play_controller will be temporarily postponed: the call will
26  * return immediately without performing the save, but the save method will
27  * then be reinvoked from this class's destructor. If multiple save attempts
28  * are performed, only the last will be carried out.
29  */
30 
31 /**
32  * NOTE: This class is broken and you probably shouldn't use it. Calling a save
33  * game dialog from the destructor of a class is a bad idea, because those
34  * functions throw exceptions. For example if the user decides to quit the game,
35  * or there is a filesystem erorr. If the destructor throws exceptions, it will
36  * cause memory leaks and crashes.
37  * http://wiki.wesnoth.org/CodingStandards#Destructors_must_not_throw_exceptions
38  *
39  * As a temporary fix the destructor has been changed to swallow all exceptions.
40  * However this means that if the user attempts to quit the game from the savegame
41  * dialog, or any filesystem error occurs, it will be suppressed instead of being
42  * handled normally. So you should avoid using this class and it may be removed.
43  */
44 
45 class save_blocker {
46 public:
47  save_blocker();
48  ~save_blocker();
49  static bool saves_are_blocked();
50  static void on_unblock(play_controller* controller, void (play_controller::*callback)());
51 
52 protected:
53  friend class play_controller;
54  static void block();
55  static bool try_block();
56  static void unblock();
57 
58  /** An exception-safe means of making sure that unblock() gets called
59  * after try_block().
60  */
62  public:
65  };
66 
67 private:
70  static SDL_sem* sem_;
71 };
72 
73 #endif
GLvoid **typedef void(GLAPIENTRY *PFNGLGETVERTEXATTRIBDVPROC)(GLuint
Definition: glew.h:1806
While any instance of this class exists, attempts to save the game via any call to play_controller wi...
static void unblock()
static void on_unblock(play_controller *controller, void(play_controller::*callback)())
An exception-safe means of making sure that unblock() gets called after try_block().
static void(play_controller::* callback_)()
static bool saves_are_blocked()
static void block()
static play_controller * controller_
static SDL_sem * sem_
static bool try_block()