wesnoth/src/quit_confirmation.hpp
Charles Dang 2101353d36 Convert include guards to the shorter #pragma once
Turns out I mistook @celticminstrel's opinion that we should use include guards over pragma (737916e).
Since all major compilers support `#pragma once`, there's no reason not to use it.

For future mergability reasons, this excludes src/spirit_po and src/xBRZ. It also excludes src/boost-patched.
2017-05-09 19:41:37 +11:00

59 lines
1.6 KiB
C++

/*
Copyright (C) 2015 - 2017 by the Battle for Wesnoth Project
<http://www.wesnoth.org/>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY.
See the COPYING file for more details.
*/
#pragma once
class CVideo;
#include <cassert>
#include <vector>
#include "utils/functional.hpp"
/**
* Implements a quit confirmation dialog.
*
* Any object of this type will prevent the game from quitting immediately.
* Instead, a confirmation dialog will pop up when attempting to close.
*/
class quit_confirmation
{
public:
explicit quit_confirmation(const std::function<bool()>& prompt = &quit_confirmation::default_prompt)
: prompt_(prompt) { blockers_.push_back(this); }
~quit_confirmation() { blockers_.pop_back(); }
/**
* Shows the quit confirmation if needed.
*
* @throws CVideo::quit If the user chooses to quit or no prompt was
* displayed.
*/
static bool quit();
static void quit_to_title();
static void quit_to_desktop();
static bool show_prompt(const std::string& message);
static bool default_prompt();
private:
// noncopyable
quit_confirmation(const quit_confirmation&) = delete;
const quit_confirmation& operator=(const quit_confirmation&) = delete;
static std::vector<quit_confirmation*> blockers_;
static bool open_;
std::function<bool()> prompt_;
};