C++ Boost


Header <boost/python/def_visitor.hpp>


Class def_visitor
Class def_visitor synopsis
Class def_visitor requirements


<boost/python/def_visitor.hpp> provides a generic visitation interface through which the class_ def member functionality can be extended non-intrusively to avoid cluttering the class_ interface. It declares the def_visitor<T> class template, which is parameterized on the derived type DerivedVisitor, which provides the actual def functionality through its visit member functions.

<boost/python/def_visitor.hpp>̡驁˒븶ͨӃ儷Iʽӿڣ썊 ͨ齸yӿڣ쿉Ҕ燇ֈ됔嘀久 class_ def㉔ᵄ餛ܣ썊 ҔᜃⅪ’class_퓿ڡ㠍 ˼ɹ÷Kdef_visitor<T> ģॣ썊 Ƥ⎊튇ʼnɺ ЍDerivedVisitor㬍 胲Ί퍨齆伢>visit㉔ắʽ ̡驊弊儼b>def餛ܡ㍊


Class template def_visitor<DerivedVisitor>

The class def_visitor is a base class paramaterized by its derived class. The def_visitor class is a protocol class. Its derived class, DerivedVisitor, is expected to have a member function visit. The def_visitor class is never instantiated directly. Instead, an instance of its subclass, DerivedVisitor,  is passed on as an argument to the class_ def member function.

def_visitor ʇ趒Ԇ䅉ɺ ΪģॲΊ빀ࡣ def_visitor ʇ趐풩 ᣍ ˼儅ɉꀠDerivedVisitor㬒ꇳɔắʽvisitᣍ def_visitor ⻻ᖱ퓊啥믡㍊淵Nj쵄ד DerivedVisitor儊啥Ỵ뵝踍 class_ def ㉔ắʽ儲Ί

Class def_visitor synopsis

namespace boost { namespace python {

    template <class DerivedVisitor>
    class def_visitor {};

def_visitor requirements

The client supplied class DerivedVisitor template parameter is expected to:

玀駔Ā͊DerivedVisitor 億㰥⎊풪dzΪ㺠



Return Type






visitor.visit(cls) void cls is an instance of a class_  being wrapped to Python. visitor is a def_visitor derived class.

clsʇ佷◰ython儼a href="class.html">class_儊啥ᣍ visitorʇdef_visitor儅ɉꀠᣍ

A call to cls.def(visitor) forwards to this member function.


visitor.visit(cls, name, options) void cls is a class_ instance, name is a C string. visitor is a def_visitor derived class. options is a context specific optional argument.

clsʇ趣lass_ʵ=㬆䃻זʇ趃ז維 visitorʇdef_visitor儅ɉꀠᣍ optionsʇӫɏς΄Ϡ陣Ŀɑ᲎ʽᣍ

A call to cls.def(name, visitor) or cls.def(name, visitor, options) forwards to this member function.

ϲ胳ɔắʽת磌ģls.def(name, visitor)벣ls.def(name, visitor, options)巔a㍊


class X {/*...*/};
class my_def_visitor : boost::python::def_visitor<my_def_visitor> { friend class def_visitor_access; template <class classT> void visit(classT& c) const { c .def("foo", &my_def_visitor::foo) .def("bar", &my_def_visitor::bar) ; } static void foo(X& self); static void bar(X& self); }; BOOST_PYTHON_MODULE(my_ext) { class_<X>("X") .def(my_def_visitor()) ; }

Revised 27 August, 2003

© Copyright Joel de Guzman 2003. Distributed under 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)