Пример #1
0
tbuilder_widget_ptr create_builder_widget2(const std::string& type, const config& cfg)
{
	std::map<std::string, boost::function<tbuilder_widget_ptr(config)> >::const_iterator it =
		builder_widget_lookup().find(type);
	VALIDATE(it != builder_widget_lookup().end(), "Unknown widget!");
	return it->second(cfg);
}
Пример #2
0
void register_builder_widget(const std::string& id
		, boost::function<tbuilder_widget_ptr(config)> functor)
{
	builder_widget_lookup().insert(std::make_pair(id, functor));
}
Пример #3
0
tbuilder_widget_ptr create_builder_widget(const config& cfg)
{
	config::all_children_itors children = cfg.all_children_range();
	size_t nb_children = std::distance(children.first, children.second);
	VALIDATE(nb_children == 1, "Grid cell does not have exactly 1 child.");

	for(const auto & item : builder_widget_lookup())
	{
		if(item.first == "window" || item.first == "tooltip") {
			continue;
		}
		if(const config& c = cfg.child(item.first)) {
			return item.second(c);
		}
	}

	if(const config& c = cfg.child("grid")) {
		return new tbuilder_grid(c);
	}

	if(const config& instance = cfg.child("instance")) {
		return new implementation::tbuilder_instance(instance);
	}

	if(const config& pane = cfg.child("pane")) {
		return new implementation::tbuilder_pane(pane);
	}

	if(const config& viewport = cfg.child("viewport")) {
		return new implementation::tbuilder_viewport(viewport);
	}

/*
 * This is rather odd, when commented out the classes no longer seem to be in
 * the executable, no real idea why, except maybe of an overzealous optimizer
 * while linking. It seems that all these classes aren't explicitly
 * instantiated but only implicitly. Also when looking at the symbols in
 * libwesnoth-game.a the repeating button is there regardless of this #if but
 * in the final binary only if the #if is enabled.
 *
 * If this code is executed, which it will cause an assertion failure.
 *
 * Its likeley that this happens becasue some build this as a library file
 * which is then used by the wesnoth executable. For msvc a good try to fix
 * this issue is to add __pragma(comment(linker, "/include:" #TYPE)) or
 * similar in the REGISTER_WIDGET3 macro. For gcc and similar this can only
 * be fixed by using --whole-archive flag when linking this library.
 */
#if 1
#define TRY(name)                                                              \
	do {                                                                       \
		if(const config& c = cfg.child(#name)) {                               \
			tbuilder_widget_ptr p = new implementation::tbuilder_##name(c);    \
			assert(false);                                                     \
		}                                                                      \
	} while(0)

	TRY(stacked_widget);
	TRY(scrollbar_panel);
	TRY(horizontal_scrollbar);
	TRY(repeating_button);
	TRY(vertical_scrollbar);
	TRY(label);
	TRY(image);
	TRY(toggle_button);
	TRY(slider);
	TRY(scroll_label);
	TRY(matrix);
	TRY(minimap);
	TRY(button);
	TRY(combobox);
	TRY(drawing);
	TRY(password_box);
	TRY(unit_preview_pane);
#undef TRY
#endif

	std::cerr << cfg;
	ERROR_LOG(false);
}