Bitcoin ABC 0.30.7
P2P Digital Currency
Public Member Functions | Private Member Functions | Private Attributes | List of all members
CBufferedFile Class Reference

Non-refcounted RAII wrapper around a FILE* that implements a ring buffer to deserialize from. More...

#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 (Span< std::byte > dst)
 read a number of bytes More...
 
void SkipTo (const uint64_t file_pos)
 Move the read position ahead in the stream to the given position. More...
 
uint64_t GetPos () const
 return the current reading position More...
 
bool SetPos (uint64_t nPos)
 rewind to a given reading position More...
 
bool SetLimit (uint64_t nPos=std::numeric_limits< uint64_t >::max())
 Prevent reading beyond a certain position. More...
 
template<typename T >
CBufferedFileoperator>> (T &&obj)
 
void FindByte (std::byte byte)
 search for a given byte in the stream, and remain positioned on it More...
 

Private Member Functions

bool Fill ()
 read data from the source to fill the buffer More...
 
std::pair< std::byte *, size_t > AdvanceStream (size_t length)
 Advance the stream's read pointer (m_read_pos) by up to 'length' bytes, filling the buffer from the file so that at least one byte is available. 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< std::byte > 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).

Definition at line 671 of file streams.h.

Constructor & Destructor Documentation

◆ CBufferedFile() [1/2]

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

Definition at line 737 of file streams.h.

◆ ~CBufferedFile()

CBufferedFile::~CBufferedFile ( )
inline

Definition at line 749 of file streams.h.

Here is the call graph for this function:

◆ CBufferedFile() [2/2]

CBufferedFile::CBufferedFile ( const CBufferedFile )
delete

Member Function Documentation

◆ AdvanceStream()

std::pair< std::byte *, size_t > CBufferedFile::AdvanceStream ( size_t  length)
inlineprivate

Advance the stream's read pointer (m_read_pos) by up to 'length' bytes, filling the buffer from the file so that at least one byte is available.

Return a pointer to the available buffer data and the number of bytes (which may be less than the requested length) that may be accessed beginning at that pointer.

Definition at line 715 of file streams.h.

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

◆ eof()

bool CBufferedFile::eof ( ) const
inline

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

Definition at line 766 of file streams.h.

Here is the caller graph for this function:

◆ fclose()

void CBufferedFile::fclose ( )
inline

Definition at line 758 of file streams.h.

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

◆ Fill()

bool CBufferedFile::Fill ( )
inlineprivate

read data from the source to fill the buffer

Definition at line 690 of file streams.h.

Here is the caller graph for this function:

◆ FindByte()

void CBufferedFile::FindByte ( std::byte  byte)
inline

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

Definition at line 823 of file streams.h.

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

◆ GetPos()

uint64_t CBufferedFile::GetPos ( ) const
inline

return the current reading position

Definition at line 787 of file streams.h.

Here is the caller graph for this function:

◆ GetType()

int CBufferedFile::GetType ( ) const
inline

Definition at line 756 of file streams.h.

◆ GetVersion()

int CBufferedFile::GetVersion ( ) const
inline

Definition at line 755 of file streams.h.

◆ operator=()

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

◆ operator>>()

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

Definition at line 816 of file streams.h.

Here is the call graph for this function:

◆ read()

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

read a number of bytes

Definition at line 769 of file streams.h.

Here is the call graph for this function:

◆ 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.

Definition at line 808 of file streams.h.

Here is the caller graph for this function:

◆ SetPos()

bool CBufferedFile::SetPos ( uint64_t  nPos)
inline

rewind to a given reading position

Definition at line 790 of file streams.h.

Here is the caller graph for this function:

◆ SkipTo()

void CBufferedFile::SkipTo ( const uint64_t  file_pos)
inline

Move the read position ahead in the stream to the given position.

Use SetPos() to back up in the stream, not SkipTo().

Definition at line 779 of file streams.h.

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

Member Data Documentation

◆ nReadLimit

uint64_t CBufferedFile::nReadLimit
private

up to which position we're allowed to read

Definition at line 683 of file streams.h.

◆ nReadPos

uint64_t CBufferedFile::nReadPos
private

how many bytes have been read from this

Definition at line 681 of file streams.h.

◆ nRewind

uint64_t CBufferedFile::nRewind
private

how many bytes we guarantee to rewind

Definition at line 685 of file streams.h.

◆ nSrcPos

uint64_t CBufferedFile::nSrcPos
private

how many bytes have been read from source

Definition at line 679 of file streams.h.

◆ nType

const int CBufferedFile::nType
private

Definition at line 673 of file streams.h.

◆ nVersion

const int CBufferedFile::nVersion
private

Definition at line 674 of file streams.h.

◆ src

FILE* CBufferedFile::src
private

source file

Definition at line 677 of file streams.h.

◆ vchBuf

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

the buffer

Definition at line 687 of file streams.h.


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