SoundFontInfoLib  2.21.6
Library for parsing and rendering SF2 files
SF2::IO::Pos Struct Reference

Representation of a file position. More...

#include <Pos.hpp>

Classes

struct  Mockery
 RAII struct for handling mocking of the Pos file IO methods. More...
 

Public Types

using SeekProcType = off_t(*)(int fd, off_t offset, int whence)
 Type of function to call to seek to a position in a file. More...
 
using ReadProcType = ssize_t(*)(int fd, void *buffer, size_t size)
 Type of function to call to read from current position in a file. More...
 

Public Member Functions

 Pos (int fd, size_t pos, size_t end)
 Constructor. More...
 
ChunkList makeChunkList () const
 Create a new ChunkList from the current position. More...
 
Chunk makeChunk () const
 Create a new Chunk from the current position. More...
 
template<typename T >
Pos readInto (T &buffer) const
 Read bytes from the file at the current position and place them into the given buffer. More...
 
template<typename T >
Pos readInto (T &buffer, size_t maxCount) const
 Read bytes from the file at the current position and place them into the given buffer. More...
 
Pos readInto (void *buffer, size_t count) const
 Read bytes from the file at the current position and place them into the given buffer. More...
 
constexpr size_t offset () const
 Obtain the file offset represented by this instance. More...
 
constexpr size_t available () const
 
Pos advance (size_t offset) const
 Calculate new Pos value after advancing offset bytes forward. More...
 
constexpr operator bool () const
 

Static Public Attributes

static SeekProcType SeekProc = &::lseek
 Function to call to seek to a position in a file. More...
 
static ReadProcType ReadProc = &::read
 Function to call to read from current position in a file. More...
 

Friends

bool operator< (const Pos &lhs, const Pos &rhs)
 

Detailed Description

Representation of a file position.

Instances of this type are immutable by design. It has methods that will generate instances with new position values.

Member Typedef Documentation

◆ ReadProcType

using SF2::IO::Pos::ReadProcType = ssize_t (*)(int fd, void* buffer, size_t size)

Type of function to call to read from current position in a file.

◆ SeekProcType

using SF2::IO::Pos::SeekProcType = off_t (*)(int fd, off_t offset, int whence)

Type of function to call to seek to a position in a file.

Constructor & Destructor Documentation

◆ Pos()

SF2::IO::Pos::Pos ( int  fd,
size_t  pos,
size_t  end 
)
inline

Constructor.

Parameters
fdthe file descriptor to read from
posthe current location in the file being processed
endthe end of the file being processed

Referenced by advance().

Member Function Documentation

◆ advance()

Pos SF2::IO::Pos::advance ( size_t  offset) const
inline

Calculate new Pos value after advancing offset bytes forward.

Parameters
offsetthe number of bytes to advance
Returns
new Pos instance for the next bytes in the file

References offset(), and Pos().

Referenced by SF2::IO::Chunk::advance(), SF2::IO::Chunk::end(), makeChunk(), makeChunkList(), and readInto().

◆ available()

constexpr size_t SF2::IO::Pos::available ( ) const
inlineconstexpr
Returns
number of bytes available to read at this position in the file.

◆ makeChunk()

Chunk Pos::makeChunk ( ) const

Create a new Chunk from the current position.

Returns
new Chunk instance

References advance(), and SF2::IO::error.

◆ makeChunkList()

ChunkList Pos::makeChunkList ( ) const

Create a new ChunkList from the current position.

Returns
new ChunkList instance

References advance(), and SF2::IO::error.

Referenced by SF2::IO::File::File(), and SF2::IO::Parser::parse().

◆ offset()

constexpr size_t SF2::IO::Pos::offset ( ) const
inlineconstexpr

Obtain the file offset represented by this instance.

Returns
file offset

Referenced by advance().

◆ operator bool()

constexpr SF2::IO::Pos::operator bool ( ) const
inlineexplicitconstexpr
Returns
true if Pos is invalid

◆ readInto() [1/3]

template<typename T >
Pos SF2::IO::Pos::readInto ( T &  buffer) const
inline

Read bytes from the file at the current position and place them into the given buffer.

Parameters
bufferthe destination for the bytes
Returns
new Pos instance for the next bytes in the file

Referenced by SF2::Entity::Bag::Bag(), SF2::IO::Chunk::extract(), SF2::IO::Chunk::extractSamples(), SF2::Entity::Generator::Generator::Generator(), SF2::Entity::Instrument::Instrument(), SF2::Entity::Version::load(), SF2::Entity::Modulator::Modulator::Modulator(), SF2::Entity::Preset::Preset(), readInto(), and SF2::Entity::SampleHeader::SampleHeader().

◆ readInto() [2/3]

template<typename T >
Pos SF2::IO::Pos::readInto ( T &  buffer,
size_t  maxCount 
) const
inline

Read bytes from the file at the current position and place them into the given buffer.

Parameters
bufferthe destination for the bytes
maxCountthe maximum number of bytes to read, even if the size of the buffer is larger
Returns
new Pos instance for the next bytes in the file

References readInto().

◆ readInto() [3/3]

Pos SF2::IO::Pos::readInto ( void *  buffer,
size_t  count 
) const
inline

Read bytes from the file at the current position and place them into the given buffer.

Parameters
bufferthe destination for the bytes
countthe number number of bytes to read
Returns
new Pos instance for the next bytes in the file

References advance(), and SF2::IO::error.

Friends And Related Function Documentation

◆ operator<

bool operator< ( const Pos lhs,
const Pos rhs 
)
friend
Returns
true if first Pos value is less than the second one

Member Data Documentation

◆ ReadProc

Pos::ReadProcType Pos::ReadProc = &::read
static

Function to call to read from current position in a file.

Referenced by SF2::IO::Pos::Mockery::Mockery(), and SF2::IO::Pos::Mockery::~Mockery().

◆ SeekProc

Pos::SeekProcType Pos::SeekProc = &::lseek
static

Function to call to seek to a position in a file.

Referenced by SF2::IO::Pos::Mockery::Mockery(), and SF2::IO::Pos::Mockery::~Mockery().


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