// Copyright 2005 The Trustees of Indiana University. // Use, modification and distribution is subject to the Boost Software // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) // Authors: Douglas Gregor // Andrew Lumsdaine template class BGL_PYTHON_VISITOR { class wrap : public BGL_PYTHON_VISITOR, public boost::python::wrapper > { public: typedef typename BGL_PYTHON_VISITOR::vertex_descriptor vertex_descriptor; typedef typename BGL_PYTHON_VISITOR::edge_descriptor edge_descriptor; #define BGL_PYTHON_EVENT(Name,Descriptor) \ void Name(Descriptor x, const Graph& g) const \ { \ if (boost::python::override f = this->get_override(#Name)) \ f(x, boost::cref(g)); \ else BGL_PYTHON_VISITOR::Name(x, g); \ } \ \ void default_##Name(Descriptor x, const Graph& g) const \ { this->BGL_PYTHON_VISITOR::Name(x, g); } # include BGL_PYTHON_EVENTS_HEADER #undef BGL_PYTHON_EVENT }; public: class default_arg : public BGL_PYTHON_VISITOR { }; struct ref { typedef typename graph_traits::vertex_descriptor vertex_descriptor; typedef typename graph_traits::edge_descriptor edge_descriptor; ref(const BGL_PYTHON_VISITOR& 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& v; }; typedef typename graph_traits::vertex_descriptor vertex_descriptor; typedef typename graph_traits::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) { using boost::python::class_; using boost::python::bases; using boost::python::no_init; using boost::python::objects::registered_class_object; using boost::python::type_id; if (registered_class_object(type_id()).get() != 0) return; #define BGL_PYTHON_EVENT(Name, Descriptor) \ .def(#Name, &BGL_PYTHON_VISITOR::Name, &wrap::default_##Name) class_(name) # include BGL_PYTHON_EVENTS_HEADER #undef BGL_PYTHON_EVENT ; class_ > >(default_name, no_init); } };