The Battle for Wesnoth  1.19.0+dev
linked_group_definition.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 "formula/string_utils.hpp"
19 #include "wml_exception.hpp"
20 
21 namespace gui2
22 {
23 
24 std::vector<linked_group_definition> parse_linked_group_definitions(const config& cfg)
25 {
26  std::vector<linked_group_definition> definitions;
27 
28  for(const auto& lg : cfg.child_range("linked_group")) {
29  definitions.emplace_back();
30  linked_group_definition& linked_group = definitions.back();
31 
32  linked_group.id = lg["id"].str();
33  linked_group.fixed_width = lg["fixed_width"].to_bool();
34  linked_group.fixed_height = lg["fixed_height"].to_bool();
35 
36  VALIDATE(!linked_group.id.empty(), missing_mandatory_wml_key("linked_group", "id"));
37 
38  if(!linked_group.fixed_width && !linked_group.fixed_height) {
39  const t_string msg = VGETTEXT(
40  "Linked group '$id' needs a 'fixed_width' or 'fixed_height' key.", {{"id", linked_group.id}});
41 
42  FAIL(msg);
43  }
44  }
45 
46  return definitions;
47 }
48 
49 }
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:159
child_itors child_range(config_key_type key)
Definition: config.cpp:273
#define VGETTEXT(msgid,...)
Handy wrappers around interpolate_variables_into_string and gettext.
Generic file dialog.
std::vector< linked_group_definition > parse_linked_group_definitions(const config &cfg)
Definition: pump.hpp:41
static void msg(const char *act, debug_info &i, const char *to="", const char *result="")
Definition: debugger.cpp:109
std::string missing_mandatory_wml_key(const std::string &section, const std::string &key, const std::string &primary_key, const std::string &primary_value)
Returns a standard message for a missing wml key (attribute).
Add a special kind of assert to validate whether the input from WML doesn't contain any problems that...
#define FAIL(message)
#define VALIDATE(cond, message)
The macro to use for the validation of WML.