Audacity 3.2.0
Public Member Functions | Static Public Attributes | Protected Member Functions | Private Member Functions | Private Attributes | List of all members
BufferedProjectBlobStream Class Reference
Inheritance diagram for BufferedProjectBlobStream:
[legend]
Collaboration diagram for BufferedProjectBlobStream:
[legend]

Public Member Functions

 BufferedProjectBlobStream (sqlite3 *db, const char *schema, const char *table, int64_t rowID)
 
- Public Member Functions inherited from BufferedStreamReader
 BufferedStreamReader (size_t bufferSize=4096)
 
size_t Read (void *buffer, size_t maxBytes)
 Read up to maxBytes into the buffer. Returns the number of bytes read. More...
 

Static Public Attributes

static constexpr std::array< const char *, 2 > Columns = { "dict", "doc" }
 
- Static Public Attributes inherited from BufferedStreamReader
static constexpr size_t RequiredAlignment = 8
 

Protected Member Functions

bool HasMoreData () const override
 
size_t ReadData (void *buffer, size_t maxBytes) override
 

Private Member Functions

bool OpenBlob (size_t index)
 

Private Attributes

std::optional< SQLiteBlobStreammBlobStream
 
size_t mNextBlobIndex { 0 }
 
sqlite3 * mDB
 
const char * mSchema
 
const char * mTable
 
const int64_t mRowID
 

Additional Inherited Members

- Public Attributes inherited from BufferedStreamReader
template<typename ValueType >
std::enable_if_t< sizeof(ValueType)<=RequiredAlignment, bool > ReadValue(ValueType &value) { constexpr size_t valueSize=sizeof(ValueType);const size_t availableBytes=mCurrentBytes - mCurrentIndex;if(availableBytes< valueSize) return valueSize==Read(&value, valueSize);if constexpr(valueSize==1) value=mBufferStart[mCurrentIndex];else value=UncheckedRead< ValueType >();mCurrentIndex+=valueSize;return true;} bool Eof() const ;int GetC();protected:virtual bool HasMoreData() const=0;virtual size_t ReadData(void *buffer, size_t maxBytes)=0;private:bool HandleUnderflow();template< typename T > T UncheckedRead() noexcept { T result;if((mCurrentIndex % sizeof(T))==0) { const void *ptr=mBufferStart+mCurrentIndex;result=*static_cast< const T * >(ptr);} else { const uint8_t *begin=mBufferStart+mCurrentIndex;const uint8_t *end=begin+sizeof(T);void *out=&result;std::copy(begin, end, static_cast< uint8_t * >(out));} return result;} std::vector< uint8_t > mBufferData
 Read a single value of ValueType, where sizeof(ValueType) <= 8 and value is aligned to the size boundary. More...
 
uint8_t * mBufferStart
 
size_t mBufferSize
 
size_t mCurrentIndex { 0 }
 
size_t mCurrentBytes { 0 }
 

Detailed Description

Definition at line 338 of file ProjectFileIO.cpp.

Constructor & Destructor Documentation

◆ BufferedProjectBlobStream()

BufferedProjectBlobStream::BufferedProjectBlobStream ( sqlite3 *  db,
const char *  schema,
const char *  table,
int64_t  rowID 
)
inline

Definition at line 343 of file ProjectFileIO.cpp.

351 : BufferedStreamReader(32 * 1024)
352 , mDB(db)
353 , mSchema(schema)
354 , mTable(table)
355 , mRowID(rowID)
356 {
357 }
BufferedStreamReader(size_t bufferSize=4096)

Member Function Documentation

◆ HasMoreData()

bool BufferedProjectBlobStream::HasMoreData ( ) const
inlineoverrideprotected

Definition at line 383 of file ProjectFileIO.cpp.

384 {
385 return mBlobStream.has_value() || mNextBlobIndex < Columns.size();
386 }
static constexpr std::array< const char *, 2 > Columns
std::optional< SQLiteBlobStream > mBlobStream

References Columns, mBlobStream, and mNextBlobIndex.

◆ OpenBlob()

bool BufferedProjectBlobStream::OpenBlob ( size_t  index)
inlineprivate

Definition at line 360 of file ProjectFileIO.cpp.

361 {
362 if (index >= Columns.size())
363 {
364 mBlobStream.reset();
365 return false;
366 }
367
369 mDB, mSchema, mTable, Columns[index], mRowID, true);
370
371 return mBlobStream.has_value();
372 }
static std::optional< SQLiteBlobStream > Open(sqlite3 *db, const char *schema, const char *table, const char *column, int64_t rowID, bool readOnly) noexcept

References Columns, mBlobStream, mDB, mRowID, mSchema, mTable, and SQLiteBlobStream::Open().

Referenced by ReadData().

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

◆ ReadData()

size_t BufferedProjectBlobStream::ReadData ( void *  buffer,
size_t  maxBytes 
)
inlineoverrideprotected

Definition at line 388 of file ProjectFileIO.cpp.

389 {
390 if (!mBlobStream || mBlobStream->IsEof())
391 {
392 if (!OpenBlob(mNextBlobIndex++))
393 return {};
394 }
395
396 // Do not allow reading more then 2GB at a time (O_o)
397 maxBytes = std::min<size_t>(maxBytes, std::numeric_limits<int>::max());
398 auto bytesRead = static_cast<int>(maxBytes);
399
400 if (SQLITE_OK != mBlobStream->Read(buffer, bytesRead))
401 {
402 // Reading has failed, close the stream and do not allow opening
403 // the next one
404 mBlobStream = {};
405 mNextBlobIndex = Columns.size();
406
407 return 0;
408 }
409 else if (bytesRead == 0)
410 {
411 mBlobStream = {};
412 }
413
414 return static_cast<size_t>(bytesRead);
415 }
bool OpenBlob(size_t index)

References Columns, mBlobStream, mNextBlobIndex, and OpenBlob().

Here is the call graph for this function:

Member Data Documentation

◆ Columns

constexpr std::array< const char *, 2 > BufferedProjectBlobStream::Columns = { "dict", "doc" }
staticconstexpr

Definition at line 341 of file ProjectFileIO.cpp.

Referenced by HasMoreData(), OpenBlob(), and ReadData().

◆ mBlobStream

std::optional<SQLiteBlobStream> BufferedProjectBlobStream::mBlobStream
private

Definition at line 374 of file ProjectFileIO.cpp.

Referenced by HasMoreData(), OpenBlob(), and ReadData().

◆ mDB

sqlite3* BufferedProjectBlobStream::mDB
private

Definition at line 377 of file ProjectFileIO.cpp.

Referenced by OpenBlob().

◆ mNextBlobIndex

size_t BufferedProjectBlobStream::mNextBlobIndex { 0 }
private

Definition at line 375 of file ProjectFileIO.cpp.

Referenced by HasMoreData(), and ReadData().

◆ mRowID

const int64_t BufferedProjectBlobStream::mRowID
private

Definition at line 380 of file ProjectFileIO.cpp.

Referenced by OpenBlob().

◆ mSchema

const char* BufferedProjectBlobStream::mSchema
private

Definition at line 378 of file ProjectFileIO.cpp.

Referenced by OpenBlob().

◆ mTable

const char* BufferedProjectBlobStream::mTable
private

Definition at line 379 of file ProjectFileIO.cpp.

Referenced by OpenBlob().


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