-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathClient.cpp
More file actions
67 lines (56 loc) · 1.89 KB
/
Copy pathClient.cpp
File metadata and controls
67 lines (56 loc) · 1.89 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
#include "Client.h"
#include <iostream>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <fstream>
#include <vector>
#include <sstream> // std::stringstream
#include "Instrument.h"
unordered_map<string, Client> Client::clientMap;
Client::Client() {};
Client::Client(string id, unordered_set<string> currencies, bool positionCheck, int rating) {
this->id = id;
this->currencies = currencies;
this->positionCheck = positionCheck;
this->rating = rating;
}
void Client::readcsv(string filename) {
ifstream File(filename);
if(!File.is_open()) throw runtime_error("Could not open file");
string row;
getline(File, row);
while (getline(File, row)) {
stringstream ss(row);
string word;
vector<string> commaSepValues;
while (getline(ss, word, ',')) {
commaSepValues.push_back(word);
}
string readID;
bool readPosCheck;
int readRating;
unordered_set<string> currencies = {};
readID = commaSepValues[0];
readPosCheck = (commaSepValues[commaSepValues.size() - 2] == "Y") ? true : false;
readRating = stoi(commaSepValues[commaSepValues.size() - 1]);
for (int i = 1; i <= commaSepValues.size() - 3; i++) {
string curStr = commaSepValues[i];
if (curStr[0] == '"') {
currencies.insert(curStr.substr(1, curStr.length() - 1));
} else if (curStr[curStr.length() - 1] == '"') {
currencies.insert(curStr.substr(0, curStr.length() - 1));
} else {
currencies.insert(curStr);
}
}
Client newClient = Client(readID, currencies, readPosCheck, readRating);
Client::clientMap.insert(make_pair(readID, newClient));
};
File.close();
}
void Client::printMap() {
for (auto p : Client::clientMap) {
cout << p.first << " " << p.second.id << " " << p.second.positionCheck << " " << p.second.rating << endl;
}
}