blob: cb6e3c6debd0e330648642c2d1136eb8da133c2c (
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
|
#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);
}
}
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
|