Libosmium: osmium::io::Reader Class Reference

Libosmium Fast and flexible C++ library for working with OpenStreetMap data

Loading...
Searching...
No Matches
Public Member Functions | Private Types | Private Member Functions | Static Private Member Functions | Private Attributes | List of all members
osmium::io::Reader Class Reference

`#include <reader.hpp>`

Inheritance diagram for osmium::io::Reader:
[legend]
Collaboration diagram for osmium::io::Reader:
[legend]

## Public Member Functions
template<typename... TArgs>
| Reader (const osmium::io::File &file, TArgs &&... args)
template<typename... TArgs>
| Reader (const std::string &filename, TArgs &&... args)
template<typename... TArgs>
| Reader (const char *filename, TArgs &&... args)
| Reader (const Reader &)=delete
Reader & | operator= (const Reader &)=delete
| Reader (Reader &&)=delete
Reader & | operator= (Reader &&)=delete
| ~Reader () noexcept
void | close ()
osmium::io::Header | header ()
osmium::memory::Buffer | read ()
bool | eof () const
std::size_t | file_size () const noexcept
std::size_t | offset () const noexcept

## Private Types
enum class | status { okay = 0 , error = 1 , closed = 2 , eof = 3 }

## Private Member Functions
void | set_option (osmium::thread::Pool &pool) noexcept
void | set_option (osmium::osm_entity_bits::type value) noexcept
void | set_option (osmium::io::read_meta value) noexcept
void | set_option (osmium::io::buffers_type value) noexcept

## Static Private Member Functions
static void | parser_thread (osmium::thread::Pool &pool, int fd, const detail::ParserFactory::create_parser_type &creator, detail::future_string_queue_type &input_queue, detail::future_buffer_queue_type &osmdata_queue, std::promise< osmium::io::Header > &&header_promise, std::atomic< std::size_t > *offset_ptr, osmium::osm_entity_bits::type read_which_entities, osmium::io::read_meta read_metadata, osmium::io::buffers_type buffers_kind, bool want_buffered_pages_removed)
static int | execute (const std::string &command, const std::string &filename, int *childpid)
static int | open_input_file_or_url (const std::string &filename, int *childpid)
static std::unique_ptr< Decompressor > | make_decompressor (const osmium::io::File &file, int fd, std::atomic< std::size_t > *offset_ptr)

## Private Attributes
osmium::memory::Buffer | m_back_buffers
osmium::io::File | m_file
osmium::thread::Pool * | m_pool = nullptr
std::atomic< std::size_t > | m_offset {0}
detail::ParserFactory::create_parser_type | m_creator
enum osmium::io::Reader::status | m_status = status::okay
int | m_childpid = 0
detail::future_string_queue_type | m_input_queue
int | m_fd = -1
std::size_t | m_file_size = 0
std::unique_ptr< osmium::io::Decompressor > | m_decompressor
osmium::io::detail::ReadThreadManager | m_read_thread_manager
detail::future_buffer_queue_type | m_osmdata_queue
detail::queue_wrapper< osmium::memory::Buffer > | m_osmdata_queue_wrapper
std::future< osmium::io::Header > | m_header_future
osmium::io::Header | m_header
osmium::thread::thread_handler | m_thread
osmium::osm_entity_bits::type | m_read_which_entities = osmium::osm_entity_bits::all
osmium::io::read_meta | m_read_metadata = osmium::io::read_meta::yes
osmium::io::buffers_type | m_buffers_kind = osmium::io::buffers_type::any

## Detailed Description

This is the user-facing interface for reading OSM files. Instantiate an object of this class with a file name or osmium::io::File object and then call read() on it in a loop until it returns an invalid Buffer.

## Member Enumeration Documentation

## ◆ status

enum class osmium::io::Reader::status
| strongprivate

Enumerator
okay |
error |
closed |
eof |

## Constructor & Destructor Documentation

## ◆ Reader() [1/5]

template<typename... TArgs>

osmium::io::Reader::Reader | ( | const osmium::io::File & | file,
|  | TArgs &&... | args )
| inlineexplicit

Create new Reader object.

Parameters

  file | The file (contains name and format info) to open.
  args | All further arguments are optional and can appear in any order:

- osmium::osm_entities::bits: Which OSM entities (nodes, ways, relations, and/or changesets) should be read from the input file. It can speed the read up significantly if objects that are not needed anyway are not parsed.
- osmium::io::read_meta: Read meta data or not. The default is osmium::io::read_meta::yes which means that meta data is read normally. If you set this to osmium::io::read_meta::no, meta data (like version, uid, etc.) is not read possibly speeding up the read. Not all file formats use this setting. Do not set this to osmium::io::read_meta::no for history or change files because you will loose the information whether an object is visible!
- osmium::io::buffers_type: Fill entities into buffers until the buffers are full (osmium::io::buffers_type::any) or only fill entities of the same type into a buffer (osmium::io::buffers_type::single). Every time a new entity type is seen a new buffer will be started. Do not use in "single" mode if the input file is not sorted by type, otherwise this will be rather inefficient.
- osmium::thread::Pool&: Reference to a thread pool that should be used for reading instead of the default pool. Usually it is okay to use the statically initialized shared default pool, but sometimes you want or need your own. For instance when your program will fork, using the statically initialized pool will not work.

Exceptions

  osmium::io_error | If there was an error.
  std::system_error | If the file could not be opened.

## ◆ Reader() [2/5]

template<typename... TArgs>

osmium::io::Reader::Reader | ( | const std::string & | filename,
|  | TArgs &&... | args )
| inlineexplicit

## ◆ Reader() [3/5]

template<typename... TArgs>

osmium::io::Reader::Reader | ( | const char * | filename,
|  | TArgs &&... | args )
| inlineexplicit

## ◆ Reader() [4/5]

osmium::io::Reader::Reader | ( | const Reader & |  | ) |
| delete

## ◆ Reader() [5/5]

osmium::io::Reader::Reader | ( | Reader && |  | ) |
| delete

## ◆ ~Reader()

osmium::io::Reader::~Reader | ( |  | ) |
| inlinenoexcept

## Member Function Documentation

## ◆ close()

void osmium::io::Reader::close | ( |  | ) |
| inline

Close down the Reader. A call to this is optional, because the destructor of Reader will also call this. But if you don't call this function first, you might miss an exception, because the destructor is not allowed to throw.

Exceptions

  Some | form of osmium::io_error when there is a problem.

## ◆ eof()

bool osmium::io::Reader::eof | ( |  | ) | const
| inline

Has the end of file been reached? This is set after the last data has been read. It is also set by calling close().

## ◆ execute()

int osmium::io::Reader::execute | ( | const std::string & | command,
|  | const std::string & | filename,
|  | int * | childpid )
| inlinestaticprivate

Fork and execute the given command in the child. A pipe is created between the child and the parent. The child writes to the pipe, the parent reads from it. This function never returns in the child.

Parameters

  command | Command to execute in the child.
  filename | Filename to give to command as argument.

Returns
  File descriptor of pipe in the parent.

Exceptions

  std::system_error | if a system call fails.

## ◆ file_size()

std::size_t osmium::io::Reader::file_size | ( |  | ) | const
| inlinenoexcept

Get the size of the input file. Returns 0 if the file size is not available (for instance when reading from stdin).

## ◆ header()

osmium::io::Header osmium::io::Reader::header | ( |  | ) |
| inline

Get the header data from the file.

Returns
  Header.

Exceptions

  Some | form of osmium::io_error if there is an error.

## ◆ make_decompressor()

std::unique_ptr< Decompressor > osmium::io::Reader::make_decompressor | ( | const osmium::io::File & | file,
|  | int | fd,
|  | std::atomic< std::size_t > * | offset_ptr )
| inlinestaticprivate

## ◆ offset()

std::size_t osmium::io::Reader::offset | ( |  | ) | const
| inlinenoexcept

Returns the current offset into the input file. Returns 0 if the offset is not available (for instance when reading from stdin).

The offset can be used together with the result of file_size() to estimate how much of the file has been read. Note that due to buffering inside Osmium, this value will be larger than the amount of data actually available to the application.

Do not call this function too often, certainly not for every object you are reading. Depending on the file type it might do an expensive system call.

## ◆ open_input_file_or_url()

int osmium::io::Reader::open_input_file_or_url | ( | const std::string & | filename,
|  | int * | childpid )
| inlinestaticprivate

Open File for reading. Handles URLs or normal files. URLs are opened by executing the "curl" program (which must be installed) and reading from its output.

Returns
  File descriptor of open file or pipe.

Exceptions

  std::system_error | if a system call fails.

## ◆ operator=() [1/2]

Reader & osmium::io::Reader::operator= | ( | const Reader & |  | ) |
| delete

## ◆ operator=() [2/2]

Reader & osmium::io::Reader::operator= | ( | Reader && |  | ) |
| delete

## ◆ parser_thread()

void osmium::io::Reader::parser_thread | ( | osmium::thread::Pool & | pool,
|  | int | fd,
|  | const detail::ParserFactory::create_parser_type & | creator,
|  | detail::future_string_queue_type & | input_queue,
|  | detail::future_buffer_queue_type & | osmdata_queue,
|  | std::promise< osmium::io::Header > && | header_promise,
|  | std::atomic< std::size_t > * | offset_ptr,
|  | osmium::osm_entity_bits::type | read_which_entities,
|  | osmium::io::read_meta | read_metadata,
|  | osmium::io::buffers_type | buffers_kind,
|  | bool | want_buffered_pages_removed )
| inlinestaticprivate

## ◆ read()

osmium::memory::Buffer osmium::io::Reader::read | ( |  | ) |
| inline

Reads the next buffer from the input. An invalid buffer signals end-of-file. After end-of-file all read() calls will throw an osmium::io_error.

Returns
  Buffer.

Exceptions

  Some | form of osmium::io_error if there is an error.

## ◆ set_option() [1/4]

void osmium::io::Reader::set_option | ( | osmium::io::buffers_type | value | ) |
| inlineprivatenoexcept

## ◆ set_option() [2/4]

void osmium::io::Reader::set_option | ( | osmium::io::read_meta | value | ) |
| inlineprivatenoexcept

## ◆ set_option() [3/4]

void osmium::io::Reader::set_option | ( | osmium::osm_entity_bits::type | value | ) |
| inlineprivatenoexcept

## ◆ set_option() [4/4]

void osmium::io::Reader::set_option | ( | osmium::thread::Pool & | pool | ) |
| inlineprivatenoexcept

## Member Data Documentation

## ◆ m_back_buffers

osmium::memory::Buffer osmium::io::Reader::m_back_buffers
| private

## ◆ m_buffers_kind

osmium::io::buffers_type osmium::io::Reader::m_buffers_kind = osmium::io::buffers_type::any
| private

## ◆ m_childpid

int osmium::io::Reader::m_childpid = 0
| private

## ◆ m_creator

detail::ParserFactory::create_parser_type osmium::io::Reader::m_creator
| private

## ◆ m_decompressor

std::unique_ptr<osmium::io::Decompressor> osmium::io::Reader::m_decompressor
| private

## ◆ m_fd

int osmium::io::Reader::m_fd = -1
| private

## ◆ m_file

osmium::io::File osmium::io::Reader::m_file
| private

## ◆ m_file_size

std::size_t osmium::io::Reader::m_file_size = 0
| private

## ◆ m_header

osmium::io::Header osmium::io::Reader::m_header
| private

## ◆ m_header_future

std::future<osmium::io::Header> osmium::io::Reader::m_header_future
| private

## ◆ m_input_queue

detail::future_string_queue_type osmium::io::Reader::m_input_queue
| private

## ◆ m_offset

std::atomic<std::size_t> osmium::io::Reader::m_offset {0}
| private

## ◆ m_osmdata_queue

detail::future_buffer_queue_type osmium::io::Reader::m_osmdata_queue
| private

## ◆ m_osmdata_queue_wrapper

detail::queue_wrapper<osmium::memory::Buffer> osmium::io::Reader::m_osmdata_queue_wrapper
| private

## ◆ m_pool

osmium::thread::Pool* osmium::io::Reader::m_pool = nullptr
| private

## ◆ m_read_metadata

osmium::io::read_meta osmium::io::Reader::m_read_metadata = osmium::io::read_meta::yes
| private

## ◆ m_read_thread_manager

osmium::io::detail::ReadThreadManager osmium::io::Reader::m_read_thread_manager
| private

## ◆ m_read_which_entities

osmium::osm_entity_bits::type osmium::io::Reader::m_read_which_entities = osmium::osm_entity_bits::all
| private

## ◆ m_status

enum osmium::io::Reader::status osmium::io::Reader::m_status = status::okay
| private

## ◆ m_thread

osmium::thread::thread_handler osmium::io::Reader::m_thread
| private

The documentation for this class was generated from the following file:

- include/osmium/io/reader.hpp