The Battle for Wesnoth  1.17.0-dev
game_config_view.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2013 - 2021
3  by Andrius Silinskas <silinskas.andrius@gmail.com>
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 
16 #pragma once
17 
18 #include "config.hpp"
19 
20 #include <functional>
21 #include <vector>
22 
23 using config_array_view = std::vector<std::reference_wrapper<const config>>;
24 
26 {
27 
28 public:
30  {
31 
32  }
33 
34  static game_config_view wrap(const config& cfg) {
35  return game_config_view(cfg);
36  }
37 
39 
40  const config& find_child(config_key_type key, const std::string &name, const std::string &value) const;
41 
42  const config& child(config_key_type key) const;
43 
44  const config& child_or_empty(config_key_type key) const;
45 
47 
48 
50  {
51  return cfgs_;
52  }
53 
54 private:
55 
56  explicit game_config_view(const config& cfg)
57  : cfgs_()
58  {
59  cfgs_.push_back(cfg);
60  }
62 };
static game_config_view wrap(const config &cfg)
config_array_view child_range(config_key_type key) const
Definitions for the interface to Wesnoth Markup Language (WML).
std::string_view config_key_type
Definition: config.hpp:50
game_config_view(const config &cfg)
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
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:60
config_array_view & data()
const config & child(config_key_type key) const