1//===----------------------------------------------------------------------===//
2// DuckDB
3//
4// duckdb/storage/buffer/buffer_handle.hpp
5//
6//
7//===----------------------------------------------------------------------===//
8
9#pragma once
10
11#include "duckdb/storage/storage_info.hpp"
12#include "duckdb/common/file_buffer.hpp"
13
14namespace duckdb {
15class BlockHandle;
16class FileBuffer;
17
18class BufferHandle {
19public:
20 DUCKDB_API BufferHandle();
21 DUCKDB_API BufferHandle(shared_ptr<BlockHandle> handle, FileBuffer *node);
22 DUCKDB_API ~BufferHandle();
23 // disable copy constructors
24 BufferHandle(const BufferHandle &other) = delete;
25 BufferHandle &operator=(const BufferHandle &) = delete;
26 //! enable move constructors
27 DUCKDB_API BufferHandle(BufferHandle &&other) noexcept;
28 DUCKDB_API BufferHandle &operator=(BufferHandle &&) noexcept;
29
30public:
31 //! Returns whether or not the BufferHandle is valid.
32 DUCKDB_API bool IsValid() const;
33 //! Returns a pointer to the buffer data. Handle must be valid.
34 inline data_ptr_t Ptr() const {
35 D_ASSERT(IsValid());
36 return node->buffer;
37 }
38 //! Returns a pointer to the buffer data. Handle must be valid.
39 inline data_ptr_t Ptr() {
40 D_ASSERT(IsValid());
41 return node->buffer;
42 }
43 //! Gets the underlying file buffer. Handle must be valid.
44 DUCKDB_API FileBuffer &GetFileBuffer();
45 //! Destroys the buffer handle
46 DUCKDB_API void Destroy();
47
48 const shared_ptr<BlockHandle> &GetBlockHandle() const {
49 return handle;
50 }
51
52private:
53 //! The block handle
54 shared_ptr<BlockHandle> handle;
55 //! The managed buffer node
56 FileBuffer *node;
57};
58
59} // namespace duckdb
60