LMDBAL 0.6.2
LMDB (Lightning Memory-Mapped Database Manager) Abstraction Layer
Loading...
Searching...
No Matches
cursorcommon.h
1/*
2 * LMDB Abstraction Layer.
3 * Copyright (C) 2023 Yury Gubich <blue@macaw.me>
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19#pragma once
20
21#include <stdint.h>
22#include <string>
23#include <string_view>
24
25#include <lmdb.h>
26
27namespace LMDBAL {
28
29class Transaction;
30class StorageCommon;
31
33 friend class Transaction;
34protected:
40
41protected:
44 CursorCommon(const CursorCommon& other) = delete;
46 virtual ~CursorCommon() noexcept;
47
48 CursorCommon& operator = (const CursorCommon& other) = delete;
49 CursorCommon& operator = (CursorCommon&& other);
50
51public:
52 void open();
53 void open(const Transaction& transaction);
54 void renew();
55 void renew(const Transaction& transaction);
56 bool opened() const;
57 bool empty() const;
58 void close();
59
60protected:
61 void terminated();
62 void dropped();
63 void reset();
64
65private:
66 void attachToTransaction();
67 void disconnectFromTransaction();
68
69protected:
70 uint32_t id;
71 State state;
72 MDB_cursor* handle;
73 StorageCommon* storage;
74
75private:
76 inline static constexpr std::string_view openCursorMethodName = "Cursor::open";
77 inline static constexpr std::string_view closeCursorMethodName = "Cursor::close";
78 inline static constexpr std::string_view renewCursorMethodName = "Cursor::renew";
79
80protected:
81 inline static constexpr std::string_view firstMethodName = "first";
82 inline static constexpr std::string_view lastMethodName = "last";
83 inline static constexpr std::string_view nextMethodName = "next";
84 inline static constexpr std::string_view prevMethodName = "prev";
85 inline static constexpr std::string_view currentMethodName = "current";
86 inline static constexpr std::string_view setMethodName = "set";
87
88 inline static constexpr std::string_view firstOperationName = "Cursor::first";
89 inline static constexpr std::string_view lastOperationName = "Cursor::last";
90 inline static constexpr std::string_view nextOperationName = "Cursor::next";
91 inline static constexpr std::string_view prevOperationName = "Cursor::prev";
92 inline static constexpr std::string_view currentOperationName = "Cursor::current";
93};
94
95}
An object to manage cursor internals and state.
Definition cursorcommon.h:32
void renew()
Renews a cursor.
Definition cursorcommon.cpp:259
bool empty() const
Returns true if the cursor is empty.
Definition cursorcommon.cpp:333
static constexpr std::string_view nextMethodName
member function name, just for exceptions in heir
Definition cursorcommon.h:83
void reset()
A private method that turns cursor into an empty one.
Definition cursorcommon.cpp:113
void terminated()
A private function called to inform the cursor he has been terminated.
Definition cursorcommon.cpp:136
static constexpr std::string_view lastOperationName
member function name, just for exceptions in heir
Definition cursorcommon.h:89
State
Definition cursorcommon.h:35
@ openedPublic
Definition cursorcommon.h:37
@ closed
Definition cursorcommon.h:36
@ openedPrivate
Definition cursorcommon.h:38
static constexpr std::string_view prevMethodName
member function name, just for exceptions in heir
Definition cursorcommon.h:84
static constexpr std::string_view nextOperationName
member function name, just for exceptions in heir
Definition cursorcommon.h:90
void dropped()
A private method that turns cursor into an empty one.
Definition cursorcommon.cpp:126
static constexpr std::string_view setMethodName
member function name, just for exceptions in heir
Definition cursorcommon.h:86
static constexpr std::string_view lastMethodName
member function name, just for exceptions in heir
Definition cursorcommon.h:82
static constexpr std::string_view firstOperationName
member function name, just for exceptions in heir
Definition cursorcommon.h:88
static constexpr std::string_view prevOperationName
member function name, just for exceptions in heir
Definition cursorcommon.h:91
CursorCommon()
Creates a empty class.
Definition cursorcommon.cpp:41
void close()
Termiates a sequence of operations with the cursor.
Definition cursorcommon.cpp:161
static constexpr std::string_view currentOperationName
member function name, just for exceptions in heir
Definition cursorcommon.h:92
bool opened() const
Tells if the cursor is open.
Definition cursorcommon.cpp:340
void open()
Opens the cursor for operations.
Definition cursorcommon.cpp:192
static constexpr std::string_view firstMethodName
member function name, just for exceptions in heir
Definition cursorcommon.h:81
virtual ~CursorCommon() noexcept
Destroys this cursor.
Definition cursorcommon.cpp:82
static constexpr std::string_view currentMethodName
member function name, just for exceptions in heir
Definition cursorcommon.h:85
Storage interface.
Definition storagecommon.h:34
Public read only transaction.
Definition transaction.h:27
Destroys a cache.
Definition base.h:36