The Battle for Wesnoth  1.13.4+dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
binary_or_text.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2003 by David White <[email protected]>
3  Copyright (C) 2005 - 2016 by Guillaume Melquiond <[email protected]>
4  Part of the Battle for Wesnoth Project http://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 #ifndef SERIALIZATION_BINARY_OR_TEXT_HPP_INCLUDED
19 #define SERIALIZATION_BINARY_OR_TEXT_HPP_INCLUDED
20 
21 #include "config.hpp"
22 #include "preprocessor.hpp"
24 #include "serialization/parser.hpp"
25 
26 #include <boost/iostreams/filtering_stream.hpp>
27 
28 /** Class for writing a config out to a file in pieces. */
30 {
31 public:
32  config_writer(std::ostream &out, compression::format compress);
33  config_writer(std::ostream &out, bool compress, int level = -1);
34  /** Default implementation, but defined out-of-line for efficiency reasons. */
36 
37  void write(const config &cfg);
38 
39  void write_child(const std::string &key, const config &cfg);
40  void open_child(const std::string &key);
41  void close_child(const std::string &key);
42  bool good() const;
43 
44  /// This template function will work with any type that can be assigned to
45  /// an attribute_value.
46  template <typename T>
47  void write_key_val(const std::string &key, const T &value)
48  {
50  v = value;
52  }
53 
54 private:
55  boost::iostreams::filtering_stream<boost::iostreams::output> filter_;
56  std::ostream *out_ptr_;
57  std::ostream &out_;
59  unsigned int level_;
61 };
62 
63 #endif
bool good() const
void write(const config &cfg)
GLint level
Definition: glew.h:1220
config_writer(std::ostream &out, compression::format compress)
std::string textdomain_
compression::format compress_
Definitions for the interface to Wesnoth Markup Language (WML).
Variant for storing WML attributes.
Definition: config.hpp:223
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.
const GLdouble * v
Definition: glew.h:1359
GLsizei const GLfloat * value
Definition: glew.h:1817
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:83
GLsizei const GLcharARB ** string
Definition: glew.h:4503
boost::iostreams::filtering_stream< boost::iostreams::output > filter_