OpenTTD Source: FileHandle Class Reference

OpenTTD Source 15.0-beta1

Data Structures | Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes
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< FileHandle > | Open (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, FileDeleter > | f

## 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

  filename | UTF-8 encoded filename to open.
  mode | Mode to open file.

Returns
  FileHandle, or std::nullopt on failure.

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

Parameters

  filename | UTF-8 encoded filename to open.
  mode | Mode 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:

- src/fileio_type.h
- src/fileio.cpp
- src/settingsgen/settingsgen.cpp