Statistics
| Branch: | Revision:

root / custompackages / graph-parser / src / utility.h @ 162e1bda

History | View | Annotate | Download (3.13 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 <fstream>
11
#include <boost/graph/graph_traits.hpp>
12
#include <boost/graph/undirected_graph.hpp>
13
#include <boost/spirit/include/karma.hpp>
14
#include <boost/graph/iteration_macros.hpp>
15
#include "common.h"
16

    
17
namespace outops {
18
    std::ostream& operator<<(std::ostream& os, const Graph& g);
19

    
20
    // I have to use pair to add more than one argument for cout operator<<
21
    std::ostream& operator<<(std::ostream& os, std::pair<const Graph&, const VertexIndexPMap&> p);
22

    
23
    // For set
24
    template <typename T> std::ostream& operator<<(std::ostream& os, const std::set<T>& data);
25

    
26
    // For vector
27
    template <typename T> std::ostream& operator<<(std::ostream& os, const std::vector<T>& data);
28

    
29
    // For map
30
    template <typename T> std::ostream& operator<<(std::ostream& os, const std::map<string, T>& data);
31

    
32
    // For 2-D vector
33
    std::ostream& operator<<(std::ostream& os, const vector< vector< int> >& data);
34
}
35

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

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

    
46
    void print_edge(const Graph& g, const Edge& e);
47

    
48
    void print_v_index_std_map(const Graph& g, const VertexIndexStdMap& v_index_std_map);
49
    void print_v_index_pmap(const Graph& g, const VertexIndexPMap& v_index_pmap);
50
    void print_e_index_pmap(const Graph& g, const EdgeIndexPMap& e_index_pmap);
51

    
52
    void write_betweenness_centrality(Graph const& g, std::vector<double> v_centrality_vec, string filepath);
53
}
54

    
55
namespace setops {
56
    template <typename T> std::set<T> operator-(const std::set<T>& a, const std::set<T>& b);
57
    template <typename T> std::set<T> operator/(const std::set<T>& a, const std::set<T>& b);
58
}
59

    
60
namespace stdhelper {
61
    template <typename T1, typename T2> bool exists(const std::map<T1, T2>& m, const T1& key);
62
    template <typename T> bool exists(const std::set<T>& s, const T& element);
63

    
64
}
65

    
66
namespace helper {
67
    // I do not want to use boost::filesystem, due to additional library must be included
68
    string get_file_name(const string& s);
69
}
70

    
71
template <typename Pair>
72
struct second_equal_to
73
    : std::unary_function<const Pair&, bool>
74
{
75
    second_equal_to(const typename Pair::second_type& value)
76
        : value_(value) { }
77

    
78
    bool operator()(const Pair& p) const
79
    {
80
        // I quick-hacked to make the Pair work for second argument with built-in type, such as int.
81
        // return p.second == *value_;
82
        return p.second == value_;
83
    }
84

    
85
private:
86
    typename Pair::second_type value_;
87
};
88

    
89
template <typename T1, typename T2>
90
struct less_second {
91
    typedef pair<T1, T2> type;
92
    bool operator ()(type const& a, type const& b) const {
93
        return a.second < b.second;
94
    }
95
};
96

    
97
#include "utility.tpp"
98

    
99
#endif //GRAPH_PARSER_UTILITY_H
100