Helios++
Helios software for LiDAR simulations
SimpleMultiSyncFileWriter.h
1 #pragma once
2 
3 namespace helios { namespace filems{
4 
14 template <typename ... WriteArgs>
15 class SimpleMultiSyncFileWriter : public MultiSyncFileWriter<WriteArgs ...>{
16 protected:
17  // *** ATTRIBUTES *** //
18  // ******************** //
23  std::vector<std::ofstream> ofs;
24 
25 public:
26  // *** CONSTRUCTION / DESTRUCTION *** //
27  // ************************************ //
34  std::vector<std::string> const& path,
35  std::ios_base::openmode om = std::ios_base::app
36  ) :
37  MultiSyncFileWriter<WriteArgs ...>(path),
38  ofs(path.size())
39  {
40  // For each file ...
41  size_t const numFiles = path.size();
42  for(size_t i = 0 ; i < numFiles ; ++i){
43  // Open it for writing ...
44  std::ofstream &ofsi = ofs[i];
45  ofsi.open(path[i], om);
46  ofsi.exceptions(
47  std::ios_base::eofbit |
48  std::ios_base::failbit |
49  std::ios_base::badbit
50  );
51  }
52  }
53  virtual ~SimpleMultiSyncFileWriter() {finish();}
54 
55  // *** F I N I S H *** //
56  // ********************* //
61  void finish() override {
62  for(std::ofstream &ofs : ofs){
63  if(ofs.is_open()) ofs.close();
64  }
65  }
66 };
67 
68 }}
Abstract class defining common behavior for all synchronous writers that work with multiple files at ...
Definition: MultiSyncFileWriter.h:21
std::vector< std::string > path
Paths to the files to be written.
Definition: MultiSyncFileWriter.h:28
Abstract specialization of MultiSyncFileWriter to write output to many files. Each writing operation ...
Definition: SimpleMultiSyncFileWriter.h:15
SimpleMultiSyncFileWriter(std::vector< std::string > const &path, std::ios_base::openmode om=std::ios_base::app)
Simple synchronous multi-file writer constructor.
Definition: SimpleMultiSyncFileWriter.h:33
void finish() override
SimpleMultiSyncFileWriter finish method assures that any output file stream that remains open is clos...
Definition: SimpleMultiSyncFileWriter.h:61
std::vector< std::ofstream > ofs
Output file streams to be used by the simple multi synchronous file writer.
Definition: SimpleMultiSyncFileWriter.h:23