OpenTTD Source 20241224-master-gf74b0cf984
FileWriter Struct Reference

Yes, simply writing to a file. More...

Inheritance diagram for FileWriter:
SaveFilter HeaderFileWriter LanguageFileWriter

Public Member Functions

 FileWriter (FileHandle &&file)
 Create the file writer, so it writes to a specific file.
 
 ~FileWriter ()
 Make sure everything is cleaned up.
 
void Write (uint8_t *buf, size_t size) override
 Write a given number of bytes into the savegame.
 
void Finish () override
 Prepare everything to finish writing the savegame.
 
 FileWriter (const std::filesystem::path &path, std::ios_base::openmode openmode)
 Open a file to write to.
 
void Finalise ()
 Finalise the writing.
 
virtual ~FileWriter ()
 Make sure the file is closed.
 
- Public Member Functions inherited from SaveFilter
 SaveFilter (std::shared_ptr< SaveFilter > chain)
 Initialise this filter.
 
virtual ~SaveFilter ()=default
 Make sure the writers are properly closed.
 

Data Fields

std::optional< FileHandlefile
 The file to write to.
 
std::ofstream output_stream
 The stream to write all the output to.
 
const std::filesystem::path path
 The file name we're writing to.
 
- Data Fields inherited from SaveFilter
std::shared_ptr< SaveFilterchain
 Chained to the (savegame) filters.
 

Detailed Description

Yes, simply writing to a file.

Base class for writing data to disk.

Definition at line 2280 of file saveload.cpp.

Constructor & Destructor Documentation

◆ FileWriter() [1/2]

FileWriter::FileWriter ( FileHandle &&  file)
inline

Create the file writer, so it writes to a specific file.

Parameters
fileThe file to write to.

Definition at line 2287 of file saveload.cpp.

◆ ~FileWriter() [1/2]

FileWriter::~FileWriter ( )
inline

Make sure everything is cleaned up.

Definition at line 2292 of file saveload.cpp.

References Finish().

◆ FileWriter() [2/2]

FileWriter::FileWriter ( const std::filesystem::path &  path,
std::ios_base::openmode  openmode 
)
inline

Open a file to write to.

Parameters
pathThe path to the file to open.
openmodeThe openmode flags for opening the file.

Definition at line 200 of file strgen.cpp.

References path.

◆ ~FileWriter() [2/2]

virtual FileWriter::~FileWriter ( )
inlinevirtual

Make sure the file is closed.

Definition at line 212 of file strgen.cpp.

Member Function Documentation

◆ Finalise()

void FileWriter::Finalise ( )
inline

Finalise the writing.

Definition at line 206 of file strgen.cpp.

Referenced by LanguageFileWriter::Finalise(), and HeaderFileWriter::Finalise().

◆ Finish()

void FileWriter::Finish ( )
inlineoverridevirtual

Prepare everything to finish writing the savegame.

Reimplemented from SaveFilter.

Definition at line 2305 of file saveload.cpp.

References _game_session_stats, and GameSessionStats::savegame_size.

Referenced by ~FileWriter().

◆ Write()

void FileWriter::Write ( uint8_t *  buf,
size_t  len 
)
inlineoverridevirtual

Write a given number of bytes into the savegame.

Parameters
bufThe bytes to write.
lenThe number of bytes to write.

Implements SaveFilter.

Definition at line 2297 of file saveload.cpp.

References SlError().

Field Documentation

◆ file

std::optional<FileHandle> FileWriter::file

The file to write to.

Definition at line 2281 of file saveload.cpp.

◆ output_stream

std::ofstream FileWriter::output_stream

◆ path

const std::filesystem::path FileWriter::path

The file name we're writing to.

Definition at line 193 of file strgen.cpp.

Referenced by FileWriter(), and HeaderFileWriter::Finalise().


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