Audacity 3.2.0
Blob.h
Go to the documentation of this file.
1/*
2 * SPDX-License-Identifier: GPL-2.0-or-later
3 * SPDX-FileName: Blob.h
4 * SPDX-FileContributor: Dmitry Vedenko
5 */
6
7#pragma once
8
9#include <cstdint>
10
11struct sqlite3_blob;
12
13namespace audacity::sqlite
14{
15
17class SQLITE_HELPERS_API Blob final
18{
19 friend class Connection;
20 explicit Blob(sqlite3_blob* blob) noexcept;
21
22public:
23 ~Blob() noexcept;
24
25 Blob(const Blob&) = delete;
26 Blob(Blob&&) noexcept;
27 Blob& operator=(const Blob&) = delete;
28 Blob& operator=(Blob&&) noexcept;
29
31 int64_t Size() const noexcept;
32
34 int64_t Read(void* buffer, int64_t offset, int64_t bufferSize) const noexcept;
36 int64_t Write(const void* buffer, int64_t offset, int64_t bufferSize) noexcept;
37
39
43 template<typename ContainerType>
44 ContainerType Read(int64_t offset = 0, int64_t bufferSize = -1) const
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 }
59
60private:
61 sqlite3_blob* mBlob {};
62}; // class Blob
63
64} // namespace audacity::sqlite
A class representing a BLOB in a SQLite database.
Definition: Blob.h:18
A class representing a connection to a SQLite database.
Definition: Connection.h:48
SizeType< float > Size
Alias for SizeType<float>
Definition: Size.h:174