⇤ ← Revision 1 as of 2002-09-26 20:42:03
Size: 709
Comment:
|
Size: 1162
Comment: v2
|
Deletions are marked like this. | Additions are marked like this. |
Line 1: | Line 1: |
If the class had no `def_init(...)` calls, you now must pass `python::no_init` instead. On the upside, you never need to call `def_init()` with no arguments, since that's the default. So: |
'''class_<>''' statement constructs python class object. Usually it's included in BOOST_PYTHON_MODULE to wrap C++ class: {{{ class A { ... }; BOOST_PYTHON_MODULE(example) { class_<A>("A"); } }}} Also it can be used explicitly to create class instances from C++: {{{ BOOST_PYTHON_MODULE(example1) { object class_a = class_<A>("A"); object instance_a = class_a(); } }}} If you want to forbid creating class instancies from python, you now must pass `no_init` to class_<> definition. Default, as in python, will be init with no arguments. There is no limit to number of init<>'s in the boost.python. '''Synopsis:''' |
Line 7: | Line 25: |
.def_init(args<int, int>()) | .def(init<int, int>()) |
Line 11: | Line 29: |
class_<B>("B", args<int, int>()) | class_<B>("B", init<int, int>()) |
Line 15: | Line 33: |
class_<C>("C", "C's docstring", args<int, int>()) | class_<C>("C", "C's docstring", init<int, int>()) |
Line 19: | Line 37: |
class_<D>("D", "D's docstring", args<int, int>(), "__init__ doc") | class_<D>("D", "D's docstring", init<int, int>(), "__init__ doc") |
Line 39: | Line 57: |
}}} |
class_<> statement constructs python class object.
Usually it's included in BOOST_PYTHON_MODULE to wrap C++ class:
class A { ... }; BOOST_PYTHON_MODULE(example) { class_<A>("A"); }
Also it can be used explicitly to create class instances from C++:
BOOST_PYTHON_MODULE(example1) { object class_a = class_<A>("A"); object instance_a = class_a(); }
If you want to forbid creating class instancies from python, you now must pass no_init to class_<> definition. Default, as in python, will be init with no arguments. There is no limit to number of init<>'s in the boost.python.
Synopsis:
class_<A>("A") .def(init<int, int>()) .def(...) ; class_<B>("B", init<int, int>()) .def(...) ; class_<C>("C", "C's docstring", init<int, int>()) .def(...) ; class_<D>("D", "D's docstring", init<int, int>(), "__init__ doc") .def(...) ; class_<E>("E") .def(...) ; class_<F>("F", no_init) .def(...) ; class_<G>("G", "G's docstring", no_init) .def(...) ; class_<H>("H", "H's docstring") .def(...) ;