Statistics
| Branch: | Revision:

root / custompackages / graph-parser / src / utility.h @ 20756421

History | View | Annotate | Download (2.23 KB)

1 6a12e353 Quynh PX Nguyen
//
2
// Created by quynh on 12/15/15.
3 cb770240 Quynh PX Nguyen
// All the generic functions are defined in utility.tpp - 27/01/2015
4 6a12e353 Quynh PX Nguyen
//
5
6
#ifndef GRAPH_PARSER_UTILITY_H
7
#define GRAPH_PARSER_UTILITY_H
8
9
#include <iostream>
10
#include <boost/graph/graph_traits.hpp>
11
#include <boost/graph/undirected_graph.hpp>
12 ee0dd796 Quynh PX Nguyen
#include <boost/spirit/include/karma.hpp>
13
#include <boost/graph/iteration_macros.hpp>
14 6a12e353 Quynh PX Nguyen
#include "common.h"
15
16 ee0dd796 Quynh PX Nguyen
namespace outops {
17
    std::ostream& operator<<(std::ostream& os, const Graph& g);
18
19 cb770240 Quynh PX Nguyen
    // I have to use pair to add more than one argument for cout operator<<
20
    std::ostream& operator<<(std::ostream& os, std::pair<const Graph&, const VertexIndexMap&> p);
21
22
    template <typename T> // declared in utitlity.tpp
23 ee0dd796 Quynh PX Nguyen
    std::ostream& operator<<(std::ostream& os, const std::set<T>& s);
24 cb770240 Quynh PX Nguyen
25
    std::ostream& operator<<(std::ostream& os, const std::map<string, int>& m);
26
27
    std::ostream& operator<<(std::ostream& os, const vector< vector< int> >& data);
28 ee0dd796 Quynh PX Nguyen
}
29
30 cb770240 Quynh PX Nguyen
namespace printhelper {
31
    template <typename T1, typename T2> void for_map(const std::map<T1, T2> m);
32
}
33 ee0dd796 Quynh PX Nguyen
// non-member functions operating on Graph datatype.
34
namespace graphext {
35 cb770240 Quynh PX Nguyen
    void id_of_all_vertices(const Graph& g, std::set<std::string>& r);
36 ee0dd796 Quynh PX Nguyen
37 efed924d Quynh PX Nguyen
    template <typename Container>
38 cb770240 Quynh PX Nguyen
    void id_of_some_vertices(const Graph& g, const Container& container, std::set<std::string>& r);
39
40
    void print_v_index_std_map(const Graph& g, const VertexIndexStdMap& v_index_std_map);
41
    void print_v_index_map(const Graph& g, const VertexIndexMap& v_index_map);
42 ee0dd796 Quynh PX Nguyen
}
43 efed924d Quynh PX Nguyen
44 cb770240 Quynh PX Nguyen
namespace setops {
45
    template <typename T> std::set<T> operator-(const std::set<T>& a, const std::set<T>& b);
46
    template <typename T> std::set<T> operator/(const std::set<T>& a, const std::set<T>& b);
47
}
48
49
namespace stdhelper {
50
    template <typename T1, typename T2> bool exists(const std::map<T1, T2>& m, const T1& key);
51
    template <typename T> bool exists(const std::set<T>& s, const T& element);
52
}
53
54
template <typename Pair>
55
struct second_equal_to
56
    : std::unary_function<const Pair&, bool>
57
{
58
    second_equal_to(const typename Pair::second_type& value)
59
        : value_(value) { }
60
61
    bool operator()(const Pair& p) const
62
    {
63
        return p.second == value_;
64
    }
65 efed924d Quynh PX Nguyen
66 cb770240 Quynh PX Nguyen
private:
67
    typename Pair::second_type value_;
68
};
69 efed924d Quynh PX Nguyen
70
#include "utility.tpp"
71
72 6a12e353 Quynh PX Nguyen
#endif //GRAPH_PARSER_UTILITY_H