NuriaProject Framework  0.1
The NuriaProject Framework
Public Types | Signals | Public Member Functions | Protected Member Functions | List of all members
Nuria::TemporaryBufferDevice Class Reference

In-memory buffer device with fallback to a temporary file. More...

#include <temporarybufferdevice.hpp>

Inheritance diagram for Nuria::TemporaryBufferDevice:

Public Types

enum  { DefaultMemorySize = 4096 * 1024 }
 
enum  StorageMode { NoDevice = 0, InMemory, TemporaryFile }
 

Signals

void storageModeChanged (Nuria::TemporaryBufferDevice::StorageMode storageMode)
 

Public Member Functions

 TemporaryBufferDevice (int maximumMemorySize, QObject *parent=0)
 
 TemporaryBufferDevice (QObject *parent=0)
 
 ~TemporaryBufferDevice () override
 
bool atEnd () const
 
qint64 bytesAvailable () const
 
qint64 bytesToWrite () const
 
bool canReadLine () const
 
void close ()
 
void discard ()
 
QIODevice * internalDevice () const
 
bool isSequential () const
 
int maximumMemorySize () const
 
bool open (OpenMode mode)
 
qint64 pos () const
 
bool reset ()
 
bool seek (qint64 pos)
 
void setMaximumMemorySize (int maximumSize)
 
qint64 size () const
 
QIODevice * stealInternalDevice ()
 
StorageMode storageMode () const
 
bool waitForBytesWritten (int msecs)
 
bool waitForReadyRead (int msecs)
 

Protected Member Functions

qint64 readData (char *data, qint64 maxlen)
 
qint64 readLineData (char *data, qint64 maxlen)
 
qint64 writeData (const char *data, qint64 len)
 

Detailed Description

In-memory buffer device with fallback to a temporary file.

This buffer uses internally a QBuffer to store data, but will start using a temporary file as storage when the buffer gets bigger than a given amount of bytes.

See also
DefaultMemorySize
Behaviour
This class acts as usual random-access (i.e. non-sequential) QIODevice for easy and quick storage of temporary data. It will try to use a QBuffer to store the data directly in-memory first. When the data gets bigger than a certain value though, it'll copy the data into a temporary file and begin using it as back-end. This process is completely transparent to the user.

The device itself is usually opened for read and write access. You can change this using open(), though this has no effect on the internal device.

Member Enumeration Documentation

anonymous enum
Enumerator
DefaultMemorySize 

Default maximum size of the in-memory buffer.

Storage mode for the internal device.

Enumerator
NoDevice 

The buffer device contains no data.

InMemory 

In-memory buffer.

TemporaryFile 

Temporary file as buffer.

Constructor & Destructor Documentation

Nuria::TemporaryBufferDevice::TemporaryBufferDevice ( int  maximumMemorySize,
QObject *  parent = 0 
)
explicit

Constructor. Initializes maximumMemorySize directly.

Nuria::TemporaryBufferDevice::TemporaryBufferDevice ( QObject *  parent = 0)
explicit

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Nuria::TemporaryBufferDevice::~TemporaryBufferDevice ( )
override

Destructor.

Member Function Documentation

void Nuria::TemporaryBufferDevice::close ( )

Closes the internal device, deleting all buffered data.

void Nuria::TemporaryBufferDevice::discard ( )

Discards the internal buffer. Doing so will loose all buffered data.

QIODevice* Nuria::TemporaryBufferDevice::internalDevice ( ) const

Returns the currently used internal storage device.

Note
Usually you don't need this.
int Nuria::TemporaryBufferDevice::maximumMemorySize ( ) const

Returns the maximum size of the in-memory buffer. After the buffer grows beyond this barrier, a temporary file will be used instead.

void Nuria::TemporaryBufferDevice::setMaximumMemorySize ( int  maximumSize)

Sets the maximum size of the in-memory buffer. The new value is applied immediately, thus if the buffer is exceeding the limit, a temporary file will be used.

QIODevice* Nuria::TemporaryBufferDevice::stealInternalDevice ( )

Steals the internal storage device from the instance. Ownership of the device is transferred to the caller. The TemporaryBufferDevice instance will act as if it was just created, thus contain no data.

StorageMode Nuria::TemporaryBufferDevice::storageMode ( ) const

Returns the current storage mode.

void Nuria::TemporaryBufferDevice::storageModeChanged ( Nuria::TemporaryBufferDevice::StorageMode  storageMode)
signal

Triggered when the storage mode has been changed.


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