Osmium  0.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
Classes | Public Member Functions | Private Member Functions | Private Attributes
Osmium::OSMFile Class Reference

#include <osmfile.hpp>

Collaboration diagram for Osmium::OSMFile:
Collaboration graph
[legend]

List of all members.

Classes

class  ArgumentError
class  FileEncoding
class  FileType
struct  FileTypeError
struct  FileTypeHistoryExpected
struct  FileTypeOSMExpected
class  IOError
class  SystemError

Public Member Functions

 OSMFile (const std::string &filename="")
void set_type_and_encoding (const std::string &suffix)
 OSMFile (const OSMFile &orig)
OSMFileoperator= (const OSMFile &orig)
 ~OSMFile ()
void close ()
void default_settings_for_stdinout ()
void default_settings_for_file ()
void default_settings_for_url ()
int get_fd () const
FileTypeget_type () const
OSMFileset_type (FileType *type)
OSMFileset_type (std::string &type)
bool has_multiple_object_versions () const
FileEncodingget_encoding () const
OSMFileset_encoding (FileEncoding *encoding)
OSMFileset_encoding (std::string &encoding)
OSMFileset_filename (std::string &filename)
std::string get_filename () const
std::string get_filename_without_suffix () const
std::string get_filename_with_default_suffix () const
void open_for_input ()
void open_for_output ()
template<class T >
void read (T &handler)
Osmium::Output::Basecreate_output_file ()

Private Member Functions

int execute (std::string command, int input)
int open_input_file () const
int open_output_file () const
int open_input_file_or_url ()

Private Attributes

FileTypem_type
 Type of file.
FileEncodingm_encoding
 Encoding of file.
std::string m_filename
 File name.
int m_fd
 File descriptor. -1 before the file is opened.
pid_t m_childpid

Detailed Description

This class describes an OSM file in one of several different formats. It can be used as factory class for generating input and output OSM files.

If the filename is empty, this means stdin or stdout is used. If you set the filename to "-" it will be treated the same.


Constructor & Destructor Documentation

Osmium::OSMFile::OSMFile ( const std::string &  filename = "") [inline]

Create OSMFile using type and encoding from filename. If you want to overwrite these settings you can change them later.

Parameters:
filenameFilename including suffix. The type and encoding of the file will be taken from the suffix. An empty filename or "-" means stdin or stdout.
Osmium::OSMFile::OSMFile ( const OSMFile orig) [inline]

Copy constructor. Only attributes not related to the open file will be copied.


Member Function Documentation

void Osmium::OSMFile::close ( ) [inline]

Create output file from OSMFile.

Set default settings for type and encoding when the filename is a normal file. If you want to have a different default setting override this in a subclass.

Set default settings for type and encoding when the filename is empty or "-". If you want to have a different default setting override this in a subclass.

Set default settings for type and encoding when the filename is a URL. If you want to have a different default setting override this in a subclass.

int Osmium::OSMFile::execute ( std::string  command,
int  input 
) [inline, private]

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.
input0 for reading from child, 1 for writing to child.
Returns:
File descriptor of pipe in the parent.
Exceptions:
SystemErrorif a system call fails.
int Osmium::OSMFile::get_fd ( ) const [inline]
std::string Osmium::OSMFile::get_filename ( ) const [inline]
std::string Osmium::OSMFile::get_filename_with_default_suffix ( ) const [inline]
std::string Osmium::OSMFile::get_filename_without_suffix ( ) const [inline]
FileType* Osmium::OSMFile::get_type ( ) const [inline]
int Osmium::OSMFile::open_input_file ( ) const [inline, private]

Open OSMFile for reading.

Returns:
File descriptor of open file.
Exceptions:
IOErrorif the file can't be opened.
int Osmium::OSMFile::open_input_file_or_url ( ) [inline, private]

Open OSMFile 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:
SystemErrorif a system call fails.
IOErrorif the file can't be opened.
int Osmium::OSMFile::open_output_file ( ) const [inline, private]

Open OSMFile for writing. If the file exists, it is truncated, if not it is created.

Returns:
File descriptor of open file.
Exceptions:
IOErrorif the file can't be opened.
OSMFile& Osmium::OSMFile::operator= ( const OSMFile orig) [inline]

Assignement operator. Only attributes not related to the open file will be copied.

template<class T >
void Osmium::OSMFile::read ( T &  handler)

Read OSM file and call methods on handler object.

OSMFile& Osmium::OSMFile::set_encoding ( std::string &  encoding) [inline]
OSMFile& Osmium::OSMFile::set_filename ( std::string &  filename) [inline]
OSMFile& Osmium::OSMFile::set_type ( std::string &  type) [inline]
void Osmium::OSMFile::set_type_and_encoding ( const std::string &  suffix) [inline]

Member Data Documentation

pid_t Osmium::OSMFile::m_childpid [private]

Contains the child process id if a child was created to uncompress data or for getting a URL.

Encoding of file.

int Osmium::OSMFile::m_fd [private]

File descriptor. -1 before the file is opened.

std::string Osmium::OSMFile::m_filename [private]

File name.

Type of file.


The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines