libdballe 9.6
Public Member Functions | Static Public Member Functions | Protected Attributes | List of all members
dballe::core::File Class Reference

Base for dballe::File implementations. More...

#include <file.h>

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

Public Member Functions

 File (const std::string &name, FILE *fd, bool close_on_exit=true)
 
std::string pathname () const override
 Get the file pathname.
 
void close () override
 Close the underlying file.
 
bool foreach (std::function< bool(const BinaryMessage &)> dest) override
 Read all the messages from the file, calling the function on each of them.
 
- Public Member Functions inherited from dballe::File
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.
 
virtual bool foreach (std::function< bool(const BinaryMessage &)> dest)=0
 Read all the messages from the file, calling the function on each of them.
 
virtual void write (const std::string &msg)=0
 Append the binary message to the file.
 

Static Public Member Functions

static std::string resolve_test_data_file (const std::string &name)
 Resolve the location of a test data file.
 
static std::unique_ptr< dballe::Fileopen_test_data_file (Encoding type, const std::string &name)
 Open a test data file.
 
- Static Public Member Functions inherited from dballe::File
static std::unique_ptr< Filecreate (const std::string &pathname, const char *mode)
 Open a file from the filesystem, autodetecting the encoding type.
 
static std::unique_ptr< Filecreate (Encoding type, const std::string &pathname, const char *mode)
 Open a file from the filesystem.
 
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.
 
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.
 
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.
 

Protected Attributes

std::string m_name
 Name of the file.
 
FILE * fd
 FILE structure used to read or write to the file.
 
bool close_on_exit
 True if fd should be closed on destruction.
 
int idx
 Index of the last message read from the file or written to the file.
 

Detailed Description

Base for dballe::File implementations.

Constructor & Destructor Documentation

◆ ~File()

virtual dballe::core::File::~File ( )
virtual

Reimplemented from dballe::File.

Member Function Documentation

◆ close()

void dballe::core::File::close ( )
overridevirtual

Close the underlying file.

Implements dballe::File.

◆ foreach()

bool dballe::core::File::foreach ( std::function< bool(const BinaryMessage &)>  dest)
overridevirtual

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.

Implements dballe::File.

◆ open_test_data_file()

static std::unique_ptr< dballe::File > dballe::core::File::open_test_data_file ( Encoding  type,
const std::string &  name 
)
static

Open a test data file.

This should only be used during dballe unit tests.

◆ pathname()

std::string dballe::core::File::pathname ( ) const
inlineoverridevirtual

Get the file pathname.

Implements dballe::File.

References m_name.

◆ resolve_test_data_file()

static std::string dballe::core::File::resolve_test_data_file ( const std::string &  name)
static

Resolve the location of a test data file.

This should only be used during dballe unit tests.


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