blob: 1d37083d6c31aa72f2aae9955a949e5d69f7c158 (
plain)
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
|
#ifndef PARSE_H
#define PARSE_H
#include <fstream>
#include <set>
#include <sstream>
#include <string>
#include "graph.h"
class Parser {
public:
Parser(std::string filename) : graph_(), input_file_(filename) {
std::string edge;
while (std::getline(input_file_, edge)) {
parse_edge_(edge);
}
graph_.sort_vertices();
}
const Graph & get_graph() {
return graph_;
}
private:
Graph graph_;
std::ifstream input_file_;
void parse_edge_(std::string edge) {
int from, to;
std::stringstream sstream(edge);
sstream >> from >> to;
graph_.add_edge(from, to);
}
};
#endif
|