m-chrzan.xyz
aboutsummaryrefslogtreecommitdiff
path: root/src/parse.h
blob: 52b8520802873afbc5b18205df11302c2a30a4e8 (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
38
39
#ifndef PARSE_H
#define PARSE_H

#include <fstream>
#include <set>
#include "graph.h"

class Parser {
public:
    Parser(std::string filename) : graph_(), input_file_(filename) {
        parse_number_edges_();

        for (int i = 0; i < number_edges_; i++) {
            parse_edge_();
        }
    }

    const Graph & get_graph() {
        return graph_;
    }
private:
    Graph graph_;
    std::ifstream input_file_;
    int number_edges_;

    void parse_number_edges_() {
        input_file_ >> number_edges_;
    }

    void parse_edge_() {
        int from, to;

        input_file_ >> from >> to;

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

#endif