Statistics
| Branch: | Revision:

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

History | View | Annotate | Download (2.23 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 VertexIndexMap&> p);
21

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

    
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
}
29

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

    
37
    template <typename Container>
38
    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
}
43

    
44
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

    
66
private:
67
    typename Pair::second_type value_;
68
};
69

    
70
#include "utility.tpp"
71

    
72
#endif //GRAPH_PARSER_UTILITY_H
73