serialization/binary_or_text.cpp

Go to the documentation of this file.
00001 /* $Id: binary_or_text.cpp 52533 2012-01-07 02:35:17Z shadowmaster $ */
00002 /*
00003    Copyright (C) 2003 by David White <dave@whitevine.net>
00004    Copyright (C) 2005 - 2012 by Guillaume Melquiond <guillaume.melquiond@gmail.com>
00005    Part of the Battle for Wesnoth Project http://www.wesnoth.org/
00006 
00007    This program is free software; you can redistribute it and/or modify
00008    it under the terms of the GNU General Public License as published by
00009    the Free Software Foundation; either version 2 of the License, or
00010    (at your option) any later version.
00011    This program is distributed in the hope that it will be useful,
00012    but WITHOUT ANY WARRANTY.
00013 
00014    See the COPYING file for more details.
00015 */
00016 
00017 /**
00018  * @file
00019  * Read/Write file in binary (compressed) or text-format (uncompressed).
00020  */
00021 
00022 #include "global.hpp"
00023 
00024 #include "binary_or_text.hpp"
00025 #include "config.hpp"
00026 #include "log.hpp"
00027 #include "wesconfig.h"
00028 #include "serialization/parser.hpp"
00029 
00030 
00031 #include <boost/iostreams/filter/gzip.hpp>
00032 
00033 static lg::log_domain log_config("config");
00034 #define ERR_CF LOG_STREAM(err, log_config)
00035 
00036 config_writer::config_writer(
00037     std::ostream &out, bool compress, int level) :
00038         filter_(),
00039         out_ptr_(compress ? &filter_ : &out), //ternary indirection creates a temporary
00040         out_(*out_ptr_), //now MSVC will allow binding to the reference member
00041         compress_(compress),
00042         level_(0),
00043         textdomain_(PACKAGE)
00044 {
00045     if(compress_) {
00046         if (level >=0)
00047             filter_.push(boost::iostreams::gzip_compressor(boost::iostreams::gzip_params(level)));
00048         else
00049             filter_.push(boost::iostreams::gzip_compressor(boost::iostreams::gzip_params()));
00050 
00051         filter_.push(out);
00052     }
00053 }
00054 
00055 config_writer::~config_writer()
00056 {
00057 }
00058 
00059 void config_writer::write(const config &cfg)
00060 {
00061 	::write(out_, cfg, level_);
00062 }
00063 
00064 void config_writer::write_child(const std::string &key, const config &cfg)
00065 {
00066     open_child(key);
00067 	::write(out_, cfg, level_);
00068     close_child(key);
00069 }
00070 
00071 void config_writer::write_key_val(const std::string &key, const std::string &value)
00072 {
00073     config::attribute_value v;
00074     v = value;
00075 	::write_key_val(out_, key, v, level_, textdomain_);
00076 }
00077 
00078 void config_writer::open_child(const std::string &key)
00079 {
00080 	::write_open_child(out_, key, level_++);
00081 }
00082 
00083 void config_writer::close_child(const std::string &key)
00084 {
00085 	::write_close_child(out_, key, --level_);
00086 }
00087 
00088 bool config_writer::good() const
00089 {
00090     return out_.good();
00091 }
00092 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated by doxygen 1.7.1 on Wed May 23 2012 01:02:55 for The Battle for Wesnoth
Gna! | Forum | Wiki | CIA | devdocs