Libosmium  2.3.0
Fast and flexible C++ library for working with OpenStreetMap data
Public Member Functions | Static Private Member Functions | 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 ()
 
void close ()
 
osmium::io::Header header () const
 
osmium::memory::Buffer read ()
 
bool eof () const
 

Static Private Member Functions

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
 
std::atomic< bool > m_input_done
 
int m_childpid
 
osmium::thread::Queue< std::string > m_input_queue
 
std::unique_ptr< osmium::io::Decompressorm_decompressor
 
std::future< bool > m_read_future
 
std::unique_ptr< osmium::io::detail::InputFormat > m_input
 

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.

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 ( )
inline

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, the destructor might throw an exception which is not good.

Exceptions
Someform of std::runtime_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 ( ) const
inline

Get the header data from the file.

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
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 std::runtime_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
std::unique_ptr<osmium::io::detail::InputFormat> osmium::io::Reader::m_input
private
std::atomic<bool> osmium::io::Reader::m_input_done
private
osmium::thread::Queue<std::string> osmium::io::Reader::m_input_queue
private
std::future<bool> osmium::io::Reader::m_read_future
private
osmium::osm_entity_bits::type osmium::io::Reader::m_read_which_entities
private

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