-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathUserInfo.cpp
More file actions
49 lines (42 loc) · 1.62 KB
/
UserInfo.cpp
File metadata and controls
49 lines (42 loc) · 1.62 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
#include "UserInfo.h"
namespace trainsys {
UserInfo::UserInfo(UserID userID, const char *username, const char *password, int privilege) {
this->userID = userID;
this->privilege = privilege;
int len = strlen(username);
if (len > MAX_USERNAME_LEN) len = MAX_USERNAME_LEN;
memcpy(this->username, username, len);
this->username[len] = '\0';
len = strlen(password);
if (len > MAX_PASSWORD_LEN) len = MAX_PASSWORD_LEN;
memcpy(this->password, password, len);
this->password[len] = '\0';
}
UserInfo::UserInfo(const UserInfo &rhs) {
this->userID = rhs.userID;
this->privilege = rhs.privilege;
memcpy(this->username, rhs.username, MAX_USERNAME_LEN + 1);
memcpy(this->password, rhs.password, MAX_PASSWORD_LEN + 1);
}
UserInfo& UserInfo::operator =(const UserInfo& rhs) {
if (this != &rhs) {
this->userID = rhs.userID;
this->privilege = rhs.privilege;
memcpy(this->username, rhs.username, MAX_USERNAME_LEN + 1);
memcpy(this->password, rhs.password, MAX_PASSWORD_LEN + 1);
}
return *this;
}
bool UserInfo::operator ==(const UserInfo& rhs) const {
return userID == rhs.userID &&
strcmp(username, rhs.username) == 0 &&
strcmp(password, rhs.password) == 0 &&
privilege == rhs.privilege;
}
bool UserInfo::operator !=(const UserInfo& rhs) const {
return !(*this == rhs);
}
bool UserInfo::operator <(const UserInfo& rhs) const {
return userID < rhs.userID;
}
} // namespace trainsys