Libosmium
2.20.0
Fast and flexible C++ library for working with OpenStreetMap data
|
#include <writer.hpp>
Classes | |
struct | options_type |
Public Member Functions | |
template<typename... TArgs> | |
Writer (const osmium::io::File &file, TArgs &&... args) | |
template<typename... TArgs> | |
Writer (const std::string &filename, TArgs &&... args) | |
template<typename... TArgs> | |
Writer (const char *filename, TArgs &&... args) | |
Writer (const Writer &)=delete | |
Writer & | operator= (const Writer &)=delete |
Writer (Writer &&)=delete | |
Writer & | operator= (Writer &&)=delete |
~Writer () noexcept | |
size_t | buffer_size () const noexcept |
void | set_buffer_size (size_t size) noexcept |
void | set_header (const osmium::io::Header &header) |
void | flush () |
void | operator() (osmium::memory::Buffer &&buffer) |
void | operator() (const osmium::memory::Item &item) |
std::size_t | close () |
Private Types | |
enum | { default_buffer_size = 10UL * 1024UL * 1024UL } |
enum class | status { okay = 0 , error = 1 , closed = 2 } |
Private Member Functions | |
void | write_header () |
void | do_write (osmium::memory::Buffer &&buffer) |
void | do_flush () |
template<typename TFunction , typename... TArgs> | |
void | ensure_cleanup (TFunction func, TArgs &&... args) |
void | do_close () |
Static Private Member Functions | |
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) |
static void | set_option (options_type &options, osmium::thread::Pool &pool) |
static void | set_option (options_type &options, const osmium::io::Header &header) |
static void | set_option (options_type &options, overwrite value) |
static void | set_option (options_type &options, fsync value) |
Private Attributes | |
osmium::io::File | m_file |
detail::future_string_queue_type | m_output_queue {detail::get_output_queue_size(), "raw_output"} |
std::unique_ptr< osmium::io::detail::OutputFormat > | m_output {nullptr} |
osmium::memory::Buffer | m_buffer {} |
osmium::io::Header | m_header |
size_t | m_buffer_size = default_buffer_size |
std::future< std::size_t > | m_write_future {} |
osmium::thread::thread_handler | m_thread {} |
std::atomic_bool | m_notification {false} |
enum osmium::io::Writer::status | m_status = status::okay |
bool | m_header_written = false |
This is the user-facing interface for writing OSM files. Instantiate an object of this class with a file name or osmium::io::File object and optionally the data for the header and then call operator() on it to write Buffers or Items.
The writer uses multithreading internally to do the actual encoding of the data into the intended format, possible compress the data and then write it out. But this is intentionally hidden from the user of this class who can use it without knowing those details.
If you are done call the close() method to finish up. Only if you don't get an exception from the close() method, you can be sure the data is written correctly (modulo operating system buffering). The destructor of this class will also do the right thing if you forget to call close(), but because the destructor can't throw you will not get informed about any problems.
The writer is usually used to write complete blocks of data stored in osmium::memory::Buffers. But you can also write single osmium::memory::Items. In this case the Writer uses an internal Buffer.
|
strongprivate |
|
inlineexplicit |
The constructor of the Writer object opens a file and writes the header to it.
file | File (contains name and format info) to open. |
args | All further arguments are optional and can appear in any order: |
osmium::io_error | If there was an error. |
std::system_error | If the file could not be opened. |
|
inlineexplicit |
|
inlineexplicit |
|
delete |
|
delete |
|
inlinenoexcept |
|
inlinenoexcept |
Get the currently configured size of the internal buffer.
|
inline |
Flushes internal buffer and closes output file. If you do not call this, the destructor of Writer will also do the same thing. But because this call might throw an exception, which the destructor will ignore, it is better to call close() explicitly.
Some | form of osmium::io_error when there is a problem. |
|
inlineprivate |
|
inlineprivate |
|
inlineprivate |
|
inlineprivate |
|
inline |
Flush the internal buffer if it contains any data. This is usually not needed as the buffer gets flushed on close() automatically.
Some | form of osmium::io_error when there is a problem. |
|
inline |
Add item to the internal buffer for eventual writing to the output file.
item | Item to write (usually an OSM object). |
Some | form of osmium::io_error when there is a problem. |
|
inline |
Write contents of a buffer to the output file. The buffer is moved into this function and will be in an undefined moved-from state afterwards.
buffer | Buffer that is being written out. |
Some | form of osmium::io_error when there is a problem. |
|
inlinenoexcept |
Set the size of the internal buffer. This will only take effect if you have not yet written anything or after the next flush().
|
inline |
Set header. This will overwrite a header set in the constructor.
Has to be called before writing anything to the file, otherwise this will not do anything.
|
inlinestaticprivate |
|
inlinestaticprivate |
|
inlinestaticprivate |
|
inlinestaticprivate |
|
inlineprivate |
|
inlinestaticprivate |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |