-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsocial.h
488 lines (283 loc) · 11.9 KB
/
social.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
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
//
// Created by antronyx on 07/12/18.
//
#ifndef ANTOCOON_SOCIAL_H
#define ANTOCOON_SOCIAL_H
#endif //ANTOCOON_SOCIAL_H
#include <iostream>
#include <fstream>
#include <string>
#include <cstring>
#include <vector>
#include <ctime>
#include <csignal>
#include <iomanip>
#include <iterator>
#include <sstream>
using namespace std;
const std::string LIKE = " \xF0\x9F\x91\x8D LIKE";
const std::string DISLIKE = " \xF0\x9F\x91\x8E DISLIKE";
/*ricorda che se la funzione si chiama isQUALCOSA ritorna 1 in caso positivo sempre*/
/*poiche se qualcosa va strorto indipendentemente, conviene per verificate l assenza
* imporre il !isPresent*/
struct Date {
int dd, mm, yyyy;
};
class Post {
public:
void print();
unsigned long nLikes = 0;
unsigned long nDislikes = 0;
string username = "";
string message = "";
string sdate = "";
Date date;
vector<string> likes{};
vector<string> dislikes{};
void addLike(string _username);
void addDislike(string _username);
void removeLike(string _username);
void removeDislike(string _username);
long GetNLikes();
long GetNDislikes();
Post(const Post &_post) { /*copy constructor */
message = _post.message;
sdate = _post.sdate;
date = _post.date;
nLikes = _post.nLikes;
nDislikes = _post.nDislikes;
username = _post.username;
likes = _post.likes;
dislikes = _post.dislikes;
}
friend std::ostream &operator<<(std::ostream &out, const Post &post);
Post();
~Post();
private:
};
class gUser {
protected:
char __type;
int __dd, __mm, __yyyy, __daysalive;
string __username, __file_ref, __posts_file_ref, __relation_file_ref, __name, __date, __city;
vector<Post> __post;
public:
virtual string getUsername() const;
char GetType();
virtual string getName() const;
virtual int getDays() const; //ritorna il valore privato di giorni dalla nascita
virtual string getCity() const;
virtual string getDate() const;
virtual int getDD() const;
virtual int getMM() const;
virtual int getYYYY() const;
virtual string getPostsFileRef();
virtual string getFileRef();
virtual string getRelFileRef();
virtual unsigned long GetNPosts();
virtual void SetPost(vector<Post> _posts);
virtual void setUsername(string _user_name);
virtual void setDays();
virtual void setName();
virtual void setName(string _name);
virtual void setCity();
virtual void setCity(string _city);
virtual void setDate();
virtual void setDate(string _date);
virtual void addPost(Post _to_add);
virtual void setFileRef(string _file_ref);
virtual void setPostsFileRef(string _file_ref);
virtual void setRelFileRef(string _file_ref);
//virtual void addLikes();
virtual void loadPosts();
//virtual void addDisLikes();
virtual vector<Post> getPost();
void loadPosts(vector<Post> _to_add);
gUser(const gUser &obj) { /** Declaring Copy-Constructor **/
__dd = obj.__dd;
__mm = obj.__mm;
__yyyy = obj.__yyyy;
__daysalive = obj.__daysalive;
__username = obj.__username;
__file_ref = obj.__file_ref;
__posts_file_ref = obj.__posts_file_ref;
__relation_file_ref = obj.__relation_file_ref;
__name = obj.__name;
__date = obj.__date;
__city = obj.__city;
__post = obj.__post;
}
gUser();
explicit gUser(string _file_name);
gUser(string _user_name, string _file_ref);
~gUser();
};
class User : public gUser {
private:
vector<string> __friends, __sons, __knowedpoeple, __subscribed_groups;
string __surname, __university, __religion, __party, __father, __mother, __mate;
char __sex;
char __type = 'S';
unsigned short __age;
public:
void setDays() override;
string getSurname();
string getUniversity();
string getReligion();
string getParty();
char getSex();
string GetFather();
string GetMother();
void SetMate(string _mate);
string GetMate();
string GetParent(char _sex); /*Generic getfather/getmother it dipend by the insertion*/
void SetFather(string _father);
void SetMother(string _father);
void SetFriends(vector<string> _friends);
void SetKnowed(vector<string> _knowed);
void SetSubsGroups(vector<string> _subsribed);
vector<string> GetFriends();
vector<string> GetSubsGroups();
vector<string> GetSons();
void SetSons(vector<string> _sons);
unsigned long GetNFriends();
vector<string> GetKnowed();
unsigned long GetNKnowed();
unsigned short getAge();
void setAge();
void setRelations();
void setSurname();
void setSurname(string _surname);
void setUniversity();
void setUniversity(string _university);
void setReligion();
void setReligion(string _religion);
void setParty();
void setParty(string _party);
void setSex(char _sex);
void setSex();
User();
friend void gUser::setDays(); /**Overriding, to make possible to set age for people**/
User(string _username, string _file_ref, string _relation_file, string _post_file);
~User();
};
class Group : public gUser {
private:
string __field, __headquarter;
vector<string> __components;
unsigned long __ncomponents;
char __type = 'G';
public:
void AddComponent(string _component);
void RemoveComponent(string _component);
string GetField();
string GetHeadquarter();
void SetField();
void SetField(string _field);
void SetHeadquarter();
void SetHeadquarter(string _headquarter);
vector<string> GetComponents();
unsigned long GetNComponents();
void SetComponents();
void SetComponents(vector<string> &_to_set);
Group();
};
class Company : public gUser {
private:
char __type = 'C';
string __field, __tax_office, __code, __headquarter;
vector<string> __employees, __subsidiary;
public:
void SetField();
void SetField(string _field);
void SetHeadquarter();
void SetHeadquarter(string _headquarter);
void SetTaxOffice();
void SetTaxOffice(string _tax_office);
void SetCode();
void SetCode(string _code);
string GetField();
string GetHeadquarter();
string GetTaxOffice();
string GetCode();
void SetEmployees(vector<string> _emp);
void SetEmployees();
void SetSubsidiary();
void SetSubsidiary(vector<string> _subs);
vector<string> GetEmployees();
vector<string> GetSubsidiary();
vector<string> SetCumulativeEmployees();
unsigned long GetNEmployees();
unsigned long GetNSubsidiary();
unsigned long GetComulativeEmployees();
};
/**#########################################################################################################################################**/
/**###################Here i declare all the prototypes of the functions that can be used to read, write or modify the file ################**/
/**#########################################################################################################################################**/
/** void showFile(string _file_name) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ As declared **/
/** void showIDs(string _file_name) -------------------------------------------------------------------------------------------- As declared **/
/** bool isIdPresent(string _file_name, string _user_name) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ As declared **/
/** unsigned int typeUsersNum(string _file_name, char type) ---------- type accept S,C,G; It return the number of simple/company/group users **/
/** unsigned int getIdPos(string _file_name, string _user_name) ~~~~~~~~~~~~~~~~~~~Return position in file, else return error with the code 0 **/
/** char getUserType(string _file_name, string _user_name) ---------------------- return S/C/G=simple/company/group; else error w/ err_code E **/
/** bool isEntry(string _parameter) ~~~~~~~~~~~~~~~~~~~~~~~~~some parameters is not accepted in parser (e.g <shoe_size> or <number_of_hair>) **/
/** bool isParameterPresent(string _file_name, string _user_name, string _parameter) -----tell if a parameter (e.g. <name>) is already present **/
/** void modifyInfo(string _file_name, string _user_name, string _parameter, string _info) ~~~~~~~~~~~~~~~~~~~~~~~~~~~ Modify Info by parameter **/
/** string getInfo(string _file_name, string _user_name, string _parameter) -------------------------------------------- Get Info by parameter **/
/** void addParameterAndInfo(string _file_name, string _user_name, string _parameter,string _info) ~~~~~~~~~~~~NOW WRITE ON LOG*******************/
/**#########################################################################################################################################**/
void showFile(string _file_name);
void showIDs(string _file_name);
bool isIdPresent(string _file_name, string _user_name);
unsigned int typeUsersNum(string _file_name, char type);
unsigned int getIdPos(string _file_name, string _user_name); //0 se non esiste, in altri casi ritorna posizione
char getUserType(string _file_name, string _user_name);
bool isEntry(string _parameter);
bool isUsEntry(string _parameter);
bool isParameterPresent(string _file_name, string _user_name, string _parameter);
void modifyInfo(string _file_name, string _user_name, string _parameter, string _info);
string getInfo(string _file_name, string _user_name, string _parameter);//get info by parameter
void addParameterAndInfo(string _file_name, string _user_name, string _parameter, string _info);
unsigned int numS(string _file_username);/***Functions to now analytics***/
unsigned int numC(string _file_name);
unsigned int numG(string _file_name);
int countLeapYears(Date d);
bool isDateCorrect(string _date);
int dateDiff(Date dmin, Date dsup);
Date strtoD(string _date); /**String to Date **/
int daysByDate(string _date); /*** ritorna giorni di vita, da data, In case of ERROR, return -1 ****/
/** return a vector with all users/company/groups **/
vector<string> getUsers(string _file_users);
vector<string> getCompanies(string _file_users);
vector<string> getGroups(string _file_users);
/**************************************************/
vector<string> PostingPeople(string _file_posts);
vector<string> split(const string &_string_in, char _delimiter);
bool common(vector<string> _bigger, vector<string> _little);
bool common(const string _str_to_compare,
const vector<string> _list2);
long getVecPos(string _to_find, vector<string> _vec);
unsigned long getEmployees(Company __company);
void showSUser(User _to_show);
void showSUser(vector<User> _to_show);
void showCUser(Company _to_show);
void showCUser(vector<Company> _to_show);
void showGUser(Group _to_show);
void showGUser(vector<Group> _to_show);
User modifySUser(User _to_modify, string _command, string _argument);
Company modifyCUser(Company _to_modify, string _command, string _argument);
Group modifyGUser(Group _to_modify, string _command, string _argument);
string trim(const std::string &s);
std::string ltrim(const std::string &s);
std::string rtrim(const std::string &s);
long totPosts(vector<User> &_u, vector<Company> &_c, vector<Group> &_g);
void showPosts(vector<User> &_u, vector<Company> &_c, vector<Group> &_g, string _username_logged);
char getType(string _to_find, vector<string> _users, vector<string> _companyes, vector<string> _groups);
bool isnumerical(string);
Post modifyPost(Post &_to_modify, string _command, string _argument);
void
save(vector<User> &_u, vector<Company> &_c, vector<Group> &_g, string userfile, string postfile, string relationfile);
string
printLD(const vector<string> &to_print);/*function for printing likes and dislikes in file respecting right notation*/
vector<pair<int, string>> occurr(vector<string> &_to_analize);
bool isVoid(string _to_know);