-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPerson.h
More file actions
108 lines (84 loc) · 3.59 KB
/
Person.h
File metadata and controls
108 lines (84 loc) · 3.59 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
/* A Person object simply contains std::strings for a person's data.
Once created, the data cannot be modified. */
#ifndef PERSON_H
#define PERSON_H
#include <string>
#include <fstream>
#include <set>
#include <map>
class Person {
public:
Person(const std::string& firstname_, const std::string& lastname_, const std::string& phoneno_)
: firstname(firstname_), lastname(lastname_), phoneno(phoneno_)
{}
// construct a Person object with only a lastname
Person(const std::string& lastname_)
: lastname(lastname_)
{}
// Disallow all forms of copy/move construction or assignment
Person(Person& original) = delete;
Person(Person&& original) = delete;
Person& operator=(Person& original) = delete;
Person& operator=(Person&& original) = delete;
// These declarations help ensure that Person objects are unique,
// like they are in the problem domain
// Construct a Person object from a file stream in save format.
// Throw Error exception if invalid data discovered in file.
// No check made for whether the Person already exists or not.
// Input for a member variable value is read directly into the member variable.
Person(std::ifstream& is);
// Accessors
std::string get_lastname() const
{return lastname;}
// Write a Person's data to a stream in save format with final endl.
void save(std::ostream& os) const;
// returns true if a person is committed at the provided time
bool is_committed_at(int);
bool has_Commitments();
// adds a commitment to this person commitments container
void add_Commitment(int room_no, int time, std::string topic);
// removes the commitment at the specified time from the persons commitments
void remove_Commitment(int time);
// prints all the commitments for a person
void print_Commitments();
void update_Commitment(int old_time, int new_room_no, int new_time);
// This operator defines the order relation between Persons, based just on the last name
bool operator< (const Person& rhs) const
{return lastname < rhs.lastname;}
bool operator== (const Person& rhs) const
{return lastname == rhs.lastname;}
friend std::ostream& operator<< (std::ostream& os, const Person& person);
private:
struct Commitment_t {
Commitment_t(int, int, std::string);
Commitment_t(int, int);
int room_no;
int time;
std::string topic;
};
struct Comp_Commitments {
bool operator() (const Commitment_t*, const Commitment_t*);
bool operator() (const int&, const int&);
};
// two different containers, while slightly redundant, allows for commitment
// lookup in logarithmic time since only using one container would result in
// either a linear search for is_committed_at, or a linear searches for
// printing commitments which is foribben as per the spec
// the first container maps room number to a commitment pointer
using Commitment_times_container_t = std::map<int, Commitment_t*, Comp_Commitments>;
Commitment_times_container_t commitment_times;
// the second container is just a set of commitment pointers
using Commitments_container_t = std::set<Commitment_t*, Comp_Commitments>;
Commitments_container_t commitments;
std::string firstname;
std::string lastname;
std::string phoneno;
public:
friend std::ostream& operator<< (std::ostream& os, const Person::Commitment_t& commitment);
};
// output firstname, lastname, phoneno with one separating space, NO endl
std::ostream& operator<< (std::ostream& os, const Person& person);
std::ostream& operator<< (std::ostream& os, const Person* person);
// this outputs the commitment according to the style present in string.txt
std::ostream& operator<< (std::ostream& os, const Person::Commitment_t& commitment);
#endif