-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathstream.h
360 lines (308 loc) · 9.57 KB
/
stream.h
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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
//
// Created by joaog on 10/23/2020.
//
#ifndef PROJETO1_STREAM_H
#define PROJETO1_STREAM_H
#include <map>
#include <fstream>
#include <set>
#include <vector>
#include "date.h"
/**
* @brief Abstract class representing a stream
*/
class Stream{
protected:
/**
* @brief Title of the Stream
*/
std::string title;
/**
* @brief Start date of the Stream
*/
Date startDate;
/**
* @brief Language of the Stream
*/
std::string language;
/**
* @brief Minimum age of the Stream
*/
int minAge;
/**
* @brief The Stream's Viewers are stored in this set
*/
std::set<unsigned int> viewers;
/**
* @brief Number of likes of the Stream
*/
int noLikes;
/**
* Number of Viewers of the Stream
*/
int numViewers;
/**
* @brief Nickname of the Streamer controlling the Stream
*/
string streamerNick;
/**
* @brief ID of the Stream
*/
unsigned int id;
public:
/**
* @brief ID of the next Stream created
*/
static unsigned int nextID;
/**
* @brief Constructs a Stream with given title, start date, language, minimum age and the nick of the Streamer
* @param title Title of the Stream
* @param startDate Start date of the Stream
* @param language Language of the Stream
* @param minAge Minimum age of the Stream
* @param streamerNick Nickname of the Streamer controlling the Stream
*/
Stream(const string& title, const Date& startDate, const string& language, int minAge, const string& streamerNick);
/**
* @brief Default constructor of the base class Stream
*/
virtual ~Stream();
/**
* @brief Adds a User to the viewers set. Only defined in the derived classes
* @param user User joining the stream
*/
virtual void addUser(unsigned int user) = 0;
/**
* @brief Removes a User from the viewers set
* @param user ID of the user intended to remove
*/
void removeUser(unsigned int user);
/**
* @brief Gets number of current Viewers in the stream
* @return Integer containing the number of Viewers
*/
int getNumViewers() const;
/**
* @brief Gets the tile of the Stream
* @return String containing the title of the Stream
*/
std::string getTitle() const;
/**
* @brief Gets the Stream's start date
* @return Date with the start date
*/
Date getStartDate() const;
/**
* @brief Gets the language of the Stream
* @return String containing the language of the Stream
*/
std::string getLanguage() const;
/**
* @brief Gets the minimum age of the Stream
* @return Integer containing the minimum age of the Stream
*/
int getMinAge() const;
/**
* @brief Gets the number of likes of the Stream
* @return Integer containing the number of likes
*/
int getNoLikes() const;
/**
* @brief Gets the nickname of the Streamer controlling the Stream
* @return String containing the nickname of the Streamer
*/
std::string getStreamerNick() const;
/**
* @brief Gets the set of Viewers in the Stream (by reference)
* @return Set of Viewers in the Stream
*/
std::set<unsigned int>& getViewers();
/**
* @brief Receives feedback from a Viewer in the form of a like (1) or a dislike (-1)
* @param megaLikezao Value added to the overall feedback (1 or -1)
*/
void feedback(int megaLikezao);
/**
* @brief Prints the Stream's information to the standard output
*/
virtual void showStream() const;
/**
* @brief Gets the ID of the Stream
* @return Unsigned int containing the ID of the Stream
*/
unsigned int getId() const;
/**
* @brief Sets the nickname of the Streamer
* @param nick Nickname of the Streamer
*/
void setStreamerNick(const string& nick);
void add50likes();
};
/**
* @brief Stream restricted to certain Viewers (subscribers) with a maximum number of Viewers at a time.
* Derived from Stream class
*/
class PrivateStream : public Stream{
/**
* @brief Maximum number of viewers watching at a time
*/
int capacity;
/**
* @brief Set of Viewers subscribed to the Streamer controlling the Stream
*/
std::set<unsigned int> subscribers;
/**
* @brief Vector storing the messages that the Viewers send
*/
std::vector<std::string> messages;
public:
/**
* @brief Creates a private stream with given subscribers, capacity and Stream() parameters. Also see Stream()
* @param title Title of the stream
* @param startDate Start date of the stream
* @param language Language of the stream
* @param minAge Minimum age of the stream
* @param streamerNick Nickname of the Streamer controlling the stream
* @param subscribers Set of Viewers (IDs) subscribed to the Streamer
* @param capacity Capacity of the stream
* @throw NoCapacity If the number of Viewers in the PrivateStream exceeds the capacity
* @throw NotSubscribed If the Viewer trying to join isn't subscribed to the Streamer
*/
PrivateStream(const string& title, const Date& startDate, const string& language, int minAge, const string& streamerNick,
std::set<unsigned int> &subscribers, int capacity);
/**
* @brief Default destructor of the derived PrivateStream class
*/
virtual ~PrivateStream();
/**
* @brief Adds a User to the viewers set. Throws the exceptions noCapacity if the stream is full
* and NotSubscribed if the given User is not subscribed
* @param user ID of the user trying to join the stream
*/
virtual void addUser(unsigned int user);
/**
* @brief Prints the private stream's information to the standard output
*/
virtual void showStream() const;
/**
* @brief Prints all the Viewer's messages to the standard output
*/
void showMessages() const;
/**
* @brief Adds a message from a Viewer to the messages vector
* @param message Message written by a Viewer
*/
void addMessage(const std::string& message); // the message includes the name of the user
};
/**
* @brief Stream which can be accessed by any Viewer. Derived from Stream class
*/
class PublicStream : public Stream{
public:
/**
* @brief Creates a public stream with Stream() parameters. Also see Stream()
* @param title Title of the stream
* @param startDate Start date of the stream
* @param language Language of the stream
* @param minAge Minimum age of the stream
* @param streamerNick Nickname of the Streamer controlling the stream
*/
PublicStream(const string& title, const Date& startDate, const string& language, int minAge, const string& streamerNick);
/**
* @brief Default destructor of the derived class PublicStream
*/
virtual ~PublicStream();
/**
* @brief Adds a User to the viewers set
* @param user ID of the User joining the stream
*/
virtual void addUser(unsigned int user);
/**
* @brief Prints the public stream's information to the standard output
*/
virtual void showStream() const;
};
/**
* @brief Prints the given Stream's information to the standard output
* @param out Output stream which is going to be written to
* @param stream Stream whose information is going to be printed
* @return Returns the given ostream out
*/
ostream& operator<<(ostream& out, Stream& stream );
/**
* @brief Struct used to store a Stream which has already ended
*/
struct PastStream{
/**
* @brief Creates an empty PastStream struct. Its members should be updated before using it
*/
PastStream(){Stream::nextID++;};
/**
* @brief Creates a struct storing a past Stream, containing the Stream title, its ID and its start date;
* noViewers is set to -1 and updated when the Stream ends.
* @param stream Pointer to the stream intended to store
*/
PastStream(Stream* stream){this->name = stream->getTitle(), this->noViewers = -1, this->id = stream->getId(),
this->StartDate = stream->getStartDate();};
/**
* @brief Name of the Stream
*/
std::string name;
/**
* @brief Number of Viewers the moment the Stream ended
*/
int noViewers;
/**
* @brief ID of the Stream
*/
unsigned int id;
/**
* @brief Start Date of the Stream
*/
Date StartDate;
};
// Exceptions
/**
* @brief Exception class which should be thrown when a PrivateStream's capacity is full and a Viewer tries to join
*/
class NoCapacity{
private:
/**
* @brief Reason the exception was thrown
*/
string reason;
public:
/**
* @brief Creates a noCapacity exception with a given reason
* @param reason Reason for the exception to be thrown
*/
NoCapacity(const string& reason);
/**
* Gets the reason for which the exception was thrown
* @return String containing the reason
*/
string what();
};
/**
* @brief Exception class which should be thrown when a Viewer tries to join a PrivateStream
* he is not subscribed to
*/
class NotSubscribed{
private:
/**
* @brief Reason the exception was thrown
*/
string reason;
public:
/**
* @brief Creates a NotSubscribed exception with a given reason
* @param reason Reason for the exception to be thrown
*/
NotSubscribed(const string& reason);
/**
* Gets the reason for which the exception was thrown
* @return String containing the reason
*/
string what() const;
};
#endif //PROJETO1_STREAM_H