LMDBAL 0.6.0
LMDB (Lightning Memory-Mapped Database Manager) Abstraction Layer
Loading...
Searching...
No Matches
storagecommon.hpp
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 "storagecommon.h"
22
37template<class K, class V>
38inline int LMDBAL::StorageCommon::makeStorage(MDB_txn* transaction, bool duplicates) {
39 unsigned int flags = MDB_CREATE;
40 if constexpr (std::is_integral<K>::value)
41 flags |= MDB_INTEGERKEY;
42
43 if (duplicates) {
44 flags |= MDB_DUPSORT;
45
46 if constexpr (std::is_scalar<V>::value)
47 flags |= MDB_DUPFIXED;
48
49 if constexpr (
50 std::is_same<V, uint32_t>::value ||
51 std::is_same<V, int32_t>::value ||
52 std::is_same<V, uint64_t>::value ||
53 std::is_same<V, int64_t>::value
54 ) //for some reason lmdb breaks if it's not one of these types in MDB_DUPFIXED mode
55 flags |= MDB_INTEGERDUP;
56 }
57
58 return _mdbOpen(transaction, flags);
59}
60
70template<class T>
71inline std::string LMDBAL::StorageCommon::toString(const T& value) {
72 return std::to_string(value);
73}
74
83template<>
84inline std::string LMDBAL::StorageCommon::toString(const QString& value) {
85 return value.toStdString();
86}
87
96template<>
97inline std::string LMDBAL::StorageCommon::toString(const std::string& value) {
98 return value;
99}
int makeStorage(MDB_txn *transaction, bool duplicates=false)
A functiion to actually open MDB_dbi storage.
Definition storagecommon.hpp:38
static std::string toString(const T &value)
A method to cast a value (which can be a value or a key) to string.
Definition storagecommon.hpp:71
const bool duplicates
true if storage supports duplicates
Definition storagecommon.h:112