root / custompackages / graph-parser / src / utility.tpp @ 293a61eb
History | View | Annotate | Download (1.96 KB)
1 |
namespace outops |
---|---|
2 |
{ |
3 |
template <typename T> |
4 |
std::ostream& operator<<(std::ostream& os, const std::set<T>& s) |
5 |
{ |
6 |
using namespace boost::spirit::karma; |
7 |
os << format("(" << (auto_ % "\n ") << ")", s); |
8 |
os << endl; |
9 |
} |
10 |
} |
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 |
} |
23 |
namespace graphext { |
24 |
template <typename Container> |
25 |
void id_of_some_vertices(const Graph& g, const Container& container, std::set<std::string>& r) |
26 |
{ |
27 |
/* |
28 |
** Find id for a vec |
29 |
*/ |
30 |
for (typename Container::const_iterator ci = container.begin(); ci != container.end(); ++ci) { |
31 |
r.insert(g[*ci].id); |
32 |
} |
33 |
} |
34 |
} |
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 |
|