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

View differences:

custompackages/graph-parser/src/utility.cpp
3 3
//
4 4

  
5 5
#include "utility.h"
6

  
6
using namespace boost;
7 7

  
8 8
void printGraph(Graph &g) {
9 9
    typename boost::graph_traits<Graph>::out_edge_iterator out_i, out_ie;
......
26 26
        }
27 27
        cout << endl;
28 28
    }
29
}
30

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

  
35
        os <<   "Graph has: \n"
36
                "---------- " << boost::num_vertices(g) << " vertices\n"
37
                "---------- " << boost::num_edges(g) << " edges\n";
38

  
39
        std::set<std::string> verticesSet;
40
        BGL_FORALL_VERTICES_T(v, g, Graph) verticesSet.insert(g[v].id);
41

  
42
        std::vector<std::string> edgesVec;
43
        std::vector<double> costsVec;
44
        BGL_FORALL_EDGES_T(e, g, Graph) {
45
            std::string s = "(" + g[e.m_source].id + ", " + g[e.m_target].id + ") - " + std::to_string(g[e].cost);
46
            edgesVec.push_back(s);
47
            costsVec.push_back(g[e].cost);
48
        }
49

  
50
        using namespace boost::spirit::karma;
51
        os <<   "Vertices:\n"
52
                "  ";
53
        os << format("(" << auto_ % ", " << ") ", verticesSet);
54
        os << "\n";
55

  
56
        os <<   "Edges:\n";
57
        os << format("  " << (auto_ % "\n  ") << eol, edgesVec);
58
        os << "\n";
59

  
60
        return os;
61
    }
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)
66
        */
67
        using namespace boost::spirit::karma;
68
        os << format("( " << (auto_ % "\n  ") << ")", s);
69
    }
70

  
71
}
72

  
73
namespace outopserror {
74
    template <typename T>
75
    std::ostream& operator<<(std::ostream& os, const std::set<T>& s) {
76
        /* can't make it work with a generic function
77
        ** std::ostream& opeartor<<(std::ostream& os, const Container<std::string>& s)
78
        */
79
        using namespace boost::spirit::karma;
80
        os << format("( " << (auto_ % "\n  ") << ")", s);
81
    }
82
}
83

  
84
namespace graphext {
85
    void id_of_vertices(const Graph& g, std::set<std::string>& r) {
86
        BGL_FORALL_VERTICES_T(v, g, Graph) {
87
            r.insert(g[v].id);
88
        }
89
    }
90

  
91
    // template <typename Container>
92
    // void id_of_vertices(const Graph& g, const Container& container, std::set<std::string>& r) {
93
    void id_of_vertices(const Graph& g, const VertexVec& container, std::set<std::string>& r) {
94
        /*
95
        ** Find id for a vec
96
        */
97
        for (VertexVec::const_iterator ci = container.begin(); ci != container.end(); ++ci) {
98
            r.insert(g[*ci].id);
99
        }
100
    }
29 101
}

Also available in: Unified diff