-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathReader.cpp
49 lines (37 loc) · 862 Bytes
/
Reader.cpp
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
#include "Reader.h"
Reader::Reader() {
_id= 0;
_name = "";
}
Reader::Reader(unsigned int id) : _id(id), _name() {
}
unsigned int Reader::get_id() const {
return _id;
}
std::string Reader::get_name() const {
return _name;
}
Reader *Reader::from_raw_string(std::string line) {
unsigned int id;
std::string name;
if(line.empty()) {
return nullptr;
}
// _id
size_t idx = line.find('|');
if(idx == std::string::npos) {
std::cerr << "from_raw_string() failed!" << std::endl;
return nullptr;
}
id = std::atoi(line.substr(0, idx).c_str());
line.erase(0, idx+1);
// name
name = line;
Reader *result = new Reader();
result->_id = id;
result->_name = name;
return result;
}
void Reader::println() const {
std::cout << _id << " " << _name << std::endl;
}