File object for doing I/O on binary message streams.
More...
#include <file.h>
|
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 std::unique_ptr< File > | create (const std::string &pathname, const char *mode) |
| Open a file from the filesystem, autodetecting the encoding type. More...
|
|
static std::unique_ptr< File > | create (Encoding type, const std::string &pathname, const char *mode) |
| Open a file from the filesystem. More...
|
|
static std::unique_ptr< File > | create (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< File > | create (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.
|
|
File object for doing I/O on binary message streams.
It provides a unified interface to read and write messages to files.
◆ 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
-
pathname | The pathname of the file to access. |
mode | The 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
-
type | The type of data contained in the file. |
pathname | The pathname of the file to access. |
mode | The 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
-
file | The FILE* stream for the file to access. |
close_on_exit | If true, fclose() will be called on the stream when the File object is destroyed. |
name | Pathname 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
-
type | The type of data contained in the file. |
file | The FILE* stream for the file to access. |
close_on_exit | If true, fclose() will be called on the stream when the File object is destroyed. |
name | Pathname 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()
The documentation for this struct was generated from the following file: