port.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_COMMON_PORT_H_
18 #define CARTOGRAPHER_COMMON_PORT_H_
19 
20 #include <cinttypes>
21 #include <cmath>
22 #include <string>
23 
24 #include <boost/iostreams/device/back_inserter.hpp>
25 #include <boost/iostreams/filter/gzip.hpp>
26 #include <boost/iostreams/filtering_stream.hpp>
27 
28 using int8 = int8_t;
29 using int16 = int16_t;
30 using int32 = int32_t;
31 using int64 = int64_t;
32 using uint8 = uint8_t;
33 using uint16 = uint16_t;
34 using uint32 = uint32_t;
35 using uint64 = uint64_t;
36 
37 using std::string;
38 
39 namespace cartographer {
40 namespace common {
41 
42 inline int RoundToInt(const float x) { return std::lround(x); }
43 
44 inline int RoundToInt(const double x) { return std::lround(x); }
45 
46 inline int64 RoundToInt64(const float x) { return std::lround(x); }
47 
48 inline int64 RoundToInt64(const double x) { return std::lround(x); }
49 
50 inline void FastGzipString(const string& uncompressed, string* compressed) {
51  boost::iostreams::filtering_ostream out;
52  out.push(
53  boost::iostreams::gzip_compressor(boost::iostreams::zlib::best_speed));
54  out.push(boost::iostreams::back_inserter(*compressed));
55  boost::iostreams::write(out,
56  reinterpret_cast<const char*>(uncompressed.data()),
57  uncompressed.size());
58 }
59 
60 inline void FastGunzipString(const string& compressed, string* decompressed) {
61  boost::iostreams::filtering_ostream out;
62  out.push(boost::iostreams::gzip_decompressor());
63  out.push(boost::iostreams::back_inserter(*decompressed));
64  boost::iostreams::write(out, reinterpret_cast<const char*>(compressed.data()),
65  compressed.size());
66 }
67 
68 } // namespace common
69 } // namespace cartographer
70 
71 #endif // CARTOGRAPHER_COMMON_PORT_H_
void FastGzipString(const string &uncompressed, string *compressed)
Definition: port.h:50
int RoundToInt(const float x)
Definition: port.h:42
uint64_t uint64
Definition: port.h:35
uint8_t uint8
Definition: port.h:32
void FastGunzipString(const string &compressed, string *decompressed)
Definition: port.h:60
int32_t int32
Definition: port.h:30
int8_t int8
Definition: port.h:28
int16_t int16
Definition: port.h:29
int64_t int64
Definition: port.h:31
uint32_t uint32
Definition: port.h:34
uint16_t uint16
Definition: port.h:33
int64 RoundToInt64(const float x)
Definition: port.h:46


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