Helios++
Helios software for LiDAR simulations
ZipSyncFileWriter.h
1 #pragma once
2 
3 #include <string>
4 #include <filems/write/comps/SimpleSyncFileWriter.h>
5 #include <boost/iostreams/filtering_stream.hpp>
6 #include <boost/iostreams/filter/zlib.hpp>
7 #include <boost/archive/binary_oarchive.hpp>
8 
9 namespace helios { namespace filems {
10 
11 using std::string;
12 using std::unique_ptr;
13 using std::ios_base;
14 
22 template <typename ... WriteArgs>
23 class ZipSyncFileWriter : public SimpleSyncFileWriter<WriteArgs...> {
24 protected:
25 using SimpleSyncFileWriter<WriteArgs...>::ofs;
26  // *** ATTRIBUTES *** //
27  // ******************** //
31  boost::iostreams::filtering_ostream compressedOut;
35  boost::iostreams::zlib_params zp;
39  unique_ptr<boost::archive::binary_oarchive> oa;
40 
41 public:
42  // *** CONSTRUCTION / DESTRUCTION *** //
43  // ************************************ //
51  const string &path,
52  int compressionMode = boost::iostreams::zlib::best_compression
53  ) :
54  SimpleSyncFileWriter<WriteArgs ...>(
55  path, ios_base::out | ios_base::binary
56  )
57  {
58  zp = boost::iostreams::zlib_params(compressionMode);
59  compressedOut.push(boost::iostreams::zlib_compressor(zp));
60  compressedOut.push(ofs);
61  oa = std::unique_ptr<boost::archive::binary_oarchive>(
62  new boost::archive::binary_oarchive(compressedOut)
63  );
64  }
65  virtual ~ZipSyncFileWriter() = default;
66 
67  // *** F I N I S H *** //
68  // ********************* //
76  void finish() override {
77  oa = nullptr;
78  //SimpleSyncFileWriter<WriteArgs...>::finish(); // Must not be called
79  }
80 
81 };
82 
83 }}
Abstract specialization of SingleSyncFileWriter to write output directly to a file.
Definition: SimpleSyncFileWriter.h:23
std::ofstream ofs
Output file stream to be used by the simple synchronous file writer.
Definition: SimpleSyncFileWriter.h:31
std::string path
Path to file to be written.
Definition: SingleSyncFileWriter.h:28
Abstract child of SimpleSyncFileWriter which provides support for zipped output.
Definition: ZipSyncFileWriter.h:23
ZipSyncFileWriter(const string &path, int compressionMode=boost::iostreams::zlib::best_compression)
Build a ZipSyncFileWriter.
Definition: ZipSyncFileWriter.h:50
void finish() override
ZipSyncFileWriter finishes the binary output archive instead of calling its parent finish method....
Definition: ZipSyncFileWriter.h:76
unique_ptr< boost::archive::binary_oarchive > oa
Binary output archive.
Definition: ZipSyncFileWriter.h:39
boost::iostreams::zlib_params zp
ZLib compression parameters.
Definition: ZipSyncFileWriter.h:35
boost::iostreams::filtering_ostream compressedOut
Compressed output stream.
Definition: ZipSyncFileWriter.h:31