Bitcoin Core  28.1.0
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>

Public Member Functions

 AutoFile (std::FILE *file, std::vector< std::byte > data_xor={})
 
 ~AutoFile ()
 
 AutoFile (const AutoFile &)=delete
 
AutoFileoperator= (const AutoFile &)=delete
 
bool feof () const
 
int fclose ()
 
std::FILE * release ()
 Get wrapped FILE* with transfer of ownership. More...
 
bool IsNull () const
 Return true if the wrapped FILE* is nullptr, false otherwise. More...
 
void SetXor (std::vector< std::byte > data_xor)
 Continue with a different XOR key. More...
 
std::size_t detail_fread (Span< std::byte > dst)
 Implementation detail, only used internally. More...
 
void seek (int64_t offset, int origin)
 
int64_t tell ()
 
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)
 
bool Commit ()
 
bool IsError ()
 
bool Truncate (unsigned size)
 

Protected Attributes

std::FILE * m_file
 
std::vector< std::byte > m_xor
 
std::optional< int64_t > m_position
 

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 388 of file streams.h.

Constructor & Destructor Documentation

◆ AutoFile() [1/2]

AutoFile::AutoFile ( std::FILE *  file,
std::vector< std::byte >  data_xor = {} 
)
explicit

Definition at line 11 of file streams.cpp.

◆ ~AutoFile()

AutoFile::~AutoFile ( )
inline

Definition at line 398 of file streams.h.

Here is the call graph for this function:

◆ AutoFile() [2/2]

AutoFile::AutoFile ( const AutoFile )
delete

Member Function Documentation

◆ Commit()

bool AutoFile::Commit ( )

Definition at line 104 of file streams.cpp.

Here is the call graph for this function:

◆ detail_fread()

std::size_t AutoFile::detail_fread ( Span< std::byte >  dst)

Implementation detail, only used internally.

Definition at line 20 of file streams.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ fclose()

int AutoFile::fclose ( )
inline

Definition at line 406 of file streams.h.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ feof()

bool AutoFile::feof ( ) const
inline

Definition at line 404 of file streams.h.

Here is the caller graph for this function:

◆ ignore()

void AutoFile::ignore ( size_t  nSize)

Definition at line 66 of file streams.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ IsError()

bool AutoFile::IsError ( )

Definition at line 109 of file streams.cpp.

◆ IsNull()

bool AutoFile::IsNull ( ) const
inline

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

Definition at line 425 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 444 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 451 of file streams.h.

Here is the call graph for this function:

◆ read()

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

Definition at line 59 of file streams.cpp.

Here is the call graph for this function:

◆ release()

std::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 416 of file streams.h.

Here is the caller graph for this function:

◆ seek()

void AutoFile::seek ( int64_t  offset,
int  origin 
)

Definition at line 32 of file streams.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ SetXor()

void AutoFile::SetXor ( std::vector< std::byte >  data_xor)
inline

Continue with a different XOR key.

Definition at line 428 of file streams.h.

◆ tell()

int64_t AutoFile::tell ( )

Definition at line 53 of file streams.cpp.

Here is the caller graph for this function:

◆ Truncate()

bool AutoFile::Truncate ( unsigned  size)

Definition at line 114 of file streams.cpp.

Here is the call graph for this function:

◆ write()

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

Definition at line 80 of file streams.cpp.

Here is the call graph for this function:

Member Data Documentation

◆ m_file

std::FILE* AutoFile::m_file
protected

Definition at line 391 of file streams.h.

◆ m_position

std::optional<int64_t> AutoFile::m_position
protected

Definition at line 393 of file streams.h.

◆ m_xor

std::vector<std::byte> AutoFile::m_xor
protected

Definition at line 392 of file streams.h.


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