The Battle for Wesnoth  1.17.0-dev
binary_or_text.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2003 - 2021
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 
15 #pragma once
16 
17 #include "config.hpp"
18 #include "preprocessor.hpp"
20 #include "serialization/parser.hpp"
21 
22 #include <boost/iostreams/filtering_stream.hpp>
23 
24 /** Class for writing a config out to a file in pieces. */
26 {
27 public:
28  config_writer(std::ostream &out, compression::format compress);
29  config_writer(std::ostream &out, bool compress, int level = -1);
30  /** Default implementation, but defined out-of-line for efficiency reasons. */
32 
33  void write(const config &cfg);
34 
35  void write_child(const std::string &key, const config &cfg);
36  void open_child(const std::string &key);
37  void close_child(const std::string &key);
38  bool good() const;
39 
40  /** This template function will work with any type that can be assigned to an attribute_value. */
41  template <typename T>
42  void write_key_val(const std::string &key, const T &value)
43  {
45  v = value;
47  }
48 
49 private:
50  boost::iostreams::filtering_stream<boost::iostreams::output> filter_;
51  std::ostream *out_ptr_;
52  std::ostream &out_;
54  unsigned int level_;
55  std::string textdomain_;
56 };
bool good() const
void write(const config &cfg)
config_writer(std::ostream &out, compression::format compress)
Variant for storing WML attributes.
std::string textdomain_
compression::format compress_
Definitions for the interface to Wesnoth Markup Language (WML).
unsigned int level_
void write_child(const std::string &key, const config &cfg)
void write_key_val(const std::string &key, const T &value)
This template function will work with any type that can be assigned to an attribute_value.
void close_child(const std::string &key)
std::ostream & out_
Class for writing a config out to a file in pieces.
void open_child(const std::string &key)
~config_writer()
Default implementation, but defined out-of-line for efficiency reasons.
std::ostream * out_ptr_
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:59
boost::iostreams::filtering_stream< boost::iostreams::output > filter_