The Battle for Wesnoth  1.15.6+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 #include <boost/range/iterator_range.hpp>
19 
20 static lg::log_domain log_config("config");
21 #define ERR_CONFIG LOG_STREAM(err, log_config)
22 #define WRN_CONFIG LOG_STREAM(warn, log_config)
23 #define LOG_CONFIG LOG_STREAM(info, log_config)
24 
25 
27 {
29  if(cfgs_.size() <= 1 || key != "terrain_graphics") {
30  for(const config& cfg : cfgs_) {
31  for (const config& child : cfg.child_range(key)) {
32  res.push_back(child);
33  }
34  }
35  }
36  else {
37  //use mainline [terrain_graphics] last. cfgs_.front() is the main game configs while the later ones are add-ons.
38  for(const config& cfg : boost::make_iterator_range(cfgs_.begin() + 1, cfgs_.end())) {
39  for (const config& child : cfg.child_range(key)) {
40  res.push_back(child);
41  }
42  }
43  for (const config& child : cfgs_.front().get().child_range(key)) {
44  res.push_back(child);
45  }
46  }
47  return res;
48 }
49 
51 {
52  for(const config& cfg : cfgs_) {
53  if(const config& res = cfg.find_child(key, name, value)) {
54  return res;
55  }
56  }
57  LOG_CONFIG << "gcv : cannot find [" << key << "] with " << name << "=" << value << ", count = " << cfgs_.size() <<"\n";
58  const config cfg;
59  return cfg.child("invalid");
60 }
61 
63 {
64  for(const config& cfg : cfgs_) {
65  if(const config& res = cfg.child(key)) {
66  return res;
67  }
68  }
69  const config cfg;
70  return cfg.child("invalid");
71 }
72 
73 
75 {
76  for(const config& cfg : cfgs_) {
77  if(const config& res = cfg.child(key)) {
78  return res;
79  }
80  }
81  static const config cfg;
82  return cfg;
83 }
84 
86 {
87  game_config_view res;
88  for(const config& cfg : cfgs_) {
89 
90  for(const config& child : cfg.child_range(key)) {
91  res.cfgs_.push_back(child);
92  }
93  }
94  return res;
95 }
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
std::string name
Definition: sdl_ttf.cpp:70
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