File: def_visitor.qbk

package info (click to toggle)
boost1.83 1.83.0-5
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 545,632 kB
  • sloc: cpp: 3,857,086; xml: 125,552; ansic: 34,414; python: 25,887; asm: 5,276; sh: 4,799; ada: 1,681; makefile: 1,629; perl: 1,212; pascal: 1,139; sql: 810; yacc: 478; ruby: 102; lisp: 24; csh: 6
file content (58 lines) | stat: -rw-r--r-- 2,741 bytes parent folder | download | duplicates (10)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
[section boost/python/def_visitor.hpp]
[section Introduction]
<boost/python/def_visitor.hpp> provides a generic visitation interface through which the [link high_level_components.boost_python_class_hpp.class_template_class_t_bases_hel class_] def member functionality can be extended non-intrusively to avoid cluttering the [link high_level_components.boost_python_class_hpp.class_template_class_t_bases_hel 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. 
[endsect]
[section Class `def_visitor`]
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 [link high_level_components.boost_python_class_hpp.class_template_class_t_bases_hel class_] `def` member function.

``
namespace boost { namespace python {

    template <class DerivedVisitor>
    class def_visitor {};
}
``

[variablelist
 [[Requires][The client supplied class DerivedVisitor template parameter is expected to: 
 * be privately derived from def_visitor
 * grant friend access to class def_visitor_access
 * define either or both visit member functions listed in the table below:
   [table
   [[Expression][Return Type][Requirements][Effects]]
   [[`visitor.visit(cls)`][`void`]
    [`cls` is an instance of a [link high_level_components.boost_python_class_hpp.class_template_class_t_bases_hel class_]  being wrapped to Python. `visitor` is a `def_visitor` derived class.]
    [A call to `cls.def(visitor)` forwards to this member function.]]
   [[`visitor.visit(cls, name, options)`][`void`]
    [`cls` is a [link high_level_components.boost_python_class_hpp.class_template_class_t_bases_hel class_] instance, name is a C string. `visitor` is a `def_visitor` derived class. options is a context specific optional argument.]
    [A call to `cls.def(name, visitor)` or `cls.def(name, visitor, options)` forwards to this member function. ]]]
    ]]
    ]
[endsect]
[section Example]
``
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);
    c.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());
}
``
[endsect]
[endsect]