LMDBAL 0.6.0
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
24#include <lmdb.h>
25
26namespace LMDBAL {
27
28class Transaction;
29class StorageCommon;
30
32 friend class Transaction;
33protected:
39
40protected:
43 CursorCommon(const CursorCommon& other) = delete;
45 virtual ~CursorCommon() noexcept;
46
47 CursorCommon& operator = (const CursorCommon& other) = delete;
48 CursorCommon& operator = (CursorCommon&& other);
49
50public:
51 void open();
52 void open(const Transaction& transaction);
53 void renew();
54 void renew(const Transaction& transaction);
55 bool opened() const;
56 bool empty() const;
57 void close();
58
59protected:
60 void terminated();
61 void dropped();
62 void reset();
63
64private:
65 void attachToTransaction();
66 void disconnectFromTransaction();
67
68protected:
69 uint32_t id;
70 State state;
71 MDB_cursor* handle;
72 StorageCommon* storage;
73
74private:
75 inline static const std::string openCursorMethodName = "Cursor::open";
76 inline static const std::string closeCursorMethodName = "Cursor::close";
77 inline static const std::string renewCursorMethodName = "Cursor::renew";
78
79protected:
80 inline static const std::string firstMethodName = "first";
81 inline static const std::string lastMethodName = "last";
82 inline static const std::string nextMethodName = "next";
83 inline static const std::string prevMethodName = "prev";
84 inline static const std::string currentMethodName = "current";
85 inline static const std::string setMethodName = "set";
86
87 inline static const std::string firstOperationName = "Cursor::first";
88 inline static const std::string lastOperationName = "Cursor::last";
89 inline static const std::string nextOperationName = "Cursor::next";
90 inline static const std::string prevOperationName = "Cursor::prev";
91 inline static const std::string currentOperationName = "Cursor::current";
92};
93
94}
An object to manage cursor internals and state.
Definition cursorcommon.h:31
static const std::string lastOperationName
member function name, just for exceptions in heir
Definition cursorcommon.h:88
void renew()
Renews a cursor.
Definition cursorcommon.cpp:259
bool empty() const
Returns true if the cursor is empty.
Definition cursorcommon.cpp:333
void reset()
A private method that turns cursor into an empty one.
Definition cursorcommon.cpp:113
static const std::string lastMethodName
member function name, just for exceptions in heir
Definition cursorcommon.h:81
void terminated()
A private function called to inform the cursor he has been terminated.
Definition cursorcommon.cpp:136
State
Definition cursorcommon.h:34
@ openedPublic
Definition cursorcommon.h:36
@ closed
Definition cursorcommon.h:35
@ openedPrivate
Definition cursorcommon.h:37
void dropped()
A private method that turns cursor into an empty one.
Definition cursorcommon.cpp:126
static const std::string currentOperationName
member function name, just for exceptions in heir
Definition cursorcommon.h:91
static const std::string prevMethodName
member function name, just for exceptions in heir
Definition cursorcommon.h:83
static const std::string currentMethodName
member function name, just for exceptions in heir
Definition cursorcommon.h:84
static const std::string nextOperationName
member function name, just for exceptions in heir
Definition cursorcommon.h:89
static const std::string firstMethodName
member function name, just for exceptions in heir
Definition cursorcommon.h:80
CursorCommon()
Creates a empty class.
Definition cursorcommon.cpp:41
void close()
Termiates a sequence of operations with the cursor.
Definition cursorcommon.cpp:161
static const std::string firstOperationName
member function name, just for exceptions in heir
Definition cursorcommon.h:87
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 const std::string nextMethodName
member function name, just for exceptions in heir
Definition cursorcommon.h:82
virtual ~CursorCommon() noexcept
Destroys this cursor.
Definition cursorcommon.cpp:82
static const std::string prevOperationName
member function name, just for exceptions in heir
Definition cursorcommon.h:90
static const std::string setMethodName
member function name, just for exceptions in heir
Definition cursorcommon.h:85
Definition storagecommon.h:33
Public read only transaction.
Definition transaction.h:27