binary_or_text.hpp

Go to the documentation of this file.
00001 /* $Id: binary_or_text.hpp 23842 2008-02-16 08:47:16Z mordante $ */
00002 /*
00003    Copyright (C) 2003 by David White <dave@whitevine.net>
00004    Copyright (C) 2005 - 2008 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 version 2
00009    or at your option any later version.
00010    This program is distributed in the hope that it will be useful,
00011    but WITHOUT ANY WARRANTY.
00012 
00013    See the COPYING file for more details.
00014 */
00015 
00016 //! @file serialization/binary_or_text.hpp 
00017 //!
00018 
00019 #ifndef SERIALIZATION_BINARY_OR_TEXT_HPP_INCLUDED
00020 #define SERIALIZATION_BINARY_OR_TEXT_HPP_INCLUDED
00021 
00022 #include <iosfwd>
00023 #include <string>
00024 
00025 #include <boost/iostreams/filtering_stream.hpp>
00026 
00027 class config;
00028 
00029 //! Reads a file, and detects it is compressed before reading it. 
00030 //! If it is not a valid file at all, it will throw an error 
00031 //! as if it was trying to read it as text WML. 
00032 //! Returns true iff the format is compressed.
00033 bool detect_format_and_read(config &cfg, std::istream &in, std::string* error_log=NULL); // Throws config::error
00034 
00035 //! Writes a file, compressed or not depending on a flag.
00036 void write_possibly_compressed(std::ostream &out, config &cfg, bool compress);
00037 
00038 //! Class for writing a config out to a file in pieces.
00039 class config_writer
00040 {
00041 public:
00042     config_writer(std::ostream &out, bool compress, const std::string &textdomain);
00043 
00044     void write(const config &cfg);
00045     void write_child(const std::string &key, const config &cfg);
00046     void write_key_val(const std::string &key, const std::string &value);
00047     void open_child(const std::string &key);
00048     void close_child(const std::string &key);
00049     bool good() const;
00050 
00051 private:
00052     boost::iostreams::filtering_stream<boost::iostreams::output> filter_;
00053     std::ostream *out_ptr_;
00054     std::ostream &out_;
00055     bool compress_;
00056     unsigned int level_;
00057     std::string textdomain_;
00058 };
00059 
00060 #endif

Generated by doxygen 1.5.5 on 23 May 2008 for The Battle for Wesnoth
Gna! | Forum | Wiki | CIA | devdocs