Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
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),
00040 out_(*out_ptr_),
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