The Battle for Wesnoth  1.17.0-dev
synced_commands.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2014 - 2021
3  by David White <dave@whitevine.net>
4  Part of the Battle for Wesnoth Project https://www.wesnoth.org/
5 
6  This program is free software; you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation; either version 2 of the License, or
9  (at your option) any later version.
10  This program is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY.
12 
13  See the COPYING file for more details.
14 */
15 
16 #pragma once
17 
18 #include <map>
19 #include <exception>
20 #include <string>
21 
22 #include <functional>
23 
24 class config;
25 
27  public:
28  /*
29  the parameters or error handlers are
30  1) the message of the error
31  */
32  typedef std::function<void(const std::string&)> error_handler_function;
33  /*
34  returns: true if the action succeeded correctly,
35  */
36  typedef bool (*handler)(const config &, bool use_undo, bool show, error_handler_function error_handler);
37  typedef std::map<std::string, handler> map;
38 
39 
40  synced_command(const std::string & tag, handler function);
41 
42  /** using static function variable instead of static member variable to prevent static initialization fiasco when used in other files. */
43  static map& registry();
44  };
45 
46 /*
47  this is currently only used in "synced_commands.cpp" and there is no reason to use it anywhere else.
48  but if you have a good reason feel free to do so.
49 */
50 
51 #define SYNCED_COMMAND_HANDLER_FUNCTION(pname, pcfg, use_undo, show, error_handler) \
52  static bool synced_command_func_##pname(const config & pcfg, bool use_undo, bool show, synced_command::error_handler_function error_handler ); \
53  static synced_command synced_command_action_##pname(#pname, &synced_command_func_##pname); \
54  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:61
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:140