-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPersonProfile.cpp
More file actions
71 lines (63 loc) · 1.81 KB
/
Copy pathPersonProfile.cpp
File metadata and controls
71 lines (63 loc) · 1.81 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
//
// CS 32 Project 4
// Naman Modani
// PersonProfile.cpp
//
#include "PersonProfile.h"
#include "provided.h"
PersonProfile::PersonProfile(std::string name, std::string email)
: m_name(name), m_email(email), m_countAttValPairs(0), m_RadixTreeAttVal(new RadixTree<std::set<std::string>*>), m_AttValVector(new std::vector<AttValPair*>)
{}
PersonProfile::~PersonProfile()
{
for (auto it = m_AttValVector->begin(); it != m_AttValVector->end(); it++)
{
std::set<std::string>** attSet = m_RadixTreeAttVal->search((*it)->attribute);
if (attSet != nullptr)
{
// Always true
delete (*attSet);
// Do not delete the same thing twice
*attSet = nullptr;
}
delete (*it);
}
delete m_RadixTreeAttVal;
delete m_AttValVector;
}
std::string PersonProfile::GetName() const
{
return m_name;
}
std::string PersonProfile::GetEmail() const
{
return m_email;
}
void PersonProfile::AddAttValPair(const AttValPair& attval)
{
std::set<std::string>** foundAttSet = m_RadixTreeAttVal->search(attval.attribute);
if (foundAttSet == nullptr)
{
m_RadixTreeAttVal->insert(attval.attribute, new std::set<std::string>);
foundAttSet = m_RadixTreeAttVal->search(attval.attribute);
}
if ((*foundAttSet)->find(attval.value) == (*foundAttSet)->end())
{
(*foundAttSet)->insert(attval.value);
m_AttValVector->push_back(new AttValPair(attval));
m_countAttValPairs++;
}
}
int PersonProfile::GetNumAttValPairs() const
{
return m_countAttValPairs;
}
bool PersonProfile::GetAttVal(int attribute_num, AttValPair& attval) const
{
if (attribute_num < 0 || attribute_num >= GetNumAttValPairs())
{
return false;
}
attval = *(*m_AttValVector)[attribute_num];
return true;
}