The Battle for Wesnoth  1.17.0-dev
linked_group_definition.cpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2008 - 2021
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 }
Add a special kind of assert to validate whether the input from WML doesn&#39;t contain any problems that...
child_itors child_range(config_key_type key)
Definition: config.cpp:344
std::vector< linked_group_definition > parse_linked_group_definitions(const config &cfg)
static void msg(const char *act, debug_info &i, const char *to="", const char *result="")
Definition: debugger.cpp:110
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.
Generic file dialog.
Definition: field-fwd.hpp:23
#define VALIDATE(cond, message)
The macro to use for the validation of WML.
Definition: pump.hpp:40
#define VGETTEXT(msgid,...)
Handy wrappers around interpolate_variables_into_string and gettext.
#define FAIL(message)
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:61