forked from codesafe/CamScannerController
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmemdb.cpp
More file actions
105 lines (83 loc) · 1.83 KB
/
Copy pathmemdb.cpp
File metadata and controls
105 lines (83 loc) · 1.83 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
#include <stdio.h>
#include "memdb.h"
MemDB * MemDB::instance = NULL;
MemDB::MemDB()
{
}
MemDB::~MemDB()
{
}
void MemDB::reset()
{
keyvalue.clear();
}
bool MemDB::getBoolValue(std::string key, bool d)
{
std::string ret = getvalue(key);
if (ret.empty())
return d;
return ret == "true" ? true : false;
}
int MemDB::getIntValue(std::string key, int d)
{
std::string ret = getvalue(key);
if( ret.empty() )
return d;
return atoi(ret.c_str());
}
float MemDB::getFloatValue(std::string key, float d)
{
std::string ret = getvalue(key);
if( ret.empty() )
return d;
return (float)atof(ret.c_str());
}
std::string MemDB::getValue(std::string key)
{
return getvalue(key);
}
void MemDB::setValue(std::string key, int value)
{
char valuestr[256];
#ifdef WIN32
_snprintf (valuestr, sizeof (valuestr), "%d", value);
#else
snprintf (valuestr, sizeof (valuestr), "%d", value);
#endif
setvalue(key, valuestr);
}
void MemDB::setValue(std::string key, float value)
{
char valuestr[256];
#ifdef WIN32
_snprintf (valuestr, sizeof (valuestr), "%f", value);
#else
snprintf (valuestr, sizeof (valuestr), "%f", value);
#endif
setvalue(key, valuestr);
}
void MemDB::setValue(std::string key, std::string value)
{
setvalue(key, value);
}
std::string MemDB::getvalue(std::string key)
{
std::map<std::string, std::string>::iterator it = keyvalue.find(key);
if( it != keyvalue.end() )
{
return it->second;
}
return std::string("");
}
void MemDB::setvalue(std::string key, std::string value)
{
// 없으면 생성 , 있으면 갱신
std::map<std::string, std::string>::iterator it = keyvalue.find(key);
if( it == keyvalue.end() )
{
// 없어서 추가
keyvalue.insert(std::make_pair(key, value));
return;
}
it->second = value;
}