Revision cb770240 custompackages/graph-parser/src/utility.cpp

View differences:

custompackages/graph-parser/src/utility.cpp
28 28
    }
29 29
}
30 30

  
31
/* outops namespace */
31 32
namespace outops {
32 33
    std::ostream& operator<<(std::ostream& os, const Graph& g)
33 34
    {
34

  
35 35
        os <<   "Graph has: \n"
36 36
                "---------- " << boost::num_vertices(g) << " vertices\n"
37 37
                "---------- " << boost::num_edges(g) << " edges\n";
......
60 60
        return os;
61 61
    }
62 62

  
63
    // std::ostream& operator<<(std::ostream& os, const std::set<std::string>& s) {
64
    //      can't make it work with a generic function
65
    //     ** std::ostream& opeartor<<(std::ostream& os, const Container<std::string>& s)
63
    std::ostream& operator<<(std::ostream& os, std::pair<const Graph&, const VertexIndexMap&> p) {
64
        // ERROR: wrong output.
65
        // I think it's because of copy constructor.
66
        // Check out shell_output/w14
67

  
68
        // Calling example:
69
        // outops::operator<<(cout, std::pair<const Graph&, const VertexIndexMap&>(g_, v_index_map_));
70
        Graph g = p.first;
71
        VertexIndexMap v_index_map = p.second;
72

  
73
        std::list<std::string> outputs;
74
        BGL_FORALL_VERTICES_T(v, g, Graph) {
75
            int index = boost::get(v_index_map, v);
76
            cout << g[v].id << ": " << v << endl;
77
            string vertex_id = g[v].id;
78
            outputs.push_back(vertex_id + ": " + std::to_string(index));
79
        }
66 80

  
67
    //     using namespace boost::spirit::karma;
68
    //     os << format("(" << (auto_ % "\n  ") << ")", s);
69
    //     os << endl;
70
    // }
81
        using namespace boost::spirit::karma;
82
        os << "Vertex Index Map:\n";
83
        os << "[\n";
84
        os << format("  " << (auto_ % "\n  ") << "]\n", outputs);
85

  
86
        return os;
87
    }
88

  
89
    std::ostream& operator<<(std::ostream& os, const std::map<string, int>& m)
90
    {
91
        // similar to printhelper::for_map()
92
        os << "cout << std::map\n";
93
        std::map<string, int>::const_iterator iter;
94
        for (iter = m.begin(); iter != m.end(); ++iter) {
95
            os << (*iter).first << ": " << (*iter).second << endl;
96
        }
97
        os << endl;
98

  
99
        return os;
100
    }
101

  
102
    std::ostream& operator<<(std::ostream& os, const vector< vector< int> >& data) {
103
        cout << "cout << vector<vector<int> >\n";
104
        int row_size = data.size();
105
        int col_size = 0;
106
        if (row_size > 0) {
107
            col_size = data[0].size();
108
        }
109
        for (int i = 0; i < row_size; ++i) {
110
            for (int j = 0; j < col_size; ++j) {
111
                os << data[i][j] << " ";
112
            }
113
            os << endl;
114
        }
115
        return os;
116
    }
71 117
}
72 118

  
119
/* graphext namespace */
73 120
namespace graphext {
74
    void id_of_vertices(const Graph& g, std::set<std::string>& r) {
121
    void id_of_all_vertices(const Graph& g, std::set<std::string>& r) {
75 122
        BGL_FORALL_VERTICES_T(v, g, Graph) {
76 123
            r.insert(g[v].id);
77 124
        }
78 125
    }
126

  
127
    void print_v_index_std_map(const Graph& g, const VertexIndexStdMap& v_index_std_map) {
128
        std::list<std::string> outputs;
129

  
130
        VertexIndexStdMap::const_iterator iter;
131
        for (iter = v_index_std_map.begin(); iter != v_index_std_map.end(); ++iter) {
132
            outputs.push_back(std::to_string(iter->second));
133
            // outputs.push_back(std::to_string(&(iter->first)) + ": " + std::to_string(iter->second));
134
        }
135

  
136
        using namespace boost::spirit::karma;
137
        cout << "Vertex Index Std Map:\n";
138
        cout << format("[\n  " << (auto_ % "\n  ") << "\n]\n", outputs);
139
    }
140

  
141
    void print_v_index_map(const Graph& g, const VertexIndexMap& v_index_map) {
142
        cout << "Vertex Index Map:\n";
143

  
144
        std::list<std::string> outputs;
145
        BGL_FORALL_VERTICES_T(v, g, Graph) {
146
            int index = boost::get(v_index_map, v);
147
            std::string vertex_id = g[v].id;
148
            cout << v << endl;
149
            outputs.push_back(vertex_id + ": " + std::to_string(index));
150
        }
151

  
152
        using namespace boost::spirit::karma;
153
        cout << format("[\n  " << (auto_ % "\n  ") << "\n]\n", outputs);
154
    }
79 155
}

Also available in: Unified diff