Libosmium  2.6.0
Fast and flexible C++ library for working with OpenStreetMap data
Public Member Functions | Private Types | Static Private Member Functions | Private Attributes | Static Private Attributes | List of all members
osmium::io::Reader Class Reference

#include <reader.hpp>

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

Public Member Functions

 Reader (const osmium::io::File &file, osmium::osm_entity_bits::type read_which_entities=osmium::osm_entity_bits::all)
 
 Reader (const std::string &filename, osmium::osm_entity_bits::type read_types=osmium::osm_entity_bits::all)
 
 Reader (const char *filename, osmium::osm_entity_bits::type read_types=osmium::osm_entity_bits::all)
 
 Reader (const Reader &)=delete
 
Readeroperator= (const Reader &)=delete
 
 Reader (Reader &&)=default
 
Readeroperator= (Reader &&)=default
 
 ~Reader () noexcept
 
void close ()
 
osmium::io::Header header ()
 
osmium::memory::Buffer read ()
 
bool eof () const
 

Private Types

enum  status { status::okay = 0, status::error = 1, status::closed = 2, status::eof = 3 }
 

Static Private Member Functions

static void parser_thread (const osmium::io::File &file, detail::future_string_queue_type &input_queue, detail::future_buffer_queue_type &osmdata_queue, std::promise< osmium::io::Header > &&header_promise, osmium::osm_entity_bits::type read_which_entities)
 
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)
 

Private Attributes

osmium::io::File m_file
 
osmium::osm_entity_bits::type m_read_which_entities
 
enum osmium::io::Reader::status m_status
 
int m_childpid
 
detail::future_string_queue_type m_input_queue
 
std::unique_ptr< osmium::io::Decompressorm_decompressor
 
osmium::io::detail::ReadThreadManager m_read_thread_manager
 
detail::future_buffer_queue_type m_osmdata_queue
 
detail::queue_wrapper< osmium::memory::Bufferm_osmdata_queue_wrapper
 
std::future< osmium::io::Headerm_header_future
 
osmium::io::Header m_header
 
osmium::thread::thread_handler m_thread
 

Static Private Attributes

static constexpr size_t max_input_queue_size = 20
 
static constexpr size_t max_osmdata_queue_size = 20
 

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

enum osmium::io::Reader::status
strongprivate
Enumerator
okay 
error 
closed 
eof 

Constructor & Destructor Documentation

osmium::io::Reader::Reader ( const osmium::io::File file,
osmium::osm_entity_bits::type  read_which_entities = osmium::osm_entity_bits::all 
)
inlineexplicit

Create new Reader object.

Parameters
fileThe file we want to open.
read_which_entitiesWhich 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::Reader::Reader ( const std::string &  filename,
osmium::osm_entity_bits::type  read_types = osmium::osm_entity_bits::all 
)
inlineexplicit
osmium::io::Reader::Reader ( const char *  filename,
osmium::osm_entity_bits::type  read_types = osmium::osm_entity_bits::all 
)
inlineexplicit
osmium::io::Reader::Reader ( const Reader )
delete
osmium::io::Reader::Reader ( Reader &&  )
default
osmium::io::Reader::~Reader ( )
inlinenoexcept

Member Function Documentation

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
Someform of osmium::io_error when there is a problem.
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().

static 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
commandCommand to execute in the child.
filenameFilename to give to command as argument.
Returns
File descriptor of pipe in the parent.
Exceptions
std::system_errorif a system call fails.
osmium::io::Header osmium::io::Reader::header ( )
inline

Get the header data from the file.

Returns
Header.
Exceptions
Someform of osmium::io_error if there is an error.
static 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_errorif a system call fails.
Reader& osmium::io::Reader::operator= ( const Reader )
delete
Reader& osmium::io::Reader::operator= ( Reader &&  )
default
static void osmium::io::Reader::parser_thread ( const osmium::io::File file,
detail::future_string_queue_type &  input_queue,
detail::future_buffer_queue_type &  osmdata_queue,
std::promise< osmium::io::Header > &&  header_promise,
osmium::osm_entity_bits::type  read_which_entities 
)
inlinestaticprivate
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 return an invalid buffer. An invalid buffer is also always returned if osmium::osm_entity_bits::nothing was set when the Reader was constructed.

Returns
Buffer.
Exceptions
Someform of osmium::io_error if there is an error.

Member Data Documentation

int osmium::io::Reader::m_childpid
private
std::unique_ptr<osmium::io::Decompressor> osmium::io::Reader::m_decompressor
private
osmium::io::File osmium::io::Reader::m_file
private
osmium::io::Header osmium::io::Reader::m_header
private
std::future<osmium::io::Header> osmium::io::Reader::m_header_future
private
detail::future_string_queue_type osmium::io::Reader::m_input_queue
private
detail::future_buffer_queue_type osmium::io::Reader::m_osmdata_queue
private
detail::queue_wrapper<osmium::memory::Buffer> osmium::io::Reader::m_osmdata_queue_wrapper
private
osmium::io::detail::ReadThreadManager osmium::io::Reader::m_read_thread_manager
private
osmium::osm_entity_bits::type osmium::io::Reader::m_read_which_entities
private
enum osmium::io::Reader::status osmium::io::Reader::m_status
private
osmium::thread::thread_handler osmium::io::Reader::m_thread
private
constexpr size_t osmium::io::Reader::max_input_queue_size = 20
staticprivate
constexpr size_t osmium::io::Reader::max_osmdata_queue_size = 20
staticprivate

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