LMDBAL 0.6.2
LMDB (Lightning Memory-Mapped Database Manager) Abstraction Layer
Loading...
Searching...
No Matches
cursor.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 <string>
22#include <string_view>
23
24#include "lmdb.h"
25#include "base.h"
26#include "storage.h"
27#include "transaction.h"
28#include "cursorcommon.h"
29
30namespace LMDBAL {
31
32template <class K, class V>
33class Cursor : public CursorCommon {
34 friend class Storage<K, V>;
35public:
36 Cursor();
37 Cursor(Storage<K, V>* parent);
38 Cursor(const Cursor& other) = delete;
39 Cursor(Cursor&& other);
40 ~Cursor();
41
42 Cursor& operator = (const Cursor& other) = delete;
43 Cursor& operator = (Cursor&& other);
44
45 void drop();
46
47 std::pair<K, V> first();
48 std::pair<K, V> last();
49 std::pair<K, V> next();
50 std::pair<K, V> prev();
51 std::pair<K, V> current() const;
52 bool set(const K& target);
53
54 void first(K& key, V& value);
55 void last(K& key, V& value);
56 void next(K& key, V& value);
57 void prev(K& key, V& value);
58 void current(K& key, V& value) const;
59
60private:
61 void operateCursorRead(K& key, V& value, MDB_cursor_op operation, std::string_view methodName, std::string_view operationName) const;
62};
63
64};
65
66
67#include "cursor.hpp"
CursorCommon()
Creates a empty class.
Definition cursorcommon.cpp:41
std::pair< K, V > first()
Queries the first element in the storage.
Definition cursor.hpp:236
void drop()
Turns cursor into an empty one, releasing resources.
Definition cursor.hpp:116
std::pair< K, V > prev()
Queries the previous element from the storage.
Definition cursor.hpp:302
std::pair< K, V > last()
Queries the last element in the storage.
Definition cursor.hpp:254
std::pair< K, V > current() const
Returns current cursor element from the storage.
Definition cursor.hpp:322
bool set(const K &target)
Sets cursors to the defined position.
Definition cursor.hpp:341
Cursor()
Creates an empty cursor.
Definition cursor.hpp:62
std::pair< K, V > next()
Queries the next element from the storage.
Definition cursor.hpp:278
This is a basic key value storage.
Definition storage.h:38
Destroys a cache.
Definition base.h:36