The Battle for Wesnoth  1.15.3+dev
game_config_view.cpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2013 - 2018 by Andrius Silinskas <silinskas.andrius@gmail.com>
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 #include "game_config_view.hpp"
15 #include "config.hpp"
16 #include "log.hpp"
17 
18 static lg::log_domain log_config("config");
19 #define ERR_CONFIG LOG_STREAM(err, log_config)
20 #define WRN_CONFIG LOG_STREAM(warn, log_config)
21 #define LOG_CONFIG LOG_STREAM(info, log_config)
22 
23 
25 {
27  for(const config& cfg : cfgs_) {
28  for (const config& child : cfg.child_range(key)) {
29  res.push_back(child);
30  }
31  }
32  return res;
33 }
34 
35 const config& game_config_view::find_child(config_key_type key, const std::string &name, const std::string &value) const
36 {
37  for(const config& cfg : cfgs_) {
38  if(const config& res = cfg.find_child(key, name, value)) {
39  return res;
40  }
41  }
42  LOG_CONFIG << "gcv : cannot find [" << key << "] with " << name << "=" << value << ", count = " << cfgs_.size() <<"\n";
43  const config cfg;
44  return cfg.child("invalid");
45 }
46 
48 {
49  for(const config& cfg : cfgs_) {
50  if(const config& res = cfg.child(key)) {
51  return res;
52  }
53  }
54  const config cfg;
55  return cfg.child("invalid");
56 }
57 
58 
60 {
61  for(const config& cfg : cfgs_) {
62  if(const config& res = cfg.child(key)) {
63  return res;
64  }
65  }
66  static const config cfg;
67  return cfg;
68 }
69 
71 {
72  game_config_view res;
73  for(const config& cfg : cfgs_) {
74 
75  for(const config& child : cfg.child_range(key)) {
76  res.cfgs_.push_back(child);
77  }
78  }
79  return res;
80 }
config & child(config_key_type key, int n=0)
Returns the nth child with the given key, or a reference to an invalid config if there is none...
Definition: config.cpp:420
config & find_child(config_key_type key, const std::string &name, const std::string &value)
Returns the first child of tag key with a name attribute containing value.
Definition: config.cpp:836
config_array_view child_range(config_key_type key) const
child_itors child_range(config_key_type key)
Definition: config.cpp:362
Definitions for the interface to Wesnoth Markup Language (WML).
static lg::log_domain log_config("config")
game_config_view merged_children_view(config_key_type key) const
const config & child_or_empty(config_key_type key) const
config_array_view cfgs_
const config & find_child(config_key_type key, const std::string &name, const std::string &value) const
std::vector< std::reference_wrapper< const config > > config_array_view
boost::string_ref config_key_type
Definition: config.hpp:57
Standard logging facilities (interface).
#define LOG_CONFIG
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:68
const config & child(config_key_type key) const