Statistics
| Branch: | Revision:

root / custompackages / graph-parser / src / utility.h @ 437fd680

History | View | Annotate | Download (2.47 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
namespace outops {
17
    std::ostream& operator<<(std::ostream& os, const Graph& g);
18

    
19
    // 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 VertexIndexPMap&> p);
21

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

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

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

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

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

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

    
45
    void print_v_index_std_map(const Graph& g, const VertexIndexStdMap& v_index_std_map);
46
    void print_v_index_pmap(const Graph& g, const VertexIndexPMap& v_index_pmap);
47
    void print_e_index_pmap(const Graph& g, const EdgeIndexPMap& e_index_pmap);
48
}
49

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

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

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

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

    
72
private:
73
    typename Pair::second_type value_;
74
};
75

    
76
#include "utility.tpp"
77

    
78
#endif //GRAPH_PARSER_UTILITY_H
79