The Battle for Wesnoth  1.15.0+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 #include <boost/variant.hpp>
19 
20 //Similar to config_of but it stores references to configs (instead of cyoping them).
21 struct configr_of
22 {
23  template <typename AT>
24  configr_of(const std::string& attrname, AT value) : subtags_(), data_()
25  {
26  this->operator()(attrname, value);
27  }
28 
29  configr_of(const config& cfg) : subtags_(), data_()
30  {
31  this->operator()(cfg);
32  }
33 
35  {
36  data_ = &cfg;
37  return *this;
38  }
39 
40  configr_of& operator()(const std::string& tagname, const configr_of& child)
41  {
42  subtags_.emplace_back(&tagname, &child);
43  return *this;
44  }
45  std::vector<std::pair<const std::string*, const configr_of*>> subtags_;
46  const config* data_;
47 };
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:92