IMP
2.0.1
The Integrative Modeling Platform
Main Page
Related Pages
Modules
Namespaces
Classes
Files
Examples
File List
File Members
graph_macros.h
Go to the documentation of this file.
1
/**
2
* \file IMP/base/graph_macros.h
3
* \brief Various general useful macros for IMP.
4
*
5
* Copyright 2007-2013 IMP Inventors. All rights reserved.
6
*
7
*/
8
9
#ifndef IMPBASE_GRAPH_MACROS_H
10
#define IMPBASE_GRAPH_MACROS_H
11
#include <IMP/base/base_config.h>
12
#include <boost/graph/adjacency_list.hpp>
13
#include <
IMP/base/map.h
>
14
#include <boost/version.hpp>
15
16
#if defined(IMP_DOXYGEN)
17
//! Define a graph object in \imp
18
/** The docs for the graph should appear before the macro
19
invocation. Directionality should be one of
20
- \c bidirectional
21
- \c directed
22
- \c undirected
23
*/
24
#define IMP_GRAPH(Name, directionality, VertexData, EdgeData) \
25
/** See \ref graphs "Graphs in IMP" for more information.*/
\
26
typedef boost::graph Name; \
27
typedef Name::VertexNameMap Name##ConstVertexName; \
28
typedef Name::EdgeNameMap Name##ConstEdgeName; \
29
typedef boost::graph_traits<Name> Name##Traits; \
30
typedef Name::vertex_descriptor Name##Vertex; \
31
typedef Name::edge_descriptor Name##Edge; \
32
class Name##VertexIndex{}; \
33
Name##VertexIndex get_vertex_index(const Name &g)
34
35
#elif defined(SWIG)
36
#if defined(__GNUC__) && __GNUC__ == 4 && __GNUC_MINOR__ == 2 \
37
&& BOOST_VERSION <= 104800
38
#define IMP_GRAPH(Name, directionality, VertexData, EdgeData) \
39
class Name; \
40
class Name##VertexIndex {}
41
42
#else // GCC VERSION
43
#define IMP_GRAPH(Name, directionality, VertexData, EdgeData) \
44
class Name; \
45
class Name##VertexIndex {}; \
46
inline Name##VertexIndex get_vertex_index(const Name &g)
47
#endif // GCC VERSION
48
49
#else // swig and doxygen
50
51
// Some combinations of gcc/boost fail to compile Python wrappers for
52
// get_vertex_index ("no match for 'operator=' error); fall back to
53
// std::map in this case
54
#if defined(__GNUC__) && __GNUC__ == 4 \
55
&& __GNUC_MINOR__ == 7 && BOOST_VERSION == 104800
56
#define IMP_GRAPH_MAP_TYPE std::map
57
#else
58
#define IMP_GRAPH_MAP_TYPE base::map
59
#endif
60
61
#define IMP_GRAPH(Name, directionality, VertexData, EdgeData) \
62
typedef boost::adjacency_list<boost::vecS, boost::vecS, \
63
boost::directionality##S, \
64
boost::property<boost::vertex_name_t, VertexData>, \
65
boost::property<boost::edge_name_t, \
66
EdgeData> > Name; \
67
typedef boost::property_map<Name, boost::vertex_name_t>::const_type \
68
Name##ConstVertexName; \
69
typedef boost::property_map<Name, boost::edge_name_t>::const_type \
70
Name##ConstEdgeName; \
71
typedef boost::graph_traits<Name> Name##Traits; \
72
typedef Name##Traits::vertex_descriptor Name##Vertex; \
73
typedef Name##Traits::edge_descriptor Name##Edge; \
74
typedef IMP_GRAPH_MAP_TYPE<VertexData, Name##Vertex> Name##VertexIndex; \
75
inline Name##VertexIndex get_vertex_index(const Name &g) { \
76
Name##ConstVertexName vm = boost::get(boost::vertex_name, g); \
77
std::pair<Name##Traits::vertex_iterator, Name##Traits::vertex_iterator> \
78
be= boost::vertices(g); \
79
Name##VertexIndex ret; \
80
for (; be.first != be.second; ++be.first) { \
81
ret[vm[*be.first]]= *be.first; \
82
} \
83
return ret; \
84
} \
85
typedef boost::property_map<Name, boost::edge_name_t>::type \
86
Name##EdgeName; \
87
typedef boost::property_map<Name, boost::vertex_name_t>::type \
88
Name##VertexName
89
#endif // swig and doxygen
90
91
92
#ifdef IMP_DOXYGEN
93
//! Define a graph object in \imp
94
/** The docs for the graph should appear before the macro
95
invocation. Directionality should be one of
96
- \c bidirectional
97
- \c directed
98
- \c undirected
99
*/
100
#define IMP_WEIGHTED_GRAPH(Name, directionality, VertexData) \
101
/** See \ref graphs "Graphs" for more information.*/
\
102
typedef boost::graph Name
103
104
#elif defined(SWIG)
105
#define IMP_WEIGHTED_GRAPH(Name, directionality, VertexData) class Name
106
#else
107
#define IMP_WEIGHTED_GRAPH(Name, directionality, VertexData) \
108
typedef boost::adjacency_list<boost::vecS, boost::vecS, \
109
boost::directionality##S, \
110
boost::property<boost::vertex_name_t, VertexData>, \
111
boost::property<boost::edge_weight_t, \
112
double> > Name; \
113
typedef boost::property_map<Name, boost::vertex_name_t>::const_type \
114
Name##ConstVertexName; \
115
typedef boost::property_map<Name, boost::edge_weight_t>::const_type \
116
Name##ConstEdgeWeight; \
117
typedef boost::graph_traits<Name> Name##Traits; \
118
typedef Name##Traits::vertex_descriptor Name##Vertex; \
119
typedef Name##Traits::edge_descriptor Name##Edge; \
120
typedef base::map<VertexData, Name##Vertex> Name##VertexIndex; \
121
inline Name##VertexIndex get_vertex_index(const Name &g) { \
122
Name##ConstVertexName vm = boost::get(boost::vertex_name, g); \
123
std::pair<Name##Traits::vertex_iterator, Name##Traits::vertex_iterator> \
124
be= boost::vertices(g); \
125
Name##VertexIndex ret; \
126
for (; be.first != be.second; ++be.first) { \
127
ret[vm[*be.first]]= *be.first; \
128
} \
129
return ret; \
130
} \
131
typedef boost::property_map<Name, boost::edge_weight_t>::type \
132
Name##EdgeWeight; \
133
typedef boost::property_map<Name, boost::vertex_name_t>::type \
134
Name##VertexName
135
#endif
136
137
138
#endif
/* IMPBASE_GRAPH_MACROS_H */