-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPersonProfile.cpp
More file actions
73 lines (63 loc) · 1.84 KB
/
PersonProfile.cpp
File metadata and controls
73 lines (63 loc) · 1.84 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
#include "PersonProfile.h"
using namespace std;
PersonProfile::PersonProfile(string name, string email) : pName(name), pEmail(email) {}
PersonProfile::~PersonProfile() {}
string PersonProfile::GetName() const
{
return pName;
}
string PersonProfile::GetEmail() const
{
return pEmail;
}
void PersonProfile::AddAttValPair(const AttValPair& attval)
{
std::string* valueptr = nullptr;
std::vector<std::string>* values = attributes.search(attval.attribute);
if (values == nullptr)
{
std::vector<std::string> val;
val.push_back(attval.value);
attributes.insert(attval.attribute, val);
values = attributes.search(attval.attribute);
}
else
{
valueptr = find(values, attval.value);
if (valueptr != nullptr) {
return;
}
values->push_back(attval.value);
}
std::string* keyptr = keyTree.search(attval.attribute);
if (keyptr == nullptr) {
keyTree.insert(attval.attribute, attval.attribute);
keyptr = keyTree.search(attval.attribute);
}
AttValPtr avp({ keyptr, values, static_cast<int>(values->size())-1});
attvalptr_vector.push_back(avp);
}
int PersonProfile::GetNumAttValPairs() const
{
return static_cast<int>(attvalptr_vector.size());
}
bool PersonProfile::GetAttVal(int attribute_num, AttValPair& attval) const
{
if (attribute_num >= GetNumAttValPairs() || attribute_num < 0)
return false;
attval.attribute = *attvalptr_vector[attribute_num].keyptr;
std::vector<std::string> values = *attvalptr_vector[attribute_num].values;
int index = attvalptr_vector[attribute_num].index;
attval.value = values[index];
return true;
}
std::string* PersonProfile::find(std::vector<std::string>* vec, const std::string& str) {
if (vec != nullptr) {
for (int i = 0; i < vec->size(); i++) {
if ((*vec)[i].compare(str) == 0) {
return &(*vec)[i];
}
}
}
return nullptr;
}