-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEvent.cpp
More file actions
100 lines (82 loc) · 2.38 KB
/
Event.cpp
File metadata and controls
100 lines (82 loc) · 2.38 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
/*
* Event.cpp
* Created on: Jun 12, 2016
* Author: nicole
*/
#include "Event.h"
Event::Event( const std::string creator, int ID, const std::string title,
const std::string date, const std::string description):
_creator( creator), _eventId( ID), _title( title), _date( date),
_description( description)
{
// TODO Auto-generated constructor stub
}
Event::~Event()
{
RSVP_List.clear();
}
/**
* @brief: Convert event data into string in format of:
* <eventId>\t<eventTitle>\t<eventDate>\t<eventDescription>.\n
* @return: string event data.
*/
std::string Event::toString() const
{
std::string eventInfo = "";
std::string fileName = std::to_string(_eventId) + '\t' + _title + '\t';
eventInfo += _date + '\t' + _description + ".\n";
return eventInfo;
}
bool Event::isNewGuest( const std::string guest)
{
std::set<std::string>::iterator it;
std::string guestIn( guest);
/* transform first command word to upper case */
std::transform( guestIn.begin(), guestIn.end(),guestIn.begin(), ::toupper);
it = _guestsNames.find( guestIn);
if ( it != _guestsNames.end()) {
return false;
}
return true;
}
std::string Event::registerClient( const std::string guest)
{
bool isNew;
std::string guestIn( guest);
/* transform first command word to upper case */
std::transform( guestIn.begin(), guestIn.end(),guestIn.begin(), ::toupper);
isNew = isNewGuest( guestIn);
std::string response;
if ( isNew) {
_guestsNames.insert( guestIn);
RSVP_List.push_back( guestIn);
response = "SUCCESS";
} else {
response = "RSVP to event id " + std::to_string(_eventId) + ALREADY_SENT_RSVP;
}
return response;
}
std::list<std::string> Event::getGuestList()
{
return RSVP_List;
}
void Event::removeGuest( const std::string guest)
{
bool isNew;
std::list<std::string>::iterator it;
std::string guestIn( guest);
/* transform first command word to upper case */
std::transform( guestIn.begin(), guestIn.end(),guestIn.begin(), ::toupper);
isNew = isNewGuest( guestIn);
if (!isNew) {
_guestsNames.erase( guestIn);
it = RSVP_List.begin();
while ( it != RSVP_List.end()) {
if ( (*it).compare( guestIn) == 0) {
RSVP_List.erase(it);
break;
}
it++;
}
}
}