Add stream avail() methods
Makes it more readable to write code that needs to know how much data/space is available in a stream.
This commit is contained in:
committed by
Lauri Kasanen
parent
910fd8fa3e
commit
7f90205cf2
@@ -40,6 +40,14 @@ namespace rdr {
|
||||
|
||||
virtual ~OutStream() {}
|
||||
|
||||
// avail() returns the number of bytes that currently be written to the
|
||||
// stream without any risk of blocking.
|
||||
|
||||
inline size_t avail()
|
||||
{
|
||||
return end - ptr;
|
||||
}
|
||||
|
||||
// check() ensures there is buffer space for at least one item of size
|
||||
// itemSize bytes. Returns the number of items which fit (up to a maximum
|
||||
// of nItems).
|
||||
@@ -48,10 +56,10 @@ namespace rdr {
|
||||
{
|
||||
size_t nAvail;
|
||||
|
||||
if (itemSize > (size_t)(end - ptr))
|
||||
if (itemSize > avail())
|
||||
return overrun(itemSize, nItems);
|
||||
|
||||
nAvail = (end - ptr) / itemSize;
|
||||
nAvail = avail() / itemSize;
|
||||
if (nAvail < nItems)
|
||||
return nAvail;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user