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

View differences:

custompackages/graph-parser/src/utility.tpp
1
namespace outops {
1
namespace outops
2
{
2 3
    template <typename T>
3
    std::ostream& operator<<(std::ostream& os, const std::set<T>& s) {
4
    std::ostream& operator<<(std::ostream& os, const std::set<T>& s)
5
    {
4 6
        using namespace boost::spirit::karma;
5 7
        os << format("(" << (auto_ % "\n  ") << ")", s);
6 8
        os << endl;
7 9
    }
8 10
}
9 11

  
12
namespace printhelper {
13
    template <typename T1, typename T2>
14
    void for_map(const std::map<T1, T2> m) {
15
        // similar to cout<< in namespace outops
16
        cout << "printhelper - for_map\n";
17
        typename std::map<T1, T2>::const_iterator iter;
18
        for (iter = m.begin(); iter != m.end(); ++iter) {
19
            cout << (*iter).first << ": " << (*iter).second;
20
        }
21
    }
22
}
10 23
namespace graphext {
11 24
    template <typename Container>
12
    void id_of_vertices(const Graph& g, const Container& container, std::set<std::string>& r) {
25
    void id_of_some_vertices(const Graph& g, const Container& container, std::set<std::string>& r)
26
    {
13 27
        /*
14 28
        ** Find id for a vec
15 29
        */
......
19 33
    }
20 34
}
21 35

  
36
namespace setops {
37
    // From http://stackoverflow.com/questions/8175933/to-compare-two-boost-graph-having-same-vertices
38
    template <typename T> std::set<T> operator-(const std::set<T>& a, const std::set<T>& b)
39
    {
40
        std::set<T> r;
41
        std::set_difference(
42
                a.begin(), a.end(),
43
                b.begin(), b.end(),
44
                std::inserter(r, r.end()));
45

  
46
        return r;
47
    }
48

  
49
    template <typename T> std::set<T> operator/(const std::set<T>& a, const std::set<T>& b)
50
    {
51
        std::set<T> r;
52
        std::set_intersection(
53
                a.begin(), a.end(),
54
                b.begin(), b.end(),
55
                std::inserter(r, r.end()));
56

  
57
        return r;
58
    }
59
}
60

  
61
namespace stdhelper {
62
    template <typename T1, typename T2>
63
    bool exists(const std::map<T1, T2>& c, const T1& key) {
64
        return (c.count(key) > 0);
65
    }
66

  
67
    template <typename T>
68
    bool exists(const std::set<T>& c, const T& key) {
69
        return (c.count(key) > 0);
70
    }
71
}
72

  

Also available in: Unified diff