The Battle for Wesnoth  1.19.7+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 #include <utility>
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.";
41  }
42 }
43 
44 std::map<std::string, registered_widget_parser>& registered_widget_types()
45 {
46  static std::map<std::string, registered_widget_parser> 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] = {std::move(f), key};
53 }
54 
55 std::map<std::string, widget_builder_func_t>& widget_builder_lookup()
56 {
57  static std::map<std::string, widget_builder_func_t> 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.
#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