The Battle for Wesnoth  1.17.0-dev
static_registry.cpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2008 - 2021
3  by Mark de Wever <koraq@xs4all.nl>
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 
17 
18 #include "gui/core/log.hpp"
19 #include <functional>
20 
21 #include <map>
22 #include <set>
23 #include <string>
24 #include <tuple>
25 
26 namespace gui2
27 {
28 std::set<std::string>& registered_window_types()
29 {
30  static std::set<std::string> result;
31  return result;
32 }
33 
34 void register_window(const std::string& id)
35 {
36  bool added = false;
37  std::tie(std::ignore, added) = registered_window_types().emplace(id);
38 
39  if(!added) {
40  WRN_GUI_P << "Window '" << id << "' already registered. Ignoring." << std::endl;
41  }
42 }
43 
45 {
46  static registered_widget_map result;
47  return result;
48 }
49 
50 void register_widget(const std::string& type, widget_parser_t f, const char* key)
51 {
52  registered_widget_types()[type] = {f, key};
53 }
54 
56 {
57  static widget_builder_map result;
58  return result;
59 }
60 
61 void register_widget_builder(const std::string& type, widget_builder_func_t functor)
62 {
63  widget_builder_lookup().emplace(type, functor);
64 }
65 
66 } // namespace gui2
Define the common log macros for the gui toolkit.
void register_window(const std::string &id)
Registers a window.
std::map< std::string, widget_builder_func_t > widget_builder_map
std::function< styled_widget_definition_ptr(const config &)> widget_parser_t
Function type alias for register_widget.
std::function< builder_widget_ptr(const config &)> widget_builder_func_t
Function type alias for register_widget_builder.
Generic file dialog.
Definition: field-fwd.hpp:23
void register_widget(const std::string &type, widget_parser_t f, const char *key)
Registers a widget type.
registered_widget_map & registered_widget_types()
Returns the list of registered widgets and their parsers.
#define WRN_GUI_P
Definition: log.hpp:68
widget_builder_map & widget_builder_lookup()
Returns the list of registered widget builders.
#define f
void register_widget_builder(const std::string &type, widget_builder_func_t functor)
Registers a widget builder.
std::map< std::string, registered_widget_parser > registered_widget_map
std::set< std::string > & registered_window_types()
Returns the list of registered windows.