Helios++
Helios software for LiDAR simulations
SimpleSyncFileWriter.h
1 #pragma once
2 
3 #include <filems/write/comps/SingleSyncFileWriter.h>
4 #include <MathConverter.h>
5 
6 #include <fstream>
7 #include <string>
8 #include <iomanip>
9 #include <ostream>
10 #include <iterator>
11 
12 namespace helios { namespace filems{
13 
22 template <typename ... WriteArgs>
23 class SimpleSyncFileWriter : public SingleSyncFileWriter<WriteArgs ...>{
24 protected:
25  // *** ATTRIBUTES *** //
26  // ******************** //
31  std::ofstream ofs;
32 public:
33  // *** CONSTRUCTION / DESTRUCTION *** //
34  // ************************************ //
41  const std::string& path,
42  std::ios_base::openmode om = std::ios_base::app
43  ) :
44  SingleSyncFileWriter<WriteArgs ...>(path)
45  {
46  // Open file for writing ...
47  ofs.open(path, om);
48  ofs.exceptions(
49  std::ios_base::eofbit |
50  std::ios_base::failbit |
51  std::ios_base::badbit
52  );
53  }
54  virtual ~SimpleSyncFileWriter() {finish();}
55 
56  // *** F I N I S H *** //
57  // ********************* //
62  void finish() override {if(ofs.is_open()) ofs.close();}
63 };
64 
65 }}
Abstract specialization of SingleSyncFileWriter to write output directly to a file.
Definition: SimpleSyncFileWriter.h:23
void finish() override
SimpleSyncFileWriter finish method assures that output file will be closed if it is open.
Definition: SimpleSyncFileWriter.h:62
std::ofstream ofs
Output file stream to be used by the simple synchronous file writer.
Definition: SimpleSyncFileWriter.h:31
SimpleSyncFileWriter(const std::string &path, std::ios_base::openmode om=std::ios_base::app)
Simple synchronous file writer constructor.
Definition: SimpleSyncFileWriter.h:40
Abstract class defining common behavior for all synchronous writers that work with a single file at a...
Definition: SingleSyncFileWriter.h:21
std::string path
Path to file to be written.
Definition: SingleSyncFileWriter.h:28