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

#include <streams.h>

Public Member Functions

 CBufferedFile (FILE *fileIn, uint64_t nBufSize, uint64_t nRewindIn, int nTypeIn, int nVersionIn)
 
 ~CBufferedFile ()
 
 CBufferedFile (const CBufferedFile &)=delete
 
CBufferedFileoperator= (const CBufferedFile &)=delete
 
int GetVersion () const
 
int GetType () const
 
void fclose ()
 
bool eof () const
 check whether we're at the end of the source file More...
 
void read (char *pch, size_t nSize)
 read a number of bytes More...
 
uint64_t GetPos () const
 return the current reading position More...
 
bool SetPos (uint64_t nPos)
 rewind to a given reading position More...
 
bool Seek (uint64_t nPos)
 
bool SetLimit (uint64_t nPos=std::numeric_limits< uint64_t >::max())
 
template<typename T >
CBufferedFileoperator>> (T &&obj)
 
void FindByte (char ch)
 search for a given byte in the stream, and remain positioned on it More...
 

Protected Member Functions

bool Fill ()
 read data from the source to fill the buffer More...
 

Private Attributes

const int nType
 
const int nVersion
 
FILE * src
 source file More...
 
uint64_t nSrcPos
 how many bytes have been read from source More...
 
uint64_t nReadPos
 how many bytes have been read from this More...
 
uint64_t nReadLimit
 up to which position we're allowed to read More...
 
uint64_t nRewind
 how many bytes we guarantee to rewind More...
 
std::vector< char > vchBuf
 the buffer More...
 

Detailed Description

Non-refcounted RAII wrapper around a FILE* that implements a ring buffer to deserialize from. It guarantees the ability to rewind a given number of bytes.

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

Constructor & Destructor Documentation

◆ CBufferedFile() [1/2]

CBufferedFile::CBufferedFile ( FILE *  fileIn,
uint64_t  nBufSize,
uint64_t  nRewindIn,
int  nTypeIn,
int  nVersionIn 
)
inline

◆ ~CBufferedFile()

CBufferedFile::~CBufferedFile ( )
inline

◆ CBufferedFile() [2/2]

CBufferedFile::CBufferedFile ( const CBufferedFile )
delete

Member Function Documentation

◆ eof()

bool CBufferedFile::eof ( ) const
inline

check whether we're at the end of the source file

◆ fclose()

void CBufferedFile::fclose ( )
inline

◆ Fill()

bool CBufferedFile::Fill ( )
inlineprotected

read data from the source to fill the buffer

◆ FindByte()

void CBufferedFile::FindByte ( char  ch)
inline

search for a given byte in the stream, and remain positioned on it

◆ GetPos()

uint64_t CBufferedFile::GetPos ( ) const
inline

return the current reading position

◆ GetType()

int CBufferedFile::GetType ( ) const
inline

◆ GetVersion()

int CBufferedFile::GetVersion ( ) const
inline

◆ operator=()

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

◆ operator>>()

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

◆ read()

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

read a number of bytes

◆ Seek()

bool CBufferedFile::Seek ( uint64_t  nPos)
inline

◆ SetLimit()

bool CBufferedFile::SetLimit ( uint64_t  nPos = std::numeric_limits<uint64_t>::max())
inline

prevent reading beyond a certain position no argument removes the limit

◆ SetPos()

bool CBufferedFile::SetPos ( uint64_t  nPos)
inline

rewind to a given reading position

Member Data Documentation

◆ nReadLimit

uint64_t CBufferedFile::nReadLimit
private

up to which position we're allowed to read

◆ nReadPos

uint64_t CBufferedFile::nReadPos
private

how many bytes have been read from this

◆ nRewind

uint64_t CBufferedFile::nRewind
private

how many bytes we guarantee to rewind

◆ nSrcPos

uint64_t CBufferedFile::nSrcPos
private

how many bytes have been read from source

◆ nType

const int CBufferedFile::nType
private

◆ nVersion

const int CBufferedFile::nVersion
private

◆ src

FILE* CBufferedFile::src
private

source file

◆ vchBuf

std::vector<char> CBufferedFile::vchBuf
private

the buffer


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