|
Chemical Data Processing Library C++ API - Version 1.0.0
|
Go to the documentation of this file.
29 #ifndef CDPL_UTIL_COMPRESSIONSTREAMS_HPP
30 #define CDPL_UTIL_COMPRESSIONSTREAMS_HPP
34 #include <boost/filesystem.hpp>
35 #include <boost/iostreams/copy.hpp>
36 #include <boost/iostreams/filtering_stream.hpp>
37 #include <boost/iostreams/filter/gzip.hpp>
38 #include <boost/iostreams/filter/bzip2.hpp>
57 template <CompressionAlgo CompAlgo>
76 template <CompressionAlgo CompAlgo,
typename StreamType>
83 typedef typename StreamType::int_type
int_type;
84 typedef typename StreamType::pos_type
pos_type;
85 typedef typename StreamType::off_type
off_type;
86 typedef std::basic_istream<char_type, traits_type>
IStreamType;
87 typedef std::basic_ostream<char_type, traits_type>
OStreamType;
101 typedef std::basic_filebuf<char_type, traits_type> FileBufType;
103 FileBufType tmpFileBuf;
106 template <CompressionAlgo CompAlgo,
typename CharT =
char,
typename TraitsT = std::
char_traits<CharT> >
111 typedef typename std::basic_istream<CharT, TraitsT> StreamType;
121 void open(StreamType& stream);
125 template <CompressionAlgo CompAlgo,
typename CharT =
char,
typename TraitsT = std::
char_traits<CharT> >
130 typedef typename std::basic_ostream<CharT, TraitsT> StreamType;
142 void open(StreamType& stream);
150 template <CompressionAlgo CompAlgo,
typename CharT =
char,
typename TraitsT = std::
char_traits<CharT> >
155 typedef typename std::basic_iostream<CharT, TraitsT> StreamType;
167 void open(StreamType& stream);
187 template <CDPL::Util::CompressionAlgo CompAlgo,
typename StreamType>
189 StreamType(&tmpFileBuf)
192 template <CDPL::Util::CompressionAlgo CompAlgo,
typename StreamType>
195 if (!tmpFileBuf.close())
196 this->setstate(std::ios_base::failbit);
201 template <CDPL::Util::CompressionAlgo CompAlgo,
typename StreamType>
206 if (!tmpFileBuf.open(tmp_file_rem.
getPath().c_str(),
207 std::ios_base::in | std::ios_base::out |
208 std::ios_base::trunc | std::ios_base::binary))
209 this->setstate(std::ios_base::failbit);
211 this->clear(std::ios_base::goodbit);
214 template <CDPL::Util::CompressionAlgo CompAlgo,
typename StreamType>
219 is.seekg(0, std::ios_base::end);
224 this->setstate(std::ios_base::failbit);
233 boost::iostreams::filtering_stream<boost::iostreams::input, char_type, traits_type> fs;
238 boost::iostreams::copy(fs, *this->rdbuf());
240 if (this->tmpFileBuf.pubseekpos(0, std::ios_base::in | std::ios_base::out) != 0)
241 this->setstate(std::ios_base::failbit);
243 this->setstate(is.rdstate() | fs.rdstate());
246 template <CDPL::Util::CompressionAlgo CompAlgo,
typename StreamType>
249 if (tmpFileBuf.pubseekpos(0, std::ios_base::in) != 0) {
250 this->setstate(std::ios_base::failbit);
254 boost::iostreams::filtering_stream<boost::iostreams::output, char_type, traits_type> fs;
259 boost::iostreams::copy(*this->rdbuf(), fs);
261 this->setstate(os.rdstate() | fs.rdstate());
266 template <CDPL::Util::CompressionAlgo CompAlgo,
typename CharT,
typename TraitsT>
270 template <CDPL::Util::CompressionAlgo CompAlgo,
typename CharT,
typename TraitsT>
276 template <CDPL::Util::CompressionAlgo CompAlgo,
typename CharT,
typename TraitsT>
282 this->decompInput(stream);
285 template <CDPL::Util::CompressionAlgo CompAlgo,
typename CharT,
typename TraitsT>
288 this->closeTmpFile();
293 template <CDPL::Util::CompressionAlgo CompAlgo,
typename CharT,
typename TraitsT>
298 template <CDPL::Util::CompressionAlgo CompAlgo,
typename CharT,
typename TraitsT>
305 template <CDPL::Util::CompressionAlgo CompAlgo,
typename CharT,
typename TraitsT>
310 stream->seekp(outPos);
311 this->compOutput(*stream);
316 template <CDPL::Util::CompressionAlgo CompAlgo,
typename CharT,
typename TraitsT>
324 outPos = stream.tellp();
325 this->setstate(stream.rdstate());
328 this->stream = &stream;
331 template <CDPL::Util::CompressionAlgo CompAlgo,
typename CharT,
typename TraitsT>
335 stream->seekp(outPos);
336 this->compOutput(*stream);
344 this->closeTmpFile();
349 template <CDPL::Util::CompressionAlgo CompAlgo,
typename CharT,
typename TraitsT>
354 template <CDPL::Util::CompressionAlgo CompAlgo,
typename CharT,
typename TraitsT>
361 template <CDPL::Util::CompressionAlgo CompAlgo,
typename CharT,
typename TraitsT>
366 stream->seekp(outPos);
367 this->compOutput(*stream);
372 template <CDPL::Util::CompressionAlgo CompAlgo,
typename CharT,
typename TraitsT>
380 outPos = stream.tellp();
381 this->setstate(stream.rdstate());
386 this->decompInput(stream);
389 this->stream = &stream;
392 template <CDPL::Util::CompressionAlgo CompAlgo,
typename CharT,
typename TraitsT>
396 stream->seekp(outPos);
397 this->compOutput(*stream);
405 this->closeTmpFile();
408 #endif // CDPL_UTIL_COMPRESSIONSTREAMS_HPP
Definition: CompressionStreams.hpp:108
StreamType::pos_type pos_type
Definition: CompressionStreams.hpp:134
StreamType::char_type char_type
Definition: CompressionStreams.hpp:156
boost::iostreams::bzip2_decompressor DecompFilter
Definition: CompressionStreams.hpp:72
boost::iostreams::gzip_decompressor DecompFilter
Definition: CompressionStreams.hpp:64
void close()
Definition: CompressionStreams.hpp:393
StreamType::char_type char_type
Definition: CompressionStreams.hpp:81
DecompressionIStream()
Definition: CompressionStreams.hpp:267
StreamType::traits_type traits_type
Definition: CompressionStreams.hpp:113
CompressedIOStream< BZIP2 > BZip2IOStream
Definition: CompressionStreams.hpp:180
std::basic_istream< char_type, traits_type > IStreamType
Definition: CompressionStreams.hpp:86
Definition: FileRemover.hpp:44
StreamType::traits_type traits_type
Definition: CompressionStreams.hpp:82
CompressedIOStream()
Definition: CompressionStreams.hpp:350
@ BZIP2
Definition: CompressionStreams.hpp:54
void open(StreamType &stream)
Definition: CompressionStreams.hpp:317
std::basic_ostream< char_type, traits_type > OStreamType
Definition: CompressionStreams.hpp:87
void closeTmpFile()
Definition: CompressionStreams.hpp:193
StreamType::int_type int_type
Definition: CompressionStreams.hpp:83
CompressionOStream< BZIP2 > BZip2OStream
Definition: CompressionStreams.hpp:178
StreamType::char_type char_type
Definition: CompressionStreams.hpp:131
const std::string & getPath() const
Definition of the class CDPL::Util::FileRemover.
StreamType::pos_type pos_type
Definition: CompressionStreams.hpp:115
CompressionAlgo
Definition: CompressionStreams.hpp:51
Definition: CompressionStreams.hpp:78
void open(StreamType &stream)
Definition: CompressionStreams.hpp:277
Definition: CompressionStreams.hpp:152
void decompInput(IStreamType &is)
Definition: CompressionStreams.hpp:215
CompressionOStream()
Definition: CompressionStreams.hpp:294
virtual ~CompressionStreamBase()
Definition: CompressionStreams.hpp:92
StreamType::pos_type pos_type
Definition: CompressionStreams.hpp:84
void close()
Definition: CompressionStreams.hpp:286
StreamType::traits_type traits_type
Definition: CompressionStreams.hpp:157
CompressionOStream< GZIP > GZipOStream
Definition: CompressionStreams.hpp:177
StreamType::off_type off_type
Definition: CompressionStreams.hpp:160
Definition: CompressionStreams.hpp:58
StreamType::int_type int_type
Definition: CompressionStreams.hpp:133
@ GZIP
Definition: CompressionStreams.hpp:53
StreamType::char_type char_type
Definition: CompressionStreams.hpp:112
The namespace of the Chemical Data Processing Library.
void open(StreamType &stream)
Definition: CompressionStreams.hpp:373
StreamType::pos_type pos_type
Definition: CompressionStreams.hpp:159
CompressedIOStream< GZIP > GZipIOStream
Definition: CompressionStreams.hpp:179
boost::iostreams::gzip_compressor CompFilter
Definition: CompressionStreams.hpp:65
CDPL_UTIL_API std::string genCheckedTempFilePath(const std::string &dir="", const std::string &ptn="%%%%-%%%%-%%%%-%%%%")
Definition: CompressionStreams.hpp:127
StreamType::off_type off_type
Definition: CompressionStreams.hpp:116
StreamType::off_type off_type
Definition: CompressionStreams.hpp:135
~CompressionOStream()
Definition: CompressionStreams.hpp:306
StreamType::int_type int_type
Definition: CompressionStreams.hpp:114
void close()
Definition: CompressionStreams.hpp:332
~CompressedIOStream()
Definition: CompressionStreams.hpp:362
CompressionStreamBase()
Definition: CompressionStreams.hpp:188
DecompressionIStream< BZIP2 > BZip2IStream
Definition: CompressionStreams.hpp:176
StreamType::off_type off_type
Definition: CompressionStreams.hpp:85
StreamType::int_type int_type
Definition: CompressionStreams.hpp:158
void compOutput(OStreamType &os)
Definition: CompressionStreams.hpp:247
StreamType::traits_type traits_type
Definition: CompressionStreams.hpp:132
boost::iostreams::bzip2_compressor CompFilter
Definition: CompressionStreams.hpp:73
DecompressionIStream< GZIP > GZipIStream
Definition: CompressionStreams.hpp:175
Declaration of filesystem-related functions.
void openTmpFile()
Definition: CompressionStreams.hpp:202