1#ifndef OSMIUM_IO_WRITER_HPP
2#define OSMIUM_IO_WRITER_HPP
37#include <osmium/io/detail/output_format.hpp>
38#include <osmium/io/detail/queue_util.hpp>
39#include <osmium/io/detail/read_write.hpp>
40#include <osmium/io/detail/write_thread.hpp>
56#include <initializer_list>
71 inline std::size_t get_output_queue_size() noexcept {
108 detail::future_string_queue_type
m_output_queue{detail::get_output_queue_size(),
"raw_output"};
110 std::unique_ptr<osmium::io::detail::OutputFormat>
m_output{
nullptr};
137 static void write_thread(detail::future_string_queue_type& output_queue,
138 std::unique_ptr<osmium::io::Compressor>&& compressor,
139 std::promise<std::size_t>&& write_promise,
140 std::atomic_bool* notification) {
142 std::move(compressor),
143 std::move(write_promise),
149 if (
m_header.get(
"generator").empty()) {
162 if (buffer && buffer.committed() > 0) {
163 m_output->write_buffer(std::move(buffer));
176 osmium::memory::Buffer::auto_grow::no};
180 m_output->write_buffer(std::move(buffer));
184 template <
typename TFunction,
typename... TArgs>
187 throw io_error(
"Can not write to writer when in status 'closed' or 'error'");
191 func(std::forward<TArgs>(args)...);
208 options.
pool = &pool;
220 options.
sync = value;
266 template <
typename... TArgs>
272 (void)std::initializer_list<int>{(
set_option(options, args), 0)...};
282 std::unique_ptr<osmium::io::Compressor> compressor =
287 std::promise<std::size_t> write_promise;
292 template <
typename... TArgs>
293 explicit Writer(
const std::string& filename, TArgs&&... args) :
297 template <
typename... TArgs>
298 explicit Writer(
const char* filename, TArgs&&... args) :
380 osmium::memory::Buffer::auto_grow::no};
384 }
catch (
const osmium::buffer_is_full&) {
std::unique_ptr< osmium::io::Compressor > create_compressor(const osmium::io::file_compression compression, TArgs &&... args) const
Definition: compression.hpp:211
static CompressionFactory & instance()
Definition: compression.hpp:191
File & filename(const std::string &filename)
Definition: file.hpp:312
file_compression compression() const noexcept
Definition: file.hpp:294
const char * buffer() const noexcept
Definition: file.hpp:143
Definition: writer.hpp:100
std::size_t close()
Definition: writer.hpp:402
@ default_buffer_size
Definition: writer.hpp:103
void write_header()
Definition: writer.hpp:148
static void set_option(options_type &options, fsync value)
Definition: writer.hpp:219
static void set_option(options_type &options, const osmium::io::Header &header)
Definition: writer.hpp:211
static void set_option(options_type &options, osmium::thread::Pool &pool)
Definition: writer.hpp:207
size_t m_buffer_size
Definition: writer.hpp:116
void do_flush()
Definition: writer.hpp:167
Writer(const osmium::io::File &file, TArgs &&... args)
Definition: writer.hpp:267
Writer(const std::string &filename, TArgs &&... args)
Definition: writer.hpp:293
size_t buffer_size() const noexcept
Definition: writer.hpp:319
status
Definition: writer.hpp:127
osmium::thread::thread_handler m_thread
Definition: writer.hpp:120
void flush()
Definition: writer.hpp:348
void operator()(osmium::memory::Buffer &&buffer)
Definition: writer.hpp:362
bool m_header_written
Definition: writer.hpp:134
osmium::io::Header m_header
Definition: writer.hpp:114
osmium::memory::Buffer m_buffer
Definition: writer.hpp:112
std::atomic_bool m_notification
Definition: writer.hpp:125
~Writer() noexcept
Definition: writer.hpp:308
std::unique_ptr< osmium::io::detail::OutputFormat > m_output
Definition: writer.hpp:110
void set_header(const osmium::io::Header &header)
Definition: writer.hpp:337
static void set_option(options_type &options, overwrite value)
Definition: writer.hpp:215
std::future< std::size_t > m_write_future
Definition: writer.hpp:118
void do_close()
Definition: writer.hpp:223
void do_write(osmium::memory::Buffer &&buffer)
Definition: writer.hpp:158
Writer & operator=(Writer &&)=delete
Writer & operator=(const Writer &)=delete
detail::future_string_queue_type m_output_queue
Definition: writer.hpp:108
void set_buffer_size(size_t size) noexcept
Definition: writer.hpp:327
Writer(const Writer &)=delete
osmium::io::File m_file
Definition: writer.hpp:106
void operator()(const osmium::memory::Item &item)
Definition: writer.hpp:376
void ensure_cleanup(TFunction func, TArgs &&... args)
Definition: writer.hpp:185
static void write_thread(detail::future_string_queue_type &output_queue, std::unique_ptr< osmium::io::Compressor > &&compressor, std::promise< std::size_t > &&write_promise, std::atomic_bool *notification)
Definition: writer.hpp:137
Writer(const char *filename, TArgs &&... args)
Definition: writer.hpp:298
enum osmium::io::Writer::status m_status
static Pool & default_instance()
Definition: pool.hpp:186
std::size_t get_max_queue_size(const char *queue_name, const std::size_t default_value) noexcept
Definition: config.hpp:83
fsync
Definition: writer_options.hpp:51
overwrite
Definition: writer_options.hpp:43
void check_for_exception(std::future< T > &future)
Definition: util.hpp:57
Namespace for everything in the Osmium library.
Definition: assembler.hpp:53
Definition: location.hpp:555
Definition: writer.hpp:200
overwrite allow_overwrite
Definition: writer.hpp:202
osmium::thread::Pool * pool
Definition: writer.hpp:204
fsync sync
Definition: writer.hpp:203
osmium::io::Header header
Definition: writer.hpp:201
#define LIBOSMIUM_VERSION_STRING
Definition: version.hpp:45