00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #include "global.hpp"
00020
00021 #include "binary_or_text.hpp"
00022 #include "config.hpp"
00023 #include "filesystem.hpp"
00024 #include "serialization/binary_wml.hpp"
00025 #include "serialization/parser.hpp"
00026
00027 #include <sstream>
00028
00029 #include <boost/iostreams/filter/gzip.hpp>
00030
00031 bool detect_format_and_read(config &cfg, std::istream &in, std::string* error_log)
00032 {
00033 unsigned char c = in.peek();
00034 if (c < 4) {
00035 read_compressed(cfg, in);
00036 return true;
00037 } else {
00038 read(cfg, in, error_log);
00039 return false;
00040 }
00041 }
00042
00043 void write_possibly_compressed(std::ostream &out, config &cfg, bool compress)
00044 {
00045 if (compress)
00046 write_compressed(out, cfg);
00047 else
00048 write(out, cfg);
00049 }
00050
00051 config_writer::config_writer(
00052 std::ostream &out, bool compress, const std::string &textdomain) :
00053 filter_(),
00054 out_ptr_(compress ? &filter_ : &out),
00055 out_(*out_ptr_),
00056 compress_(compress),
00057 level_(0),
00058 textdomain_(textdomain)
00059 {
00060 if(compress_) {
00061 filter_.push(boost::iostreams::gzip_compressor());
00062 filter_.push(out);
00063 }
00064 }
00065
00066 void config_writer::write(const config &cfg)
00067 {
00068 ::write(out_, cfg, level_);
00069 }
00070
00071 void config_writer::write_child(const std::string &key, const config &cfg)
00072 {
00073 open_child(key);
00074 ::write(out_, cfg, level_);
00075 close_child(key);
00076 }
00077
00078 void config_writer::write_key_val(const std::string &key, const std::string &value)
00079 {
00080 ::write_key_val(out_, key, value, level_, textdomain_);
00081 }
00082
00083 void config_writer::open_child(const std::string &key)
00084 {
00085 ::write_open_child(out_, key, level_++);
00086 }
00087
00088 void config_writer::close_child(const std::string &key)
00089 {
00090 ::write_close_child(out_, key, --level_);
00091 }
00092
00093 bool config_writer::good() const
00094 {
00095 return out_.good();
00096 }
00097