coastline 0.0.4
Loading...
Searching...
No Matches
coastline::SaveFile Class Reference

An exclusive lock shared by cooperating save writers, released on destruction or process exit. More...

#include <savefile.h>

Public Member Functions

 ~SaveFile ()
 Release the process lock and its native handle.
 SaveFile (SaveFile &&) noexcept
 Transfer the source save's process lock without releasing it.
SaveFile & operator= (SaveFile &&) noexcept
 Release the destination lock and transfer the source save's process lock.
std::optional< std::vector< std::uint8_t > > Read (std::size_t limit) const
 Read the locked save with bounded allocation.
bool Write (std::span< const std::uint8_t > bytes) const
 Replace the save atomically after writing and synchronising a unique sibling file.
bool Remove () const
 Delete the locked save while excluding cooperating writers.

Static Public Member Functions

static std::optional< SaveFile > Open (const std::filesystem::path &path)
 Lock a save for a complete read-modify-write transaction, creating parent directories.

Detailed Description

An exclusive lock shared by cooperating save writers, released on destruction or process exit.

Constructor & Destructor Documentation

◆ ~SaveFile()

coastline::SaveFile::~SaveFile ( )

Release the process lock and its native handle.

◆ SaveFile()

coastline::SaveFile::SaveFile ( SaveFile && )
noexcept

Transfer the source save's process lock without releasing it.

Member Function Documentation

◆ Open()

std::optional< SaveFile > coastline::SaveFile::Open ( const std::filesystem::path & path)
static

Lock a save for a complete read-modify-write transaction, creating parent directories.

Parameters
pathDestination file. A persistent sibling lock file coordinates other writers.
Returns
Locked save, or std::nullopt when its directory or lock cannot be opened.

◆ operator=()

SaveFile & coastline::SaveFile::operator= ( SaveFile && )
noexcept

Release the destination lock and transfer the source save's process lock.

Returns
The destination save.

◆ Read()

std::optional< std::vector< std::uint8_t > > coastline::SaveFile::Read ( std::size_t limit) const

Read the locked save with bounded allocation.

Parameters
limitMaximum accepted length in bytes.
Returns
Complete contents, or std::nullopt for a missing, oversized, or unreadable save.

◆ Write()

bool coastline::SaveFile::Write ( std::span< const std::uint8_t > bytes) const

Replace the save atomically after writing and synchronising a unique sibling file.

Parameters
bytesComplete new contents.
Returns
Whether replacement and synchronisation succeed. Failures before replacement preserve the previous save.

◆ Remove()

bool coastline::SaveFile::Remove ( ) const

Delete the locked save while excluding cooperating writers.

Returns
Whether the save is absent afterwards.

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