Bitcoin
Public Member Functions | Private Attributes | List of all members
CAutoFile Class Reference

#include <streams.h>

Public Member Functions

 CAutoFile (FILE *filenew, int nTypeIn, int nVersionIn)
 
 ~CAutoFile ()
 
 CAutoFile (const CAutoFile &)=delete
 
CAutoFileoperator= (const CAutoFile &)=delete
 
void fclose ()
 
FILE * release ()
 
FILE * Get () const
 
bool IsNull () const
 
int GetType () const
 
int GetVersion () const
 
void read (char *pch, size_t nSize)
 
void ignore (size_t nSize)
 
void write (const char *pch, size_t nSize)
 
template<typename T >
CAutoFileoperator<< (const T &obj)
 
template<typename T >
CAutoFileoperator>> (T &&obj)
 

Private Attributes

const int nType
 
const int nVersion
 
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).

Constructor & Destructor Documentation

◆ CAutoFile() [1/2]

CAutoFile::CAutoFile ( FILE *  filenew,
int  nTypeIn,
int  nVersionIn 
)
inline

◆ ~CAutoFile()

CAutoFile::~CAutoFile ( )
inline

◆ CAutoFile() [2/2]

CAutoFile::CAutoFile ( const CAutoFile )
delete

Member Function Documentation

◆ fclose()

void CAutoFile::fclose ( )
inline

◆ Get()

FILE* CAutoFile::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 CAutoFile outlives use of the passed pointer.

◆ GetType()

int CAutoFile::GetType ( ) const
inline

◆ GetVersion()

int CAutoFile::GetVersion ( ) const
inline

◆ ignore()

void CAutoFile::ignore ( size_t  nSize)
inline

◆ IsNull()

bool CAutoFile::IsNull ( ) const
inline

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

◆ operator<<()

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

◆ operator=()

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

◆ operator>>()

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

◆ read()

void CAutoFile::read ( char *  pch,
size_t  nSize 
)
inline

◆ release()

FILE* CAutoFile::release ( )
inline

Get wrapped FILE* with transfer of ownership.

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

◆ write()

void CAutoFile::write ( const char *  pch,
size_t  nSize 
)
inline

Member Data Documentation

◆ file

FILE* CAutoFile::file
private

◆ nType

const int CAutoFile::nType
private

◆ nVersion

const int CAutoFile::nVersion
private

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