00001
00002
00003
00004
00005 #include <boost/algorithm/string/predicate.hpp>
00006 #include "ug_stream.h"
00007
00008 namespace ugdiss
00009 {
00010 using namespace std;
00011 using namespace boost::algorithm;
00012 using namespace boost::iostreams;
00013
00014 filtering_istream*
00015 open_input_stream(string fname)
00016 {
00017 filtering_istream* ret = new filtering_istream();
00018 open_input_stream(fname,*ret);
00019 return ret;
00020 }
00021
00022 filtering_ostream*
00023 open_output_stream(string fname)
00024 {
00025 filtering_ostream* ret = new filtering_ostream();
00026 open_output_stream(fname,*ret);
00027 return ret;
00028 }
00029
00030 void
00031 open_input_stream(string fname, filtering_istream& in)
00032 {
00033 if (ends_with(fname, ".gz"))
00034 {
00035 in.push(gzip_decompressor());
00036 }
00037 else if (ends_with(fname, "bz2"))
00038 {
00039 in.push(bzip2_decompressor());
00040 }
00041 in.push(file_source(fname.c_str()));
00042 }
00043
00044 void
00045 open_output_stream(string fname, filtering_ostream& out)
00046 {
00047 if (ends_with(fname, ".gz") || ends_with(fname, ".gz_"))
00048 {
00049 out.push(gzip_compressor());
00050 }
00051 else if (ends_with(fname, ".bz2") || ends_with(fname, ".bz2_"))
00052 {
00053 out.push(bzip2_compressor());
00054 }
00055 out.push(file_sink(fname.c_str()));
00056 }
00057 }