Statistics
| Branch: | Revision:

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

History | View | Annotate | Download (2.26 KB)

1
//
2
// Created by quynh on 12/15/15.
3
// All the generic functions are defined in utility.tpp - 27/01/2015
4
//
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
#include <boost/spirit/include/karma.hpp>
13
#include <boost/graph/iteration_macros.hpp>
14
#include "common.h"
15

    
16

    
17

    
18
void printGraph(Graph &g);
19

    
20
namespace outops {
21
    std::ostream& operator<<(std::ostream& os, const Graph& g);
22

    
23
    // I have to use pair to add more than one argument for cout operator<<
24
    std::ostream& operator<<(std::ostream& os, std::pair<const Graph&, const VertexIndexMap&> p);
25

    
26
    template <typename T> // declared in utitlity.tpp
27
    std::ostream& operator<<(std::ostream& os, const std::set<T>& s);
28

    
29
    std::ostream& operator<<(std::ostream& os, const std::map<string, int>& m);
30

    
31
    std::ostream& operator<<(std::ostream& os, const vector< vector< int> >& data);
32
}
33

    
34
namespace printhelper {
35
    template <typename T1, typename T2> void for_map(const std::map<T1, T2> m);
36
}
37
// non-member functions operating on Graph datatype.
38
namespace graphext {
39
    void id_of_all_vertices(const Graph& g, std::set<std::string>& r);
40

    
41
    template <typename Container>
42
    void id_of_some_vertices(const Graph& g, const Container& container, std::set<std::string>& r);
43

    
44
    void print_v_index_std_map(const Graph& g, const VertexIndexStdMap& v_index_std_map);
45
    void print_v_index_map(const Graph& g, const VertexIndexMap& v_index_map);
46
}
47

    
48
namespace setops {
49
    template <typename T> std::set<T> operator-(const std::set<T>& a, const std::set<T>& b);
50
    template <typename T> std::set<T> operator/(const std::set<T>& a, const std::set<T>& b);
51
}
52

    
53
namespace stdhelper {
54
    template <typename T1, typename T2> bool exists(const std::map<T1, T2>& m, const T1& key);
55
    template <typename T> bool exists(const std::set<T>& s, const T& element);
56
}
57

    
58
template <typename Pair>
59
struct second_equal_to
60
    : std::unary_function<const Pair&, bool>
61
{
62
    second_equal_to(const typename Pair::second_type& value)
63
        : value_(value) { }
64

    
65
    bool operator()(const Pair& p) const
66
    {
67
        return p.second == value_;
68
    }
69

    
70
private:
71
    typename Pair::second_type value_;
72
};
73

    
74
#include "utility.tpp"
75

    
76
#endif //GRAPH_PARSER_UTILITY_H
77