Audacity 3.2.0
Public Member Functions | Private Member Functions | Private Attributes | Friends | List of all members
audacity::sqlite::Blob Class Referencefinal

A class representing a BLOB in a SQLite database. More...

#include <Blob.h>

Public Member Functions

 ~Blob () noexcept
 
 Blob (const Blob &)=delete
 
 Blob (Blob &&) noexcept
 
Bloboperator= (const Blob &)=delete
 
Bloboperator= (Blob &&) noexcept
 
int64_t Size () const noexcept
 Returns the size of the BLOB. More...
 
int64_t Read (void *buffer, int64_t offset, int64_t bufferSize) const noexcept
 Reads up to bufferSize bytes from the BLOB into the buffer at the given offset. More...
 
int64_t Write (const void *buffer, int64_t offset, int64_t bufferSize) noexcept
 Writes up to bufferSize bytes from the buffer into the BLOB at the given offset. More...
 
template<typename ContainerType >
ContainerType Read (int64_t offset=0, int64_t bufferSize=-1) const
 Reads up to bufferSize bytes from the BLOB into a container at the given offset. More...
 

Private Member Functions

 Blob (sqlite3_blob *blob) noexcept
 

Private Attributes

sqlite3_blob * mBlob {}
 

Friends

class Connection
 

Detailed Description

A class representing a BLOB in a SQLite database.

Definition at line 17 of file Blob.h.

Constructor & Destructor Documentation

◆ Blob() [1/3]

audacity::sqlite::Blob::Blob ( sqlite3_blob *  blob)
explicitprivatenoexcept

Definition at line 17 of file Blob.cpp.

18 : mBlob { blob }
19{
20 assert(mBlob != nullptr);
21}
sqlite3_blob * mBlob
Definition: Blob.h:61

◆ ~Blob()

audacity::sqlite::Blob::~Blob ( )
noexcept

Definition at line 23 of file Blob.cpp.

24{
25 if (mBlob != nullptr)
26 {
27 sqlite3_blob_close(mBlob);
28 mBlob = nullptr;
29 }
30}

References mBlob.

◆ Blob() [2/3]

audacity::sqlite::Blob::Blob ( const Blob )
delete

◆ Blob() [3/3]

audacity::sqlite::Blob::Blob ( Blob &&  rhs)
noexcept

Definition at line 32 of file Blob.cpp.

33{
34 *this = std::move(rhs);
35}

Member Function Documentation

◆ operator=() [1/2]

Blob & audacity::sqlite::Blob::operator= ( Blob &&  rhs)
noexcept

Definition at line 37 of file Blob.cpp.

38{
39 std::swap(mBlob, rhs.mBlob);
40 return *this;
41}
void swap(std::unique_ptr< Alg_seq > &a, std::unique_ptr< Alg_seq > &b)
Definition: NoteTrack.cpp:634

References anonymous_namespace{NoteTrack.cpp}::swap().

Here is the call graph for this function:

◆ operator=() [2/2]

Blob & audacity::sqlite::Blob::operator= ( const Blob )
delete

◆ Read() [1/2]

template<typename ContainerType >
ContainerType audacity::sqlite::Blob::Read ( int64_t  offset = 0,
int64_t  bufferSize = -1 
) const
inline

Reads up to bufferSize bytes from the BLOB into a container at the given offset.

If bufferSize is negative, the entire BLOB is read. ContainerType must have a resize() method and a data() method.

Definition at line 44 of file Blob.h.

45 {
46 if (bufferSize < 0)
47 bufferSize = Size() - offset;
48
49 if (bufferSize <= 0)
50 return {};
51
52 ContainerType buffer;
53 buffer.resize(bufferSize);
54 const auto bytesRead = Read(buffer.data(), offset, bufferSize);
55 buffer.resize(bytesRead);
56
57 return buffer;
58 }
int64_t Size() const noexcept
Returns the size of the BLOB.
Definition: Blob.cpp:43
int64_t Read(void *buffer, int64_t offset, int64_t bufferSize) const noexcept
Reads up to bufferSize bytes from the BLOB into the buffer at the given offset.
Definition: Blob.cpp:52

◆ Read() [2/2]

int64_t audacity::sqlite::Blob::Read ( void *  buffer,
int64_t  offset,
int64_t  bufferSize 
) const
noexcept

Reads up to bufferSize bytes from the BLOB into the buffer at the given offset.

Definition at line 52 of file Blob.cpp.

53{
54 if (mBlob == nullptr)
55 return 0;
56
57 const int readSize = std::min<int>(bufferSize, Size() - offset);
58
59 if (bufferSize <= 0)
60 return 0;
61
62 if (
63 SQLITE_OK !=
64 sqlite3_blob_read(mBlob, buffer, readSize, static_cast<int>(offset)))
65 return 0;
66
67 return readSize;
68}

◆ Size()

int64_t audacity::sqlite::Blob::Size ( ) const
noexcept

Returns the size of the BLOB.

Definition at line 43 of file Blob.cpp.

44{
45 if (mBlob == nullptr)
46 return 0;
47
48 return sqlite3_blob_bytes(mBlob);
49}

References mBlob.

◆ Write()

int64_t audacity::sqlite::Blob::Write ( const void *  buffer,
int64_t  offset,
int64_t  bufferSize 
)
noexcept

Writes up to bufferSize bytes from the buffer into the BLOB at the given offset.

Definition at line 71 of file Blob.cpp.

72{
73 if (mBlob == nullptr)
74 return 0;
75
76 const int writeSize = std::min<int>(bufferSize, Size() - offset);
77
78 if (bufferSize <= 0)
79 return 0;
80
81 if (
82 SQLITE_OK !=
83 sqlite3_blob_write(mBlob, buffer, writeSize, static_cast<int>(offset)))
84 return 0;
85
86 return writeSize;
87}

Friends And Related Function Documentation

◆ Connection

friend class Connection
friend

Definition at line 19 of file Blob.h.

Member Data Documentation

◆ mBlob

sqlite3_blob* audacity::sqlite::Blob::mBlob {}
private

Definition at line 61 of file Blob.h.

Referenced by Size(), and ~Blob().


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