libdballe  9.11
Public Member Functions | Static Public Member Functions | List of all members
dballe::File Class Referenceabstract

File object for doing I/O on binary message streams. More...

#include <file.h>

Inheritance diagram for dballe::File:
dballe::core::File dballe::core::ArrayFile dballe::core::BufrFile dballe::core::CrexFile dballe::core::JsonFile

Public Member Functions

virtual std::string pathname () const =0
 Get the file pathname.
 
virtual Encoding encoding () const =0
 Get the file encoding.
 
virtual void close ()=0
 Close the underlying file.
 
virtual BinaryMessage read ()=0
 Read a message from the file. More...
 
virtual bool foreach (std::function< bool(const BinaryMessage &)> dest)=0
 Read all the messages from the file, calling the function on each of them. More...
 
virtual void write (const std::string &msg)=0
 Append the binary message to the file.
 

Static Public Member Functions

static std::unique_ptr< Filecreate (const std::string &pathname, const char *mode)
 Open a file from the filesystem, autodetecting the encoding type. More...
 
static std::unique_ptr< Filecreate (Encoding type, const std::string &pathname, const char *mode)
 Open a file from the filesystem. More...
 
static std::unique_ptr< Filecreate (FILE *file, bool close_on_exit, const std::string &name="(fp)")
 Create a File from an existing FILE* stream, autodetecting the encoding type. More...
 
static std::unique_ptr< Filecreate (Encoding type, FILE *file, bool close_on_exit, const std::string &name="(fp)")
 Create a File from an existing FILE* stream. More...
 
static const char * encoding_name (Encoding enc)
 Return a string with the name of this encoding.
 
static Encoding parse_encoding (const char *s)
 Return the Encoding corresponding to the given name.
 
static Encoding parse_encoding (const std::string &s)
 Return the Encoding corresponding to the given name.
 

Detailed Description

File object for doing I/O on binary message streams.

It provides a unified interface to read and write messages to files.

Member Function Documentation

◆ create() [1/4]

static std::unique_ptr<File> dballe::File::create ( const std::string &  pathname,
const char *  mode 
)
static

Open a file from the filesystem, autodetecting the encoding type.

Parameters
pathnameThe pathname of the file to access.
modeThe opening mode of the file, as used by fopen.
Returns
The new File object.

◆ create() [2/4]

static std::unique_ptr<File> dballe::File::create ( Encoding  type,
const std::string &  pathname,
const char *  mode 
)
static

Open a file from the filesystem.

Parameters
typeThe type of data contained in the file.
pathnameThe pathname of the file to access.
modeThe opening mode of the file, as used by fopen.
Returns
The new File object.

◆ create() [3/4]

static std::unique_ptr<File> dballe::File::create ( FILE *  file,
bool  close_on_exit,
const std::string &  name = "(fp)" 
)
static

Create a File from an existing FILE* stream, autodetecting the encoding type.

Parameters
fileThe FILE* stream for the file to access.
close_on_exitIf true, fclose() will be called on the stream when the File object is destroyed.
namePathname or description of the stream, used when generating error messages
Returns
The new File object.

◆ create() [4/4]

static std::unique_ptr<File> dballe::File::create ( Encoding  type,
FILE *  file,
bool  close_on_exit,
const std::string &  name = "(fp)" 
)
static

Create a File from an existing FILE* stream.

Parameters
typeThe type of data contained in the file.
fileThe FILE* stream for the file to access.
close_on_exitIf true, fclose() will be called on the stream when the File object is destroyed.
namePathname or description of the stream, used when generating error messages
Returns
The new File object.

◆ foreach()

virtual bool dballe::File::foreach ( std::function< bool(const BinaryMessage &)>  dest)
pure virtual

Read all the messages from the file, calling the function on each of them.

If dest returns false, reading will stop.

Returns
true if all file was read, false if reading was stopped because dest returned false.

Implemented in dballe::core::File.

◆ read()

virtual BinaryMessage dballe::File::read ( )
pure virtual

Read a message from the file.

Returns
the BinaryMessage with the binary data that have been read, or nullptr when the end of file has been reached.

Implemented in dballe::core::JsonFile, dballe::core::CrexFile, dballe::core::BufrFile, and dballe::core::ArrayFile.


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