Gamedev Framework (gf)  0.8.0
A C++14 framework for 2D games
Public Types | Public Member Functions | List of all members
gf::BinaryFile Class Reference

A binary file that can be read or written. More...

#include <gf/BinaryFile.h>

Public Types

enum  Mode {
  Mode::Read,
  Mode::Write,
  Mode::Append
}
 Open mode for the file. More...
 

Public Member Functions

 BinaryFile (const Path &filename, Mode mode)
 Constructor. More...
 
 BinaryFile (const BinaryFile &)=delete
 Deleted copy constructor. More...
 
BinaryFileoperator= (const BinaryFile &)=delete
 Deleted copy assignment. More...
 
 BinaryFile (BinaryFile &&other)
 Move constructor. More...
 
BinaryFileoperator= (BinaryFile &&other)
 Move assignment. More...
 
 ~BinaryFile ()
 Destructor. More...
 
std::size_t write (ArrayRef< uint8_t > buffer) const
 Write a buffer in the file. More...
 
std::size_t write (uint8_t byte) const
 Write a single byte in the file. More...
 
std::size_t read (BufferRef< uint8_t > buffer) const
 Read from the file into a buffer. More...
 
std::size_t read (uint8_t &byte) const
 Read a single byte from the file. More...
 
bool isEof () const
 Tell if the file is at the end. More...
 

Detailed Description

A binary file that can be read or written.

Member Enumeration Documentation

◆ Mode

enum gf::BinaryFile::Mode
strong

Open mode for the file.

Enumerator
Read 

Open the file in read only.

Write 

Open the file in write only.

Append 

Open the file in append only.

Constructor & Destructor Documentation

◆ BinaryFile() [1/3]

gf::BinaryFile::BinaryFile ( const Path filename,
Mode  mode 
)

Constructor.

Parameters
filenameThe filename of the binary file
modeThe open mode

◆ BinaryFile() [2/3]

gf::BinaryFile::BinaryFile ( const BinaryFile )
delete

Deleted copy constructor.

◆ BinaryFile() [3/3]

gf::BinaryFile::BinaryFile ( BinaryFile &&  other)

Move constructor.

◆ ~BinaryFile()

gf::BinaryFile::~BinaryFile ( )

Destructor.

The file is closed in the destructor.

Member Function Documentation

◆ isEof()

bool gf::BinaryFile::isEof ( ) const

Tell if the file is at the end.

Returns
True if the file reached the end

◆ operator=() [1/2]

BinaryFile& gf::BinaryFile::operator= ( const BinaryFile )
delete

Deleted copy assignment.

◆ operator=() [2/2]

BinaryFile& gf::BinaryFile::operator= ( BinaryFile &&  other)

Move assignment.

◆ read() [1/2]

std::size_t gf::BinaryFile::read ( BufferRef< uint8_t >  buffer) const

Read from the file into a buffer.

Parameters
bufferThe buffer to read from the file
Returns
The number of bytes read from the file

◆ read() [2/2]

std::size_t gf::BinaryFile::read ( uint8_t &  byte) const

Read a single byte from the file.

Parameters
byteThe byte to read from the file
Returns
The number of bytes read from the file

◆ write() [1/2]

std::size_t gf::BinaryFile::write ( ArrayRef< uint8_t >  buffer) const

Write a buffer in the file.

Parameters
bufferThe buffer to write in the file
Returns
The number of bytes written in the file

◆ write() [2/2]

std::size_t gf::BinaryFile::write ( uint8_t  byte) const

Write a single byte in the file.

Parameters
byteThe byte to write in the file
Returns
The number of bytes written in the file