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