LMDBAL 0.6.0
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
23#include "lmdb.h"
24#include "base.h"
25#include "storage.h"
26#include "transaction.h"
27#include "cursorcommon.h"
28
29namespace LMDBAL {
30
31template <class K, class V>
32class Cursor : public CursorCommon {
33 friend class Storage<K, V>;
34public:
35 Cursor();
36 Cursor(Storage<K, V>* parent);
37 Cursor(const Cursor& other) = delete;
38 Cursor(Cursor&& other);
39 ~Cursor();
40
41 Cursor& operator = (const Cursor& other) = delete;
42 Cursor& operator = (Cursor&& other);
43
44 void drop();
45
46 std::pair<K, V> first();
47 std::pair<K, V> last();
48 std::pair<K, V> next();
49 std::pair<K, V> prev();
50 std::pair<K, V> current() const;
51 bool set(const K& target);
52
53 void first(K& key, V& value);
54 void last(K& key, V& value);
55 void next(K& key, V& value);
56 void prev(K& key, V& value);
57 void current(K& key, V& value) const;
58
59private:
60 void operateCursorRead(K& key, V& value, MDB_cursor_op operation, const std::string& methodName, const std::string& operationName) const;
61};
62
63};
64
65
66#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:233
void drop()
Turns cursor into an empty one, releasing resources.
Definition cursor.hpp:113
~Cursor()
Destroys this cursor.
Definition cursor.hpp:101
std::pair< K, V > prev()
Queries the previous element from the storage.
Definition cursor.hpp:299
std::pair< K, V > last()
Queries the last element in the storage.
Definition cursor.hpp:251
std::pair< K, V > current() const
Returns current cursor element from the storage.
Definition cursor.hpp:319
bool set(const K &target)
Sets cursors to the defined position.
Definition cursor.hpp:338
Cursor()
Creates an empty cursor.
Definition cursor.hpp:62
std::pair< K, V > next()
Queries the next element from the storage.
Definition cursor.hpp:275
This is a basic key value storage.
Definition storage.h:38