port.h
Go to the documentation of this file.
00001 /*
00002  * Copyright 2016 The Cartographer Authors
00003  *
00004  * Licensed under the Apache License, Version 2.0 (the "License");
00005  * you may not use this file except in compliance with the License.
00006  * You may obtain a copy of the License at
00007  *
00008  *      http://www.apache.org/licenses/LICENSE-2.0
00009  *
00010  * Unless required by applicable law or agreed to in writing, software
00011  * distributed under the License is distributed on an "AS IS" BASIS,
00012  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00013  * See the License for the specific language governing permissions and
00014  * limitations under the License.
00015  */
00016 
00017 #ifndef CARTOGRAPHER_COMMON_PORT_H_
00018 #define CARTOGRAPHER_COMMON_PORT_H_
00019 
00020 #include <boost/iostreams/device/back_inserter.hpp>
00021 #include <boost/iostreams/filter/gzip.hpp>
00022 #include <boost/iostreams/filtering_stream.hpp>
00023 #include <cinttypes>
00024 #include <cmath>
00025 #include <string>
00026 
00027 namespace cartographer {
00028 
00029 using int8 = int8_t;
00030 using int16 = int16_t;
00031 using int32 = int32_t;
00032 using int64 = int64_t;
00033 using uint8 = uint8_t;
00034 using uint16 = uint16_t;
00035 using uint32 = uint32_t;
00036 using uint64 = uint64_t;
00037 
00038 namespace common {
00039 
00040 inline int RoundToInt(const float x) { return std::lround(x); }
00041 
00042 inline int RoundToInt(const double x) { return std::lround(x); }
00043 
00044 inline int64 RoundToInt64(const float x) { return std::lround(x); }
00045 
00046 inline int64 RoundToInt64(const double x) { return std::lround(x); }
00047 
00048 inline void FastGzipString(const std::string& uncompressed,
00049                            std::string* compressed) {
00050   boost::iostreams::filtering_ostream out;
00051   out.push(
00052       boost::iostreams::gzip_compressor(boost::iostreams::zlib::best_speed));
00053   out.push(boost::iostreams::back_inserter(*compressed));
00054   boost::iostreams::write(out,
00055                           reinterpret_cast<const char*>(uncompressed.data()),
00056                           uncompressed.size());
00057 }
00058 
00059 inline void FastGunzipString(const std::string& compressed,
00060                              std::string* decompressed) {
00061   boost::iostreams::filtering_ostream out;
00062   out.push(boost::iostreams::gzip_decompressor());
00063   out.push(boost::iostreams::back_inserter(*decompressed));
00064   boost::iostreams::write(out, reinterpret_cast<const char*>(compressed.data()),
00065                           compressed.size());
00066 }
00067 
00068 }  // namespace common
00069 }  // namespace cartographer
00070 
00071 #endif  // CARTOGRAPHER_COMMON_PORT_H_


cartographer
Author(s): The Cartographer Authors
autogenerated on Thu May 9 2019 02:27:35