LMDBAL 0.6.0
LMDB (Lightning Memory-Mapped Database Manager) Abstraction Layer
Loading...
Searching...
No Matches
serializer_double.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
21namespace LMDBAL {
22
23template<>
24class Serializer<double> {
25public:
26 Serializer():value(0) {};
27 Serializer(const double& p_value):value(p_value) {};
28 ~Serializer() {};
29
30 double deserialize(const MDB_val& data) {
31 deserialize(data, value);
32 return value;
33 };
34 void deserialize(const MDB_val& data, double& result) {
35 std::memcpy(&result, data.mv_data, 8);
36 }
37 MDB_val setData(const double& data) {
38 value = data;
39 return getData();
40 };
41 MDB_val getData() {
42 MDB_val result;
43 result.mv_data = &value;
44 result.mv_size = 8;
45 return result;
46 };
47 void clear() {}; //not possible;
48
49private:
50 double value;
51};
52
53}
54
55
56
A class handling serialization/deserialization.
Definition serializer.h:33
~Serializer()
Destoys the serializer.
Definition serializer.hpp:69
Serializer()
Creates an empty Serializer.
Definition serializer.hpp:40
MDB_val getData()
Returns the data if it already was serialized.
Definition serializer.hpp:153
T deserialize(const MDB_val &value)
Deserializes value.
Definition serializer.hpp:99
void clear()
Clears the state of serializer.
Definition serializer.hpp:137
MDB_val setData(const T &value)
Sets the data to the seriazer.
Definition serializer.hpp:83