m-chrzan.xyz
aboutsummaryrefslogtreecommitdiff
path: root/src/parse.h
blob: 31fa7c6151cedc873e441cd6f3177c11bb6e4f47 (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
36
37
#ifndef PARSE_H
#define PARSE_H

#include <fstream>
#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) {
        std::stringstream sstream(edge);

        int from, to;
        sstream >> from >> to;

        graph_.add_edge(from, to);
    }
};

#endif