-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDatabase.h
More file actions
41 lines (40 loc) · 1.15 KB
/
Database.h
File metadata and controls
41 lines (40 loc) · 1.15 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
/*************************************************************************
> File Name: Database.h
> Author: MidCHeck
> Mail: midcheck@foxmail.com
> Created Time: 2019年06月16日 星期日 15时46分27秒
************************************************************************/
#include<string>
#include<unordered_map>
#include<iostream>
namespace MidCHeck{
/*模拟数据库*/
struct Tabusr{
std::string name;
std::string passwd;
std::string home_path;
Tabusr(){};
Tabusr(const char* na, const char* pa, const char* ho):
name(na), passwd(pa), home_path(ho)
{}
};
class Database{
private:
std::unordered_map<std::string, MidCHeck::Tabusr> users;
public:
const Tabusr* query(const char* name){
std::unordered_map<std::string, MidCHeck::Tabusr>::const_iterator it =
users.find(name);
return it != users.end() ? &it->second : nullptr;
}
void add(const char* nam, const char* pass, const char* home = "."){
users[nam] = MidCHeck::Tabusr(nam, pass, home);
}
bool del(const char* name){
const MidCHeck::Tabusr* re = query(name);
if(re == nullptr) return false;
users.erase(name);
return true;
}
};
} // end namespace MidCHeck