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 namespace cartographer {
29 
30 using int8 = int8_t;
31 using int16 = int16_t;
32 using int32 = int32_t;
33 using int64 = int64_t;
34 using uint8 = uint8_t;
35 using uint16 = uint16_t;
36 using uint32 = uint32_t;
37 using uint64 = uint64_t;
38 
39 namespace common {
40 
41 inline int RoundToInt(const float x) { return std::lround(x); }
42 
43 inline int RoundToInt(const double x) { return std::lround(x); }
44 
45 inline int64 RoundToInt64(const float x) { return std::lround(x); }
46 
47 inline int64 RoundToInt64(const double x) { return std::lround(x); }
48 
49 inline void FastGzipString(const std::string& uncompressed,
50  std::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 std::string& compressed,
61  std::string* decompressed) {
62  boost::iostreams::filtering_ostream out;
63  out.push(boost::iostreams::gzip_decompressor());
64  out.push(boost::iostreams::back_inserter(*decompressed));
65  boost::iostreams::write(out, reinterpret_cast<const char*>(compressed.data()),
66  compressed.size());
67 }
68 
69 } // namespace common
70 } // namespace cartographer
71 
72 #endif // CARTOGRAPHER_COMMON_PORT_H_
uint64_t uint64
Definition: port.h:37
int RoundToInt(const float x)
Definition: port.h:41
int64_t int64
Definition: port.h:33
uint32_t uint32
Definition: port.h:36
uint16_t uint16
Definition: port.h:35
int8_t int8
Definition: port.h:30
int16_t int16
Definition: port.h:31
void FastGunzipString(const std::string &compressed, std::string *decompressed)
Definition: port.h:60
int32_t int32
Definition: port.h:32
void FastGzipString(const std::string &uncompressed, std::string *compressed)
Definition: port.h:49
int64 RoundToInt64(const float x)
Definition: port.h:45
uint8_t uint8
Definition: port.h:34


cartographer
Author(s): The Cartographer Authors
autogenerated on Mon Feb 28 2022 22:00:58