The Battle for Wesnoth  1.13.4+dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
synced_commands.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2014 - 2016 by David White <[email protected]>
3  Part of the Battle for Wesnoth Project http://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 #ifndef SYNCED_COMMANDS_H_INCLUDED
15 #define SYNCED_COMMANDS_H_INCLUDED
16 
17 #include <map>
18 #include <exception>
19 
20 #include "utils/functional.hpp"
21 
22 class config;
23 
25  public:
26  /*
27  the parameters or error handlers are
28  1) the message of the error
29  2) a boolean that indicates whether the error is heavy enough to make proceeding impossible.
30  TODO: remove the second argument because it isn't used.
31 
32  */
33  typedef std::function<void(const std::string&, bool)> error_handler_function;
34  /*
35  returns: true if the action succeeded correclty,
36 
37  */
38  typedef bool (*handler)(const config &, bool use_undo, bool show, error_handler_function error_handler);
39  typedef std::map<std::string, handler> map;
40 
41 
42  synced_command(const std::string & tag, handler function);
43 
44  /// using static function variable instead of static member variable to prevent static initialization fiasco when used in other files.
45  static map& registry();
46  };
47 
48 /*
49  this is currently only used in "synced_commands.cpp" and there is no reason to use it anywhere else.
50  but if you have a good reason feel free to do so.
51 */
52 
53 #define SYNCED_COMMAND_HANDLER_FUNCTION(pname, pcfg, use_undo, show, error_handler) \
54  static bool synced_command_func_##pname(const config & pcfg, bool use_undo, bool show, synced_command::error_handler_function error_handler ); \
55  static synced_command synced_command_action_##pname(#pname, &synced_command_func_##pname); \
56  static bool synced_command_func_##pname(const config & pcfg, bool use_undo, bool show, synced_command::error_handler_function error_handler)
57 
58 #endif
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)
void show(CVideo &video, const std::string &window_id, const t_string &message, const tpoint &mouse)
Shows a tip.
Definition: tip.cpp:133
std::function< void(const std::string &, bool)> error_handler_function
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:83
GLsizei const GLcharARB ** string
Definition: glew.h:4503