Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #ifndef CARTOGRAPHER_IO_FILE_WRITER_H_
00018 #define CARTOGRAPHER_IO_FILE_WRITER_H_
00019
00020 #include <fstream>
00021 #include <functional>
00022 #include <memory>
00023
00024 #include "cartographer/common/port.h"
00025
00026 namespace cartographer {
00027 namespace io {
00028
00029
00030 class FileWriter {
00031 public:
00032 FileWriter() {}
00033 FileWriter(const FileWriter&) = delete;
00034 FileWriter& operator=(const FileWriter&) = delete;
00035
00036 virtual ~FileWriter() {}
00037
00038
00039
00040
00041 virtual bool WriteHeader(const char* data, size_t len) = 0;
00042
00043 virtual bool Write(const char* data, size_t len) = 0;
00044 virtual bool Close() = 0;
00045 virtual std::string GetFilename() = 0;
00046 };
00047
00048
00049 class StreamFileWriter : public FileWriter {
00050 public:
00051 ~StreamFileWriter() override;
00052
00053 StreamFileWriter(const std::string& filename);
00054
00055 bool Write(const char* data, size_t len) override;
00056 bool WriteHeader(const char* data, size_t len) override;
00057 bool Close() override;
00058 std::string GetFilename() override;
00059
00060 private:
00061 const std::string filename_;
00062 std::ofstream out_;
00063 };
00064
00065 using FileWriterFactory =
00066 std::function<std::unique_ptr<FileWriter>(const std::string& filename)>;
00067
00068 }
00069 }
00070
00071 #endif // CARTOGRAPHER_IO_FILE_WRITER_H_