mirror of
https://github.com/boostorg/graph.git
synced 2026-01-29 19:42:11 +00:00
69 lines
2.5 KiB
C++
69 lines
2.5 KiB
C++
template<typename Graph>
|
|
class BGL_PYTHON_VISITOR
|
|
{
|
|
class wrap
|
|
: public BGL_PYTHON_VISITOR<Graph>,
|
|
public boost::python::wrapper<BGL_PYTHON_VISITOR<Graph> >
|
|
{
|
|
public:
|
|
typedef typename BGL_PYTHON_VISITOR<Graph>::vertex_descriptor vertex_descriptor;
|
|
typedef typename BGL_PYTHON_VISITOR<Graph>::edge_descriptor edge_descriptor;
|
|
|
|
#define BGL_PYTHON_EVENT(Name,Descriptor) \
|
|
void Name(Descriptor x, const Graph& g) const \
|
|
{ \
|
|
if (override f = this->get_override(#Name)) \
|
|
f(x, boost::cref(g)); \
|
|
else BGL_PYTHON_VISITOR<Graph>::Name(x, g); \
|
|
} \
|
|
\
|
|
void default_##Name(Descriptor x, const Graph& g) const \
|
|
{ this->BGL_PYTHON_VISITOR<Graph>::Name(x, g); }
|
|
# include BGL_PYTHON_EVENTS_HEADER
|
|
#undef BGL_PYTHON_EVENT
|
|
};
|
|
|
|
public:
|
|
class default_arg : public BGL_PYTHON_VISITOR<Graph> { };
|
|
|
|
struct ref
|
|
{
|
|
typedef typename graph_traits<Graph>::vertex_descriptor vertex_descriptor;
|
|
typedef typename graph_traits<Graph>::edge_descriptor edge_descriptor;
|
|
|
|
ref(const BGL_PYTHON_VISITOR<Graph>& v) : v(v) { }
|
|
|
|
#define BGL_PYTHON_EVENT(Name, Descriptor) \
|
|
void Name(Descriptor x, const Graph& g) const { v.Name(x, g); }
|
|
# include BGL_PYTHON_EVENTS_HEADER
|
|
#undef BGL_PYTHON_EVENT
|
|
|
|
private:
|
|
const BGL_PYTHON_VISITOR<Graph>& v;
|
|
};
|
|
|
|
typedef typename graph_traits<Graph>::vertex_descriptor vertex_descriptor;
|
|
typedef typename graph_traits<Graph>::edge_descriptor edge_descriptor;
|
|
|
|
virtual ~BGL_PYTHON_VISITOR() {}
|
|
|
|
#define BGL_PYTHON_EVENT(Name, Descriptor) \
|
|
virtual void Name(Descriptor x, const Graph& g) const {}
|
|
# include BGL_PYTHON_EVENTS_HEADER
|
|
#undef BGL_PYTHON_EVENTS
|
|
|
|
static void declare(const char* name, const char* default_name)
|
|
{
|
|
#define BGL_PYTHON_EVENT(Name, Descriptor) \
|
|
.def(#Name, &BGL_PYTHON_VISITOR<Graph>::Name, &wrap::default_##Name)
|
|
class_<wrap, boost::noncopyable>(name)
|
|
# include BGL_PYTHON_EVENTS_HEADER
|
|
#undef BGL_PYTHON_EVENT
|
|
;
|
|
|
|
class_<default_arg, bases<BGL_PYTHON_VISITOR<Graph> > >(default_name,
|
|
no_init);
|
|
}
|
|
};
|
|
|