This repository has been archived by the owner on Jan 3, 2024. It is now read-only.
forked from fnc12/sqlite_orm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjournal_mode.h
73 lines (65 loc) · 2.04 KB
/
journal_mode.h
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
#pragma once
#include <iterator> // std::back_inserter
#include <string> // std::string
#include <memory> // std::unique_ptr
#include <array> // std::array
#include <algorithm> // std::transform
#include <cctype> // std::toupper
#if defined(_WINNT_)
// DELETE is a macro defined in the Windows SDK (winnt.h)
#pragma push_macro("DELETE")
#undef DELETE
#endif
namespace sqlite_orm {
/**
* Caps case because of:
* 1) delete keyword;
* 2) https://www.sqlite.org/pragma.html#pragma_journal_mode original spelling
*/
enum class journal_mode : signed char {
DELETE = 0,
// An alternate enumeration value when using the Windows SDK that defines DELETE as a macro.
DELETE_ = DELETE,
TRUNCATE = 1,
PERSIST = 2,
MEMORY = 3,
WAL = 4,
OFF = 5,
};
namespace internal {
inline const std::string& to_string(journal_mode j) {
static std::string res[] = {
"DELETE",
"TRUNCATE",
"PERSIST",
"MEMORY",
"WAL",
"OFF",
};
return res[static_cast<int>(j)];
}
inline std::unique_ptr<journal_mode> journal_mode_from_string(const std::string& str) {
std::string upper_str;
std::transform(str.begin(), str.end(), std::back_inserter(upper_str), [](char c) {
return static_cast<char>(std::toupper(static_cast<int>(c)));
});
static std::array<journal_mode, 6> all = {{
journal_mode::DELETE,
journal_mode::TRUNCATE,
journal_mode::PERSIST,
journal_mode::MEMORY,
journal_mode::WAL,
journal_mode::OFF,
}};
for(auto j: all) {
if(to_string(j) == upper_str) {
return std::make_unique<journal_mode>(j);
}
}
return {};
}
}
}
#if defined(_WINNT_)
#pragma pop_macro("DELETE")
#endif