file_writer.h
Go to the documentation of this file.
1 /*
2  * Copyright 2016 The Cartographer Authors
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef CARTOGRAPHER_IO_FILE_WRITER_H_
18 #define CARTOGRAPHER_IO_FILE_WRITER_H_
19 
20 #include <fstream>
21 #include <functional>
22 #include <memory>
23 
25 
26 namespace cartographer {
27 namespace io {
28 
29 // Simple abstraction for a file.
30 class FileWriter {
31  public:
33  FileWriter(const FileWriter&) = delete;
34  FileWriter& operator=(const FileWriter&) = delete;
35 
36  virtual ~FileWriter() {}
37 
38  // Write 'data' to the beginning of the file. This is required to overwrite
39  // fixed size headers which contain the number of points once we actually know
40  // how many points there are.
41  virtual bool WriteHeader(const char* data, size_t len) = 0;
42 
43  virtual bool Write(const char* data, size_t len) = 0;
44  virtual bool Close() = 0;
45 };
46 
47 // An Implementation of file using std::ofstream.
48 class StreamFileWriter : public FileWriter {
49  public:
50  ~StreamFileWriter() override;
51 
52  StreamFileWriter(const string& filename);
53 
54  bool Write(const char* data, size_t len) override;
55  bool WriteHeader(const char* data, size_t len) override;
56  bool Close() override;
57 
58  private:
59  std::ofstream out_;
60 };
61 
62 using FileWriterFactory =
63  std::function<std::unique_ptr<FileWriter>(const string& filename)>;
64 
65 } // namespace io
66 } // namespace cartographer
67 
68 #endif // CARTOGRAPHER_IO_FILE_WRITER_H_
std::function< std::unique_ptr< FileWriter >(const string &filename)> FileWriterFactory
Definition: file_writer.h:63
FileWriter & operator=(const FileWriter &)=delete
virtual bool WriteHeader(const char *data, size_t len)=0
virtual bool Write(const char *data, size_t len)=0


cartographer
Author(s):
autogenerated on Mon Jun 10 2019 12:51:38