-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFunctions.cpp
More file actions
196 lines (176 loc) · 5.07 KB
/
Copy pathFunctions.cpp
File metadata and controls
196 lines (176 loc) · 5.07 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
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
#include "Functions.hpp"
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
using namespace std;
vector<string> command_splitter(string str) {
vector<string> command_line;
string word = "";
for (auto x : str)
{
if (x == ' ' || x == '\t')
{
if (word != "")
{
command_line.push_back(word);
word = "";
}
}
else
word = word + x;
}
if (word != "")
{
command_line.push_back(word);
}
return command_line;
}
vector<string> splitter(string str, char delimiter){
stringstream line(str);
string splitted;
vector<string> splitted_list;
while(getline(line, splitted, delimiter))
{
splitted_list.push_back(splitted);
}
return splitted_list;
}
vector<Users> read_users(string path){
vector<Users> users;
fstream file;
file.open(path);
string line;
string word;
getline(file, line, '\n');
while(getline(file, line, '\n'))
{
istringstream new_line(line);
getline(new_line, word, ',');
int id = stoi(word);
getline(new_line, word, ',');
string name = word;
getline(new_line, word, ',');
string place_of_birth = word;
getline(new_line, word, ',');
string member_since = word;
getline(new_line, word, ',');
vector<string> FavoriteAuthors = splitter(word, '$');
getline(new_line, word, ',');
vector<string> FavoriteGenres = splitter(word, '$');
getline(new_line, word, ',');
vector<string> Want_to_Read = splitter(word, '$');
getline(new_line, word, ',');
vector<string> Current_Reading = splitter(word, '$');
getline(new_line, word, ',');
vector<string> Read = splitter(word, '$');
users.push_back(Users(id, name, place_of_birth, member_since, FavoriteAuthors, FavoriteGenres, Want_to_Read, Current_Reading, Read));
}
file.close();
return users;
}
vector<Authors> read_authors(string path){
vector<Authors> authors;
fstream file;
file.open(path);
string line;
string word;
getline(file, line, '\n');
while(getline(file, line, '\n'))
{
istringstream new_line(line);
getline(new_line, word, ',');
int id = stoi(word);
getline(new_line, word, ',');
string name = word;
getline(new_line, word, ',');
string gender = word;
getline(new_line, word, ',');
string member_since = word;
getline(new_line, word, ',');
int year_of_birth = stoi(word);
getline(new_line, word, ',');
string place_of_birth = word;
getline(new_line, word, ',');
vector<string> genres = splitter(word, '$');
authors.push_back(Authors(id, name, gender, member_since, year_of_birth, place_of_birth, genres));
}
file.close();
return authors;
}
vector<Books> read_books(string path){
vector<Books> books;
fstream file;
file.open(path);
string line;
string word;
getline(file, line, '\n');
int i = 0;
while(getline(file, line, '\n'))
{
istringstream new_line(line);
getline(new_line, word, ',');
int id = stoi(word);
getline(new_line, word, ',');
string title = word;
getline(new_line, word, ',');
int author_id = stoi(word);
getline(new_line, word, ',');
string genre = word;
books.push_back(Books(id, title, author_id, genre));
}
file.close();
return books;
}
vector<Reviews> read_reviews(string path){
vector<Reviews> reviews;
fstream file;
file.open(path);
string line;
string word;
getline(file, line, '\n');
while(getline(file, line, '\n'))
{
istringstream new_line(line);
getline(new_line, word, ',');
int id = stoi(word);
getline(new_line, word, ',');
int book_id = stoi(word);
getline(new_line, word, ',');
int user_id = stoi(word);
getline(new_line, word, ',');
int rating = stoi(word);
getline(new_line, word, ',');
string date = word;
getline(new_line, word, ',');
int number_of_likes = stoi(word);
reviews.push_back(Reviews(id, book_id, user_id, rating, date, number_of_likes));
}
file.close();
return reviews;
}
vector<FollowEdges> read_follow_edges(string path){
vector<FollowEdges> follow_edges;
fstream file;
file.open(path);
string line;
string word;
getline(file, line, '\n');
while(getline(file, line, '\n'))
{
istringstream new_line(line);
getline(new_line, word, ',');
int id = stoi(word);
getline(new_line, word, ',');
vector<string> followings = splitter(word, '$');
getline(new_line, word, ',');
vector<string> followers = splitter(word, '$');
follow_edges.push_back(FollowEdges(id, followings, followers));
}
file.close();
return follow_edges;
}