Repository navigation
Expand file tree
/
Copy pathMemberDatabase.cpp
More file actions
111 lines (100 loc) · 2.95 KB
/
Copy pathMemberDatabase.cpp
File metadata and controls
111 lines (100 loc) · 2.95 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
//
// MemberDatabase.cpp
// proj4
//
// Created by Andy on 3/3/22.
//
#include "MemberDatabase.h"
#include "PersonProfile.h"
#include <fstream>
#include <algorithm>
MemberDatabase::MemberDatabase()
{
}
MemberDatabase::~MemberDatabase()
{
std::vector<PersonProfile*>::iterator it;
for(it = people.begin();it!=people.end();)
{
delete *it;
it = people.erase(it);
}
}
bool MemberDatabase::LoadDatabase(std::string filename)
{
std::ifstream file(filename);
if (file.fail())
{
return false;
}
std::string line;
std::vector<std::string> member;
while(getline(file, line))
{
member.push_back(line);
if(line.empty())//end of one member
{
std::string name = member[0];
std::string email = member[1];
int numPairs = std::stoi(member[2]);
PersonProfile* newPerson = new PersonProfile(name, email);
people.push_back(newPerson);
for(int i = 3;i<3+numPairs;i++)
{
std::string attributeValue = member[i];
std::vector<std::string>* emails = pairToEmail.search(attributeValue);
if(emails!=nullptr)//if that attribute is already in the radixtree
{
if(std::find(emails->begin(),emails->end(), email)==emails->end())
{
emails->push_back(email);
}
}
else
{
std::vector<std::string> newVector;
newVector.push_back(email);
pairToEmail.insert(attributeValue, newVector);
}
std::string att;
std:: string val;
for(int k = 0;k<member[i].size();k++)
{
if(member[i][k]==',')
{
att = member[i].substr(0, k);
val = member[i].substr(k+1, member[i].size());
}
}
AttValPair newPair = AttValPair(att, val);
newPerson->AddAttValPair(newPair);
}
emailtoPerson.insert(email, newPerson);
member.clear();
}
}
return true;
}
std::vector<std::string> MemberDatabase::FindMatchingMembers(const AttValPair& input) const
{//check for duplicates
std::string sourceString = input.attribute+","+input.value;
std::vector<std::string>* temp = pairToEmail.search(sourceString);
if(temp!=nullptr)
{
return *temp;
}
else
{
std::vector<std::string> newVector;//return empty vector
return newVector;
}
}
const PersonProfile* MemberDatabase::GetMemberByEmail(std::string email) const
{
PersonProfile** temp = emailtoPerson.search(email);
if(temp!=nullptr)
{
return *temp;
}
return nullptr;
}