The Battle for Wesnoth  1.15.0-dev
static_registry.cpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2008 - 2018 by Mark de Wever <koraq@xs4all.nl>
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 
16 
17 #include "gui/core/log.hpp"
18 #include "utils/functional.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." << std::endl;
40  }
41 }
42 
44 {
45  static registered_widget_map 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 
55 {
56  static widget_builder_map 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.
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:22
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:70
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.