The Battle for Wesnoth  1.15.1+dev
binary_or_text.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2003 by David White <dave@whitevine.net>
3  Copyright (C) 2005 - 2018 by Guillaume Melquiond <guillaume.melquiond@gmail.com>
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 /** @file */
17 
18 #pragma once
19 
20 #include "config.hpp"
21 #include "preprocessor.hpp"
23 #include "serialization/parser.hpp"
24 
25 #include <boost/iostreams/filtering_stream.hpp>
26 
27 /** Class for writing a config out to a file in pieces. */
29 {
30 public:
31  config_writer(std::ostream &out, compression::format compress);
32  config_writer(std::ostream &out, bool compress, int level = -1);
33  /** Default implementation, but defined out-of-line for efficiency reasons. */
35 
36  void write(const config &cfg);
37 
38  void write_child(const std::string &key, const config &cfg);
39  void open_child(const std::string &key);
40  void close_child(const std::string &key);
41  bool good() const;
42 
43  /// This template function will work with any type that can be assigned to
44  /// an attribute_value.
45  template <typename T>
46  void write_key_val(const std::string &key, const T &value)
47  {
49  v = value;
51  }
52 
53 private:
54  boost::iostreams::filtering_stream<boost::iostreams::output> filter_;
55  std::ostream *out_ptr_;
56  std::ostream &out_;
58  unsigned int level_;
59  std::string textdomain_;
60 };
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:92
boost::iostreams::filtering_stream< boost::iostreams::output > filter_