The Battle for Wesnoth
1.13.4+dev
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
Modules
Pages
serialization
binary_or_text.cpp
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
/**
17
* @file
18
* Read/Write file in binary (compressed) or text-format (uncompressed).
19
*/
20
21
#include "
global.hpp
"
22
23
#include "
binary_or_text.hpp
"
24
#include "
config.hpp
"
25
#include "
log.hpp
"
26
#include "
wesconfig.h
"
27
#include "
serialization/parser.hpp
"
28
29
30
#include <boost/iostreams/filter/bzip2.hpp>
31
#include <boost/iostreams/filter/gzip.hpp>
32
33
static
lg::log_domain
log_config
(
"config"
);
34
#define ERR_CF LOG_STREAM(err, log_config)
35
36
config_writer::config_writer
(
37
std::ostream &out,
compression::format
compress) :
38
filter_
(),
39
out_ptr_(compress ? &
filter_
: &out),
//ternary indirection creates a temporary
40
out_(*out_ptr_),
//now MSVC will allow binding to the reference member
41
compress_(compress),
42
level_(0),
43
textdomain_(
PACKAGE
)
44
{
45
if
(
compress_
==
compression::GZIP
) {
46
filter_
.push(boost::iostreams::gzip_compressor(boost::iostreams::gzip_params(9)));
47
filter_
.push(out);
48
49
}
else
if
(
compress_
==
compression::BZIP2
) {
50
filter_
.push(boost::iostreams::bzip2_compressor(boost::iostreams::bzip2_params()));
51
filter_
.push(out);
52
}
53
}
54
config_writer::config_writer
(
55
std::ostream &out,
bool
compress,
int
level
) :
56
filter_
(),
57
out_ptr_(compress ? &
filter_
: &out),
//ternary indirection creates a temporary
58
out_(*out_ptr_),
//now MSVC will allow binding to the reference member
59
compress_(compress ?
compression
::
GZIP
:
compression
::
NONE
),
60
level_(0),
61
textdomain_(
PACKAGE
)
62
{
63
if
(
compress_
) {
64
if
(level >=0)
65
filter_
.push(boost::iostreams::gzip_compressor(boost::iostreams::gzip_params(level)));
66
else
67
filter_
.push(boost::iostreams::gzip_compressor(boost::iostreams::gzip_params()));
68
69
filter_
.push(out);
70
}
71
}
72
73
config_writer::~config_writer
()
74
{
75
//we only need this for gzip but we also do it for bz2 for unification.
76
if
(
compress_
==
compression::GZIP
||
compress_
==
compression::BZIP2
)
77
{
78
// prevent empty gz files because of https://svn.boost.org/trac/boost/ticket/5237
79
out_
<<
"\n"
;
80
}
81
}
82
83
void
config_writer::write
(
const
config
&cfg)
84
{
85
::write
(
out_
, cfg,
level_
);
86
}
87
88
void
config_writer::write_child
(
const
std::string
&key,
const
config
&cfg)
89
{
90
open_child
(key);
91
::write
(
out_
, cfg,
level_
);
92
close_child
(key);
93
}
94
95
void
config_writer::open_child
(
const
std::string
&key)
96
{
97
::write_open_child
(
out_
, key,
level_
++);
98
}
99
100
void
config_writer::close_child
(
const
std::string
&key)
101
{
102
::write_close_child
(
out_
, key, --
level_
);
103
}
104
105
bool
config_writer::good
()
const
106
{
107
return
out_
.good();
108
}
109
config_writer::good
bool good() const
Definition:
binary_or_text.cpp:105
config_writer::write
void write(const config &cfg)
Definition:
binary_or_text.cpp:83
level
GLint level
Definition:
glew.h:1220
config_writer::config_writer
config_writer(std::ostream &out, compression::format compress)
Definition:
binary_or_text.cpp:36
log_config
static lg::log_domain log_config("config")
lg::log_domain
Definition:
log.hpp:98
compression
Definition:
compression.hpp:20
write_open_child
void write_open_child(std::ostream &out, const std::string &child, unsigned int level)
Definition:
parser.cpp:565
config_writer::compress_
compression::format compress_
Definition:
binary_or_text.hpp:58
config.hpp
Definitions for the interface to Wesnoth Markup Language (WML).
write_close_child
void write_close_child(std::ostream &out, const std::string &child, unsigned int level)
Definition:
parser.cpp:570
config_writer::level_
unsigned int level_
Definition:
binary_or_text.hpp:59
config_writer::write_child
void write_child(const std::string &key, const config &cfg)
Definition:
binary_or_text.cpp:88
filter_
gui::filter_textbox & filter_
Definition:
dialogs.cpp:99
compression::GZIP
Definition:
compression.hpp:23
compression::BZIP2
Definition:
compression.hpp:24
config_writer::close_child
void close_child(const std::string &key)
Definition:
binary_or_text.cpp:100
config_writer::out_
std::ostream & out_
Definition:
binary_or_text.hpp:57
config_writer::open_child
void open_child(const std::string &key)
Definition:
binary_or_text.cpp:95
compression::NONE
Definition:
compression.hpp:22
parser.hpp
PACKAGE
#define PACKAGE
Definition:
wesconfig.h:23
wesconfig.h
Some defines: VERSION, PACKAGE, MIN_SAVEGAME_VERSION.
compression::format
format
Definition:
compression.hpp:21
binary_or_text.hpp
config_writer::~config_writer
~config_writer()
Default implementation, but defined out-of-line for efficiency reasons.
Definition:
binary_or_text.cpp:73
global.hpp
log.hpp
Standard logging facilities (interface).
config
A config object defines a single node in a WML file, with access to child nodes.
Definition:
config.hpp:83
string
GLsizei const GLcharARB ** string
Definition:
glew.h:4503
config_writer::filter_
boost::iostreams::filtering_stream< boost::iostreams::output > filter_
Definition:
binary_or_text.hpp:55
Generated by
1.8.8