Bond 0.9
C++ Bond Runtime Library API Documentation
Loading...
Searching...
No Matches
Bond::StdioFileHandle Class Reference

A handle to a stdio FILE* to ensure that the file is properly disposed using RAII. More...

#include <bond/io/stdiofilehandle.h>

Public Member Functions

 StdioFileHandle ()
 Constructs an empty handle that is not bound to a file.
 StdioFileHandle (FILE *file)
 Constructs a handle that takes ownership of the given FILE pointer.
 StdioFileHandle (const char *fileName, const char *mode)
 Opens a file and constructs a handle that owns the resulting FILE pointer.
 StdioFileHandle (StdioFileHandle &&other) noexcept
 Move-constructs a handle by transferring ownership from another handle.
 ~StdioFileHandle ()
 Destroys the handle and closes the owned file, if any.
StdioFileHandleoperator= (StdioFileHandle &&other) noexcept
 Move-assigns by closing any currently owned file and taking ownership from another handle.
StdioFileHandleoperator= (FILE *file)
 Rebinds the handle to the given FILE pointer.
 StdioFileHandle (const StdioFileHandle &other)=delete
StdioFileHandleoperator= (const StdioFileHandle &other)=delete
FILE * GetFile () const
 Returns the currently owned FILE pointer.
FILE * Release ()
 Releases ownership of the current FILE pointer without closing it.
void Reset (FILE *file=nullptr)
 Replaces the owned FILE pointer, closing the previously owned file if needed.
bool IsBound () const
 Indicates whether this handle currently owns a FILE pointer.

Detailed Description

A handle to a stdio FILE* to ensure that the file is properly disposed using RAII.

Constructor & Destructor Documentation

◆ StdioFileHandle() [1/5]

Bond::StdioFileHandle::StdioFileHandle ( )
inline

Constructs an empty handle that is not bound to a file.

◆ StdioFileHandle() [2/5]

Bond::StdioFileHandle::StdioFileHandle ( FILE * file)
inlineexplicit

Constructs a handle that takes ownership of the given FILE pointer.

Parameters
filePointer to an open FILE object to be owned by this handle. May be null.

◆ StdioFileHandle() [3/5]

Bond::StdioFileHandle::StdioFileHandle ( const char * fileName,
const char * mode )
inline

Opens a file and constructs a handle that owns the resulting FILE pointer.

Parameters
fileNameThe path to the file to open.
modeThe fopen mode string used to open the file.
Remarks
If fopen fails, the handle remains unbound.

◆ StdioFileHandle() [4/5]

Bond::StdioFileHandle::StdioFileHandle ( StdioFileHandle && other)
inlinenoexcept

Move-constructs a handle by transferring ownership from another handle.

Parameters
otherSource handle whose ownership is transferred.
Remarks
After construction, other is left unbound.

◆ ~StdioFileHandle()

Bond::StdioFileHandle::~StdioFileHandle ( )
inline

Destroys the handle and closes the owned file, if any.

◆ StdioFileHandle() [5/5]

Bond::StdioFileHandle::StdioFileHandle ( const StdioFileHandle & other)
delete

Member Function Documentation

◆ GetFile()

FILE * Bond::StdioFileHandle::GetFile ( ) const
inline

Returns the currently owned FILE pointer.

Returns
The owned FILE pointer, or null if no file is bound.

◆ IsBound()

bool Bond::StdioFileHandle::IsBound ( ) const
inline

Indicates whether this handle currently owns a FILE pointer.

Returns
True if a file is bound; otherwise false.

◆ operator=() [1/3]

StdioFileHandle & Bond::StdioFileHandle::operator= ( const StdioFileHandle & other)
delete

◆ operator=() [2/3]

StdioFileHandle & Bond::StdioFileHandle::operator= ( FILE * file)
inline

Rebinds the handle to the given FILE pointer.

Parameters
filePointer to an open FILE object to be owned by this handle. May be null.
Returns
A reference to this handle.
Remarks
Any previously owned file is closed first, unless file equals the currently owned pointer.

◆ operator=() [3/3]

StdioFileHandle & Bond::StdioFileHandle::operator= ( StdioFileHandle && other)
inlinenoexcept

Move-assigns by closing any currently owned file and taking ownership from another handle.

Parameters
otherSource handle whose ownership is transferred.
Returns
A reference to this handle.
Remarks
After assignment, other is left unbound.

◆ Release()

FILE * Bond::StdioFileHandle::Release ( )
inline

Releases ownership of the current FILE pointer without closing it.

Returns
The previously owned FILE pointer, or null if no file is bound.
Remarks
After this call, the handle is unbound and will not close the returned pointer.

◆ Reset()

void Bond::StdioFileHandle::Reset ( FILE * file = nullptr)
inline

Replaces the owned FILE pointer, closing the previously owned file if needed.

Parameters
fileNew FILE pointer to own. Defaults to null, which simply unbinds the handle.
Remarks
If file equals the currently owned pointer, no close is performed.

The documentation for this class was generated from the following file:
  • include/bond/io/stdiofilehandle.h