Statistics
| Branch: | Revision:

root / custompackages / graph-parser / src / graph_manager.h @ 437fd680

History | View | Annotate | Download (2.21 KB)

1
//
2
// Created by quynh on 1/15/15.
3
//
4

    
5
#ifndef GRAPH_PARSER_GRAPH_MANAGER_H
6
#define GRAPH_PARSER_GRAPH_MANAGER_H
7

    
8
#include "common.h"
9
#include "utility.h"
10

    
11
class GraphManager {
12
public:
13
    typedef boost::vertex_bundle_type<Graph>::type VertexProperties; // aka Router in common.h
14
    typedef boost::edge_bundle_type<Graph>::type EdgeProperties; // aka Link in common.h
15
    typedef std::map<std::string, Vertex> NameVertexMap;
16

    
17
    // CONSTRUCTOR
18
    GraphManager(); // constructor
19
    GraphManager(const GraphManager& other); // copy constructor
20
    GraphManager& operator=(GraphManager& rhs); // assignment operator
21
    // check out more here: http://www.cplusplus.com/articles/y8hv0pDG/
22

    
23
    // GETTERS
24
    const VertexIndexPMap& v_index_pmap() const;
25
    const EdgeIndexPMap& e_index_pmap() const;
26
    NameToIntMap const& v_id_index_map() const;
27

    
28
    // UPDATE GRAPH
29
    void AddEdge(VertexProperties vp1, VertexProperties vp2, EdgeProperties ep);
30
    void ResetVerticesAndEdgesIndexMap();
31

    
32
    // HELPERS
33
    bool vertex_existed(string s);
34
    const Vertex& get_vertex_from_id(string s);
35
    int get_index_from_id(string s);
36

    
37

    
38
    // OUTPUTTING THE RESULT
39
    // TODO: checkout utility.h, I can't overload << operator to output
40
    // the correct result. Therefore, I use print() ufnction as a replacement.
41
    void print();
42
    void print_v_index_pmap();
43
    void print_e_index_pmap();
44
    friend std::ostream& operator<<(std::ostream& os, const GraphManager& gm);
45

    
46
    // Variables
47
    Graph g_;
48
private:
49
    void reset_v_index_pmap();
50
    void reset_v_id_vertex_map();
51
    void reset_v_id_index_map(); // must be called after reset_v_index_pmap()
52

    
53
    void reset_e_index_pmap();
54
    void update_v_index_pmap(Vertex new_vertex);
55
    void update_e_index_pmap(Edge new_edge);
56

    
57
    // VARIABLES
58
    NameVertexMap v_id_vertex_map_;
59
    NameToIntMap v_id_index_map_;
60

    
61
    // VertexIndexPMap - since we use listS instead of vecS in Graph, this one maps each vertex to an id
62
    VertexIndexStdMap v_index_std_map_;
63
    VertexIndexPMap v_index_pmap_; //
64

    
65
    // EdgeIndexPMap - boost will return the component id that each edge in the graph belongs to.
66
    EdgeIndexStdMap e_index_std_map_;
67
    EdgeIndexPMap e_index_pmap_;
68
};
69

    
70
#endif //GRAPH_PARSER_GRAPH_MANAGER_H
71