OpenTTD Source 20241224-master-gf74b0cf984
FileHandle Class Reference

Data Structures

struct  FileDeleter
 Helper to close a FILE * with a std::unique_ptr. More...
 

Public Member Functions

void Close ()
 
 operator FILE * ()
 

Static Public Member Functions

static std::optional< FileHandleOpen (const std::string &filename, const std::string &mode)
 Open an RAII file handle if possible.
 

Private Member Functions

 FileHandle (FILE *f)
 

Private Attributes

std::unique_ptr< FILE, FileDeleterf
 

Detailed Description

Definition at line 158 of file fileio_type.h.

Constructor & Destructor Documentation

◆ FileHandle()

FileHandle::FileHandle ( FILE *  f)
inlineprivate

Definition at line 181 of file fileio_type.h.

Member Function Documentation

◆ Close()

void FileHandle::Close ( )
inline

Definition at line 162 of file fileio_type.h.

◆ Open()

std::optional< FileHandle > FileHandle::Open ( const std::string &  filename,
const std::string &  mode 
)
static

Open an RAII file handle if possible.

Simplified FileHandle::Open which ignores OTTD2FS.

The canonical RAII-way is for FileHandle to open the file and throw an exception on failure, but we don't want that.

Parameters
filenameUTF-8 encoded filename to open.
modeMode to open file.
Returns
FileHandle, or std::nullopt on failure.

Required as settingsgen does not include all of the fileio system.

Parameters
filenameUTF-8 encoded filename to open.
modeMode to open file.
Returns
FileHandle, or std::nullopt on failure.

Definition at line 1170 of file fileio.cpp.

References OTTD2FS().

Referenced by TarScanner::AddFile(), AppendFile(), ClientNetworkContentSocketHandler::BeforeDownload(), CompareFiles(), ExtractTar(), FioFOpenFileTar(), GetLanguageFileHeader(), GunzipFile(), DLSFile::LoadFile(), LoadFromHighScore(), main(), MakeBMPImage(), MakePCXImage(), MakePNGImage(), SettingsIniFile::OpenFile(), ReadFileToMem(), and SaveToHighScore().

◆ operator FILE *()

FileHandle::operator FILE * ( )
inline

Definition at line 164 of file fileio_type.h.

Field Documentation

◆ f

std::unique_ptr<FILE, FileDeleter> FileHandle::f
private

Definition at line 179 of file fileio_type.h.


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