The Battle for Wesnoth  1.19.1+dev
configr_assign.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2014 - 2024
3  by David White <dave@whitevine.net>
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 <string>
19 #include "config.hpp"
20 
21 //Similar to config_of but it stores references to configs (instead of cyoping them).
22 struct configr_of
23 {
24  template <typename AT>
25  configr_of(const std::string& attrname, AT value) : subtags_(), data_()
26  {
27  this->operator()(attrname, value);
28  }
29 
30  configr_of(const config& cfg) : subtags_(), data_()
31  {
32  this->operator()(cfg);
33  }
34 
36  {
37  data_ = &cfg;
38  return *this;
39  }
40 
41  configr_of& operator()(const std::string& tagname, const configr_of& child)
42  {
43  subtags_.emplace_back(&tagname, &child);
44  return *this;
45  }
46  std::vector<std::pair<const std::string*, const configr_of*>> subtags_;
47  const config* data_;
48 };
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:159
configr_of(const config &cfg)
std::vector< std::pair< const std::string *, const configr_of * > > subtags_
configr_of(const std::string &attrname, AT value)
configr_of & operator()(const config &cfg)
configr_of & operator()(const std::string &tagname, const configr_of &child)
const config * data_