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 293 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 298 of file ProjectFileIO.cpp.

306 : BufferedStreamReader(32 * 1024)
307 , mDB(db)
308 , mSchema(schema)
309 , mTable(table)
310 , mRowID(rowID)
311 {
312 }
BufferedStreamReader(size_t bufferSize=4096)

Member Function Documentation

◆ HasMoreData()

bool BufferedProjectBlobStream::HasMoreData ( ) const
inlineoverrideprotected

Definition at line 338 of file ProjectFileIO.cpp.

339 {
340 return mBlobStream.has_value() || mNextBlobIndex < Columns.size();
341 }
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 315 of file ProjectFileIO.cpp.

316 {
317 if (index >= Columns.size())
318 {
319 mBlobStream.reset();
320 return false;
321 }
322
324 mDB, mSchema, mTable, Columns[index], mRowID, true);
325
326 return mBlobStream.has_value();
327 }
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 343 of file ProjectFileIO.cpp.

344 {
345 if (!mBlobStream || mBlobStream->IsEof())
346 {
347 if (!OpenBlob(mNextBlobIndex++))
348 return {};
349 }
350
351 // Do not allow reading more then 2GB at a time (O_o)
352 maxBytes = std::min<size_t>(maxBytes, std::numeric_limits<int>::max());
353 auto bytesRead = static_cast<int>(maxBytes);
354
355 if (SQLITE_OK != mBlobStream->Read(buffer, bytesRead))
356 {
357 // Reading has failed, close the stream and do not allow opening
358 // the next one
359 mBlobStream = {};
360 mNextBlobIndex = Columns.size();
361
362 return 0;
363 }
364 else if (bytesRead == 0)
365 {
366 mBlobStream = {};
367 }
368
369 return static_cast<size_t>(bytesRead);
370 }
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 296 of file ProjectFileIO.cpp.

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

◆ mBlobStream

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

Definition at line 329 of file ProjectFileIO.cpp.

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

◆ mDB

sqlite3* BufferedProjectBlobStream::mDB
private

Definition at line 332 of file ProjectFileIO.cpp.

Referenced by OpenBlob().

◆ mNextBlobIndex

size_t BufferedProjectBlobStream::mNextBlobIndex { 0 }
private

Definition at line 330 of file ProjectFileIO.cpp.

Referenced by HasMoreData(), and ReadData().

◆ mRowID

const int64_t BufferedProjectBlobStream::mRowID
private

Definition at line 335 of file ProjectFileIO.cpp.

Referenced by OpenBlob().

◆ mSchema

const char* BufferedProjectBlobStream::mSchema
private

Definition at line 333 of file ProjectFileIO.cpp.

Referenced by OpenBlob().

◆ mTable

const char* BufferedProjectBlobStream::mTable
private

Definition at line 334 of file ProjectFileIO.cpp.

Referenced by OpenBlob().


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