1#ifndef OSMIUM_IO_COMPRESSION_HPP
2#define OSMIUM_IO_COMPRESSION_HPP
36#include <osmium/io/detail/read_write.hpp>
49#include <system_error>
81 virtual
void write(const
std::
string& data) = 0;
175 std::string error_message{
"Support for compression '"};
177 error_message +=
"' not compiled into this binary";
202 const compression_map_type::value_type cc{compression,
204 create_decompressor_fd,
205 create_decompressor_buffer)};
210 template <
typename... TArgs>
213 return std::unique_ptr<osmium::io::Compressor>(std::get<0>(callbacks)(std::forward<TArgs>(args)...));
218 return std::unique_ptr<osmium::io::Decompressor>(std::get<1>(callbacks)(fd));
223 return std::unique_ptr<osmium::io::Decompressor>(std::get<2>(callbacks)(buffer, size));
254 void write(
const std::string& data)
override {
255 osmium::io::detail::reliable_write(
m_fd, data.data(), data.size());
270 osmium::io::detail::reliable_fsync(fd);
272 osmium::io::detail::reliable_close(fd);
357 osmium::io::detail::remove_buffered_pages(
m_fd,
m_offset);
360 buffer.resize(
static_cast<std::string::size_type
>(nread));
372 osmium::io::detail::remove_buffered_pages(
m_fd);
376 osmium::io::detail::reliable_close(fd);
393 inline bool get_registered_no_compression() noexcept {
394 return registered_no_compression;
Definition: compression.hpp:148
~CompressionFactory() noexcept=default
std::unique_ptr< osmium::io::Decompressor > create_decompressor(const osmium::io::file_compression compression, const int fd) const
Definition: compression.hpp:216
bool register_compression(osmium::io::file_compression compression, const create_compressor_type &create_compressor, const create_decompressor_type_fd &create_decompressor_fd, const create_decompressor_type_buffer &create_decompressor_buffer)
Definition: compression.hpp:196
compression_map_type m_callbacks
Definition: compression.hpp:164
CompressionFactory & operator=(const CompressionFactory &)=delete
std::function< osmium::io::Compressor *(int, fsync)> create_compressor_type
Definition: compression.hpp:152
const callbacks_type & find_callbacks(const osmium::io::file_compression compression) const
Definition: compression.hpp:168
std::map< const osmium::io::file_compression, callbacks_type > compression_map_type
Definition: compression.hpp:162
std::unique_ptr< osmium::io::Compressor > create_compressor(const osmium::io::file_compression compression, TArgs &&... args) const
Definition: compression.hpp:211
std::function< osmium::io::Decompressor *(int)> create_decompressor_type_fd
Definition: compression.hpp:153
CompressionFactory(const CompressionFactory &)=delete
CompressionFactory & operator=(CompressionFactory &&)=delete
std::function< osmium::io::Decompressor *(const char *, std::size_t)> create_decompressor_type_buffer
Definition: compression.hpp:154
CompressionFactory(CompressionFactory &&)=delete
CompressionFactory()=default
static CompressionFactory & instance()
Definition: compression.hpp:191
std::tuple< create_compressor_type, create_decompressor_type_fd, create_decompressor_type_buffer > callbacks_type
Definition: compression.hpp:160
std::unique_ptr< osmium::io::Decompressor > create_decompressor(const osmium::io::file_compression compression, const char *buffer, const std::size_t size) const
Definition: compression.hpp:221
Definition: compression.hpp:57
bool do_fsync() const noexcept
Definition: compression.hpp:63
Compressor(const fsync sync) noexcept
Definition: compression.hpp:69
Compressor(const Compressor &)=default
Compressor(Compressor &&) noexcept=default
fsync m_fsync
Definition: compression.hpp:59
virtual void write(const std::string &data)=0
Compressor & operator=(const Compressor &)=default
virtual std::size_t file_size() const
Definition: compression.hpp:85
Definition: compression.hpp:91
std::atomic_bool m_want_buffered_pages_removed
Definition: compression.hpp:95
void set_offset_ptr(std::atomic< std::size_t > *offset_ptr) noexcept
Definition: compression.hpp:121
@ input_buffer_size
Definition: compression.hpp:100
virtual bool is_real() const noexcept
Definition: compression.hpp:117
virtual std::string read()=0
Decompressor & operator=(const Decompressor &)=delete
void set_want_buffered_pages_removed(bool value) noexcept
Definition: compression.hpp:135
Decompressor & operator=(Decompressor &&)=delete
virtual ~Decompressor() noexcept=default
std::atomic< std::size_t > * m_offset_ptr
Definition: compression.hpp:93
void set_offset(const std::size_t offset) noexcept
Definition: compression.hpp:125
bool want_buffered_pages_removed() const noexcept
Definition: compression.hpp:131
Decompressor(const Decompressor &)=delete
Decompressor(Decompressor &&)=delete
Definition: compression.hpp:287
DummyDecompressor & operator=(const DummyDecompressor &)=delete
~DummyDecompressor() noexcept override=default
void close() override
Definition: compression.hpp:304
bool is_real() const noexcept override
Definition: compression.hpp:307
DummyDecompressor()=default
std::string read() override
Definition: compression.hpp:300
DummyDecompressor(DummyDecompressor &&)=delete
DummyDecompressor(const DummyDecompressor &)=delete
DummyDecompressor & operator=(DummyDecompressor &&)=delete
Definition: compression.hpp:228
void close() override
Definition: compression.hpp:259
void write(const std::string &data) override
Definition: compression.hpp:254
NoCompressor(const NoCompressor &)=delete
NoCompressor & operator=(NoCompressor &&)=delete
~NoCompressor() noexcept override
Definition: compression.hpp:246
std::size_t m_file_size
Definition: compression.hpp:230
NoCompressor & operator=(const NoCompressor &)=delete
std::size_t file_size() const override
Definition: compression.hpp:276
NoCompressor(const int fd, const fsync sync)
Definition: compression.hpp:235
NoCompressor(NoCompressor &&)=delete
int m_fd
Definition: compression.hpp:231
Definition: compression.hpp:313
NoDecompressor & operator=(const NoDecompressor &)=delete
const char * m_buffer
Definition: compression.hpp:316
NoDecompressor(const NoDecompressor &)=delete
int m_fd
Definition: compression.hpp:315
NoDecompressor(const char *buffer, const std::size_t size)
Definition: compression.hpp:326
std::size_t m_buffer_size
Definition: compression.hpp:317
std::size_t m_offset
Definition: compression.hpp:318
NoDecompressor & operator=(NoDecompressor &&)=delete
std::string read() override
Definition: compression.hpp:345
NoDecompressor(NoDecompressor &&)=delete
~NoDecompressor() noexcept override
Definition: compression.hpp:337
NoDecompressor(const int fd)
Definition: compression.hpp:322
void close() override
Definition: compression.hpp:369
const char * as_string(file_compression compression)
Definition: file_compression.hpp:48
file_compression
Definition: file_compression.hpp:42
fsync
Definition: writer_options.hpp:51
Namespace for everything in the Osmium library.
Definition: assembler.hpp:53
Definition: location.hpp:555