The Battle for Wesnoth  1.19.0-dev
synced_commands.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2014 - 2024
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 <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)
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:159
synced_command(const std::string &tag, handler function)
static map & registry()
using static function variable instead of static member variable to prevent static initialization fia...
bool(* handler)(const config &, bool use_undo, bool show, error_handler_function error_handler)
std::function< void(const std::string &)> error_handler_function
std::map< std::string, handler > map
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:79