file_writer.cc
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 
18 
19 namespace cartographer {
20 namespace io {
21 
22 StreamFileWriter::StreamFileWriter(const string& filename)
23  : out_(filename, std::ios::out | std::ios::binary) {}
24 
26 
27 bool StreamFileWriter::Write(const char* const data, const size_t len) {
28  if (out_.bad()) {
29  return false;
30  }
31  out_.write(data, len);
32  return !out_.bad();
33 }
34 
36  if (out_.bad()) {
37  return false;
38  }
39  out_.close();
40  return !out_.bad();
41 }
42 
43 bool StreamFileWriter::WriteHeader(const char* const data, const size_t len) {
44  if (out_.bad()) {
45  return false;
46  }
47  out_.flush();
48  out_.seekp(0);
49  return Write(data, len);
50 }
51 
52 } // namespace io
53 } // namespace cartographer
StreamFileWriter(const string &filename)
Definition: file_writer.cc:22
bool Write(const char *data, size_t len) override
Definition: file_writer.cc:27
bool WriteHeader(const char *data, size_t len) override
Definition: file_writer.cc:43


cartographer
Author(s):
autogenerated on Wed Jun 5 2019 21:57:58