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