The Battle for Wesnoth  1.15.13+dev
synced_commands.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2014 - 2018 by David White <dave@whitevine.net>
3  Part of the Battle for Wesnoth Project https://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 #pragma once
16 
17 #include <map>
18 #include <exception>
19 #include <string>
20 
21 #include <functional>
22 
23 class config;
24 
26  public:
27  /*
28  the parameters or error handlers are
29  1) the message of the error
30  */
31  typedef std::function<void(const std::string&)> error_handler_function;
32  /*
33  returns: true if the action succeeded correctly,
34  */
35  typedef bool (*handler)(const config &, bool use_undo, bool show, error_handler_function error_handler);
36  typedef std::map<std::string, handler> map;
37 
38 
39  synced_command(const std::string & tag, handler function);
40 
41  /** using static function variable instead of static member variable to prevent static initialization fiasco when used in other files. */
42  static map& registry();
43  };
44 
45 /*
46  this is currently only used in "synced_commands.cpp" and there is no reason to use it anywhere else.
47  but if you have a good reason feel free to do so.
48 */
49 
50 #define SYNCED_COMMAND_HANDLER_FUNCTION(pname, pcfg, use_undo, show, error_handler) \
51  static bool synced_command_func_##pname(const config & pcfg, bool use_undo, bool show, synced_command::error_handler_function error_handler ); \
52  static synced_command synced_command_action_##pname(#pname, &synced_command_func_##pname); \
53  static bool synced_command_func_##pname(const config & pcfg, bool use_undo, bool show, synced_command::error_handler_function error_handler)
static map & registry()
using static function variable instead of static member variable to prevent static initialization fia...
synced_command(const std::string &tag, handler function)
std::map< std::string, handler > map
bool(* handler)(const config &, bool use_undo, bool show, error_handler_function error_handler)
std::function< void(const std::string &)> error_handler_function
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:59
void show(const std::string &window_id, const t_string &message, const point &mouse, const SDL_Rect &source_rect)
Shows a tip.
Definition: tooltip.cpp:139