The Battle for Wesnoth  1.19.5+dev
game_config_view.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2013 - 2024
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 
25 /**
26  * A class grating read only view to a vector of config objects, viewed as one config
27  * with all children appended, used by the game_config class to read data from addons
28  * config, and from the main config.
29  **/
31 {
32 
33 public:
35  {}
36 
37  static game_config_view wrap(const config& cfg)
38  {
39  return game_config_view(cfg);
40  }
41 
43 
44  optional_const_config find_child(config_key_type key, const std::string &name, const std::string &value) const;
45  const config& find_mandatory_child(config_key_type key, const std::string &name, const std::string &value) const;
46 
47  // const config& child(config_key_type key) const;
48  const config& mandatory_child(config_key_type key) const;
50 
51  const config& child_or_empty(config_key_type key) const;
52 
54 
55 
57  {
58  return cfgs_;
59  }
60 
61 private:
62 
63  explicit game_config_view(const config& cfg)
64  : cfgs_()
65  {
66  cfgs_.push_back(cfg);
67  }
69 };
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:172
A class grating read only view to a vector of config objects, viewed as one config with all children ...
const config & child_or_empty(config_key_type key) const
config_array_view cfgs_
const config & mandatory_child(config_key_type key) const
game_config_view(const config &cfg)
optional_const_config optional_child(config_key_type key) const
optional_const_config find_child(config_key_type key, const std::string &name, const std::string &value) const
static game_config_view wrap(const config &cfg)
config_array_view child_range(config_key_type key) const
config_array_view & data()
const config & find_mandatory_child(config_key_type key, const std::string &name, const std::string &value) const
game_config_view merged_children_view(config_key_type key) const
Definitions for the interface to Wesnoth Markup Language (WML).
std::string_view config_key_type
Definition: config.hpp:62
std::vector< std::reference_wrapper< const config > > config_array_view