mirror of
https://github.com/boostorg/python.git
synced 2026-01-20 16:52:15 +00:00
Compare commits
212 Commits
boost-1.26
...
svn-branch
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
debba1c7c6 | ||
|
|
d72128107e | ||
|
|
3b8dc924c3 | ||
|
|
08ac287726 | ||
|
|
a8d6f40794 | ||
|
|
a2071feeb1 | ||
|
|
aa705b07f3 | ||
|
|
fbbc1981ca | ||
|
|
6528bd0e4f | ||
|
|
81a07899ae | ||
|
|
c18d8fa967 | ||
|
|
3caa91cc36 | ||
|
|
0bdf3542e4 | ||
|
|
23769371bc | ||
|
|
bccd854676 | ||
|
|
2fa0910547 | ||
|
|
c170b1b83e | ||
|
|
be6016a972 | ||
|
|
a56f66e721 | ||
|
|
e589d7f1e1 | ||
|
|
948cde1a31 | ||
|
|
3447aaa8c6 | ||
|
|
688c64ce21 | ||
|
|
7eb42dc36b | ||
|
|
ae1c1b3a47 | ||
|
|
74078552df | ||
|
|
5da8206915 | ||
|
|
f271726cd8 | ||
|
|
22f6612354 | ||
|
|
74fe5bc4dd | ||
|
|
69d7011baf | ||
|
|
0301d4462b | ||
|
|
7c009e2443 | ||
|
|
a16d9f91ee | ||
|
|
7e76c85535 | ||
|
|
3054694726 | ||
|
|
a25021d215 | ||
|
|
532833ff70 | ||
|
|
e79a66851c | ||
|
|
97825fb2c7 | ||
|
|
bd9df7e619 | ||
|
|
087f09e9a6 | ||
|
|
1257b32464 | ||
|
|
a437af44f8 | ||
|
|
9644610e04 | ||
|
|
71cbe1cf50 | ||
|
|
edad2a1ee5 | ||
|
|
0e597f5768 | ||
|
|
b28dc55237 | ||
|
|
a2dec7a05d | ||
|
|
db9fb22cf4 | ||
|
|
412a00249f | ||
|
|
ccb7a8f94f | ||
|
|
ee26e13bea | ||
|
|
493ff9c685 | ||
|
|
bbc49e1ba3 | ||
|
|
0ef39e4440 | ||
|
|
8a956bcdf6 | ||
|
|
a16ff29638 | ||
|
|
f6381e7e5e | ||
|
|
e014765797 | ||
|
|
3899684686 | ||
|
|
e11b457b79 | ||
|
|
a04cbd111c | ||
|
|
6c7d3e1eab | ||
|
|
d965b41bdd | ||
|
|
d660c12a74 | ||
|
|
43bcbf771e | ||
|
|
7f420361b1 | ||
|
|
361455678a | ||
|
|
47c1c6288c | ||
|
|
07abc9fac4 | ||
|
|
266923d9e8 | ||
|
|
622ff9d764 | ||
|
|
b75d11da3a | ||
|
|
8af49161fb | ||
|
|
ca872af3c8 | ||
|
|
aeccf45d4e | ||
|
|
dcae0eadd5 | ||
|
|
80effaa541 | ||
|
|
edd93c80a1 | ||
|
|
39646acf5b | ||
|
|
f697d2daa1 | ||
|
|
607631604f | ||
|
|
09d012a10b | ||
|
|
b303d49634 | ||
|
|
371723a5d4 | ||
|
|
4481c3bada | ||
|
|
70bb30b95a | ||
|
|
ebc641440e | ||
|
|
586b4db968 | ||
|
|
12c7981450 | ||
|
|
08c909fd41 | ||
|
|
44e43d3b47 | ||
|
|
9e8273c7f7 | ||
|
|
93735c7bf1 | ||
|
|
e37a97e2d5 | ||
|
|
8ff5450ece | ||
|
|
5d30ddac22 | ||
|
|
80f697ef2a | ||
|
|
47c7748707 | ||
|
|
9f33aa2afc | ||
|
|
1dc6600b59 | ||
|
|
1ec58c1161 | ||
|
|
d023d577b2 | ||
|
|
21d65ca0bf | ||
|
|
bcf4401858 | ||
|
|
262396d48b | ||
|
|
0a9d5f680f | ||
|
|
64239f1c04 | ||
|
|
7590d546f1 | ||
|
|
021070f066 | ||
|
|
55a4318839 | ||
|
|
90647f30f8 | ||
|
|
8cc9080d36 | ||
|
|
6e5fc91885 | ||
|
|
71de2b5ec5 | ||
|
|
7703f91ee2 | ||
|
|
ecc8abcc50 | ||
|
|
14917c9791 | ||
|
|
25c56164b0 | ||
|
|
12988b879e | ||
|
|
684e391a9a | ||
|
|
7a16cd4c37 | ||
|
|
b3117c2b02 | ||
|
|
6a75fa83b5 | ||
|
|
88a8721b89 | ||
|
|
1f12857551 | ||
|
|
71032f6c4c | ||
|
|
088b1cab83 | ||
|
|
f40a534bfb | ||
|
|
f278530239 | ||
|
|
0389aab0a3 | ||
|
|
51a66a3202 | ||
|
|
248985e51a | ||
|
|
996d83eae0 | ||
|
|
98a1329dd7 | ||
|
|
ed2ebc7d3d | ||
|
|
41634f9998 | ||
|
|
93501af046 | ||
|
|
078585db28 | ||
|
|
03e9e4c1d9 | ||
|
|
4a1d077238 | ||
|
|
f7a5e6deb8 | ||
|
|
dabb22bb6a | ||
|
|
3d03ca3d10 | ||
|
|
386992c3b8 | ||
|
|
a48f252cfa | ||
|
|
c3a311ab85 | ||
|
|
7926e1bc3c | ||
|
|
b796db648a | ||
|
|
0964ecac8c | ||
|
|
dd1ac7952b | ||
|
|
7d1cbcb0c1 | ||
|
|
98c9e67625 | ||
|
|
aeef66ce35 | ||
|
|
8cff66e8c6 | ||
|
|
10a04acf41 | ||
|
|
9923a4c4ff | ||
|
|
0dafa9e229 | ||
|
|
e83e8a8f1c | ||
|
|
72aa768235 | ||
|
|
65c74e3976 | ||
|
|
cdac34efea | ||
|
|
03fef3106d | ||
|
|
d598d0a4db | ||
|
|
ab22e1b3a9 | ||
|
|
26d520af3c | ||
|
|
fb333f3641 | ||
|
|
1cc65a47eb | ||
|
|
8d56c52991 | ||
|
|
4b88b9eed1 | ||
|
|
462b91fb08 | ||
|
|
b65f4ff963 | ||
|
|
8d27b48225 | ||
|
|
e2623c5e82 | ||
|
|
acdae42fc5 | ||
|
|
451aac806e | ||
|
|
586e6178b4 | ||
|
|
1201761ff3 | ||
|
|
bdf68f092e | ||
|
|
a179f87d54 | ||
|
|
b2944a12de | ||
|
|
bfcb36927c | ||
|
|
ccd21d5254 | ||
|
|
a7b8448107 | ||
|
|
e934be2d99 | ||
|
|
015b875a9e | ||
|
|
1247ff2543 | ||
|
|
dc831fb3f6 | ||
|
|
94c0e947f5 | ||
|
|
ed9bc835a2 | ||
|
|
2eb2e52a79 | ||
|
|
14f6f88526 | ||
|
|
1f78c74085 | ||
|
|
c494649dde | ||
|
|
460f3aebe9 | ||
|
|
d4b215a66b | ||
|
|
1a13387012 | ||
|
|
291c36df05 | ||
|
|
bed2c8a371 | ||
|
|
e65ca4ccac | ||
|
|
f9e6933840 | ||
|
|
5134fb2ec1 | ||
|
|
3a86a69964 | ||
|
|
c6fd3c47a4 | ||
|
|
a365fa6109 | ||
|
|
160451b210 | ||
|
|
2f6e3cc09d | ||
|
|
d05cc7ccec | ||
|
|
ccfd4acbda | ||
|
|
6a6084ed0e |
24
Jamfile
Normal file
24
Jamfile
Normal file
@@ -0,0 +1,24 @@
|
||||
subproject libs/python ;
|
||||
|
||||
# bring in the rules for python
|
||||
SEARCH on <module@>python.jam = $(BOOST_BUILD_PATH) ;
|
||||
include <module@>python.jam ;
|
||||
|
||||
dll bpl
|
||||
:
|
||||
src/converter/from_python.cpp
|
||||
src/converter/registry.cpp
|
||||
src/converter/type_id.cpp
|
||||
src/object/class.cpp
|
||||
src/object/function.cpp
|
||||
src/object/inheritance.cpp
|
||||
src/object/life_support.cpp
|
||||
src/errors.cpp
|
||||
src/module.cpp
|
||||
src/objects.cpp
|
||||
src/converter/builtin_converters.cpp
|
||||
src/converter/callback.cpp
|
||||
:
|
||||
$(BOOST_PYTHON_V2_PROPERTIES)
|
||||
<define>BOOST_PYTHON_SOURCE
|
||||
;
|
||||
242
build/Jamfile
242
build/Jamfile
@@ -9,7 +9,7 @@
|
||||
# To run all tests with verbose output: jam -sPYTHON_TEST_ARGS=-v test
|
||||
#
|
||||
# Declares the following targets:
|
||||
# 1. libboost_python, a static link library to be linked with all
|
||||
# 1. libboost_python.dll/.so, a dynamic library to be linked with all
|
||||
# Boost.Python modules
|
||||
#
|
||||
# 2. pairs of test targets of the form <name>.test and <name>.run
|
||||
@@ -54,52 +54,20 @@
|
||||
# PYTHON_VECT_ITERATIONS - specifies the number of test iterations to use for
|
||||
# the dvect and ivect tests above.
|
||||
|
||||
|
||||
# declare the location of this subproject relative to the root
|
||||
subproject libs/python/build ;
|
||||
|
||||
# grab variables from command-line or environment.
|
||||
local PYTHON_VERSION = $(PYTHON_VERSION) ;
|
||||
local PYTHON_ROOT = $(PYTHON_ROOT) ;
|
||||
local PYTHON_INCLUDES = $(PYTHON_INCLUDES) ;
|
||||
local PYTHON_LIBS = $(PYTHON_LIBS) ;
|
||||
local PYTHON_LIB_PATH = $(PYTHON_LIB_PATH) ;
|
||||
local PYTHON_PROPERTIES = $(PYTHON_PROPERTIES) ;
|
||||
# bring in the rules for python
|
||||
SEARCH on <module@>python.jam = $(BOOST_BUILD_PATH) ;
|
||||
include <module@>python.jam ;
|
||||
|
||||
# Do some OS-specific setup
|
||||
if $(NT)
|
||||
local PYTHON_PROPERTIES = $(PYTHON_PROPERTIES) <define>BOOST_PYTHON_DYNAMIC_LIB ;
|
||||
|
||||
#######################
|
||||
rule bpl-test ( test-name : sources + )
|
||||
{
|
||||
PYTHON_VERSION ?= 2.1 ;
|
||||
PYTHON_ROOT ?= c:/tools/python ;
|
||||
PYTHON_INCLUDES ?= <include>$(PYTHON_ROOT)/include <gcc><*><include>/usr/include/python$(PYTHON_VERSION) ;
|
||||
PYTHON_LIBS ?= c:/cygnus/lib/python$(PYTHON_VERSION)/config/libpython$(PYTHON_VERSION).dll.a ;
|
||||
PYTHON_LIB_PATH ?= $(PYTHON_ROOT)/libs ;
|
||||
|
||||
# common properties required for compiling any Python module.
|
||||
PYTHON_PROPERTIES ?=
|
||||
<gcc><*><define>SIZEOF_LONG=4
|
||||
<gcc><*><define>USE_DL_IMPORT
|
||||
<debug><define>_DEBUG
|
||||
<runtime-link>dynamic
|
||||
;
|
||||
|
||||
boost-python-test $(test-name) : $(sources) <dll>boost_python ;
|
||||
}
|
||||
else if $(UNIX)
|
||||
{
|
||||
PYTHON_VERSION ?= 1.5 ;
|
||||
PYTHON_INCLUDES ?= <include>/usr/include/python$(PYTHON_VERSION) ;
|
||||
PYTHON_LIBS ?= /usr/lib/python$(PYTHON_VERSION)/config/libpython$(PYTHON_VERSION).a ;
|
||||
}
|
||||
|
||||
local PYTHON_VERSION_NODOT
|
||||
= [ SUBST $(PYTHON_VERSION) ([0-9]*)\.([0-9]*) $1$2 ]
|
||||
;
|
||||
|
||||
# how do we invoke python?
|
||||
local PYTHON = $(PYTHON) ;
|
||||
PYTHON ?= python ;
|
||||
PYTHON = [ FAppendSuffix $(PYTHON:G=<executable-grist>) : $(SUFEXE) ] ;
|
||||
SEARCH on $(PYTHON) = $(PATH) ;
|
||||
|
||||
#######################
|
||||
|
||||
@@ -107,176 +75,46 @@ SEARCH on $(PYTHON) = $(PATH) ;
|
||||
# Declare the boost python static link library
|
||||
#
|
||||
|
||||
# standard include requirements for anything using Boost.Python
|
||||
local BOOST_PYTHON_INCLUDES = <include>$(BOOST_ROOT) $(PYTHON_INCLUDES) ;
|
||||
|
||||
# Base names of the source files for libboost_python
|
||||
local CPP_SOURCES =
|
||||
types classes conversions extension_class functions
|
||||
init_function module_builder objects cross_module ;
|
||||
types classes conversions extension_class functions
|
||||
init_function module_builder objects cross_module errors
|
||||
;
|
||||
|
||||
lib libboost_python : ../src/$(CPP_SOURCES).cpp
|
||||
lib boost_python_static : ../src/$(CPP_SOURCES).cpp
|
||||
# requirements
|
||||
: $(BOOST_PYTHON_INCLUDES)
|
||||
<shared-linkable>true
|
||||
<define>BOOST_PYTHON_STATIC_LIB=1
|
||||
$(PYTHON_PROPERTIES) ;
|
||||
|
||||
lib libboost_python_d : ../src/$(CPP_SOURCES).cpp
|
||||
# requirements
|
||||
: $(BOOST_PYTHON_INCLUDES)
|
||||
<shared-linkable>true
|
||||
$(PYTHON_PROPERTIES)
|
||||
<define>BOOST_DEBUG_PYTHON
|
||||
;
|
||||
|
||||
#######################
|
||||
|
||||
# boost-python name : sources : requirements : default-BUILD
|
||||
#
|
||||
# Declare a boost python module. Return a list of the DLL files generated.
|
||||
rule boost-python
|
||||
{
|
||||
local debug = "" ;
|
||||
if ( <define>BOOST_DEBUG_PYTHON in $(3) ) || ( debug-python in $(BUILD) )
|
||||
{
|
||||
debug = _d ;
|
||||
}
|
||||
|
||||
# declare a DLL; add the boost python library to sources
|
||||
dll $(<) : <lib>libboost_python$(debug) $(>)
|
||||
|
||||
# Requirements
|
||||
: $(3) # caller-specified requirements
|
||||
|
||||
# standard requirements
|
||||
$(BOOST_PYTHON_INCLUDES)
|
||||
<msvc><*><library-path>$(PYTHON_LIB_PATH)
|
||||
<intel-win32><*><library-path>$(PYTHON_LIB_PATH)
|
||||
<metrowerks><*><library-file>$(PYTHON_LIB_PATH)/python$(PYTHON_VERSION_NODOT)$(debug).lib
|
||||
<gcc><*><library-file>$(PYTHON_LIBS)
|
||||
$(PYTHON_PROPERTIES)
|
||||
|
||||
: $(4) ; # pass on the default-BUILD, if any
|
||||
}
|
||||
|
||||
# boost-python-test name : sources : requirements : default-BUILD
|
||||
#
|
||||
# Just like boost-python, but the result becomes part of the test pseudotarget
|
||||
# instead of being built by 'all'
|
||||
rule boost-python-test
|
||||
{
|
||||
type-DEPENDS test : $(<) ;
|
||||
type-DEPENDS test_d : $(<)_d ;
|
||||
NOTFILE test_d ;
|
||||
|
||||
local gSUPPRESS_FAKE_TARGETS = true ;
|
||||
boost-python $(1) : $(2) : $(3) : $(4) ;
|
||||
boost-python $(1)_d : $(2) : $(3) <define>BOOST_DEBUG_PYTHON : $(4) ;
|
||||
}
|
||||
|
||||
#######################
|
||||
|
||||
# boost-python-runtest target : python-script sources : requirements : local-build : args
|
||||
#
|
||||
# declare two python module tests: $(<).test which builds when out-of-date, and
|
||||
# $(<).run which builds unconditionally.
|
||||
rule boost-python-runtest
|
||||
{
|
||||
# tell Jam that the python script is relative to this directory
|
||||
SEARCH on $(>[1]) = $(SEARCH_SOURCE) ;
|
||||
|
||||
# required command-line args can be specified in argument 5
|
||||
# The user can add additional arguments in PYTHON_TEST_ARGS.
|
||||
local gPYTHON_TEST_ARGS = $(5) $(PYTHON_TEST_ARGS) ;
|
||||
|
||||
# declare the two subsidiary tests.
|
||||
declare-local-target $(<:S=.test) : $(>) : $(PYTHON_PROPERTIES) : $(4) : PYTHON_TEST ;
|
||||
declare-local-target $(<:S=.run) : $(>) : $(PYTHON_PROPERTIES) : $(4) : PYTHON_RUNTEST ;
|
||||
}
|
||||
|
||||
# special rules for two new target types: PYTHON_TEST and PYTHON_RUNTEST.
|
||||
# These are identical except that PYTHON_TEST runs the test when out-of-date, and
|
||||
# PYTHON_RUNTEST runs the test unconditionally. These are used by boost-python-runtest.
|
||||
SUFPYTHON_TEST = .test ;
|
||||
gGENERATOR_FUNCTION(PYTHON_TEST) = python-test-target ;
|
||||
rule python-test-target # test-target : sources :
|
||||
{
|
||||
python-runtest-aux $(<) : $(>) ;
|
||||
Clean clean : $(<) ; # remove the test-target as part of any clean operation
|
||||
local debug = [ SUBST $(<:B) (_d)$ $1 ] ;
|
||||
debug ?= "" ;
|
||||
type-DEPENDS test$(debug) : $(<) ;
|
||||
MakeLocate $(<) : $(LOCATE_TARGET) ;
|
||||
}
|
||||
actions python-test-target bind PYTHON
|
||||
{
|
||||
$(SHELL_SET)PYTHONPATH=$(PYTHONPATH)
|
||||
$(SHELL_EXPORT)PYTHONPATH
|
||||
$(PYTHON) "$(>)" $(ARGS) > "$(<)"
|
||||
}
|
||||
|
||||
SUFPYTHON_RUNTEST = .run ;
|
||||
gGENERATOR_FUNCTION(PYTHON_RUNTEST) = python-runtest-target ;
|
||||
rule python-runtest-target # test-target : sources :
|
||||
{
|
||||
python-runtest-aux $(<) : $(>) ;
|
||||
NOTFILE $(<) ;
|
||||
ALWAYS $(<) ;
|
||||
}
|
||||
actions python-runtest-target bind PYTHON
|
||||
{
|
||||
$(SHELL_SET)PYTHONPATH=$(PYTHONPATH)
|
||||
$(SHELL_EXPORT)PYTHONPATH
|
||||
$(PYTHON) "$(>)" $(ARGS)
|
||||
}
|
||||
|
||||
rule python-runtest-aux # target : sources
|
||||
{
|
||||
DEPENDS $(<) : $(>) ;
|
||||
|
||||
ARGS on $(<) += $(gPYTHON_TEST_ARGS) ;
|
||||
|
||||
# Some tests need an extra command-line arg if built with
|
||||
# msvc. Checking the target grist is a cheap way to
|
||||
# find out.
|
||||
switch $(<)
|
||||
{
|
||||
case <*\\\\msvc\\\\*>* : ARGS on $(<) += --broken-auto-ptr ;
|
||||
case <*\\\\intel-win32\\\\*>* : ARGS on $(<) += --broken-auto-ptr ;
|
||||
}
|
||||
|
||||
# compute the PYTHONPATH environment variable that will allow the test to
|
||||
# find all of the modules on which it depends.
|
||||
PYTHONPATH on $(<) = [ join
|
||||
$(gLOCATE($(>[1]))) # location of python test file
|
||||
$(gRUN_PATH($(<))) # location of module dependencies
|
||||
[ join-path $(TOP) libs python test ] # location of doctest
|
||||
$(>:D) # directory of python driver file(s)
|
||||
$(PYTHONPATH) # base PYTHONPATH from environment
|
||||
: $(SPLITPATH) ] ; # platform path separator
|
||||
|
||||
PYTHON on $(<) = $(PYTHON) ;
|
||||
DEPENDS $(<) : $(PYTHON) ;
|
||||
}
|
||||
dll boost_python
|
||||
# $(SUFDLL[1])
|
||||
: ../src/$(CPP_SOURCES).cpp
|
||||
# requirements
|
||||
: $(BOOST_PYTHON_INCLUDES)
|
||||
<shared-linkable>true
|
||||
<runtime-link>dynamic
|
||||
<define>BOOST_PYTHON_HAS_DLL_RUNTIME=1
|
||||
$(PYTHON_PROPERTIES)
|
||||
;
|
||||
|
||||
############# comprehensive module and test ###########
|
||||
boost-python-test boost_python_test : ../test/comprehensive.cpp ;
|
||||
bpl-test boost_python_test
|
||||
: ../test/comprehensive.cpp ;
|
||||
|
||||
boost-python-runtest comprehensive
|
||||
: [ join-path $(DOTDOT) test comprehensive.py ]
|
||||
<lib>boost_python_test ;
|
||||
|
||||
boost-python-runtest comprehensive_d
|
||||
: [ join-path $(DOTDOT) test comprehensive.py ]
|
||||
<lib>boost_python_test_d ;
|
||||
: ../test/comprehensive.py <pyd>boost_python_test <dll>boost_python ;
|
||||
|
||||
############# simple tests from ../example ############
|
||||
|
||||
rule boost-python-example-runtest
|
||||
rule boost-python-example-runtest ( name )
|
||||
{
|
||||
boost-python-test $(<) : ../example/$(<).cpp ;
|
||||
boost-python-runtest $(<) : [ join-path $(DOTDOT) example test_$(<).py ] <lib>$(<) ;
|
||||
boost-python-runtest $(<)_d : [ join-path $(DOTDOT) example test_$(<).py ] <lib>$(<)_d ;
|
||||
bpl-test $(name)
|
||||
: ../example/$(name).cpp ;
|
||||
|
||||
boost-python-runtest $(name)
|
||||
: ../example/test_$(name).py <pyd>$(name) ;
|
||||
}
|
||||
|
||||
|
||||
@@ -290,18 +128,18 @@ boost-python-example-runtest pickle2 ;
|
||||
boost-python-example-runtest pickle3 ;
|
||||
|
||||
|
||||
boost-python-test ivect : ../example/ivect.cpp ;
|
||||
boost-python-test dvect : ../example/dvect.cpp ;
|
||||
boost-python-test noncopyable_export : ../example/noncopyable_export.cpp ;
|
||||
boost-python-test noncopyable_import : ../example/noncopyable_import.cpp ;
|
||||
bpl-test ivect : ../example/ivect.cpp ;
|
||||
bpl-test dvect : ../example/dvect.cpp ;
|
||||
bpl-test noncopyable_export : ../example/noncopyable_export.cpp ;
|
||||
bpl-test noncopyable_import : ../example/noncopyable_import.cpp ;
|
||||
|
||||
############## cross-module tests from ../example ##########
|
||||
|
||||
# A simple rule to build a test which depends on multiple modules in the PYTHONPATH
|
||||
rule boost-python-multi-example-runtest # test-name : python-file libs
|
||||
rule boost-python-multi-example-runtest ( test-name : modules + )
|
||||
{
|
||||
boost-python-runtest $(<)
|
||||
: ../example/tst_$(<).py <lib>$(>)
|
||||
boost-python-runtest $(test-name)
|
||||
: ../example/tst_$(test-name).py <pyd>$(modules) <dll>boost_python
|
||||
: : : $(PYTHON_VECT_ITERATIONS) ;
|
||||
}
|
||||
|
||||
|
||||
@@ -7,6 +7,7 @@ LIBSRC = \
|
||||
classes.cpp \
|
||||
conversions.cpp \
|
||||
cross_module.cpp \
|
||||
errors.cpp \
|
||||
extension_class.cpp \
|
||||
functions.cpp \
|
||||
init_function.cpp \
|
||||
|
||||
@@ -8,6 +8,7 @@ bpl_exa = "/libs/python/example"
|
||||
files = (
|
||||
bpl_src + "/classes.cpp",
|
||||
bpl_src + "/conversions.cpp",
|
||||
bpl_src + "/errors.cpp",
|
||||
bpl_src + "/extension_class.cpp",
|
||||
bpl_src + "/functions.cpp",
|
||||
bpl_src + "/init_function.cpp",
|
||||
|
||||
@@ -11,6 +11,7 @@ LIBSRC = \
|
||||
classes.cpp \
|
||||
conversions.cpp \
|
||||
cross_module.cpp \
|
||||
errors.cpp \
|
||||
extension_class.cpp \
|
||||
functions.cpp \
|
||||
init_function.cpp \
|
||||
|
||||
@@ -17,10 +17,10 @@
|
||||
ROOT=$(HOME)
|
||||
BOOST=$(ROOT)/boost
|
||||
|
||||
PYEXE=PYTHONPATH=. /usr/local/Python-1.5.2/bin/python
|
||||
PYINC=-I/usr/local/Python-1.5.2/include/python1.5
|
||||
#PYEXE=PYTHONPATH=. /usr/local/Python-2.1/bin/python
|
||||
#PYINC=-I/usr/local/Python-2.1/include/python2.1
|
||||
#PYEXE=PYTHONPATH=. /usr/local/Python-1.5.2/bin/python
|
||||
#PYINC=-I/usr/local/Python-1.5.2/include/python1.5
|
||||
PYEXE=PYTHONPATH=. /usr/local_cci/Python-2.1.1/bin/python
|
||||
PYINC=-I/usr/local_cci/Python-2.1.1/include/python2.1
|
||||
STLPORTINC=-I$(BOOST)/boost/compatibility/cpp_c_headers
|
||||
|
||||
STDOPTS=
|
||||
@@ -35,7 +35,7 @@ MAKEDEP=-M
|
||||
LD=CC -LANG:std -n32 -mips4
|
||||
LDOPTS=-shared
|
||||
|
||||
OBJ=classes.o conversions.o extension_class.o functions.o \
|
||||
OBJ=classes.o conversions.o errors.o extension_class.o functions.o \
|
||||
init_function.o module_builder.o \
|
||||
objects.o types.o cross_module.o
|
||||
DEPOBJ=$(OBJ) \
|
||||
|
||||
@@ -17,12 +17,12 @@
|
||||
ROOT=$(HOME)
|
||||
BOOST=$(ROOT)/boost
|
||||
|
||||
PYEXE=PYTHONPATH=. /usr/bin/python
|
||||
PYINC=-I/usr/include/python1.5
|
||||
#PYEXE=PYTHONPATH=. /usr/bin/python
|
||||
#PYINC=-I/usr/include/python1.5
|
||||
#PYEXE=PYTHONPATH=. /usr/local/Python-1.5.2/bin/python
|
||||
#PYINC=-I/usr/local/Python-1.5.2/include/python1.5
|
||||
#PYEXE=PYTHONPATH=. /usr/local/Python-2.1/bin/python
|
||||
#PYINC=-I/usr/local/Python-2.1/include/python2.1
|
||||
PYEXE=PYTHONPATH=. /usr/local_cci/Python-2.1.1/bin/python
|
||||
PYINC=-I/usr/local_cci/Python-2.1.1/include/python2.1
|
||||
|
||||
STDOPTS=-fPIC -ftemplate-depth-21
|
||||
WARNOPTS=
|
||||
@@ -36,7 +36,7 @@ MAKEDEP=-M
|
||||
LD=$(CPP)
|
||||
LDOPTS=-shared
|
||||
|
||||
OBJ=classes.o conversions.o extension_class.o functions.o \
|
||||
OBJ=classes.o conversions.o errors.o extension_class.o functions.o \
|
||||
init_function.o module_builder.o \
|
||||
objects.o types.o cross_module.o
|
||||
DEPOBJ=$(OBJ) \
|
||||
|
||||
@@ -52,7 +52,7 @@ CPPOPTS=$(STLPORTINC) $(STLPORTOPTS) -I$(BOOST_WIN) $(PYINC) \
|
||||
LD=g++
|
||||
LDOPTS=-shared
|
||||
|
||||
OBJ=classes.o conversions.o extension_class.o functions.o \
|
||||
OBJ=classes.o conversions.o errors.o extension_class.o functions.o \
|
||||
init_function.o module_builder.o \
|
||||
objects.o types.o cross_module.o
|
||||
|
||||
|
||||
@@ -17,10 +17,10 @@
|
||||
ROOT=$(HOME)
|
||||
BOOST=$(ROOT)/boost
|
||||
|
||||
PYEXE=PYTHONPATH=. /usr/local/Python-1.5.2/bin/python
|
||||
PYINC=-I/usr/local/Python-1.5.2/include/python1.5
|
||||
#PYEXE=PYTHONPATH=. /usr/local/Python-2.1/bin/python
|
||||
#PYINC=-I/usr/local/Python-2.1/include/python2.1
|
||||
#PYEXE=PYTHONPATH=. /usr/local/Python-1.5.2/bin/python
|
||||
#PYINC=-I/usr/local/Python-1.5.2/include/python1.5
|
||||
PYEXE=PYTHONPATH=. /usr/local_cci/Python-2.1.1/bin/python
|
||||
PYINC=-I/usr/local_cci/Python-2.1.1/include/python2.1
|
||||
#STLPORTINC=-I/usr/local/STLport-4.1b3/stlport
|
||||
#STLPORTINC=-I/usr/local/STLport-4.1b4/stlport
|
||||
#STLPORTOPTS= \
|
||||
@@ -46,7 +46,7 @@ LDOPTS=-shared -expect_unresolved 'Py*' -expect_unresolved '_Py*'
|
||||
|
||||
#HIDDEN=-hidden
|
||||
|
||||
OBJ=classes.o conversions.o extension_class.o functions.o \
|
||||
OBJ=classes.o conversions.o errors.o extension_class.o functions.o \
|
||||
init_function.o module_builder.o \
|
||||
objects.o types.o cross_module.o
|
||||
DEPOBJ=$(OBJ) \
|
||||
|
||||
@@ -14,14 +14,14 @@ ROOT=R:
|
||||
BOOST_WIN="$(ROOT)\boost"
|
||||
BOOST_UNIX=$(HOME)/boost
|
||||
|
||||
PYEXE="C:\Program files\Python\python.exe"
|
||||
PYINC=/I"C:\Program files\Python\include"
|
||||
PYLIB="C:\Program files\Python\libs\python15.lib"
|
||||
#PYEXE="C:\Python21\python.exe"
|
||||
#PYINC=/I"C:\Python21\include"
|
||||
#PYLIB="C:\Python21\libs\python21.lib"
|
||||
#PYEXE="C:\Program files\Python\python.exe"
|
||||
#PYINC=/I"C:\Program files\Python\include"
|
||||
#PYLIB="C:\Program files\Python\libs\python15.lib"
|
||||
PYEXE="C:\Python21\python.exe"
|
||||
PYINC=/I"C:\Python21\include"
|
||||
PYLIB="C:\Python21\libs\python21.lib"
|
||||
|
||||
STDOPTS=/nologo /MD /GR /GX /Zm200
|
||||
STDOPTS=/nologo /MD /GR /GX /Zm300 /DBOOST_PYTHON_STATIC_LIB
|
||||
WARNOPTS=
|
||||
OPTOPTS=
|
||||
|
||||
@@ -32,7 +32,7 @@ CPPOPTS=$(STLPORTINC) $(STLPORTOPTS) /I$(BOOST_WIN) $(PYINC) \
|
||||
LD=link.exe
|
||||
LDOPTS=/nologo /dll /incremental:no
|
||||
|
||||
OBJ=classes.obj conversions.obj extension_class.obj functions.obj \
|
||||
OBJ=classes.obj conversions.obj errors.obj extension_class.obj functions.obj \
|
||||
init_function.obj module_builder.obj \
|
||||
objects.obj types.obj cross_module.obj
|
||||
|
||||
|
||||
149
build/win32_mwcc.mak
Executable file
149
build/win32_mwcc.mak
Executable file
@@ -0,0 +1,149 @@
|
||||
# Usage:
|
||||
#
|
||||
# make copy Copy the sources and tests
|
||||
# make Compile all sources
|
||||
# make test Run doctest tests
|
||||
# make clean Remove all object files
|
||||
# make del Remove the sources and tests
|
||||
#
|
||||
# Revision history:
|
||||
# 14 Dec 01 derived from vc60.mak (R.W. Grosse-Kunstleve)
|
||||
|
||||
ROOT=R:
|
||||
BOOST_WIN="$(ROOT)\boost"
|
||||
BOOST_UNIX=$(HOME)/boost
|
||||
|
||||
#PYEXE="C:\Program files\Python\python.exe"
|
||||
#PYINC=-I"C:\Program files\Python\include"
|
||||
#PYLIB="C:\Program files\Python\libs\python15.lib"
|
||||
PYEXE="C:\Python21\python.exe"
|
||||
PYINC=-I"C:\Python21\include"
|
||||
PYLIB="C:\Python21\libs\python21.lib"
|
||||
|
||||
STDOPTS=-gccinc -prefix UseDLLPrefix.h -DBOOST_PYTHON_STATIC_LIB
|
||||
WARNOPTS=-warn on,nounusedexpr,nounused
|
||||
OPTOPTS=-O
|
||||
|
||||
CPP=mwcc
|
||||
CPPOPTS=$(STDOPTS) $(WARNOPTS) $(OPTOPTS) \
|
||||
$(STLPORTINC) $(STLPORTOPTS) -I$(BOOST_WIN) $(PYINC)
|
||||
|
||||
LD=mwld
|
||||
LDOPTS=-export dllexport -shared
|
||||
|
||||
OBJ=classes.obj conversions.obj errors.obj extension_class.obj functions.obj \
|
||||
init_function.obj module_builder.obj \
|
||||
objects.obj types.obj cross_module.obj
|
||||
|
||||
.SUFFIXES: .obj .cpp
|
||||
|
||||
all: libboost_python.lib \
|
||||
boost_python_test.pyd \
|
||||
abstract.pyd \
|
||||
getting_started1.pyd getting_started2.pyd \
|
||||
simple_vector.pyd \
|
||||
do_it_yourself_convts.pyd \
|
||||
nested.pyd \
|
||||
pickle1.pyd pickle2.pyd pickle3.pyd \
|
||||
noncopyable_export.pyd noncopyable_import.pyd \
|
||||
ivect.pyd dvect.pyd \
|
||||
richcmp1.pyd richcmp2.pyd richcmp3.pyd
|
||||
|
||||
libboost_python.lib: $(OBJ)
|
||||
$(LD) -library -o libboost_python.lib $(OBJ)
|
||||
|
||||
boost_python_test.pyd: $(OBJ) comprehensive.obj
|
||||
$(LD) $(LDOPTS) $(OBJ) comprehensive.obj $(PYLIB) -o boost_python_test.pyd
|
||||
|
||||
abstract.pyd: $(OBJ) abstract.obj
|
||||
$(LD) $(LDOPTS) $(OBJ) abstract.obj $(PYLIB) -o abstract.pyd
|
||||
|
||||
getting_started1.pyd: $(OBJ) getting_started1.obj
|
||||
$(LD) $(LDOPTS) $(OBJ) getting_started1.obj $(PYLIB) -o getting_started1.pyd
|
||||
|
||||
getting_started2.pyd: $(OBJ) getting_started2.obj
|
||||
$(LD) $(LDOPTS) $(OBJ) getting_started2.obj $(PYLIB) -o getting_started2.pyd
|
||||
|
||||
simple_vector.pyd: $(OBJ) simple_vector.obj
|
||||
$(LD) $(LDOPTS) $(OBJ) simple_vector.obj $(PYLIB) -o simple_vector.pyd
|
||||
|
||||
do_it_yourself_convts.pyd: $(OBJ) do_it_yourself_convts.obj
|
||||
$(LD) $(LDOPTS) $(OBJ) do_it_yourself_convts.obj $(PYLIB) -o do_it_yourself_convts.pyd
|
||||
|
||||
nested.pyd: $(OBJ) nested.obj
|
||||
$(LD) $(LDOPTS) $(OBJ) nested.obj $(PYLIB) -o nested.pyd
|
||||
|
||||
pickle1.pyd: $(OBJ) pickle1.obj
|
||||
$(LD) $(LDOPTS) $(OBJ) pickle1.obj $(PYLIB) -o pickle1.pyd
|
||||
|
||||
pickle2.pyd: $(OBJ) pickle2.obj
|
||||
$(LD) $(LDOPTS) $(OBJ) pickle2.obj $(PYLIB) -o pickle2.pyd
|
||||
|
||||
pickle3.pyd: $(OBJ) pickle3.obj
|
||||
$(LD) $(LDOPTS) $(OBJ) pickle3.obj $(PYLIB) -o pickle3.pyd
|
||||
|
||||
noncopyable_export.pyd: $(OBJ) noncopyable_export.obj
|
||||
$(LD) $(LDOPTS) $(OBJ) noncopyable_export.obj $(PYLIB) -o noncopyable_export.pyd
|
||||
|
||||
noncopyable_import.pyd: $(OBJ) noncopyable_import.obj
|
||||
$(LD) $(LDOPTS) $(OBJ) noncopyable_import.obj $(PYLIB) -o noncopyable_import.pyd
|
||||
|
||||
ivect.pyd: $(OBJ) ivect.obj
|
||||
$(LD) $(LDOPTS) $(OBJ) ivect.obj $(PYLIB) -o ivect.pyd
|
||||
|
||||
dvect.pyd: $(OBJ) dvect.obj
|
||||
$(LD) $(LDOPTS) $(OBJ) dvect.obj $(PYLIB) -o dvect.pyd
|
||||
|
||||
richcmp1.pyd: $(OBJ) richcmp1.obj
|
||||
$(LD) $(LDOPTS) $(OBJ) richcmp1.obj $(PYLIB) -o richcmp1.pyd
|
||||
|
||||
richcmp2.pyd: $(OBJ) richcmp2.obj
|
||||
$(LD) $(LDOPTS) $(OBJ) richcmp2.obj $(PYLIB) -o richcmp2.pyd
|
||||
|
||||
richcmp3.pyd: $(OBJ) richcmp3.obj
|
||||
$(LD) $(LDOPTS) $(OBJ) richcmp3.obj $(PYLIB) -o richcmp3.pyd
|
||||
|
||||
.cpp.obj:
|
||||
$(CPP) $(CPPOPTS) -c $*.cpp
|
||||
|
||||
test:
|
||||
$(PYEXE) comprehensive.py
|
||||
$(PYEXE) test_abstract.py
|
||||
$(PYEXE) test_getting_started1.py
|
||||
$(PYEXE) test_getting_started2.py
|
||||
$(PYEXE) test_simple_vector.py
|
||||
$(PYEXE) test_do_it_yourself_convts.py
|
||||
$(PYEXE) test_nested.py
|
||||
$(PYEXE) test_pickle1.py
|
||||
$(PYEXE) test_pickle2.py
|
||||
$(PYEXE) test_pickle3.py
|
||||
$(PYEXE) test_cross_module.py
|
||||
$(PYEXE) test_richcmp1.py
|
||||
$(PYEXE) test_richcmp2.py
|
||||
$(PYEXE) test_richcmp3.py
|
||||
|
||||
clean:
|
||||
-del *.obj
|
||||
-del *.lib
|
||||
-del *.exp
|
||||
-del *.idb
|
||||
-del *.pyd
|
||||
-del *.pyc
|
||||
|
||||
softlinks:
|
||||
python $(BOOST_UNIX)/libs/python/build/filemgr.py $(BOOST_UNIX) softlinks
|
||||
|
||||
unlink:
|
||||
python $(BOOST_UNIX)/libs/python/build/filemgr.py $(BOOST_UNIX) unlink
|
||||
|
||||
cp:
|
||||
python $(BOOST_UNIX)/libs/python/build/filemgr.py $(BOOST_UNIX) cp
|
||||
|
||||
rm:
|
||||
python $(BOOST_UNIX)/libs/python/build/filemgr.py $(BOOST_UNIX) rm
|
||||
|
||||
copy:
|
||||
$(PYEXE) $(BOOST_WIN)\libs\python\build\filemgr.py $(BOOST_WIN) copy
|
||||
|
||||
del:
|
||||
$(PYEXE) $(BOOST_WIN)\libs\python\build\filemgr.py $(BOOST_WIN) del
|
||||
2
build/win32_mwcc_setup.bat
Executable file
2
build/win32_mwcc_setup.bat
Executable file
@@ -0,0 +1,2 @@
|
||||
call "c:\program files\metrowerks\codewarrior\other metrowerks tools\command line tools\cwenv.bat"
|
||||
set MWWinx86LibraryFiles=MSL_All-DLL_x86.lib;gdi32.lib;user32.lib;kernel32.lib
|
||||
59
doc/boost.css
Normal file
59
doc/boost.css
Normal file
@@ -0,0 +1,59 @@
|
||||
H1
|
||||
{
|
||||
FONT-SIZE: 200%
|
||||
COLOR: #00007f
|
||||
}
|
||||
H2
|
||||
{
|
||||
FONT-SIZE: 150%;
|
||||
}
|
||||
H3
|
||||
{
|
||||
FONT-SIZE: 125%;
|
||||
}
|
||||
H4
|
||||
{
|
||||
FONT-SIZE: 108%;
|
||||
}
|
||||
BODY
|
||||
{
|
||||
FONT-SIZE: 100%;
|
||||
BACKGROUND-COLOR: #ffffff
|
||||
}
|
||||
PRE
|
||||
{
|
||||
MARGIN-LEFT: 2pc;
|
||||
FONT-SIZE: 80%;
|
||||
BACKGROUND-COLOR: #dfffff
|
||||
}
|
||||
CODE
|
||||
{
|
||||
FONT-SIZE: 95%;
|
||||
white-space: pre
|
||||
}
|
||||
.index
|
||||
{
|
||||
TEXT-ALIGN: left
|
||||
}
|
||||
.page-index
|
||||
{
|
||||
TEXT-ALIGN: left
|
||||
}
|
||||
.definition
|
||||
{
|
||||
TEXT-ALIGN: left
|
||||
}
|
||||
.footnote
|
||||
{
|
||||
FONT-SIZE: 66%;
|
||||
VERTICAL-ALIGN: super;
|
||||
TEXT-DECORATION: none
|
||||
}
|
||||
.function-semantics
|
||||
{
|
||||
CLEAR: left
|
||||
}
|
||||
.metafunction-semantics
|
||||
{
|
||||
CLEAR: left
|
||||
}
|
||||
@@ -37,19 +37,12 @@ namespace python = boost::python;
|
||||
|
||||
BOOST_PYTHON_MODULE_INIT(getting_started1)
|
||||
{
|
||||
try
|
||||
{
|
||||
// Create an object representing this extension module.
|
||||
python::module_builder this_module("getting_started1");
|
||||
|
||||
// Add regular functions to the module.
|
||||
this_module.def(greet, "greet");
|
||||
this_module.def(square, "square");
|
||||
}
|
||||
catch(...)
|
||||
{
|
||||
python::handle_exception(); // Deal with the exception for Python
|
||||
}
|
||||
}
|
||||
</pre>
|
||||
</blockquote>
|
||||
|
||||
@@ -47,8 +47,6 @@ namespace python = boost::python;
|
||||
|
||||
BOOST_PYTHON_MODULE_INIT(getting_started2)
|
||||
{
|
||||
try
|
||||
{
|
||||
// Create an object representing this extension module.
|
||||
python::module_builder this_module("getting_started2");
|
||||
|
||||
@@ -65,11 +63,6 @@ BOOST_PYTHON_MODULE_INIT(getting_started2)
|
||||
|
||||
// Even better, invite() can also be made a member of hello_class!!!
|
||||
hello_class.def(invite, "invite");
|
||||
}
|
||||
catch(...)
|
||||
{
|
||||
python::handle_exception(); // Deal with the exception for Python
|
||||
}
|
||||
}
|
||||
</blockquote></pre>
|
||||
<p>
|
||||
@@ -98,6 +91,12 @@ Notes:<ul>
|
||||
|
||||
<li>Any function added to a class whose initial argument matches the class (or
|
||||
any base) will act like a member function in Python.
|
||||
|
||||
<li>To define a nested class, just pass the enclosing
|
||||
<tt>class_builder</tt> (instead of a <tt>module_builder</tt>) as the
|
||||
first argument to the nested <tt>class_builder</tt>'s constructor.
|
||||
|
||||
|
||||
</ul>
|
||||
<p>
|
||||
We can even make a subclass of <code>hello.world</code>:
|
||||
|
||||
@@ -78,26 +78,19 @@ namespace python = boost::python;
|
||||
|
||||
BOOST_PYTHON_MODULE_INIT(my_module)
|
||||
{
|
||||
try
|
||||
{
|
||||
python::module_builder my_module("my_module");
|
||||
|
||||
python::class_builder<Base> base_class(my_module, "Base");
|
||||
base_class.def(python::constructor<void>());
|
||||
|
||||
python::class_builder<Derived> derived_class(my_module, "Derived");
|
||||
derived_class.def(python::constructor<void>());
|
||||
<b>// Establish the inheritance relationship between Base and Derived
|
||||
derived_class.declare_base(base_class);</b>
|
||||
|
||||
my_module.def(derived_as_base, "derived_as_base");
|
||||
my_module.def(get_name, "get_name");
|
||||
my_module.def(get_derived_x, "get_derived_x");
|
||||
}
|
||||
catch(...)
|
||||
{
|
||||
python::handle_exception(); // Deal with the exception for Python
|
||||
}
|
||||
python::module_builder my_module("my_module");
|
||||
|
||||
python::class_builder<Base> base_class(my_module, "Base");
|
||||
base_class.def(python::constructor<void>());
|
||||
|
||||
python::class_builder<Derived> derived_class(my_module, "Derived");
|
||||
derived_class.def(python::constructor<void>());
|
||||
<b>// Establish the inheritance relationship between Base and Derived
|
||||
derived_class.declare_base(base_class);</b>
|
||||
|
||||
my_module.def(derived_as_base, "derived_as_base");
|
||||
my_module.def(get_name, "get_name");
|
||||
my_module.def(get_derived_x, "get_derived_x");
|
||||
}
|
||||
</pre>
|
||||
</blockquote>
|
||||
|
||||
326
doc/new-conversions.html
Normal file
326
doc/new-conversions.html
Normal file
@@ -0,0 +1,326 @@
|
||||
<html>
|
||||
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
|
||||
<title>A New Type Conversion Mechanism for Boost.Python</title>
|
||||
</head>
|
||||
|
||||
<body bgcolor="#FFFFFF" text="#000000">
|
||||
|
||||
<p><img border="0" src="../../../c++boost.gif" width="277" height="86"
|
||||
alt="boost logo"></p>
|
||||
|
||||
<h1>A New Type Conversion Mechanism for Boost.Python</h1>
|
||||
|
||||
<p>By <a href="../../../people/dave_abrahams.htm">David Abrahams</a>.
|
||||
|
||||
<h2>Introduction</h2>
|
||||
|
||||
This document describes a redesign of the mechanism for automatically
|
||||
converting objects between C++ and Python. The current implementation
|
||||
uses two functions for any type <tt>T</tt>:
|
||||
|
||||
<blockquote><pre>
|
||||
U from_python(PyObject*, type<T>);
|
||||
void to_python(V);
|
||||
</pre></blockquote>
|
||||
|
||||
where U is convertible to T and T is convertible to V. These functions
|
||||
are at the heart of C++/Python interoperability in Boost.Python, so
|
||||
why would we want to change them? There are many reasons:
|
||||
|
||||
<h3>Bugs</h3>
|
||||
<p>Firstly, the current mechanism relies on a common C++ compiler
|
||||
bug. This is not just embarrassing: as compilers get to be more
|
||||
conformant, the library stops working. The issue, in detail, is the
|
||||
use of inline friend functions in templates to generate
|
||||
conversions. It is a very powerful, and legal technique as long as
|
||||
it's used correctly:
|
||||
|
||||
<blockquote><pre>
|
||||
template <class Derived>
|
||||
struct add_some_functions
|
||||
{
|
||||
friend <i>return-type</i> some_function1(..., Derived <i>cv-*-&-opt</i>, ...);
|
||||
friend <i>return-type</i> some_function2(..., Derived <i>cv-*-&-opt</i>, ...);
|
||||
};
|
||||
|
||||
template <class T>
|
||||
struct some_template : add_some_functions<some_template<T> >
|
||||
{
|
||||
};
|
||||
</pre></blockquote>
|
||||
|
||||
The <tt>add_some_functions</tt> template generates free functions
|
||||
which operate on <tt>Derived</tt>, or on related types. Strictly
|
||||
speaking the related types are not just cv-qualified <tt>Derived</tt>
|
||||
values, pointers and/or references. Section 3.4.2 in the standard
|
||||
describes exactly which types you must use as parameters to these
|
||||
functions if you want the functions to be found
|
||||
(there is also a less-technical description in section 11.5.1 of
|
||||
C++PL3 <a href="#ref_1">[1]</a>). Suffice it to say that
|
||||
with the current design, the <tt>from_python</tt> and
|
||||
<tt>to_python</tt> functions are not supposed to be callable under any
|
||||
conditions!
|
||||
|
||||
<h3>Compilation and Linking Time</h3>
|
||||
|
||||
The conversion functions generated for each wrapped class using the
|
||||
above technique are not function templates, but regular functions. The
|
||||
upshot is that they must <i>all</i> be generated regardless of whether
|
||||
they are actually used. Generating all of those functions can slow
|
||||
down module compilation, and resolving the references can slow down
|
||||
linking.
|
||||
|
||||
<h3>Efficiency</h3>
|
||||
|
||||
The conversion functions are primarily used in (member) function
|
||||
wrappers to convert the arguments and return values. Being functions,
|
||||
converters have no interface which allows us to ask "will the
|
||||
conversion succeed?" without calling the function. Since the
|
||||
return value of the function must be the object to be passed as an
|
||||
argument, Boost.Python currently uses C++ exception-handling to detect
|
||||
an unsuccessful conversion. It's not a particularly good use of
|
||||
exception-handling, since the failure is not handled very far from
|
||||
where it occurred. More importantly, it means that C++ exceptions are
|
||||
thrown during overload resolution as we seek an overload that matches
|
||||
the arguments passed. Depending on the implementation, this approach
|
||||
can result in significant slowdowns.
|
||||
|
||||
<p>It is also unclear that the current library generates a minimal
|
||||
amount of code for any type conversion. Many of the conversion
|
||||
functions are nontrivial, and partly because of compiler limitations,
|
||||
they are declared <tt>inline</tt>. Also, we could have done a better
|
||||
job separating the type-specific conversion code from the code which
|
||||
is type-independent.
|
||||
|
||||
<h3>Cross-module Support</h3>
|
||||
|
||||
The current strategy requires every module to contain the definition
|
||||
of conversions it uses. In general, a new module can never supply
|
||||
conversion code which is used by another module. Ralf Grosse-Kunstleve
|
||||
designed a clever system which imports conversions directly from one
|
||||
library into another using some explicit declarations, but it has some
|
||||
disadvantages also:
|
||||
|
||||
<ol>
|
||||
<li>The system Ullrich Koethe designed for implicit conversion between
|
||||
wrapped classes related through inheritance does not currently work if
|
||||
the classes are defined in separate modules.
|
||||
|
||||
<li>The writer of the importing module is required to know the name of
|
||||
the module supplying the imported conversions.
|
||||
|
||||
<li>There can be only one way to extract any given C++ type from a
|
||||
Python object in a given module.
|
||||
</ol>
|
||||
|
||||
The first item might be addressed by moving Boost.Python into a shared
|
||||
library, but the other two cannot. Ralf turned the limitation in item
|
||||
two into a feature: the required module is loaded implicitly when a
|
||||
conversion it defines is invoked. We will probably want to provide
|
||||
that functionality anyway, but it's not clear that we should require
|
||||
the declaration of all such conversions. The final item is a more
|
||||
serious limitation. If, for example, new numeric types are defined in
|
||||
separate modules, and these types can all be converted to
|
||||
<tt>double</tt>s, we have to choose just one conversion method.
|
||||
|
||||
<h3>Ease-of-use</h3>
|
||||
|
||||
One persistent source of confusion for users of Boost.Python has been
|
||||
the fact that conversions for a class are not be visible at
|
||||
compile-time until the declaration of that class has been seen. When
|
||||
the user tries to expose a (member) function operating on or returning
|
||||
an instance of the class in question, compilation fails...even though
|
||||
the user goes on to expose the class in the same translation unit!
|
||||
|
||||
<p>
|
||||
The new system lifts all compile-time checks for the existence of
|
||||
particular type conversions and replaces them with runtime checks, in
|
||||
true Pythonic style. While this might seem cavalier, the compile-time
|
||||
checks are actually not much use in the current system if many classes
|
||||
are wrapped in separate modules, since the checks are based only on
|
||||
the user's declaration that the conversions exist.
|
||||
|
||||
<h2>The New Design</h2>
|
||||
|
||||
<h3>Motivation</h3>
|
||||
|
||||
The new design was heavily influenced by a desire to generate as
|
||||
little code as possible in extension modules. Some of Boost.Python's
|
||||
clients are enormous projects where link time is proportional to the
|
||||
amount of object code, and there are many Python extension modules. As
|
||||
such, we try to keep type-specific conversion code out of modules
|
||||
other than the one the converters are defined in, and rely as much as
|
||||
possible on centralized control through a shared library.
|
||||
|
||||
<h3>The Basics</h3>
|
||||
|
||||
The library contains a <tt>registry</tt> which maps runtime type
|
||||
identifiers (actually an extension of <tt>std::type_info</tt> which
|
||||
preserves references and constness) to entries containing type
|
||||
converters. An <tt>entry</tt> can contain only one converter from C++ to Python
|
||||
(<tt>wrapper</tt>), but many converters from Python to C++
|
||||
(<tt>unwrapper</tt>s). <font color="#ff0000">What should happen if
|
||||
multiple modules try to register wrappers for the same type?</font>. Wrappers
|
||||
and unwrappers are known as <tt>body</tt> objects, and are accessed
|
||||
by the user and the library (in its function-wrapping code) through
|
||||
corresponding <tt>handle</tt> (<tt>wrap<T></tt> and
|
||||
<tt>unwrap<T></tt>) objects. The <tt>handle</tt> objects are
|
||||
extremely lightweight, and delegate <i>all</i> of their operations to
|
||||
the corresponding <tt>body</tt>.
|
||||
|
||||
<p>
|
||||
When a <tt>handle</tt> object is constructed, it accesses the
|
||||
registry to find a corresponding <tt>body</tt> that can convert the
|
||||
handle's constructor argument. Actually the registry record for any
|
||||
type
|
||||
<tt>T</tt>used in a module is looked up only once and stored in a
|
||||
static <tt>registration<T></tt> object for efficiency. For
|
||||
example, if the handle is an <tt>unwrap<Foo&></tt> object,
|
||||
the <tt>entry</tt> for <tt>Foo&</tt> is looked up in the
|
||||
<tt>registry</tt>, and each <tt>unwrapper</tt> it contains is queried
|
||||
to determine if it can convert the
|
||||
<tt>PyObject*</tt> with which the <tt>unwrap</tt> was constructed. If
|
||||
a body object which can perform the conversion is found, a pointer to
|
||||
it is stored in the handle. A body object may at any point store
|
||||
additional data in the handle to speed up the conversion process.
|
||||
|
||||
<p>
|
||||
Now that the handle has been constructed, the user can ask it whether
|
||||
the conversion can be performed. All handles can be tested as though
|
||||
they were convertible to <tt>bool</tt>; a <tt>true</tt> value
|
||||
indicates success. If the user forges ahead and tries to do the
|
||||
conversion without checking when no conversion is possible, an
|
||||
exception will be thrown as usual. The conversion itself is performed
|
||||
by the body object.
|
||||
|
||||
<h3>Handling complex conversions</h3>
|
||||
|
||||
<p>Some conversions may require a dynamic allocation. For example,
|
||||
when a Python tuple is converted to a <tt>std::vector<double>
|
||||
const&</tt>, we need some storage into which to construct the
|
||||
vector so that a reference to it can be formed. Furthermore, multiple
|
||||
conversions of the same type may need to be "active"
|
||||
simultaneously, so we can't keep a single copy of the storage
|
||||
anywhere. We could keep the storage in the <tt>body</tt> object, and
|
||||
have the body clone itself in case the storage is used, but in that
|
||||
case the storage in the body which lives in the registry is never
|
||||
used. If the storage was actually an object of the target type (the
|
||||
safest way in C++), we'd have to find a way to construct one for the
|
||||
body in the registry, since it may not have a default constructor.
|
||||
|
||||
<p>
|
||||
The most obvious way out of this quagmire is to allocate the object using a
|
||||
<i>new-expression</i>, and store a pointer to it in the handle. Since
|
||||
the <tt>body</tt> object knows everything about the data it needs to
|
||||
allocate (if any), it is also given responsibility for destroying that
|
||||
data. When the <tt>handle</tt> is destroyed it asks the <tt>body</tt>
|
||||
object to tear down any data it may have stored there. In many ways,
|
||||
you can think of the <tt>body</tt> as a "dynamically-determined
|
||||
vtable" for the handle.
|
||||
|
||||
<h3>Eliminating Redundancy</h3>
|
||||
|
||||
If you look at the current Boost.Python code, you'll see that there
|
||||
are an enormous number of conversion functions generated for each
|
||||
wrapped class. For a given class <tt>T</tt>, functions are generated
|
||||
to extract the following types <tt>from_python</tt>:
|
||||
|
||||
<blockquote><pre>
|
||||
T*
|
||||
T const*
|
||||
T const* const&
|
||||
T* const&
|
||||
T&
|
||||
T const&
|
||||
T
|
||||
std::auto_ptr<T>&
|
||||
std::auto_ptr<T>
|
||||
std::auto_ptr<T> const&
|
||||
boost::shared_ptr<T>&
|
||||
boost::shared_ptr<T>
|
||||
boost::shared_ptr<T> const&
|
||||
</pre></blockquote>
|
||||
|
||||
Most of these are implemented in terms of just a few conversions, and
|
||||
<t>if you're lucky</t>, they will be inlined and cause no extra
|
||||
overhead. In the new system, however, a significant amount of data
|
||||
will be associated with each type that needs to be converted. We
|
||||
certainly don't want to register a separate unwrapper object for all
|
||||
of the above types.
|
||||
|
||||
<p>Fortunately, much of the redundancy can be eliminated. For example,
|
||||
if we generate an unwrapper for <tt>T&</tt>, we don't need an
|
||||
unwrapper for <tt>T const&</tt> or <tt>T</tt>. Accordingly, the user's
|
||||
request to wrap/unwrap a given type is translated at compile-time into
|
||||
a request which helps to eliminate redundancy. The rules used to
|
||||
<tt>unwrap</tt> a type are:
|
||||
|
||||
<ol>
|
||||
<li> Treat built-in types specially: when unwrapping a value or
|
||||
constant reference to one of these, use a value for the target
|
||||
type. It will bind to a const reference if neccessary, and more
|
||||
importantly, avoids having to dynamically allocate room for
|
||||
an lvalue of types which can be cheaply copied.
|
||||
<li>
|
||||
Reduce everything else to a reference to an un-cv-qualified type
|
||||
where possible. Since cv-qualification is lost on Python
|
||||
anyway, there's no point in trying to convert to a
|
||||
<tt>const&</tt>. <font color="#ff0000">What about conversions
|
||||
to values like the tuple->vector example above? It seems to me
|
||||
that we don't want to make a <tt>vector<double>&</tt>
|
||||
(non-const) converter available for that case. We may need to
|
||||
rethink this slightly.</font>
|
||||
</ol>
|
||||
|
||||
<p>To handle the problem described above in item 2, we modify the
|
||||
procedure slightly. To unwrap any non-scalar <tt>T</tt>, we seek an
|
||||
unwrapper for <tt>add_reference<T>::type</tt>. Unwrappers for
|
||||
<tt>T const&</tt> always return <tt>T&</tt>, and are
|
||||
registered under both <tt>T &</tt> and
|
||||
<tt>T const&</tt>.
|
||||
|
||||
<p>For compilers not supporting partial specialization, unwrappers for
|
||||
<tt>T const&</tt> must return <tt>T const&</tt>
|
||||
(since constness can't be stripped), but a separate unwrapper object
|
||||
need to be registered for <tt>T &</tt> and
|
||||
<tt>T const&</tt> anyway, for the same reasons.
|
||||
|
||||
<font color="#ff0000">We may want to make it possible to compile as
|
||||
though partial specialization were unavailable even on compilers where
|
||||
it is available, in case modules could be compiled by different
|
||||
compilers with compatible ABIs (e.g. Intel C++ and MSVC6).</font>
|
||||
|
||||
<h3>Efficient Argument Conversion</h3>
|
||||
|
||||
Since type conversions are primarily used in function wrappers, an
|
||||
optimization is provided for the case where a group of conversions are
|
||||
used together. Each <tt>handle</tt> class has a corresponding
|
||||
"<tt>_more</tt>" class which does the same job, but has a
|
||||
trivial destructor. Instead of asking each "<tt>_more</tt>"
|
||||
handle to destroy its own body, it is linked into an endogenous list
|
||||
managed by the first (ordinary) handle. The <tt>wrap</tt> and
|
||||
<tt>unwrap</tt> destructors are responsible for traversing that list
|
||||
and asking each <tt>body</tt> class to tear down its
|
||||
<tt>handle</tt>. This mechanism is also used to determine if all of
|
||||
the argument/return-value conversions can succeed with a single
|
||||
function call in the function wrapping code. <font color="#ff0000">We
|
||||
might need to handle return values in a separate step for Python
|
||||
callbacks, since the availablility of a conversion won't be known
|
||||
until the result object is retrieved.</font>
|
||||
|
||||
<br>
|
||||
<hr>
|
||||
<h2>References</h2>
|
||||
|
||||
<p><a name="ref_1">[1]</a>B. Stroustrup, The C++ Programming Language
|
||||
Special Edition Addison-Wesley, ISBN 0-201-70073-5.
|
||||
|
||||
<hr>
|
||||
<p>Revised <!--webbot bot="Timestamp" s-type="EDITED" s-format="%d %B %Y" startspan -->19 December 2001<!--webbot bot="Timestamp" endspan i-checksum="31283" --></p>
|
||||
<p>© Copyright David Abrahams, 2001</p>
|
||||
|
||||
</body>
|
||||
|
||||
</html>
|
||||
111
doc/new-conversions.txt
Normal file
111
doc/new-conversions.txt
Normal file
@@ -0,0 +1,111 @@
|
||||
This hierarchy contains converter handle classes.
|
||||
|
||||
|
||||
+-------------+
|
||||
| noncopyable |
|
||||
+-------------+
|
||||
^
|
||||
| A common base class used so that
|
||||
+--------+--------+ conversions can be linked into a
|
||||
| conversion_base | chain for efficient argument
|
||||
+-----------------+ conversion
|
||||
^
|
||||
|
|
||||
+---------+-----------+
|
||||
| |
|
||||
+-----------+----+ +------+-------+ only used for
|
||||
| unwrap_more<T> | | wrap_more<T> | chaining, and don't manage any
|
||||
+----------------+ +--------------+ resources.
|
||||
^ ^
|
||||
| |
|
||||
+-----+-----+ +-------+-+ These converters are what users
|
||||
| unwrap<T> | | wrap<T> | actually touch, but they do so
|
||||
+-----------+ +---------+ through a type generator which
|
||||
minimizes the number of converters
|
||||
that must be generated, so they
|
||||
|
||||
|
||||
Each unwrap<T>, unwrap_more<T>, wrap<T>, wrap_more<T> converter holds
|
||||
a reference to an appropriate converter object
|
||||
|
||||
This hierarchy contains converter body classes
|
||||
|
||||
Exposes use/release which
|
||||
are needed in case the converter
|
||||
+-----------+ in the registry needs to be
|
||||
| converter | cloned. That occurs when a
|
||||
+-----------+ unwrap target type is not
|
||||
^ contained within the Python object.
|
||||
|
|
||||
+------------------+-----+
|
||||
| |
|
||||
+--------+-------+ Exposes |
|
||||
| unwrapper_base | convertible() |
|
||||
+----------------+ |
|
||||
^ |
|
||||
| |
|
||||
+--------+----+ +-----+-----+
|
||||
| unwrapper<T>| | wrapper<T>|
|
||||
+-------------+ +-----------+
|
||||
Exposes T convert(PyObject*) Exposes PyObject* convert(T)
|
||||
|
||||
|
||||
unwrap:
|
||||
|
||||
constructed with a PyObject*, whose reference count is
|
||||
incremented.
|
||||
|
||||
find the registry entry for the target type
|
||||
|
||||
look in the collection of converters for one which claims to be
|
||||
able to convert the PyObject to the target type.
|
||||
|
||||
stick a pointer to the unwrapper in the unwrap object
|
||||
|
||||
when unwrap is queried for convertibility, it checks to see
|
||||
if it has a pointer to an unwrapper.
|
||||
|
||||
on conversion, the unwrapper is asked to allocate an
|
||||
implementation if the unwrap object isn't already holding
|
||||
one. The unwrap object "takes ownership" of the unwrapper's
|
||||
implementation. No memory allocation will actually take place
|
||||
unless this is a value conversion.
|
||||
|
||||
on destruction, the unwrapper is asked to free any implementation
|
||||
held by the unwrap object. No memory deallocation actually
|
||||
takes place unless this is a value conversion
|
||||
|
||||
on destruction, the reference count on the held PyObject is
|
||||
decremented.
|
||||
|
||||
We need to make sure that by default, you can't instantiate
|
||||
callback<> for reference and pointer return types: although the
|
||||
unwrappers may exist, they may convert by-value, which would cause
|
||||
the referent to be destroyed upon return.
|
||||
|
||||
wrap:
|
||||
|
||||
find the registry entry for the source type
|
||||
|
||||
see if there is a converter. If found, stick a pointer to it in
|
||||
the wrap object.
|
||||
|
||||
when queried for convertibility, it checks to see if it has a
|
||||
pointer to a converter.
|
||||
|
||||
on conversion, a reference to the target PyObject is held by the
|
||||
converter. Generally, the PyObject will have been created by the
|
||||
converter, but in certain cases it may be a pre-existing object,
|
||||
whose reference count will have been incremented.
|
||||
|
||||
when a wrap<T> x is used to return from a C++ function,
|
||||
x.release() is returned so that x no longer holds a reference to
|
||||
the PyObject when destroyed.
|
||||
|
||||
Otherwise, on destruction, any PyObject still held has its
|
||||
reference-count decremented.
|
||||
|
||||
|
||||
When a converter is created by the user, the appropriate element must
|
||||
be added to the registry; when it is destroyed, it must be removed
|
||||
from the registry.
|
||||
@@ -151,16 +151,9 @@ struct baz_callback {
|
||||
|
||||
BOOST_PYTHON_MODULE_INIT(foobar)
|
||||
{
|
||||
try
|
||||
{
|
||||
boost::python::module_builder foobar("foobar");
|
||||
boost::python::class_builder<baz,baz_callback> baz_class("baz");
|
||||
baz_class.def(&baz::calls_pure, "calls_pure");
|
||||
}
|
||||
catch(...)
|
||||
{
|
||||
boost::python::handle_exception(); // Deal with the exception for Python
|
||||
}
|
||||
boost::python::module_builder foobar("foobar");
|
||||
boost::python::class_builder<baz,baz_callback> baz_class("baz");
|
||||
baz_class.def(&baz::calls_pure, "calls_pure");
|
||||
}
|
||||
</pre>
|
||||
</blockquote>
|
||||
|
||||
@@ -287,6 +287,35 @@ bignum_class.def(&rmod, "__rmod__");
|
||||
found first (be it ``<code>int</code>`` or ``<code>float</code>'') will be
|
||||
used for either of the two types.
|
||||
|
||||
<h3><a name="inplace">Inplace Operators</a></h3>
|
||||
<p>
|
||||
Boost.Python can also be used to expose inplace numeric operations
|
||||
(i.e., <code>+=</code> and so forth). These operators must be wrapped
|
||||
manually, as described in the previous section. For example, suppose
|
||||
the class BigNum has an <code>operator+=</code>:
|
||||
|
||||
<blockquote><pre>
|
||||
BigNum& operator+= (BigNum const& right);
|
||||
</pre></blockquote>
|
||||
|
||||
This can be exposed by first writing a wrapper function:
|
||||
|
||||
<blockquote><pre>
|
||||
BigNum& iadd (BigNum& self, const BigNum& right)
|
||||
{
|
||||
return self += right;
|
||||
}
|
||||
</pre></blockquote>
|
||||
|
||||
and then exposing the wrapper with
|
||||
|
||||
<blockquote><pre>
|
||||
bignum_class.def(&iadd, "__iadd__");
|
||||
</pre></blockquote>
|
||||
|
||||
|
||||
|
||||
|
||||
<h3><a name="coercion">Coercion</a></h3>
|
||||
|
||||
|
||||
|
||||
31
doc/v2/acknowledgments.html
Normal file
31
doc/v2/acknowledgments.html
Normal file
@@ -0,0 +1,31 @@
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
|
||||
<link rel="stylesheet" type="text/css" href="../boost.css">
|
||||
<title>Boost.Python - Acknowledgments</title>
|
||||
</head>
|
||||
<body link="#0000ff" vlink="#800080">
|
||||
<table border="0" cellpadding="7" cellspacing="0" width="100%" summary=
|
||||
"header">
|
||||
<tr>
|
||||
<td valign="top" width="300">
|
||||
<h3><a href="http://www.boost.org"><img height="86" width="277" alt="C++ Boost" src="../c++boost.gif" border="0"></a></h3>
|
||||
</td>
|
||||
<td valign="top">
|
||||
<h1 align="center">Boost.Python</h1>
|
||||
<h2 align="center">Acknowledgments</h2>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<hr>
|
||||
{{text}}
|
||||
<hr>
|
||||
<p>Revised
|
||||
<!--webbot bot="Timestamp" S-Type="EDITED" S-Format="%d %B, %Y" startspan -->
|
||||
05 November, 2002
|
||||
<!--webbot bot="Timestamp" endspan i-checksum="39359" -->
|
||||
</p>
|
||||
<p><i>© Copyright <a href="../../../../people/dave_abrahams.htm">Dave Abrahams</a>
|
||||
2002. All Rights Reserved.</i></p>
|
||||
</body>
|
||||
</html>
|
||||
31
doc/v2/bibliography.html
Normal file
31
doc/v2/bibliography.html
Normal file
@@ -0,0 +1,31 @@
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
|
||||
<link rel="stylesheet" type="text/css" href="../boost.css">
|
||||
<title>Boost.Python - Bibliography</title>
|
||||
</head>
|
||||
<body link="#0000ff" vlink="#800080">
|
||||
<table border="0" cellpadding="7" cellspacing="0" width="100%" summary=
|
||||
"header">
|
||||
<tr>
|
||||
<td valign="top" width="300">
|
||||
<h3><a href="http://www.boost.org"><img height="86" width="277" alt="C++ Boost" src="../c++boost.gif" border="0"></a></h3>
|
||||
</td>
|
||||
<td valign="top">
|
||||
<h1 align="center">Boost.Python</h1>
|
||||
<h2 align="center">Bibliography</h2>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<hr>
|
||||
{{bibliographical information}}
|
||||
<hr>
|
||||
<p>Revised
|
||||
<!--webbot bot="Timestamp" S-Type="EDITED" S-Format="%d %B, %Y" startspan -->
|
||||
05 November, 2002
|
||||
<!--webbot bot="Timestamp" endspan i-checksum="39359" -->
|
||||
</p>
|
||||
<p><i>© Copyright <a href="../../../../people/dave_abrahams.htm">Dave Abrahams</a>
|
||||
2002. All Rights Reserved.</i></p>
|
||||
</body>
|
||||
</html>
|
||||
62
doc/v2/call.html
Normal file
62
doc/v2/call.html
Normal file
@@ -0,0 +1,62 @@
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
|
||||
<link rel="stylesheet" type="text/css" href="../boost.css">
|
||||
<title>Boost.Python - <call.hpp></title>
|
||||
</head>
|
||||
<body link="#0000ff" vlink="#800080">
|
||||
<table border="0" cellpadding="7" cellspacing="0" width="100%" summary=
|
||||
"header">
|
||||
<tr>
|
||||
<td valign="top" width="300">
|
||||
<h3><a href="http://www.boost.org"><img height="86" width="277" alt="C++ Boost" src="../c++boost.gif" border="0"></a></h3>
|
||||
</td>
|
||||
<td valign="top">
|
||||
<h1 align="center">Boost.Python</h1>
|
||||
<h2 align="center">Header <call.hpp></h2>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<hr>
|
||||
<h2>Contents</h2>
|
||||
<dl class="page-index">
|
||||
<dt><a href="#introduction">Introduction</a></dt>
|
||||
|
||||
<dt><a href="#functions">Functions</a></dt>
|
||||
<dl class="page-index">
|
||||
<dt><a href="#call-spec">call</a></dt>
|
||||
</dl>
|
||||
|
||||
<dt><a href="#examples">Example(s)</a></dt>
|
||||
|
||||
</dl>
|
||||
<hr>
|
||||
<h2><a name="introduction"></a>Introduction</h2>
|
||||
<p>{{Introductory text}}</p>
|
||||
|
||||
<h2><a name="functions"></a>Functions</h2>
|
||||
<pre>
|
||||
<a name="call-spec"></a>call
|
||||
</pre>
|
||||
<dl class="function-semantics">
|
||||
<dt><b>Requires:</b> {{text}}</dt>
|
||||
<dt><b>Effects:</b> {{text}}</dt>
|
||||
<dt><b>Postconditions:</b> {{text}}</dt>
|
||||
<dt><b>Returns:</b> {{text}}</dt>
|
||||
<dt><b>Throws:</b> {{text}}</dt>
|
||||
<dt><b>Complexity:</b> {{text}}</dt>
|
||||
<dt><b>Rationale:</b> {{text}}</dt>
|
||||
</dl>
|
||||
|
||||
<h2><a name="examples"></a>Example(s)</h2>
|
||||
|
||||
<p>{{Example(s)}}</p>
|
||||
<p>Revised
|
||||
<!--webbot bot="Timestamp" S-Type="EDITED" S-Format="%d %B, %Y" startspan -->
|
||||
05 November, 2002
|
||||
<!--webbot bot="Timestamp" endspan i-checksum="39359" -->
|
||||
</p>
|
||||
<p><i>© Copyright <a href="../../../../people/dave_abrahams.htm">Dave Abrahams</a>
|
||||
2002. All Rights Reserved.</i></p>
|
||||
</body>
|
||||
</html>
|
||||
337
doc/v2/class.html
Normal file
337
doc/v2/class.html
Normal file
@@ -0,0 +1,337 @@
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
|
||||
<meta name="generator" content="HTML Tidy, see www.w3.org">
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
|
||||
<link rel="stylesheet" type="text/css" href="../boost.css">
|
||||
|
||||
<title>Boost.Python - <boost/python/class.hpp>,
|
||||
<boost/python/class_fwd.hpp></title>
|
||||
|
||||
<table border="0" cellpadding="7" cellspacing="0" width="100%" summary=
|
||||
"header">
|
||||
<tr>
|
||||
<td valign="top" width="300">
|
||||
<h3><a href="../../../../index.htm"><img height="86" width="277" alt=
|
||||
"C++ Boost" src="../../../../c++boost.gif" border="0"></a></h3>
|
||||
|
||||
<td valign="top">
|
||||
<h1 align="center">Boost.Python</h1>
|
||||
|
||||
<h2 align="center">Headers <boost/python/class.hpp>,
|
||||
<boost/python/class_fwd.hpp></h2>
|
||||
</table>
|
||||
<hr>
|
||||
|
||||
<h2>Contents</h2>
|
||||
|
||||
<dl class="page-index">
|
||||
<dt><a href="#introduction">Introduction</a>
|
||||
|
||||
<dt><a href="#classes">Classes</a>
|
||||
|
||||
<dd>
|
||||
<dl class="page-index">
|
||||
<dt><a href="#class_-spec">Class template <code>class_</code></a>
|
||||
|
||||
<dd>
|
||||
<dl class="page-index">
|
||||
<dt><a href="#class_-spec-synopsis">Class <code>class_</code>
|
||||
synopsis</a>
|
||||
|
||||
<dt><a href="#class_-spec-ctors">Class <code>class_</code>
|
||||
constructors</a>
|
||||
|
||||
<dt><a href="#class_-spec-modifiers">Class <code>class_</code>
|
||||
modifier functions</a>
|
||||
|
||||
<dt><a href="#class_-spec-observers">Class <code>class_</code>
|
||||
observer functions</a>
|
||||
</dl>
|
||||
|
||||
<dt><a href="#bases-spec">Class template <code>bases</code></a>
|
||||
|
||||
<dd>
|
||||
<dl class="page-index">
|
||||
<dt><a href="#bases-spec-synopsis">Class <code>bases</code>
|
||||
synopsis</a>
|
||||
</dl>
|
||||
|
||||
<dt><a href="#args-spec">Class template <code>args</code></a>
|
||||
|
||||
<dd>
|
||||
<dl class="page-index">
|
||||
<dt><a href="#args-spec-synopsis">Class <code>args</code>
|
||||
synopsis</a>
|
||||
</dl>
|
||||
</dl>
|
||||
|
||||
<dt><a href="#examples">Example(s)</a>
|
||||
</dl>
|
||||
<hr>
|
||||
|
||||
<h2><a name="introduction"></a>Introduction</h2>
|
||||
|
||||
<p><code><boost/python/class.hpp></code> defines the interface
|
||||
through which users expose their C++ classes to Python. It declares the
|
||||
<code>class_</code> class template, which is parameterized on the class
|
||||
type being exposed, and the <code>args</code> and <code>bases</code>
|
||||
utility class templates in the anonymous namespace (the latter definitions
|
||||
will probably be moved in a future release).
|
||||
|
||||
<p><code><boost/python/class_fwd.hpp></code> contains a forward
|
||||
declaration of the <code>class_</code> class template.
|
||||
|
||||
<h2><a name="classes"></a>Classes</h2>
|
||||
|
||||
<h3><a name="class_-spec"></a>Class template <code>class_<T, Bases, <a
|
||||
href="HolderGenerator.html">HolderGenerator</a>></code></h3>
|
||||
|
||||
<p>Creates a Python class associated with the C++ type passed as its first
|
||||
parameter. Its template arguments are:<br>
|
||||
<br>
|
||||
|
||||
|
||||
<table border="1" summary="class_ template parameters">
|
||||
<tr>
|
||||
<th>Parameter
|
||||
|
||||
<th>Requirements
|
||||
|
||||
<th>Default
|
||||
|
||||
<tr>
|
||||
<td><code>T</code>
|
||||
|
||||
<td>A class type.
|
||||
|
||||
<tr>
|
||||
<td><code>Bases</code>
|
||||
|
||||
<td>An <a href="../../../mpl/doc/Sequences.html">MPL sequence</a> of
|
||||
C++ base classes of <code>T</code>.
|
||||
|
||||
<td>An unspecified empty sequence
|
||||
|
||||
<tr>
|
||||
<td><code>HolderGenerator</code>
|
||||
|
||||
<td>A model of <code><a href=
|
||||
"HolderGenerator.html">HolderGenerator</a></code>.
|
||||
|
||||
<td><code>boost::python::objects::value_holder_generator</code>
|
||||
</table>
|
||||
|
||||
<h4><a name="class_-spec-synopsis"></a>Class template <code>class_</code>
|
||||
synopsis</h4>
|
||||
<pre>
|
||||
namespace boost { namespace python
|
||||
{
|
||||
|
||||
template <class T
|
||||
, class Bases = <i>none</i>
|
||||
, class HolderGenerator = objects::value_holder_generator>
|
||||
class class_
|
||||
{
|
||||
class_();
|
||||
class_(char const* name);
|
||||
|
||||
template <class F>
|
||||
class_& def(char const* name, F f);
|
||||
|
||||
template <class Fn, class CallPolicy>
|
||||
class_& def(char const* name, Fn fn, CallPolicy policy);
|
||||
|
||||
template <class Args>
|
||||
class_& def_init(Args const& = Args());
|
||||
|
||||
class_& def_init();
|
||||
|
||||
ref object() const;
|
||||
};
|
||||
}}
|
||||
</pre>
|
||||
|
||||
<h4><a name="class_-spec-ctors"></a>Class template <code>class_</code>
|
||||
constructors</h4>
|
||||
<pre>
|
||||
class_()
|
||||
</pre>
|
||||
|
||||
<dl class="function-semantics">
|
||||
<dt><b>Requires:</b> The platform's <code>std::type_info::name()</code>
|
||||
implementation produces a string which corresponds to the type's
|
||||
declaration in C++
|
||||
|
||||
<dt><b>Effects:</b> Constructs a <code>class_</code> object which
|
||||
generates a Boost.Python extension class with the same name as
|
||||
<code>T</code>.
|
||||
|
||||
<dt><b>Rationale:</b> Many platforms can generate reasonable names for
|
||||
Python classes without user intervention.
|
||||
</dl>
|
||||
<pre>
|
||||
class_(char const* name)
|
||||
</pre>
|
||||
|
||||
<dl class="function-semantics">
|
||||
<dt><b>Requires:</b> <code>name</code> is a ntbs which conforms to
|
||||
Python's <a href=
|
||||
"http://www.python.org/doc/2.2/ref/identifiers.html">identifier
|
||||
naming rules</a>.
|
||||
|
||||
<dt><b>Effects:</b> Constructs a <code>class_</code> object which
|
||||
generates a Boost.Python extension class named <code>name</code>.
|
||||
|
||||
<dt><b>Rationale:</b> Gives the user full control over class naming.
|
||||
</dl>
|
||||
|
||||
<h4><a name="class_-spec-modifiers"></a>Class template <code>class_</code>
|
||||
modifier functions</h4>
|
||||
<pre>
|
||||
template <class F>
|
||||
class_& def(char const* name, F f)
|
||||
|
||||
template <class Fn, class CallPolicy>
|
||||
class_& def(char const* name, Fn f, CallPolicy policy)
|
||||
</pre>
|
||||
|
||||
<dl class="function-semantics">
|
||||
<dt><b>Requires:</b> <code>f</code> is a non-null pointer-to-function or
|
||||
pointer-to-member-function. <code>name</code> is a ntbs which conforms to
|
||||
Python's <a href=
|
||||
"http://www.python.org/doc/2.2/ref/identifiers.html">identifier
|
||||
naming rules</a>. In the first form, the return type of
|
||||
<code>f</code> is not a reference and is not a pointer other
|
||||
than <code>char const*</code> or <code>PyObject*</code>. In the
|
||||
second form <code>policy</code> is a model of <a
|
||||
href="CallPolicies.html">CallPolicies</a>.
|
||||
|
||||
<dt><b>Effects:</b> Adds the result of <code><a href=
|
||||
"make_function.html#make_function-spec">make_function</a>(f)</code> to
|
||||
the Boost.Python extension class being defined, with the given
|
||||
<code>name</code>. If the extension class already has an attribute named
|
||||
<code><i>name</i></code>, the usual <a href=
|
||||
"overloading.html">overloading procedure</a> applies.
|
||||
|
||||
<dt><b>Returns:</b> <code>*this</code>
|
||||
</dl>
|
||||
<pre>
|
||||
template <class Args>
|
||||
class_& def_init(Args const& argument_types)
|
||||
|
||||
class_& def_init()
|
||||
</pre>
|
||||
|
||||
<dl class="function-semantics">
|
||||
<dt><b>Requires:</b> in the first form, argument_types must be an <a
|
||||
href="../../../mpl/doc/Sequences.html">MPL sequence</a> of C++ argument
|
||||
types (<i>A1, A2,... AN</i>) such that if
|
||||
<code>a1, a2</code>... <code>aN</code> are objects of type
|
||||
<i>A1, A2,... AN</i> respectively, the expression
|
||||
<code>T(a1, a2</code>... <code>aN</code>) is valid. In the second form,
|
||||
the expression <code>T()</code> must be valid.
|
||||
|
||||
<dt><b>Effects:</b> Adds the result of <code><a href=
|
||||
"make_function.html#make_constructor-spec">make_constructor</a><T,Args,HolderGenerator>()</code>
|
||||
to the Boost.Python extension class being defined with the name
|
||||
"__init__". If the 2nd form is used, an unspecified empty <a href=
|
||||
"../../../mpl/doc/Sequences.html">MPL sequence</a> type is substituted
|
||||
for <code>Args</code>. If the extension class already has an "__init__"
|
||||
attribute, the usual <a href="http:overloading.html">overloading
|
||||
procedure</a> applies.
|
||||
|
||||
<dt><b>Returns:</b> <code>*this</code>
|
||||
|
||||
<dt><b>Rationale:</b> Allows users to easily expose a class' constructor
|
||||
to Python.
|
||||
</dl>
|
||||
|
||||
<h4><a name="class_-spec-observers"></a>Class template <code>class_</code>
|
||||
observer functions</h4>
|
||||
<pre>
|
||||
ref object() const;
|
||||
</pre>
|
||||
|
||||
<dl class="function-semantics">
|
||||
<dt><b>Returns:</b> A <code>ref</code> object which holds a reference to
|
||||
the Boost.Python extension class object created by the
|
||||
<code>class_</code> constructor.
|
||||
|
||||
<dt><b>Rationale:</b> Mostly not needed by users, since <code><a href=
|
||||
"module.html#add-spec">module::add</a>()</code> uses this to insert the
|
||||
extension class in the module.
|
||||
</dl>
|
||||
|
||||
<h3><a name="args-spec"></a>Class template
|
||||
<code>args<T1, T2,</code>...<code>TN></code></h3>
|
||||
|
||||
<p>Essentially an alias for <code>boost::mpl::type_list</code> which users
|
||||
can use in <code>def_init</code> calls to make their code more readable.
|
||||
Currently it is in the global unnammed namespace, but that will probably
|
||||
change.
|
||||
|
||||
<h4><a name="args-spec-synopsis"></a>Class template <code>args</code>
|
||||
synopsis</h4>
|
||||
<pre>
|
||||
namespace
|
||||
{
|
||||
template <T1 = <i>unspecified</i>,...TN = <i>unspecified</i>>
|
||||
struct args : ::boost::mpl::type_list<T1,...TN>::type
|
||||
{};
|
||||
}
|
||||
</pre>
|
||||
|
||||
<h3><a name="bases-spec"></a>Class template
|
||||
<code>bases<T1, T2,</code>...<code>TN></code></h3>
|
||||
|
||||
<p>Essentially an alias for <code>boost::mpl::type_list</code> which users
|
||||
can use in <code>class_<</code>...<code>></code> instantiations to
|
||||
make their code more readable. Currently it is in the global unnammed
|
||||
namespace, but that will probably change.
|
||||
|
||||
<h4><a name="bases-spec-synopsis"></a>Class template <code>bases</code>
|
||||
synopsis</h4>
|
||||
<pre>
|
||||
namespace
|
||||
{
|
||||
template <T1 = <i>unspecified</i>,...TN = <i>unspecified</i>>
|
||||
struct bases : ::boost::mpl::type_list<T1,...TN>::type
|
||||
{};
|
||||
}
|
||||
</pre>
|
||||
|
||||
<h2><a name="examples"></a>Example(s)</h2>
|
||||
|
||||
<p>Given a C++ class declaration:
|
||||
<pre>
|
||||
class Foo : public Bar, public Baz
|
||||
{
|
||||
public:
|
||||
Foo(int, char const*);
|
||||
Foo(double);
|
||||
|
||||
std::string const& name() { return m_name; }
|
||||
void name(char const*);
|
||||
private:
|
||||
...
|
||||
};
|
||||
</pre>
|
||||
A corresponding Boost.Python extension class can be created with:
|
||||
<pre>
|
||||
using namespace boost::python;
|
||||
ref foo =
|
||||
class_<Foo,bases<Bar,Baz> >()
|
||||
.def_init(args<int,char const*>())
|
||||
.def_init(args<double>())
|
||||
.def("get_name", &Foo::get_name, return_internal_reference<>())
|
||||
.def("set_name", &Foo::set_name)
|
||||
.object();
|
||||
</pre>
|
||||
Revised
|
||||
<!--webbot bot="Timestamp" S-Type="EDITED" S-Format="%d %B, %Y" startspan -->
|
||||
05 November, 2001
|
||||
<!--webbot bot="Timestamp" endspan i-checksum="39359" -->
|
||||
|
||||
|
||||
<p><i>© Copyright <a href="../../../../people/dave_abrahams.htm">Dave
|
||||
Abrahams</a> 2002. All Rights Reserved.</i>
|
||||
|
||||
90
doc/v2/configuration.html
Normal file
90
doc/v2/configuration.html
Normal file
@@ -0,0 +1,90 @@
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
|
||||
<link rel="stylesheet" type="text/css" href="../boost.css">
|
||||
<title>Boost.Python - Configuration</title>
|
||||
</head>
|
||||
<body link="#0000ff" vlink="#800080">
|
||||
<table border="0" cellpadding="7" cellspacing="0" width="100%" summary=
|
||||
"header">
|
||||
<tr>
|
||||
<td valign="top" width="300">
|
||||
<h3><a href="http://www.boost.org"><img height="86" width="277" alt="C++ Boost" src="../c++boost.gif" border="0"></a></h3>
|
||||
</td>
|
||||
<td valign="top">
|
||||
<h1 align="center">Boost.Python</h1>
|
||||
<h2 align="center">Configuration</h2>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<hr>
|
||||
<dl class="page-index">
|
||||
<dt><a href="#introduction">Introduction</a></dt>
|
||||
<dt><a href="#app-defined">Application Defined Macros</a></dt>
|
||||
<dt><a href="#lib-defined-public">Public Library Defined Macros</a></dt>
|
||||
<dt><a href="#lib-defined-impl">Library Defined Implementation Macros</a></dt>
|
||||
</dl>
|
||||
<h2><a name="introduction"></a>Introduction</h2>
|
||||
<p>Boost.Python uses several configuration macros in <a href="http://www.boost.org/libs/config/config.htm"><boost/config.hpp></a>,
|
||||
as well as configuration macros meant to be supplied by the application. These
|
||||
macros are documented here.</p>
|
||||
<h2><a name="app-defined"></a>Application Defined Macros</h2>
|
||||
<p>These are the macros that may be defined by an application using Boost.Python.</p>
|
||||
<table summary="application defined macros" cellspacing="10" width="100%">
|
||||
<tr>
|
||||
<td><b>Macro</b></td>
|
||||
<td><b>Meaning</b></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>{{macro}}</td>
|
||||
<td>{{meaning}}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>{{macro}}</td>
|
||||
<td>{{meaning}}</td>
|
||||
</tr>
|
||||
</table>
|
||||
<h2><a name="lib-defined-public"></a>Public Library Defined Macros</h2>
|
||||
<p>These macros are defined by Boost.Python but are expected to be used by application
|
||||
code.</p>
|
||||
<table summary="public library defined macros" cellspacing="10" width="100%">
|
||||
<tr>
|
||||
<td><b>Macro</b></td>
|
||||
<td><b>Meaning</b></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>{{macro}}</td>
|
||||
<td>{{meaning}}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>{{macro}}</td>
|
||||
<td>{{meaning}}</td>
|
||||
</tr>
|
||||
</table>
|
||||
<h2><a name="lib-defined-impl"></a>Library Defined Implementation Macros</h2>
|
||||
<p>These macros are defined by Boost.Python and are implementation details of interest
|
||||
only to implementers.</p>
|
||||
<table summary="library defined implementation macros" cellspacing="10" width="100%">
|
||||
<tr>
|
||||
<td><b>Macro</b></td>
|
||||
<td><b>Meaning</b></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>{{macro}}</td>
|
||||
<td>{{meaning}}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>{{macro}}</td>
|
||||
<td>{{meaning}}</td>
|
||||
</tr>
|
||||
</table>
|
||||
<hr>
|
||||
<p>Revised
|
||||
<!--webbot bot="Timestamp" S-Type="EDITED" S-Format="%d %B, %Y" startspan -->
|
||||
05 November, 2002
|
||||
<!--webbot bot="Timestamp" endspan i-checksum="39359" -->
|
||||
</p>
|
||||
<p><i>© Copyright <a href="../../../../people/dave_abrahams.htm">Dave Abrahams</a>
|
||||
2002. All Rights Reserved.</i></p>
|
||||
</body>
|
||||
</html>
|
||||
135
doc/v2/copy_const_reference.html
Normal file
135
doc/v2/copy_const_reference.html
Normal file
@@ -0,0 +1,135 @@
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
|
||||
<meta name="generator" content="HTML Tidy, see www.w3.org">
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
|
||||
<link rel="stylesheet" type="text/css" href="../boost.css">
|
||||
|
||||
<title>Boost.Python - <boost/python/copy_const_reference.hpp></title>
|
||||
|
||||
<table border="0" cellpadding="7" cellspacing="0" width="100%" summary=
|
||||
"header">
|
||||
<tr>
|
||||
<td valign="top" width="300">
|
||||
<h3><a href="../../../../index.htm"><img height="86" width="277" alt=
|
||||
"C++ Boost" src="../../../../c++boost.gif" border="0"></a></h3>
|
||||
|
||||
<td valign="top">
|
||||
<h1 align="center">Boost.Python</h1>
|
||||
|
||||
<h2 align="center">Header
|
||||
<boost/python/copy_const_reference.hpp></h2>
|
||||
</table>
|
||||
<hr>
|
||||
|
||||
<h2>Contents</h2>
|
||||
|
||||
<dl class="page-index">
|
||||
<dt><a href="#classes">Classes</a>
|
||||
|
||||
<dd>
|
||||
<dl class="page-index">
|
||||
<dt><a href="#copy_const_reference-spec">Class
|
||||
<code>copy_const_reference</code></a>
|
||||
|
||||
<dd>
|
||||
<dl class="page-index">
|
||||
<dt><a href="#copy_const_reference-spec-synopsis">Class
|
||||
<code>copy_const_reference</code> synopsis</a>
|
||||
|
||||
<dt><a href="#copy_const_reference-spec-metafunctions">Class
|
||||
<code>copy_const_reference</code> metafunctions</a>
|
||||
</dl>
|
||||
</dl>
|
||||
|
||||
<dt><a href="#examples">Example</a>
|
||||
</dl>
|
||||
<hr>
|
||||
|
||||
<h2><a name="classes"></a>Classes</h2>
|
||||
|
||||
<h3><a name="copy_const_reference-spec"></a>Class
|
||||
<code>copy_const_reference</code></h3>
|
||||
|
||||
<p><code>copy_const_reference</code> is a model of <a href=
|
||||
"ResultConverterGenerator.html">ResultConverterGenerator</a> which can be
|
||||
used to wrap C++ functions returning a reference-to-const type such that
|
||||
the referenced value is copied into a new Python object.
|
||||
|
||||
<h4><a name="copy_const_reference-spec-synopsis"></a>Class
|
||||
<code>copy_const_reference</code> synopsis</h4>
|
||||
<pre>
|
||||
namespace boost { namespace python
|
||||
{
|
||||
struct copy_const_reference
|
||||
{
|
||||
template <class T> struct apply;
|
||||
};
|
||||
}}
|
||||
</pre>
|
||||
|
||||
<h4><a name="copy_const_reference-spec-metafunctions"></a>Class
|
||||
<code>copy_const_reference</code> metafunctions</h4>
|
||||
<pre>
|
||||
template <class T> struct apply
|
||||
</pre>
|
||||
|
||||
<dl class="metafunction-semantics">
|
||||
<dt><b>Requires:</b> <code>T</code> is <code>U const&</code> for some
|
||||
<code>U</code>.
|
||||
|
||||
<dt><b>Returns:</b> <code>typedef <a href=
|
||||
"to_python_value.html#to_python_value-spec">to_python_value</a><T>
|
||||
type;</code>
|
||||
</dl>
|
||||
|
||||
<h2><a name="examples"></a>Example</h2>
|
||||
|
||||
<h3>C++ Module Definition</h3>
|
||||
<pre>
|
||||
#include <boost/python/module.hpp>
|
||||
#include <boost/python/class.hpp>
|
||||
#include <boost/python/copy_const_reference.hpp>
|
||||
#include <boost/python/return_value_policy.hpp>
|
||||
|
||||
// classes to wrap
|
||||
struct Bar { int x; }
|
||||
|
||||
struct Foo {
|
||||
Foo(int x) : { b.x = x; }
|
||||
Bar const& get_bar() const { return b; }
|
||||
private:
|
||||
Bar b;
|
||||
};
|
||||
|
||||
// Wrapper code
|
||||
using namespace boost::python;
|
||||
BOOST_PYTHON_MODULE_INIT(my_module)
|
||||
{
|
||||
module m("my_module")
|
||||
.add(
|
||||
class_<Bar>()
|
||||
)
|
||||
.add(
|
||||
class_<Foo>()
|
||||
.def_init(args<int>())
|
||||
.def("get_bar", &Foo::get_bar
|
||||
, return_value_policy<copy_const_reference>())
|
||||
)
|
||||
;
|
||||
}
|
||||
</pre>
|
||||
<h3>Python Code</h3>
|
||||
<pre>
|
||||
>>> from my_module import *
|
||||
>>> f = Foo(3) # create a Foo object
|
||||
>>> b = f.get_bar() # make a copy of the internal Bar object
|
||||
</pre>
|
||||
|
||||
<p>Revised
|
||||
<!--webbot bot="Timestamp" S-Type="EDITED" S-Format="%d %B, %Y" startspan -->
|
||||
15 February, 2002
|
||||
<!--webbot bot="Timestamp" endspan i-checksum="39359" -->
|
||||
|
||||
|
||||
<p><i>© Copyright <a href="../../../../people/dave_abrahams.htm">Dave
|
||||
Abrahams</a> 2002. All Rights Reserved.</i>
|
||||
|
||||
135
doc/v2/copy_non_const_reference.html
Normal file
135
doc/v2/copy_non_const_reference.html
Normal file
@@ -0,0 +1,135 @@
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
|
||||
<meta name="generator" content="HTML Tidy, see www.w3.org">
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
|
||||
<link rel="stylesheet" type="text/css" href="../boost.css">
|
||||
|
||||
<title>Boost.Python -
|
||||
<boost/python/copy_non_const_reference.hpp></title>
|
||||
|
||||
<table border="0" cellpadding="7" cellspacing="0" width="100%" summary=
|
||||
"header">
|
||||
<tr>
|
||||
<td valign="top" width="300">
|
||||
<h3><a href="../../../../index.htm"><img height="86" width="277" alt=
|
||||
"C++ Boost" src="../../../../c++boost.gif" border="0"></a></h3>
|
||||
|
||||
<td valign="top">
|
||||
<h1 align="center">Boost.Python</h1>
|
||||
|
||||
<h2 align="center">Header
|
||||
<boost/python/copy_non_const_reference.hpp></h2>
|
||||
</table>
|
||||
<hr>
|
||||
|
||||
<h2>Contents</h2>
|
||||
|
||||
<dl class="page-index">
|
||||
<dt><a href="#classes">Classes</a>
|
||||
|
||||
<dd>
|
||||
<dl class="page-index">
|
||||
<dt><a href="#copy_non_const_reference-spec">Class
|
||||
<code>copy_non_const_reference</code></a>
|
||||
|
||||
<dd>
|
||||
<dl class="page-index">
|
||||
<dt><a href="#copy_non_const_reference-spec-synopsis">Class
|
||||
<code>copy_non_const_reference</code> synopsis</a>
|
||||
|
||||
<dt><a href="#copy_non_const_reference-spec-metafunctions">Class
|
||||
<code>copy_non_const_reference</code> metafunctions</a>
|
||||
</dl>
|
||||
</dl>
|
||||
|
||||
<dt><a href="#examples">Example</a>
|
||||
</dl>
|
||||
<hr>
|
||||
|
||||
<h2><a name="classes"></a>Classes</h2>
|
||||
|
||||
<h3><a name="copy_non_const_reference-spec"></a>Class
|
||||
<code>copy_non_const_reference</code></h3>
|
||||
|
||||
<p><code>copy_non_const_reference</code> is a model of <a href=
|
||||
"ResultConverterGenerator.html">ResultConverterGenerator</a> which can be
|
||||
used to wrap C++ functions returning a reference-to-non-const type such
|
||||
that the referenced value is copied into a new Python object.
|
||||
|
||||
<h4><a name="copy_non_const_reference-spec-synopsis"></a>Class
|
||||
<code>copy_non_const_reference</code> synopsis</h4>
|
||||
<pre>
|
||||
namespace boost { namespace python
|
||||
{
|
||||
struct copy_non_const_reference
|
||||
{
|
||||
template <class T> struct apply;
|
||||
};
|
||||
}}
|
||||
</pre>
|
||||
|
||||
<h4><a name="copy_non_const_reference-spec-metafunctions"></a>Class
|
||||
<code>copy_non_const_reference</code> metafunctions</h4>
|
||||
<pre>
|
||||
template <class T> struct apply
|
||||
</pre>
|
||||
|
||||
<dl class="metafunction-semantics">
|
||||
<dt><b>Requires:</b> <code>T</code> is <code>U&</code> for some
|
||||
non-const <code>U</code>.
|
||||
|
||||
<dt><b>Returns:</b> <code>typedef <a href=
|
||||
"to_python_value.html#to_python_value-spec">to_python_value</a><T>
|
||||
type;</code>
|
||||
</dl>
|
||||
|
||||
<h2><a name="examples"></a>Example</h2>
|
||||
|
||||
<p>C++ code:
|
||||
<pre>
|
||||
#include <boost/python/module.hpp>
|
||||
#include <boost/python/class.hpp>
|
||||
#include <boost/python/copy_non_const_reference.hpp>
|
||||
#include <boost/python/return_value_policy.hpp>
|
||||
|
||||
// classes to wrap
|
||||
struct Bar { int x; }
|
||||
|
||||
struct Foo {
|
||||
Foo(int x) : { b.x = x; }
|
||||
Bar& get_bar() { return b; }
|
||||
private:
|
||||
Bar b;
|
||||
};
|
||||
|
||||
// Wrapper code
|
||||
using namespace boost::python;
|
||||
BOOST_PYTHON_MODULE_INIT(my_module)
|
||||
{
|
||||
module m("my_module")
|
||||
.add(
|
||||
class_<Bar>()
|
||||
)
|
||||
.add(
|
||||
class_<Foo>()
|
||||
.def_init(args<int>())
|
||||
.def("get_bar", &Foo::get_bar
|
||||
, return_value_policy<copy_non_const_reference>())
|
||||
);
|
||||
}
|
||||
</pre>
|
||||
Python Code:
|
||||
<pre>
|
||||
>>> from my_module import *
|
||||
>>> f = Foo(3) # create a Foo object
|
||||
>>> b = f.get_bar() # make a copy of the internal Bar object
|
||||
</pre>
|
||||
|
||||
<p>Revised
|
||||
<!--webbot bot="Timestamp" S-Type="EDITED" S-Format="%d %B, %Y" startspan -->
|
||||
05 November, 2001
|
||||
<!--webbot bot="Timestamp" endspan i-checksum="39359" -->
|
||||
|
||||
|
||||
<p><i>© Copyright <a href="../../../../people/dave_abrahams.htm">Dave
|
||||
Abrahams</a> 2002. All Rights Reserved.</i>
|
||||
|
||||
170
doc/v2/default_call_policies.html
Normal file
170
doc/v2/default_call_policies.html
Normal file
@@ -0,0 +1,170 @@
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
|
||||
<meta name="generator" content="HTML Tidy, see www.w3.org">
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
|
||||
<link rel="stylesheet" type="text/css" href="../boost.css">
|
||||
|
||||
<title>Boost.Python -
|
||||
<boost/python/default_call_policies.hpp></title>
|
||||
|
||||
<table border="0" cellpadding="7" cellspacing="0" width="100%" summary=
|
||||
"header">
|
||||
<tr>
|
||||
<td valign="top" width="300">
|
||||
<h3><a href="../../../../index.htm"><img height="86" width="277" alt=
|
||||
"C++ Boost" src="../../../../c++boost.gif" border="0"></a></h3>
|
||||
|
||||
<td valign="top">
|
||||
<h1 align="center">Boost.Python</h1>
|
||||
|
||||
<h2 align="center">Header
|
||||
<boost/python/default_call_policies.hpp></h2>
|
||||
</table>
|
||||
<hr>
|
||||
|
||||
<h2>Contents</h2>
|
||||
|
||||
<dl class="page-index">
|
||||
<dt><a href="#classes">Classes</a>
|
||||
|
||||
<dd>
|
||||
<dl class="page-index">
|
||||
<dt><a href="#default_call_policies-spec">Class
|
||||
<code>default_call_policies</code></a>
|
||||
|
||||
<dd>
|
||||
<dl class="page-index">
|
||||
<dt><a href="#default_call_policies-spec-synopsis">Class
|
||||
<code>default_call_policies</code> synopsis</a>
|
||||
|
||||
<dt><a href="#default_call_policies-spec-statics">Class
|
||||
<code>default_call_policies</code> static functions</a>
|
||||
</dl>
|
||||
|
||||
<dt><a href="#default_result_converter-spec">Class
|
||||
<code>default_result_converter</code></a>
|
||||
|
||||
<dd>
|
||||
<dl class="page-index">
|
||||
<dt><a href="#default_result_converter-spec-synopsis">Class
|
||||
<code>default_result_converter</code> synopsis</a>
|
||||
|
||||
<dt><a href="#default_result_converter-spec-metafunctions">Class
|
||||
<code>default_result_converter</code> metafunctions</a>
|
||||
</dl>
|
||||
</dl>
|
||||
|
||||
<dt><a href="#examples">Example</a>
|
||||
</dl>
|
||||
<hr>
|
||||
|
||||
<h2><a name="classes"></a>Classes</h2>
|
||||
|
||||
<h3><a name="default_call_policies-spec"></a>Class
|
||||
<code>default_call_policies</code></h3>
|
||||
|
||||
<p><code>default_call_policies</code> is a model of <a href=
|
||||
"CallPolicies.html">CallPolicies</a> with no <code>precall</code> or
|
||||
<code>postcall</code> behavior and a <code>result_converter</code> which
|
||||
handles by-value returns. Wrapped C++ functions and member functions use
|
||||
<code>default_call_policies</code> unless otherwise specified. You may find
|
||||
it convenient to derive new models of <a href=
|
||||
"CallPolicies.html">CallPolicies</a> from
|
||||
<code>default_call_policies</code>.
|
||||
|
||||
<h4><a name="default_call_policies-spec-synopsis"></a>Class
|
||||
<code>default_call_policies</code> synopsis</h4>
|
||||
<pre>
|
||||
namespace boost { namespace python
|
||||
{
|
||||
struct default_call_policies
|
||||
{
|
||||
static bool precall(PyObject*);
|
||||
static PyObject* postcall(PyObject*, PyObject* result);
|
||||
typedef <a href=
|
||||
"#default_result_converter-spec">default_result_converter</a> result_converter;
|
||||
};
|
||||
}}
|
||||
</pre>
|
||||
|
||||
<h4><a name="default_call_policies-spec-statics"></a>Class
|
||||
<code>default_call_policies</code> static functions</h4>
|
||||
<pre>
|
||||
bool precall(PyObject*);
|
||||
</pre>
|
||||
|
||||
<dl class="function-semantics">
|
||||
<dt><b>Returns:</b> <code>true</code>
|
||||
|
||||
<dt><b>Throws:</b> nothing
|
||||
</dl>
|
||||
<pre>
|
||||
PyObject* postcall(PyObject*, PyObject* result);
|
||||
</pre>
|
||||
|
||||
<dl class="function-semantics">
|
||||
<dt><b>Returns:</b> <code>result</code>
|
||||
|
||||
<dt><b>Throws:</b> nothing
|
||||
</dl>
|
||||
|
||||
<h3><a name="default_result_converter-spec"></a>Class
|
||||
<code>default_result_converter</code></h3>
|
||||
|
||||
<p><code>default_result_converter</code> is a model of <a href=
|
||||
"ResultConverterGenerator.html">ResultConverterGenerator</a> which can be
|
||||
used to wrap C++ functions returning non-pointer types, <code>char
|
||||
const*</code>, and <code>PyObject*</code>, by-value.
|
||||
|
||||
<h4><a name="default_result_converter-spec-synopsis"></a>Class
|
||||
<code>default_result_converter</code> synopsis</h4>
|
||||
<pre>
|
||||
namespace boost { namespace python
|
||||
{
|
||||
struct default_result_converter
|
||||
{
|
||||
template <class T> struct apply;
|
||||
};
|
||||
}}
|
||||
</pre>
|
||||
|
||||
<h4><a name="default_result_converter-spec-metafunctions"></a>Class
|
||||
<code>default_result_converter</code> metafunctions</h4>
|
||||
<pre>
|
||||
template <class T> struct apply
|
||||
</pre>
|
||||
|
||||
<dl class="metafunction-semantics">
|
||||
<dt><b>Requires:</b> <code>T</code> is not a reference type. If
|
||||
<code>T</code> is a pointer type, <code>T</code> is <code>const
|
||||
char*</code> or <code>PyObject*</code>.
|
||||
|
||||
<dt><b>Returns:</b> <code>typedef <a href=
|
||||
"to_python_value.html#to_python_value-spec">to_python_value</a><T
|
||||
const&> type;</code>
|
||||
</dl>
|
||||
|
||||
<h2><a name="examples"></a>Example</h2>
|
||||
|
||||
<p>This example comes from the Boost.Python implementation itself. Because
|
||||
the <a href=
|
||||
"return_value_policy.html#return_value_policy-spec">return_value_policy</a>
|
||||
class template does not implement <code>precall</code> or
|
||||
<code>postcall</code> behavior, its default base class is
|
||||
<code>default_call_policies</code>:
|
||||
<pre>
|
||||
template <class Handler, class Base = default_call_policies>
|
||||
struct return_value_policy : Base
|
||||
{
|
||||
typedef Handler result_converter;
|
||||
};
|
||||
</pre>
|
||||
|
||||
<p>Revised
|
||||
<!--webbot bot="Timestamp" S-Type="EDITED" S-Format="%d %B, %Y" startspan -->
|
||||
05 November, 2001
|
||||
<!--webbot bot="Timestamp" endspan i-checksum="39359" -->
|
||||
|
||||
|
||||
<p><i>© Copyright <a href="../../../../people/dave_abrahams.htm">Dave
|
||||
Abrahams</a> 2002. All Rights Reserved.</i>
|
||||
|
||||
34
doc/v2/definitions.html
Normal file
34
doc/v2/definitions.html
Normal file
@@ -0,0 +1,34 @@
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
|
||||
<link rel="stylesheet" type="text/css" href="../boost.css">
|
||||
<title>Boost.Python - Definitions</title>
|
||||
</head>
|
||||
<body link="#0000ff" vlink="#800080">
|
||||
<table border="0" cellpadding="7" cellspacing="0" width="100%" summary=
|
||||
"header">
|
||||
<tr>
|
||||
<td valign="top" width="300">
|
||||
<h3><a href="http://www.boost.org"><img height="86" width="277" alt="C++ Boost" src="../c++boost.gif" border="0"></a></h3>
|
||||
</td>
|
||||
<td valign="top">
|
||||
<h1 align="center">Boost.Python</h1>
|
||||
<h2 align="center">Definitions</h2>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<hr>
|
||||
<dl class="definitions">
|
||||
<dt><b>{{term}}:</b> {{definition}}</dt>
|
||||
<dt><b>{{term}}:</b> {{definition}}</dt>
|
||||
</dl>
|
||||
<hr>
|
||||
<p>Revised
|
||||
<!--webbot bot="Timestamp" S-Type="EDITED" S-Format="%d %B, %Y" startspan -->
|
||||
05 November, 2002
|
||||
<!--webbot bot="Timestamp" endspan i-checksum="39359" -->
|
||||
</p>
|
||||
<p><i>© Copyright <a href="../../../../people/dave_abrahams.htm">Dave Abrahams</a>
|
||||
2002. All Rights Reserved.</i></p>
|
||||
</body>
|
||||
</html>
|
||||
232
doc/v2/errors.html
Normal file
232
doc/v2/errors.html
Normal file
@@ -0,0 +1,232 @@
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
|
||||
<meta name="generator" content="HTML Tidy, see www.w3.org">
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
|
||||
<link rel="stylesheet" type="text/css" href="../boost.css">
|
||||
|
||||
<title>Boost.Python - <{{header}}></title>
|
||||
|
||||
<table border="0" cellpadding="7" cellspacing="0" width="100%" summary=
|
||||
"header">
|
||||
<tr>
|
||||
<td valign="top" width="300">
|
||||
<h3><a href="../../../../index.htm"><img height="86" width="277" alt=
|
||||
"C++ Boost" src="../../../../c++boost.gif" border="0"></a></h3>
|
||||
|
||||
<td valign="top">
|
||||
<h1 align="center">Boost.Python</h1>
|
||||
|
||||
<h2 align="center">Header <boost/python/errors.hpp></h2>
|
||||
</table>
|
||||
<hr>
|
||||
|
||||
<h2>Contents</h2>
|
||||
|
||||
<dl class="page-index">
|
||||
<dt><a href="#introduction">Introduction</a>
|
||||
|
||||
<dt><a href="#classes">Classes</a>
|
||||
|
||||
<dd>
|
||||
<dl class="page-index">
|
||||
<dt><a href="#class-spec">Class <code>error_already_set</code></a>
|
||||
|
||||
<dd>
|
||||
<dl class="page-index">
|
||||
<dt><a href="#error_already_set-spec-synopsis">Class
|
||||
<code>error_already_set</code> synopsis</a>
|
||||
</dl>
|
||||
</dl>
|
||||
|
||||
<dt><a href="#functions">Functions</a>
|
||||
|
||||
<dd>
|
||||
<dl class="page-index">
|
||||
<dt><a href="#handle_exception-spec">handle_exception</a>
|
||||
|
||||
<dt><a href="#expect_non_null-spec">expect_non_null</a>
|
||||
</dl>
|
||||
|
||||
<dt><a href="#examples">Examples</a>
|
||||
</dl>
|
||||
<hr>
|
||||
|
||||
<h2><a name="introduction"></a>Introduction</h2>
|
||||
|
||||
<p><code><boost/python/errors.hpp></code> provides types and
|
||||
functions for managing and translating between Python and C++ exceptions.
|
||||
This is relatively low-level functionality that is mostly used internally
|
||||
by Boost.Python. Users should seldom need it.
|
||||
|
||||
<h2><a name="classes"></a>Classes</h2>
|
||||
|
||||
<h3><a name="error_already_set-spec"></a>Class
|
||||
<code>error_already_set</code></h3>
|
||||
|
||||
<p><code>error_already_set</code> is an exception type which can be thrown
|
||||
to indicate that a Python error has occurred. If thrown, the precondition
|
||||
is that <a href=
|
||||
"http://www.python.org/doc/2.2/api/exceptionHandling.html#l2h-71">PyErr_Occurred()</a>
|
||||
returns a value convertible to <code>true</code>.
|
||||
|
||||
<h4><a name="class-spec-synopsis"></a>Class error_already_set synopsis</h4>
|
||||
<pre>
|
||||
namespace boost { namespace python
|
||||
{
|
||||
class error_already_set {};
|
||||
}}
|
||||
</pre>
|
||||
|
||||
<h2><a name="functions"></a>Functions</h2>
|
||||
<pre>
|
||||
<a name=
|
||||
"handle_exception-spec">template <class T> bool handle_exception</a>(T f) throw();
|
||||
|
||||
void handle_exception() throw();
|
||||
</pre>
|
||||
|
||||
<dl class="handle_exception-semantics">
|
||||
<dt><b>Requires:</b> The first form requires that the expression <code><a
|
||||
href=
|
||||
"../../../function/doc/reference.html#functionN">function0</a><void>(f)</code>
|
||||
is valid. The second form requires that a C++ exception is currently
|
||||
being handled (see section 15.1 in the C++ standard).
|
||||
|
||||
<dt><b>Effects:</b> The first form calls <code>f()</code> inside a
|
||||
<code>try</code> block whose <code>catch</code> clauses set an
|
||||
appropriate Python exception for the C++ exception caught, returning
|
||||
<code>true</code> if an exception was caught, <code>false</code>
|
||||
otherwise. The second form passes a function which rethrows the exception
|
||||
currently being handled to the first form.
|
||||
|
||||
<dt><b>Postconditions:</b> No exception is being handled
|
||||
|
||||
<dt><b>Throws:</b> nothing
|
||||
|
||||
<dt><b>Rationale:</b> At inter-language boundaries it is important to
|
||||
ensure that no C++ exceptions escape, since the calling language usually
|
||||
doesn't have the equipment neccessary to properly unwind the stack. Use
|
||||
<code>handle_exception</code> to manage exception translation whenever
|
||||
your C++ code is called directly from the Python API. This is done for
|
||||
you automatically by the usual function wrapping facilities: <a href=
|
||||
"make_function.html#make_function-spec">make_function()</a>, <a href=
|
||||
"make_function.html#make_constructor-spec">make_constructor()</a>, <a
|
||||
href="module.html#def-spec">module::def</a> and <a href=
|
||||
"class.html#def-spec">class_::def</a>). The second form can be more
|
||||
convenient to use (see the <a href="#examples">example</a> below), but
|
||||
various compilers have problems when exceptions are rethrown from within
|
||||
an enclosing <code>try</code> block.
|
||||
</dl>
|
||||
<pre>
|
||||
<a name="expect_non_null-spec">PyObject* expect_non_null(PyObject* x);</a>
|
||||
|
||||
template <class T> T* expect_non_null(T* x);
|
||||
</pre>
|
||||
|
||||
<dl class="expect_non_null-semantics">
|
||||
<dt><b>Returns:</b> <code>x</code>
|
||||
|
||||
<dt><b>Throws:</b> <code><a href=
|
||||
"#error_already_set-spec">error_already_set()</a></code> iff <code>x ==
|
||||
0</code>.
|
||||
|
||||
<dt><b>Rationale:</b> Simplifies error-handling when calling many
|
||||
functions in the <a href=
|
||||
"http://www.python.org/doc/2.2/api/api.html">Python/C API</a>, which
|
||||
return 0 on error.
|
||||
</dl>
|
||||
|
||||
<h2><a name="examples"></a>Examples</h2>
|
||||
<pre>
|
||||
#include <string>
|
||||
#include <boost/python/errors.hpp>
|
||||
#include <boost/python/reference.hpp>
|
||||
|
||||
// Returns a std::string which has the same value as obj's "__name__"
|
||||
// attribute.
|
||||
std::string get_name(boost::python::ref obj)
|
||||
{
|
||||
// throws if there's no __name__ attribute
|
||||
PyObject* p = boost::python::expect_non_null(
|
||||
PyObject_GetAttrString(obj.get(), "__name__"));
|
||||
|
||||
// throws if it's not a Python string
|
||||
std::string result(
|
||||
boost::python::expect_non_null(
|
||||
PyString_AsString(p)));
|
||||
|
||||
Py_XDECREF(p); // Done with p
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Demonstrate form 1 of handle_exception
|
||||
//
|
||||
|
||||
// Place a Python Int object whose value is 1 if a and b have
|
||||
// identical "__name__" attributes, 0 otherwise.
|
||||
void same_name_impl(PyObject*& result, PyObject* a, PyObject* b)
|
||||
{
|
||||
result = PyInt_FromLong(
|
||||
get_name(boost::python::ref(a1)) == get_name(boost::python::ref(a2)));
|
||||
}
|
||||
|
||||
// This is an example Python 'C' API interface function
|
||||
extern "C" PyObject*
|
||||
same_name(PyObject* args, PyObject* keywords)
|
||||
{
|
||||
PyObject* a1;
|
||||
PyObject* a2;
|
||||
PyObject* result = 0;
|
||||
|
||||
if (!PyArg_ParseTuple(args, const_cast<char*>("OO"), &a1, &a2))
|
||||
return 0;
|
||||
|
||||
// Use boost::bind to make an object compatible with
|
||||
// boost::Function0<void>
|
||||
if (boost::python::handle_exception(
|
||||
boost::bind<void>(same_name_impl, boost::ref(result), a1, a2)))
|
||||
{
|
||||
// an exception was thrown; the Python error was set by
|
||||
// handle_exception()
|
||||
return 0;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Demonstrate form 2 of handle_exception. Not well-supported by all
|
||||
// compilers.
|
||||
//
|
||||
extern "C" PyObject*
|
||||
same_name2(PyObject* args, PyObject* keywords)
|
||||
{
|
||||
PyObject* a1;
|
||||
PyObject* a2;
|
||||
PyObject* result = 0;
|
||||
|
||||
if (!PyArg_ParseTuple(args, const_cast<char*>("OO"), &a1, &a2))
|
||||
return 0;
|
||||
try {
|
||||
return PyInt_FromLong(
|
||||
get_name(boost::python::ref(a1)) == get_name(boost::python::ref(a2)));
|
||||
}
|
||||
catch(...)
|
||||
{
|
||||
// If an exception was thrown, translate it to Python
|
||||
boost::python::handle_exception();
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
</pre>
|
||||
|
||||
<p>Revised
|
||||
<!--webbot bot="Timestamp" S-Type="EDITED" S-Format="%d %B, %Y" startspan -->
|
||||
05 November, 2001
|
||||
<!--webbot bot="Timestamp" endspan i-checksum="39359" -->
|
||||
|
||||
|
||||
<p><i>© Copyright <a href="../../../../people/dave_abrahams.htm">Dave
|
||||
Abrahams</a> 2002. All Rights Reserved.</i>
|
||||
|
||||
38
doc/v2/faq.html
Normal file
38
doc/v2/faq.html
Normal file
@@ -0,0 +1,38 @@
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
|
||||
<link rel="stylesheet" type="text/css" href="../boost.css">
|
||||
<title>Boost.Python - FAQ</title>
|
||||
</head>
|
||||
<body link="#0000ff" vlink="#800080">
|
||||
<table border="0" cellpadding="7" cellspacing="0" width="100%" summary=
|
||||
"header">
|
||||
<tr>
|
||||
<td valign="top" width="300">
|
||||
<h3><a href="http://www.boost.org"><img height="86" width="277" alt="C++ Boost" src="../c++boost.gif" border="0"></a></h3>
|
||||
</td>
|
||||
<td valign="top">
|
||||
<h1 align="center">Boost.Python</h1>
|
||||
<h2 align="center">Frequently Asked Questions (FAQs)</h2>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<hr>
|
||||
<dl class="page-index">
|
||||
<dt><a href="#question1">{{question}}</a></dt>
|
||||
<dt><a href="#question2">{{question}}</a></dt>
|
||||
</dl>
|
||||
<h2><a name="question1"></a>{{question}}</h2>
|
||||
<p>{{answer}}</p>
|
||||
<h2><a name="question2"></a>{{question}}</h2>
|
||||
<p>{{answer}}</p>
|
||||
<hr>
|
||||
<p>Revised
|
||||
<!--webbot bot="Timestamp" S-Type="EDITED" S-Format="%d %B, %Y" startspan -->
|
||||
05 November, 2002
|
||||
<!--webbot bot="Timestamp" endspan i-checksum="39359" -->
|
||||
</p>
|
||||
<p><i>© Copyright <a href="../../../../people/dave_abrahams.htm">Dave Abrahams</a>
|
||||
2002. All Rights Reserved.</i></p>
|
||||
</body>
|
||||
</html>
|
||||
166
doc/v2/from_python.html
Normal file
166
doc/v2/from_python.html
Normal file
@@ -0,0 +1,166 @@
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
|
||||
<meta name="generator" content="HTML Tidy, see www.w3.org">
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
|
||||
<link rel="stylesheet" type="text/css" href="../boost.css">
|
||||
|
||||
<title>Boost.Python - <boost/python/from_python.hpp></title>
|
||||
|
||||
<table border="0" cellpadding="7" cellspacing="0" width="100%" summary=
|
||||
"header">
|
||||
<tr>
|
||||
<td valign="top" width="300">
|
||||
<h3><a href="../../../../index.htm"><img height="86" width="277" alt=
|
||||
"C++ Boost" src="../../../../c++boost.gif" border="0"></a></h3>
|
||||
|
||||
<td valign="top">
|
||||
<h1 align="center">Boost.Python</h1>
|
||||
|
||||
<h2 align="center">Header <boost/python/from_python.hpp></h2>
|
||||
</table>
|
||||
<hr>
|
||||
|
||||
<h2>Contents</h2>
|
||||
|
||||
<dl class="page-index">
|
||||
<dt><a href="#introduction">Introduction</a>
|
||||
|
||||
<dt><a href="#classes">Classes</a>
|
||||
|
||||
<dd>
|
||||
<dl class="page-index">
|
||||
<dt><a href="#from_python-spec">Class
|
||||
Template<code>from_python</code></a>
|
||||
|
||||
<dd>
|
||||
<dl class="page-index">
|
||||
<dt><a href="#from_python-spec-synopsis">Class Template
|
||||
<code>from_python</code> synopsis</a>
|
||||
|
||||
<dt><a href="#from_python-spec-ctors">Class Template
|
||||
<code>from_python</code> constructor</a>
|
||||
|
||||
<dt><a href="#from_python-spec-observers">Class Template
|
||||
<code>from_python</code> observer functions</a>
|
||||
</dl>
|
||||
</dl>
|
||||
|
||||
<dt><a href="#examples">Example</a>
|
||||
</dl>
|
||||
<hr>
|
||||
|
||||
<h2><a name="introduction"></a>Introduction</h2>
|
||||
|
||||
<p><code><boost/python/from_python.hpp></code> introduces a class
|
||||
template <code>from_python<T></code> for extracting a C++ object of
|
||||
type <code>T</code> from a Python object.
|
||||
|
||||
<h2><a name="classes"></a>Classes</h2>
|
||||
|
||||
<h3><a name="from_python-spec"></a>Class Template
|
||||
<code>from_python<class T></code></h3>
|
||||
|
||||
<p><code>from_python<T></code> is the type used internally by
|
||||
Boost.Python to extract C++ function arguments from a Python argument tuple
|
||||
when calling a wrapped function. It can also be used directly to make
|
||||
similar conversions in other contexts.
|
||||
|
||||
<h4><a name="from_python-spec-synopsis"></a>Class Template
|
||||
<code>from_python</code> synopsis</h4>
|
||||
<pre>
|
||||
namespace boost { namespace python
|
||||
{
|
||||
template <class T>
|
||||
struct from_python : private <a href=
|
||||
"../../../utility/utility.htm#Class noncopyable">boost::noncopyable</a> // Exposition only.
|
||||
// from_python<T> meets the <a href=
|
||||
"NonCopyable.html">NonCopyable</a> requirements
|
||||
{
|
||||
from_python(PyObject*);
|
||||
bool convertible() const;
|
||||
<i>convertible-to-T</i> operator()(PyObject*) const;
|
||||
};
|
||||
}
|
||||
</pre>
|
||||
|
||||
<h4><a name="from_python-spec-ctors"></a>Class Template
|
||||
<code>from_python</code> constructor</h4>
|
||||
<pre>
|
||||
from_python(PyObject* p);
|
||||
</pre>
|
||||
|
||||
<dl class="function-semantics">
|
||||
<dt><b>Requires:</b> <code>p != 0</code>
|
||||
|
||||
<dt><b>Effects:</b> Constructs a <code>from_python</code> object suitable
|
||||
for extracting a C++ object of type <code>T</code> from <code>p</code>.
|
||||
</dl>
|
||||
|
||||
<h4><a name="from_python-spec-observers"></a>Class Template
|
||||
<code>from_python</code> observer functions</h4>
|
||||
<pre>
|
||||
bool convertible() const;
|
||||
</pre>
|
||||
|
||||
<dl class="function-semantics">
|
||||
<dt><b>Returns:</b> <code>false</code> if the conversion cannot succeed.
|
||||
This indicates that either:
|
||||
|
||||
<dd>
|
||||
<ol>
|
||||
<li>No <code>from_python_converter</code> was registered for
|
||||
<code>T</code>, or
|
||||
|
||||
<li>any such converter rejected the constructor argument
|
||||
<code>p</code> by returning <code>0</code> from its
|
||||
<code>convertible()</code> function
|
||||
</ol>
|
||||
Note that conversion may still fail in <code>operator()</code> due to
|
||||
an exception.
|
||||
|
||||
<dt><b>Throws:</b> nothing
|
||||
|
||||
<dt><b>Rationale:</b> Because <code>from_python<></code> is used in
|
||||
overload resolution, and throwing an exception can be slow, it is useful
|
||||
to be able to rule out a broad class of unsuccessful conversions without
|
||||
throwing an exception.
|
||||
</dl>
|
||||
<pre>
|
||||
<i>convertible-to-T</i> operator()(PyObject* p) const;
|
||||
</pre>
|
||||
|
||||
<dl class="function-semantics">
|
||||
<dt><b>Requires:</b> <code>*p</code> refers to the same object which was
|
||||
passed to the constructor, and <code>convertible()</code> returns
|
||||
<code>true</code>.
|
||||
|
||||
<dt><b>Effects:</b> performs the conversion
|
||||
|
||||
<dt><b>Returns:</b> an object convertible to <code>T</code>.
|
||||
</dl>
|
||||
|
||||
<h2><a name="examples"></a>Example</h2>
|
||||
<pre>
|
||||
#include <string>
|
||||
#include <boost/python/from_python.hpp>
|
||||
|
||||
// If a std::string can be extracted from p, return its
|
||||
// length. Otherwise, return 0.
|
||||
std::size_t length_if_string(PyObject* p)
|
||||
{
|
||||
from_python<std::string> converter(p);
|
||||
if (!converter.convertible())
|
||||
return 0;
|
||||
else
|
||||
return converter().size();
|
||||
}
|
||||
</pre>
|
||||
|
||||
<p>Revised
|
||||
<!--webbot bot="Timestamp" S-Type="EDITED" S-Format="%d %B, %Y" startspan -->
|
||||
05 November, 2001
|
||||
<!--webbot bot="Timestamp" endspan i-checksum="39359" -->
|
||||
|
||||
|
||||
<p><i>© Copyright <a href="../../../../people/dave_abrahams.htm">Dave
|
||||
Abrahams</a> 2002. All Rights Reserved.</i>
|
||||
|
||||
288
doc/v2/header.html
Normal file
288
doc/v2/header.html
Normal file
@@ -0,0 +1,288 @@
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
|
||||
<meta name="generator" content="HTML Tidy, see www.w3.org">
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
|
||||
<link rel="stylesheet" type="text/css" href="../boost.css">
|
||||
|
||||
<title>Boost.Python - <{{header}}></title>
|
||||
|
||||
<table border="0" cellpadding="7" cellspacing="0" width="100%" summary=
|
||||
"header">
|
||||
<tr>
|
||||
<td valign="top" width="300">
|
||||
<h3><a href="../../../../index.htm"><img height="86" width="277" alt=
|
||||
"C++ Boost" src="../../../../c++boost.gif" border="0"></a></h3>
|
||||
|
||||
<td valign="top">
|
||||
<h1 align="center">Boost.Python</h1>
|
||||
|
||||
<h2 align="center">Header <{{header}}></h2>
|
||||
</table>
|
||||
<hr>
|
||||
|
||||
<h2>Contents</h2>
|
||||
|
||||
<dl class="page-index">
|
||||
<dt><a href="#introduction">Introduction</a>
|
||||
|
||||
<dt><a href="#macros">Macros</a>
|
||||
|
||||
<dd>
|
||||
<dl class="page-index">
|
||||
<dt><a href="#macro-spec">{{macro name}}</a>
|
||||
</dl>
|
||||
|
||||
<dt><a href="#values">Values</a>
|
||||
|
||||
<dd>
|
||||
<dl class="page-index">
|
||||
<dt><a href="#value-spec">{{value name}}</a>
|
||||
</dl>
|
||||
|
||||
<dt><a href="#types">Types</a>
|
||||
|
||||
<dd>
|
||||
<dl class="page-index">
|
||||
<dt><a href="#type-spec">{{type name}}</a>
|
||||
</dl>
|
||||
|
||||
<dt><a href="#classes">Classes</a>
|
||||
|
||||
<dd>
|
||||
<dl class="page-index">
|
||||
<dt><a href="#class-spec">Class <code>{{name}}</code></a>
|
||||
|
||||
<dd>
|
||||
<dl class="page-index">
|
||||
<dt><a href="#class-spec-synopsis">Class <code>{{name}}</code> synopsis</a>
|
||||
|
||||
<dt><a href="#class-spec-ctors">Class <code>{{name}}</code>
|
||||
constructors and destructor</a>
|
||||
|
||||
<dt><a href="#class-spec-comparisons">Class <code>{{name}}</code> comparison functions</a>
|
||||
|
||||
<dt><a href="#class-spec-modifiers">Class <code>{{name}}</code> modifier functions</a>
|
||||
|
||||
<dt><a href="#class-spec-observers">Class <code>{{name}}</code> observer functions</a>
|
||||
|
||||
<dt><a href="#class-spec-statics">Class <code>{{name}}</code> static functions</a>
|
||||
</dl>
|
||||
</dl>
|
||||
|
||||
<dt><a href="#functions">Functions</a>
|
||||
|
||||
<dd>
|
||||
<dl class="page-index">
|
||||
<dt><a href="#function-spec">{{function name}}</a>
|
||||
</dl>
|
||||
|
||||
<dt><a href="#objects">Objects</a>
|
||||
|
||||
<dd>
|
||||
<dl class="page-index">
|
||||
<dt><a href="#object-spec">{{object name}}</a>
|
||||
</dl>
|
||||
|
||||
<dt><a href="#examples">Example(s)</a>
|
||||
</dl>
|
||||
<hr>
|
||||
|
||||
<h2><a name="introduction"></a>Introduction</h2>
|
||||
|
||||
<p>{{Introductory text}}
|
||||
|
||||
<h2><a name="macros"></a>Macros</h2>
|
||||
|
||||
<p><a name="macro-spec"></a>{{Macro specifications}}
|
||||
|
||||
<h2><a name="values"></a>Values</h2>
|
||||
|
||||
<p><a name="value-spec"></a>{{Value specifications}}
|
||||
|
||||
<h2><a name="types"></a>Types</h2>
|
||||
|
||||
<p><a name="type-spec"></a>{{Type specifications}}
|
||||
|
||||
<h2><a name="classes"></a>Classes</h2>
|
||||
|
||||
<h3><a name="class-spec"></a>Class <code>{{name}}</code></h3>
|
||||
|
||||
<p>{{class overview text}}
|
||||
|
||||
<h4><a name="class-spec-synopsis"></a>Class <code>{{name}}</code> synopsis</h4>
|
||||
<pre>
|
||||
namespace boost
|
||||
{
|
||||
class {{name}}
|
||||
{
|
||||
};
|
||||
};
|
||||
</pre>
|
||||
|
||||
<h4><a name="class-spec-ctors"></a>Class <code>{{name}}</code> constructors and
|
||||
destructor</h4>
|
||||
<pre>
|
||||
{{constructor}}
|
||||
</pre>
|
||||
|
||||
<dl class="function-semantics">
|
||||
<dt><b>Requires:</b> {{text}}
|
||||
|
||||
<dt><b>Effects:</b> {{text}}
|
||||
|
||||
<dt><b>Postconditions:</b> {{text}}
|
||||
|
||||
<dt><b>Returns:</b> {{text}}
|
||||
|
||||
<dt><b>Throws:</b> {{text}}
|
||||
|
||||
<dt><b>Complexity:</b> {{text}}
|
||||
|
||||
<dt><b>Rationale:</b> {{text}}
|
||||
</dl>
|
||||
<pre>
|
||||
{{destructor}}
|
||||
</pre>
|
||||
|
||||
<dl class="function-semantics">
|
||||
<dt><b>Requires:</b> {{text}}
|
||||
|
||||
<dt><b>Effects:</b> {{text}}
|
||||
|
||||
<dt><b>Postconditions:</b> {{text}}
|
||||
|
||||
<dt><b>Returns:</b> {{text}}
|
||||
|
||||
<dt><b>Throws:</b> {{text}}
|
||||
|
||||
<dt><b>Complexity:</b> {{text}}
|
||||
|
||||
<dt><b>Rationale:</b> {{text}}
|
||||
</dl>
|
||||
|
||||
<h4><a name="class-spec-comparisons"></a>Class <code>{{name}}</code> comparison
|
||||
functions</h4>
|
||||
<pre>
|
||||
{{function}}
|
||||
</pre>
|
||||
|
||||
<dl class="function-semantics">
|
||||
<dt><b>Requires:</b> {{text}}
|
||||
|
||||
<dt><b>Effects:</b> {{text}}
|
||||
|
||||
<dt><b>Postconditions:</b> {{text}}
|
||||
|
||||
<dt><b>Returns:</b> {{text}}
|
||||
|
||||
<dt><b>Throws:</b> {{text}}
|
||||
|
||||
<dt><b>Complexity:</b> {{text}}
|
||||
|
||||
<dt><b>Rationale:</b> {{text}}
|
||||
</dl>
|
||||
|
||||
<h4><a name="class-spec-modifiers"></a>Class <code>{{name}}</code> modifier
|
||||
functions</h4>
|
||||
<pre>
|
||||
{{function}}
|
||||
</pre>
|
||||
|
||||
<dl class="function-semantics">
|
||||
<dt><b>Requires:</b> {{text}}
|
||||
|
||||
<dt><b>Effects:</b> {{text}}
|
||||
|
||||
<dt><b>Postconditions:</b> {{text}}
|
||||
|
||||
<dt><b>Returns:</b> {{text}}
|
||||
|
||||
<dt><b>Throws:</b> {{text}}
|
||||
|
||||
<dt><b>Complexity:</b> {{text}}
|
||||
|
||||
<dt><b>Rationale:</b> {{text}}
|
||||
</dl>
|
||||
|
||||
<h4><a name="class-spec-observers"></a>Class <code>{{name}}</code> observer
|
||||
functions</h4>
|
||||
<pre>
|
||||
{{function}}
|
||||
</pre>
|
||||
|
||||
<dl class="function-semantics">
|
||||
<dt><b>Requires:</b> {{text}}
|
||||
|
||||
<dt><b>Effects:</b> {{text}}
|
||||
|
||||
<dt><b>Postconditions:</b> {{text}}
|
||||
|
||||
<dt><b>Returns:</b> {{text}}
|
||||
|
||||
<dt><b>Throws:</b> {{text}}
|
||||
|
||||
<dt><b>Complexity:</b> {{text}}
|
||||
|
||||
<dt><b>Rationale:</b> {{text}}
|
||||
</dl>
|
||||
|
||||
<h4><a name="class-spec-statics"></a>Class <code>{{name}}</code> static functions</h4>
|
||||
<pre>
|
||||
{{function}}
|
||||
</pre>
|
||||
|
||||
<dl class="function-semantics">
|
||||
<dt><b>Requires:</b> {{text}}
|
||||
|
||||
<dt><b>Effects:</b> {{text}}
|
||||
|
||||
<dt><b>Postconditions:</b> {{text}}
|
||||
|
||||
<dt><b>Returns:</b> {{text}}
|
||||
|
||||
<dt><b>Throws:</b> {{text}}
|
||||
|
||||
<dt><b>Complexity:</b> {{text}}
|
||||
|
||||
<dt><b>Rationale:</b> {{text}}
|
||||
</dl>
|
||||
|
||||
<h2><a name="functions"></a>Functions</h2>
|
||||
<pre>
|
||||
|
||||
|
||||
<a name="function-spec"></a>{{function}}
|
||||
</pre>
|
||||
|
||||
<dl class="function-semantics">
|
||||
<dt><b>Requires:</b> {{text}}
|
||||
|
||||
<dt><b>Effects:</b> {{text}}
|
||||
|
||||
<dt><b>Postconditions:</b> {{text}}
|
||||
|
||||
<dt><b>Returns:</b> {{text}}
|
||||
|
||||
<dt><b>Throws:</b> {{text}}
|
||||
|
||||
<dt><b>Complexity:</b> {{text}}
|
||||
|
||||
<dt><b>Rationale:</b> {{text}}
|
||||
</dl>
|
||||
|
||||
<h2><a name="objects"></a>Objects</h2>
|
||||
|
||||
<p><a name="object-spec"></a>{{Object specifications}}
|
||||
|
||||
<h2><a name="examples"></a>Example(s)</h2>
|
||||
|
||||
<p>{{Example(s)}}
|
||||
|
||||
<p>Revised
|
||||
<!--webbot bot="Timestamp" S-Type="EDITED" S-Format="%d %B, %Y" startspan -->
|
||||
05 November, 2001
|
||||
<!--webbot bot="Timestamp" endspan i-checksum="39359" -->
|
||||
|
||||
|
||||
<p><i>© Copyright <a href="../../../../people/dave_abrahams.htm">Dave
|
||||
Abrahams</a> 2002. All Rights Reserved.</i>
|
||||
|
||||
41
doc/v2/index.html
Normal file
41
doc/v2/index.html
Normal file
@@ -0,0 +1,41 @@
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
|
||||
<link rel="stylesheet" type="text/css" href="../boost.css">
|
||||
<title>Boost.Python</title>
|
||||
</head>
|
||||
<body link="#0000ff" vlink="#800080">
|
||||
<table border="0" cellpadding="7" cellspacing="0" width="100%" summary=
|
||||
"header">
|
||||
<tr>
|
||||
<td valign="top" width="300">
|
||||
<h3><a href="http://www.boost.org"><img height="86" width="277" alt="C++ Boost" src="../c++boost.gif" border="0"></a></h3>
|
||||
</td>
|
||||
<td valign="top">
|
||||
<h1 align="center">Boost.Python</h1>
|
||||
<h2 align="center">Index</h2>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<hr>
|
||||
<h2>Contents</h2>
|
||||
<dl class="index">
|
||||
<dt><a href="overview.html">Overview</a></dt>
|
||||
<dt><a href="reference.html">Reference</a></dt>
|
||||
<dt><a href="configuration.html">Configuration Information</a></dt>
|
||||
<dt><a href="rationale.html">Rationale</a></dt>
|
||||
<dt><a href="definitions.html">Definitions</a></dt>
|
||||
<dt><a href="faq.html">Frequently Asked Questions (FAQs)</a></dt>
|
||||
<dt><a href="bibliography.html">Bibliography</a></dt>
|
||||
<dt><a href="acknowledgments.html">Acknowledgments</a></dt>
|
||||
</dl>
|
||||
<hr>
|
||||
<p>Revised
|
||||
<!--webbot bot="Timestamp" S-Type="EDITED" S-Format="%d %B, %Y" startspan -->
|
||||
05 November, 2002
|
||||
<!--webbot bot="Timestamp" endspan i-checksum="39359" -->
|
||||
</p>
|
||||
<p><i>© Copyright <a href="../../../../people/dave_abrahams.htm">Dave Abrahams</a>
|
||||
2002. All Rights Reserved.</i></p>
|
||||
</body>
|
||||
</html>
|
||||
279
doc/v2/lvalue_from_python.html
Normal file
279
doc/v2/lvalue_from_python.html
Normal file
@@ -0,0 +1,279 @@
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
|
||||
<meta name="generator" content="HTML Tidy, see www.w3.org">
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
|
||||
<link rel="stylesheet" type="text/css" href="../boost.css">
|
||||
|
||||
<title>Boost.Python - <boost/python/lvalue_from_python.hpp></title>
|
||||
|
||||
<table border="0" cellpadding="7" cellspacing="0" width="100%" summary=
|
||||
"header">
|
||||
<tr>
|
||||
<td valign="top" width="300">
|
||||
<h3><a href="../../../../index.htm"><img height="86" width="277" alt=
|
||||
"C++ Boost" src="../../../../c++boost.gif" border="0"></a></h3>
|
||||
|
||||
<td valign="top">
|
||||
<h1 align="center">Boost.Python</h1>
|
||||
|
||||
<h2 align="center">Header <boost/python/lvalue_from_python.hpp></h2>
|
||||
</table>
|
||||
<hr>
|
||||
|
||||
<h2>Contents</h2>
|
||||
|
||||
<dl class="page-index">
|
||||
<dt><a href="#introduction">Introduction</a>
|
||||
|
||||
|
||||
<dt><a href="#classes">Classes</a>
|
||||
|
||||
<dd>
|
||||
<dl class="page-index">
|
||||
<dt><a href="#lvalue_from_python-spec">Class Template <code>lvalue_from_python</code></a>
|
||||
|
||||
<dd>
|
||||
<dl class="page-index">
|
||||
|
||||
<dt><a href="#lvalue_from_python-spec-synopsis">Class Template
|
||||
<code>lvalue_from_python</code> synopsis</a>
|
||||
|
||||
<dt><a href="#lvalue_from_python-spec-ctors">Class Template
|
||||
<code>lvalue_from_python</code> constructor</a>
|
||||
</dl>
|
||||
</dl>
|
||||
|
||||
<dl class="page-index">
|
||||
<dt><a href="#get_member-spec">Class Template <code>get_member</code></a>
|
||||
|
||||
<dd>
|
||||
<dl class="page-index">
|
||||
|
||||
<dt><a href="#get_member-spec-synopsis">Class Template
|
||||
<code>get_member</code> synopsis</a>
|
||||
|
||||
<dt><a href="#get_member-spec-statics">Class Template
|
||||
<code>get_member</code> static functions</a>
|
||||
</dl>
|
||||
</dl>
|
||||
|
||||
<dt><a href="#examples">Example</a>
|
||||
</dl>
|
||||
<hr>
|
||||
|
||||
<h2><a name="introduction"></a>Introduction</h2>
|
||||
|
||||
<code><boost/python/lvalue_from_python.hpp></code> supplies
|
||||
a facility for extracting C++ objects from within instances of a
|
||||
given Python type. This is typically useful for dealing with
|
||||
"traditional" Python extension types.
|
||||
|
||||
<h2><a name="classes"></a>Classes</h2>
|
||||
|
||||
<h3><a name="lvalue_from_python-spec"></a>Class template <code>lvalue_from_python</code></h3>
|
||||
|
||||
<p>Class template <code>lvalue_from_python</code> will register
|
||||
from_python converters which extract a references and pointers to
|
||||
a C++ type which is held within an object of a given Python
|
||||
type. Its template arguments are:
|
||||
|
||||
<p>
|
||||
|
||||
|
||||
<table border="1" summary="lvalue_from_python template parameters">
|
||||
<caption>
|
||||
<b><code>lvalue_from_python</code> Requirements</b><br>
|
||||
|
||||
In the table below, <b><code>x</code></b> denotes an object of type <code>PythonObject&</code>
|
||||
|
||||
</caption>
|
||||
<tr>
|
||||
<th>Parameter
|
||||
|
||||
<th>Requirements
|
||||
|
||||
<th>Description
|
||||
|
||||
<th>Default
|
||||
|
||||
<tr>
|
||||
<td><code>python_type</code>
|
||||
|
||||
<td>A compile-time constant <code><a
|
||||
href="http://www.python.org/doc/2.2/ext/dnt-type-methods.html">PyTypeObject</a>*</code>
|
||||
|
||||
<td>The Python type of instances convertible by this
|
||||
converter. Python subtypes are also convertible.
|
||||
|
||||
<tr>
|
||||
<td><code>Value</code>
|
||||
|
||||
<td>A non-reference type.
|
||||
|
||||
<td>The C++ type to be extracted
|
||||
|
||||
<tr>
|
||||
<td><code>PythonObject</code>
|
||||
|
||||
<td>initial <code>sizeof(PyObject)</code> bytes are
|
||||
layout-compatible with <code>PyObject</code>.
|
||||
|
||||
<td>The C++ type used to hold Python instances of
|
||||
<code>python_type</code>.
|
||||
|
||||
<td><code>Value</code>
|
||||
|
||||
<tr>
|
||||
<td><code>Extract</code>
|
||||
|
||||
<td><code>Value& v = Extract::execute(x);</code>
|
||||
|
||||
<td>A type whose static <code>execute</code> function extracts a <code>Value</code> reference from within an object of type <code>PythonObject</code>.
|
||||
|
||||
<td>An unspecified type whose <code>execute</code> function consists of <code>return x;</code>
|
||||
</table>
|
||||
|
||||
If only the first two template arguments are supplied, these
|
||||
converters extract the entire <code>PythonObject</code> as a
|
||||
whole.
|
||||
|
||||
<p>
|
||||
|
||||
If the lifetime of the <code>lvalue_from_python</code> object ends
|
||||
before the last attempt to convert to one its target types, the
|
||||
behavior is undefined. The easiest way to ensure correct behavior
|
||||
is to declare an <code>lvalue_from_python</code> instance as a
|
||||
static local in a <a
|
||||
href="module.html#BOOST_PYTHON_MODULE_INIT-spec">module init
|
||||
function</a>, as shown in the <a href="#examples">example</a>
|
||||
below.
|
||||
|
||||
<h4><a name="lvalue_from_python-spec-synopsis"></a>Class template <code>lvalue_from_python</code> synopsis</h4>
|
||||
<pre>
|
||||
namespace boost { namespace python
|
||||
{
|
||||
template <
|
||||
PyTypeObject const* python_type
|
||||
, class Value
|
||||
, class PythonObject = Value
|
||||
, class Extract = <i>unspecified</i>
|
||||
>
|
||||
class lvalue_from_python
|
||||
{
|
||||
lvalue_from_python();
|
||||
};
|
||||
}}
|
||||
</pre>
|
||||
|
||||
<h4><a name="lvalue_from_python-spec-ctors"></a>Class template <code>lvalue_from_python</code> constructor</h4>
|
||||
<pre>
|
||||
lvalue_from_python();
|
||||
</pre>
|
||||
|
||||
<dl class="function-semantics">
|
||||
|
||||
<dt><b>Effects:</b> Registers from_python converters which
|
||||
extract
|
||||
<code>Value&</code>, <code>Value const&</code>,
|
||||
<code>Value*</code>, or <code>Value const*</code> from Python
|
||||
objects of type <code>python_type</code> using
|
||||
<code>Extract::execute()</code>.
|
||||
|
||||
</dl>
|
||||
|
||||
<h3><a name="get_member-spec"></a>Class template <code>get_member</code></h3>
|
||||
|
||||
<p><code>get_member</code> can be used with
|
||||
<code>lvalue_from_python</code> in the common case where the C++
|
||||
type to be extracted is a member of the Python object.
|
||||
|
||||
<h4><a name="get_member-spec-synopsis"></a>Class template <code>get_member</code> synopsis</h4>
|
||||
<pre>
|
||||
namespace boost { namespace python
|
||||
{
|
||||
template <class Class, class Member, Member (Class::*mp)>
|
||||
struct get_member
|
||||
{
|
||||
static Member& execute(Class& c);
|
||||
};
|
||||
}}
|
||||
</pre>
|
||||
|
||||
<h4><a name="get_member-spec-statics"></a>Class template <code>get_member</code> static functions</h4>
|
||||
<pre>
|
||||
Member& execute(Class& c);
|
||||
</pre>
|
||||
|
||||
<dl class="function-semantics">
|
||||
|
||||
<dt><b>Returns:</b> <code>c.*mp</code>
|
||||
|
||||
</dl>
|
||||
|
||||
|
||||
<h2><a name="examples"></a>Example</h2>
|
||||
|
||||
This example presumes that someone has implemented the standard <a
|
||||
href="http://www.python.org/doc/2.2/ext/dnt-basics.html">noddy
|
||||
example module</a> from the Python documentation, and we want to build
|
||||
a module which manipulates <code>Noddy</code>s. Since
|
||||
<code>noddy_NoddyObject</code> is so simple that it carries no
|
||||
interesting information, the example is a bit contrived: it assumes
|
||||
you want to keep track of one particular object for some reason.
|
||||
|
||||
<h3>C++ module definition</h3>
|
||||
|
||||
<pre>
|
||||
#include <boost/python/reference.hpp>
|
||||
#include <boost/python/module.hpp>
|
||||
|
||||
// definition lifted from the Python docs
|
||||
typedef struct {
|
||||
PyObject_HEAD
|
||||
} noddy_NoddyObject;
|
||||
|
||||
using namespace boost::python;
|
||||
static ref cache;
|
||||
|
||||
bool is_cached(noddy_NoddyObject* x)
|
||||
{
|
||||
return x == cache.get();
|
||||
}
|
||||
|
||||
void set_cache(noddy_NoddyObject* x)
|
||||
{
|
||||
cache.reset((PyObject*)x, ref::increment_count);
|
||||
}
|
||||
|
||||
BOOST_PYTHON_MODULE_INIT(noddy_cache)
|
||||
{
|
||||
module noddy_cache("noddy_cache")
|
||||
.def("is_cached", is_cached)
|
||||
.def("set_cache", set_cache)
|
||||
;
|
||||
}
|
||||
</pre>
|
||||
|
||||
<h3>Python code</h3>
|
||||
|
||||
<pre>
|
||||
>>> import noddy
|
||||
>>> n = noddy.new_noddy()
|
||||
>>> import noddy_cache
|
||||
>>> noddy_cache.is_cached(n)
|
||||
0
|
||||
>>> noddy_cache.set_cache(n)
|
||||
>>> noddy_cache.is_cached(n)
|
||||
1
|
||||
>>> noddy_cache.is_cached(noddy.new_noddy())
|
||||
0
|
||||
</pre>
|
||||
|
||||
<p>Revised
|
||||
<!--webbot bot="Timestamp" S-Type="EDITED" S-Format="%d %B, %Y" startspan -->
|
||||
05 November, 2001
|
||||
<!--webbot bot="Timestamp" endspan i-checksum="39359" -->
|
||||
|
||||
|
||||
<p><i>© Copyright <a href="../../../../people/dave_abrahams.htm">Dave
|
||||
Abrahams</a> 2002. All Rights Reserved.</i>
|
||||
|
||||
146
doc/v2/make_function.html
Normal file
146
doc/v2/make_function.html
Normal file
@@ -0,0 +1,146 @@
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
|
||||
<meta name="generator" content="HTML Tidy, see www.w3.org">
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
|
||||
<link rel="stylesheet" type="text/css" href="../boost.css">
|
||||
|
||||
<title>Boost.Python - <boost/python/make_function.hpp></title>
|
||||
|
||||
<table border="0" cellpadding="7" cellspacing="0" width="100%" summary=
|
||||
"header">
|
||||
<tr>
|
||||
<td valign="top" width="300">
|
||||
<h3><a href="../../../../index.htm"><img height="86" width="277" alt=
|
||||
"C++ Boost" src="../../../../c++boost.gif" border="0"></a></h3>
|
||||
|
||||
<td valign="top">
|
||||
<h1 align="center">Boost.Python</h1>
|
||||
|
||||
<h2 align="center">Header <boost/python/make_function.hpp></h2>
|
||||
</table>
|
||||
<hr>
|
||||
|
||||
<h2>Contents</h2>
|
||||
|
||||
<dl class="page-index">
|
||||
<dt><a href="#introduction">Introduction</a>
|
||||
|
||||
<dt><a href="#functions">Functions</a>
|
||||
|
||||
<dd>
|
||||
<dl class="page-index">
|
||||
<dt><a href="#make_function-spec">make_function</a>
|
||||
|
||||
<dt><a href="#make_constructor-spec">make_constructor</a>
|
||||
</dl>
|
||||
|
||||
<dt><a href="#examples">Example</a>
|
||||
</dl>
|
||||
<hr>
|
||||
|
||||
<h2><a name="introduction"></a>Introduction</h2>
|
||||
|
||||
<p><code><a href="#make_function-spec">make_function</a>()</code> and
|
||||
<code><a href="#make_constructor-spec">make_constructor</a>()</code> are
|
||||
the functions used internally by <code>class_<>::<a href=
|
||||
"class.html#class_-spec-modifiers">def</a></code>, <code>class_<>::<a
|
||||
href="module.html#module-spec-modifiers">def</a></code>, and
|
||||
<code>class_<>::<a href=
|
||||
"class.html#class_-spec-modifiers">def_init</a></code> to produce Python
|
||||
callable objects which wrap C++ functions and member functions.
|
||||
|
||||
<h2><a name="functions"></a>Functions</h2>
|
||||
<pre>
|
||||
<a name="make_function-spec">template <class F></a>
|
||||
objects::function* make_function(F f)</a>
|
||||
|
||||
template <class F, class Policies>
|
||||
objects::function* make_function(F f, Policies const& policies)
|
||||
</pre>
|
||||
|
||||
<dl class="function-semantics">
|
||||
<dt><b>Requires:</b> <code>F</code> is a function pointer or member
|
||||
function pointer type
|
||||
|
||||
<dt><b>Effects:</b> Creates a Python callable object which, when called
|
||||
from Python, converts its arguments to C++ and calls <code>f</code>. If
|
||||
<code>F</code> is a pointer-to-member-function type, the target object of
|
||||
the function call (<code>*this</code>) will be taken from the first
|
||||
Python argument, and subsequent Python arguments will be used as the
|
||||
arguments to <code>f</code>. If <code>policies</code> are supplied, it
|
||||
must be a model of <a href="CallPolicies.html">CallPolicies</a>, and will
|
||||
be applied to the function as described <a href=
|
||||
"CallPolicies.html">here</a>.
|
||||
|
||||
<dt><b>Returns:</b> A pointer convertible to <code>PyObject*</code> which
|
||||
refers to the new Python callable object.
|
||||
</dl>
|
||||
<pre>
|
||||
<a name=
|
||||
"make_constructor-spec">template <class T, class ArgList, class Generator>
|
||||
objects::function* make_constructor();</a>
|
||||
</pre>
|
||||
|
||||
<dl class="make_constructor-semantics">
|
||||
<dt><b>Requires:</b> <code>T</code> is a class type. <code>ArgList</code>
|
||||
is an <a href="../../../mpl/doc/Sequences.html">MPL sequence</a> of C++
|
||||
argument types (<i>A1, A2,... AN</i>) such that if
|
||||
<code>a1, a2</code>... <code>aN</code> are objects of type
|
||||
<i>A1, A2,... AN</i> respectively, the expression <code>new
|
||||
Generator::apply<T>::type(a1, a2</code>... <code>aN</code>) is
|
||||
valid. Generator is a model of <a href=
|
||||
"HolderGenerator.html">HolderGenerator</a>.
|
||||
|
||||
<dt><b>Effects:</b> Creates a Python callable object which, when called
|
||||
from Python, expects its first argument to be a Boost.Python extension
|
||||
class object. It converts its remaining its arguments to C++ and passes
|
||||
them to the constructor of a dynamically-allocated
|
||||
<code>Generator::apply<T>::type</code> object. The result is
|
||||
installed in the extension class object.
|
||||
|
||||
<dt><b>Returns:</b> The new Python callable object
|
||||
</dl>
|
||||
|
||||
<h2><a name="examples"></a>Example</h2>
|
||||
|
||||
<p>C++ function exposed below returns a callable object wrapping one of two
|
||||
functions.
|
||||
<pre>
|
||||
#include <boost/python/make_function.hpp>
|
||||
#include <boost/python/module.hpp>
|
||||
|
||||
char const* foo() { return "foo"; }
|
||||
char const* bar() { return "bar"; }
|
||||
|
||||
PyObject* choose_function(bool selector)
|
||||
{
|
||||
if (selector)
|
||||
return boost::python::make_function(foo);
|
||||
else
|
||||
return boost::python::make_function(bar);
|
||||
}
|
||||
|
||||
BOOST_PYTHON_MODULE_INIT(make_function_test)
|
||||
{
|
||||
module("make_function_test")
|
||||
.def("choose_function", choose_function);
|
||||
}
|
||||
</pre>
|
||||
It can be used this way in Python:
|
||||
<pre>
|
||||
>>> from make_function_test import *
|
||||
>>> f = choose_function(1)
|
||||
>>> g = choose_function(0)
|
||||
>>> f()
|
||||
'foo'
|
||||
>>> g()
|
||||
'bar'
|
||||
</pre>
|
||||
|
||||
<p>
|
||||
<!--webbot bot="Timestamp" S-Type="EDITED" S-Format="%d %B, %Y" startspan -->
|
||||
14 February 2002 <!--webbot bot="Timestamp" endspan i-checksum="39359" -->
|
||||
|
||||
|
||||
<p><i>© Copyright <a href="../../../../people/dave_abrahams.htm">Dave
|
||||
Abrahams</a> 2002. All Rights Reserved.</i>
|
||||
|
||||
130
doc/v2/manage_new_object.html
Normal file
130
doc/v2/manage_new_object.html
Normal file
@@ -0,0 +1,130 @@
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
|
||||
<meta name="generator" content="HTML Tidy, see www.w3.org">
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
|
||||
<link rel="stylesheet" type="text/css" href="../boost.css">
|
||||
|
||||
<title>Boost.Python - <boost/python/manage_new_object.hpp></title>
|
||||
|
||||
<table border="0" cellpadding="7" cellspacing="0" width="100%" summary=
|
||||
"header">
|
||||
<tr>
|
||||
<td valign="top" width="300">
|
||||
<h3><a href="../../../../index.htm"><img height="86" width="277" alt=
|
||||
"C++ Boost" src="../../../../c++boost.gif" border="0"></a></h3>
|
||||
|
||||
<td valign="top">
|
||||
<h1 align="center">Boost.Python</h1>
|
||||
|
||||
<h2 align="center">Header
|
||||
<boost/python/manage_new_object.hpp></h2>
|
||||
</table>
|
||||
<hr>
|
||||
|
||||
<h2>Contents</h2>
|
||||
|
||||
<dl class="page-index">
|
||||
<dt><a href="#classes">Classes</a>
|
||||
|
||||
<dd>
|
||||
<dl class="page-index">
|
||||
<dt><a href="#manage_new_object-spec">Class
|
||||
<code>manage_new_object</code></a>
|
||||
|
||||
<dd>
|
||||
<dl class="page-index">
|
||||
<dt><a href="#manage_new_object-spec-synopsis">Class
|
||||
<code>manage_new_object</code> synopsis</a>
|
||||
|
||||
<dt><a href="#manage_new_object-spec-metafunctions">Class
|
||||
<code>manage_new_object</code> metafunctions</a>
|
||||
</dl>
|
||||
</dl>
|
||||
|
||||
<dt><a href="#examples">Example</a>
|
||||
</dl>
|
||||
<hr>
|
||||
|
||||
<h2><a name="classes"></a>Classes</h2>
|
||||
|
||||
<h3><a name="manage_new_object-spec"></a>Class
|
||||
<code>manage_new_object</code></h3>
|
||||
|
||||
<p><code>manage_new_object</code> is a model of <a href=
|
||||
"ResultConverterGenerator.html">ResultConverterGenerator</a> which can be
|
||||
used to wrap C++ functions which return a pointer to an object allocated
|
||||
with a <i>new-expression</i>, and expect the caller to take responsibility
|
||||
for deleting that object.
|
||||
|
||||
<h4><a name="manage_new_object-spec-synopsis"></a>Class
|
||||
<code>manage_new_object</code> synopsis</h4>
|
||||
<pre>
|
||||
namespace boost { namespace python
|
||||
{
|
||||
struct manage_new_object
|
||||
{
|
||||
template <class T> struct apply;
|
||||
};
|
||||
}}
|
||||
</pre>
|
||||
|
||||
<h4><a name="manage_new_object-spec-metafunctions"></a>Class
|
||||
<code>manage_new_object</code> metafunctions</h4>
|
||||
<pre>
|
||||
template <class T> struct apply
|
||||
</pre>
|
||||
|
||||
<dl class="metafunction-semantics">
|
||||
<dt><b>Requires:</b> <code>T</code> is <code>U*</code> for some
|
||||
<code>U</code>.
|
||||
|
||||
<dt><b>Returns:</b> <code>typedef <a href=
|
||||
"to_python_indirect.html#to_python_indirect-spec">to_python_indirect</a><T>
|
||||
type;</code>
|
||||
</dl>
|
||||
|
||||
<h2><a name="examples"></a>Example</h2>
|
||||
|
||||
<p>In C++:
|
||||
<pre>
|
||||
#include <boost/python/module.hpp>
|
||||
#include <boost/python/class.hpp>
|
||||
#include <boost/python/manage_new_object.hpp>
|
||||
#include <boost/python/return_value_policy.hpp>
|
||||
|
||||
|
||||
struct Foo {
|
||||
Foo(int x) : x(x){}
|
||||
int get_x() { return x; }
|
||||
int x;
|
||||
};
|
||||
|
||||
Foo* make_foo(int x) { return new Foo(x); }
|
||||
|
||||
// Wrapper code
|
||||
using namespace boost::python;
|
||||
BOOST_PYTHON_MODULE_INIT(my_module)
|
||||
{
|
||||
module m("my_module")
|
||||
.def("make_foo", make_foo)
|
||||
.add(
|
||||
class_<Foo>()
|
||||
.def("get_x", &Foo::get_x)
|
||||
)
|
||||
}
|
||||
</pre>
|
||||
In Python:
|
||||
<pre>
|
||||
>>> from my_module import *
|
||||
>>> f = make_foo(3) # create a Foo object
|
||||
>>> f.get_x()
|
||||
3
|
||||
</pre>
|
||||
|
||||
<p>Revised
|
||||
<!--webbot bot="Timestamp" S-Type="EDITED" S-Format="%d %B, %Y" startspan -->
|
||||
14 February 2002 <!--webbot bot="Timestamp" endspan i-checksum="39359" -->
|
||||
|
||||
|
||||
<p><i>© Copyright <a href="../../../../people/dave_abrahams.htm">Dave
|
||||
Abrahams</a> 2002. All Rights Reserved.</i>
|
||||
|
||||
262
doc/v2/module.html
Normal file
262
doc/v2/module.html
Normal file
@@ -0,0 +1,262 @@
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
|
||||
<meta name="generator" content="HTML Tidy, see www.w3.org">
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
|
||||
<link rel="stylesheet" type="text/css" href="../boost.css">
|
||||
|
||||
<title>Boost.Python - <boost/python/module.hpp></title>
|
||||
|
||||
<table border="0" cellpadding="7" cellspacing="0" width="100%" summary=
|
||||
"header">
|
||||
<tr>
|
||||
<td valign="top" width="300">
|
||||
<h3><a href="../../../../index.htm"><img height="86" width="277" alt=
|
||||
"C++ Boost" src="../../../../c++boost.gif" border="0"></a></h3>
|
||||
|
||||
<td valign="top">
|
||||
<h1 align="center">Boost.Python</h1>
|
||||
|
||||
<h2 align="center">Header <boost/python/module.hpp></h2>
|
||||
</table>
|
||||
<hr>
|
||||
|
||||
<h2>Contents</h2>
|
||||
|
||||
<dl class="page-index">
|
||||
<dt><a href="#introduction">Introduction</a>
|
||||
|
||||
<dt><a href="#macros">Macros</a>
|
||||
|
||||
<dd>
|
||||
<dl class="page-index">
|
||||
<dt><a href=
|
||||
"#BOOST_PYTHON_MODULE_INIT-spec">BOOST_PYTHON_MODULE_INIT</a>
|
||||
</dl>
|
||||
|
||||
<dt><a href="#classes">Classes</a>
|
||||
|
||||
<dd>
|
||||
<dl class="page-index">
|
||||
<dt><a href="#module-spec">Class <code>module</code></a>
|
||||
|
||||
<dd>
|
||||
<dl class="page-index">
|
||||
<dt><a href="#module-spec-synopsis">Class <code>module</code>
|
||||
synopsis</a>
|
||||
|
||||
<dt><a href="#module-spec-ctors">Class <code>module</code>
|
||||
constructor</a>
|
||||
|
||||
<dt><a href="#module-spec-modifiers">Class <code>module</code>
|
||||
modifier functions</a>
|
||||
|
||||
<dt><a href="#module-spec-observers">Class <code>module</code>
|
||||
observer functions</a>
|
||||
</dl>
|
||||
</dl>
|
||||
|
||||
<dt><a href="#examples">Example(s)</a>
|
||||
</dl>
|
||||
<hr>
|
||||
|
||||
<h2><a name="introduction"></a>Introduction</h2>
|
||||
|
||||
<p>{{Introductory text}}
|
||||
|
||||
<h2><a name="macros"></a>Macros</h2>
|
||||
|
||||
<p><a name=
|
||||
"BOOST_PYTHON_MODULE_INIT-spec"><code>BOOST_PYTHON_MODULE_INIT(name)</code></a>
|
||||
is used to declare Python <a href=
|
||||
"http://www.python.org/doc/2.2/ext/methodTable.html#SECTION003400000000000000000">
|
||||
module initialization functions</a>. The <code>name</code> argument must
|
||||
exactly match the name of the module to be initialized, and must conform to
|
||||
Python's <a href=
|
||||
"http://www.python.org/doc/2.2/ref/identifiers.html">identifier naming
|
||||
rules</a>. Where you would normally write
|
||||
<pre>
|
||||
void init<i>name</i>()
|
||||
{
|
||||
...
|
||||
</pre>
|
||||
Boost.Python modules should be initialized with
|
||||
<pre>
|
||||
BOOST_PYTHON_MODULE_INIT(<i>name</i>)
|
||||
{
|
||||
...
|
||||
</pre>
|
||||
|
||||
<h2><a name="classes"></a>Classes</h2>
|
||||
|
||||
<h3><a name="module-spec">Class <code>module</code></a></h3>
|
||||
|
||||
<p>This class represents the Python extension module under construction. It
|
||||
provides functions for adding attributes and for retrieving the underlying
|
||||
Python module object.
|
||||
|
||||
<h4><a name="module-spec-synopsis"></a>Class <code>module</code>
|
||||
synopsis</h4>
|
||||
<pre>
|
||||
namespace boost { namespace python
|
||||
{
|
||||
class module : public module_base
|
||||
{
|
||||
public:
|
||||
module(const char* name);
|
||||
|
||||
// modifier functions
|
||||
module& setattr(const char* name, PyObject*);
|
||||
module& setattr(const char* name, PyTypeObject*);
|
||||
module& setattr(const char* name, ref const&);
|
||||
|
||||
module& add(PyTypeObject* x);
|
||||
template <class T, class Bases, class HolderGenerator>
|
||||
module& add(class_<T,Bases,HolderGenerator> const& c);
|
||||
|
||||
template <class Fn>
|
||||
module& def(char const* name, Fn fn);
|
||||
template <class Fn, class ResultHandler>
|
||||
module& def(char const* name, Fn fn, ResultHandler handler);
|
||||
|
||||
// observer function
|
||||
ref object() const;
|
||||
};
|
||||
|
||||
}}
|
||||
</pre>
|
||||
|
||||
<h4><a name="module-spec-ctors">Class <code>module</code></a>
|
||||
constructor</h4>
|
||||
<pre>
|
||||
module(const char* name);
|
||||
</pre>
|
||||
|
||||
<dl class="function-semantics">
|
||||
<dt><b>Requires:</b> <code>name</code> is a ntbs whose value matches the
|
||||
argument passed to <a href=
|
||||
"#BOOST_PYTHON_MODULE_INIT-spec">BOOST_PYTHON_MODULE_INIT</a>.
|
||||
|
||||
<dt><b>Effects:</b> Creates a <code>module</code> object representing a
|
||||
Python module named <code>name</code>.
|
||||
</dl>
|
||||
|
||||
<h4><a name="module-spec-modifiers">Class <code>module</code></a> modifier
|
||||
functions</h4>
|
||||
<pre>
|
||||
module& setattr(const char* name, PyObject* obj);
|
||||
module& setattr(const char* name, PyTypeObject* obj);
|
||||
module& setattr(const char* name, ref const& r);
|
||||
</pre>
|
||||
|
||||
<dl class="function-semantics">
|
||||
<dt><b>Requires:</b> <code>name</code> is a ntbs which conforms to
|
||||
Python's <a href=
|
||||
"http://www.python.org/doc/2.2/ref/identifiers.html">identifier
|
||||
naming rules</a>. In the first two forms, <code>obj</code> is non-null.
|
||||
In the third form, <code>r.get()</code> is non-null.
|
||||
|
||||
<dt><b>Effects:</b> Adds the given Python object to the module. If the
|
||||
object is a product of <code><a href=
|
||||
"make_function.html#make_function-spec">make_function</a>()</code>, the
|
||||
usual <a href="overloading.html">overloading procedure</a> applies.
|
||||
In the first two forms, ownership of a reference to obj is transferred
|
||||
from caller to callee, even if an exception is thrown.
|
||||
|
||||
<dt><b>Returns:</b> <code>*this</code>
|
||||
</dl>
|
||||
<pre>
|
||||
module& add(PyTypeObject* x);
|
||||
|
||||
template <class T, class Bases, class HolderGenerator>
|
||||
module& add(class_<T,Bases,HolderGenerator> const& c);
|
||||
</pre>
|
||||
|
||||
<dl class="function-semantics">
|
||||
<dt><b>Requires:</b> In the first form, <code>x</code> is non-null
|
||||
|
||||
<dt><b>Effects:</b> The first form adds the Python type object named by
|
||||
<code>x</code> to the Python module under construction, with the name
|
||||
given by the type's <code><a href=
|
||||
"http://www.python.org/doc/2.2/ext/dnt-type-methods.html">tp_name</a></code>
|
||||
field. The second form adds the extension class object being constructed
|
||||
by <code>c</code> to the module, with the same name that was passed to
|
||||
<code>c</code>'s constructor.
|
||||
|
||||
<dt><b>Returns:</b> <code>*this</code>
|
||||
|
||||
<dt><b>Rationale:</b> Provides a way to set type attributes in the module
|
||||
without having to explicitly specify the name.
|
||||
</dl>
|
||||
<pre>
|
||||
template <class Fn>
|
||||
module& def(char const* name, Fn f);
|
||||
|
||||
template <class Fn, class ResultHandler>
|
||||
module& def(char const* name, Fn f, ResultHandler handler);
|
||||
</pre>
|
||||
|
||||
<dl class="function-semantics">
|
||||
|
||||
<dt><b>Requires:</b> <code>f</code> is a non-null pointer-to-function or
|
||||
pointer-to-member-function. <code>name</code> is a ntbs which conforms to
|
||||
Python's <a href=
|
||||
"http://www.python.org/doc/2.2/ref/identifiers.html">identifier
|
||||
naming rules</a>. In the first form, the return type of
|
||||
<code>f</code> is not a reference and is not a pointer other
|
||||
than <code>char const*</code> or <code>PyObject*</code>. In the
|
||||
second form <code>policy</code> is a model of <a
|
||||
href="CallPolicy.html">CallPolicy</a>.
|
||||
|
||||
<dt><b>Effects:</b> Adds the result of <code><a href=
|
||||
"make_function.html#make_function-spec">make_function</a>(f)</code> to
|
||||
the extension module being defined, with the given <code>name</code>. If
|
||||
the module already has an attribute named <code><i>name</i></code>, the
|
||||
usual <a href="http:overloading.html">overloading procedure</a> applies.
|
||||
|
||||
<dt><b>Returns:</b> <code>*this</code>
|
||||
</dl>
|
||||
|
||||
<h4><a name="module-spec-observers">Class <code>module</code></a> observer
|
||||
functions</h4>
|
||||
<pre>
|
||||
ref object() const;
|
||||
</pre>
|
||||
|
||||
<dl class="function-semantics">
|
||||
<dt><b>Returns:</b> A <code>ref</code> object which holds a reference to
|
||||
the Python module object created by the <code>module</code> constructor.
|
||||
</dl>
|
||||
|
||||
<h2><a name="examples"></a>Example(s)</h2>
|
||||
|
||||
<p>C++ module definition:
|
||||
<pre>
|
||||
#include <boost/python/module.hpp>
|
||||
|
||||
char const* greet()
|
||||
{
|
||||
return "hello, Boost.Python!";
|
||||
}
|
||||
|
||||
BOOST_PYTHON_MODULE_INIT(boost_greet)
|
||||
{
|
||||
module("boost_greet")
|
||||
.def("greet", greet);
|
||||
}
|
||||
</pre>
|
||||
|
||||
Interactive Python:
|
||||
<pre>
|
||||
>>> import boost_greet
|
||||
>>> boost_greet.greet()
|
||||
'hello, Boost.Python!'
|
||||
</pre>
|
||||
|
||||
<p>Revised
|
||||
<!--webbot bot="Timestamp" S-Type="EDITED" S-Format="%d %B, %Y" startspan -->
|
||||
14 February, 2002
|
||||
<!--webbot bot="Timestamp" endspan i-checksum="39359" -->
|
||||
|
||||
|
||||
<p><i>© Copyright <a href="../../../../people/dave_abrahams.htm">Dave
|
||||
Abrahams</a> 2002. All Rights Reserved.</i>
|
||||
|
||||
47
doc/v2/overview.html
Normal file
47
doc/v2/overview.html
Normal file
@@ -0,0 +1,47 @@
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
|
||||
<link rel="stylesheet" type="text/css" href="../boost.css">
|
||||
<title>Boost.Python - Overview</title>
|
||||
</head>
|
||||
<body link="#0000ff" vlink="#800080">
|
||||
<table border="0" cellpadding="7" cellspacing="0" width="100%" summary=
|
||||
"header">
|
||||
<tr>
|
||||
<td valign="top" width="300">
|
||||
<h3><a href="http://www.boost.org"><img height="86" width="277" alt="C++ Boost" src="../c++boost.gif" border="0"></a></h3>
|
||||
</td>
|
||||
<td valign="top">
|
||||
<h1 align="center">Boost.Python</h1>
|
||||
<h2 align="center">Overview</h2>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<hr>
|
||||
<dl class="index">
|
||||
<dt><a href="#introduction">Introduction</a></dt>
|
||||
<dt><a href="#topic1">First topic</a></dt>
|
||||
<dt><a href="#topic2">Second topic</a></dt>
|
||||
<dt><a href="#footnotes">Footnotes</a></dt>
|
||||
</dl>
|
||||
<h2><a name="introduction"></a>Introduction</h2>
|
||||
<p>{{text}}</p>
|
||||
<h2><a name="topic1"></a>First Topic</h2>
|
||||
<p>{{text}}</p>
|
||||
<h2><a name="topic2"></a>Second Topic</h2>
|
||||
<p>{{text}}</p>
|
||||
<h2><a name="footnotes"></a>Footnotes</h2>
|
||||
<dl>
|
||||
<dt><a name="footnote1" class="footnote">(1)</a> {{text}}</dt>
|
||||
<dt><a name="footnote2" class="footnote">(2)</a> {{text}}</dt>
|
||||
</dl>
|
||||
<hr>
|
||||
<p>Revised
|
||||
<!--webbot bot="Timestamp" S-Type="EDITED" S-Format="%d %B, %Y" startspan -->
|
||||
05 November, 2002
|
||||
<!--webbot bot="Timestamp" endspan i-checksum="39359" -->
|
||||
</p>
|
||||
<p><i>© Copyright <a href="../../../../people/dave_abrahams.htm">Dave Abrahams</a>
|
||||
2002. All Rights Reserved.</i></p>
|
||||
</body>
|
||||
</html>
|
||||
47
doc/v2/rationale.html
Normal file
47
doc/v2/rationale.html
Normal file
@@ -0,0 +1,47 @@
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
|
||||
<link rel="stylesheet" type="text/css" href="../boost.css">
|
||||
<title>Boost.Python - Rationale</title>
|
||||
</head>
|
||||
<body link="#0000ff" vlink="#800080">
|
||||
<table border="0" cellpadding="7" cellspacing="0" width="100%" summary=
|
||||
"header">
|
||||
<tr>
|
||||
<td valign="top" width="300">
|
||||
<h3><a href="http://www.boost.org"><img height="86" width="277" alt="C++ Boost" src="../c++boost.gif" border="0"></a></h3>
|
||||
</td>
|
||||
<td valign="top">
|
||||
<h1 align="center">Boost.Python</h1>
|
||||
<h2 align="center">Rationale</h2>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<hr>
|
||||
<dl class="index">
|
||||
<dt><a href="#introduction">Introduction</a></dt>
|
||||
<dt><a href="#topic1">First topic</a></dt>
|
||||
<dt><a href="#topic2">Second topic</a></dt>
|
||||
<dt><a href="#footnotes">Footnotes</a></dt>
|
||||
</dl>
|
||||
<h2><a name="introduction"></a>Introduction</h2>
|
||||
<p>{{text}}</p>
|
||||
<h2><a name="topic1"></a>First Topic</h2>
|
||||
<p>{{text}}</p>
|
||||
<h2><a name="topic2"></a>Second Topic</h2>
|
||||
<p>{{text}}</p>
|
||||
<h2><a name="footnotes"></a>Footnotes</h2>
|
||||
<dl>
|
||||
<dt><a name="footnote1" class="footnote">(1)</a> {{text}}</dt>
|
||||
<dt><a name="footnote2" class="footnote">(2)</a> {{text}}</dt>
|
||||
</dl>
|
||||
<hr>
|
||||
<p>Revised
|
||||
<!--webbot bot="Timestamp" S-Type="EDITED" S-Format="%d %B, %Y" startspan -->
|
||||
05 November, 2002
|
||||
<!--webbot bot="Timestamp" endspan i-checksum="39359" -->
|
||||
</p>
|
||||
<p><i>© Copyright <a href="../../../../../people/dave_abrahams.htm">Dave Abrahams</a>
|
||||
2002. All Rights Reserved.</i></p>
|
||||
</body>
|
||||
</html>
|
||||
383
doc/v2/reference.html
Normal file
383
doc/v2/reference.html
Normal file
@@ -0,0 +1,383 @@
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
|
||||
<meta name="generator" content="HTML Tidy, see www.w3.org">
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
|
||||
<link rel="stylesheet" type="text/css" href="../boost.css">
|
||||
|
||||
<title>Boost.Python - Reference</title>
|
||||
|
||||
<table border="0" cellpadding="7" cellspacing="0" width="100%" summary=
|
||||
"reference">
|
||||
<tr>
|
||||
<td valign="top" width="300">
|
||||
<h3><a href="http://www.boost.org"><img height="86" width="277" alt=
|
||||
"C++ Boost" src="../c++boost.gif" border="0"></a></h3>
|
||||
|
||||
<td valign="top">
|
||||
<h1 align="center">Boost.Python</h1>
|
||||
|
||||
<h2 align="center">Reference</h2>
|
||||
</table>
|
||||
<hr>
|
||||
|
||||
<h2>Contents</h2>
|
||||
|
||||
<dl class="Reference">
|
||||
<dt><a href="#high_level">High Level Components</a>
|
||||
|
||||
<dt><a href="#framework">Framework Elements</a>
|
||||
|
||||
<dt><a href="#utilities">Utilities</a>
|
||||
|
||||
<dt><a href="#by_name">Index By Name</a>
|
||||
</dl>
|
||||
<a name="high_level"></a>
|
||||
|
||||
<h2>High Level Components</h2>
|
||||
|
||||
<dl class="index">
|
||||
<dd>
|
||||
<a name="general_purpose"></a>
|
||||
|
||||
<h3>General Purpose</h3>
|
||||
|
||||
<dl class="index">
|
||||
<dt><a href="class.html">class.hpp/class_fwd.hpp</a>
|
||||
|
||||
<dd>
|
||||
<dl class="index">
|
||||
<dt><a href="class.html#classes">Classes</a>
|
||||
|
||||
<dd>
|
||||
<dl class="index">
|
||||
<dt><a href="class.html#class_-spec">class_</a>
|
||||
|
||||
<dt><a href="class.html#bases-spec">bases</a>
|
||||
|
||||
<dt><a href="class.html#args-spec">args</a>
|
||||
</dl>
|
||||
</dl>
|
||||
|
||||
<dt><a href="errors.html">errors.hpp</a>
|
||||
|
||||
<dd>
|
||||
<dl class="index">
|
||||
<dt><a href="errors.html#classes">Classes</a>
|
||||
|
||||
<dd>
|
||||
<dl class="index">
|
||||
<dt><a href=
|
||||
"errors.html#error_already_set-spec">error_already_set</a>
|
||||
</dl>
|
||||
|
||||
<dt><a href="errors.html#functions">Functions</a>
|
||||
|
||||
<dd>
|
||||
<dl class="index">
|
||||
<dt><a href=
|
||||
"errors.html#handle_exception-spec">handle_exception</a>
|
||||
|
||||
<dt><a href=
|
||||
"errors.html#expect_non_null-spec">expect_non_null</a>
|
||||
</dl>
|
||||
</dl>
|
||||
|
||||
<dt><a href="make_function.html">make_function.hpp</a>
|
||||
|
||||
<dd>
|
||||
<dl class="index">
|
||||
<dt><a href="make_function.html#classes">Functions</a>
|
||||
|
||||
<dd>
|
||||
<dl class="index">
|
||||
<dt><a href=
|
||||
"make_function.html#make_function-spec">make_function</a>
|
||||
|
||||
<dt><a href=
|
||||
"make_.html#make_constructor-spec">make_constructor</a>
|
||||
</dl>
|
||||
</dl>
|
||||
|
||||
<dt><a href="module.html">module.hpp</a>
|
||||
|
||||
<dd>
|
||||
<dl class="index">
|
||||
<dt><a href="module.html#classes">Classes</a>
|
||||
|
||||
<dd>
|
||||
<dl class="index">
|
||||
<dt><a href="module.html#module-spec">module</a>
|
||||
</dl>
|
||||
</dl>
|
||||
|
||||
<dt><a href="objects.html">objects.hpp</a>
|
||||
|
||||
<dd>
|
||||
<dl class="index">
|
||||
<dt><a href="objects.html#classes">Classes</a>
|
||||
|
||||
<dd>
|
||||
<dl class="index">
|
||||
<dt><a href="objects.html#xxx-spec">not yet documented</a>
|
||||
</dl>
|
||||
</dl>
|
||||
|
||||
<dt><a href="reference_hpp.html">reference.hpp</a>
|
||||
|
||||
<dd>
|
||||
<dl class="index">
|
||||
<dt><a href="reference_hpp.html#classes">Classes</a>
|
||||
|
||||
<dd>
|
||||
<dl class="index">
|
||||
<dt><a href="reference_hpp.html#reference-spec">reference</a>
|
||||
</dl>
|
||||
|
||||
<dt><a href="reference_hpp.html#types">Types</a>
|
||||
|
||||
<dd>
|
||||
<dl class="index">
|
||||
<dt><a href="reference_hpp.html#ref-spec">ref</a>
|
||||
</dl>
|
||||
</dl>
|
||||
</dl>
|
||||
<a name="type_conversion"></a>
|
||||
|
||||
<h3>To/From Python Type Conversion</h3>
|
||||
|
||||
<dl class="index">
|
||||
<dt><a href="from_python.html">from_python.hpp</a>
|
||||
|
||||
<dd>
|
||||
<dl class="index">
|
||||
<dt><a href="from_python.html#classes">Classes</a>
|
||||
|
||||
<dd>
|
||||
<dl class="index">
|
||||
<dt><a href=
|
||||
"from_python.html#from_python-spec">from_python</a>
|
||||
</dl>
|
||||
</dl>
|
||||
|
||||
<dt><a href="to_python_converter.html">to_python_converter.hpp</a>
|
||||
|
||||
<dd>
|
||||
<dl class="index">
|
||||
<dt><a href="to_python_converter.html#classes">Classes</a>
|
||||
|
||||
<dd>
|
||||
<dl class="index">
|
||||
<dt><a href=
|
||||
"to_python_converter.html#to_python_converter-spec">to_python_converter</a>
|
||||
</dl>
|
||||
</dl>
|
||||
|
||||
<dt><a href="to_python_indirect.html">to_python_indirect.hpp</a>
|
||||
|
||||
<dd>
|
||||
<dl class="index">
|
||||
<dt><a href="to_python_indirect.html#classes">Classes</a>
|
||||
|
||||
<dd>
|
||||
<dl class="index">
|
||||
<dt><a href=
|
||||
"to_python_indirect.html#to_python_indirect-spec">to_python_indirect</a>
|
||||
</dl>
|
||||
</dl>
|
||||
|
||||
<dt><a href="to_python_value.html">to_python_value.hpp</a>
|
||||
|
||||
<dd>
|
||||
<dl class="index">
|
||||
<dt><a href="to_python_value.html#classes">Classes</a>
|
||||
|
||||
<dd>
|
||||
<dl class="index">
|
||||
<dt><a href=
|
||||
"to_python_value.html#to_python_value-spec">to_python_value</a>
|
||||
</dl>
|
||||
</dl>
|
||||
|
||||
<dt><a href="type_from_python.html">type_from_python.hpp</a>
|
||||
|
||||
<dd>
|
||||
<dl class="index">
|
||||
<dt><a href="type_from_python.html#classes">Classes</a>
|
||||
|
||||
<dd>
|
||||
<dl class="index">
|
||||
<dt><a href=
|
||||
"type_from_python.html#type_from_python-spec">type_from_python</a>
|
||||
</dl>
|
||||
</dl>
|
||||
|
||||
<dt><a href="value_from_python.html">value_from_python.hpp</a>
|
||||
|
||||
<dd>
|
||||
<dl class="index">
|
||||
<dt><a href="value_from_python.html#classes">Classes</a>
|
||||
|
||||
<dd>
|
||||
<dl class="index">
|
||||
<dt><a href=
|
||||
"value_from_python.html#value_from_python-spec">value_from_python</a>
|
||||
</dl>
|
||||
</dl>
|
||||
</dl>
|
||||
<a name="models_of_call_policies"></a>
|
||||
|
||||
<h3>Models of CallPolicies</h3>
|
||||
|
||||
<dl class="index">
|
||||
<dt><a href=
|
||||
"default_call_policies.html">default_call_policies.hpp</a>
|
||||
|
||||
<dd>
|
||||
<dl class="index">
|
||||
<dt><a href="default_call_policies.html#classes">Classes</a>
|
||||
|
||||
<dd>
|
||||
<dl class="index">
|
||||
<dt><a href=
|
||||
"default_call_policies.html#default_call_policies-spec">default_call_policies</a>
|
||||
|
||||
<dt><a href=
|
||||
"default_call_policies.html#default_result_converter-spec">default_result_converter</a>
|
||||
</dl>
|
||||
</dl>
|
||||
|
||||
<dt><a href=
|
||||
"return_internal_reference.html">return_internal_reference.hpp</a>
|
||||
|
||||
<dd>
|
||||
<dl class="index">
|
||||
<dt><a href="return_internal_reference.html#classes">Classes</a>
|
||||
|
||||
<dd>
|
||||
<dl class="index">
|
||||
<dt><a href=
|
||||
"return_internal_reference.html#return_internal_reference-spec">
|
||||
return_internal_reference</a>
|
||||
</dl>
|
||||
</dl>
|
||||
|
||||
<dt><a href="return_value_policy.html">return_value_policy.hpp</a>
|
||||
|
||||
<dd>
|
||||
<dl class="index">
|
||||
<dt><a href="return_value_policy.html#classes">Classes</a>
|
||||
|
||||
<dd>
|
||||
<dl class="index">
|
||||
<dt><a href=
|
||||
"return_value_policy.html#return_value_policy-spec">return_value_policy</a>
|
||||
</dl>
|
||||
</dl>
|
||||
|
||||
<dt><a href=
|
||||
"with_custodian_and_ward.html">with_custodian_and_ward.hpp</a>
|
||||
|
||||
<dd>
|
||||
<dl class="index">
|
||||
<dt><a href="with_custodian_and_ward.html#classes">Classes</a>
|
||||
|
||||
<dd>
|
||||
<dl class="index">
|
||||
<dt><a href=
|
||||
"with_custodian_and_ward.html#with_custodian_and_ward-spec">with_custodian_and_ward</a>
|
||||
|
||||
<dt><a href=
|
||||
"with_custodian_and_ward.html#with_custodian_and_ward_postcall-spec">
|
||||
with_custodian_and_ward_postcall</a>
|
||||
</dl>
|
||||
</dl>
|
||||
</dl>
|
||||
<a name="return_handler_generators"></a>
|
||||
|
||||
<h3>Models of ReturnHandlerGenerator</h3>
|
||||
|
||||
<dl class="index">
|
||||
<dt><a href="copy_const_reference.html">copy_const_reference.hpp</a>
|
||||
|
||||
<dd>
|
||||
<dl class="index">
|
||||
<dt><a href="copy_const_reference.html#classes">Classes</a>
|
||||
|
||||
<dd>
|
||||
<dl class="index">
|
||||
<dt><a href=
|
||||
"copy_const_reference.html#copy_const_reference-spec">copy_const_reference</a>
|
||||
</dl>
|
||||
</dl>
|
||||
|
||||
<dt><a href=
|
||||
"copy_non_const_reference.html">copy_non_const_reference.hpp</a>
|
||||
|
||||
<dd>
|
||||
<dl class="index">
|
||||
<dt><a href="copy_non_const_reference.html#classes">Classes</a>
|
||||
|
||||
<dd>
|
||||
<dl class="index">
|
||||
<dt><a href=
|
||||
"copy_non_const_reference.html#copy_non_const_reference-spec">
|
||||
copy_non_const_reference</a>
|
||||
</dl>
|
||||
</dl>
|
||||
|
||||
<dt><a href="manage_new_object.html">manage_new_object.hpp</a>
|
||||
|
||||
<dd>
|
||||
<dl class="index">
|
||||
<dt><a href="manage_new_object.html#classes">Classes</a>
|
||||
|
||||
<dd>
|
||||
<dl class="index">
|
||||
<dt><a href=
|
||||
"manage_new_object.html#manage_new_object-spec">manage_new_object</a>
|
||||
</dl>
|
||||
</dl>
|
||||
|
||||
<dt><a href=
|
||||
"reference_existing_object.html">reference_existing_object.hpp</a>
|
||||
|
||||
<dd>
|
||||
<dl class="index">
|
||||
<dt><a href="reference_existing_object.html#classes">Classes</a>
|
||||
|
||||
<dd>
|
||||
<dl class="index">
|
||||
<dt><a href=
|
||||
"reference_existing_object.html#reference_existing_object-spec">
|
||||
reference_existing_object</a>
|
||||
</dl>
|
||||
</dl>
|
||||
|
||||
<dt><a href=
|
||||
"lvalue_from_python.html">reference_from_python.hpp</a>
|
||||
|
||||
<dd>
|
||||
<dl class="index">
|
||||
<dt><a href="lvalue_from_python.html#classes">Classes</a>
|
||||
|
||||
<dd>
|
||||
<dl class="index">
|
||||
<dt><a href=
|
||||
"lvalue_from_python.html#reference_from_python-spec">reference_from_python</a>
|
||||
|
||||
<dt><a href=
|
||||
"lvalue_from_python.html#get_member-spec">get_member</a>
|
||||
</dl>
|
||||
</dl>
|
||||
</dl>
|
||||
</dl>
|
||||
<hr>
|
||||
|
||||
<p>Revised
|
||||
<!--webbot bot="Timestamp" S-Type="EDITED" S-Format="%d %B, %Y" startspan -->
|
||||
05 November, 2002
|
||||
<!--webbot bot="Timestamp" endspan i-checksum="39359" -->
|
||||
|
||||
|
||||
<p><i>© Copyright <a href="../../../../people/dave_abrahams.htm">Dave
|
||||
Abrahams</a> 2002. All Rights Reserved.</i>
|
||||
|
||||
161
doc/v2/reference_existing_object.html
Normal file
161
doc/v2/reference_existing_object.html
Normal file
@@ -0,0 +1,161 @@
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
|
||||
<meta name="generator" content="HTML Tidy, see www.w3.org">
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
|
||||
<link rel="stylesheet" type="text/css" href="../boost.css">
|
||||
|
||||
<title>Boost.Python -
|
||||
<boost/python/reference_existing_object.hpp></title>
|
||||
|
||||
<table border="0" cellpadding="7" cellspacing="0" width="100%" summary=
|
||||
"header">
|
||||
<tr>
|
||||
<td valign="top" width="300">
|
||||
<h3><a href="../../../../index.htm"><img height="86" width="277" alt=
|
||||
"C++ Boost" src="../../../../c++boost.gif" border="0"></a></h3>
|
||||
|
||||
<td valign="top">
|
||||
<h1 align="center">Boost.Python</h1>
|
||||
|
||||
<h2 align="center">Header
|
||||
<boost/python/reference_existing_object.hpp></h2>
|
||||
</table>
|
||||
<hr>
|
||||
|
||||
<h2>Contents</h2>
|
||||
|
||||
<dl class="page-index">
|
||||
<dt><a href="#classes">Classes</a>
|
||||
|
||||
<dd>
|
||||
<dl class="page-index">
|
||||
<dt><a href="#reference_existing_object-spec">Class
|
||||
<code>reference_existing_object</code></a>
|
||||
|
||||
<dd>
|
||||
<dl class="page-index">
|
||||
<dt><a href="#reference_existing_object-spec-synopsis">Class
|
||||
<code>reference_existing_object</code> synopsis</a>
|
||||
|
||||
<dt><a href="#reference_existing_object-spec-metafunctions">Class
|
||||
<code>reference_existing_object</code> metafunctions</a>
|
||||
</dl>
|
||||
</dl>
|
||||
|
||||
<dt><a href="#examples">Example</a>
|
||||
</dl>
|
||||
<hr>
|
||||
|
||||
<h2><a name="classes"></a>Classes</h2>
|
||||
|
||||
<h3><a name="reference_existing_object-spec"></a>Class
|
||||
<code>reference_existing_object</code></h3>
|
||||
|
||||
<p><code>reference_existing_object</code> is a model of <a href=
|
||||
"ResultConverterGenerator.html">ResultConverterGenerator</a> which can be
|
||||
used to wrap C++ functions which return a reference or pointer to a C++
|
||||
object. When the wrapped function is called, the value referenced by its
|
||||
return value is not copied. A new Python object is created which contains a
|
||||
pointer to the referent, and no attempt is made to ensure that the lifetime
|
||||
of the referent is at least as long as that of the corresponding Python
|
||||
object. Thus, it can be <font color="#ff0000"><b>highly
|
||||
dangerous</b></font> to use <code>reference_existing_object</code> without
|
||||
additional lifetime management from such models of <a href=
|
||||
"CallPolicies.html">CallPolicies</a> as <a href=
|
||||
"with_custodian_and_ward.html#with_custodian_and_ward-spec">with_custodian_and_ward</a>.
|
||||
This class is used in the implementation of <a href=
|
||||
"return_internal_reference.html#return_internal_reference-spec">return_internal_reference</a>.
|
||||
|
||||
<h4><a name="reference_existing_object-spec-synopsis"></a>Class
|
||||
<code>reference_existing_object</code> synopsis</h4>
|
||||
<pre>
|
||||
namespace boost { namespace python
|
||||
{
|
||||
struct reference_existing_object
|
||||
{
|
||||
template <class T> struct apply;
|
||||
};
|
||||
}}
|
||||
</pre>
|
||||
|
||||
<h4><a name="reference_existing_object-spec-metafunctions"></a>Class
|
||||
<code>reference_existing_object</code> metafunctions</h4>
|
||||
<pre>
|
||||
template <class T> struct apply
|
||||
</pre>
|
||||
|
||||
<dl class="metafunction-semantics">
|
||||
<dt><b>Requires:</b> <code>T</code> is <code>U&</code> or
|
||||
<code>U*</code>for some <code>U</code>.
|
||||
|
||||
<dt><b>Returns:</b> <code>typedef <a href=
|
||||
"to_python_indirect.html#to_python_indirect-spec">to_python_indirect</a><T,V>
|
||||
type</code>, where <code>V</code> is a <a href=
|
||||
"to_python_indirect.html#HolderObjectGenerator">HolderObjectGenerator</a>
|
||||
which constructs an instance holder containing an <i>unowned</i>
|
||||
<code>U*</code> pointing to the referent of the wrapped function's return
|
||||
value.
|
||||
</dl>
|
||||
|
||||
<h2><a name="examples"></a>Example</h2>
|
||||
|
||||
<p>In C++:
|
||||
<pre>
|
||||
#include <boost/python/module.hpp>
|
||||
#include <boost/python/class.hpp>
|
||||
#include <boost/python/reference_existing_object.hpp>
|
||||
#include <boost/python/return_value_policy.hpp>
|
||||
#include <utility>
|
||||
|
||||
// classes to wrap
|
||||
struct Singleton
|
||||
{
|
||||
Singleton() : x(0) {}
|
||||
|
||||
int exchange(int n) // set x and return the old value
|
||||
{
|
||||
std::swap(n, x);
|
||||
return n;
|
||||
}
|
||||
|
||||
int x;
|
||||
};
|
||||
|
||||
Singleton& get_it()
|
||||
{
|
||||
static Singleton just_one;
|
||||
return just_one;
|
||||
}
|
||||
|
||||
// Wrapper code
|
||||
using namespace boost::python;
|
||||
BOOST_PYTHON_MODULE_INIT(singleton)
|
||||
{
|
||||
module m("singleton")
|
||||
.def("get_it", get_it)
|
||||
.add(
|
||||
class_<Singleton>()
|
||||
.def("exchange", &Singleton::exchange)
|
||||
);
|
||||
}
|
||||
</pre>
|
||||
In Python:
|
||||
<pre>
|
||||
>>> import singleton
|
||||
>>> s1 = singleton.get_it()
|
||||
>>> s2 = singleton.get_it()
|
||||
>>> id(s1) == id(s2) # s1 and s2 are not the same object
|
||||
0
|
||||
>>> s1.exchange(42) # but they reference the same C++ Singleton
|
||||
0
|
||||
>>> s2.exchange(99)
|
||||
42
|
||||
</pre>
|
||||
|
||||
<p>Revised
|
||||
<!--webbot bot="Timestamp" S-Type="EDITED" S-Format="%d %B, %Y" startspan -->
|
||||
14 February 2002 <!--webbot bot="Timestamp" endspan i-checksum="39359" -->
|
||||
|
||||
|
||||
<p><i>© Copyright <a href="../../../../people/dave_abrahams.htm">Dave
|
||||
Abrahams</a> 2002. All Rights Reserved.</i>
|
||||
|
||||
210
doc/v2/return_internal_reference.html
Normal file
210
doc/v2/return_internal_reference.html
Normal file
@@ -0,0 +1,210 @@
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
|
||||
<meta name="generator" content="HTML Tidy, see www.w3.org">
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
|
||||
<link rel="stylesheet" type="text/css" href="../boost.css">
|
||||
|
||||
<title>Boost.Python - <boost/python/return_internal_reference.hpp></title>
|
||||
|
||||
<table border="0" cellpadding="7" cellspacing="0" width="100%" summary=
|
||||
"header">
|
||||
<tr>
|
||||
<td valign="top" width="300">
|
||||
<h3><a href="../../../../index.htm"><img height="86" width="277" alt=
|
||||
"C++ Boost" src="../../../../c++boost.gif" border="0"></a></h3>
|
||||
|
||||
<td valign="top">
|
||||
<h1 align="center">Boost.Python</h1>
|
||||
|
||||
<h2 align="center">Header <boost/python/return_internal_reference.hpp></h2>
|
||||
</table>
|
||||
<hr>
|
||||
|
||||
<h2>Contents</h2>
|
||||
|
||||
<dl class="page-index">
|
||||
<dt><a href="#introduction">Introduction</a>
|
||||
|
||||
|
||||
<dt><a href="#classes">Classes</a>
|
||||
|
||||
<dd>
|
||||
<dl class="page-index">
|
||||
<dt><a href="#return_internal_reference-spec">Class Template <code>return_internal_reference</code></a>
|
||||
|
||||
<dd>
|
||||
<dl class="page-index">
|
||||
|
||||
<dt><a href="#return_internal_reference-spec-synopsis">Class Template
|
||||
<code>return_internal_reference</code> synopsis</a>
|
||||
|
||||
<dt><a href="#return_internal_reference-spec-statics">Class
|
||||
<code>return_internal_reference</code> static functions</a>
|
||||
</dl>
|
||||
</dl>
|
||||
|
||||
|
||||
<dt><a href="#examples">Example</a>
|
||||
</dl>
|
||||
<hr>
|
||||
|
||||
<h2><a name="introduction"></a>Introduction</h2>
|
||||
|
||||
<code>return_internal_reference</code> instantiations are models of <a href=
|
||||
"CallPolicies.html">CallPolicies</a> which allow pointers and
|
||||
references to objects held internally by a free or member function
|
||||
argument or from the target of a member function to be returned
|
||||
safely without making a copy of the referent. The default for its
|
||||
first template argument handles the common case where the
|
||||
containing object is the target (<code>*this</code>) of a wrapped
|
||||
member function.
|
||||
|
||||
<h2><a name="classes"></a>Classes</h2>
|
||||
|
||||
<h3><a name="return_internal_reference-spec"></a>Class template <code>return_internal_reference</code></h3>
|
||||
|
||||
|
||||
<table border="1" summary="return_internal_reference template parameters">
|
||||
<caption>
|
||||
<b><code>return_internal_reference</code> template parameters</b>
|
||||
</caption>
|
||||
<tr>
|
||||
<th>Parameter
|
||||
|
||||
<th>Requirements
|
||||
|
||||
<th>Description
|
||||
|
||||
<th>Default
|
||||
|
||||
<tr>
|
||||
<td><code>owner_arg</code>
|
||||
|
||||
<td>A positive compile-time constant of type
|
||||
<code>std::size_t</code>.
|
||||
|
||||
<td>The index of the parameter which contains the object to
|
||||
which the reference or pointer is being returned. If used to
|
||||
wrap a member function, parameter 1 is the target object
|
||||
(<code>*this</code>). Note that if the target Python object
|
||||
type doesn't support weak references, a Python
|
||||
<code>TypeError</code> exception will be raised when the
|
||||
function being wrapped is called.
|
||||
|
||||
<td>1
|
||||
|
||||
<tr>
|
||||
<td><code>Base</code>
|
||||
|
||||
<td>A model of <a href="CallPolicies.html">CallPolicies</a>
|
||||
|
||||
<td>Used for policy composition. Any
|
||||
<code>result_converter</code> it supplies will be overridden by
|
||||
<code>return_internal_reference</code>, but its
|
||||
<code>precall</code> and <code>postcall</code> policies are
|
||||
composed as described here <a
|
||||
href="CallPolicies.html#composition">CallPolicies</a>.
|
||||
|
||||
<td><code><a href="default_call_policies.html#default_call_policies-spec">default_call_policies</a></code>
|
||||
|
||||
</table>
|
||||
|
||||
<h4><a name="return_internal_reference-spec-synopsis"></a>Class template <code>return_internal_reference</code> synopsis</h4>
|
||||
<pre>
|
||||
namespace boost { namespace python
|
||||
{
|
||||
template <std::size_t owner_arg = 1, class Base = default_call_policies>
|
||||
struct return_internal_reference : Base
|
||||
{
|
||||
static PyObject* postcall(PyObject*, PyObject* result);
|
||||
typedef <a href="reference_existing_object.html#reference_existing_object-spec">reference_existing_object</a> result_converter;
|
||||
};
|
||||
}}
|
||||
</pre>
|
||||
|
||||
<h4><a name="default_call_policies-spec-statics"></a>Class
|
||||
<code>default_call_policies</code> static functions</h4>
|
||||
|
||||
<pre>
|
||||
PyObject* postcall(PyObject* args, PyObject* result);
|
||||
</pre>
|
||||
|
||||
<dl class="function-semantics">
|
||||
<dt><b>Requires:</b> <code><a href="http://www.python.org/doc/2.2/api/tupleObjects.html#l2h-476">PyTuple_Check</a>(args) != 0</code>
|
||||
|
||||
<dt><b>Returns:</b> <code><a href="with_custodian_and_ward.html#with_custodian_and_ward_postcall-spec-statics">with_custodian_and_ward_postcall::postcall(args, result)</a></code>
|
||||
</dl>
|
||||
|
||||
|
||||
<h2><a name="examples"></a>Example</h2>
|
||||
|
||||
<h3>C++ module definition</h3>
|
||||
|
||||
<pre>
|
||||
#include <boost/python/module.hpp>
|
||||
#include <boost/python/class.hpp>
|
||||
#include <boost/python/return_internal_reference.hpp>
|
||||
|
||||
class Bar
|
||||
{
|
||||
Bar(int x) : x(x) {}
|
||||
int get_x() const { return x; }
|
||||
void set_x(int x) { this->x = x; }
|
||||
private:
|
||||
int x;
|
||||
}
|
||||
|
||||
class Foo
|
||||
{
|
||||
public:
|
||||
Foo(int x) : b(x) {}
|
||||
|
||||
// Returns an internal reference
|
||||
Bar const& get_bar() const { return b; }
|
||||
|
||||
private:
|
||||
Bar b;
|
||||
};
|
||||
|
||||
using namespace boost::python;
|
||||
BOOST_PYTHON_MODULE_INIT(internal_refs)
|
||||
{
|
||||
module m("internal_refs")
|
||||
.add(
|
||||
class_<Bar>()
|
||||
.def("get_x", &Bar::get_x)
|
||||
.def("set_x", &Bar::set_x)
|
||||
)
|
||||
.add(
|
||||
class_<Foo>()
|
||||
.def_init(args<int>())
|
||||
.def("get_bar", &Foo::get_bar
|
||||
, return_internal_reference<>())
|
||||
)
|
||||
;
|
||||
}
|
||||
</pre>
|
||||
|
||||
<h3>Python code</h3>
|
||||
|
||||
<pre>
|
||||
>>> from internal_refs import *
|
||||
>>> f = Foo(3)
|
||||
>>> b1 = f.get_bar()
|
||||
>>> b2 = f.get_bar()
|
||||
>>> b1.get_x()
|
||||
3
|
||||
>>> b2.get_x()
|
||||
3
|
||||
>>> b1.set_x(42)
|
||||
>>> b2.get_x()
|
||||
42
|
||||
</pre>
|
||||
|
||||
<p>Revised
|
||||
<!--webbot bot="Timestamp" S-Type="EDITED" S-Format="%d %B, %Y" startspan -->
|
||||
15 February, 2002
|
||||
<!--webbot bot="Timestamp" endspan i-checksum="39359" -->
|
||||
|
||||
<p><i>© Copyright <a href="../../../../people/dave_abrahams.htm">Dave
|
||||
Abrahams</a> 2002. All Rights Reserved.</i>
|
||||
|
||||
148
doc/v2/return_value_policy.html
Normal file
148
doc/v2/return_value_policy.html
Normal file
@@ -0,0 +1,148 @@
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
|
||||
<meta name="generator" content="HTML Tidy, see www.w3.org">
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
|
||||
<link rel="stylesheet" type="text/css" href="../boost.css">
|
||||
|
||||
<title>Boost.Python - <boost/python/return_value_policy.hpp></title>
|
||||
|
||||
<table border="0" cellpadding="7" cellspacing="0" width="100%" summary=
|
||||
"header">
|
||||
<tr>
|
||||
<td valign="top" width="300">
|
||||
<h3><a href="../../../../index.htm"><img height="86" width="277" alt=
|
||||
"C++ Boost" src="../../../../c++boost.gif" border="0"></a></h3>
|
||||
|
||||
<td valign="top">
|
||||
<h1 align="center">Boost.Python</h1>
|
||||
|
||||
<h2 align="center">Header <boost/python/return_value_policy.hpp></h2>
|
||||
</table>
|
||||
<hr>
|
||||
|
||||
<h2>Contents</h2>
|
||||
|
||||
<dl class="page-index">
|
||||
<dt><a href="#introduction">Introduction</a>
|
||||
|
||||
|
||||
<dt><a href="#classes">Classes</a>
|
||||
|
||||
<dd>
|
||||
<dl class="page-index">
|
||||
<dt><a href="#return_value_policy-spec">Class Template <code>return_value_policy</code></a>
|
||||
|
||||
<dd>
|
||||
<dl class="page-index">
|
||||
|
||||
<dt><a href="#return_value_policy-spec-synopsis">Class Template
|
||||
<code>return_value_policy</code> synopsis</a>
|
||||
</dl>
|
||||
</dl>
|
||||
|
||||
|
||||
<dt><a href="#examples">Example</a>
|
||||
</dl>
|
||||
<hr>
|
||||
|
||||
<h2><a name="introduction"></a>Introduction</h2>
|
||||
|
||||
<code>return_value_policy</code> instantiations are simply models
|
||||
of <a href=
|
||||
"CallPolicies.html">CallPolicies</a> which are composed of a <a href=
|
||||
"ResultConverterGenerator.html">ResultConverterGenerator</a> and optional <code>Base</code> <a href=
|
||||
"CallPolicies.html">CallPolicies</a>.
|
||||
|
||||
<h2><a name="classes"></a>Classes</h2>
|
||||
|
||||
<h3><a name="return_value_policy-spec"></a>Class template <code>return_value_policy</code></h3>
|
||||
|
||||
|
||||
<table border="1" summary="return_value_policy template parameters">
|
||||
<caption>
|
||||
<b><code>return_value_policy</code> template parameters</b>
|
||||
</caption>
|
||||
<tr>
|
||||
<th>Parameter
|
||||
|
||||
<th>Requirements
|
||||
|
||||
<th>Default
|
||||
|
||||
<tr>
|
||||
<td><code>ResultConverterGenerator</code>
|
||||
|
||||
<td>A model of <a href=
|
||||
"ResultConverterGenerator.html">ResultConverterGenerator</a>.
|
||||
|
||||
<tr>
|
||||
<td><code>Base</code>
|
||||
|
||||
<td>A model of <a href="CallPolicies.html">CallPolicies</a>
|
||||
|
||||
<td><code><a href="default_call_policies.html#default_call_policies-spec">default_call_policies</a></code>
|
||||
|
||||
</table>
|
||||
|
||||
<h4><a name="return_value_policy-spec-synopsis"></a>Class template <code>return_value_policy</code> synopsis</h4>
|
||||
<pre>
|
||||
namespace boost { namespace python
|
||||
{
|
||||
template <class ResultConverterGenerator, class Base = default_call_policies>
|
||||
struct return_value_policy : Base
|
||||
{
|
||||
typedef ResultConverterGenerator result_converter;
|
||||
};
|
||||
}}
|
||||
</pre>
|
||||
|
||||
<h2><a name="examples"></a>Example</h2>
|
||||
|
||||
<h3>C++ Module Definition</h3>
|
||||
<pre>
|
||||
#include <boost/python/module.hpp>
|
||||
#include <boost/python/class.hpp>
|
||||
#include <boost/python/copy_const_reference.hpp>
|
||||
#include <boost/python/return_value_policy.hpp>
|
||||
|
||||
// classes to wrap
|
||||
struct Bar { int x; }
|
||||
|
||||
struct Foo {
|
||||
Foo(int x) : { b.x = x; }
|
||||
Bar const& get_bar() const { return b; }
|
||||
private:
|
||||
Bar b;
|
||||
};
|
||||
|
||||
// Wrapper code
|
||||
using namespace boost::python;
|
||||
BOOST_PYTHON_MODULE_INIT(my_module)
|
||||
{
|
||||
module m("my_module")
|
||||
.add(
|
||||
class_<Bar>()
|
||||
)
|
||||
.add(
|
||||
class_<Foo>()
|
||||
.def_init(args<int>())
|
||||
.def("get_bar", &Foo::get_bar
|
||||
, return_value_policy<copy_const_reference>())
|
||||
)
|
||||
;
|
||||
}
|
||||
</pre>
|
||||
<h3>Python Code</h3>
|
||||
<pre>
|
||||
>>> from my_module import *
|
||||
>>> f = Foo(3) # create a Foo object
|
||||
>>> b = f.get_bar() # make a copy of the internal Bar object
|
||||
</pre>
|
||||
|
||||
<p>Revised
|
||||
<!--webbot bot="Timestamp" S-Type="EDITED" S-Format="%d %B, %Y" startspan -->
|
||||
15 February, 2002
|
||||
<!--webbot bot="Timestamp" endspan i-checksum="39359" -->
|
||||
|
||||
<p><i>© Copyright <a href="../../../../people/dave_abrahams.htm">Dave
|
||||
Abrahams</a> 2002. All Rights Reserved.</i>
|
||||
|
||||
189
doc/v2/to_python_converter.html
Normal file
189
doc/v2/to_python_converter.html
Normal file
@@ -0,0 +1,189 @@
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
|
||||
<meta name="generator" content="HTML Tidy, see www.w3.org">
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
|
||||
<link rel="stylesheet" type="text/css" href="../boost.css">
|
||||
|
||||
<title>Boost.Python - <boost/python/to_python_converter.hpp></title>
|
||||
|
||||
<table border="0" cellpadding="7" cellspacing="0" width="100%" summary=
|
||||
"header">
|
||||
<tr>
|
||||
<td valign="top" width="300">
|
||||
<h3><a href="../../../../index.htm"><img height="86" width="277" alt=
|
||||
"C++ Boost" src="../../../../c++boost.gif" border="0"></a></h3>
|
||||
|
||||
<td valign="top">
|
||||
<h1 align="center">Boost.Python</h1>
|
||||
|
||||
<h2 align="center">Header <boost/python/to_python_converter.hpp></h2>
|
||||
</table>
|
||||
<hr>
|
||||
|
||||
<h2>Contents</h2>
|
||||
|
||||
<dl class="page-index">
|
||||
<dt><a href="#introduction">Introduction</a>
|
||||
|
||||
|
||||
<dt><a href="#classes">Classes</a>
|
||||
|
||||
<dd>
|
||||
<dl class="page-index">
|
||||
<dt><a href="#to_python_converter-spec">Class Template <code>to_python_converter</code></a>
|
||||
|
||||
<dd>
|
||||
<dl class="page-index">
|
||||
|
||||
<dt><a href="#to_python_converter-spec-synopsis">Class Template
|
||||
<code>to_python_converter</code> synopsis</a>
|
||||
|
||||
<dt><a href="#to_python_converter-spec-ctors">Class Template
|
||||
<code>to_python_converter</code> constructor</a>
|
||||
</dl>
|
||||
</dl>
|
||||
|
||||
<dt><a href="#examples">Example</a>
|
||||
</dl>
|
||||
<hr>
|
||||
|
||||
<h2><a name="introduction"></a>Introduction</h2>
|
||||
|
||||
<code>to_python_converter</code> registers a conversion from
|
||||
objects of a given C++ type into a Python object.
|
||||
|
||||
<h2><a name="classes"></a>Classes</h2>
|
||||
|
||||
<h3><a name="to_python_converter-spec"></a>Class template <code>to_python_converter</code></h3>
|
||||
|
||||
<code>to_python_converter</code> adds a wrapper around a static
|
||||
member function of its second template parameter, handling
|
||||
low-level details such as insertion into the converter registry.
|
||||
|
||||
<table border="1" summary="to_python_converter template parameters">
|
||||
<caption>
|
||||
<b><code>to_python_converter</code> template parameters</b><br>
|
||||
In the table below, <b><code>x</code></b> denotes an object of type <code>T</code>
|
||||
</caption>
|
||||
<tr>
|
||||
<th>Parameter
|
||||
|
||||
<th>Requirements
|
||||
|
||||
<th>Description
|
||||
|
||||
<tr>
|
||||
<td><code>T</code>
|
||||
|
||||
<td>
|
||||
|
||||
<td>The C++ type of the source object in the conversion
|
||||
|
||||
<tr>
|
||||
<td><code>Conversion</code>
|
||||
|
||||
<td><code>PyObject* p = Conversion::convert(x)</code>,<br>
|
||||
if <code>p == 0</code>, <code><a href="http://www.python.org/doc/2.2/api/exceptionHandling.html#l2h-71">PyErr_Occurred</a>() != 0</code>.
|
||||
|
||||
<td>A class type whose static member function
|
||||
<code>convert</code> does the real work of the conversion.
|
||||
|
||||
<tr>
|
||||
</table>
|
||||
|
||||
<h4><a name="to_python_converter-spec-synopsis"></a>Class template <code>to_python_converter</code> synopsis</h4>
|
||||
<pre>
|
||||
namespace boost { namespace python
|
||||
{
|
||||
template <class T, class Conversion>
|
||||
struct to_python_converter
|
||||
{
|
||||
to_python_converter();
|
||||
};
|
||||
}}
|
||||
</pre>
|
||||
|
||||
<h4><a name="to_python_converter-spec-ctors"></a>Class template <code>to_python_converter</code> constructor</h4>
|
||||
<pre>
|
||||
to_python_converter();
|
||||
</pre>
|
||||
|
||||
<dl class="function-semantics">
|
||||
|
||||
<dt><b>Effects:</b> Registers a to_python converter which uses
|
||||
<code>Conversion::convert()</code> to do its work.
|
||||
|
||||
</dl>
|
||||
|
||||
<h2><a name="examples"></a>Example</h2>
|
||||
|
||||
This example presumes that someone has implemented the standard <a
|
||||
href="http://www.python.org/doc/2.2/ext/dnt-basics.html">noddy example
|
||||
module</a> from the Python documentation, and placed the corresponding
|
||||
declarations in <code>"noddy.h"</code>. Because
|
||||
<code>noddy_NoddyObject</code> is the ultimate trivial extension type,
|
||||
the example is a bit contrived: it wraps a function for which all
|
||||
information is contained in the <i>type</i> of its return value.
|
||||
|
||||
<h3>C++ module definition</h3>
|
||||
|
||||
<pre>
|
||||
#include <boost/python/reference.hpp>
|
||||
#include <boost/python/module.hpp>
|
||||
#include "noddy.h"
|
||||
|
||||
struct tag {};
|
||||
tag make_tag() { return tag(); }
|
||||
|
||||
using namespace boost::python;
|
||||
|
||||
struct tag_to_noddy
|
||||
{
|
||||
static PyObject* convert(tag const& x)
|
||||
{
|
||||
return PyObject_New(noddy_NoddyObject, &noddy_NoddyType);
|
||||
}
|
||||
};
|
||||
|
||||
BOOST_PYTHON_MODULE_INIT(to_python_converter)
|
||||
{
|
||||
module to_python("to_python_converter")
|
||||
.def("make_tag", make_tag)
|
||||
;
|
||||
to_python_converter<tag, tag_to_noddy>();
|
||||
}
|
||||
</pre>
|
||||
|
||||
<h3>Python code</h3>
|
||||
|
||||
<pre>
|
||||
>>> import to_python_converter
|
||||
>>> def always_none():
|
||||
... return None
|
||||
...
|
||||
>>> def choose_function(x):
|
||||
... if (x % 2 != 0):
|
||||
... return to_python_converter.make_tag
|
||||
... else:
|
||||
... return always_none
|
||||
...
|
||||
>>> a = [ choose_function(x) for x in range(5) ]
|
||||
>>> b = [ f() for f in a ]
|
||||
>>> type(b[0])
|
||||
<type 'NoneType'>
|
||||
>>> type(b[1])
|
||||
<type 'Noddy'>
|
||||
>>> type(b[2])
|
||||
<type 'NoneType'>
|
||||
>>> type(b[3])
|
||||
<type 'Noddy'>
|
||||
</pre>
|
||||
|
||||
<p>Revised
|
||||
<!--webbot bot="Timestamp" S-Type="EDITED" S-Format="%d %B, %Y" startspan -->
|
||||
05 November, 2001
|
||||
<!--webbot bot="Timestamp" endspan i-checksum="39359" -->
|
||||
|
||||
|
||||
<p><i>© Copyright <a href="../../../../people/dave_abrahams.htm">Dave
|
||||
Abrahams</a> 2002. All Rights Reserved.</i>
|
||||
|
||||
194
doc/v2/to_python_indirect.html
Normal file
194
doc/v2/to_python_indirect.html
Normal file
@@ -0,0 +1,194 @@
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
|
||||
<meta name="generator" content="HTML Tidy, see www.w3.org">
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
|
||||
<link rel="stylesheet" type="text/css" href="../boost.css">
|
||||
|
||||
<title>Boost.Python - <boost/python/to_python_indirect.hpp></title>
|
||||
|
||||
<table border="0" cellpadding="7" cellspacing="0" width="100%" summary=
|
||||
"header">
|
||||
<tr>
|
||||
<td valign="top" width="300">
|
||||
<h3><a href="../../../../index.htm"><img height="86" width="277" alt=
|
||||
"C++ Boost" src="../../../../c++boost.gif" border="0"></a></h3>
|
||||
|
||||
<td valign="top">
|
||||
<h1 align="center">Boost.Python</h1>
|
||||
|
||||
<h2 align="center">Header <boost/python/to_python_indirect.hpp></h2>
|
||||
</table>
|
||||
<hr>
|
||||
|
||||
<h2>Contents</h2>
|
||||
|
||||
<dl class="page-index">
|
||||
<dt><a href="#introduction">Introduction</a>
|
||||
|
||||
|
||||
<dt><a href="#classes">Classes</a>
|
||||
|
||||
<dd>
|
||||
<dl class="page-index">
|
||||
<dt><a href="#to_python_indirect-spec">Class Template <code>to_python_indirect</code></a>
|
||||
|
||||
<dd>
|
||||
<dl class="page-index">
|
||||
|
||||
<dt><a href="#to_python_indirect-spec-synopsis">Class Template
|
||||
<code>to_python_indirect</code> synopsis</a>
|
||||
|
||||
<dt><a href="#to_python_indirect-spec-observers">Class Template
|
||||
<code>to_python_indirect</code> observer functions</a>
|
||||
|
||||
<dt><a href="#to_python_indirect-spec-statics">Class Template
|
||||
<code>to_python_indirect</code> static functions</a>
|
||||
</dl>
|
||||
</dl>
|
||||
|
||||
<dt><a href="#examples">Example</a>
|
||||
</dl>
|
||||
<hr>
|
||||
|
||||
<h2><a name="introduction"></a>Introduction</h2>
|
||||
|
||||
<code><boost/python/to_python_indirect.hpp></code> supplies
|
||||
a way to construct new Python objects that hold wrapped C++ class
|
||||
instances via a pointer or smart pointer.
|
||||
|
||||
<h2><a name="classes"></a>Classes</h2>
|
||||
|
||||
<h3><a name="to_python_indirect-spec"></a>Class template <code>to_python_indirect</code></h3>
|
||||
<p>Class template <code>to_python_indirect</code> converts objects
|
||||
of its first argument type to python as extension class instances, using the ownership policy provided by its 2nd argument.
|
||||
|
||||
<p>
|
||||
|
||||
|
||||
<table border="1" summary="to_python_indirect template parameters">
|
||||
<caption>
|
||||
<b><code>to_python_indirect</code> Requirements</b><br>
|
||||
|
||||
In the table below, <b><code>x</code></b> denotes an object of
|
||||
type <code>T</code>, <b><code>h</code></b> denotes an
|
||||
object of type
|
||||
<code>boost::python::objects::instance_holder*</code>, and
|
||||
<b><code>p</code></b> denotes an object of type
|
||||
<code>U*</code>.
|
||||
|
||||
</caption>
|
||||
<tr>
|
||||
<th>Parameter
|
||||
|
||||
<th>Requirements
|
||||
|
||||
<th>Description
|
||||
|
||||
<tr>
|
||||
<td><code>T</code>
|
||||
|
||||
<td>Either <code>U</code> <i>cv</i><code>&</code>
|
||||
(where <i>cv</i> is any optional cv-qualification) or a <a
|
||||
href="Dereferenceable.html">Dereferenceable</a> type such that
|
||||
<code>*x</code> is convertible to <code>U const&</code>, where
|
||||
<code>U</code> is a class type.
|
||||
|
||||
<td>A type deferencing a C++ class exposed to Python using
|
||||
class template <code><a
|
||||
href="class.html#class_-spec">class_</a></code>.
|
||||
|
||||
<tr>
|
||||
<td><code>MakeHolder</code>
|
||||
|
||||
<td>h = MakeHolder::execute(p);
|
||||
|
||||
<td>A class whose static <code>execute()</code> creates an
|
||||
<code>instance_holder</code>.
|
||||
|
||||
</table>
|
||||
|
||||
Instantiations of <code>to_python_indirect</code> are models of <a
|
||||
href="ResultConverter.html">ResultConverter</a>.
|
||||
|
||||
|
||||
<h4><a name="to_python_indirect-spec-synopsis"></a>Class template <code>to_python_indirect</code> synopsis</h4>
|
||||
<pre>
|
||||
namespace boost { namespace python
|
||||
{
|
||||
template <class T, class MakeHolder>
|
||||
struct to_python_indirect
|
||||
{
|
||||
static bool convertible();
|
||||
PyObject* operator()(T ptr_or_reference) const;
|
||||
private:
|
||||
static PyTypeObject* type();
|
||||
};
|
||||
}}
|
||||
</pre>
|
||||
|
||||
<h4><a name="to_python_indirect-spec-observers"></a>Class template <code>to_python_indirect</code> observers</h4>
|
||||
<pre>
|
||||
PyObject* operator()(T x) const;
|
||||
</pre>
|
||||
|
||||
<dl class="function-semantics">
|
||||
|
||||
<dt><b>Requires:</b> <code>x</code> refers to an object (if it
|
||||
is a pointer type, it is non-null). <code>convertible() ==
|
||||
true</code>.
|
||||
|
||||
<dt><b>Effects:</b> Creates an appropriately-typed Boost.Python
|
||||
extension class instance, uses <code>MakeHolder</code> to create
|
||||
an <code>instance_holder</code> from <code>x</code>, installs
|
||||
the <code>instance_holder</code> in the new extension class
|
||||
instance, and returns a pointer to it.
|
||||
|
||||
</dl>
|
||||
|
||||
|
||||
<h4><a name="to_python_indirect-spec-statics"></a>Class template <code>to_python_indirect</code> statics</h4>
|
||||
<pre>
|
||||
bool convertible();
|
||||
</pre>
|
||||
|
||||
<dt><b>Effects:</b> Returns <code>true</code> iff any module has
|
||||
registered a Python type corresponding to <code>U</code>.
|
||||
|
||||
<h2><a name="examples"></a>Example</h2>
|
||||
|
||||
This example replicates the functionality of <a
|
||||
href="reference_existing_object.html#reference_existing_object-spec">reference_existing_object</a>,
|
||||
but without some of the compile-time error checking.
|
||||
|
||||
|
||||
<pre>
|
||||
|
||||
struct make_reference_holder
|
||||
{
|
||||
typedef boost::python::objects::instance_holder* result_type;
|
||||
template <class T>
|
||||
static result_type execute(T* p)
|
||||
{
|
||||
return new boost::python::objects::pointer_holder<T*, T>(p);
|
||||
}
|
||||
};
|
||||
|
||||
struct reference_existing_object
|
||||
{
|
||||
// metafunction returning the <a href="ResultConverter.html">ResultConverter</a>
|
||||
template <class T>
|
||||
struct apply
|
||||
{
|
||||
typedef boost::python::to_python_indirect<T,make_reference_holder> type;
|
||||
};
|
||||
};
|
||||
</pre>
|
||||
|
||||
<p>Revised
|
||||
<!--webbot bot="Timestamp" S-Type="EDITED" S-Format="%d %B, %Y" startspan -->
|
||||
16 February, 2002
|
||||
<!--webbot bot="Timestamp" endspan i-checksum="39359" -->
|
||||
|
||||
|
||||
<p><i>© Copyright <a href="../../../../people/dave_abrahams.htm">Dave
|
||||
Abrahams</a> 2002. All Rights Reserved.</i>
|
||||
|
||||
@@ -16,10 +16,15 @@ namespace python = boost::python;
|
||||
// extension module. This is where we build the module contents.
|
||||
BOOST_PYTHON_MODULE_INIT(getting_started1)
|
||||
{
|
||||
try {
|
||||
// Create an object representing this extension module.
|
||||
python::module_builder this_module("getting_started1");
|
||||
|
||||
// Add regular functions to the module.
|
||||
this_module.def(greet, "greet");
|
||||
this_module.def(square, "square");
|
||||
}
|
||||
catch(...) {
|
||||
boost::python::handle_exception();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,50 +0,0 @@
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
|
||||
namespace { // Avoid cluttering the global namespace.
|
||||
|
||||
// A friendly class.
|
||||
class world
|
||||
{
|
||||
private:
|
||||
std::string country;
|
||||
public:
|
||||
world(const std::string& country) { this->country = country; }
|
||||
std::string greet() const { return "Hello from " + country + "!"; }
|
||||
};
|
||||
|
||||
// A function taking a world object as an argument.
|
||||
std::string invite(const world& w) {
|
||||
return w.greet() + " Please come soon!";
|
||||
}
|
||||
}
|
||||
|
||||
#include <py_cpp/class_wrapper.h>
|
||||
|
||||
// Python requires an exported function called init<module-name> in every
|
||||
// extension module. This is where we build the module contents.
|
||||
BOOST_PYTHON_MODULE_INIT(example2)
|
||||
{
|
||||
// Create an object representing this extension module.
|
||||
py::Module this_module("example2");
|
||||
|
||||
// Create the Python type object for our extension class.
|
||||
py::ClassWrapper<world> world_class(this_module, "world");
|
||||
|
||||
// Add the __init__ function.
|
||||
world_class.def(py::Constructor<std::string>());
|
||||
// Add a regular member function.
|
||||
world_class.def(&world::greet, "greet");
|
||||
|
||||
// Add invite() as a regular function to the module.
|
||||
this_module.def(invite, "invite");
|
||||
|
||||
// Even better, invite() can also be made a member of world_class!!!
|
||||
world_class.def(invite, "invite");
|
||||
}
|
||||
|
||||
// Win32 DLL boilerplate
|
||||
#if defined(_WIN32)
|
||||
#include <windows.h>
|
||||
extern "C" BOOL WINAPI DllMain(HINSTANCE, DWORD, LPVOID) { return 1; }
|
||||
#endif // _WIN32
|
||||
@@ -1,101 +0,0 @@
|
||||
#include <py_cpp/class_wrapper.h>
|
||||
#include <py_cpp/objects.h>
|
||||
|
||||
#define rangei(n) for (int i = 0; i < n; i++)
|
||||
|
||||
namespace { // Avoid cluttering the global namespace.
|
||||
|
||||
// A wrapper is used to define additional constructors.
|
||||
//
|
||||
struct vector_double_wrapper: std::vector<double>
|
||||
{
|
||||
// Tell the compiler how to convert a base class object to
|
||||
// this wrapper object.
|
||||
vector_double_wrapper(PyObject*, const std::vector<double>& vd)
|
||||
: std::vector<double>(vd) {}
|
||||
|
||||
vector_double_wrapper(PyObject* self)
|
||||
: std::vector<double>() {}
|
||||
|
||||
vector_double_wrapper(PyObject* self, const int n)
|
||||
: std::vector<double>(n) {}
|
||||
|
||||
vector_double_wrapper(PyObject* self, py::Tuple tuple)
|
||||
: std::vector<double>(tuple.size())
|
||||
{
|
||||
std::vector<double>::iterator vd = begin();
|
||||
rangei(tuple.size())
|
||||
vd[i] = from_python(tuple[i].get(), py::Type<double>()); // GCC BUG
|
||||
}
|
||||
};
|
||||
|
||||
double getitem(const std::vector<double>& vd, const std::size_t key) {
|
||||
return vd[key];
|
||||
}
|
||||
|
||||
void setitem(std::vector<double>& vd, const std::size_t key,
|
||||
const double &d) {
|
||||
std::vector<double>::iterator vditer = vd.begin();
|
||||
vditer[key] = d;
|
||||
}
|
||||
|
||||
void delitem(std::vector<double>& vd, const std::size_t key) {
|
||||
std::vector<double>::iterator vditer = vd.begin();
|
||||
vd.erase(&vditer[key]);
|
||||
}
|
||||
|
||||
// Convert vector_double to a regular Python tuple.
|
||||
//
|
||||
py::Tuple as_tuple(const std::vector<double>& vd)
|
||||
{
|
||||
py::Tuple t(vd.size());
|
||||
rangei(vd.size()) t.set_item(i, py::Ptr(py::to_python(vd[i]))); // GCC BUG
|
||||
return t;
|
||||
}
|
||||
|
||||
// Function returning a vector_double object to Python.
|
||||
//
|
||||
std::vector<double> foo(const int n)
|
||||
{
|
||||
std::vector<double> vd(n);
|
||||
std::vector<double>::iterator vditer = vd.begin();
|
||||
rangei(n) vditer[i] = double(i);
|
||||
return vd;
|
||||
}
|
||||
|
||||
// Same as foo(), but avoid copying on return.
|
||||
//
|
||||
std::auto_ptr<std::vector<double> > bar(const int n)
|
||||
{
|
||||
std::auto_ptr<std::vector<double> > vdptr(new std::vector<double>(n));
|
||||
std::vector<double>::iterator vditer = vdptr->begin();
|
||||
rangei(n) vditer[i] = double(10 * i);
|
||||
return vdptr;
|
||||
}
|
||||
}
|
||||
|
||||
BOOST_PYTHON_MODULE_INIT(example3)
|
||||
{
|
||||
py::Module this_module("example3");
|
||||
|
||||
py::ClassWrapper<std::vector<double>, vector_double_wrapper>
|
||||
vector_double(this_module, "vector_double");
|
||||
|
||||
vector_double.def(py::Constructor<>());
|
||||
vector_double.def(py::Constructor<const int>());
|
||||
vector_double.def(py::Constructor<py::Tuple>());
|
||||
vector_double.def(&std::vector<double>::size, "__len__");
|
||||
vector_double.def(getitem, "__getitem__");
|
||||
vector_double.def(setitem, "__setitem__");
|
||||
vector_double.def(delitem, "__delitem__");
|
||||
vector_double.def(as_tuple, "as_tuple");
|
||||
|
||||
this_module.def(foo, "foo");
|
||||
this_module.def(bar, "bar");
|
||||
}
|
||||
|
||||
// Win32 DLL boilerplate
|
||||
#if defined(_WIN32)
|
||||
#include <windows.h>
|
||||
extern "C" BOOL WINAPI DllMain(HINSTANCE, DWORD, LPVOID) { return 1; }
|
||||
#endif // _WIN32
|
||||
@@ -91,7 +91,7 @@ BOOST_PYTHON_MODULE_INIT(simple_vector)
|
||||
vector_double(this_module, "vector_double");
|
||||
|
||||
vector_double.def(python::constructor<>());
|
||||
vector_double.def(python::constructor<const int>());
|
||||
vector_double.def(python::constructor<int>());
|
||||
vector_double.def(python::constructor<python::tuple>());
|
||||
vector_double.def(&std::vector<double>::size, "__len__");
|
||||
vector_double.def(getitem, "__getitem__");
|
||||
|
||||
208
include/boost/python/class.hpp
Normal file
208
include/boost/python/class.hpp
Normal file
@@ -0,0 +1,208 @@
|
||||
// Copyright David Abrahams 2002. Permission to copy, use,
|
||||
// modify, sell and distribute this software is granted provided this
|
||||
// copyright notice appears in all copies. This software is provided
|
||||
// "as is" without express or implied warranty, and with no claim as
|
||||
// to its suitability for any purpose.
|
||||
#ifndef CLASS_DWA200216_HPP
|
||||
# define CLASS_DWA200216_HPP
|
||||
|
||||
# include <boost/python/class_fwd.hpp>
|
||||
# include <boost/python/reference.hpp>
|
||||
# include <boost/python/object/class.hpp>
|
||||
# include <boost/python/object/value_holder_fwd.hpp>
|
||||
# include <boost/python/converter/type_id.hpp>
|
||||
# include <boost/python/detail/wrap_function.hpp>
|
||||
# include <boost/python/detail/member_function_cast.hpp>
|
||||
# include <boost/mpl/type_list.hpp>
|
||||
# include <boost/python/object/class_converters.hpp>
|
||||
# include <boost/mpl/size.hpp>
|
||||
# include <boost/mpl/for_each.hpp>
|
||||
# include <boost/python/detail/type_list.hpp>
|
||||
|
||||
namespace // put some convenience classes into the unnamed namespace for the user
|
||||
{
|
||||
// A type list for specifying bases
|
||||
template < BOOST_MPL_LIST_DEFAULT_PARAMETERS(typename B, ::boost::mpl::null_argument) >
|
||||
struct bases : ::boost::mpl::type_list< BOOST_MPL_LIST_PARAMETERS(B) >::type
|
||||
{};
|
||||
|
||||
// A type list for specifying arguments
|
||||
template < BOOST_MPL_LIST_DEFAULT_PARAMETERS(typename A, ::boost::mpl::null_argument) >
|
||||
struct args : ::boost::mpl::type_list< BOOST_MPL_LIST_PARAMETERS(A) >::type
|
||||
{};
|
||||
}
|
||||
|
||||
namespace boost { namespace python {
|
||||
|
||||
namespace detail
|
||||
{
|
||||
// This is an mpl BinaryMetaFunction object with a runtime behavior,
|
||||
// which is to write the id of the type which is passed as its 2nd
|
||||
// compile-time argument into the iterator pointed to by its runtime
|
||||
// argument
|
||||
struct write_type_id
|
||||
{
|
||||
// The first argument is Ignored because mpl::for_each is still
|
||||
// currently an accumulate (reduce) implementation.
|
||||
template <class Ignored, class T> struct apply
|
||||
{
|
||||
// also an artifact of accumulate-based for_each
|
||||
typedef void type;
|
||||
|
||||
// Here's the runtime behavior
|
||||
static void execute(converter::undecorated_type_id_t** p)
|
||||
{
|
||||
*(*p)++ = converter::undecorated_type_id<T>();
|
||||
}
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
//
|
||||
// class_<T,Bases,HolderGenerator>
|
||||
//
|
||||
// This is the primary mechanism through which users will expose
|
||||
// C++ classes to Python. The three template arguments are:
|
||||
//
|
||||
// T - The class being exposed to Python
|
||||
//
|
||||
// Bases - An MPL sequence of base classes
|
||||
//
|
||||
// HolderGenerator -
|
||||
// An optional type generator for the "holder" which
|
||||
// maintains the C++ object inside the Python instance. The
|
||||
// default just holds the object "by-value", but other
|
||||
// holders can be substituted which will hold the C++ object
|
||||
// by smart pointer, for example.
|
||||
//
|
||||
template <
|
||||
class T // class being wrapped
|
||||
, class Bases
|
||||
, class HolderGenerator
|
||||
>
|
||||
class class_ : private objects::class_base
|
||||
{
|
||||
typedef class_<T,Bases,HolderGenerator> self;
|
||||
public:
|
||||
|
||||
// Automatically derive the class name - only works on some
|
||||
// compilers because type_info::name is sometimes mangled (gcc)
|
||||
class_();
|
||||
|
||||
// Construct with the class name. [ Would have used a default
|
||||
// argument but gcc-2.95.2 choked on typeid(T).name() as a default
|
||||
// parameter value]
|
||||
class_(char const* name);
|
||||
|
||||
|
||||
// Wrap a member function or a non-member function which can take
|
||||
// a T, T cv&, or T cv* as its first parameter, or a callable
|
||||
// python object.
|
||||
template <class F>
|
||||
self& def(char const* name, F f)
|
||||
{
|
||||
// Use function::add_to_namespace to achieve overloading if
|
||||
// appropriate.
|
||||
objects::function::add_to_namespace(
|
||||
this->object(), name,
|
||||
ref(detail::wrap_function(
|
||||
// This bit of nastiness casts F to a member function of T if possible.
|
||||
detail::member_function_cast<T,F>::stage1(f).stage2((T*)0).stage3(f)
|
||||
)));
|
||||
return *this;
|
||||
}
|
||||
|
||||
template <class Fn, class CallPolicy>
|
||||
self& def(char const* name, Fn fn, CallPolicy policy)
|
||||
{
|
||||
this->def(name
|
||||
, boost::python::make_function(
|
||||
// This bit of nastiness casts F to a member function of T if possible.
|
||||
detail::member_function_cast<T,Fn>::stage1(fn).stage2((T*)0).stage3(fn)
|
||||
, policy)
|
||||
);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
// Define the constructor with the given Args, which should be an
|
||||
// MPL sequence of types.
|
||||
template <class Args>
|
||||
self& def_init(Args const&)
|
||||
{
|
||||
def("__init__", make_constructor<T,Args,HolderGenerator>());
|
||||
return *this;
|
||||
}
|
||||
|
||||
// Define the default constructor.
|
||||
self& def_init()
|
||||
{
|
||||
this->def_init(mpl::type_list<>::type());
|
||||
return *this;
|
||||
}
|
||||
|
||||
// return the underlying object
|
||||
ref object() const;
|
||||
|
||||
private: // types
|
||||
typedef objects::class_id class_id;
|
||||
|
||||
// A helper class which will contain an array of id objects to be
|
||||
// passed to the base class constructor
|
||||
struct id_vector
|
||||
{
|
||||
typedef objects::class_id class_id;
|
||||
id_vector()
|
||||
{
|
||||
// Stick the derived class id into the first element of the array
|
||||
ids[0] = converter::undecorated_type_id<T>();
|
||||
|
||||
// Write the rest of the elements into succeeding positions.
|
||||
class_id* p = ids + 1;
|
||||
mpl::for_each<Bases, void, detail::write_type_id>::execute(&p);
|
||||
}
|
||||
|
||||
BOOST_STATIC_CONSTANT(
|
||||
std::size_t, size = mpl::size<Bases>::value + 1);
|
||||
class_id ids[size];
|
||||
};
|
||||
|
||||
private: // helper functions
|
||||
void initialize_converters();
|
||||
};
|
||||
|
||||
|
||||
//
|
||||
// implementations
|
||||
//
|
||||
template <class T, class Bases, class HolderGenerator>
|
||||
inline class_<T, Bases, HolderGenerator>::class_()
|
||||
: class_base(typeid(T).name(), id_vector::size, id_vector().ids)
|
||||
{
|
||||
// Bring the class converters into existence. This static object
|
||||
// will survive until the shared library this module lives in is
|
||||
// unloaded (that doesn't happen until Python terminates).
|
||||
static objects::class_converters<T,Bases> converters(object());
|
||||
}
|
||||
|
||||
template <class T, class Bases, class HolderGenerator>
|
||||
inline class_<T, Bases, HolderGenerator>::class_(char const* name)
|
||||
: class_base(name, id_vector::size, id_vector().ids)
|
||||
{
|
||||
// Bring the class converters into existence. This static object
|
||||
// will survive until the shared library this module lives in is
|
||||
// unloaded (that doesn't happen until Python terminates).
|
||||
static objects::class_converters<T,Bases> converters(object());
|
||||
}
|
||||
|
||||
template <class T, class Bases, class HolderGenerator>
|
||||
inline ref class_<T, Bases, HolderGenerator>::object() const
|
||||
{
|
||||
typedef objects::class_base base;
|
||||
|
||||
return this->base::object();
|
||||
}
|
||||
|
||||
}} // namespace boost::python
|
||||
|
||||
#endif // CLASS_DWA200216_HPP
|
||||
@@ -25,6 +25,22 @@ class class_builder
|
||||
module.add(ref(as_object(m_class.get()), ref::increment_count), name);
|
||||
}
|
||||
|
||||
template <class OtherT, class OtherU>
|
||||
class_builder(class_builder<OtherT, OtherU>& cls, const char* name)
|
||||
: m_class(new detail::extension_class<T, U>(name))
|
||||
{
|
||||
cls.add(ref(as_object(m_class.get()), ref::increment_count), name);
|
||||
}
|
||||
|
||||
template <class OtherT, class OtherU>
|
||||
class_builder(detail::extension_class<OtherT, OtherU>* cls,
|
||||
const char* name)
|
||||
: m_class(new detail::extension_class<T, U>(name))
|
||||
{
|
||||
cls->set_attribute(name,
|
||||
ref(as_object(m_class.get()), ref::increment_count));
|
||||
}
|
||||
|
||||
~class_builder()
|
||||
{}
|
||||
|
||||
|
||||
26
include/boost/python/class_fwd.hpp
Normal file
26
include/boost/python/class_fwd.hpp
Normal file
@@ -0,0 +1,26 @@
|
||||
// Copyright David Abrahams 2002. Permission to copy, use,
|
||||
// modify, sell and distribute this software is granted provided this
|
||||
// copyright notice appears in all copies. This software is provided
|
||||
// "as is" without express or implied warranty, and with no claim as
|
||||
// to its suitability for any purpose.
|
||||
#ifndef CLASS_FWD_DWA200222_HPP
|
||||
# define CLASS_FWD_DWA200222_HPP
|
||||
# include <boost/python/object/value_holder_fwd.hpp>
|
||||
|
||||
namespace boost { namespace python {
|
||||
|
||||
namespace detail
|
||||
{
|
||||
struct empty_list;
|
||||
}
|
||||
|
||||
template <
|
||||
class T // class being wrapped
|
||||
, class Bases = detail::empty_list
|
||||
, class HolderGenerator = objects::value_holder_generator<>
|
||||
>
|
||||
class class_;
|
||||
|
||||
}} // namespace boost::python
|
||||
|
||||
#endif // CLASS_FWD_DWA200222_HPP
|
||||
@@ -20,7 +20,7 @@
|
||||
namespace boost { namespace python {
|
||||
|
||||
// A simple type which acts something like a built-in Python class obj.
|
||||
class instance
|
||||
class BOOST_PYTHON_DECL instance
|
||||
: public boost::python::detail::python_object
|
||||
{
|
||||
public:
|
||||
@@ -78,6 +78,19 @@ class instance
|
||||
PyObject* gt(PyObject* other);
|
||||
PyObject* ge(PyObject* other);
|
||||
|
||||
// Inplace operations.
|
||||
PyObject* inplace_add(PyObject* other);
|
||||
PyObject* inplace_subtract(PyObject* other);
|
||||
PyObject* inplace_multiply(PyObject* other);
|
||||
PyObject* inplace_divide(PyObject* other);
|
||||
PyObject* inplace_remainder(PyObject* other);
|
||||
PyObject* inplace_power(PyObject* exponent, PyObject* modulus);
|
||||
PyObject* inplace_lshift(PyObject* other);
|
||||
PyObject* inplace_rshift(PyObject* other);
|
||||
PyObject* inplace_and(PyObject* other);
|
||||
PyObject* inplace_or(PyObject* other);
|
||||
PyObject* inplace_xor(PyObject* other);
|
||||
|
||||
private: // noncopyable, without the size bloat
|
||||
instance(const instance&);
|
||||
void operator=(const instance&);
|
||||
@@ -92,7 +105,7 @@ class instance
|
||||
template <class T> class meta_class;
|
||||
|
||||
namespace detail {
|
||||
class class_base : public type_object_base
|
||||
class BOOST_PYTHON_DECL class_base : public type_object_base
|
||||
{
|
||||
public:
|
||||
class_base(PyTypeObject* meta_class_obj, string name, tuple bases, const dictionary& name_space);
|
||||
@@ -115,6 +128,10 @@ namespace detail {
|
||||
|
||||
private: // boost::python::type_object_base required interface implementation
|
||||
void instance_dealloc(PyObject*) const; // subclasses should not override this
|
||||
|
||||
private: // noncopyable, without the size bloat
|
||||
class_base(const class_base&);
|
||||
void operator=(const class_base&);
|
||||
|
||||
private:
|
||||
string m_name;
|
||||
@@ -128,11 +145,12 @@ namespace detail {
|
||||
// A type which acts a lot like a built-in Python class. T is the obj type,
|
||||
// so class_t<instance> is a very simple "class-alike".
|
||||
template <class T>
|
||||
class class_t
|
||||
class BOOST_PYTHON_DECL_TEMPLATE class_t
|
||||
: public boost::python::detail::class_base
|
||||
{
|
||||
public:
|
||||
class_t(meta_class<T>* meta_class_obj, string name, tuple bases, const dictionary& name_space);
|
||||
~class_t();
|
||||
|
||||
// Standard Python functions.
|
||||
PyObject* call(PyObject* args, PyObject* keywords);
|
||||
@@ -178,6 +196,18 @@ class class_t
|
||||
PyObject* instance_number_oct(PyObject*) const;
|
||||
PyObject* instance_number_hex(PyObject*) const;
|
||||
|
||||
PyObject* instance_number_inplace_add(PyObject*, PyObject*) const;
|
||||
PyObject* instance_number_inplace_subtract(PyObject*, PyObject*) const;
|
||||
PyObject* instance_number_inplace_multiply(PyObject*, PyObject*) const;
|
||||
PyObject* instance_number_inplace_divide(PyObject*, PyObject*) const;
|
||||
PyObject* instance_number_inplace_remainder(PyObject*, PyObject*) const;
|
||||
PyObject* instance_number_inplace_power(PyObject*, PyObject*, PyObject*) const;
|
||||
PyObject* instance_number_inplace_lshift(PyObject*, PyObject*) const;
|
||||
PyObject* instance_number_inplace_rshift(PyObject*, PyObject*) const;
|
||||
PyObject* instance_number_inplace_and(PyObject*, PyObject*) const;
|
||||
PyObject* instance_number_inplace_or(PyObject*, PyObject*) const;
|
||||
PyObject* instance_number_inplace_xor(PyObject*, PyObject*) const;
|
||||
|
||||
private: // Implement rich comparisons
|
||||
PyObject* instance_lt(PyObject*, PyObject*) const;
|
||||
PyObject* instance_le(PyObject*, PyObject*) const;
|
||||
@@ -193,21 +223,17 @@ class class_t
|
||||
|
||||
private: // Implementation of boost::python::detail::class_base required interface
|
||||
void delete_instance(PyObject*) const;
|
||||
|
||||
private: // noncopyable, without the size bloat
|
||||
class_t(const class_t<T>&);
|
||||
void operator=(const class_t&);
|
||||
};
|
||||
|
||||
// The type of a class_t<T> object.
|
||||
template <class T>
|
||||
class meta_class
|
||||
class BOOST_PYTHON_DECL_TEMPLATE meta_class
|
||||
: public boost::python::detail::reprable<
|
||||
boost::python::detail::callable<
|
||||
boost::python::detail::getattrable<
|
||||
boost::python::detail::setattrable<
|
||||
boost::python::detail::type_object<class_t<T> > > > > >,
|
||||
boost::noncopyable
|
||||
private boost::noncopyable
|
||||
{
|
||||
public:
|
||||
meta_class();
|
||||
@@ -239,6 +265,11 @@ class_t<T>::class_t(meta_class<T>* meta_class_obj, string name, tuple bases, con
|
||||
{
|
||||
}
|
||||
|
||||
template <class T>
|
||||
class_t<T>::~class_t()
|
||||
{
|
||||
}
|
||||
|
||||
template <class T>
|
||||
void class_t<T>::delete_instance(PyObject* obj) const
|
||||
{
|
||||
@@ -319,7 +350,7 @@ int class_t<T>::instance_mapping_ass_subscript(PyObject* obj, PyObject* key, PyO
|
||||
return 0;
|
||||
}
|
||||
|
||||
void adjust_slice_indices(PyObject* obj, int& start, int& finish);
|
||||
void BOOST_PYTHON_DECL adjust_slice_indices(PyObject* obj, int& start, int& finish);
|
||||
|
||||
template <class T>
|
||||
PyObject* class_t<T>::instance_sequence_slice(PyObject* obj, int start, int finish) const
|
||||
@@ -493,6 +524,72 @@ PyObject* class_t<T>::instance_number_hex(PyObject* obj) const
|
||||
return downcast<T>(obj)->hex();
|
||||
}
|
||||
|
||||
template <class T>
|
||||
PyObject* class_t<T>::instance_number_inplace_add(PyObject* obj, PyObject* other) const
|
||||
{
|
||||
return downcast<T>(obj)->inplace_add(other);
|
||||
}
|
||||
|
||||
template <class T>
|
||||
PyObject* class_t<T>::instance_number_inplace_subtract(PyObject* obj, PyObject* other) const
|
||||
{
|
||||
return downcast<T>(obj)->inplace_subtract(other);
|
||||
}
|
||||
|
||||
template <class T>
|
||||
PyObject* class_t<T>::instance_number_inplace_multiply(PyObject* obj, PyObject* other) const
|
||||
{
|
||||
return downcast<T>(obj)->inplace_multiply(other);
|
||||
}
|
||||
|
||||
template <class T>
|
||||
PyObject* class_t<T>::instance_number_inplace_divide(PyObject* obj, PyObject* other) const
|
||||
{
|
||||
return downcast<T>(obj)->inplace_divide(other);
|
||||
}
|
||||
|
||||
template <class T>
|
||||
PyObject* class_t<T>::instance_number_inplace_remainder(PyObject* obj, PyObject* other) const
|
||||
{
|
||||
return downcast<T>(obj)->inplace_remainder(other);
|
||||
}
|
||||
|
||||
template <class T>
|
||||
PyObject* class_t<T>::instance_number_inplace_power(PyObject* obj, PyObject* exponent, PyObject* modulus) const
|
||||
{
|
||||
return downcast<T>(obj)->inplace_power(exponent, modulus);
|
||||
}
|
||||
|
||||
template <class T>
|
||||
PyObject* class_t<T>::instance_number_inplace_lshift(PyObject* obj, PyObject* other) const
|
||||
{
|
||||
return downcast<T>(obj)->inplace_lshift(other);
|
||||
}
|
||||
|
||||
template <class T>
|
||||
PyObject* class_t<T>::instance_number_inplace_rshift(PyObject* obj, PyObject* other) const
|
||||
{
|
||||
return downcast<T>(obj)->inplace_rshift(other);
|
||||
}
|
||||
|
||||
template <class T>
|
||||
PyObject* class_t<T>::instance_number_inplace_and(PyObject* obj, PyObject* other) const
|
||||
{
|
||||
return downcast<T>(obj)->inplace_and(other);
|
||||
}
|
||||
|
||||
template <class T>
|
||||
PyObject* class_t<T>::instance_number_inplace_or(PyObject* obj, PyObject* other) const
|
||||
{
|
||||
return downcast<T>(obj)->inplace_or(other);
|
||||
}
|
||||
|
||||
template <class T>
|
||||
PyObject* class_t<T>::instance_number_inplace_xor(PyObject* obj, PyObject* other) const
|
||||
{
|
||||
return downcast<T>(obj)->inplace_xor(other);
|
||||
}
|
||||
|
||||
template <class T>
|
||||
PyObject* class_t<T>::instance_lt(PyObject* obj, PyObject* other) const
|
||||
{
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
# include <boost/python/detail/wrap_python.hpp>
|
||||
# include <boost/python/detail/none.hpp>
|
||||
# include <boost/python/detail/signatures.hpp>
|
||||
# include <boost/smart_ptr.hpp>
|
||||
# include <boost/shared_ptr.hpp>
|
||||
# include <boost/python/errors.hpp>
|
||||
# include <string>
|
||||
|
||||
@@ -122,61 +122,67 @@ BOOST_PYTHON_BEGIN_CONVERSION_NAMESPACE
|
||||
// Converters
|
||||
//
|
||||
PyObject* to_python(long);
|
||||
long from_python(PyObject* p, boost::python::type<long>);
|
||||
BOOST_PYTHON_DECL long from_python(PyObject* p, boost::python::type<long>);
|
||||
long from_python(PyObject* p, boost::python::type<const long&>);
|
||||
|
||||
PyObject* to_python(unsigned long);
|
||||
unsigned long from_python(PyObject* p, boost::python::type<unsigned long>);
|
||||
BOOST_PYTHON_DECL PyObject* to_python(unsigned long);
|
||||
BOOST_PYTHON_DECL unsigned long from_python(PyObject* p, boost::python::type<unsigned long>);
|
||||
unsigned long from_python(PyObject* p, boost::python::type<const unsigned long&>);
|
||||
|
||||
PyObject* to_python(int);
|
||||
int from_python(PyObject*, boost::python::type<int>);
|
||||
BOOST_PYTHON_DECL int from_python(PyObject*, boost::python::type<int>);
|
||||
int from_python(PyObject*, boost::python::type<const int&>);
|
||||
|
||||
PyObject* to_python(unsigned int);
|
||||
unsigned int from_python(PyObject*, boost::python::type<unsigned int>);
|
||||
BOOST_PYTHON_DECL PyObject* to_python(unsigned int);
|
||||
BOOST_PYTHON_DECL unsigned int from_python(PyObject*, boost::python::type<unsigned int>);
|
||||
unsigned int from_python(PyObject*, boost::python::type<const unsigned int&>);
|
||||
|
||||
PyObject* to_python(short);
|
||||
short from_python(PyObject*, boost::python::type<short>);
|
||||
BOOST_PYTHON_DECL short from_python(PyObject*, boost::python::type<short>);
|
||||
short from_python(PyObject*, boost::python::type<const short&>);
|
||||
|
||||
PyObject* to_python(unsigned short);
|
||||
unsigned short from_python(PyObject*, boost::python::type<unsigned short>);
|
||||
BOOST_PYTHON_DECL PyObject* to_python(unsigned short);
|
||||
BOOST_PYTHON_DECL unsigned short from_python(PyObject*, boost::python::type<unsigned short>);
|
||||
unsigned short from_python(PyObject*, boost::python::type<const unsigned short&>);
|
||||
|
||||
PyObject* to_python(char);
|
||||
char from_python(PyObject*, boost::python::type<char>);
|
||||
BOOST_PYTHON_DECL PyObject* to_python(char);
|
||||
BOOST_PYTHON_DECL char from_python(PyObject*, boost::python::type<char>);
|
||||
char from_python(PyObject*, boost::python::type<const char&>);
|
||||
|
||||
PyObject* to_python(signed char);
|
||||
signed char from_python(PyObject*, boost::python::type<signed char>);
|
||||
BOOST_PYTHON_DECL PyObject* to_python(signed char);
|
||||
BOOST_PYTHON_DECL signed char from_python(PyObject*, boost::python::type<signed char>);
|
||||
signed char from_python(PyObject*, boost::python::type<const signed char&>);
|
||||
|
||||
PyObject* to_python(unsigned char);
|
||||
unsigned char from_python(PyObject*, boost::python::type<unsigned char>);
|
||||
BOOST_PYTHON_DECL PyObject* to_python(unsigned char);
|
||||
BOOST_PYTHON_DECL unsigned char from_python(PyObject*, boost::python::type<unsigned char>);
|
||||
unsigned char from_python(PyObject*, boost::python::type<const unsigned char&>);
|
||||
|
||||
BOOST_PYTHON_DECL float from_python(PyObject*, boost::python::type<float>);
|
||||
BOOST_PYTHON_DECL double from_python(PyObject*, boost::python::type<double>);
|
||||
|
||||
# ifndef BOOST_MSVC6_OR_EARLIER
|
||||
PyObject* to_python(float);
|
||||
float from_python(PyObject*, boost::python::type<float>);
|
||||
PyObject* to_python(double);
|
||||
# else
|
||||
BOOST_PYTHON_DECL PyObject* to_python(float);
|
||||
BOOST_PYTHON_DECL PyObject* to_python(double);
|
||||
# endif
|
||||
float from_python(PyObject*, boost::python::type<const float&>);
|
||||
|
||||
PyObject* to_python(double);
|
||||
double from_python(PyObject*, boost::python::type<double>);
|
||||
double from_python(PyObject*, boost::python::type<const double&>);
|
||||
|
||||
PyObject* to_python(bool);
|
||||
bool from_python(PyObject*, boost::python::type<bool>);
|
||||
BOOST_PYTHON_DECL bool from_python(PyObject*, boost::python::type<bool>);
|
||||
bool from_python(PyObject*, boost::python::type<const bool&>);
|
||||
|
||||
PyObject* to_python(void);
|
||||
void from_python(PyObject*, boost::python::type<void>);
|
||||
BOOST_PYTHON_DECL PyObject* to_python(void);
|
||||
BOOST_PYTHON_DECL void from_python(PyObject*, boost::python::type<void>);
|
||||
|
||||
PyObject* to_python(const char* s);
|
||||
const char* from_python(PyObject*, boost::python::type<const char*>);
|
||||
BOOST_PYTHON_DECL const char* from_python(PyObject*, boost::python::type<const char*>);
|
||||
|
||||
PyObject* to_python(const std::string& s);
|
||||
std::string from_python(PyObject*, boost::python::type<std::string>);
|
||||
BOOST_PYTHON_DECL PyObject* to_python(const std::string& s);
|
||||
BOOST_PYTHON_DECL std::string from_python(PyObject*, boost::python::type<std::string>);
|
||||
std::string from_python(PyObject*, boost::python::type<const std::string&>);
|
||||
|
||||
inline PyObject* to_python(const std::complex<float>& x)
|
||||
|
||||
104
include/boost/python/converter/builtin_converters.hpp
Normal file
104
include/boost/python/converter/builtin_converters.hpp
Normal file
@@ -0,0 +1,104 @@
|
||||
// Copyright David Abrahams 2002. Permission to copy, use,
|
||||
// modify, sell and distribute this software is granted provided this
|
||||
// copyright notice appears in all copies. This software is provided
|
||||
// "as is" without express or implied warranty, and with no claim as
|
||||
// to its suitability for any purpose.
|
||||
#ifndef BUILTIN_CONVERTERS_DWA2002124_HPP
|
||||
# define BUILTIN_CONVERTERS_DWA2002124_HPP
|
||||
# include <boost/python/detail/wrap_python.hpp>
|
||||
# include <boost/python/detail/none.hpp>
|
||||
# include <boost/python/reference.hpp>
|
||||
# include <string>
|
||||
# include <complex>
|
||||
|
||||
namespace boost { namespace python {
|
||||
|
||||
// Provide specializations of to_python_value
|
||||
template <class T> struct to_python_value;
|
||||
|
||||
namespace detail
|
||||
{
|
||||
struct builtin_to_python
|
||||
{
|
||||
static bool convertible() { return true; }
|
||||
};
|
||||
}
|
||||
|
||||
namespace converter
|
||||
{
|
||||
template <class T> struct callback_to_python;
|
||||
BOOST_PYTHON_DECL PyObject* do_call_to_python(char);
|
||||
BOOST_PYTHON_DECL PyObject* do_call_to_python(char const*);
|
||||
BOOST_PYTHON_DECL PyObject* do_call_to_python(PyObject*);
|
||||
BOOST_PYTHON_DECL PyObject* do_callback_to_python(PyObject*);
|
||||
}
|
||||
|
||||
# define BOOST_PYTHON_CALL_TO_PYTHON_BY_VALUE(T, expr) \
|
||||
template <> struct to_python_value<T&> \
|
||||
: detail::builtin_to_python \
|
||||
{ \
|
||||
PyObject* operator()(T const& x) const \
|
||||
{ \
|
||||
return (expr); \
|
||||
} \
|
||||
}; \
|
||||
template <> struct to_python_value<T const&> \
|
||||
: detail::builtin_to_python \
|
||||
{ \
|
||||
PyObject* operator()(T const& x) const \
|
||||
{ \
|
||||
return (expr); \
|
||||
} \
|
||||
};
|
||||
|
||||
# define BOOST_PYTHON_CALLBACK_TO_PYTHON_BY_VALUE(T, expr) \
|
||||
namespace converter \
|
||||
{ \
|
||||
template <> struct callback_to_python< T > \
|
||||
{ \
|
||||
callback_to_python(T const& x) \
|
||||
: m_held(expr) {} \
|
||||
PyObject* get() const \
|
||||
{ return m_held.get(); } \
|
||||
private: \
|
||||
ref m_held; \
|
||||
}; \
|
||||
}
|
||||
|
||||
# define BOOST_PYTHON_TO_PYTHON_BY_VALUE(T, expr) \
|
||||
BOOST_PYTHON_CALL_TO_PYTHON_BY_VALUE(T,expr) \
|
||||
BOOST_PYTHON_CALLBACK_TO_PYTHON_BY_VALUE(T,expr)
|
||||
|
||||
# define BOOST_PYTHON_TO_INT(T) \
|
||||
BOOST_PYTHON_TO_PYTHON_BY_VALUE(signed T, PyInt_FromLong(x)) \
|
||||
BOOST_PYTHON_TO_PYTHON_BY_VALUE(unsigned T, PyInt_FromLong(x))
|
||||
|
||||
BOOST_PYTHON_TO_PYTHON_BY_VALUE(bool, PyInt_FromLong(x))
|
||||
BOOST_PYTHON_TO_INT(char)
|
||||
BOOST_PYTHON_TO_INT(short)
|
||||
BOOST_PYTHON_TO_INT(int)
|
||||
BOOST_PYTHON_TO_INT(long)
|
||||
# undef BOOST_TO_PYTHON_INT
|
||||
|
||||
BOOST_PYTHON_TO_PYTHON_BY_VALUE(char, converter::do_call_to_python(x))
|
||||
BOOST_PYTHON_TO_PYTHON_BY_VALUE(char const*, converter::do_call_to_python(x))
|
||||
BOOST_PYTHON_TO_PYTHON_BY_VALUE(std::string, PyString_FromString(x.c_str()))
|
||||
BOOST_PYTHON_TO_PYTHON_BY_VALUE(float, PyFloat_FromDouble(x))
|
||||
BOOST_PYTHON_TO_PYTHON_BY_VALUE(double, PyFloat_FromDouble(x))
|
||||
BOOST_PYTHON_TO_PYTHON_BY_VALUE(long double, PyFloat_FromDouble(x))
|
||||
BOOST_PYTHON_CALL_TO_PYTHON_BY_VALUE(PyObject*, converter::do_call_to_python(x))
|
||||
BOOST_PYTHON_CALLBACK_TO_PYTHON_BY_VALUE(PyObject*, converter::do_callback_to_python(x))
|
||||
BOOST_PYTHON_TO_PYTHON_BY_VALUE(std::complex<float>, PyComplex_FromDoubles(x.real(), x.imag()))
|
||||
BOOST_PYTHON_TO_PYTHON_BY_VALUE(std::complex<double>, PyComplex_FromDoubles(x.real(), x.imag()))
|
||||
BOOST_PYTHON_TO_PYTHON_BY_VALUE(std::complex<long double>, PyComplex_FromDoubles(x.real(), x.imag()))
|
||||
|
||||
namespace converter
|
||||
{
|
||||
|
||||
void initialize_builtin_converters();
|
||||
|
||||
}
|
||||
|
||||
}} // namespace boost::python::converter
|
||||
|
||||
#endif // BUILTIN_CONVERTERS_DWA2002124_HPP
|
||||
242
include/boost/python/converter/callback.hpp
Normal file
242
include/boost/python/converter/callback.hpp
Normal file
@@ -0,0 +1,242 @@
|
||||
// Copyright David Abrahams 2002. Permission to copy, use,
|
||||
// modify, sell and distribute this software is granted provided this
|
||||
// copyright notice appears in all copies. This software is provided
|
||||
// "as is" without express or implied warranty, and with no claim as
|
||||
// to its suitability for any purpose.
|
||||
#ifndef CALLBACK_DWA2002228_HPP
|
||||
# define CALLBACK_DWA2002228_HPP
|
||||
|
||||
# include <boost/python/converter/type_id.hpp>
|
||||
# include <boost/python/converter/to_python_function.hpp>
|
||||
# include <boost/python/converter/pointee_to_python_function.hpp>
|
||||
# include <boost/python/converter/from_python.hpp>
|
||||
# include <boost/mpl/select_type.hpp>
|
||||
# include <boost/python/converter/callback_to_python_base.hpp>
|
||||
# include <boost/python/converter/callback_from_python_base.hpp>
|
||||
# include <boost/python/converter/builtin_converters.hpp>
|
||||
# include <boost/python/to_python_indirect.hpp>
|
||||
# include <boost/python/detail/none.hpp>
|
||||
# include <boost/python/ptr.hpp>
|
||||
|
||||
namespace boost { namespace python { namespace converter {
|
||||
|
||||
namespace detail
|
||||
{
|
||||
template <class T>
|
||||
struct pointer_callback_from_python
|
||||
{
|
||||
pointer_callback_from_python();
|
||||
T operator()(PyObject*) const;
|
||||
};
|
||||
|
||||
template <class T>
|
||||
struct reference_callback_from_python
|
||||
{
|
||||
reference_callback_from_python();
|
||||
T operator()(PyObject*) const;
|
||||
};
|
||||
|
||||
template <class T>
|
||||
struct rvalue_callback_from_python
|
||||
{
|
||||
rvalue_callback_from_python();
|
||||
T const& operator()(PyObject*);
|
||||
private:
|
||||
rvalue_data<T> m_data;
|
||||
};
|
||||
|
||||
template <class T>
|
||||
struct select_callback_from_python
|
||||
{
|
||||
BOOST_STATIC_CONSTANT(
|
||||
bool, ptr = is_pointer<T>::value);
|
||||
|
||||
BOOST_STATIC_CONSTANT(
|
||||
bool, ref = is_reference<T>::value);
|
||||
|
||||
typedef typename mpl::select_type<
|
||||
ptr
|
||||
, pointer_callback_from_python<T>
|
||||
, typename mpl::select_type<
|
||||
ref
|
||||
, reference_callback_from_python<T>
|
||||
, rvalue_callback_from_python<T>
|
||||
>::type
|
||||
>::type type;
|
||||
};
|
||||
|
||||
|
||||
template <class T>
|
||||
struct reference_callback_to_python : callback_to_python_holder
|
||||
{
|
||||
reference_callback_to_python(T& x);
|
||||
private:
|
||||
static PyObject* get_object(T& x);
|
||||
};
|
||||
|
||||
template <class T>
|
||||
struct value_callback_to_python : callback_to_python_base
|
||||
{
|
||||
// Throw an exception if the conversion can't succeed
|
||||
value_callback_to_python(T const&);
|
||||
};
|
||||
|
||||
template <class Ptr>
|
||||
struct pointer_deep_callback_to_python : callback_to_python_base
|
||||
{
|
||||
// Throw an exception if the conversion can't succeed
|
||||
pointer_deep_callback_to_python(Ptr);
|
||||
};
|
||||
|
||||
template <class Ptr>
|
||||
struct pointer_shallow_callback_to_python : callback_to_python_holder
|
||||
{
|
||||
// Throw an exception if the conversion can't succeed
|
||||
pointer_shallow_callback_to_python(Ptr);
|
||||
private:
|
||||
static PyObject* get_object(Ptr p);
|
||||
};
|
||||
|
||||
template <class T>
|
||||
struct select_callback_to_python
|
||||
{
|
||||
BOOST_STATIC_CONSTANT(
|
||||
bool, ptr = is_pointer<T>::value);
|
||||
|
||||
BOOST_STATIC_CONSTANT(
|
||||
bool, ref_wrapper = is_reference_wrapper<T>::value);
|
||||
|
||||
BOOST_STATIC_CONSTANT(
|
||||
bool, ptr_wrapper = is_pointer_wrapper<T>::value);
|
||||
|
||||
typedef typename unwrap_reference<T>::type unwrapped_referent;
|
||||
typedef typename unwrap_pointer<T>::type unwrapped_ptr;
|
||||
|
||||
typedef typename mpl::select_type<
|
||||
ptr
|
||||
, pointer_deep_callback_to_python<T>
|
||||
, typename mpl::select_type<
|
||||
ptr_wrapper
|
||||
, pointer_shallow_callback_to_python<unwrapped_ptr>
|
||||
, typename mpl::select_type<
|
||||
ref_wrapper
|
||||
, reference_callback_to_python<unwrapped_referent>
|
||||
, value_callback_to_python<T>
|
||||
>::type
|
||||
>::type
|
||||
>::type type;
|
||||
};
|
||||
}
|
||||
|
||||
template <class T>
|
||||
struct callback_from_python
|
||||
: detail::select_callback_from_python<T>::type
|
||||
{
|
||||
};
|
||||
|
||||
template <class T>
|
||||
struct callback_to_python
|
||||
: detail::select_callback_to_python<T>::type
|
||||
{
|
||||
typedef typename detail::select_callback_to_python<T>::type base;
|
||||
public: // member functions
|
||||
// Throw an exception if the conversion can't succeed
|
||||
callback_to_python(T const& x);
|
||||
};
|
||||
|
||||
//
|
||||
// Implementations
|
||||
//
|
||||
namespace detail
|
||||
{
|
||||
template <class T>
|
||||
inline rvalue_callback_from_python<T>::rvalue_callback_from_python()
|
||||
: m_data(rvalue_from_python_chain<T>::value)
|
||||
{
|
||||
throw_if_not_registered(m_data.stage1);
|
||||
}
|
||||
|
||||
template <class T>
|
||||
inline T const& rvalue_callback_from_python<T>::operator()(PyObject* obj)
|
||||
{
|
||||
return *(T*)convert_rvalue(obj, m_data.stage1, m_data.storage.bytes);
|
||||
}
|
||||
|
||||
BOOST_PYTHON_DECL void throw_no_class_registered();
|
||||
|
||||
template <class T>
|
||||
inline reference_callback_from_python<T>::reference_callback_from_python()
|
||||
{
|
||||
detail::throw_if_not_registered(lvalue_from_python_chain<T,true>::value);
|
||||
}
|
||||
|
||||
template <class T>
|
||||
inline T reference_callback_from_python<T>::operator()(PyObject* obj) const
|
||||
{
|
||||
return python::detail::void_ptr_to_reference(
|
||||
callback_convert_reference(obj, lvalue_from_python_chain<T,true>::value)
|
||||
, (T(*)())0);
|
||||
}
|
||||
|
||||
template <class T>
|
||||
inline pointer_callback_from_python<T>::pointer_callback_from_python()
|
||||
{
|
||||
detail::throw_if_not_registered(lvalue_from_python_chain<T,true>::value);
|
||||
}
|
||||
|
||||
template <class T>
|
||||
inline T pointer_callback_from_python<T>::operator()(PyObject* obj) const
|
||||
{
|
||||
return T(callback_convert_pointer(obj, lvalue_from_python_chain<T,true>::value));
|
||||
}
|
||||
|
||||
template <class T>
|
||||
inline value_callback_to_python<T>::value_callback_to_python(T const& x)
|
||||
: callback_to_python_base(&x, to_python_function<T>::value)
|
||||
{
|
||||
}
|
||||
|
||||
template <class Ptr>
|
||||
inline pointer_deep_callback_to_python<Ptr>::pointer_deep_callback_to_python(Ptr x)
|
||||
: callback_to_python_base(x, pointee_to_python_function<Ptr>::value)
|
||||
{
|
||||
}
|
||||
|
||||
template <class T>
|
||||
inline PyObject* reference_callback_to_python<T>::get_object(T& x)
|
||||
{
|
||||
to_python_indirect<T&,python::detail::make_reference_holder> convert;
|
||||
if (!convert.convertible())
|
||||
throw_no_class_registered();
|
||||
return convert(x);
|
||||
}
|
||||
|
||||
template <class T>
|
||||
inline reference_callback_to_python<T>::reference_callback_to_python(T& x)
|
||||
: callback_to_python_holder(get_object(x))
|
||||
{
|
||||
}
|
||||
|
||||
template <class Ptr>
|
||||
inline pointer_shallow_callback_to_python<Ptr>::pointer_shallow_callback_to_python(Ptr x)
|
||||
: callback_to_python_holder(get_object(x))
|
||||
{}
|
||||
|
||||
template <class Ptr>
|
||||
inline PyObject* pointer_shallow_callback_to_python<Ptr>::get_object(Ptr x)
|
||||
{
|
||||
to_python_indirect<Ptr,python::detail::make_reference_holder> convert;
|
||||
if (!convert.convertible())
|
||||
throw_no_class_registered();
|
||||
return x ? convert(x) : python::detail::none();
|
||||
}
|
||||
}
|
||||
|
||||
template <class T>
|
||||
inline callback_to_python<T>::callback_to_python(T const& x)
|
||||
: base(x)
|
||||
{}
|
||||
|
||||
}}} // namespace boost::python::converter
|
||||
|
||||
#endif // CALLBACK_DWA2002228_HPP
|
||||
25
include/boost/python/converter/callback_from_python_base.hpp
Normal file
25
include/boost/python/converter/callback_from_python_base.hpp
Normal file
@@ -0,0 +1,25 @@
|
||||
// Copyright David Abrahams 2002. Permission to copy, use,
|
||||
// modify, sell and distribute this software is granted provided this
|
||||
// copyright notice appears in all copies. This software is provided
|
||||
// "as is" without express or implied warranty, and with no claim as
|
||||
// to its suitability for any purpose.
|
||||
#ifndef CALLBACK_FROM_PYTHON_BASE_DWA200237_HPP
|
||||
# define CALLBACK_FROM_PYTHON_BASE_DWA200237_HPP
|
||||
|
||||
namespace boost { namespace python { namespace converter {
|
||||
|
||||
namespace detail
|
||||
{
|
||||
|
||||
// Throw an exception
|
||||
BOOST_PYTHON_DECL void throw_if_not_registered(rvalue_stage1_data const&);
|
||||
BOOST_PYTHON_DECL void* convert_rvalue(PyObject*, rvalue_stage1_data& data, void* storage);
|
||||
|
||||
BOOST_PYTHON_DECL void throw_if_not_registered(lvalue_from_python_registration*const&);
|
||||
BOOST_PYTHON_DECL void* callback_convert_reference(PyObject*, lvalue_from_python_registration*const&);
|
||||
BOOST_PYTHON_DECL void* callback_convert_pointer(PyObject*, lvalue_from_python_registration*const&);
|
||||
}
|
||||
|
||||
}}} // namespace boost::python::converter
|
||||
|
||||
#endif // CALLBACK_FROM_PYTHON_BASE_DWA200237_HPP
|
||||
45
include/boost/python/converter/callback_to_python_base.hpp
Normal file
45
include/boost/python/converter/callback_to_python_base.hpp
Normal file
@@ -0,0 +1,45 @@
|
||||
// Copyright David Abrahams 2002. Permission to copy, use,
|
||||
// modify, sell and distribute this software is granted provided this
|
||||
// copyright notice appears in all copies. This software is provided
|
||||
// "as is" without express or implied warranty, and with no claim as
|
||||
// to its suitability for any purpose.
|
||||
#ifndef CALLBACK_TO_PYTHON_BASE_DWA200237_HPP
|
||||
# define CALLBACK_TO_PYTHON_BASE_DWA200237_HPP
|
||||
# include <boost/python/converter/to_python_function_type.hpp>
|
||||
# include <boost/python/detail/wrap_python.hpp>
|
||||
# include <boost/python/reference.hpp>
|
||||
|
||||
namespace boost { namespace python { namespace converter {
|
||||
|
||||
namespace detail
|
||||
{
|
||||
struct callback_to_python_holder
|
||||
{
|
||||
callback_to_python_holder(PyObject* obj);
|
||||
inline PyObject* get() const;
|
||||
private:
|
||||
ref m_held;
|
||||
};
|
||||
|
||||
struct BOOST_PYTHON_DECL callback_to_python_base : callback_to_python_holder
|
||||
{
|
||||
callback_to_python_base(void const volatile* source, to_python_function_t);
|
||||
};
|
||||
|
||||
//
|
||||
// implmentation
|
||||
//
|
||||
inline callback_to_python_holder::callback_to_python_holder(PyObject* obj)
|
||||
: m_held(obj)
|
||||
{
|
||||
}
|
||||
|
||||
inline PyObject* callback_to_python_holder::get() const
|
||||
{
|
||||
return m_held.get();
|
||||
}
|
||||
}
|
||||
|
||||
}}} // namespace boost::python::converter
|
||||
|
||||
#endif // CALLBACK_TO_PYTHON_BASE_DWA200237_HPP
|
||||
26
include/boost/python/converter/find_from_python.hpp
Normal file
26
include/boost/python/converter/find_from_python.hpp
Normal file
@@ -0,0 +1,26 @@
|
||||
// Copyright David Abrahams 2002. Permission to copy, use,
|
||||
// modify, sell and distribute this software is granted provided this
|
||||
// copyright notice appears in all copies. This software is provided
|
||||
// "as is" without express or implied warranty, and with no claim as
|
||||
// to its suitability for any purpose.
|
||||
#ifndef FIND_FROM_PYTHON_DWA2002223_HPP
|
||||
# define FIND_FROM_PYTHON_DWA2002223_HPP
|
||||
|
||||
# include <boost/python/detail/config.hpp>
|
||||
# include <boost/python/detail/wrap_python.hpp>
|
||||
# include <boost/python/converter/from_python_stage1_data.hpp>
|
||||
|
||||
namespace boost { namespace python { namespace converter {
|
||||
|
||||
struct lvalue_from_python_registration;
|
||||
struct rvalue_from_python_registration;
|
||||
|
||||
BOOST_PYTHON_DECL void* find(
|
||||
PyObject* source, lvalue_from_python_registration const*);
|
||||
|
||||
BOOST_PYTHON_DECL rvalue_stage1_data find(
|
||||
PyObject* source, rvalue_from_python_registration const*);
|
||||
|
||||
}}} // namespace boost::python::converter
|
||||
|
||||
#endif // FIND_FROM_PYTHON_DWA2002223_HPP
|
||||
237
include/boost/python/converter/from_python.hpp
Normal file
237
include/boost/python/converter/from_python.hpp
Normal file
@@ -0,0 +1,237 @@
|
||||
// Copyright David Abrahams 2002. Permission to copy, use,
|
||||
// modify, sell and distribute this software is granted provided this
|
||||
// copyright notice appears in all copies. This software is provided
|
||||
// "as is" without express or implied warranty, and with no claim as
|
||||
// to its suitability for any purpose.
|
||||
#ifndef FROM_PYTHON_DWA2002127_HPP
|
||||
# define FROM_PYTHON_DWA2002127_HPP
|
||||
|
||||
# include <boost/python/converter/find_from_python.hpp>
|
||||
# include <boost/python/detail/wrap_python.hpp>
|
||||
# include <boost/type_traits/transform_traits.hpp>
|
||||
# include <boost/type_traits/cv_traits.hpp>
|
||||
# include <boost/python/converter/from_python_data.hpp>
|
||||
# include <boost/mpl/select_type.hpp>
|
||||
# include <boost/python/converter/registry.hpp>
|
||||
# include <boost/python/converter/lvalue_from_python_chain.hpp>
|
||||
# include <boost/python/converter/rvalue_from_python_chain.hpp>
|
||||
# include <boost/python/detail/void_ptr.hpp>
|
||||
|
||||
namespace boost { namespace python { namespace converter {
|
||||
|
||||
struct from_python_base
|
||||
{
|
||||
public: // member functions
|
||||
from_python_base(void* result);
|
||||
from_python_base(PyObject*, lvalue_from_python_registration const* chain);
|
||||
bool convertible() const;
|
||||
|
||||
protected: // member functions
|
||||
void*const& result() const;
|
||||
|
||||
private: // data members
|
||||
void* m_result;
|
||||
};
|
||||
|
||||
// Used when T == U*const&
|
||||
template <class T>
|
||||
struct pointer_const_reference_from_python
|
||||
{
|
||||
pointer_const_reference_from_python(PyObject*);
|
||||
T operator()(PyObject*) const;
|
||||
bool convertible() const;
|
||||
|
||||
private:
|
||||
typename detail::referent_storage<T>::type m_result;
|
||||
};
|
||||
|
||||
// Used when T == U*
|
||||
template <class T>
|
||||
struct pointer_from_python : from_python_base
|
||||
{
|
||||
pointer_from_python(PyObject*);
|
||||
T operator()(PyObject*) const;
|
||||
};
|
||||
|
||||
// Used when T == U& and (T != V const& or T == W volatile&)
|
||||
template <class T>
|
||||
struct reference_from_python : from_python_base
|
||||
{
|
||||
reference_from_python(PyObject*);
|
||||
T operator()(PyObject*) const;
|
||||
};
|
||||
|
||||
// ------- rvalue converters ---------
|
||||
|
||||
// Used for the case where T is a non-pointer, non-reference type OR
|
||||
// is a const non-volatile reference to a non-pointer type.
|
||||
template <class T>
|
||||
class rvalue_from_python
|
||||
{
|
||||
typedef typename boost::add_reference<
|
||||
typename boost::add_const<T>::type
|
||||
>::type result_type;
|
||||
|
||||
public:
|
||||
rvalue_from_python(PyObject*);
|
||||
bool convertible() const;
|
||||
|
||||
result_type operator()(PyObject*);
|
||||
|
||||
private:
|
||||
rvalue_data<result_type> m_data;
|
||||
};
|
||||
|
||||
template <class T>
|
||||
struct select_from_python
|
||||
{
|
||||
BOOST_STATIC_CONSTANT(
|
||||
bool, ptr = is_pointer<T>::value);
|
||||
|
||||
BOOST_STATIC_CONSTANT(
|
||||
bool, ptr_cref
|
||||
= boost::python::detail::is_reference_to_pointer<T>::value
|
||||
&& boost::python::detail::is_reference_to_const<T>::value
|
||||
&& !boost::python::detail::is_reference_to_volatile<T>::value);
|
||||
|
||||
|
||||
BOOST_STATIC_CONSTANT(
|
||||
bool, ref =
|
||||
boost::python::detail::is_reference_to_non_const<T>::value
|
||||
|| boost::python::detail::is_reference_to_volatile<T>::value);
|
||||
|
||||
typedef typename mpl::select_type<
|
||||
ptr
|
||||
, pointer_from_python<T>
|
||||
, typename mpl::select_type<
|
||||
ptr_cref
|
||||
, pointer_const_reference_from_python<T>
|
||||
, typename mpl::select_type<
|
||||
ref
|
||||
, reference_from_python<T>
|
||||
, rvalue_from_python<T>
|
||||
>::type
|
||||
>::type
|
||||
>::type type;
|
||||
};
|
||||
|
||||
//
|
||||
// implementations
|
||||
//
|
||||
inline from_python_base::from_python_base(void* result)
|
||||
: m_result(result)
|
||||
{
|
||||
}
|
||||
|
||||
inline from_python_base::from_python_base(
|
||||
PyObject* source
|
||||
, lvalue_from_python_registration const* chain)
|
||||
: m_result(find(source, chain))
|
||||
{
|
||||
}
|
||||
|
||||
inline bool from_python_base::convertible() const
|
||||
{
|
||||
return m_result != 0;
|
||||
}
|
||||
|
||||
inline void*const& from_python_base::result() const
|
||||
{
|
||||
return m_result;
|
||||
}
|
||||
|
||||
// --------
|
||||
|
||||
namespace detail
|
||||
{
|
||||
template <class T>
|
||||
struct null_ptr_owner
|
||||
{
|
||||
static T value;
|
||||
};
|
||||
template <class T> T null_ptr_owner<T>::value = 0;
|
||||
|
||||
template <class U>
|
||||
inline U& null_ptr_reference(U&(*)())
|
||||
{
|
||||
return null_ptr_owner<U>::value;
|
||||
}
|
||||
}
|
||||
|
||||
template <class T>
|
||||
inline pointer_const_reference_from_python<T>::pointer_const_reference_from_python(PyObject* p)
|
||||
{
|
||||
python::detail::write_void_ptr_reference(
|
||||
m_result.bytes
|
||||
, p == Py_None ? p : find(p, lvalue_from_python_chain<T>::value)
|
||||
, (T(*)())0);
|
||||
}
|
||||
|
||||
template <class T>
|
||||
inline bool pointer_const_reference_from_python<T>::convertible() const
|
||||
{
|
||||
return python::detail::void_ptr_to_reference(m_result.bytes, (T(*)())0) != 0;
|
||||
}
|
||||
template <class T>
|
||||
inline T pointer_const_reference_from_python<T>::operator()(PyObject* p) const
|
||||
{
|
||||
return (p == Py_None)
|
||||
? detail::null_ptr_reference((T(*)())0)
|
||||
: python::detail::void_ptr_to_reference(m_result.bytes, (T(*)())0);
|
||||
}
|
||||
|
||||
// --------
|
||||
|
||||
template <class T>
|
||||
inline pointer_from_python<T>::pointer_from_python(PyObject* p)
|
||||
: from_python_base(p == Py_None ? p : find(p, lvalue_from_python_chain<T>::value))
|
||||
{
|
||||
}
|
||||
|
||||
template <class T>
|
||||
inline T pointer_from_python<T>::operator()(PyObject* p) const
|
||||
{
|
||||
return (p == Py_None) ? 0 : T(result());
|
||||
}
|
||||
|
||||
// --------
|
||||
|
||||
template <class T>
|
||||
inline reference_from_python<T>::reference_from_python(PyObject* p)
|
||||
: from_python_base(find(p,lvalue_from_python_chain<T>::value))
|
||||
{
|
||||
}
|
||||
|
||||
template <class T>
|
||||
inline T reference_from_python<T>::operator()(PyObject*) const
|
||||
{
|
||||
return python::detail::void_ptr_to_reference(result(), (T(*)())0);
|
||||
}
|
||||
|
||||
// -------
|
||||
|
||||
template <class T>
|
||||
inline rvalue_from_python<T>::rvalue_from_python(PyObject* obj)
|
||||
: m_data(find(obj, rvalue_from_python_chain<T>::value))
|
||||
{
|
||||
}
|
||||
|
||||
template <class T>
|
||||
inline bool rvalue_from_python<T>::convertible() const
|
||||
{
|
||||
return m_data.stage1.convertible != 0;
|
||||
}
|
||||
|
||||
template <class T>
|
||||
inline typename rvalue_from_python<T>::result_type
|
||||
rvalue_from_python<T>::operator()(PyObject* p)
|
||||
{
|
||||
if (m_data.stage1.construct != 0)
|
||||
m_data.stage1.construct(p, &m_data.stage1);
|
||||
|
||||
return python::detail::void_ptr_to_reference(m_data.stage1.convertible, (result_type(*)())0);
|
||||
}
|
||||
|
||||
}}} // namespace boost::python::converter
|
||||
|
||||
#endif // FROM_PYTHON_DWA2002127_HPP
|
||||
207
include/boost/python/converter/from_python_data.hpp
Normal file
207
include/boost/python/converter/from_python_data.hpp
Normal file
@@ -0,0 +1,207 @@
|
||||
// Copyright David Abrahams 2002. Permission to copy, use,
|
||||
// modify, sell and distribute this software is granted provided this
|
||||
// copyright notice appears in all copies. This software is provided
|
||||
// "as is" without express or implied warranty, and with no claim as
|
||||
// to its suitability for any purpose.
|
||||
#ifndef FROM_PYTHON_AUX_DATA_DWA2002128_HPP
|
||||
# define FROM_PYTHON_AUX_DATA_DWA2002128_HPP
|
||||
|
||||
# include <boost/python/detail/char_array.hpp>
|
||||
# include <boost/mpl/select_type.hpp>
|
||||
# include <boost/type_traits/same_traits.hpp>
|
||||
# include <boost/type_traits/alignment_traits.hpp>
|
||||
# include <boost/type_traits/transform_traits.hpp>
|
||||
# include <boost/static_assert.hpp>
|
||||
# include <boost/python/converter/from_python_stage1_data.hpp>
|
||||
# include <boost/type_traits/composite_traits.hpp>
|
||||
# include <boost/type_traits/cv_traits.hpp>
|
||||
# include <boost/python/detail/destroy.hpp>
|
||||
# include <boost/preprocessor/list/for_each_i.hpp>
|
||||
# include <boost/preprocessor/tuple/to_list.hpp>
|
||||
# include <boost/preprocessor/cat.hpp>
|
||||
|
||||
namespace boost { namespace python { namespace converter {
|
||||
|
||||
namespace detail
|
||||
{
|
||||
template <class T> struct referent_alignment;
|
||||
template <class T> struct referent_size;
|
||||
|
||||
# ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
|
||||
|
||||
template <class T>
|
||||
struct referent_alignment<T&>
|
||||
{
|
||||
BOOST_STATIC_CONSTANT(
|
||||
std::size_t, value = alignment_of<T>::value);
|
||||
};
|
||||
|
||||
template <class T>
|
||||
struct referent_size<T&>
|
||||
{
|
||||
BOOST_STATIC_CONSTANT(
|
||||
std::size_t, value = sizeof(T));
|
||||
};
|
||||
|
||||
# else
|
||||
|
||||
template <class U>
|
||||
struct alignment_chars
|
||||
{
|
||||
BOOST_STATIC_CONSTANT(
|
||||
std::size_T, n = alignment_of<U>::value);
|
||||
char elements[n + 1];
|
||||
};
|
||||
|
||||
template <class T> struct referent_alignment
|
||||
{
|
||||
template <class U>
|
||||
static alignment_chars<U> helper(U&);
|
||||
|
||||
static T t;
|
||||
|
||||
BOOST_STATIC_CONSTANT(
|
||||
std::size_t, value = sizeof(helper(t).elements) - 1);
|
||||
};
|
||||
|
||||
|
||||
template <class T> struct referent_size
|
||||
{
|
||||
static T f();
|
||||
BOOST_STATIC_CONSTANT(std::size_t, value = sizeof(f()));
|
||||
};
|
||||
|
||||
# endif
|
||||
struct alignment_dummy;
|
||||
typedef void (*function_ptr)();
|
||||
typedef int (alignment_dummy::*member_ptr);
|
||||
typedef int (alignment_dummy::*member_function_ptr)();
|
||||
|
||||
# define BOOST_PYTHON_ALIGNMENT_TYPES BOOST_PP_TUPLE_TO_LIST( \
|
||||
11, ( \
|
||||
char, short, int, long, float, double, long double \
|
||||
, void*, function_ptr, member_ptr, member_function_ptr))
|
||||
|
||||
# define BOOST_PYTHON_CHOOSE_LOWER_ALIGNMENT(R,P,I,T) \
|
||||
typename mpl::select_type< \
|
||||
alignment_of<T>::value <= target, T, char>::type BOOST_PP_CAT(t,I);
|
||||
|
||||
# define BOOST_PYTHON_CHOOSE_LOWER_SIZE(R,P,I,T) \
|
||||
typename mpl::select_type< \
|
||||
sizeof(T) <= target, T, char>::type BOOST_PP_CAT(t,I);
|
||||
|
||||
# define BOOST_PYTHON_CHOOSE_T(R,P,I,T) T BOOST_PP_CAT(t,I);
|
||||
|
||||
template <std::size_t target>
|
||||
union lower_alignment
|
||||
{
|
||||
BOOST_PP_LIST_FOR_EACH_I(
|
||||
BOOST_PYTHON_CHOOSE_LOWER_ALIGNMENT
|
||||
, ignored, BOOST_PYTHON_ALIGNMENT_TYPES)
|
||||
};
|
||||
|
||||
template <std::size_t target>
|
||||
union lower_size
|
||||
{
|
||||
BOOST_PP_LIST_FOR_EACH_I(
|
||||
BOOST_PYTHON_CHOOSE_LOWER_SIZE
|
||||
, ignored, BOOST_PYTHON_ALIGNMENT_TYPES)
|
||||
};
|
||||
|
||||
union max_align
|
||||
{
|
||||
BOOST_PP_LIST_FOR_EACH_I(
|
||||
BOOST_PYTHON_CHOOSE_T
|
||||
, ignored, BOOST_PYTHON_ALIGNMENT_TYPES)
|
||||
};
|
||||
|
||||
template <class Align, std::size_t size>
|
||||
union aligned_storage
|
||||
{
|
||||
Align align;
|
||||
char bytes[size];
|
||||
};
|
||||
|
||||
template <class Reference>
|
||||
struct referent_storage
|
||||
{
|
||||
typedef typename remove_cv<typename remove_reference<Reference>::type>::type referent;
|
||||
|
||||
BOOST_STATIC_CONSTANT(std::size_t, target = referent_alignment<Reference>::value);
|
||||
typedef lower_alignment<target> t1;
|
||||
|
||||
BOOST_STATIC_CONSTANT(bool, t1_aligned =
|
||||
(alignment_of<t1>::value >= target)
|
||||
& (alignment_of<t1>::value % target == 0));
|
||||
|
||||
typedef lower_size<referent_size<Reference>::value> t2;
|
||||
|
||||
BOOST_STATIC_CONSTANT(bool, t2_aligned =
|
||||
(alignment_of<t2>::value >= target)
|
||||
& (alignment_of<t2>::value % target == 0));
|
||||
|
||||
|
||||
typedef typename mpl::select_type<
|
||||
t1_aligned
|
||||
, t1
|
||||
, typename mpl::select_type<
|
||||
t2_aligned
|
||||
, t2
|
||||
, max_align
|
||||
>::type
|
||||
>::type align_t;
|
||||
|
||||
BOOST_STATIC_CONSTANT(std::size_t, found = alignment_of<align_t>::value);
|
||||
|
||||
BOOST_STATIC_ASSERT(found >= target);
|
||||
BOOST_STATIC_ASSERT(found % target == 0);
|
||||
|
||||
typedef aligned_storage<align_t,referent_size<Reference>::value> type;
|
||||
};
|
||||
}
|
||||
|
||||
template <class T>
|
||||
struct rvalue_base_data
|
||||
{
|
||||
rvalue_stage1_data stage1;
|
||||
|
||||
typename detail::referent_storage<
|
||||
typename add_reference<T>::type
|
||||
>::type storage;
|
||||
};
|
||||
|
||||
template <class T>
|
||||
struct rvalue_data : rvalue_base_data<T>
|
||||
{
|
||||
rvalue_data(rvalue_stage1_data const&);
|
||||
rvalue_data(void*);
|
||||
~rvalue_data();
|
||||
private:
|
||||
typedef typename add_reference<typename add_cv<T>::type>::type ref_type;
|
||||
};
|
||||
|
||||
//
|
||||
// Implementataions
|
||||
//
|
||||
template <class T>
|
||||
inline rvalue_data<T>::rvalue_data(rvalue_stage1_data const& stage1)
|
||||
{
|
||||
this->stage1 = stage1;
|
||||
}
|
||||
|
||||
template <class T>
|
||||
inline rvalue_data<T>::rvalue_data(void* convertible)
|
||||
{
|
||||
this->stage1.convertible = convertible;
|
||||
}
|
||||
|
||||
template <class T>
|
||||
inline rvalue_data<T>::~rvalue_data()
|
||||
{
|
||||
if (this->stage1.convertible == this->storage.bytes)
|
||||
python::detail::destroy_reference<ref_type>(this->storage.bytes);
|
||||
}
|
||||
|
||||
}}} // namespace boost::python::converter
|
||||
|
||||
#endif // FROM_PYTHON_AUX_DATA_DWA2002128_HPP
|
||||
18
include/boost/python/converter/from_python_function.hpp
Normal file
18
include/boost/python/converter/from_python_function.hpp
Normal file
@@ -0,0 +1,18 @@
|
||||
// Copyright David Abrahams 2002. Permission to copy, use,
|
||||
// modify, sell and distribute this software is granted provided this
|
||||
// copyright notice appears in all copies. This software is provided
|
||||
// "as is" without express or implied warranty, and with no claim as
|
||||
// to its suitability for any purpose.
|
||||
#ifndef FROM_PYTHON_FUNCTION_DWA2002128_HPP
|
||||
# define FROM_PYTHON_FUNCTION_DWA2002128_HPP
|
||||
|
||||
# include <boost/python/detail/wrap_python.hpp>
|
||||
|
||||
namespace boost { namespace python { namespace converter {
|
||||
|
||||
struct rvalue_stage1_data;
|
||||
typedef void (*constructor_function)(PyObject* source, rvalue_stage1_data*);
|
||||
|
||||
}}} // namespace boost::python::converter
|
||||
|
||||
#endif // FROM_PYTHON_FUNCTION_DWA2002128_HPP
|
||||
21
include/boost/python/converter/from_python_stage1_data.hpp
Normal file
21
include/boost/python/converter/from_python_stage1_data.hpp
Normal file
@@ -0,0 +1,21 @@
|
||||
// Copyright David Abrahams 2002. Permission to copy, use,
|
||||
// modify, sell and distribute this software is granted provided this
|
||||
// copyright notice appears in all copies. This software is provided
|
||||
// "as is" without express or implied warranty, and with no claim as
|
||||
// to its suitability for any purpose.
|
||||
#ifndef FROM_PYTHON_STAGE1_DATA_DWA2002223_HPP
|
||||
# define FROM_PYTHON_STAGE1_DATA_DWA2002223_HPP
|
||||
|
||||
# include <boost/python/converter/from_python_function.hpp>
|
||||
|
||||
namespace boost { namespace python { namespace converter {
|
||||
|
||||
struct rvalue_stage1_data
|
||||
{
|
||||
void* convertible;
|
||||
constructor_function construct;
|
||||
};
|
||||
|
||||
}}} // namespace boost::python::converter
|
||||
|
||||
#endif // FROM_PYTHON_STAGE1_DATA_DWA2002223_HPP
|
||||
70
include/boost/python/converter/lvalue_from_python_chain.hpp
Normal file
70
include/boost/python/converter/lvalue_from_python_chain.hpp
Normal file
@@ -0,0 +1,70 @@
|
||||
// Copyright David Abrahams 2002. Permission to copy, use,
|
||||
// modify, sell and distribute this software is granted provided this
|
||||
// copyright notice appears in all copies. This software is provided
|
||||
// "as is" without express or implied warranty, and with no claim as
|
||||
// to its suitability for any purpose.
|
||||
#ifndef LVALUE_FROM_PYTHON_CHAIN_DWA200237_HPP
|
||||
# define LVALUE_FROM_PYTHON_CHAIN_DWA200237_HPP
|
||||
|
||||
# include <boost/python/converter/pointer_type_id.hpp>
|
||||
# include <boost/python/converter/registry.hpp>
|
||||
# include <boost/type_traits/cv_traits.hpp>
|
||||
|
||||
namespace boost { namespace python { namespace converter {
|
||||
|
||||
// Given T == U*cv&, T == U*, or T == U&, lvalue_from_python_chain<T>
|
||||
// declares a "templated global reference" to the lvalue from_python
|
||||
// converter chain for U. The optional bool second argument callback,
|
||||
// when true, removes special treatment for T == U*cv& so that the
|
||||
// converter for U* is found.
|
||||
namespace detail
|
||||
{
|
||||
template <class T>
|
||||
struct ptr_or_ptr_ref_lvalue_from_python_chain
|
||||
{
|
||||
static lvalue_from_python_registration*const& value;
|
||||
};
|
||||
|
||||
template <class T>
|
||||
lvalue_from_python_registration*const&
|
||||
ptr_or_ptr_ref_lvalue_from_python_chain<T>::value
|
||||
= registry::lvalue_converters(pointer_type_id<T>());
|
||||
|
||||
template <class T>
|
||||
struct ref_lvalue_from_python_chain
|
||||
{
|
||||
static lvalue_from_python_registration*const& value;
|
||||
};
|
||||
|
||||
template <class T>
|
||||
lvalue_from_python_registration*const&
|
||||
ref_lvalue_from_python_chain<T>::value
|
||||
= registry::lvalue_converters(undecorated_type_id<T>());
|
||||
|
||||
template <class T, bool callback>
|
||||
struct select_lvalue_from_python_chain
|
||||
{
|
||||
BOOST_STATIC_CONSTANT(
|
||||
bool, ptr
|
||||
= !callback && boost::python::detail::is_reference_to_pointer<T>::value
|
||||
|| is_pointer<T>::value);
|
||||
|
||||
typedef typename add_reference<typename add_cv<T>::type>::type normalized;
|
||||
|
||||
typedef typename mpl::select_type<
|
||||
ptr
|
||||
, ptr_or_ptr_ref_lvalue_from_python_chain<normalized>
|
||||
, ref_lvalue_from_python_chain<normalized>
|
||||
>::type type;
|
||||
};
|
||||
}
|
||||
|
||||
template <class T, bool callback = false>
|
||||
struct lvalue_from_python_chain
|
||||
: detail::select_lvalue_from_python_chain<T,callback>::type
|
||||
{
|
||||
};
|
||||
|
||||
}}} // namespace boost::python::converter
|
||||
|
||||
#endif // LVALUE_FROM_PYTHON_CHAIN_DWA200237_HPP
|
||||
@@ -0,0 +1,51 @@
|
||||
// Copyright David Abrahams 2002. Permission to copy, use,
|
||||
// modify, sell and distribute this software is granted provided this
|
||||
// copyright notice appears in all copies. This software is provided
|
||||
// "as is" without express or implied warranty, and with no claim as
|
||||
// to its suitability for any purpose.
|
||||
#ifndef POINTEE_TO_PYTHON_FUNCTION_DWA2002128_HPP
|
||||
# define POINTEE_TO_PYTHON_FUNCTION_DWA2002128_HPP
|
||||
|
||||
# include <boost/python/detail/wrap_python.hpp>
|
||||
# include <boost/type_traits/transform_traits.hpp>
|
||||
# include <boost/type_traits/cv_traits.hpp>
|
||||
# include <boost/python/converter/type_id.hpp>
|
||||
# include <boost/python/converter/registry.hpp>
|
||||
# include <boost/python/converter/to_python_function_type.hpp>
|
||||
# include <boost/python/converter/pointer_type_id.hpp>
|
||||
|
||||
namespace boost { namespace python { namespace converter {
|
||||
|
||||
// pointee_to_python_function --
|
||||
//
|
||||
// essentially a "templated global reference" which holds the
|
||||
// converter for converting a type to Python by-value. We "normalize"
|
||||
// T by adding "const volatile&" so that fewer global variables and
|
||||
// associated static initializations are generated.
|
||||
namespace detail
|
||||
{
|
||||
template <class T>
|
||||
struct pointee_to_python_function_base
|
||||
{
|
||||
static to_python_function_t const& value;
|
||||
};
|
||||
|
||||
template <class T>
|
||||
to_python_function_t const&
|
||||
pointee_to_python_function_base<T>::value
|
||||
= converter::registry::get_to_python_function(pointer_type_id<T>());
|
||||
}
|
||||
|
||||
template <class T>
|
||||
struct pointee_to_python_function
|
||||
: detail::pointee_to_python_function_base<
|
||||
typename add_reference<
|
||||
typename add_cv<T>::type
|
||||
>::type
|
||||
>
|
||||
{
|
||||
};
|
||||
|
||||
}}} // namespace boost::python::converter
|
||||
|
||||
#endif // POINTEE_TO_PYTHON_FUNCTION_DWA2002128_HPP
|
||||
69
include/boost/python/converter/pointer_type_id.hpp
Normal file
69
include/boost/python/converter/pointer_type_id.hpp
Normal file
@@ -0,0 +1,69 @@
|
||||
// Copyright David Abrahams 2002. Permission to copy, use,
|
||||
// modify, sell and distribute this software is granted provided this
|
||||
// copyright notice appears in all copies. This software is provided
|
||||
// "as is" without express or implied warranty, and with no claim as
|
||||
// to its suitability for any purpose.
|
||||
#ifndef POINTER_TYPE_ID_DWA2002222_HPP
|
||||
# define POINTER_TYPE_ID_DWA2002222_HPP
|
||||
|
||||
# include <boost/python/converter/type_id.hpp>
|
||||
# include <boost/type_traits/composite_traits.hpp>
|
||||
|
||||
namespace boost { namespace python { namespace converter {
|
||||
|
||||
namespace detail
|
||||
{
|
||||
template <bool is_ref = false>
|
||||
struct pointer_typeid_select
|
||||
{
|
||||
template <class T>
|
||||
static inline undecorated_type_id_t execute(T*(*)() = 0)
|
||||
{
|
||||
return undecorated_type_id<T>();
|
||||
}
|
||||
};
|
||||
|
||||
template <>
|
||||
struct pointer_typeid_select<true>
|
||||
{
|
||||
template <class T>
|
||||
static inline undecorated_type_id_t execute(T* const volatile&(*)() = 0)
|
||||
{
|
||||
return undecorated_type_id<T>();
|
||||
}
|
||||
|
||||
template <class T>
|
||||
static inline undecorated_type_id_t execute(T*volatile&(*)() = 0)
|
||||
{
|
||||
return undecorated_type_id<T>();
|
||||
}
|
||||
|
||||
template <class T>
|
||||
static inline undecorated_type_id_t execute(T*const&(*)() = 0)
|
||||
{
|
||||
return undecorated_type_id<T>();
|
||||
}
|
||||
|
||||
template <class T>
|
||||
static inline undecorated_type_id_t execute(T*&(*)() = 0)
|
||||
{
|
||||
return undecorated_type_id<T>();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
// Usage: pointer_type_id<T>()
|
||||
//
|
||||
// Returns an undecorated_type_id_t associated with the type pointed
|
||||
// to by T, which may be a pointer or a reference to a pointer.
|
||||
template <class T>
|
||||
undecorated_type_id_t pointer_type_id(T(*)() = 0)
|
||||
{
|
||||
return detail::pointer_typeid_select<
|
||||
is_reference<T>::value
|
||||
>::execute((T(*)())0);
|
||||
}
|
||||
|
||||
}}} // namespace boost::python::converter
|
||||
|
||||
#endif // POINTER_TYPE_ID_DWA2002222_HPP
|
||||
28
include/boost/python/converter/registrations.hpp
Normal file
28
include/boost/python/converter/registrations.hpp
Normal file
@@ -0,0 +1,28 @@
|
||||
// Copyright David Abrahams 2002. Permission to copy, use,
|
||||
// modify, sell and distribute this software is granted provided this
|
||||
// copyright notice appears in all copies. This software is provided
|
||||
// "as is" without express or implied warranty, and with no claim as
|
||||
// to its suitability for any purpose.
|
||||
#ifndef REGISTRATIONS_DWA2002223_HPP
|
||||
# define REGISTRATIONS_DWA2002223_HPP
|
||||
|
||||
# include <boost/python/converter/from_python_function.hpp>
|
||||
|
||||
namespace boost { namespace python { namespace converter {
|
||||
|
||||
struct lvalue_from_python_registration
|
||||
{
|
||||
void* (*convert)(PyObject* source);
|
||||
lvalue_from_python_registration* next;
|
||||
};
|
||||
|
||||
struct rvalue_from_python_registration
|
||||
{
|
||||
void* (*convertible)(PyObject*);
|
||||
constructor_function construct;
|
||||
rvalue_from_python_registration* next;
|
||||
};
|
||||
|
||||
}}} // namespace boost::python::converter
|
||||
|
||||
#endif // REGISTRATIONS_DWA2002223_HPP
|
||||
45
include/boost/python/converter/registry.hpp
Normal file
45
include/boost/python/converter/registry.hpp
Normal file
@@ -0,0 +1,45 @@
|
||||
// Copyright David Abrahams 2001. Permission to copy, use,
|
||||
// modify, sell and distribute this software is granted provided this
|
||||
// copyright notice appears in all copies. This software is provided
|
||||
// "as is" without express or implied warranty, and with no claim as
|
||||
// to its suitability for any purpose.
|
||||
#ifndef REGISTRY_DWA20011127_HPP
|
||||
# define REGISTRY_DWA20011127_HPP
|
||||
# include <boost/python/converter/type_id.hpp>
|
||||
# include <boost/python/detail/config.hpp>
|
||||
# include <boost/python/detail/wrap_python.hpp>
|
||||
# include <boost/python/converter/to_python_function_type.hpp>
|
||||
# include <boost/python/converter/from_python_function.hpp>
|
||||
|
||||
namespace boost { namespace python { namespace converter {
|
||||
|
||||
struct lvalue_from_python_registration;
|
||||
struct rvalue_from_python_registration;
|
||||
|
||||
// This namespace acts as a sort of singleton
|
||||
namespace registry
|
||||
{
|
||||
BOOST_PYTHON_DECL lvalue_from_python_registration*& lvalue_converters(undecorated_type_id_t);
|
||||
BOOST_PYTHON_DECL rvalue_from_python_registration*& rvalue_converters(undecorated_type_id_t);
|
||||
|
||||
BOOST_PYTHON_DECL to_python_function_t const&
|
||||
get_to_python_function(undecorated_type_id_t);
|
||||
|
||||
BOOST_PYTHON_DECL void insert(to_python_function_t, undecorated_type_id_t);
|
||||
|
||||
// Insert an lvalue from_python converter
|
||||
BOOST_PYTHON_DECL void insert(void* (*convert)(PyObject*), undecorated_type_id_t);
|
||||
|
||||
// Insert an rvalue from_python converter
|
||||
BOOST_PYTHON_DECL void insert(
|
||||
void* (*convertible)(PyObject*)
|
||||
, constructor_function
|
||||
, undecorated_type_id_t
|
||||
);
|
||||
|
||||
BOOST_PYTHON_DECL PyTypeObject*& class_object(undecorated_type_id_t key);
|
||||
}
|
||||
|
||||
}}} // namespace boost::python::converter
|
||||
|
||||
#endif // REGISTRY_DWA20011127_HPP
|
||||
39
include/boost/python/converter/rvalue_from_python_chain.hpp
Normal file
39
include/boost/python/converter/rvalue_from_python_chain.hpp
Normal file
@@ -0,0 +1,39 @@
|
||||
// Copyright David Abrahams 2002. Permission to copy, use,
|
||||
// modify, sell and distribute this software is granted provided this
|
||||
// copyright notice appears in all copies. This software is provided
|
||||
// "as is" without express or implied warranty, and with no claim as
|
||||
// to its suitability for any purpose.
|
||||
#ifndef RVALUE_FROM_PYTHON_CHAIN_DWA200237_HPP
|
||||
# define RVALUE_FROM_PYTHON_CHAIN_DWA200237_HPP
|
||||
# include <boost/python/converter/registry.hpp>
|
||||
# include <boost/type_traits/transform_traits.hpp>
|
||||
# include <boost/type_traits/cv_traits.hpp>
|
||||
|
||||
namespace boost { namespace python { namespace converter {
|
||||
|
||||
namespace detail
|
||||
{
|
||||
template <class T>
|
||||
struct rvalue_from_python_chain_impl
|
||||
{
|
||||
static rvalue_from_python_registration*const& value;
|
||||
};
|
||||
|
||||
template <class T>
|
||||
rvalue_from_python_registration*const& rvalue_from_python_chain_impl<T>::value
|
||||
= registry::rvalue_converters(undecorated_type_id<T>());
|
||||
}
|
||||
|
||||
template <class T>
|
||||
struct rvalue_from_python_chain
|
||||
: detail::rvalue_from_python_chain_impl<
|
||||
typename add_reference<
|
||||
typename add_cv<T>::type
|
||||
>::type
|
||||
>
|
||||
{
|
||||
};
|
||||
|
||||
}}} // namespace boost::python::converter
|
||||
|
||||
#endif // RVALUE_FROM_PYTHON_CHAIN_DWA200237_HPP
|
||||
70
include/boost/python/converter/smart_ptr.hpp
Normal file
70
include/boost/python/converter/smart_ptr.hpp
Normal file
@@ -0,0 +1,70 @@
|
||||
// Copyright David Abrahams 2002. Permission to copy, use,
|
||||
// modify, sell and distribute this software is granted provided this
|
||||
// copyright notice appears in all copies. This software is provided
|
||||
// "as is" without express or implied warranty, and with no claim as
|
||||
// to its suitability for any purpose.
|
||||
#ifndef SMART_PTR_DWA2002123_HPP
|
||||
# define SMART_PTR_DWA2002123_HPP
|
||||
|
||||
# include <boost/python/converter/class.hpp>
|
||||
# include <boost/python/object/pointer_holder.hpp>
|
||||
namespace boost { namespace python { namespace converter {
|
||||
|
||||
template <class Pointer, class Value>
|
||||
class smart_ptr_wrapper
|
||||
: wrapper<Pointer const&>
|
||||
{
|
||||
smart_ptr_wrapper(ref const& type_)
|
||||
: m_class_object(type_)
|
||||
{
|
||||
assert(type_->ob_type == (PyTypeObject*)class_metatype().get());
|
||||
}
|
||||
|
||||
PyObject* convert(Pointer x) const;
|
||||
|
||||
private:
|
||||
ref m_class_object;
|
||||
|
||||
smart_ptr_converters();
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// implementations
|
||||
//
|
||||
|
||||
template <class Pointer, class Value>
|
||||
PyObject* smart_ptr_wrapper<Pointer,Value>::convert(Pointer x) const
|
||||
{
|
||||
if (x.operator->() == 0)
|
||||
return detail::none();
|
||||
|
||||
// Don't call the type to do the construction, since that
|
||||
// would require the registration of an __init__ copy
|
||||
// constructor. Instead, just construct the object in place.
|
||||
PyObject* raw_result = (PyObject*)PyObject_New(
|
||||
instance, (PyTypeObject*)m_class_object.get());
|
||||
|
||||
if (raw_result == 0)
|
||||
return 0;
|
||||
|
||||
// Everything's OK; Bypass NULL checks but guard against
|
||||
// exceptions.
|
||||
ref result(raw_result, ref::allow_null());
|
||||
|
||||
// Build a value_holder to contain the object using the copy
|
||||
// constructor
|
||||
objects::pointer_holder<Pointer,Value>*
|
||||
p = new objects::pointer_holder<Pointer,Value>(x);
|
||||
|
||||
// Install it in the instance
|
||||
p->install(raw_result);
|
||||
|
||||
// Return the new result
|
||||
return result.release();
|
||||
}
|
||||
|
||||
|
||||
}}} // namespace boost::python::converter
|
||||
|
||||
#endif // SMART_PTR_DWA2002123_HPP
|
||||
50
include/boost/python/converter/to_python_function.hpp
Normal file
50
include/boost/python/converter/to_python_function.hpp
Normal file
@@ -0,0 +1,50 @@
|
||||
// Copyright David Abrahams 2002. Permission to copy, use,
|
||||
// modify, sell and distribute this software is granted provided this
|
||||
// copyright notice appears in all copies. This software is provided
|
||||
// "as is" without express or implied warranty, and with no claim as
|
||||
// to its suitability for any purpose.
|
||||
#ifndef TO_PYTHON_FUNCTION_DWA2002128_HPP
|
||||
# define TO_PYTHON_FUNCTION_DWA2002128_HPP
|
||||
|
||||
# include <boost/python/detail/wrap_python.hpp>
|
||||
# include <boost/type_traits/transform_traits.hpp>
|
||||
# include <boost/type_traits/cv_traits.hpp>
|
||||
# include <boost/python/converter/type_id.hpp>
|
||||
# include <boost/python/converter/registry.hpp>
|
||||
# include <boost/python/converter/to_python_function_type.hpp>
|
||||
|
||||
namespace boost { namespace python { namespace converter {
|
||||
|
||||
// to_python_function --
|
||||
//
|
||||
// essentially a "templated global reference" which holds the
|
||||
// converter for converting a type to Python by-value. We "normalize"
|
||||
// T by adding "const volatile&" so that fewer global variables and
|
||||
// associated static initializations are generated.
|
||||
namespace detail
|
||||
{
|
||||
template <class T>
|
||||
struct to_python_function_base
|
||||
{
|
||||
static to_python_function_t const& value;
|
||||
};
|
||||
|
||||
template <class T>
|
||||
to_python_function_t const&
|
||||
to_python_function_base<T>::value
|
||||
= converter::registry::get_to_python_function(undecorated_type_id<T>());
|
||||
}
|
||||
|
||||
template <class T>
|
||||
struct to_python_function
|
||||
: detail::to_python_function_base<
|
||||
typename add_reference<
|
||||
typename add_cv<T>::type
|
||||
>::type
|
||||
>
|
||||
{
|
||||
};
|
||||
|
||||
}}} // namespace boost::python::converter
|
||||
|
||||
#endif // TO_PYTHON_FUNCTION_DWA2002128_HPP
|
||||
30
include/boost/python/converter/to_python_function_type.hpp
Normal file
30
include/boost/python/converter/to_python_function_type.hpp
Normal file
@@ -0,0 +1,30 @@
|
||||
// Copyright David Abrahams 2002. Permission to copy, use,
|
||||
// modify, sell and distribute this software is granted provided this
|
||||
// copyright notice appears in all copies. This software is provided
|
||||
// "as is" without express or implied warranty, and with no claim as
|
||||
// to its suitability for any purpose.
|
||||
#ifndef TO_PYTHON_FUNCTION_TYPE_DWA200236_HPP
|
||||
# define TO_PYTHON_FUNCTION_TYPE_DWA200236_HPP
|
||||
# include <boost/python/detail/wrap_python.hpp>
|
||||
|
||||
namespace boost { namespace python { namespace converter {
|
||||
|
||||
// The type of stored function pointers which actually do conversion
|
||||
// by-value. The void* points to the object to be converted, and
|
||||
// type-safety is preserved through runtime registration.
|
||||
typedef PyObject* (*to_python_function_t)(void const*);
|
||||
|
||||
// Given a typesafe to_python conversion function, produces a
|
||||
// to_python_function_t which can be registered in the usual way.
|
||||
template <class T, class ToPython>
|
||||
struct as_to_python_function
|
||||
{
|
||||
static PyObject* convert(void const* x)
|
||||
{
|
||||
return ToPython::convert(*(T const*)x);
|
||||
}
|
||||
};
|
||||
|
||||
}}} // namespace boost::python::converter
|
||||
|
||||
#endif // TO_PYTHON_FUNCTION_TYPE_DWA200236_HPP
|
||||
176
include/boost/python/converter/type_id.hpp
Normal file
176
include/boost/python/converter/type_id.hpp
Normal file
@@ -0,0 +1,176 @@
|
||||
// Copyright David Abrahams 2001. Permission to copy, use,
|
||||
// modify, sell and distribute this software is granted provided this
|
||||
// copyright notice appears in all copies. This software is provided
|
||||
// "as is" without express or implied warranty, and with no claim as
|
||||
// to its suitability for any purpose.
|
||||
#ifndef TYPE_ID_DWA20011127_HPP
|
||||
# define TYPE_ID_DWA20011127_HPP
|
||||
# include <boost/python/detail/config.hpp>
|
||||
# include <boost/python/detail/indirect_traits.hpp>
|
||||
# include <boost/python/detail/msvc_typeinfo.hpp>
|
||||
# include <boost/type_traits/cv_traits.hpp>
|
||||
# include <boost/type_traits/composite_traits.hpp>
|
||||
# include <boost/mpl/select_type.hpp>
|
||||
# include <boost/operators.hpp>
|
||||
# include <boost/type.hpp>
|
||||
# include <typeinfo>
|
||||
# include <iosfwd>
|
||||
# include <cstring>
|
||||
|
||||
|
||||
namespace boost { namespace python { namespace converter {
|
||||
|
||||
// for this compiler at least, cross-shared-library type_info
|
||||
// comparisons don't work, so use typeid(x).name() instead. It's not
|
||||
// yet clear what the best default strategy is.
|
||||
# if defined(__GNUC__) && __GNUC__ >= 3
|
||||
# define BOOST_PYTHON_TYPE_ID_NAME
|
||||
# endif
|
||||
|
||||
// type ids which represent the same information as std::type_info
|
||||
// (i.e. the top-level reference and cv-qualifiers are stripped), but
|
||||
// which works across shared libraries.
|
||||
struct undecorated_type_id_t : totally_ordered<undecorated_type_id_t>
|
||||
{
|
||||
undecorated_type_id_t(std::type_info const&);
|
||||
|
||||
// default constructor needed to build arrays, etc.
|
||||
undecorated_type_id_t();
|
||||
|
||||
bool operator<(undecorated_type_id_t const& rhs) const;
|
||||
bool operator==(undecorated_type_id_t const& rhs) const;
|
||||
|
||||
char const* name() const;
|
||||
friend BOOST_PYTHON_DECL std::ostream& operator<<(
|
||||
std::ostream&, undecorated_type_id_t const&);
|
||||
|
||||
private: // data members
|
||||
# ifdef BOOST_PYTHON_TYPE_ID_NAME
|
||||
typedef char const* base_id_t;
|
||||
# else
|
||||
typedef std::type_info const* base_id_t;
|
||||
# endif
|
||||
|
||||
base_id_t m_base_type;
|
||||
};
|
||||
|
||||
struct type_id_t : totally_ordered<type_id_t>
|
||||
{
|
||||
enum decoration { const_ = 0x1, volatile_ = 0x2, reference = 0x4 };
|
||||
|
||||
type_id_t(undecorated_type_id_t, decoration = decoration());
|
||||
|
||||
bool operator<(type_id_t const& rhs) const;
|
||||
bool operator==(type_id_t const& rhs) const;
|
||||
|
||||
friend BOOST_PYTHON_DECL std::ostream& operator<<(std::ostream&, type_id_t const&);
|
||||
|
||||
operator undecorated_type_id_t const&() const;
|
||||
private: // type
|
||||
typedef undecorated_type_id_t base_id_t;
|
||||
|
||||
private: // data members
|
||||
decoration m_decoration;
|
||||
base_id_t m_base_type;
|
||||
};
|
||||
|
||||
template <class T>
|
||||
inline undecorated_type_id_t undecorated_type_id(boost::type<T>* = 0)
|
||||
{
|
||||
return undecorated_type_id_t(
|
||||
# if (!defined(BOOST_MSVC) || BOOST_MSVC > 1300) && (!defined(BOOST_INTEL_CXX_VERSION) || BOOST_INTEL_CXX_VERSION > 600)
|
||||
typeid(T)
|
||||
# else // strip the decoration which msvc and Intel mistakenly leave in
|
||||
python::detail::msvc_typeid<T>()
|
||||
# endif
|
||||
);
|
||||
}
|
||||
|
||||
template <class T>
|
||||
inline type_id_t type_id(boost::type<T>* = 0)
|
||||
{
|
||||
return type_id_t(
|
||||
undecorated_type_id<T>()
|
||||
, type_id_t::decoration(
|
||||
(is_const<T>::value || python::detail::is_reference_to_const<T>::value
|
||||
? type_id_t::const_ : 0)
|
||||
| (is_volatile<T>::value || python::detail::is_reference_to_volatile<T>::value
|
||||
? type_id_t::volatile_ : 0)
|
||||
| (is_reference<T>::value ? type_id_t::reference : 0)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
inline undecorated_type_id_t::undecorated_type_id_t(std::type_info const& id)
|
||||
: m_base_type(
|
||||
# ifdef BOOST_PYTHON_TYPE_ID_NAME
|
||||
id.name()
|
||||
# else
|
||||
&id
|
||||
# endif
|
||||
)
|
||||
{
|
||||
}
|
||||
|
||||
inline undecorated_type_id_t::undecorated_type_id_t()
|
||||
: m_base_type()
|
||||
{
|
||||
}
|
||||
|
||||
inline type_id_t::type_id_t(undecorated_type_id_t base_t, decoration decoration)
|
||||
: m_decoration(decoration)
|
||||
, m_base_type(base_t)
|
||||
{
|
||||
}
|
||||
|
||||
inline bool undecorated_type_id_t::operator<(undecorated_type_id_t const& rhs) const
|
||||
{
|
||||
# ifdef BOOST_PYTHON_TYPE_ID_NAME
|
||||
return std::strcmp(m_base_type, rhs.m_base_type) < 0;
|
||||
# else
|
||||
return m_base_type->before(*rhs.m_base_type);
|
||||
# endif
|
||||
}
|
||||
|
||||
inline bool type_id_t::operator<(type_id_t const& rhs) const
|
||||
{
|
||||
return m_decoration < rhs.m_decoration
|
||||
|| m_decoration == rhs.m_decoration
|
||||
&& m_base_type < rhs.m_base_type;
|
||||
}
|
||||
|
||||
inline bool undecorated_type_id_t::operator==(undecorated_type_id_t const& rhs) const
|
||||
{
|
||||
# ifdef BOOST_PYTHON_TYPE_ID_NAME
|
||||
return !std::strcmp(m_base_type, rhs.m_base_type);
|
||||
# else
|
||||
return *m_base_type == *rhs.m_base_type;
|
||||
# endif
|
||||
}
|
||||
|
||||
inline bool type_id_t::operator==(type_id_t const& rhs) const
|
||||
{
|
||||
return m_decoration == rhs.m_decoration && m_base_type == rhs.m_base_type;
|
||||
}
|
||||
|
||||
inline type_id_t::operator undecorated_type_id_t const&() const
|
||||
{
|
||||
return m_base_type;
|
||||
}
|
||||
|
||||
inline char const* undecorated_type_id_t::name() const
|
||||
{
|
||||
# ifdef BOOST_PYTHON_TYPE_ID_NAME
|
||||
return m_base_type;
|
||||
# else
|
||||
return m_base_type->name();
|
||||
# endif
|
||||
}
|
||||
|
||||
|
||||
BOOST_PYTHON_DECL std::ostream& operator<<(std::ostream&, undecorated_type_id_t const&);
|
||||
BOOST_PYTHON_DECL std::ostream& operator<<(std::ostream&, type_id_t const&);
|
||||
|
||||
}}} // namespace boost::python::converter
|
||||
|
||||
#endif // TYPE_ID_DWA20011127_HPP
|
||||
42
include/boost/python/copy_const_reference.hpp
Normal file
42
include/boost/python/copy_const_reference.hpp
Normal file
@@ -0,0 +1,42 @@
|
||||
// Copyright David Abrahams 2002. Permission to copy, use,
|
||||
// modify, sell and distribute this software is granted provided this
|
||||
// copyright notice appears in all copies. This software is provided
|
||||
// "as is" without express or implied warranty, and with no claim as
|
||||
// to its suitability for any purpose.
|
||||
#ifndef COPY_CONST_REFERENCE_DWA2002131_HPP
|
||||
# define COPY_CONST_REFERENCE_DWA2002131_HPP
|
||||
# include <boost/python/detail/indirect_traits.hpp>
|
||||
# include <boost/mpl/select_type.hpp>
|
||||
# include <boost/python/to_python_value.hpp>
|
||||
|
||||
namespace boost { namespace python {
|
||||
|
||||
namespace detail
|
||||
{
|
||||
template <class R>
|
||||
struct copy_const_reference_expects_a_const_reference_return_type
|
||||
# if defined(__GNUC__) && __GNUC__ >= 3 || defined(__EDG__)
|
||||
{}
|
||||
# endif
|
||||
;
|
||||
}
|
||||
|
||||
template <class T> struct to_python_value;
|
||||
|
||||
struct copy_const_reference
|
||||
{
|
||||
template <class T>
|
||||
struct apply
|
||||
{
|
||||
typedef typename mpl::select_type<
|
||||
detail::is_reference_to_const<T>::value
|
||||
, to_python_value<T>
|
||||
, detail::copy_const_reference_expects_a_const_reference_return_type<T>
|
||||
>::type type;
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
}} // namespace boost::python
|
||||
|
||||
#endif // COPY_CONST_REFERENCE_DWA2002131_HPP
|
||||
42
include/boost/python/copy_non_const_reference.hpp
Normal file
42
include/boost/python/copy_non_const_reference.hpp
Normal file
@@ -0,0 +1,42 @@
|
||||
// Copyright David Abrahams 2002. Permission to copy, use,
|
||||
// modify, sell and distribute this software is granted provided this
|
||||
// copyright notice appears in all copies. This software is provided
|
||||
// "as is" without express or implied warranty, and with no claim as
|
||||
// to its suitability for any purpose.
|
||||
#ifndef COPY_NON_CONST_REFERENCE_DWA2002131_HPP
|
||||
# define COPY_NON_CONST_REFERENCE_DWA2002131_HPP
|
||||
# include <boost/python/detail/indirect_traits.hpp>
|
||||
# include <boost/mpl/select_type.hpp>
|
||||
# include <boost/python/to_python_value.hpp>
|
||||
|
||||
namespace boost { namespace python {
|
||||
|
||||
namespace detail
|
||||
{
|
||||
template <class R>
|
||||
struct copy_non_const_reference_expects_a_non_const_reference_return_type
|
||||
# if defined(__GNUC__) && __GNUC__ >= 3 || defined(__EDG__)
|
||||
{}
|
||||
# endif
|
||||
;
|
||||
}
|
||||
|
||||
template <class T> struct to_python_value;
|
||||
|
||||
struct copy_non_const_reference
|
||||
{
|
||||
template <class T>
|
||||
struct apply
|
||||
{
|
||||
typedef typename mpl::select_type<
|
||||
boost::python::detail::is_reference_to_non_const<T>::value
|
||||
, to_python_value<T>
|
||||
, detail::copy_non_const_reference_expects_a_non_const_reference_return_type<T>
|
||||
>::type type;
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
}} // namespace boost::python
|
||||
|
||||
#endif // COPY_NON_CONST_REFERENCE_DWA2002131_HPP
|
||||
@@ -18,26 +18,28 @@
|
||||
# include <boost/python/class_builder.hpp>
|
||||
|
||||
namespace boost { namespace python {
|
||||
struct import_error : error_already_set {};
|
||||
struct export_error : error_already_set {};
|
||||
}}
|
||||
struct BOOST_PYTHON_DECL import_error: error_already_set {};
|
||||
struct BOOST_PYTHON_DECL export_error : error_already_set {};
|
||||
|
||||
namespace boost { namespace python { namespace detail {
|
||||
namespace detail
|
||||
{
|
||||
|
||||
// Concept: throw exception if api_major is changed
|
||||
// show warning on stderr if api_minor is changed
|
||||
const int export_converters_api_major = 4;
|
||||
const int export_converters_api_minor = 1;
|
||||
extern const char* converters_attribute_name;
|
||||
void* import_converter_object(const std::string& module_name,
|
||||
const std::string& py_class_name,
|
||||
const std::string& attribute_name);
|
||||
void check_export_converters_api(const int importing_major,
|
||||
const int importing_minor,
|
||||
const int imported_major,
|
||||
const int imported_minor);
|
||||
const int export_converters_api_major = 4;
|
||||
const int export_converters_api_minor = 1;
|
||||
extern BOOST_PYTHON_DECL const char* converters_attribute_name;
|
||||
BOOST_PYTHON_DECL void* import_converter_object(const std::string& module_name,
|
||||
const std::string& py_class_name,
|
||||
const std::string& attribute_name);
|
||||
BOOST_PYTHON_DECL void check_export_converters_api(const int importing_major,
|
||||
const int importing_minor,
|
||||
const int imported_major,
|
||||
const int imported_minor);
|
||||
|
||||
}}}
|
||||
}
|
||||
|
||||
}} // namespace boost::python
|
||||
|
||||
// forward declaration
|
||||
namespace boost { namespace python { namespace detail {
|
||||
@@ -232,56 +234,56 @@ struct export_converter_object : export_converter_object_noncopyable<T>
|
||||
}
|
||||
};
|
||||
|
||||
namespace detail {
|
||||
namespace detail
|
||||
{
|
||||
|
||||
/* This class template is instantiated by import_converters<T>.
|
||||
Its purpose is to import the converter_object via the Python API.
|
||||
The actual import is only done once. The pointer to the
|
||||
imported converter object is kept in the static data member
|
||||
imported_converters.
|
||||
*/
|
||||
template <class T>
|
||||
class import_extension_class
|
||||
: public python_import_extension_class_converters<T>
|
||||
{
|
||||
public:
|
||||
inline import_extension_class(const char* module, const char* py_class) {
|
||||
m_module = module;
|
||||
m_py_class = py_class;
|
||||
}
|
||||
*/
|
||||
template <class T>
|
||||
class import_extension_class
|
||||
: public python_import_extension_class_converters<T>
|
||||
{
|
||||
public:
|
||||
inline import_extension_class(const char* module, const char* py_class) {
|
||||
m_module = module;
|
||||
m_py_class = py_class;
|
||||
}
|
||||
|
||||
static boost::python::export_converter_object_base<T>* get_converters();
|
||||
static boost::python::export_converter_object_base<T>* get_converters();
|
||||
|
||||
private:
|
||||
static std::string m_module;
|
||||
static std::string m_py_class;
|
||||
static boost::python::export_converter_object_base<T>* imported_converters;
|
||||
};
|
||||
private:
|
||||
static std::string m_module;
|
||||
static std::string m_py_class;
|
||||
static boost::python::export_converter_object_base<T>* imported_converters;
|
||||
};
|
||||
|
||||
template <class T> std::string import_extension_class<T>::m_module;
|
||||
template <class T> std::string import_extension_class<T>::m_py_class;
|
||||
template <class T>
|
||||
boost::python::export_converter_object_base<T>*
|
||||
import_extension_class<T>::imported_converters = 0;
|
||||
template <class T> std::string import_extension_class<T>::m_module;
|
||||
template <class T> std::string import_extension_class<T>::m_py_class;
|
||||
template <class T>
|
||||
boost::python::export_converter_object_base<T>*
|
||||
import_extension_class<T>::imported_converters = 0;
|
||||
|
||||
template <class T>
|
||||
boost::python::export_converter_object_base<T>*
|
||||
import_extension_class<T>::get_converters() {
|
||||
if (imported_converters == 0) {
|
||||
void* cobject
|
||||
= import_converter_object(m_module, m_py_class,
|
||||
converters_attribute_name);
|
||||
imported_converters
|
||||
= static_cast<boost::python::export_converter_object_base<T>*>(cobject);
|
||||
check_export_converters_api(
|
||||
export_converters_api_major,
|
||||
export_converters_api_minor,
|
||||
imported_converters->get_api_major(),
|
||||
imported_converters->get_api_minor());
|
||||
template <class T>
|
||||
boost::python::export_converter_object_base<T>*
|
||||
import_extension_class<T>::get_converters() {
|
||||
if (imported_converters == 0) {
|
||||
void* cobject
|
||||
= import_converter_object(m_module, m_py_class,
|
||||
converters_attribute_name);
|
||||
imported_converters
|
||||
= static_cast<boost::python::export_converter_object_base<T>*>(cobject);
|
||||
check_export_converters_api(
|
||||
export_converters_api_major,
|
||||
export_converters_api_minor,
|
||||
imported_converters->get_api_major(),
|
||||
imported_converters->get_api_minor());
|
||||
}
|
||||
return imported_converters;
|
||||
}
|
||||
return imported_converters;
|
||||
}
|
||||
|
||||
}}} // namespace boost::python::detail
|
||||
|
||||
namespace boost { namespace python {
|
||||
|
||||
78
include/boost/python/default_call_policies.hpp
Normal file
78
include/boost/python/default_call_policies.hpp
Normal file
@@ -0,0 +1,78 @@
|
||||
// Copyright David Abrahams 2002. Permission to copy, use,
|
||||
// modify, sell and distribute this software is granted provided this
|
||||
// copyright notice appears in all copies. This software is provided
|
||||
// "as is" without express or implied warranty, and with no claim as
|
||||
// to its suitability for any purpose.
|
||||
#ifndef DEFAULT_CALL_POLICIES_DWA2002131_HPP
|
||||
# define DEFAULT_CALL_POLICIES_DWA2002131_HPP
|
||||
# include <boost/python/detail/wrap_python.hpp>
|
||||
# include <boost/mpl/select_type.hpp>
|
||||
# include <boost/python/to_python_value.hpp>
|
||||
# include <boost/type_traits/transform_traits.hpp>
|
||||
|
||||
namespace boost { namespace python {
|
||||
|
||||
template <class T> struct to_python_value;
|
||||
|
||||
namespace detail
|
||||
{
|
||||
// for "readable" error messages
|
||||
template <class T> struct specify_a_result_policy_to_wrap_functions_returning
|
||||
# if defined(__GNUC__) && __GNUC__ >= 3 || defined(__EDG__)
|
||||
{}
|
||||
# endif
|
||||
;
|
||||
}
|
||||
|
||||
struct default_result_converter;
|
||||
|
||||
struct default_call_policies
|
||||
{
|
||||
// Nothing to do
|
||||
static bool precall(PyObject*)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
// Pass the result through
|
||||
static PyObject* postcall(PyObject*, PyObject* result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
typedef default_result_converter result_converter;
|
||||
};
|
||||
|
||||
struct default_result_converter
|
||||
{
|
||||
template <class R>
|
||||
struct apply
|
||||
{
|
||||
BOOST_STATIC_CONSTANT(bool, is_illegal = is_reference<R>::value || is_pointer<R>::value);
|
||||
|
||||
typedef typename mpl::select_type<
|
||||
is_illegal
|
||||
, detail::specify_a_result_policy_to_wrap_functions_returning<R>
|
||||
, boost::python::to_python_value<
|
||||
typename add_reference<typename add_const<R>::type>::type
|
||||
>
|
||||
>::type type;
|
||||
};
|
||||
};
|
||||
|
||||
// Exceptions for c strings an PyObject*s
|
||||
template <>
|
||||
struct default_result_converter::apply<char const*>
|
||||
{
|
||||
typedef boost::python::to_python_value<char const*const&> type;
|
||||
};
|
||||
|
||||
template <>
|
||||
struct default_result_converter::apply<PyObject*>
|
||||
{
|
||||
typedef boost::python::to_python_value<PyObject*const&> type;
|
||||
};
|
||||
|
||||
}} // namespace boost::python
|
||||
|
||||
#endif // DEFAULT_CALL_POLICIES_DWA2002131_HPP
|
||||
341
include/boost/python/detail/arg_tuple_size.hpp
Normal file
341
include/boost/python/detail/arg_tuple_size.hpp
Normal file
@@ -0,0 +1,341 @@
|
||||
// (C) Copyright David Abrahams 2001. Permission to copy, use, modify, sell and
|
||||
// distribute this software is granted provided this copyright notice appears
|
||||
// in all copies. This software is provided "as is" without express or implied
|
||||
// warranty, and with no claim as to its suitability for any purpose.
|
||||
//
|
||||
// This work was funded in part by Lawrence Berkeley National Labs
|
||||
//
|
||||
// This file generated for 5-argument member functions and 6-argument free
|
||||
// functions by gen_arg_tuple_size.python
|
||||
|
||||
#ifndef ARG_TUPLE_SIZE_DWA20011201_HPP
|
||||
# define ARG_TUPLE_SIZE_DWA20011201_HPP
|
||||
|
||||
# include <boost/python/detail/char_array.hpp>
|
||||
|
||||
namespace boost { namespace python { namespace detail {
|
||||
|
||||
// Computes (at compile-time) the number of elements that a Python
|
||||
// argument tuple must have in order to be passed to a wrapped C++
|
||||
// (member) function of the given type.
|
||||
template <class F> struct arg_tuple_size;
|
||||
|
||||
# if !defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION) && !defined(__BORLANDC__)
|
||||
|
||||
template <class R>
|
||||
struct arg_tuple_size<R (*)()>
|
||||
{
|
||||
BOOST_STATIC_CONSTANT(std::size_t, value = 0);
|
||||
};
|
||||
|
||||
template <class R, class A1>
|
||||
struct arg_tuple_size<R (*)(A1)>
|
||||
{
|
||||
BOOST_STATIC_CONSTANT(std::size_t, value = 1);
|
||||
};
|
||||
|
||||
template <class R, class A1, class A2>
|
||||
struct arg_tuple_size<R (*)(A1, A2)>
|
||||
{
|
||||
BOOST_STATIC_CONSTANT(std::size_t, value = 2);
|
||||
};
|
||||
|
||||
template <class R, class A1, class A2, class A3>
|
||||
struct arg_tuple_size<R (*)(A1, A2, A3)>
|
||||
{
|
||||
BOOST_STATIC_CONSTANT(std::size_t, value = 3);
|
||||
};
|
||||
|
||||
template <class R, class A1, class A2, class A3, class A4>
|
||||
struct arg_tuple_size<R (*)(A1, A2, A3, A4)>
|
||||
{
|
||||
BOOST_STATIC_CONSTANT(std::size_t, value = 4);
|
||||
};
|
||||
|
||||
template <class R, class A1, class A2, class A3, class A4, class A5>
|
||||
struct arg_tuple_size<R (*)(A1, A2, A3, A4, A5)>
|
||||
{
|
||||
BOOST_STATIC_CONSTANT(std::size_t, value = 5);
|
||||
};
|
||||
|
||||
template <class R, class A1, class A2, class A3, class A4, class A5, class A6>
|
||||
struct arg_tuple_size<R (*)(A1, A2, A3, A4, A5, A6)>
|
||||
{
|
||||
BOOST_STATIC_CONSTANT(std::size_t, value = 6);
|
||||
};
|
||||
|
||||
|
||||
template <class R, class A0>
|
||||
struct arg_tuple_size<R (A0::*)()>
|
||||
{
|
||||
BOOST_STATIC_CONSTANT(std::size_t, value = 1);
|
||||
};
|
||||
|
||||
template <class R, class A0, class A1>
|
||||
struct arg_tuple_size<R (A0::*)(A1)>
|
||||
{
|
||||
BOOST_STATIC_CONSTANT(std::size_t, value = 2);
|
||||
};
|
||||
|
||||
template <class R, class A0, class A1, class A2>
|
||||
struct arg_tuple_size<R (A0::*)(A1, A2)>
|
||||
{
|
||||
BOOST_STATIC_CONSTANT(std::size_t, value = 3);
|
||||
};
|
||||
|
||||
template <class R, class A0, class A1, class A2, class A3>
|
||||
struct arg_tuple_size<R (A0::*)(A1, A2, A3)>
|
||||
{
|
||||
BOOST_STATIC_CONSTANT(std::size_t, value = 4);
|
||||
};
|
||||
|
||||
template <class R, class A0, class A1, class A2, class A3, class A4>
|
||||
struct arg_tuple_size<R (A0::*)(A1, A2, A3, A4)>
|
||||
{
|
||||
BOOST_STATIC_CONSTANT(std::size_t, value = 5);
|
||||
};
|
||||
|
||||
template <class R, class A0, class A1, class A2, class A3, class A4, class A5>
|
||||
struct arg_tuple_size<R (A0::*)(A1, A2, A3, A4, A5)>
|
||||
{
|
||||
BOOST_STATIC_CONSTANT(std::size_t, value = 6);
|
||||
};
|
||||
|
||||
|
||||
// Metrowerks thinks this creates ambiguities
|
||||
# if !defined(__MWERKS__) || __MWERKS__ > 0x2406
|
||||
|
||||
template <class R, class A0>
|
||||
struct arg_tuple_size<R (A0::*)() const>
|
||||
{
|
||||
BOOST_STATIC_CONSTANT(std::size_t, value = 1);
|
||||
};
|
||||
|
||||
template <class R, class A0, class A1>
|
||||
struct arg_tuple_size<R (A0::*)(A1) const>
|
||||
{
|
||||
BOOST_STATIC_CONSTANT(std::size_t, value = 2);
|
||||
};
|
||||
|
||||
template <class R, class A0, class A1, class A2>
|
||||
struct arg_tuple_size<R (A0::*)(A1, A2) const>
|
||||
{
|
||||
BOOST_STATIC_CONSTANT(std::size_t, value = 3);
|
||||
};
|
||||
|
||||
template <class R, class A0, class A1, class A2, class A3>
|
||||
struct arg_tuple_size<R (A0::*)(A1, A2, A3) const>
|
||||
{
|
||||
BOOST_STATIC_CONSTANT(std::size_t, value = 4);
|
||||
};
|
||||
|
||||
template <class R, class A0, class A1, class A2, class A3, class A4>
|
||||
struct arg_tuple_size<R (A0::*)(A1, A2, A3, A4) const>
|
||||
{
|
||||
BOOST_STATIC_CONSTANT(std::size_t, value = 5);
|
||||
};
|
||||
|
||||
template <class R, class A0, class A1, class A2, class A3, class A4, class A5>
|
||||
struct arg_tuple_size<R (A0::*)(A1, A2, A3, A4, A5) const>
|
||||
{
|
||||
BOOST_STATIC_CONSTANT(std::size_t, value = 6);
|
||||
};
|
||||
|
||||
|
||||
template <class R, class A0>
|
||||
struct arg_tuple_size<R (A0::*)() volatile>
|
||||
{
|
||||
BOOST_STATIC_CONSTANT(std::size_t, value = 1);
|
||||
};
|
||||
|
||||
template <class R, class A0, class A1>
|
||||
struct arg_tuple_size<R (A0::*)(A1) volatile>
|
||||
{
|
||||
BOOST_STATIC_CONSTANT(std::size_t, value = 2);
|
||||
};
|
||||
|
||||
template <class R, class A0, class A1, class A2>
|
||||
struct arg_tuple_size<R (A0::*)(A1, A2) volatile>
|
||||
{
|
||||
BOOST_STATIC_CONSTANT(std::size_t, value = 3);
|
||||
};
|
||||
|
||||
template <class R, class A0, class A1, class A2, class A3>
|
||||
struct arg_tuple_size<R (A0::*)(A1, A2, A3) volatile>
|
||||
{
|
||||
BOOST_STATIC_CONSTANT(std::size_t, value = 4);
|
||||
};
|
||||
|
||||
template <class R, class A0, class A1, class A2, class A3, class A4>
|
||||
struct arg_tuple_size<R (A0::*)(A1, A2, A3, A4) volatile>
|
||||
{
|
||||
BOOST_STATIC_CONSTANT(std::size_t, value = 5);
|
||||
};
|
||||
|
||||
template <class R, class A0, class A1, class A2, class A3, class A4, class A5>
|
||||
struct arg_tuple_size<R (A0::*)(A1, A2, A3, A4, A5) volatile>
|
||||
{
|
||||
BOOST_STATIC_CONSTANT(std::size_t, value = 6);
|
||||
};
|
||||
|
||||
|
||||
template <class R, class A0>
|
||||
struct arg_tuple_size<R (A0::*)() const volatile>
|
||||
{
|
||||
BOOST_STATIC_CONSTANT(std::size_t, value = 1);
|
||||
};
|
||||
|
||||
template <class R, class A0, class A1>
|
||||
struct arg_tuple_size<R (A0::*)(A1) const volatile>
|
||||
{
|
||||
BOOST_STATIC_CONSTANT(std::size_t, value = 2);
|
||||
};
|
||||
|
||||
template <class R, class A0, class A1, class A2>
|
||||
struct arg_tuple_size<R (A0::*)(A1, A2) const volatile>
|
||||
{
|
||||
BOOST_STATIC_CONSTANT(std::size_t, value = 3);
|
||||
};
|
||||
|
||||
template <class R, class A0, class A1, class A2, class A3>
|
||||
struct arg_tuple_size<R (A0::*)(A1, A2, A3) const volatile>
|
||||
{
|
||||
BOOST_STATIC_CONSTANT(std::size_t, value = 4);
|
||||
};
|
||||
|
||||
template <class R, class A0, class A1, class A2, class A3, class A4>
|
||||
struct arg_tuple_size<R (A0::*)(A1, A2, A3, A4) const volatile>
|
||||
{
|
||||
BOOST_STATIC_CONSTANT(std::size_t, value = 5);
|
||||
};
|
||||
|
||||
template <class R, class A0, class A1, class A2, class A3, class A4, class A5>
|
||||
struct arg_tuple_size<R (A0::*)(A1, A2, A3, A4, A5) const volatile>
|
||||
{
|
||||
BOOST_STATIC_CONSTANT(std::size_t, value = 6);
|
||||
};
|
||||
|
||||
|
||||
# endif // __MWERKS__
|
||||
# else
|
||||
|
||||
// We will use the "sizeof() trick" to work around the lack of
|
||||
// partial specialization in MSVC6 and its broken-ness in borland.
|
||||
// See http://opensource.adobe.com or
|
||||
// http://groups.yahoo.com/group/boost/message/5441 for
|
||||
// more examples
|
||||
|
||||
// The following helper functions are never actually called, since
|
||||
// they are only used within a sizeof() expression, but the type of
|
||||
// their return value is used to discriminate between various free
|
||||
// and member function pointers at compile-time.
|
||||
|
||||
template <class R>
|
||||
char_array<0> arg_tuple_size_helper(R (*)());
|
||||
|
||||
template <class R, class A1>
|
||||
char_array<1> arg_tuple_size_helper(R (*)(A1));
|
||||
|
||||
template <class R, class A1, class A2>
|
||||
char_array<2> arg_tuple_size_helper(R (*)(A1, A2));
|
||||
|
||||
template <class R, class A1, class A2, class A3>
|
||||
char_array<3> arg_tuple_size_helper(R (*)(A1, A2, A3));
|
||||
|
||||
template <class R, class A1, class A2, class A3, class A4>
|
||||
char_array<4> arg_tuple_size_helper(R (*)(A1, A2, A3, A4));
|
||||
|
||||
template <class R, class A1, class A2, class A3, class A4, class A5>
|
||||
char_array<5> arg_tuple_size_helper(R (*)(A1, A2, A3, A4, A5));
|
||||
|
||||
template <class R, class A1, class A2, class A3, class A4, class A5, class A6>
|
||||
char_array<6> arg_tuple_size_helper(R (*)(A1, A2, A3, A4, A5, A6));
|
||||
|
||||
template <class R, class A0>
|
||||
char_array<1> arg_tuple_size_helper(R (A0::*)());
|
||||
|
||||
template <class R, class A0, class A1>
|
||||
char_array<2> arg_tuple_size_helper(R (A0::*)(A1));
|
||||
|
||||
template <class R, class A0, class A1, class A2>
|
||||
char_array<3> arg_tuple_size_helper(R (A0::*)(A1, A2));
|
||||
|
||||
template <class R, class A0, class A1, class A2, class A3>
|
||||
char_array<4> arg_tuple_size_helper(R (A0::*)(A1, A2, A3));
|
||||
|
||||
template <class R, class A0, class A1, class A2, class A3, class A4>
|
||||
char_array<5> arg_tuple_size_helper(R (A0::*)(A1, A2, A3, A4));
|
||||
|
||||
template <class R, class A0, class A1, class A2, class A3, class A4, class A5>
|
||||
char_array<6> arg_tuple_size_helper(R (A0::*)(A1, A2, A3, A4, A5));
|
||||
|
||||
|
||||
template <class R, class A0>
|
||||
char_array<1> arg_tuple_size_helper(R (A0::*)() const);
|
||||
|
||||
template <class R, class A0, class A1>
|
||||
char_array<2> arg_tuple_size_helper(R (A0::*)(A1) const);
|
||||
|
||||
template <class R, class A0, class A1, class A2>
|
||||
char_array<3> arg_tuple_size_helper(R (A0::*)(A1, A2) const);
|
||||
|
||||
template <class R, class A0, class A1, class A2, class A3>
|
||||
char_array<4> arg_tuple_size_helper(R (A0::*)(A1, A2, A3) const);
|
||||
|
||||
template <class R, class A0, class A1, class A2, class A3, class A4>
|
||||
char_array<5> arg_tuple_size_helper(R (A0::*)(A1, A2, A3, A4) const);
|
||||
|
||||
template <class R, class A0, class A1, class A2, class A3, class A4, class A5>
|
||||
char_array<6> arg_tuple_size_helper(R (A0::*)(A1, A2, A3, A4, A5) const);
|
||||
|
||||
|
||||
template <class R, class A0>
|
||||
char_array<1> arg_tuple_size_helper(R (A0::*)() volatile);
|
||||
|
||||
template <class R, class A0, class A1>
|
||||
char_array<2> arg_tuple_size_helper(R (A0::*)(A1) volatile);
|
||||
|
||||
template <class R, class A0, class A1, class A2>
|
||||
char_array<3> arg_tuple_size_helper(R (A0::*)(A1, A2) volatile);
|
||||
|
||||
template <class R, class A0, class A1, class A2, class A3>
|
||||
char_array<4> arg_tuple_size_helper(R (A0::*)(A1, A2, A3) volatile);
|
||||
|
||||
template <class R, class A0, class A1, class A2, class A3, class A4>
|
||||
char_array<5> arg_tuple_size_helper(R (A0::*)(A1, A2, A3, A4) volatile);
|
||||
|
||||
template <class R, class A0, class A1, class A2, class A3, class A4, class A5>
|
||||
char_array<6> arg_tuple_size_helper(R (A0::*)(A1, A2, A3, A4, A5) volatile);
|
||||
|
||||
|
||||
template <class R, class A0>
|
||||
char_array<1> arg_tuple_size_helper(R (A0::*)() const volatile);
|
||||
|
||||
template <class R, class A0, class A1>
|
||||
char_array<2> arg_tuple_size_helper(R (A0::*)(A1) const volatile);
|
||||
|
||||
template <class R, class A0, class A1, class A2>
|
||||
char_array<3> arg_tuple_size_helper(R (A0::*)(A1, A2) const volatile);
|
||||
|
||||
template <class R, class A0, class A1, class A2, class A3>
|
||||
char_array<4> arg_tuple_size_helper(R (A0::*)(A1, A2, A3) const volatile);
|
||||
|
||||
template <class R, class A0, class A1, class A2, class A3, class A4>
|
||||
char_array<5> arg_tuple_size_helper(R (A0::*)(A1, A2, A3, A4) const volatile);
|
||||
|
||||
template <class R, class A0, class A1, class A2, class A3, class A4, class A5>
|
||||
char_array<6> arg_tuple_size_helper(R (A0::*)(A1, A2, A3, A4, A5) const volatile);
|
||||
|
||||
|
||||
template <class F>
|
||||
struct arg_tuple_size
|
||||
{
|
||||
// The sizeof() magic happens here
|
||||
BOOST_STATIC_CONSTANT(std::size_t, value
|
||||
= sizeof(arg_tuple_size_helper(F(0)).elements) - 1);
|
||||
};
|
||||
# endif // BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
|
||||
}}} // namespace boost::python::detail
|
||||
|
||||
#endif // ARG_TUPLE_SIZE_DWA20011201_HPP
|
||||
|
||||
@@ -13,7 +13,6 @@
|
||||
# define BASE_OBJECT_DWA051600_H_
|
||||
|
||||
# include <boost/python/detail/config.hpp>
|
||||
# include <boost/python/detail/signatures.hpp> // really just for type<>
|
||||
# include <boost/python/detail/wrap_python.hpp>
|
||||
# include <cstring>
|
||||
|
||||
@@ -45,10 +44,7 @@ template <class PythonType>
|
||||
base_object<PythonType>::base_object(PyTypeObject* type_obj)
|
||||
{
|
||||
base_python_type* bp = this;
|
||||
#if !defined(_MSC_VER) || defined(__STLPORT)
|
||||
std::
|
||||
#endif
|
||||
memset(bp, 0, sizeof(base_python_type));
|
||||
BOOST_CSTD_::memset(bp, 0, sizeof(base_python_type));
|
||||
Py_INCREF(type_obj);
|
||||
PyObject_INIT(bp, type_obj);
|
||||
}
|
||||
|
||||
66
include/boost/python/detail/call_object.hpp
Normal file
66
include/boost/python/detail/call_object.hpp
Normal file
@@ -0,0 +1,66 @@
|
||||
// Copyright David Abrahams 2001. Permission to copy, use,
|
||||
// modify, sell and distribute this software is granted provided this
|
||||
// copyright notice appears in all copies. This software is provided
|
||||
// "as is" without express or implied warranty, and with no claim as
|
||||
// to its suitability for any purpose.
|
||||
#ifndef CALL_OBJECT_DWA20011222_HPP
|
||||
# define CALL_OBJECT_DWA20011222_HPP
|
||||
# include <boost/python/errors.hpp>
|
||||
# include <boost/python/detail/types.hpp>
|
||||
# include <boost/bind.hpp>
|
||||
|
||||
namespace boost { namespace python {
|
||||
|
||||
namespace detail
|
||||
{
|
||||
// A function object adaptor which turns a function returning R into
|
||||
// an "equivalent" function returning void, but taking an R& in
|
||||
// which the adapted function's result is stored.
|
||||
template <class R, class F>
|
||||
struct return_by_reference
|
||||
{
|
||||
typedef void return_type;
|
||||
|
||||
return_by_reference(R& result, F f)
|
||||
: m_result(result)
|
||||
, m_f(f)
|
||||
{
|
||||
}
|
||||
|
||||
void operator()() const
|
||||
{
|
||||
m_result = m_f();
|
||||
}
|
||||
|
||||
R& m_result;
|
||||
F m_f;
|
||||
};
|
||||
|
||||
// An object generator for the above adaptors
|
||||
template <class R, class F>
|
||||
return_by_reference<R,F> bind_return(R& result, F f)
|
||||
{
|
||||
return return_by_reference<R,F>(result, f);
|
||||
}
|
||||
|
||||
// Given a function object f with signature
|
||||
//
|
||||
// R f(PyTypeObject*,PyObject*)
|
||||
//
|
||||
// calls f inside of handle_exception_impl, placing f's result in
|
||||
// ret. Returns true iff an exception is thrown by f, leaving ret
|
||||
// unmodified.
|
||||
template <class R, class F>
|
||||
bool call_object(R& ret, PyObject* obj, F f)
|
||||
{
|
||||
return handle_exception(
|
||||
detail::bind_return(
|
||||
ret
|
||||
, boost::bind<R>(
|
||||
f, static_cast<type_object_base*>(obj->ob_type), obj)));
|
||||
}
|
||||
} // namespace detail
|
||||
|
||||
}} // namespace boost::python
|
||||
|
||||
#endif // CALL_OBJECT_DWA20011222_HPP
|
||||
216
include/boost/python/detail/caller.hpp
Normal file
216
include/boost/python/detail/caller.hpp
Normal file
@@ -0,0 +1,216 @@
|
||||
// Copyright David Abrahams 2001. Permission to copy, use,
|
||||
// modify, sell and distribute this software is granted provided this
|
||||
// copyright notice appears in all copies. This software is provided
|
||||
// "as is" without express or implied warranty, and with no claim as
|
||||
// to its suitability for any purpose.
|
||||
#ifndef CALLER_DWA20011214_HPP
|
||||
# define CALLER_DWA20011214_HPP
|
||||
|
||||
# include <boost/python/detail/wrap_python.hpp>
|
||||
# include <boost/python/detail/returning.hpp>
|
||||
# include <boost/mpl/select_type.hpp>
|
||||
# include <boost/type_traits/composite_traits.hpp>
|
||||
# include <boost/type_traits/same_traits.hpp>
|
||||
|
||||
namespace boost { namespace python
|
||||
{
|
||||
template <class T> struct to_python;
|
||||
}}
|
||||
|
||||
namespace boost { namespace python { namespace detail {
|
||||
|
||||
struct caller
|
||||
{
|
||||
typedef PyObject* result_type;
|
||||
|
||||
template <class P, class R>
|
||||
PyObject* operator()(R (*f)(), PyObject* args, PyObject* keywords, P const& policies) const
|
||||
{
|
||||
return returning<R>::call(f, args, keywords, policies);
|
||||
}
|
||||
|
||||
template <class P, class R, class A0>
|
||||
PyObject* operator()(R (*f)(A0), PyObject* args, PyObject* keywords, P const& policies) const
|
||||
{
|
||||
return returning<R>::call(f, args, keywords, policies);
|
||||
}
|
||||
|
||||
template <class P, class R, class A0, class A1>
|
||||
PyObject* operator()(R (*f)(A0, A1), PyObject* args, PyObject* keywords, P const& policies) const
|
||||
{
|
||||
return returning<R>::call(f, args, keywords, policies);
|
||||
}
|
||||
|
||||
template <class P, class R, class A0, class A1, class A2>
|
||||
PyObject* operator()(R (*f)(A0, A1, A2), PyObject* args, PyObject* keywords, P const& policies) const
|
||||
{
|
||||
return returning<R>::call(f, args, keywords, policies);
|
||||
}
|
||||
|
||||
template <class P, class R, class A0, class A1, class A2, class A3>
|
||||
PyObject* operator()(R (*f)(A0, A1, A2, A3), PyObject* args, PyObject* keywords, P const& policies) const
|
||||
{
|
||||
return returning<R>::call(f, args, keywords, policies);
|
||||
}
|
||||
|
||||
template <class P, class R, class A0, class A1, class A2, class A3, class A4>
|
||||
PyObject* operator()(R (*f)(A0, A1, A2, A3, A4), PyObject* args, PyObject* keywords, P const& policies) const
|
||||
{
|
||||
return returning<R>::call(f, args, keywords, policies);
|
||||
}
|
||||
|
||||
template <class P, class R, class A0, class A1, class A2, class A3, class A4, class A5>
|
||||
PyObject* operator()(R (*f)(A0, A1, A2, A3, A4, A5), PyObject* args, PyObject* keywords, P const& policies) const
|
||||
{
|
||||
return returning<R>::call(f, args, keywords, policies);
|
||||
}
|
||||
|
||||
// Member functions
|
||||
template <class P, class R, class A0>
|
||||
PyObject* operator()(R (A0::*f)(), PyObject* args, PyObject* keywords, P const& policies) const
|
||||
{
|
||||
return returning<R>::call(f, args, keywords, policies);
|
||||
}
|
||||
|
||||
template <class P, class R, class A0, class A1>
|
||||
PyObject* operator()(R (A0::*f)(A1), PyObject* args, PyObject* keywords, P const& policies) const
|
||||
{
|
||||
return returning<R>::call(f, args, keywords, policies);
|
||||
}
|
||||
|
||||
template <class P, class R, class A0, class A1, class A2>
|
||||
PyObject* operator()(R (A0::*f)(A1, A2), PyObject* args, PyObject* keywords, P const& policies) const
|
||||
{
|
||||
return returning<R>::call(f, args, keywords, policies);
|
||||
}
|
||||
|
||||
template <class P, class R, class A0, class A1, class A2, class A3>
|
||||
PyObject* operator()(R (A0::*f)(A1, A2, A3), PyObject* args, PyObject* keywords, P const& policies) const
|
||||
{
|
||||
return returning<R>::call(f, args, keywords, policies);
|
||||
}
|
||||
|
||||
template <class P, class R, class A0, class A1, class A2, class A3, class A4>
|
||||
PyObject* operator()(R (A0::*f)(A1, A2, A3, A4), PyObject* args, PyObject* keywords, P const& policies) const
|
||||
{
|
||||
return returning<R>::call(f, args, keywords, policies);
|
||||
}
|
||||
|
||||
template <class P, class R, class A0, class A1, class A2, class A3, class A4, class A5>
|
||||
PyObject* operator()(R (A0::*f)(A1, A2, A3, A4, A5), PyObject* args, PyObject* keywords, P const& policies) const
|
||||
{
|
||||
return returning<R>::call(f, args, keywords, policies);
|
||||
}
|
||||
|
||||
template <class P, class R, class A0>
|
||||
PyObject* operator()(R (A0::*f)() const, PyObject* args, PyObject* keywords, P const& policies) const
|
||||
{
|
||||
return returning<R>::call(f, args, keywords, policies);
|
||||
}
|
||||
|
||||
template <class P, class R, class A0, class A1>
|
||||
PyObject* operator()(R (A0::*f)(A1) const, PyObject* args, PyObject* keywords, P const& policies) const
|
||||
{
|
||||
return returning<R>::call(f, args, keywords, policies);
|
||||
}
|
||||
|
||||
template <class P, class R, class A0, class A1, class A2>
|
||||
PyObject* operator()(R (A0::*f)(A1, A2) const, PyObject* args, PyObject* keywords, P const& policies) const
|
||||
{
|
||||
return returning<R>::call(f, args, keywords, policies);
|
||||
}
|
||||
|
||||
template <class P, class R, class A0, class A1, class A2, class A3>
|
||||
PyObject* operator()(R (A0::*f)(A1, A2, A3) const, PyObject* args, PyObject* keywords, P const& policies) const
|
||||
{
|
||||
return returning<R>::call(f, args, keywords, policies);
|
||||
}
|
||||
|
||||
template <class P, class R, class A0, class A1, class A2, class A3, class A4>
|
||||
PyObject* operator()(R (A0::*f)(A1, A2, A3, A4) const, PyObject* args, PyObject* keywords, P const& policies) const
|
||||
{
|
||||
return returning<R>::call(f, args, keywords, policies);
|
||||
}
|
||||
|
||||
template <class P, class R, class A0, class A1, class A2, class A3, class A4, class A5>
|
||||
PyObject* operator()(R (A0::*f)(A1, A2, A3, A4, A5) const, PyObject* args, PyObject* keywords, P const& policies) const
|
||||
{
|
||||
return returning<R>::call(f, args, keywords, policies);
|
||||
}
|
||||
|
||||
template <class P, class R, class A0>
|
||||
PyObject* operator()(R (A0::*f)() volatile, PyObject* args, PyObject* keywords, P const& policies) const
|
||||
{
|
||||
return returning<R>::call(f, args, keywords, policies);
|
||||
}
|
||||
|
||||
template <class P, class R, class A0, class A1>
|
||||
PyObject* operator()(R (A0::*f)(A1) volatile, PyObject* args, PyObject* keywords, P const& policies) const
|
||||
{
|
||||
return returning<R>::call(f, args, keywords, policies);
|
||||
}
|
||||
|
||||
template <class P, class R, class A0, class A1, class A2>
|
||||
PyObject* operator()(R (A0::*f)(A1, A2) volatile, PyObject* args, PyObject* keywords, P const& policies) const
|
||||
{
|
||||
return returning<R>::call(f, args, keywords, policies);
|
||||
}
|
||||
|
||||
template <class P, class R, class A0, class A1, class A2, class A3>
|
||||
PyObject* operator()(R (A0::*f)(A1, A2, A3) volatile, PyObject* args, PyObject* keywords, P const& policies) const
|
||||
{
|
||||
return returning<R>::call(f, args, keywords, policies);
|
||||
}
|
||||
|
||||
template <class P, class R, class A0, class A1, class A2, class A3, class A4>
|
||||
PyObject* operator()(R (A0::*f)(A1, A2, A3, A4) volatile, PyObject* args, PyObject* keywords, P const& policies) const
|
||||
{
|
||||
return returning<R>::call(f, args, keywords, policies);
|
||||
}
|
||||
|
||||
template <class P, class R, class A0, class A1, class A2, class A3, class A4, class A5>
|
||||
PyObject* operator()(R (A0::*f)(A1, A2, A3, A4, A5) volatile, PyObject* args, PyObject* keywords, P const& policies) const
|
||||
{
|
||||
return returning<R>::call(f, args, keywords, policies);
|
||||
}
|
||||
|
||||
template <class P, class R, class A0>
|
||||
PyObject* operator()(R (A0::*f)() const volatile, PyObject* args, PyObject* keywords, P const& policies) const
|
||||
{
|
||||
return returning<R>::call(f, args, keywords, policies);
|
||||
}
|
||||
|
||||
template <class P, class R, class A0, class A1>
|
||||
PyObject* operator()(R (A0::*f)(A1) const volatile, PyObject* args, PyObject* keywords, P const& policies) const
|
||||
{
|
||||
return returning<R>::call(f, args, keywords, policies);
|
||||
}
|
||||
|
||||
template <class P, class R, class A0, class A1, class A2>
|
||||
PyObject* operator()(R (A0::*f)(A1, A2) const volatile, PyObject* args, PyObject* keywords, P const& policies) const
|
||||
{
|
||||
return returning<R>::call(f, args, keywords, policies);
|
||||
}
|
||||
|
||||
template <class P, class R, class A0, class A1, class A2, class A3>
|
||||
PyObject* operator()(R (A0::*f)(A1, A2, A3) const volatile, PyObject* args, PyObject* keywords, P const& policies) const
|
||||
{
|
||||
return returning<R>::call(f, args, keywords, policies);
|
||||
}
|
||||
|
||||
template <class P, class R, class A0, class A1, class A2, class A3, class A4>
|
||||
PyObject* operator()(R (A0::*f)(A1, A2, A3, A4) const volatile, PyObject* args, PyObject* keywords, P const& policies) const
|
||||
{
|
||||
return returning<R>::call(f, args, keywords, policies);
|
||||
}
|
||||
|
||||
template <class P, class R, class A0, class A1, class A2, class A3, class A4, class A5>
|
||||
PyObject* operator()(R (A0::*f)(A1, A2, A3, A4, A5) const volatile, PyObject* args, PyObject* keywords, P const& policies) const
|
||||
{
|
||||
return returning<R>::call(f, args, keywords, policies);
|
||||
}
|
||||
};
|
||||
|
||||
}}} // namespace boost::python::detail
|
||||
|
||||
#endif // CALLER_DWA20011214_HPP
|
||||
@@ -9,8 +9,9 @@
|
||||
#ifndef CAST_DWA052500_H_
|
||||
# define CAST_DWA052500_H_
|
||||
|
||||
# include <boost/python/detail/wrap_python.hpp>
|
||||
# include <boost/operators.hpp>
|
||||
# ifndef BOOST_PYTHON_V2
|
||||
# include <boost/python/detail/wrap_python.hpp>
|
||||
# include <boost/operators.hpp>
|
||||
|
||||
namespace boost { namespace python {
|
||||
|
||||
@@ -75,4 +76,6 @@ struct downcast
|
||||
|
||||
}} // namespace boost::python
|
||||
|
||||
# endif // BOOST_PYTHON_V2
|
||||
|
||||
#endif // CAST_DWA052500_H_
|
||||
|
||||
23
include/boost/python/detail/char_array.hpp
Normal file
23
include/boost/python/detail/char_array.hpp
Normal file
@@ -0,0 +1,23 @@
|
||||
// Copyright David Abrahams 2002. Permission to copy, use,
|
||||
// modify, sell and distribute this software is granted provided this
|
||||
// copyright notice appears in all copies. This software is provided
|
||||
// "as is" without express or implied warranty, and with no claim as
|
||||
// to its suitability for any purpose.
|
||||
#ifndef CHAR_ARRAY_DWA2002129_HPP
|
||||
# define CHAR_ARRAY_DWA2002129_HPP
|
||||
|
||||
namespace boost { namespace python { namespace detail {
|
||||
|
||||
// This little package is used to transmit the number of arguments
|
||||
// from the helper functions below to the sizeof() expression below.
|
||||
// Because we can never have an array of fewer than 1 element, we
|
||||
// add 1 to n and then subtract 1 from the result of sizeof() below.
|
||||
template <int n>
|
||||
struct char_array
|
||||
{
|
||||
char elements[n+1];
|
||||
};
|
||||
|
||||
}}} // namespace boost::python::detail
|
||||
|
||||
#endif // CHAR_ARRAY_DWA2002129_HPP
|
||||
@@ -33,10 +33,15 @@
|
||||
# define BOOST_MSVC6_OR_EARLIER 1
|
||||
# endif
|
||||
|
||||
# pragma warning (disable : 4786)
|
||||
# pragma warning (disable : 4786)
|
||||
|
||||
# elif defined(__ICL) && __ICL < 600 // Intel C++ 5
|
||||
|
||||
# pragma warning(disable: 985) // identifier was truncated in debug information
|
||||
|
||||
# endif
|
||||
|
||||
|
||||
// Work around the broken library implementation/strict ansi checking on some
|
||||
// EDG-based compilers (e.g. alpha), which incorrectly warn that the result of
|
||||
// offsetof() is not an integer constant expression.
|
||||
@@ -57,10 +62,113 @@
|
||||
# define BOOST_CSTD_ std
|
||||
# endif
|
||||
|
||||
#if defined(_WIN32) || defined(__CYGWIN__)
|
||||
# define BOOST_PYTHON_MODULE_INIT(name) void init_module_##name(); extern "C" __declspec(dllexport) void init##name() { boost::python::handle_exception(init_module_##name); } void init_module_##name()
|
||||
# ifndef BOOST_PYTHON_MODULE_INIT
|
||||
# if defined(_WIN32) || defined(__CYGWIN__)
|
||||
# define BOOST_PYTHON_MODULE_INIT(name) void init_module_##name(); extern "C" __declspec(dllexport) void init##name() { boost::python::handle_exception(&init_module_##name); } void init_module_##name()
|
||||
# else
|
||||
# define BOOST_PYTHON_MODULE_INIT(name) void init_module_##name(); extern "C" void init##name() { boost::python::handle_exception(&init_module_##name); } void init_module_##name()
|
||||
# endif
|
||||
# endif
|
||||
|
||||
/*****************************************************************************
|
||||
*
|
||||
* Set up dll import/export options:
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
// backwards compatibility:
|
||||
#ifdef BOOST_PYTHON_STATIC_LIB
|
||||
# define BOOST_PYTHON_STATIC_LINK
|
||||
#endif
|
||||
|
||||
#if defined(__MWERKS__) \
|
||||
|| (defined(__DECCXX_VER) && __DECCXX_VER <= 60590002) \
|
||||
|| (defined(__sgi) && defined(_COMPILER_VERSION) && _COMPILER_VERSION <= 730)
|
||||
# define BOOST_PYTHON_NO_TEMPLATE_EXPORT
|
||||
#endif
|
||||
|
||||
#if defined(__GNUC__)
|
||||
# define BOOST_PYTHON_IMPORT_TEMPLATE_KEYWORD extern
|
||||
# define BOOST_PYTHON_EXPORT_TEMPLATE_KEYWORD extern
|
||||
#endif
|
||||
|
||||
// Handle default cases
|
||||
#ifndef BOOST_PYTHON_IMPORT_TEMPLATE_KEYWORD
|
||||
# ifdef _WIN32
|
||||
# define BOOST_PYTHON_IMPORT_TEMPLATE_KEYWORD extern
|
||||
# else
|
||||
# define BOOST_PYTHON_IMPORT_TEMPLATE_KEYWORD
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifndef BOOST_PYTHON_EXPORT_TEMPLATE_KEYWORD
|
||||
# define BOOST_PYTHON_EXPORT_TEMPLATE_KEYWORD
|
||||
#endif
|
||||
|
||||
#if defined(BOOST_PYTHON_DYNAMIC_LIB) && defined(_WIN32)
|
||||
# if defined(BOOST_PYTHON_SOURCE)
|
||||
# define BOOST_PYTHON_DECL __declspec(dllexport)
|
||||
# define BOOST_PYTHON_BUILD_DLL
|
||||
# else
|
||||
# define BOOST_PYTHON_DECL __declspec(dllimport)
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifndef BOOST_PYTHON_DECL
|
||||
# define BOOST_PYTHON_DECL
|
||||
#endif
|
||||
|
||||
#ifndef BOOST_PYTHON_DECL_TEMPLATE
|
||||
# ifndef BOOST_PYTHON_NO_TEMPLATE_EXPORT
|
||||
# define BOOST_PYTHON_DECL_TEMPLATE BOOST_PYTHON_DECL
|
||||
# else
|
||||
# define BOOST_PYTHON_DECL_TEMPLATE
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#if defined(BOOST_PYTHON_SOURCE)
|
||||
# define BOOST_PYTHON_EXPORT BOOST_PYTHON_EXPORT_TEMPLATE_KEYWORD
|
||||
#else
|
||||
# define BOOST_PYTHON_MODULE_INIT(name) void init_module_##name(); extern "C" void init##name() { boost::python::handle_exception(init_module_##name); } void init_module_##name()
|
||||
# define BOOST_PYTHON_EXPORT BOOST_PYTHON_IMPORT_TEMPLATE_KEYWORD
|
||||
#endif
|
||||
|
||||
# ifndef BOOST_PYTHON_EXPORT_TEMPLATE
|
||||
# define BOOST_PYTHON_EXPORT_TEMPLATE BOOST_PYTHON_EXPORT template
|
||||
# endif
|
||||
|
||||
# define BOOST_PYTHON_EXPORT_TEMPLATE_CLASS BOOST_PYTHON_EXPORT template class BOOST_PYTHON_DECL
|
||||
|
||||
// Borland C++ Fix/error check:
|
||||
#if defined(__BORLANDC__)
|
||||
# if (__BORLANDC__ == 0x550) || (__BORLANDC__ == 0x551)
|
||||
// problems with std::basic_string and dll RTL:
|
||||
# if defined(_RTLDLL) && defined(_RWSTD_COMPILE_INSTANTIATE)
|
||||
# ifdef BOOST_PYTHON_BUILD_DLL
|
||||
# error _RWSTD_COMPILE_INSTANTIATE must not be defined when building regex++ as a DLL
|
||||
# else
|
||||
# pragma warn defining _RWSTD_COMPILE_INSTANTIATE when linking to the DLL version of the RTL may produce memory corruption problems in std::basic_string, as a result of separate versions of basic_string's static data in the RTL and you're exe/dll: be warned!!
|
||||
# endif
|
||||
# endif
|
||||
# ifndef _RTLDLL
|
||||
// this is harmless for a static link:
|
||||
# define _RWSTD_COMPILE_INSTANTIATE
|
||||
# endif
|
||||
# endif
|
||||
//
|
||||
// VCL support:
|
||||
// if we're building a console app then there can't be any VCL (can there?)
|
||||
# if !defined(__CONSOLE__) && !defined(_NO_VCL)
|
||||
# define BOOST_PYTHON_USE_VCL
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#if defined(__sgi) && defined(_COMPILER_VERSION) && _COMPILER_VERSION <= 730
|
||||
// Work around a compiler bug.
|
||||
// boost::python::detail::function has to be seen by the compiler before the
|
||||
// boost::function class template.
|
||||
namespace boost { namespace python { namespace detail {
|
||||
class function;
|
||||
}}}
|
||||
#endif
|
||||
|
||||
#endif // CONFIG_DWA052200_H_
|
||||
|
||||
34
include/boost/python/detail/cv_category.hpp
Normal file
34
include/boost/python/detail/cv_category.hpp
Normal file
@@ -0,0 +1,34 @@
|
||||
// Copyright David Abrahams 2002. Permission to copy, use,
|
||||
// modify, sell and distribute this software is granted provided this
|
||||
// copyright notice appears in all copies. This software is provided
|
||||
// "as is" without express or implied warranty, and with no claim as
|
||||
// to its suitability for any purpose.
|
||||
#ifndef CV_CATEGORY_DWA200222_HPP
|
||||
# define CV_CATEGORY_DWA200222_HPP
|
||||
# include <boost/type_traits/cv_traits.hpp>
|
||||
|
||||
namespace boost { namespace python { namespace detail {
|
||||
|
||||
template <bool is_const_, bool is_volatile_>
|
||||
struct cv_tag
|
||||
{
|
||||
BOOST_STATIC_CONSTANT(bool, is_const = is_const_);
|
||||
BOOST_STATIC_CONSTANT(bool, is_volatile = is_const_);
|
||||
};
|
||||
|
||||
typedef cv_tag<false,false> cv_unqualified;
|
||||
typedef cv_tag<true,false> const_;
|
||||
typedef cv_tag<false,true> volatile_;
|
||||
typedef cv_tag<true,true> const_volatile_;
|
||||
|
||||
template <class T>
|
||||
struct cv_category
|
||||
{
|
||||
BOOST_STATIC_CONSTANT(bool, c = is_const<T>::value);
|
||||
BOOST_STATIC_CONSTANT(bool, v = is_volatile<T>::value);
|
||||
typedef cv_tag<c,v> type;
|
||||
};
|
||||
|
||||
}}} // namespace boost::python::detail
|
||||
|
||||
#endif // CV_CATEGORY_DWA200222_HPP
|
||||
83
include/boost/python/detail/destroy.hpp
Normal file
83
include/boost/python/detail/destroy.hpp
Normal file
@@ -0,0 +1,83 @@
|
||||
// Copyright David Abrahams 2002. Permission to copy, use,
|
||||
// modify, sell and distribute this software is granted provided this
|
||||
// copyright notice appears in all copies. This software is provided
|
||||
// "as is" without express or implied warranty, and with no claim as
|
||||
// to its suitability for any purpose.
|
||||
#ifndef DESTROY_DWA2002221_HPP
|
||||
# define DESTROY_DWA2002221_HPP
|
||||
|
||||
# include <boost/type_traits/composite_traits.hpp>
|
||||
# include <boost/type_traits/object_traits.hpp>
|
||||
|
||||
namespace boost { namespace python { namespace detail {
|
||||
|
||||
template <bool array, bool trivial_destructor> struct value_destroyer;
|
||||
|
||||
template <>
|
||||
struct value_destroyer<false,false>
|
||||
{
|
||||
template <class T>
|
||||
static void execute(T const volatile* p)
|
||||
{
|
||||
p->T::~T();
|
||||
}
|
||||
};
|
||||
|
||||
template <>
|
||||
struct value_destroyer<true,false>
|
||||
{
|
||||
template <class A, class T>
|
||||
static void execute(A*, T const volatile* const first)
|
||||
{
|
||||
for (T const volatile* p = first; p != first + sizeof(A)/sizeof(T); ++p)
|
||||
value_destroyer<
|
||||
boost::is_array<T>::value
|
||||
,boost::has_trivial_destructor<T>::value
|
||||
>::execute(p);
|
||||
}
|
||||
|
||||
template <class T>
|
||||
static void execute(T const volatile* p)
|
||||
{
|
||||
execute(p, *p);
|
||||
}
|
||||
};
|
||||
|
||||
template <>
|
||||
struct value_destroyer<true,true>
|
||||
{
|
||||
template <class T>
|
||||
static void execute(T const volatile* p)
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
template <>
|
||||
struct value_destroyer<false,true>
|
||||
{
|
||||
template <class T>
|
||||
static void execute(T const volatile* p)
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
template <class T>
|
||||
inline void destroy_reference_impl(void* p, T& (*)())
|
||||
{
|
||||
// note: cv-qualification needed for MSVC6
|
||||
// must come *before* T for metrowerks
|
||||
value_destroyer<
|
||||
(boost::is_array<T>::value)
|
||||
, (boost::has_trivial_destructor<T>::value)
|
||||
>::execute((const volatile T*)p);
|
||||
}
|
||||
|
||||
template <class T>
|
||||
inline void destroy_reference(void* p, T(*)() = 0)
|
||||
{
|
||||
destroy_reference_impl(p, (T(*)())0);
|
||||
}
|
||||
|
||||
}}} // namespace boost::python::detail
|
||||
|
||||
#endif // DESTROY_DWA2002221_HPP
|
||||
@@ -1,4 +1,4 @@
|
||||
// (C) Copyright David Abrahams 2000. Permission to copy, use, modify, sell and
|
||||
// (C) Copyright David Abrahams 2001. Permission to copy, use, modify, sell and
|
||||
// distribute this software is granted provided this copyright notice appears
|
||||
// in all copies. This software is provided "as is" without express or implied
|
||||
// warranty, and with no claim as to its suitability for any purpose.
|
||||
@@ -26,7 +26,7 @@
|
||||
# include <memory>
|
||||
# include <boost/python/detail/init_function.hpp>
|
||||
# include <typeinfo>
|
||||
# include <boost/smart_ptr.hpp>
|
||||
# include <boost/shared_ptr.hpp>
|
||||
# include <boost/type_traits.hpp>
|
||||
|
||||
namespace boost { namespace python {
|
||||
@@ -38,26 +38,51 @@ template <class T> struct right_operand;
|
||||
|
||||
enum without_downcast_t { without_downcast };
|
||||
|
||||
namespace detail {
|
||||
namespace detail
|
||||
{
|
||||
|
||||
// forward declarations
|
||||
class extension_instance;
|
||||
class extension_class_base;
|
||||
template <class T> class instance_holder;
|
||||
template <class T, class U> class instance_value_holder;
|
||||
template <class ref, class T> class instance_ptr_holder;
|
||||
template <class Specified> struct operand_select;
|
||||
class extension_instance;
|
||||
class extension_class_base;
|
||||
template <class T> class instance_holder;
|
||||
template <class T, class U> class instance_value_holder;
|
||||
template <class ref, class T> class instance_ptr_holder;
|
||||
template <class Specified> struct operand_select;
|
||||
template <long> struct choose_op;
|
||||
template <long> struct choose_rop;
|
||||
template <long> struct choose_unary_op;
|
||||
template <long> struct define_operator;
|
||||
|
||||
meta_class<extension_instance>* extension_meta_class();
|
||||
extension_instance* get_extension_instance(PyObject* p);
|
||||
void report_missing_instance_data(extension_instance*, class_t<extension_instance>*, const std::type_info&);
|
||||
void report_missing_ptr_data(extension_instance*, class_t<extension_instance>*, const std::type_info&);
|
||||
void report_missing_class_object(const std::type_info&);
|
||||
void report_released_smart_pointer(const std::type_info&);
|
||||
class BOOST_PYTHON_DECL extension_instance : public instance
|
||||
{
|
||||
public:
|
||||
extension_instance(PyTypeObject* class_);
|
||||
~extension_instance();
|
||||
|
||||
void add_implementation(std::auto_ptr<instance_holder_base> holder);
|
||||
|
||||
typedef std::vector<instance_holder_base*> held_objects;
|
||||
const held_objects& wrapped_objects() const
|
||||
{ return m_wrapped_objects; }
|
||||
private:
|
||||
held_objects m_wrapped_objects;
|
||||
};
|
||||
|
||||
} // namespace detail
|
||||
|
||||
# ifndef BOOST_PYTHON_NO_TEMPLATE_EXPORT
|
||||
BOOST_PYTHON_EXPORT_TEMPLATE_CLASS class_t<detail::extension_instance>;
|
||||
BOOST_PYTHON_EXPORT_TEMPLATE_CLASS meta_class<detail::extension_instance>;
|
||||
# endif
|
||||
|
||||
namespace detail {
|
||||
|
||||
BOOST_PYTHON_DECL meta_class<extension_instance>* extension_meta_class();
|
||||
BOOST_PYTHON_DECL extension_instance* get_extension_instance(PyObject* p);
|
||||
BOOST_PYTHON_DECL void report_missing_instance_data(extension_instance*, class_t<extension_instance>*, const std::type_info&);
|
||||
BOOST_PYTHON_DECL void report_missing_ptr_data(extension_instance*, class_t<extension_instance>*, const std::type_info&);
|
||||
BOOST_PYTHON_DECL void report_missing_class_object(const std::type_info&);
|
||||
BOOST_PYTHON_DECL void report_released_smart_pointer(const std::type_info&);
|
||||
|
||||
template <class T>
|
||||
T* check_non_null(T* p)
|
||||
@@ -71,7 +96,7 @@ template <class Held> class held_instance;
|
||||
|
||||
typedef void* (*conversion_function_ptr)(void*);
|
||||
|
||||
struct base_class_info
|
||||
struct BOOST_PYTHON_DECL base_class_info
|
||||
{
|
||||
base_class_info(extension_class_base* t, conversion_function_ptr f)
|
||||
:class_object(t), convert(f)
|
||||
@@ -85,7 +110,7 @@ typedef base_class_info derived_class_info;
|
||||
|
||||
struct add_operator_base;
|
||||
|
||||
class extension_class_base : public class_t<extension_instance>
|
||||
class BOOST_PYTHON_DECL extension_class_base : public class_t<extension_instance>
|
||||
{
|
||||
public:
|
||||
extension_class_base(const char* name);
|
||||
@@ -378,7 +403,7 @@ namespace detail {
|
||||
|
||||
template <class T> class instance_holder;
|
||||
|
||||
class read_only_setattr_function : public function
|
||||
class BOOST_PYTHON_DECL read_only_setattr_function : public function
|
||||
{
|
||||
public:
|
||||
read_only_setattr_function(const char* name);
|
||||
@@ -702,30 +727,85 @@ class held_instance : public Held
|
||||
public:
|
||||
held_instance(PyObject*) : Held() {}
|
||||
template <class A1>
|
||||
held_instance(PyObject*, A1 a1) : Held(a1) {}
|
||||
held_instance(PyObject*, A1 a1) : Held(
|
||||
typename unwrap_parameter<A1>::type(a1)) {}
|
||||
template <class A1, class A2>
|
||||
held_instance(PyObject*, A1 a1, A2 a2) : Held(a1, a2) {}
|
||||
held_instance(PyObject*, A1 a1, A2 a2) : Held(
|
||||
typename unwrap_parameter<A1>::type(a1)
|
||||
, typename unwrap_parameter<A2>::type(a2)) {}
|
||||
template <class A1, class A2, class A3>
|
||||
held_instance(PyObject*, A1 a1, A2 a2, A3 a3) : Held(a1, a2, a3) {}
|
||||
held_instance(PyObject*, A1 a1, A2 a2, A3 a3) : Held(
|
||||
typename unwrap_parameter<A1>::type(a1)
|
||||
, typename unwrap_parameter<A2>::type(a2)
|
||||
, typename unwrap_parameter<A3>::type(a3)) {}
|
||||
template <class A1, class A2, class A3, class A4>
|
||||
held_instance(PyObject*, A1 a1, A2 a2, A3 a3, A4 a4) : Held(a1, a2, a3, a4) {}
|
||||
held_instance(PyObject*, A1 a1, A2 a2, A3 a3, A4 a4) : Held(
|
||||
typename unwrap_parameter<A1>::type(a1)
|
||||
, typename unwrap_parameter<A2>::type(a2)
|
||||
, typename unwrap_parameter<A3>::type(a3)
|
||||
, typename unwrap_parameter<A4>::type(a4)) {}
|
||||
template <class A1, class A2, class A3, class A4, class A5>
|
||||
held_instance(PyObject*, A1 a1, A2 a2, A3 a3, A4 a4, A5 a5) : Held(a1, a2, a3, a4, a5) {}
|
||||
held_instance(PyObject*, A1 a1, A2 a2, A3 a3, A4 a4, A5 a5) : Held(
|
||||
typename unwrap_parameter<A1>::type(a1)
|
||||
, typename unwrap_parameter<A2>::type(a2)
|
||||
, typename unwrap_parameter<A3>::type(a3)
|
||||
, typename unwrap_parameter<A4>::type(a4)
|
||||
, typename unwrap_parameter<A5>::type(a5)) {}
|
||||
template <class A1, class A2, class A3, class A4, class A5, class A6>
|
||||
held_instance(PyObject*, A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6) : Held(a1, a2, a3, a4, a5, a6) {}
|
||||
held_instance(PyObject*, A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6) : Held(
|
||||
typename unwrap_parameter<A1>::type(a1)
|
||||
, typename unwrap_parameter<A2>::type(a2)
|
||||
, typename unwrap_parameter<A3>::type(a3)
|
||||
, typename unwrap_parameter<A4>::type(a4)
|
||||
, typename unwrap_parameter<A5>::type(a5)
|
||||
, typename unwrap_parameter<A6>::type(a6)) {}
|
||||
template <class A1, class A2, class A3, class A4, class A5, class A6, class A7>
|
||||
held_instance(PyObject*, A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7) : Held(a1, a2, a3, a4, a5, a6, a7) {}
|
||||
held_instance(PyObject*, A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7) : Held(
|
||||
typename unwrap_parameter<A1>::type(a1)
|
||||
, typename unwrap_parameter<A2>::type(a2)
|
||||
, typename unwrap_parameter<A3>::type(a3)
|
||||
, typename unwrap_parameter<A4>::type(a4)
|
||||
, typename unwrap_parameter<A5>::type(a5)
|
||||
, typename unwrap_parameter<A6>::type(a6)
|
||||
, typename unwrap_parameter<A7>::type(a7)) {}
|
||||
template <class A1, class A2, class A3, class A4, class A5, class A6, class A7, class A8>
|
||||
held_instance(PyObject*, A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, A8 a8) : Held(a1, a2, a3, a4, a5, a6, a7, a8) {}
|
||||
held_instance(PyObject*, A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, A8 a8) : Held(
|
||||
typename unwrap_parameter<A1>::type(a1)
|
||||
, typename unwrap_parameter<A2>::type(a2)
|
||||
, typename unwrap_parameter<A3>::type(a3)
|
||||
, typename unwrap_parameter<A4>::type(a4)
|
||||
, typename unwrap_parameter<A5>::type(a5)
|
||||
, typename unwrap_parameter<A6>::type(a6)
|
||||
, typename unwrap_parameter<A7>::type(a7)
|
||||
, typename unwrap_parameter<A8>::type(a8)) {}
|
||||
template <class A1, class A2, class A3, class A4, class A5, class A6, class A7, class A8, class A9>
|
||||
held_instance(PyObject*, A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, A8 a8, A9 a9) : Held(a1, a2, a3, a4, a5, a6, a7, a8, a9) {}
|
||||
held_instance(PyObject*, A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, A8 a8, A9 a9) : Held(
|
||||
typename unwrap_parameter<A1>::type(a1)
|
||||
, typename unwrap_parameter<A2>::type(a2)
|
||||
, typename unwrap_parameter<A3>::type(a3)
|
||||
, typename unwrap_parameter<A4>::type(a4)
|
||||
, typename unwrap_parameter<A5>::type(a5)
|
||||
, typename unwrap_parameter<A6>::type(a6)
|
||||
, typename unwrap_parameter<A7>::type(a7)
|
||||
, typename unwrap_parameter<A8>::type(a8)
|
||||
, typename unwrap_parameter<A9>::type(a9)) {}
|
||||
template <class A1, class A2, class A3, class A4, class A5, class A6, class A7, class A8, class A9, class A10>
|
||||
held_instance(PyObject*, A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, A8 a8, A9 a9, A10 a10) : Held(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10) {}
|
||||
held_instance(PyObject*, A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, A8 a8, A9 a9, A10 a10) : Held(
|
||||
typename unwrap_parameter<A1>::type(a1)
|
||||
, typename unwrap_parameter<A2>::type(a2)
|
||||
, typename unwrap_parameter<A3>::type(a3)
|
||||
, typename unwrap_parameter<A4>::type(a4)
|
||||
, typename unwrap_parameter<A5>::type(a5)
|
||||
, typename unwrap_parameter<A6>::type(a6)
|
||||
, typename unwrap_parameter<A7>::type(a7)
|
||||
, typename unwrap_parameter<A8>::type(a8)
|
||||
, typename unwrap_parameter<A9>::type(a9)
|
||||
, typename unwrap_parameter<A10>::type(a10)) {}
|
||||
};
|
||||
|
||||
// Abstract base class for all obj holders. Base for template class
|
||||
// instance_holder<>, below.
|
||||
class instance_holder_base
|
||||
class BOOST_PYTHON_DECL instance_holder_base
|
||||
{
|
||||
public:
|
||||
virtual ~instance_holder_base() {}
|
||||
@@ -813,21 +893,6 @@ class instance_ptr_holder : public instance_holder<HeldType>
|
||||
PtrType m_ptr;
|
||||
};
|
||||
|
||||
class extension_instance : public instance
|
||||
{
|
||||
public:
|
||||
extension_instance(PyTypeObject* class_);
|
||||
~extension_instance();
|
||||
|
||||
void add_implementation(std::auto_ptr<instance_holder_base> holder);
|
||||
|
||||
typedef std::vector<instance_holder_base*> held_objects;
|
||||
const held_objects& wrapped_objects() const
|
||||
{ return m_wrapped_objects; }
|
||||
private:
|
||||
held_objects m_wrapped_objects;
|
||||
};
|
||||
|
||||
//
|
||||
// Template function implementations
|
||||
//
|
||||
|
||||
@@ -29,7 +29,7 @@ class extension_instance;
|
||||
// function --
|
||||
// the common base class for all overloadable function and method objects
|
||||
// supplied by the library.
|
||||
class function : public python_object
|
||||
class BOOST_PYTHON_DECL function : public python_object
|
||||
{
|
||||
public:
|
||||
function();
|
||||
@@ -201,7 +201,7 @@ inline function* new_virtual_function(
|
||||
// the expression a.b where a is an instance or extension_instance object and b
|
||||
// is a callable object not found in the obj namespace but on its class or
|
||||
// a base class.
|
||||
class bound_function : public python_object
|
||||
class BOOST_PYTHON_DECL bound_function : public python_object
|
||||
{
|
||||
public:
|
||||
static bound_function* create(const ref& target, const ref& fn);
|
||||
|
||||
175
include/boost/python/detail/indirect_traits.hpp
Normal file
175
include/boost/python/detail/indirect_traits.hpp
Normal file
@@ -0,0 +1,175 @@
|
||||
// Copyright David Abrahams 2002. Permission to copy, use,
|
||||
// modify, sell and distribute this software is granted provided this
|
||||
// copyright notice appears in all copies. This software is provided
|
||||
// "as is" without express or implied warranty, and with no claim as
|
||||
// to its suitability for any purpose.
|
||||
#ifndef INDIRECT_TRAITS_DWA2002131_HPP
|
||||
# define INDIRECT_TRAITS_DWA2002131_HPP
|
||||
# include <boost/type_traits/cv_traits.hpp>
|
||||
# include <boost/type_traits/composite_traits.hpp>
|
||||
# include <boost/mpl/select_type.hpp>
|
||||
|
||||
namespace boost { namespace python { namespace detail {
|
||||
|
||||
# ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
|
||||
template <class T>
|
||||
struct is_reference_to_const
|
||||
{
|
||||
BOOST_STATIC_CONSTANT(bool, value = false);
|
||||
};
|
||||
|
||||
template <class T>
|
||||
struct is_reference_to_const<T const&>
|
||||
{
|
||||
BOOST_STATIC_CONSTANT(bool, value = true);
|
||||
};
|
||||
|
||||
template <class T>
|
||||
struct is_reference_to_non_const
|
||||
{
|
||||
BOOST_STATIC_CONSTANT(
|
||||
bool, value = (
|
||||
::boost::type_traits::ice_and<
|
||||
::boost::is_reference<T>::value
|
||||
, ::boost::type_traits::ice_not<
|
||||
::boost::python::detail::is_reference_to_const<T>::value>::value
|
||||
>::value)
|
||||
);
|
||||
};
|
||||
|
||||
template <class T>
|
||||
struct is_reference_to_volatile
|
||||
{
|
||||
BOOST_STATIC_CONSTANT(bool, value = false);
|
||||
};
|
||||
|
||||
template <class T>
|
||||
struct is_reference_to_volatile<T volatile&>
|
||||
{
|
||||
BOOST_STATIC_CONSTANT(bool, value = true);
|
||||
};
|
||||
|
||||
template <class T>
|
||||
struct is_reference_to_pointer
|
||||
{
|
||||
BOOST_STATIC_CONSTANT(bool, value = false);
|
||||
};
|
||||
|
||||
template <class T>
|
||||
struct is_reference_to_pointer<T*&>
|
||||
{
|
||||
BOOST_STATIC_CONSTANT(bool, value = true);
|
||||
};
|
||||
|
||||
template <class T>
|
||||
struct is_reference_to_pointer<T* const&>
|
||||
{
|
||||
BOOST_STATIC_CONSTANT(bool, value = true);
|
||||
};
|
||||
|
||||
template <class T>
|
||||
struct is_reference_to_pointer<T* volatile&>
|
||||
{
|
||||
BOOST_STATIC_CONSTANT(bool, value = true);
|
||||
};
|
||||
|
||||
template <class T>
|
||||
struct is_reference_to_pointer<T* const volatile&>
|
||||
{
|
||||
BOOST_STATIC_CONSTANT(bool, value = true);
|
||||
};
|
||||
# else
|
||||
|
||||
typedef char (&inner_yes_type)[3];
|
||||
typedef char (&inner_no_type)[2];
|
||||
typedef char (&outer_no_type)[1];
|
||||
|
||||
template <typename V>
|
||||
struct is_const_help
|
||||
{
|
||||
typedef typename mpl::select_type<
|
||||
is_const<V>::value
|
||||
, inner_yes_type
|
||||
, inner_no_type
|
||||
>::type type;
|
||||
};
|
||||
|
||||
template <typename V>
|
||||
struct is_volatile_help
|
||||
{
|
||||
typedef typename mpl::select_type<
|
||||
is_volatile<V>::value
|
||||
, inner_yes_type
|
||||
, inner_no_type
|
||||
>::type type;
|
||||
};
|
||||
|
||||
template <typename V>
|
||||
struct is_pointer_help
|
||||
{
|
||||
typedef typename mpl::select_type<
|
||||
is_pointer<V>::value
|
||||
, inner_yes_type
|
||||
, inner_no_type
|
||||
>::type type;
|
||||
};
|
||||
|
||||
template <typename V>
|
||||
typename is_const_help<V>::type reference_to_const_helper(V&);
|
||||
outer_no_type
|
||||
reference_to_const_helper(...);
|
||||
|
||||
template <class T>
|
||||
struct is_reference_to_const
|
||||
{
|
||||
static T t;
|
||||
BOOST_STATIC_CONSTANT(
|
||||
bool, value
|
||||
= (is_reference<T>::value
|
||||
&& sizeof(reference_to_const_helper(t)) == sizeof(inner_yes_type)));
|
||||
};
|
||||
|
||||
template <class T>
|
||||
struct is_reference_to_non_const
|
||||
{
|
||||
static T t;
|
||||
BOOST_STATIC_CONSTANT(
|
||||
bool, value
|
||||
= (is_reference<T>::value
|
||||
&& sizeof(reference_to_const_helper(t)) == sizeof(inner_no_type)));
|
||||
};
|
||||
|
||||
template <typename V>
|
||||
typename is_volatile_help<V>::type reference_to_volatile_helper(V&);
|
||||
outer_no_type reference_to_volatile_helper(...);
|
||||
|
||||
template <class T>
|
||||
struct is_reference_to_volatile
|
||||
{
|
||||
static T t;
|
||||
BOOST_STATIC_CONSTANT(
|
||||
bool, value
|
||||
= (is_reference<T>::value
|
||||
&& sizeof(reference_to_volatile_helper(t)) == sizeof(inner_yes_type)));
|
||||
};
|
||||
|
||||
|
||||
template <typename V>
|
||||
typename is_pointer_help<V>::type reference_to_pointer_helper(V&);
|
||||
outer_no_type reference_to_pointer_helper(...);
|
||||
|
||||
template <class T>
|
||||
struct is_reference_to_pointer
|
||||
{
|
||||
static T t;
|
||||
BOOST_STATIC_CONSTANT(
|
||||
bool, value
|
||||
= (is_reference<T>::value
|
||||
&& sizeof(reference_to_pointer_helper(t)) == sizeof(inner_yes_type))
|
||||
);
|
||||
};
|
||||
# endif // BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
|
||||
|
||||
}}} // namespace boost::python::detail
|
||||
|
||||
#endif // INDIRECT_TRAITS_DWA2002131_HPP
|
||||
@@ -1,4 +1,4 @@
|
||||
// (C) Copyright David Abrahams 2000. Permission to copy, use, modify, sell and
|
||||
// (C) Copyright David Abrahams 2001. Permission to copy, use, modify, sell and
|
||||
// distribute this software is granted provided this copyright notice appears
|
||||
// in all copies. This software is provided "as is" without express or implied
|
||||
// warranty, and with no claim as to its suitability for any purpose.
|
||||
@@ -89,11 +89,14 @@ namespace detail {
|
||||
typedef void const_reference;
|
||||
};
|
||||
|
||||
struct reference_parameter_base {};
|
||||
|
||||
template <class T>
|
||||
class reference_parameter
|
||||
: public reference_parameter_base
|
||||
{
|
||||
typedef typename parameter_traits<T>::const_reference const_reference;
|
||||
public:
|
||||
typedef typename parameter_traits<T>::const_reference const_reference;
|
||||
reference_parameter(const_reference value)
|
||||
: value(value) {}
|
||||
operator const_reference() { return value; }
|
||||
@@ -101,6 +104,51 @@ namespace detail {
|
||||
const_reference value;
|
||||
};
|
||||
|
||||
# ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
|
||||
template <class T>
|
||||
struct unwrap_parameter
|
||||
{
|
||||
typedef typename boost::add_reference<T>::type type;
|
||||
};
|
||||
|
||||
template <class T>
|
||||
struct unwrap_parameter<reference_parameter<T> >
|
||||
{
|
||||
typedef typename reference_parameter<T>::const_reference type;
|
||||
};
|
||||
# else
|
||||
template <bool is_wrapped>
|
||||
struct unwrap_parameter_helper
|
||||
{
|
||||
template <class T>
|
||||
struct apply
|
||||
{
|
||||
typedef typename T::const_reference type;
|
||||
};
|
||||
};
|
||||
|
||||
template <>
|
||||
struct unwrap_parameter_helper<false>
|
||||
{
|
||||
template <class T>
|
||||
struct apply
|
||||
{
|
||||
typedef typename add_reference<T>::type type;
|
||||
};
|
||||
};
|
||||
|
||||
template <class T>
|
||||
struct unwrap_parameter
|
||||
{
|
||||
BOOST_STATIC_CONSTANT(
|
||||
bool, is_wrapped = (is_base_and_derived<T,reference_parameter_base>::value));
|
||||
|
||||
typedef typename unwrap_parameter_helper<
|
||||
is_wrapped
|
||||
>::template apply<T>::type type;
|
||||
};
|
||||
# endif
|
||||
|
||||
class extension_instance;
|
||||
class instance_holder_base;
|
||||
|
||||
@@ -120,6 +168,9 @@ template <class T, class A1, class A2, class A3, class A4, class A5, class A6, c
|
||||
template <class T>
|
||||
struct init_function
|
||||
{
|
||||
# ifdef BOOST_MSVC6_OR_EARLIER
|
||||
# define typename
|
||||
# endif
|
||||
static init* create(signature0) {
|
||||
return new init0<T>;
|
||||
}
|
||||
@@ -127,110 +178,113 @@ struct init_function
|
||||
template <class A1>
|
||||
static init* create(signature1<A1>) {
|
||||
return new init1<T,
|
||||
detail::parameter_traits<A1>::const_reference>;
|
||||
typename detail::parameter_traits<A1>::const_reference>;
|
||||
}
|
||||
|
||||
template <class A1, class A2>
|
||||
static init* create(signature2<A1, A2>) {
|
||||
return new init2<T,
|
||||
detail::parameter_traits<A1>::const_reference,
|
||||
detail::parameter_traits<A2>::const_reference>;
|
||||
typename detail::parameter_traits<A1>::const_reference,
|
||||
typename detail::parameter_traits<A2>::const_reference>;
|
||||
}
|
||||
|
||||
template <class A1, class A2, class A3>
|
||||
static init* create(signature3<A1, A2, A3>) {
|
||||
return new init3<T,
|
||||
detail::parameter_traits<A1>::const_reference,
|
||||
detail::parameter_traits<A2>::const_reference,
|
||||
detail::parameter_traits<A3>::const_reference>;
|
||||
typename detail::parameter_traits<A1>::const_reference,
|
||||
typename detail::parameter_traits<A2>::const_reference,
|
||||
typename detail::parameter_traits<A3>::const_reference>;
|
||||
}
|
||||
|
||||
template <class A1, class A2, class A3, class A4>
|
||||
static init* create(signature4<A1, A2, A3, A4>) {
|
||||
return new init4<T,
|
||||
detail::parameter_traits<A1>::const_reference,
|
||||
detail::parameter_traits<A2>::const_reference,
|
||||
detail::parameter_traits<A3>::const_reference,
|
||||
detail::parameter_traits<A4>::const_reference>;
|
||||
typename detail::parameter_traits<A1>::const_reference,
|
||||
typename detail::parameter_traits<A2>::const_reference,
|
||||
typename detail::parameter_traits<A3>::const_reference,
|
||||
typename detail::parameter_traits<A4>::const_reference>;
|
||||
}
|
||||
|
||||
template <class A1, class A2, class A3, class A4, class A5>
|
||||
static init* create(signature5<A1, A2, A3, A4, A5>) {
|
||||
return new init5<T,
|
||||
detail::parameter_traits<A1>::const_reference,
|
||||
detail::parameter_traits<A2>::const_reference,
|
||||
detail::parameter_traits<A3>::const_reference,
|
||||
detail::parameter_traits<A4>::const_reference,
|
||||
detail::parameter_traits<A5>::const_reference>;
|
||||
typename detail::parameter_traits<A1>::const_reference,
|
||||
typename detail::parameter_traits<A2>::const_reference,
|
||||
typename detail::parameter_traits<A3>::const_reference,
|
||||
typename detail::parameter_traits<A4>::const_reference,
|
||||
typename detail::parameter_traits<A5>::const_reference>;
|
||||
}
|
||||
|
||||
template <class A1, class A2, class A3, class A4, class A5, class A6>
|
||||
static init* create(signature6<A1, A2, A3, A4, A5, A6>) {
|
||||
return new init6<T,
|
||||
detail::parameter_traits<A1>::const_reference,
|
||||
detail::parameter_traits<A2>::const_reference,
|
||||
detail::parameter_traits<A3>::const_reference,
|
||||
detail::parameter_traits<A4>::const_reference,
|
||||
detail::parameter_traits<A5>::const_reference,
|
||||
detail::parameter_traits<A6>::const_reference>;
|
||||
typename detail::parameter_traits<A1>::const_reference,
|
||||
typename detail::parameter_traits<A2>::const_reference,
|
||||
typename detail::parameter_traits<A3>::const_reference,
|
||||
typename detail::parameter_traits<A4>::const_reference,
|
||||
typename detail::parameter_traits<A5>::const_reference,
|
||||
typename detail::parameter_traits<A6>::const_reference>;
|
||||
}
|
||||
|
||||
template <class A1, class A2, class A3, class A4, class A5, class A6, class A7>
|
||||
static init* create(signature7<A1, A2, A3, A4, A5, A6, A7>) {
|
||||
return new init7<T,
|
||||
detail::parameter_traits<A1>::const_reference,
|
||||
detail::parameter_traits<A2>::const_reference,
|
||||
detail::parameter_traits<A3>::const_reference,
|
||||
detail::parameter_traits<A4>::const_reference,
|
||||
detail::parameter_traits<A5>::const_reference,
|
||||
detail::parameter_traits<A6>::const_reference,
|
||||
detail::parameter_traits<A7>::const_reference>;
|
||||
typename detail::parameter_traits<A1>::const_reference,
|
||||
typename detail::parameter_traits<A2>::const_reference,
|
||||
typename detail::parameter_traits<A3>::const_reference,
|
||||
typename detail::parameter_traits<A4>::const_reference,
|
||||
typename detail::parameter_traits<A5>::const_reference,
|
||||
typename detail::parameter_traits<A6>::const_reference,
|
||||
typename detail::parameter_traits<A7>::const_reference>;
|
||||
}
|
||||
|
||||
template <class A1, class A2, class A3, class A4, class A5, class A6, class A7, class A8>
|
||||
static init* create(signature8<A1, A2, A3, A4, A5, A6, A7, A8>) {
|
||||
return new init8<T,
|
||||
detail::parameter_traits<A1>::const_reference,
|
||||
detail::parameter_traits<A2>::const_reference,
|
||||
detail::parameter_traits<A3>::const_reference,
|
||||
detail::parameter_traits<A4>::const_reference,
|
||||
detail::parameter_traits<A5>::const_reference,
|
||||
detail::parameter_traits<A6>::const_reference,
|
||||
detail::parameter_traits<A7>::const_reference,
|
||||
detail::parameter_traits<A8>::const_reference>;
|
||||
typename detail::parameter_traits<A1>::const_reference,
|
||||
typename detail::parameter_traits<A2>::const_reference,
|
||||
typename detail::parameter_traits<A3>::const_reference,
|
||||
typename detail::parameter_traits<A4>::const_reference,
|
||||
typename detail::parameter_traits<A5>::const_reference,
|
||||
typename detail::parameter_traits<A6>::const_reference,
|
||||
typename detail::parameter_traits<A7>::const_reference,
|
||||
typename detail::parameter_traits<A8>::const_reference>;
|
||||
}
|
||||
|
||||
template <class A1, class A2, class A3, class A4, class A5, class A6, class A7, class A8, class A9>
|
||||
static init* create(signature9<A1, A2, A3, A4, A5, A6, A7, A8, A9>) {
|
||||
return new init9<T,
|
||||
detail::parameter_traits<A1>::const_reference,
|
||||
detail::parameter_traits<A2>::const_reference,
|
||||
detail::parameter_traits<A3>::const_reference,
|
||||
detail::parameter_traits<A4>::const_reference,
|
||||
detail::parameter_traits<A5>::const_reference,
|
||||
detail::parameter_traits<A6>::const_reference,
|
||||
detail::parameter_traits<A7>::const_reference,
|
||||
detail::parameter_traits<A8>::const_reference,
|
||||
detail::parameter_traits<A9>::const_reference>;
|
||||
typename detail::parameter_traits<A1>::const_reference,
|
||||
typename detail::parameter_traits<A2>::const_reference,
|
||||
typename detail::parameter_traits<A3>::const_reference,
|
||||
typename detail::parameter_traits<A4>::const_reference,
|
||||
typename detail::parameter_traits<A5>::const_reference,
|
||||
typename detail::parameter_traits<A6>::const_reference,
|
||||
typename detail::parameter_traits<A7>::const_reference,
|
||||
typename detail::parameter_traits<A8>::const_reference,
|
||||
typename detail::parameter_traits<A9>::const_reference>;
|
||||
}
|
||||
|
||||
template <class A1, class A2, class A3, class A4, class A5, class A6, class A7, class A8, class A9, class A10>
|
||||
static init* create(signature10<A1, A2, A3, A4, A5, A6, A7, A8, A9, A10>) {
|
||||
return new init10<T,
|
||||
detail::parameter_traits<A1>::const_reference,
|
||||
detail::parameter_traits<A2>::const_reference,
|
||||
detail::parameter_traits<A3>::const_reference,
|
||||
detail::parameter_traits<A4>::const_reference,
|
||||
detail::parameter_traits<A5>::const_reference,
|
||||
detail::parameter_traits<A6>::const_reference,
|
||||
detail::parameter_traits<A7>::const_reference,
|
||||
detail::parameter_traits<A8>::const_reference,
|
||||
detail::parameter_traits<A9>::const_reference,
|
||||
detail::parameter_traits<A10>::const_reference>;
|
||||
typename detail::parameter_traits<A1>::const_reference,
|
||||
typename detail::parameter_traits<A2>::const_reference,
|
||||
typename detail::parameter_traits<A3>::const_reference,
|
||||
typename detail::parameter_traits<A4>::const_reference,
|
||||
typename detail::parameter_traits<A5>::const_reference,
|
||||
typename detail::parameter_traits<A6>::const_reference,
|
||||
typename detail::parameter_traits<A7>::const_reference,
|
||||
typename detail::parameter_traits<A8>::const_reference,
|
||||
typename detail::parameter_traits<A9>::const_reference,
|
||||
typename detail::parameter_traits<A10>::const_reference>;
|
||||
}
|
||||
#ifdef BOOST_MSVC6_OR_EARLIER
|
||||
# undef typename
|
||||
#endif
|
||||
};
|
||||
|
||||
class init : public function
|
||||
class BOOST_PYTHON_DECL init : public function
|
||||
{
|
||||
private: // override function hook
|
||||
PyObject* do_call(PyObject* args, PyObject* keywords) const;
|
||||
|
||||
44
include/boost/python/detail/map_entry.hpp
Normal file
44
include/boost/python/detail/map_entry.hpp
Normal file
@@ -0,0 +1,44 @@
|
||||
// Copyright David Abrahams 2002. Permission to copy, use,
|
||||
// modify, sell and distribute this software is granted provided this
|
||||
// copyright notice appears in all copies. This software is provided
|
||||
// "as is" without express or implied warranty, and with no claim as
|
||||
// to its suitability for any purpose.
|
||||
#ifndef MAP_ENTRY_DWA2002118_HPP
|
||||
# define MAP_ENTRY_DWA2002118_HPP
|
||||
|
||||
namespace boost { namespace python { namespace detail {
|
||||
|
||||
// A trivial type that works well as the value_type of associative
|
||||
// vector maps
|
||||
template <class Key, class Value>
|
||||
struct map_entry
|
||||
{
|
||||
map_entry() {}
|
||||
map_entry(Key k) : key(k), value() {}
|
||||
map_entry(Key k, Value v) : key(k), value(v) {}
|
||||
|
||||
bool operator<(map_entry const& rhs) const
|
||||
{
|
||||
return this->key < rhs.key;
|
||||
}
|
||||
|
||||
Key key;
|
||||
Value value;
|
||||
};
|
||||
|
||||
template <class Key, class Value>
|
||||
bool operator<(map_entry<Key,Value> const& e, Key const& k)
|
||||
{
|
||||
return e.key < k;
|
||||
}
|
||||
|
||||
template <class Key, class Value>
|
||||
bool operator<(Key const& k, map_entry<Key,Value> const& e)
|
||||
{
|
||||
return k < e.key;
|
||||
}
|
||||
|
||||
|
||||
}}} // namespace boost::python::detail
|
||||
|
||||
#endif // MAP_ENTRY_DWA2002118_HPP
|
||||
239
include/boost/python/detail/member_function_cast.hpp
Normal file
239
include/boost/python/detail/member_function_cast.hpp
Normal file
@@ -0,0 +1,239 @@
|
||||
// Copyright David Abrahams 2002. Permission to copy, use,
|
||||
// modify, sell and distribute this software is granted provided this
|
||||
// copyright notice appears in all copies. This software is provided
|
||||
// "as is" without express or implied warranty, and with no claim as
|
||||
// to its suitability for any purpose.
|
||||
#ifndef MEMBER_FUNCTION_CAST_DWA2002311_HPP
|
||||
# define MEMBER_FUNCTION_CAST_DWA2002311_HPP
|
||||
# include <boost/mpl/select_type.hpp>
|
||||
# include <boost/type_traits/composite_traits.hpp>
|
||||
|
||||
namespace boost { namespace python { namespace detail {
|
||||
|
||||
template <class S, class FT>
|
||||
struct cast_helper
|
||||
{
|
||||
struct yes_helper
|
||||
{
|
||||
static FT stage3(FT x) { return x; }
|
||||
};
|
||||
|
||||
struct no_helper
|
||||
{
|
||||
template <class T>
|
||||
static T stage3(T x) { return x; }
|
||||
};
|
||||
|
||||
static yes_helper stage2(S*) { return yes_helper(); }
|
||||
static no_helper stage2(void*) { return no_helper(); }
|
||||
};
|
||||
|
||||
struct non_member_function_cast_impl
|
||||
{
|
||||
template <class T>
|
||||
static non_member_function_cast_impl stage1(T) { return non_member_function_cast_impl(); }
|
||||
|
||||
template <class T>
|
||||
static non_member_function_cast_impl stage2(T) { return non_member_function_cast_impl(); }
|
||||
|
||||
template <class T>
|
||||
T stage3(T x) { return x; }
|
||||
};
|
||||
|
||||
template <class T>
|
||||
struct member_function_cast_impl
|
||||
{
|
||||
# ifndef BOOST_NO_FUNCTION_TEMPLATE_ORDERING
|
||||
template <class U>
|
||||
static non_member_function_cast_impl stage1(U)
|
||||
{
|
||||
return non_member_function_cast_impl();
|
||||
}
|
||||
# endif
|
||||
template <class S, class R>
|
||||
static cast_helper<S,R(T::*)()> stage1(R (S::*)())
|
||||
{
|
||||
return cast_helper<S,R(T::*)()>();
|
||||
}
|
||||
|
||||
template <class S, class R, class A0>
|
||||
static cast_helper<S,R(T::*)(A0)> stage1(R (S::*)(A0))
|
||||
{
|
||||
return cast_helper<S,R(T::*)(A0)>();
|
||||
}
|
||||
|
||||
template <class S, class R, class A0, class A1>
|
||||
static cast_helper<S,R(T::*)(A0,A1) > stage1(R (S::*)(A0,A1))
|
||||
{
|
||||
return cast_helper<R(S::*)(A0,A1),R(T::*)(A0,A1) >();
|
||||
}
|
||||
|
||||
template <class S, class R, class A0, class A1,class A2>
|
||||
static cast_helper<S,R(T::*)(A0,A1,A2) > stage1(R (S::*)(A0,A1,A2))
|
||||
{
|
||||
return cast_helper<R(S::*)(A0,A1,A2),R(T::*)(A0,A1,A2) >();
|
||||
}
|
||||
|
||||
template <class S, class R, class A0, class A1, class A2, class A3>
|
||||
static cast_helper<S,R(T::*)(A0,A1,A2,A3)> stage1(R (S::*)(A0,A1,A2,A3))
|
||||
{
|
||||
return cast_helper<S,R(T::*)(A0,A1,A2,A3)>();
|
||||
}
|
||||
|
||||
template <class S, class R, class A0, class A1, class A2, class A3, class A4>
|
||||
static cast_helper<S,R(T::*)(A0,A1,A2,A3,A4)> stage1(R (S::*)(A0,A1,A2,A3,A4))
|
||||
{
|
||||
return cast_helper<S,R(T::*)(A0,A1,A2,A3,A4)>();
|
||||
}
|
||||
|
||||
template <class S, class R, class A0, class A1, class A2, class A3, class A4, class A5>
|
||||
static cast_helper<S,R(T::*)(A0,A1,A2,A3,A4,A5)> stage1(R (S::*)(A0,A1,A2,A3,A4,A5))
|
||||
{
|
||||
return cast_helper<S,R(T::*)(A0,A1,A2,A3,A4,A5)>();
|
||||
}
|
||||
|
||||
template <class S, class R>
|
||||
static cast_helper<S,R(T::*)()const> stage1(R (S::*)()const)
|
||||
{
|
||||
return cast_helper<S,R(T::*)()const>();
|
||||
}
|
||||
|
||||
template <class S, class R, class A0>
|
||||
static cast_helper<S,R(T::*)(A0)const> stage1(R (S::*)(A0)const)
|
||||
{
|
||||
return cast_helper<S,R(T::*)(A0)const>();
|
||||
}
|
||||
|
||||
template <class S, class R, class A0, class A1>
|
||||
static cast_helper<S,R(T::*)(A0,A1)const> stage1(R (S::*)(A0,A1)const)
|
||||
{
|
||||
return cast_helper<S,R(T::*)(A0,A1)const>();
|
||||
}
|
||||
|
||||
template <class S, class R, class A0, class A1,class A2>
|
||||
static cast_helper<S,R(T::*)(A0,A1,A2)const> stage1(R (S::*)(A0,A1,A2)const)
|
||||
{
|
||||
return cast_helper<S,R(T::*)(A0,A1,A2)const>();
|
||||
}
|
||||
|
||||
template <class S, class R, class A0, class A1, class A2, class A3>
|
||||
static cast_helper<S,R(T::*)(A0,A1,A2,A3)const> stage1(R (S::*)(A0,A1,A2,A3)const)
|
||||
{
|
||||
return cast_helper<S,R(T::*)(A0,A1,A2,A3)const>();
|
||||
}
|
||||
|
||||
template <class S, class R, class A0, class A1, class A2, class A3, class A4>
|
||||
static cast_helper<S,R(T::*)(A0,A1,A2,A3,A4)const> stage1(R (S::*)(A0,A1,A2,A3,A4)const)
|
||||
{
|
||||
return cast_helper<S,R(T::*)(A0,A1,A2,A3,A4)const>();
|
||||
}
|
||||
|
||||
template <class S, class R, class A0, class A1, class A2, class A3, class A4, class A5>
|
||||
static cast_helper<S,R(T::*)(A0,A1,A2,A3,A4,A5)const> stage1(R (S::*)(A0,A1,A2,A3,A4,A5)const)
|
||||
{
|
||||
return cast_helper<S,R(T::*)(A0,A1,A2,A3,A4,A5)const>();
|
||||
}
|
||||
|
||||
template <class S, class R>
|
||||
static cast_helper<S,R(T::*)()volatile> stage1(R (S::*)()volatile)
|
||||
{
|
||||
return cast_helper<S,R(T::*)()volatile>();
|
||||
}
|
||||
|
||||
template <class S, class R, class A0>
|
||||
static cast_helper<S,R(T::*)(A0)volatile> stage1(R (S::*)(A0)volatile)
|
||||
{
|
||||
return cast_helper<S,R(T::*)(A0)volatile>();
|
||||
}
|
||||
|
||||
template <class S, class R, class A0, class A1>
|
||||
static cast_helper<S,R(T::*)(A0,A1)volatile> stage1(R (S::*)(A0,A1)volatile)
|
||||
{
|
||||
return cast_helper<S,R(T::*)(A0,A1)volatile>();
|
||||
}
|
||||
|
||||
template <class S, class R, class A0, class A1,class A2>
|
||||
static cast_helper<S,R(T::*)(A0,A1,A2)volatile> stage1(R (S::*)(A0,A1,A2)volatile)
|
||||
{
|
||||
return cast_helper<S,R(T::*)(A0,A1,A2)volatile>();
|
||||
}
|
||||
|
||||
template <class S, class R, class A0, class A1, class A2, class A3>
|
||||
static cast_helper<S,R(T::*)(A0,A1,A2,A3)volatile> stage1(R (S::*)(A0,A1,A2,A3)volatile)
|
||||
{
|
||||
return cast_helper<S,R(T::*)(A0,A1,A2,A3)volatile>();
|
||||
}
|
||||
|
||||
template <class S, class R, class A0, class A1, class A2, class A3, class A4>
|
||||
static cast_helper<S,R(T::*)(A0,A1,A2,A3,A4)volatile> stage1(R (S::*)(A0,A1,A2,A3,A4)volatile)
|
||||
{
|
||||
return cast_helper<S,R(T::*)(A0,A1,A2,A3,A4)volatile>();
|
||||
}
|
||||
|
||||
template <class S, class R, class A0, class A1, class A2, class A3, class A4, class A5>
|
||||
static cast_helper<S,R(T::*)(A0,A1,A2,A3,A4,A5)volatile> stage1(R (S::*)(A0,A1,A2,A3,A4,A5)volatile)
|
||||
{
|
||||
return cast_helper<S,R(T::*)(A0,A1,A2,A3,A4,A5)volatile>();
|
||||
}
|
||||
|
||||
template <class S, class R>
|
||||
static cast_helper<S,R(T::*)()const volatile> stage1(R (S::*)()const volatile)
|
||||
{
|
||||
return cast_helper<S,R(T::*)()const volatile>();
|
||||
}
|
||||
|
||||
template <class S, class R, class A0>
|
||||
static cast_helper<S,R(T::*)(A0)const volatile> stage1(R (S::*)(A0)const volatile)
|
||||
{
|
||||
return cast_helper<S,R(T::*)(A0)const volatile>();
|
||||
}
|
||||
|
||||
template <class S, class R, class A0, class A1>
|
||||
static cast_helper<S,R(T::*)(A0,A1)const volatile> stage1(R (S::*)(A0,A1)const volatile)
|
||||
{
|
||||
return cast_helper<S,R(T::*)(A0,A1)const volatile>();
|
||||
}
|
||||
|
||||
template <class S, class R, class A0, class A1,class A2>
|
||||
static cast_helper<S,R(T::*)(A0,A1,A2)const volatile> stage1(R (S::*)(A0,A1,A2)const volatile)
|
||||
{
|
||||
return cast_helper<S,R(T::*)(A0,A1,A2)const volatile>();
|
||||
}
|
||||
|
||||
template <class S, class R, class A0, class A1, class A2, class A3>
|
||||
static cast_helper<S,R(T::*)(A0,A1,A2,A3)const volatile> stage1(R (S::*)(A0,A1,A2,A3)const volatile)
|
||||
{
|
||||
return cast_helper<S,R(T::*)(A0,A1,A2,A3)const volatile>();
|
||||
}
|
||||
|
||||
template <class S, class R, class A0, class A1, class A2, class A3, class A4>
|
||||
static cast_helper<S,R(T::*)(A0,A1,A2,A3,A4)const volatile> stage1(R (S::*)(A0,A1,A2,A3,A4)const volatile)
|
||||
{
|
||||
return cast_helper<S,R(T::*)(A0,A1,A2,A3,A4)const volatile>();
|
||||
}
|
||||
|
||||
template <class S, class R, class A0, class A1, class A2, class A3, class A4, class A5>
|
||||
static cast_helper<S,R(T::*)(A0,A1,A2,A3,A4,A5)const volatile> stage1(R (S::*)(A0,A1,A2,A3,A4,A5)const volatile)
|
||||
{
|
||||
return cast_helper<S,R(T::*)(A0,A1,A2,A3,A4,A5)const volatile>();
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
template <class T, class SF>
|
||||
struct member_function_cast
|
||||
# ifndef BOOST_NO_FUNCTION_TEMPLATE_ORDERING
|
||||
: member_function_cast_impl<T>
|
||||
# else
|
||||
: mpl::select_type<
|
||||
is_member_function_pointer<SF>::value
|
||||
, member_function_cast_impl<T>
|
||||
, non_member_function_cast_impl
|
||||
>::type
|
||||
# endif
|
||||
{
|
||||
};
|
||||
|
||||
}}} // namespace boost::python::detail
|
||||
|
||||
#endif // MEMBER_FUNCTION_CAST_DWA2002311_HPP
|
||||
44
include/boost/python/detail/module_base.hpp
Normal file
44
include/boost/python/detail/module_base.hpp
Normal file
@@ -0,0 +1,44 @@
|
||||
// Copyright David Abrahams 2002. Permission to copy, use,
|
||||
// modify, sell and distribute this software is granted provided this
|
||||
// copyright notice appears in all copies. This software is provided
|
||||
// "as is" without express or implied warranty, and with no claim as
|
||||
// to its suitability for any purpose.
|
||||
#ifndef MODULE_BASE_DWA2002227_HPP
|
||||
# define MODULE_BASE_DWA2002227_HPP
|
||||
# include <boost/python/detail/wrap_python.hpp>
|
||||
# include <boost/python/reference.hpp>
|
||||
|
||||
namespace boost { namespace python { namespace detail {
|
||||
|
||||
class BOOST_PYTHON_DECL module_base
|
||||
{
|
||||
public:
|
||||
// Create a module. REQUIRES: only one module is created per module.
|
||||
module_base(const char* name);
|
||||
~module_base();
|
||||
|
||||
// Add elements to the module
|
||||
void setattr(const char* name, PyObject*);
|
||||
void setattr(const char* name, ref const&);
|
||||
void add(PyTypeObject* x); // just use the type's name
|
||||
void add_type(ref);
|
||||
|
||||
// Return a reference to the Python module object being built
|
||||
inline ref object() const;
|
||||
|
||||
private:
|
||||
ref m_module;
|
||||
static PyMethodDef initial_methods[1];
|
||||
};
|
||||
|
||||
//
|
||||
// inline implementations
|
||||
//
|
||||
inline ref module_base::object() const
|
||||
{
|
||||
return m_module;
|
||||
}
|
||||
|
||||
}}} // namespace boost::python::detail
|
||||
|
||||
#endif // MODULE_BASE_DWA2002227_HPP
|
||||
99
include/boost/python/detail/msvc_typeinfo.hpp
Normal file
99
include/boost/python/detail/msvc_typeinfo.hpp
Normal file
@@ -0,0 +1,99 @@
|
||||
// Copyright David Abrahams 2002. Permission to copy, use,
|
||||
// modify, sell and distribute this software is granted provided this
|
||||
// copyright notice appears in all copies. This software is provided
|
||||
// "as is" without express or implied warranty, and with no claim as
|
||||
// to its suitability for any purpose.
|
||||
#ifndef MSVC_TYPEINFO_DWA200222_HPP
|
||||
# define MSVC_TYPEINFO_DWA200222_HPP
|
||||
|
||||
#include <boost/type.hpp>
|
||||
#include <typeinfo>
|
||||
|
||||
//
|
||||
// Fix for MSVC's broken typeid() implementation which doesn't strip
|
||||
// decoration. This fix doesn't handle cv-qualified array types. It
|
||||
// could probably be done, but I haven't figured it out yet.
|
||||
//
|
||||
|
||||
# if defined(BOOST_MSVC) && BOOST_MSVC <= 1300 || defined(BOOST_INTEL_CXX_VERSION) && BOOST_INTEL_CXX_VERSION <= 600
|
||||
|
||||
namespace boost { namespace python { namespace detail {
|
||||
|
||||
typedef std::type_info const& typeinfo;
|
||||
|
||||
template<int>struct value_id_accessor;
|
||||
|
||||
template<>
|
||||
struct value_id_accessor<0>
|
||||
{
|
||||
template <class T>
|
||||
static typeinfo get(T*) { return typeid(T); }
|
||||
};
|
||||
|
||||
template<>
|
||||
struct value_id_accessor<1>
|
||||
{
|
||||
template <class T>
|
||||
static typeinfo get(T const*) { return typeid(T); }
|
||||
};
|
||||
|
||||
template<>
|
||||
struct value_id_accessor<2>
|
||||
{
|
||||
template <class T>
|
||||
static typeinfo get(T volatile*) { return typeid(T); }
|
||||
};
|
||||
|
||||
template<>
|
||||
struct value_id_accessor<3>
|
||||
{
|
||||
template <class T>
|
||||
static typeinfo get(T const volatile*) { return typeid(T); }
|
||||
};
|
||||
|
||||
template <bool> struct bool_t{};
|
||||
|
||||
template <class T>
|
||||
inline typeinfo typeid_nonref(boost::type<T>* = 0)
|
||||
{
|
||||
BOOST_STATIC_CONSTANT(bool, c = is_const<T>::value);
|
||||
BOOST_STATIC_CONSTANT(bool, v = is_volatile<T>::value);
|
||||
return value_id_accessor<(2 * v + c)>::get((T*)0);
|
||||
}
|
||||
|
||||
template <class T>
|
||||
inline typeinfo typeid_ref(boost::type<T>*, ...)
|
||||
{
|
||||
return typeid_nonref<T>();
|
||||
}
|
||||
|
||||
template <class U, class T>
|
||||
inline typeinfo typeid_ref(boost::type<U>*, T& (*)())
|
||||
{
|
||||
return typeid_nonref<T>();
|
||||
}
|
||||
|
||||
template <class T>
|
||||
inline typeinfo typeid_array(bool_t<false>, boost::type<T>* = 0)
|
||||
{
|
||||
typedef T (*x)();
|
||||
return typeid_ref((boost::type<T>*)0, x(0));
|
||||
}
|
||||
|
||||
template <class T>
|
||||
inline typeinfo typeid_array(bool_t<true>, boost::type<T>* = 0)
|
||||
{
|
||||
return typeid_nonref<T>();
|
||||
}
|
||||
|
||||
template <class T>
|
||||
inline typeinfo msvc_typeid(boost::type<T>* = 0)
|
||||
{
|
||||
typedef bool_t<is_array<T>::value> tag;
|
||||
return typeid_array(tag(), (boost::type<T>*)0);
|
||||
}
|
||||
|
||||
}}} // namespace boost::python::detail
|
||||
|
||||
# endif // BOOST_MSVC
|
||||
#endif // MSVC_TYPEINFO_DWA200222_HPP
|
||||
183
include/boost/python/detail/python_library_include.hpp
Normal file
183
include/boost/python/detail/python_library_include.hpp
Normal file
@@ -0,0 +1,183 @@
|
||||
#error obsolete
|
||||
/*
|
||||
*
|
||||
* Copyright (c) 1998-2000
|
||||
* Dr John Maddock
|
||||
*
|
||||
* Permission to use, copy, modify, distribute and sell this software
|
||||
* and its documentation for any purpose is hereby granted without fee,
|
||||
* provided that the above copyright notice appear in all copies and
|
||||
* that both that copyright notice and this permission notice appear
|
||||
* in supporting documentation. Dr John Maddock makes no representations
|
||||
* about the suitability of this software for any purpose.
|
||||
* It is provided "as is" without express or implied warranty.
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* LOCATION: see http://www.boost.org for most recent version.
|
||||
* FILE regex_libary_include.hpp
|
||||
* VERSION see <boost/version.hpp>
|
||||
* DESCRIPTION: Automatic library inclusion for Borland/Microsoft compilers.
|
||||
* Note this is an internal header file included
|
||||
* by regex.hpp, do not include on its own.
|
||||
*/
|
||||
|
||||
|
||||
#ifndef BOOST_REGEX_LIBRARY_INCLUDE_HPP
|
||||
#define BOOST_REGEX_LIBRARY_INCLUDE_HPP
|
||||
#ifndef BOOST_REGEX_NO_LIB
|
||||
|
||||
#if defined(BOOST_MSVC) && !defined(BOOST_REGEX_BUILD_DLL)
|
||||
#ifdef __SGI_STL_PORT
|
||||
#ifdef _DLL
|
||||
// All these are multithreaded:
|
||||
#if defined(_DEBUG) && defined(__STL_DEBUG)
|
||||
#pragma comment(lib, "vc6-stlport-re300ddl.lib")
|
||||
#elif defined(_DEBUG)
|
||||
#pragma comment(lib, "vc6-stlport-re300dl.lib")
|
||||
#elif defined(BOOST_REGEX_STATIC_LINK)
|
||||
// static regex lib, dll runtime
|
||||
#pragma comment(lib, "vc6-stlport-re300ls.lib")
|
||||
#else // DEBUG
|
||||
#pragma comment(lib, "vc6-stlport-re300l.lib")
|
||||
#endif // _DEBUG
|
||||
#else // _DLL
|
||||
#ifdef _MT
|
||||
#if defined(_DEBUG) && defined(__STL_DEBUG)
|
||||
#pragma comment(lib, "vc6-stlport-re300ddm.lib")
|
||||
#elif defined(_DEBUG)
|
||||
#pragma comment(lib, "vc6-stlport-re300dm.lib")
|
||||
#else //_DEBUG
|
||||
#pragma comment(lib, "vc6-stlport-re300m.lib")
|
||||
#endif //_DEBUG
|
||||
#else //_MT
|
||||
// STLPort does not support single threaded builds:
|
||||
#error STLPort does not support single threaded builds
|
||||
#endif //_MT
|
||||
#endif //_DLL
|
||||
#elif _MSC_VER < 1300
|
||||
#ifdef _DLL
|
||||
// All these are multithreaded:
|
||||
#ifdef _DEBUG
|
||||
#pragma comment(lib, "vc6-re300dl.lib")
|
||||
#elif defined(BOOST_REGEX_STATIC_LINK)
|
||||
// static regex lib, dll runtime
|
||||
#pragma comment(lib, "vc6-re300ls.lib")
|
||||
#else // DEBUG
|
||||
#pragma comment(lib, "vc6-re300l.lib")
|
||||
#endif // _DEBUG
|
||||
#else // _DLL
|
||||
#ifdef _MT
|
||||
#ifdef _DEBUG
|
||||
#pragma comment(lib, "vc6-re300dm.lib")
|
||||
#else //_DEBUG
|
||||
#pragma comment(lib, "vc6-re300m.lib")
|
||||
#endif //_DEBUG
|
||||
#else //_MT
|
||||
#ifdef _DEBUG
|
||||
#pragma comment(lib, "vc6-re300d.lib")
|
||||
#else //_DEBUG
|
||||
#pragma comment(lib, "vc6-re300.lib")
|
||||
#endif //_DEBUG
|
||||
#endif //_MT
|
||||
#endif //_DLL
|
||||
#else
|
||||
#ifdef _DLL
|
||||
// All these are multithreaded:
|
||||
#ifdef _DEBUG
|
||||
#pragma comment(lib, "vc7-re300dl.lib")
|
||||
#elif defined(BOOST_REGEX_STATIC_LINK)
|
||||
// static regex lib, dll runtime
|
||||
#pragma comment(lib, "vc7-re300ls.lib")
|
||||
#else // DEBUG
|
||||
#pragma comment(lib, "vc7-re300l.lib")
|
||||
#endif // _DEBUG
|
||||
#else // _DLL
|
||||
#ifdef _MT
|
||||
#ifdef _DEBUG
|
||||
#pragma comment(lib, "vc7-re300dm.lib")
|
||||
#else //_DEBUG
|
||||
#pragma comment(lib, "vc7-re300m.lib")
|
||||
#endif //_DEBUG
|
||||
#else //_MT
|
||||
#ifdef _DEBUG
|
||||
#pragma comment(lib, "vc7-re300d.lib")
|
||||
#else //_DEBUG
|
||||
#pragma comment(lib, "vc7-re300.lib")
|
||||
#endif //_DEBUG
|
||||
#endif //_MT
|
||||
#endif //_DLL
|
||||
#endif // __SGI_STL_PORT
|
||||
#endif //BOOST_MSVC
|
||||
|
||||
|
||||
#if defined(__BORLANDC__) && !defined(BOOST_REGEX_BUILD_DLL)
|
||||
|
||||
#if __BORLANDC__ < 0x550
|
||||
|
||||
#ifdef BOOST_REGEX_USE_VCL
|
||||
|
||||
#ifdef _RTLDLL
|
||||
#pragma comment(lib, "bcb4re300lv.lib")
|
||||
#else
|
||||
#pragma comment(lib, "bcb4re300v.lib")
|
||||
#endif
|
||||
|
||||
#else // VCL
|
||||
|
||||
#ifdef _RTLDLL
|
||||
#ifdef __MT__
|
||||
#pragma comment(lib, "bcb4re300lm.lib")
|
||||
#else // __MT__
|
||||
#pragma comment(lib, "bcb4re300l.lib")
|
||||
#endif // __MT__
|
||||
#else //_RTLDLL
|
||||
#ifdef __MT__
|
||||
#pragma comment(lib, "bcb4re300m.lib")
|
||||
#else // __MT__
|
||||
#pragma comment(lib, "bcb4re300.lib")
|
||||
#endif // __MT__
|
||||
#endif // _RTLDLL
|
||||
|
||||
#endif // VCL
|
||||
|
||||
#else // C++ Builder 5:
|
||||
|
||||
#ifdef BOOST_REGEX_USE_VCL
|
||||
|
||||
#ifdef _RTLDLL
|
||||
#pragma comment(lib, "bcb5re300lv.lib")
|
||||
#else
|
||||
#pragma comment(lib, "bcb5re300v.lib")
|
||||
#endif
|
||||
|
||||
#else // VCL
|
||||
|
||||
#ifdef _RTLDLL
|
||||
#ifdef __MT__
|
||||
#pragma comment(lib, "bcb5re300lm.lib")
|
||||
#else // __MT__
|
||||
#pragma comment(lib, "bcb5re300l.lib")
|
||||
#endif // __MT__
|
||||
#else //_RTLDLL
|
||||
#ifdef __MT__
|
||||
#pragma comment(lib, "bcb5re300m.lib")
|
||||
#else // __MT__
|
||||
#pragma comment(lib, "bcb5re300.lib")
|
||||
#endif // __MT__
|
||||
#endif // _RTLDLL
|
||||
|
||||
#endif // VCL
|
||||
|
||||
#endif
|
||||
|
||||
#endif //__BORLANDC__
|
||||
|
||||
#endif //BOOST_REGEX_NO_LIB
|
||||
|
||||
#endif // BOOST_REGEX_LIBRARY_INCLUDE_HPP
|
||||
|
||||
|
||||
|
||||
|
||||
1478
include/boost/python/detail/returning.hpp
Normal file
1478
include/boost/python/detail/returning.hpp
Normal file
File diff suppressed because it is too large
Load Diff
217
include/boost/python/detail/signature.hpp
Normal file
217
include/boost/python/detail/signature.hpp
Normal file
@@ -0,0 +1,217 @@
|
||||
// (C) Copyright David Abrahams 2002. Permission to copy, use, modify, sell and
|
||||
// distribute this software is granted provided this copyright notice appears
|
||||
// in all copies. This software is provided "as is" without express or implied
|
||||
// warranty, and with no claim as to its suitability for any purpose.
|
||||
//
|
||||
// This work was funded in part by Lawrence Berkeley and Lawrence
|
||||
// Livermore National Labs
|
||||
//
|
||||
// This file generated for 5-argument member functions and 6-argument free
|
||||
// functions by gen_signature.py
|
||||
|
||||
#ifndef SIGNATURE_DWA2002128_HPP
|
||||
# define SIGNATURE_DWA2002128_HPP
|
||||
|
||||
# include <boost/mpl/type_list.hpp>
|
||||
|
||||
namespace boost { namespace python { namespace detail {
|
||||
|
||||
template <class R>
|
||||
mpl::type_list<R>
|
||||
signature(R (*)())
|
||||
{
|
||||
return mpl::type_list<R>();
|
||||
}
|
||||
|
||||
template <class R, class A0>
|
||||
mpl::type_list<R,A0>
|
||||
signature(R (*)(A0))
|
||||
{
|
||||
return mpl::type_list<R,A0>();
|
||||
}
|
||||
|
||||
template <class R, class A0, class A1>
|
||||
mpl::type_list<R,A0,A1>
|
||||
signature(R (*)(A0, A1))
|
||||
{
|
||||
return mpl::type_list<R,A0,A1>();
|
||||
}
|
||||
|
||||
template <class R, class A0, class A1, class A2>
|
||||
mpl::type_list<R,A0,A1,A2>
|
||||
signature(R (*)(A0, A1, A2))
|
||||
{
|
||||
return mpl::type_list<R,A0,A1,A2>();
|
||||
}
|
||||
|
||||
template <class R, class A0, class A1, class A2, class A3>
|
||||
mpl::type_list<R,A0,A1,A2,A3>
|
||||
signature(R (*)(A0, A1, A2, A3))
|
||||
{
|
||||
return mpl::type_list<R,A0,A1,A2,A3>();
|
||||
}
|
||||
|
||||
template <class R, class A0, class A1, class A2, class A3, class A4>
|
||||
mpl::type_list<R,A0,A1,A2,A3,A4>
|
||||
signature(R (*)(A0, A1, A2, A3, A4))
|
||||
{
|
||||
return mpl::type_list<R,A0,A1,A2,A3,A4>();
|
||||
}
|
||||
|
||||
template <class R, class A0, class A1, class A2, class A3, class A4, class A5>
|
||||
mpl::type_list<R,A0,A1,A2,A3,A4,A5>
|
||||
signature(R (*)(A0, A1, A2, A3, A4, A5))
|
||||
{
|
||||
return mpl::type_list<R,A0,A1,A2,A3,A4,A5>();
|
||||
}
|
||||
template <class R, class A0>
|
||||
mpl::type_list<R,A0&> signature(R (A0::*)())
|
||||
{
|
||||
return mpl::type_list<R,A0&>();
|
||||
}
|
||||
|
||||
template <class R, class A0, class A1>
|
||||
mpl::type_list<R,A0&,A1> signature(R (A0::*)(A1))
|
||||
{
|
||||
return mpl::type_list<R,A0&,A1>();
|
||||
}
|
||||
|
||||
template <class R, class A0, class A1, class A2>
|
||||
mpl::type_list<R,A0&,A1,A2> signature(R (A0::*)(A1, A2))
|
||||
{
|
||||
return mpl::type_list<R,A0&,A1,A2>();
|
||||
}
|
||||
|
||||
template <class R, class A0, class A1, class A2, class A3>
|
||||
mpl::type_list<R,A0&,A1,A2,A3> signature(R (A0::*)(A1, A2, A3))
|
||||
{
|
||||
return mpl::type_list<R,A0&,A1,A2,A3>();
|
||||
}
|
||||
|
||||
template <class R, class A0, class A1, class A2, class A3, class A4>
|
||||
mpl::type_list<R,A0&,A1,A2,A3,A4> signature(R (A0::*)(A1, A2, A3, A4))
|
||||
{
|
||||
return mpl::type_list<R,A0&,A1,A2,A3,A4>();
|
||||
}
|
||||
|
||||
template <class R, class A0, class A1, class A2, class A3, class A4, class A5>
|
||||
mpl::type_list<R,A0&,A1,A2,A3,A4,A5> signature(R (A0::*)(A1, A2, A3, A4, A5))
|
||||
{
|
||||
return mpl::type_list<R,A0&,A1,A2,A3,A4,A5>();
|
||||
}
|
||||
|
||||
|
||||
template <class R, class A0>
|
||||
mpl::type_list<R,A0 const&> signature(R (A0::*)() const)
|
||||
{
|
||||
return mpl::type_list<R,A0 const&>();
|
||||
}
|
||||
|
||||
template <class R, class A0, class A1>
|
||||
mpl::type_list<R,A0 const&,A1> signature(R (A0::*)(A1) const)
|
||||
{
|
||||
return mpl::type_list<R,A0 const&,A1>();
|
||||
}
|
||||
|
||||
template <class R, class A0, class A1, class A2>
|
||||
mpl::type_list<R,A0 const&,A1,A2> signature(R (A0::*)(A1, A2) const)
|
||||
{
|
||||
return mpl::type_list<R,A0 const&,A1,A2>();
|
||||
}
|
||||
|
||||
template <class R, class A0, class A1, class A2, class A3>
|
||||
mpl::type_list<R,A0 const&,A1,A2,A3> signature(R (A0::*)(A1, A2, A3) const)
|
||||
{
|
||||
return mpl::type_list<R,A0 const&,A1,A2,A3>();
|
||||
}
|
||||
|
||||
template <class R, class A0, class A1, class A2, class A3, class A4>
|
||||
mpl::type_list<R,A0 const&,A1,A2,A3,A4> signature(R (A0::*)(A1, A2, A3, A4) const)
|
||||
{
|
||||
return mpl::type_list<R,A0 const&,A1,A2,A3,A4>();
|
||||
}
|
||||
|
||||
template <class R, class A0, class A1, class A2, class A3, class A4, class A5>
|
||||
mpl::type_list<R,A0 const&,A1,A2,A3,A4,A5> signature(R (A0::*)(A1, A2, A3, A4, A5) const)
|
||||
{
|
||||
return mpl::type_list<R,A0 const&,A1,A2,A3,A4,A5>();
|
||||
}
|
||||
|
||||
|
||||
template <class R, class A0>
|
||||
mpl::type_list<R,A0 volatile&> signature(R (A0::*)() volatile)
|
||||
{
|
||||
return mpl::type_list<R,A0 volatile&>();
|
||||
}
|
||||
|
||||
template <class R, class A0, class A1>
|
||||
mpl::type_list<R,A0 volatile&,A1> signature(R (A0::*)(A1) volatile)
|
||||
{
|
||||
return mpl::type_list<R,A0 volatile&,A1>();
|
||||
}
|
||||
|
||||
template <class R, class A0, class A1, class A2>
|
||||
mpl::type_list<R,A0 volatile&,A1,A2> signature(R (A0::*)(A1, A2) volatile)
|
||||
{
|
||||
return mpl::type_list<R,A0 volatile&,A1,A2>();
|
||||
}
|
||||
|
||||
template <class R, class A0, class A1, class A2, class A3>
|
||||
mpl::type_list<R,A0 volatile&,A1,A2,A3> signature(R (A0::*)(A1, A2, A3) volatile)
|
||||
{
|
||||
return mpl::type_list<R,A0 volatile&,A1,A2,A3>();
|
||||
}
|
||||
|
||||
template <class R, class A0, class A1, class A2, class A3, class A4>
|
||||
mpl::type_list<R,A0 volatile&,A1,A2,A3,A4> signature(R (A0::*)(A1, A2, A3, A4) volatile)
|
||||
{
|
||||
return mpl::type_list<R,A0 volatile&,A1,A2,A3,A4>();
|
||||
}
|
||||
|
||||
template <class R, class A0, class A1, class A2, class A3, class A4, class A5>
|
||||
mpl::type_list<R,A0 volatile&,A1,A2,A3,A4,A5> signature(R (A0::*)(A1, A2, A3, A4, A5) volatile)
|
||||
{
|
||||
return mpl::type_list<R,A0 volatile&,A1,A2,A3,A4,A5>();
|
||||
}
|
||||
|
||||
|
||||
template <class R, class A0>
|
||||
mpl::type_list<R,A0 const volatile&> signature(R (A0::*)() const volatile)
|
||||
{
|
||||
return mpl::type_list<R,A0 const volatile&>();
|
||||
}
|
||||
|
||||
template <class R, class A0, class A1>
|
||||
mpl::type_list<R,A0 const volatile&,A1> signature(R (A0::*)(A1) const volatile)
|
||||
{
|
||||
return mpl::type_list<R,A0 const volatile&,A1>();
|
||||
}
|
||||
|
||||
template <class R, class A0, class A1, class A2>
|
||||
mpl::type_list<R,A0 const volatile&,A1,A2> signature(R (A0::*)(A1, A2) const volatile)
|
||||
{
|
||||
return mpl::type_list<R,A0 const volatile&,A1,A2>();
|
||||
}
|
||||
|
||||
template <class R, class A0, class A1, class A2, class A3>
|
||||
mpl::type_list<R,A0 const volatile&,A1,A2,A3> signature(R (A0::*)(A1, A2, A3) const volatile)
|
||||
{
|
||||
return mpl::type_list<R,A0 const volatile&,A1,A2,A3>();
|
||||
}
|
||||
|
||||
template <class R, class A0, class A1, class A2, class A3, class A4>
|
||||
mpl::type_list<R,A0 const volatile&,A1,A2,A3,A4> signature(R (A0::*)(A1, A2, A3, A4) const volatile)
|
||||
{
|
||||
return mpl::type_list<R,A0 const volatile&,A1,A2,A3,A4>();
|
||||
}
|
||||
|
||||
template <class R, class A0, class A1, class A2, class A3, class A4, class A5>
|
||||
mpl::type_list<R,A0 const volatile&,A1,A2,A3,A4,A5> signature(R (A0::*)(A1, A2, A3, A4, A5) const volatile)
|
||||
{
|
||||
return mpl::type_list<R,A0 const volatile&,A1,A2,A3,A4,A5>();
|
||||
}
|
||||
|
||||
}}} // namespace boost::python::detail
|
||||
|
||||
#endif // SIGNATURE_DWA2002128_HPP
|
||||
|
||||
@@ -17,7 +17,7 @@ namespace boost { namespace python {
|
||||
namespace detail {
|
||||
// A stand-in for the built-in void. This one can be passed to functions and
|
||||
// (under MSVC, which has a bug, be used as a default template type parameter).
|
||||
struct void_t {};
|
||||
struct BOOST_PYTHON_DECL void_t {};
|
||||
}
|
||||
|
||||
// An envelope in which type information can be delivered for the purposes
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
|
||||
namespace boost { namespace python { namespace detail {
|
||||
|
||||
struct empty {};
|
||||
struct BOOST_PYTHON_DECL empty {};
|
||||
template <class Derived, class Base = empty>
|
||||
struct singleton : Base
|
||||
{
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user