Inviwo  0.9.10.1
Inviwo documentation
inviwo::util::MemoryFileHandle Class Reference

RAII class for providing a FILE stream handle to a buffer in memory. This class will open a file handle to /dev/null and use a dedicated buffer for buffering. As long as less bytes than getBufferSize() bytes are written/read, its status is well defined. However, after writing more than buffer size bytes, the buffer contents will be flushed, i.e. are no longer accessible. More...

#include <memoryfilehandle.h>

Public Member Functions

 MemoryFileHandle (size_t bufferSize)
 
 MemoryFileHandle (const MemoryFileHandle &)=delete
 
MemoryFileHandleoperator= (const MemoryFileHandle &)=delete
 
 MemoryFileHandle (MemoryFileHandle &&rhs)
 
MemoryFileHandleoperator= (MemoryFileHandle &&rhs)
 
FILE * getHandle ()
 
 operator FILE * ()
 
void reset ()
 
void resize (size_t bufferSize)
 
size_t getBufferSize () const
 
size_t getNumberOfBytesInBuffer () const
 returns the number of bytes currently stored in the buffer. If the number of bytes written using the file handle exceeds the buffer size, the result will be the number of bytes modulo buffer size. More...
 
std::vector< unsigned char > & getBuffer ()
 
const std::vector< unsigned char > & getBuffer () const
 
bool checkForOverflow () const
 

Detailed Description

RAII class for providing a FILE stream handle to a buffer in memory. This class will open a file handle to /dev/null and use a dedicated buffer for buffering. As long as less bytes than getBufferSize() bytes are written/read, its status is well defined. However, after writing more than buffer size bytes, the buffer contents will be flushed, i.e. are no longer accessible.

To detect potential overflows, the entire buffer is initialized with the value 0xaf. If the number of bytes in the buffer is less than the buffer size, the next 8 bytes are checked whether they contain 0xaf. If not, then there was a potential buffer overflow.

Member Function Documentation

◆ getNumberOfBytesInBuffer()

size_t inviwo::util::MemoryFileHandle::getNumberOfBytesInBuffer ( ) const

returns the number of bytes currently stored in the buffer. If the number of bytes written using the file handle exceeds the buffer size, the result will be the number of bytes modulo buffer size.

Returns
number of bytes

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