Bitcoin ABC  0.29.2
P2P Digital Currency
Public Member Functions | Protected Attributes | List of all members
AutoFile Class Reference

Non-refcounted RAII wrapper for FILE*. More...

#include <streams.h>

Inheritance diagram for AutoFile:
[legend]

Public Member Functions

 AutoFile (FILE *filenew)
 
 ~AutoFile ()
 
 AutoFile (const AutoFile &)=delete
 
AutoFileoperator= (const AutoFile &)=delete
 
int fclose ()
 
FILE * release ()
 Get wrapped FILE* with transfer of ownership. More...
 
FILE * Get () const
 Get wrapped FILE* without transfer of ownership. More...
 
bool IsNull () const
 Return true if the wrapped FILE* is nullptr, false otherwise. More...
 
void read (Span< std::byte > dst)
 
void ignore (size_t nSize)
 
void write (Span< const std::byte > src)
 
template<typename T >
AutoFileoperator<< (const T &obj)
 
template<typename T >
AutoFileoperator>> (T &&obj)
 

Protected Attributes

FILE * file
 

Detailed Description

Non-refcounted RAII wrapper for FILE*.

Will automatically close the file when it goes out of scope if not null. If you're returning the file pointer, return file.release(). If you need to close the file early, use file.fclose() instead of fclose(file).

Definition at line 528 of file streams.h.

Constructor & Destructor Documentation

◆ AutoFile() [1/2]

AutoFile::AutoFile ( FILE *  filenew)
inlineexplicit

Definition at line 533 of file streams.h.

◆ ~AutoFile()

AutoFile::~AutoFile ( )
inline

Definition at line 535 of file streams.h.

Here is the call graph for this function:

◆ AutoFile() [2/2]

AutoFile::AutoFile ( const AutoFile )
delete

Member Function Documentation

◆ fclose()

int AutoFile::fclose ( )
inline

Definition at line 541 of file streams.h.

Here is the caller graph for this function:

◆ Get()

FILE* AutoFile::Get ( ) const
inline

Get wrapped FILE* without transfer of ownership.

Note
Ownership of the FILE* will remain with this class. Use this only if the scope of the AutoFile outlives use of the passed pointer.

Definition at line 567 of file streams.h.

Here is the caller graph for this function:

◆ ignore()

void AutoFile::ignore ( size_t  nSize)
inline

Definition at line 587 of file streams.h.

◆ IsNull()

bool AutoFile::IsNull ( ) const
inline

Return true if the wrapped FILE* is nullptr, false otherwise.

Definition at line 570 of file streams.h.

Here is the caller graph for this function:

◆ operator<<()

template<typename T >
AutoFile& AutoFile::operator<< ( const T &  obj)
inline

Definition at line 614 of file streams.h.

Here is the call graph for this function:

◆ operator=()

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

◆ operator>>()

template<typename T >
AutoFile& AutoFile::operator>> ( T &&  obj)
inline

Definition at line 622 of file streams.h.

Here is the call graph for this function:

◆ read()

void AutoFile::read ( Span< std::byte >  dst)
inline

Definition at line 575 of file streams.h.

Here is the call graph for this function:

◆ release()

FILE* AutoFile::release ( )
inline

Get wrapped FILE* with transfer of ownership.

Note
This will invalidate the AutoFile object, and makes it the responsibility of the caller of this function to clean up the returned FILE*.

Definition at line 556 of file streams.h.

◆ write()

void AutoFile::write ( Span< const std::byte >  src)
inline

Definition at line 604 of file streams.h.

Here is the call graph for this function:

Member Data Documentation

◆ file

FILE* AutoFile::file
protected

Definition at line 530 of file streams.h.


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