wesnoth/src/synced_commands.hpp
Charles Dang 0ca4e6c943 Convert uses of boost functional to standard library variants
This commit converts the following function calls:

* boost::bind                          -> std::bind
* boost::function and boost::functionN -> std::function
* boost::ref and boost::cref           -> std::ref and std::cref
* boost::bad_function_call             -> std::bad_function_call

In the process, it was discovered that std::bind has trouble with overloaded
functions. There were two such cases in the code:

* gui2::twindow had an ancient unused overload to draw(). The overload was removed.
* gui2::trepeating_button was binding tdispatcher::fire. This case was converted
  to a lambda.
2016-04-04 02:20:52 +11:00

59 lines
2.1 KiB
C++

/*
Copyright (C) 2014 - 2016 by David White <dave@whitevine.net>
Part of 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.
*/
#ifndef SYNCED_COMMANDS_H_INCLUDED
#define SYNCED_COMMANDS_H_INCLUDED
#include <map>
#include <exception>
#include "utils/functional.hpp"
class config;
class synced_command {
public:
/*
the parameters or error handlers are
1) the message of the error
2) a boolean that indicates whether the error is heavy enough to make proceeding impossible.
TODO: remove the second argument because it isn't used.
*/
typedef std::function<void(const std::string&, bool)> error_handler_function;
/*
returns: true if the action succeeded correclty,
*/
typedef bool (*handler)(const config &, bool use_undo, bool show, error_handler_function error_handler);
typedef std::map<std::string, handler> map;
synced_command(const std::string & tag, handler function);
/// using static function variable instead of static member variable to prevent static initialization fiasco when used in other files.
static map& registry();
};
/*
this is currently only used in "synced_commands.cpp" and there is no reason to use it anywhere else.
but if you have a good reason feel free to do so.
*/
#define SYNCED_COMMAND_HANDLER_FUNCTION(pname, pcfg, use_undo, show, error_handler) \
static bool synced_command_func_##pname(const config & pcfg, bool use_undo, bool show, synced_command::error_handler_function error_handler ); \
static synced_command synced_command_action_##pname(#pname, &synced_command_func_##pname); \
static bool synced_command_func_##pname(const config & pcfg, bool use_undo, bool show, synced_command::error_handler_function error_handler)
#endif