The Battle for Wesnoth  1.19.0-dev
binary_or_text.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2005 - 2024
3  by Guillaume Melquiond <guillaume.melquiond@gmail.com>
4  Copyright (C) 2003 by David White <dave@whitevine.net>
5  Part of the Battle for Wesnoth Project https://www.wesnoth.org/
6 
7  This program is free software; you can redistribute it and/or modify
8  it under the terms of the GNU General Public License as published by
9  the Free Software Foundation; either version 2 of the License, or
10  (at your option) any later version.
11  This program is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY.
13 
14  See the COPYING file for more details.
15 */
16 
17 #pragma once
18 
19 #include "config.hpp"
21 #include "serialization/parser.hpp"
22 
23 #include <boost/iostreams/filtering_stream.hpp>
24 
25 /** Class for writing a config out to a file in pieces. */
27 {
28 public:
29  config_writer(std::ostream &out, compression::format compress);
30  config_writer(std::ostream &out, bool compress, int level = -1);
31  /** Default implementation, but defined out-of-line for efficiency reasons. */
33 
34  void write(const config &cfg);
35 
36  void write_child(const std::string &key, const config &cfg);
37  void open_child(const std::string &key);
38  void close_child(const std::string &key);
39  bool good() const;
40 
41  /** This template function will work with any type that can be assigned to an attribute_value. */
42  template <typename T>
43  void write_key_val(const std::string &key, const T &value)
44  {
46  v = value;
48  }
49 
50 private:
51  boost::iostreams::filtering_stream<boost::iostreams::output> filter_;
52  std::ostream *out_ptr_;
53  std::ostream &out_;
55  unsigned int level_;
56  std::string textdomain_;
57 };
Variant for storing WML attributes.
Class for writing a config out to a file in pieces.
boost::iostreams::filtering_stream< boost::iostreams::output > filter_
void close_child(const std::string &key)
bool good() const
unsigned int level_
void write(const config &cfg)
std::ostream * out_ptr_
~config_writer()
Default implementation, but defined out-of-line for efficiency reasons.
std::ostream & out_
void write_child(const std::string &key, const config &cfg)
std::string textdomain_
compression::format compress_
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.
config_writer(std::ostream &out, compression::format compress)
void open_child(const std::string &key)
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:159