-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathDataBase.hpp
More file actions
116 lines (87 loc) · 3.28 KB
/
DataBase.hpp
File metadata and controls
116 lines (87 loc) · 3.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
/*
Pterodon Recovery - header file of the DataBase
Copyright (C) <2020> ATGDroid <bythedroid@gmail.com>
This file is part of Pterodon Recovery Project
Pterodon Recovery is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Pterodon Recovery is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Pterodon Recovery. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef _PTERODON_DATABASE_HPP
#define _PTERODON_DATABASE_HPP
#include <string>
#include <unordered_map>
#define PTERODON_DATABASE_USES_LOWLEVEL_CALLS 1
namespace Pterodon {
namespace wrappers {
class DataBase
{
public:
DataBase() = default;
virtual ~DataBase();
public:
bool operator==(const DataBase& other) const;
bool operator!=(const DataBase& other) const;
DataBase& operator=(const DataBase& other);
DataBase& operator+(const DataBase& other);
DataBase& operator-(const DataBase& other);
DataBase& operator+=(const DataBase& other);
DataBase& operator-=(const DataBase& other);
std::unordered_map<std::string, std::string>::iterator begin() { return data_.begin(); }
std::unordered_map<std::string, std::string>::iterator end() { return data_.end(); }
std::unordered_map<std::string, std::string>::const_iterator begin() const { return data_.begin(); }
std::unordered_map<std::string, std::string>::const_iterator end() const { return data_.end(); }
public:
void NewVar(const std::string& mVarName, const std::string& mVarValue);
bool GetVar(const std::string& mVarName, std::string &mVarValue) const;
std::string GetVar(const std::string& mVarName) const;
void SetVar(const std::string& mVarName, const std::string& mVarValue);
void DelVar(const std::string& mVarName);
bool GetVarByValue(const std::string& mVarName, std::string &mVarValue) const;
void reserve(const size_t& value);
void clear(void);
bool contains(const std::string& mVarName) const;
bool contains(const std::string& mVarName, const std::string& mVarValue) const;
size_t size(void) const;
void print(void) const;
bool empty(void) const;
//std::unordered_map<std::string, std::string>* GetData(void) { return &data_; }
/*
* Serialize
*
* If (Serialize("/sdcard/pterodon/settings/boot_data"))
* printf("Serialized boot_data to /sdcard/Pterodon/settings/boot_data\n");
*
*/
bool Serialize(const std::string& path) const;
bool Unserialize(const std::string& path, bool check_version);
bool SaveToPropFile(const std::string& path) const;
bool LoadFromPropFile(const std::string& path);
private:
void Format(std::string &str) const;
bool WriteValue(
#ifdef PTERODON_DATABASE_USES_LOWLEVEL_CALLS
int fd,
#else
FILE* fp,
#endif
const std::string& mValue) const;
bool ReadValue(
#ifdef PTERODON_DATABASE_USES_LOWLEVEL_CALLS
int fd,
#else
FILE* fp,
#endif
std::string &mValue) const;
private:
std::unordered_map<std::string, std::string> data_;
};
} // namespace wrappers
} // namespace Pterodon
#endif // _PTERODON_DATABASE_HPP