2
0
mirror of https://github.com/boostorg/python.git synced 2026-01-26 18:52:26 +00:00

new API changes

[SVN r15344]
This commit is contained in:
Joel de Guzman
2002-09-15 21:13:12 +00:00
parent 4a6762540d
commit 604928adc4
2 changed files with 50 additions and 8 deletions

View File

@@ -158,25 +158,25 @@ BOOST_PYTHON_MODULE_INIT(defaults_ext)
.def("barfoo", (object(*)(int, char, std::string, double))0, bar_stubs())
;
class_<Y>("Y", no_init)
class_<Y>("Y", init<>("doc of Y init")) // this should work
.def("get_state", &Y::get_state)
;
class_<X>("X")
# if (!defined(BOOST_INTEL_CXX_VERSION) || BOOST_INTEL_CXX_VERSION > 600)
.def(init<int, optional<char, std::string, double> >())
.def(init<std::string, bool>())
.def(init<int, optional<char, std::string, double> >("doc of init"))
.def(init<std::string, bool>()[default_call_policies()]) // what's a good policy here?
# else
.def_init(args<int>())
.def_init(args<int, char>())
.def_init(args<int, char, std::string>())
.def_init(args<int, char, std::string, double>())
.def_init(args<int>(), "doc of init")
.def_init(args<int, char>(), "doc of init")
.def_init(args<int, char, std::string>(), "doc of init")
.def_init(args<int, char, std::string, double>(), "doc of init")
.def_init(args<std::string, bool>())
# endif
.def("get_state", &X::get_state)
.def("bar", &X::bar, X_bar_stubs())
.def("bar2", &X::bar2, X_bar_stubs2(), return_internal_reference<>())
.def("bar2", &X::bar2, X_bar_stubs2("doc of X::bar2")[return_internal_reference<>()])
.def("foo", (object(X::*)(std::string, bool) const)0, X_foo_2_stubs())
.def("foo", (object(X::*)(int, bool) const)0, X_foo_2_stubs())
.def("foo", (object(X::*)(list, list, bool) const)0, X_foo_3_stubs())

View File

@@ -3,73 +3,115 @@
>>> from defaults_ext import *
>>> bar(1)
'int(1); char(D); string(default); double(0.0); '
>>> bar(2, 'X')
'int(2); char(X); string(default); double(0.0); '
>>> bar(3, 'Y', "Hello World")
'int(3); char(Y); string(Hello World); double(0.0); '
>>> bar(4, 'Z', "Hi There", 3.3)
'int(4); char(Z); string(Hi There); double(3.3); '
>>> foo(1)
'int(1); char(D); string(default); double(0.0); '
>>> foo(2, 'X')
'int(2); char(X); string(default); double(0.0); '
>>> foo(3, 'Y', "Hello World")
'int(3); char(Y); string(Hello World); double(0.0); '
>>> foo(4, 'Z', "Hi There", 3.3)
'int(4); char(Z); string(Hi There); double(3.3); '
>>> x = X()
>>> x.bar(1)
'int(1); char(D); string(default); double(0.0); '
>>> x.bar(2, 'X')
'int(2); char(X); string(default); double(0.0); '
>>> x.bar(3, 'Y', "Hello World")
'int(3); char(Y); string(Hello World); double(0.0); '
>>> x.bar(4, 'Z', "Hi There", 3.3)
'int(4); char(Z); string(Hi There); double(3.3); '
>>> x.foo(5)
'int(5); bool(0); '
>>> x.foo(6, 0)
'int(6); bool(0); '
>>> x.foo(7, 1)
'int(7); bool(1); '
>>> x.foo("A")
'string(A); bool(0); '
>>> x.foo("B", False)
'string(B); bool(0); '
>>> x.foo("C", True)
'string(C); bool(1); '
>>> x.foo([0,1,2], [2,3,4])
'list([0, 1, 2]); list([2, 3, 4]); bool(0); '
>>> x.foo([0,1,2], [2,3,4], False)
'list([0, 1, 2]); list([2, 3, 4]); bool(0); '
>>> x.foo([0,1,2], [2,3,4], True)
'list([0, 1, 2]); list([2, 3, 4]); bool(1); '
>>> x = X(1)
>>> x.get_state()
'int(1); char(D); string(constructor); double(0.0); '
>>> x = X(1, 'X')
>>> x.get_state()
'int(1); char(X); string(constructor); double(0.0); '
>>> x = X(1, 'X', "Yabadabadoo")
>>> x.get_state()
'int(1); char(X); string(Yabadabadoo); double(0.0); '
>>> x = X(1, 'X', "Phoenix", 3.65)
>>> x.get_state()
'int(1); char(X); string(Phoenix); double(3.65); '
>>> x.bar2().get_state()
'int(0); char(D); string(default); double(0.0); '
>>> x.bar2(1).get_state()
'int(1); char(D); string(default); double(0.0); '
>>> x.bar2(1, 'K').get_state()
'int(1); char(K); string(default); double(0.0); '
>>> x.bar2(1, 'K', "Kim").get_state()
'int(1); char(K); string(Kim); double(0.0); '
>>> x.bar2(1, 'K', "Kim", 9.9).get_state()
'int(1); char(K); string(Kim); double(9.9); '
>>> x = X("Phoenix", 1)
>>> x.get_state()
'Got exactly two arguments from constructor: string(Phoenix); bool(1); '
>>> def printdoc(x):
... print x.__doc__
>>> printdoc(X.__init__)
doc of init
>>> printdoc(Y.__init__)
doc of Y init
>>> printdoc(X.bar2)
doc of X::bar2
"""
def run(args = None):
import sys