The Battle for Wesnoth  1.15.1+dev
linked_group_definition.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 https://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 "formula/string_utils.hpp"
18 #include "wml_exception.hpp"
19 
20 namespace gui2
21 {
22 
23 std::vector<linked_group_definition> parse_linked_group_definitions(const config& cfg)
24 {
25  std::vector<linked_group_definition> definitions;
26 
27  for(const auto& lg : cfg.child_range("linked_group")) {
28  definitions.emplace_back();
29  linked_group_definition& linked_group = definitions.back();
30 
31  linked_group.id = lg["id"].str();
32  linked_group.fixed_width = lg["fixed_width"].to_bool();
33  linked_group.fixed_height = lg["fixed_height"].to_bool();
34 
35  VALIDATE(!linked_group.id.empty(), missing_mandatory_wml_key("linked_group", "id"));
36 
37  if(!linked_group.fixed_width && !linked_group.fixed_height) {
38  const t_string msg = VGETTEXT(
39  "Linked group '$id' needs a 'fixed_width' or 'fixed_height' key.", {{"id", linked_group.id}});
40 
41  FAIL(msg);
42  }
43  }
44 
45  return definitions;
46 }
47 
48 }
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:362
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: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.
Generic file dialog.
Definition: field-fwd.hpp:22
#define VALIDATE(cond, message)
The macro to use for the validation of WML.
Definition: pump.hpp:39
#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:92