The Battle for Wesnoth  1.17.14+dev
game_config_view.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2013 - 2022
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  static game_config_view wrap(const config& cfg)
33  {
34  return game_config_view(cfg);
35  }
36 
38 
39  const config& find_child(config_key_type key, const std::string &name, const std::string &value) const;
40 
41  const config& child(config_key_type key) const;
42 
43  const config& child_or_empty(config_key_type key) const;
44 
46 
47 
49  {
50  return cfgs_;
51  }
52 
53 private:
54 
55  explicit game_config_view(const config& cfg)
56  : cfgs_()
57  {
58  cfgs_.push_back(cfg);
59  }
61 };
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