game_launcher 1.1.0
Modern Linux game launcher with Steam / Proton / Wine integration
Loading...
Searching...
No Matches
FileHandle Class Reference

RAII wrapper for FILE* from fopen(). More...

#include <file_handle.h>

Public Member Functions

 FileHandle (const char *filename, const char *mode)
 Open file with specified mode.
 FileHandle (const FileHandle &)=delete
 FileHandle (const std::string &filename, const char *mode)
 FileHandle (FileHandle &&other) noexcept
 ~FileHandle ()
 Destructor - automatically closes file.
FILE * get () const
 Get raw FILE* pointer.
bool isOpen () const
 Check if file is open.
 operator bool () const
 Explicit bool conversion for easy checking.
FileHandle & operator= (const FileHandle &)=delete
FileHandle & operator= (FileHandle &&other) noexcept
FILE * release ()
 Release ownership of FILE* without closing.

Detailed Description

RAII wrapper for FILE* from fopen().

Automatically closes file handle on destruction, preventing resource leaks. Non-copyable but movable.

Definition at line 52 of file file_handle.h.

Constructor & Destructor Documentation

◆ FileHandle() [1/4]

FileHandle::FileHandle ( const char * filename,
const char * mode )
inline

Open file with specified mode.

Parameters
filenamePath to file
modeFile open mode ("r", "w", "a", etc.)

Definition at line 60 of file file_handle.h.

Referenced by FileHandle(), FileHandle(), operator=(), and operator=().

◆ FileHandle() [2/4]

FileHandle::FileHandle ( const std::string & filename,
const char * mode )
inline

Definition at line 62 of file file_handle.h.

◆ ~FileHandle()

FileHandle::~FileHandle ( )
inline

Destructor - automatically closes file.

Definition at line 70 of file file_handle.h.

◆ FileHandle() [3/4]

FileHandle::FileHandle ( const FileHandle & )
delete

References FileHandle().

◆ FileHandle() [4/4]

FileHandle::FileHandle ( FileHandle && other)
inlinenoexcept

Definition at line 84 of file file_handle.h.

References FileHandle().

Member Function Documentation

◆ get()

FILE * FileHandle::get ( ) const
inline

Get raw FILE* pointer.

Returns
FILE* pointer (nullptr if not open)

Definition at line 107 of file file_handle.h.

◆ isOpen()

bool FileHandle::isOpen ( ) const
inline

Check if file is open.

Returns
true if file handle is valid

Definition at line 116 of file file_handle.h.

Referenced by operator bool().

◆ operator bool()

FileHandle::operator bool ( ) const
inlineexplicit

Explicit bool conversion for easy checking.

Definition at line 124 of file file_handle.h.

References isOpen().

◆ operator=() [1/2]

FileHandle & FileHandle::operator= ( const FileHandle & )
delete

References FileHandle().

◆ operator=() [2/2]

FileHandle & FileHandle::operator= ( FileHandle && other)
inlinenoexcept

Definition at line 89 of file file_handle.h.

References FileHandle().

◆ release()

FILE * FileHandle::release ( )
inline

Release ownership of FILE* without closing.

Returns
FILE* pointer (caller must close manually)

Definition at line 133 of file file_handle.h.


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