-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathelement.cpp
More file actions
129 lines (105 loc) · 3.17 KB
/
Copy pathelement.cpp
File metadata and controls
129 lines (105 loc) · 3.17 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
117
118
119
120
121
122
123
124
125
126
127
128
129
//
// Created by 房诗涵 on 2022/12/12.
//
#include "element.h"
Index::Index() {
index[0] = '\0';//empty string
}
Index::Index(std::string id) {
for (int i = 0; i < id.size(); ++i)
index[i] = id[i];
index[id.size()] = '\0';
}
bool Index::operator>(const Index &id) const {
for (int i = 0;; ++i) {
if (index[i] > id.index[i])return true;
if(index[i] < id.index[i]) return false;
if (index[i] == '\0')return false;
if (id.index[i] == '\0')return true;
}
}
bool Index::operator==(const Index &id) const {
int i = 0;
while (index[i] != '\0') {
if (index[i] != id.index[i])return false;
++i;
}
return true;
}
bool Index::operator>=(const Index &id) const {
if ((*this > id) || (*this == id))return true;
else return false;
}
std::ostream &operator<<(std::ostream &os, const Index &index) {
int i = 0;
while (index.index[i] != '\0') {
os << index.index[i];
}
return os;
}
Index &Index::operator=(const Index &id) = default;
Index::~Index() = default;
bool account::operator>(const account &id) const {
if (index > id.index || (index == id.index && value > id.value)) return true;
else return false;
}
Index account::GetKey() const {
return index;
}
bool account::operator==(const account &account) const {
if (account.index == index && account.value == value)return true;
else return false;
}
bool account::operator>=(const account &account) const {
if (*this > account || *this == account)return true;
else return false;
}
int account::GetVal() const {
return value;
}
account &account::operator=(std::pair<account, bool> account) {
return account.first;
}
AccountManager::AccountManager() {
}
void AccountManager::AddUser(std::string &index, int value) {
//create an account
account userAccount;
Index index1(index);
userAccount.index = index1;
userAccount.value = value;
//insert
accountList.Insert(index1, userAccount);
}
bool AccountManager::DeleteUser(std::string &index, int value) {
account a;
a.value = value;
Index id(index);
a.index = id;
bool b = accountList.Erase(id, value);
return b;
}
//more than one
std::pair<account, bool> AccountManager::FindAccount(const std::string &UserID) {
account a;
Index id(UserID);
a.index = id;
if (!more) {//haven't gotten any
if (accountList.FindKey(id).second) {
currentValue = accountList.FindKey(id).first.value;
return std::make_pair(accountList.FindKey(id).first, true);
} else return std::make_pair(a, false);
} else {
if (accountList.FindK(id, currentValue).second) {
currentValue = accountList.FindK(id, currentValue).first.value;//update currentValue
return std::make_pair(accountList.FindK(id, currentValue).first, true);
}else return std::make_pair(a,false);
}
}
void AccountManager::StringToChar(std::string str, char *ch) {
int i;
for (i = 0; i < str.size(); ++i) {
ch[i] = str[i];
}
ch[i] = '\0';
}