2
0
mirror of https://github.com/boostorg/python.git synced 2026-01-21 17:12:22 +00:00

Compare commits

...

114 Commits

Author SHA1 Message Date
nobody
bb69e7fdb7 This commit was manufactured by cvs2svn to create tag
'Version_1_34_1_RC2'.

[SVN r38193]
2007-07-12 01:07:47 +00:00
Thomas Witt
2851325748 Doc and build fixes by Dave Abrahams.
[SVN r38154]
2007-07-06 19:47:17 +00:00
Thomas Witt
bd606e5017 Fix #583.
[SVN r37947]
2007-06-08 18:30:46 +00:00
Thomas Witt
a5706ec3b0 Fixes for #583.
[SVN r37929]
2007-06-07 18:08:54 +00:00
Rene Rivera
a346c577cf Fix the abolute reference to the Boost sources inserted by Dave.
[SVN r37837]
2007-05-31 22:03:06 +00:00
Dave Abrahams
217e4ca8f8 Repair auto-configuration and allow this project to work with --build-dir
[SVN r37829]
2007-05-31 13:49:45 +00:00
Stefan Seefeld
f2f47f85c0 Enhance embedding python docs.
[SVN r37710]
2007-05-18 15:54:25 +00:00
Stefan Seefeld
b130c93af6 Backport new eval() function from HEAD.
[SVN r37693]
2007-05-15 13:43:52 +00:00
Dave Abrahams
13432b504f Jamfile had extra bogus tst executable target
Build/test instructions were outdated somehow; a checkin must've failed.


[SVN r37620]
2007-05-07 19:00:01 +00:00
Dave Abrahams
0739bb7df8 Added reference to Py++
[SVN r37586]
2007-05-04 01:08:54 +00:00
Dave Abrahams
c253c5cc9c Updated build-and-test howto
[SVN r37585]
2007-05-04 00:56:22 +00:00
Dave Abrahams
8f263e1fdb Progress on the build docs
[SVN r37551]
2007-05-01 16:14:39 +00:00
Ralf W. Grosse-Kunstleve
a6125a3632 merged from trunk
[SVN r37520]
2007-04-27 22:16:47 +00:00
nobody
a784bfc0f8 This commit was manufactured by cvs2svn to create branch 'RC_1_34_0'.
[SVN r37419]
2007-04-11 23:35:09 +00:00
Dave Abrahams
b8937d0bae Relieve need to explicitly configure Python
[SVN r37382]
2007-04-06 18:17:43 +00:00
Dave Abrahams
4827ae73d5 Trivial change to force a rebuild on incremental testers' machines.
[SVN r37327]
2007-04-02 00:54:48 +00:00
Dave Abrahams
8eddc7aa37 Support for --with-pydebug builds.
python.jam:

  Support for the specification of "_d" extension suffix.

  In compute-default-paths, fixed the check for residence in
  a "PCBuild.*" directory so we can build against Windows Python built
  in a source distribution.

common.jam:

  Fixed generation of the "y" tag to look for <python-debugging>on
  rather than the whole debug-python build variant.

  Fixed some grammar and spelling.

virtual-target.jam:

  Added the ability to forego the prepending of "." to a
  generated-target-suffix by specifying the suffix enclosed in <...>

libs/python/build/Jamfile.v2:

  #define BOOST_DEBUG_PYTHON when <python-debugging>on


[SVN r37326]
2007-04-02 00:51:15 +00:00
Stefan Seefeld
98a468dadc Fix reference counting error.
[SVN r37312]
2007-03-28 18:12:08 +00:00
Dave Abrahams
ea4e6c0a4c Trivial change to force a rebuild on incremental testers' machines.
[SVN r37311]
2007-03-28 12:44:57 +00:00
Dave Abrahams
7cd7f6d8ee Trivial change to force a rebuild on incremental testers' machines.
[SVN r37287]
2007-03-26 15:47:05 +00:00
Dave Abrahams
4c39e8c990 Making a trivial change to trigger a test run from incremental testers
[SVN r37278]
2007-03-24 18:57:19 +00:00
Dave Abrahams
6c6f654fbe Add commented-out test for import_ so it's easy to reinstate
[SVN r37256]
2007-03-21 17:44:57 +00:00
Dave Abrahams
b7eaea096e Eliminate import_ test, as it doesn't work consistently on Windows and Linux.
[SVN r37250]
2007-03-21 05:09:21 +00:00
Dave Abrahams
904ae8604c fix builtin_converters test so it can work (BBv1 allowed the
duplication of main target names; BBv2 does not)


[SVN r37216]
2007-03-17 20:26:21 +00:00
Dave Abrahams
44d53c448b libs/python/build/Jamfile.v2: remove needless <define> property.
libs/python/test/Jamfile.v2:
  * add dynamically-linked embedding test

  * fix builtin_converters test so it can work (BBv1 allowed the
    duplication of main target names; BBv2 does not)


libs/python/test/import_.cpp: move some more of the Python code within
  a handle_exception callback so at least we can better diagnose
  failures.


[SVN r37214]
2007-03-17 20:17:56 +00:00
Stefan Seefeld
e61401d27e Fix import_ failure.
[SVN r37141]
2007-03-05 18:44:45 +00:00
Stefan Seefeld
be7ca7d269 Add copyright notice.
[SVN r37132]
2007-03-02 17:16:51 +00:00
Stefan Seefeld
47b4b4efbb Fix boost::python::import.
[SVN r37123]
2007-03-01 18:31:10 +00:00
nobody
4fa07f2b3d This commit was manufactured by cvs2svn to create branch 'RC_1_34_0'.
[SVN r37121]
2007-03-01 15:17:30 +00:00
Dave Abrahams
c880e7d69d Correct testing bugs:
either changing assert(...) or BOOST_ASSERT(...) to BOOST_TEST
    (in my code only)

    or adding "return boost::report_errors();" where it was clearly
    missing (and a pure bug, in anyone's code).

    or changing BOOST_TEST to BOOST_CHECK where the integer library
    was clearly using Boost.Test and not returning report_errors().


[SVN r37063]
2007-02-25 15:28:02 +00:00
Dave Abrahams
c73ad50286 Roll back improved error message because it causes problems for vc6/7
[SVN r36435]
2006-12-16 22:00:35 +00:00
Dave Abrahams
0910710ac4 Correct class/function mismatches for MSVC and bring across
documentation tweaks from HEAD.


[SVN r36355]
2006-12-13 15:08:26 +00:00
Dave Abrahams
04c528138b Fully switch to BBv2
[SVN r36327]
2006-12-11 05:22:04 +00:00
nobody
1b66cd9643 This commit was manufactured by cvs2svn to create branch 'RC_1_34_0'.
[SVN r36324]
2006-12-11 05:02:35 +00:00
Dave Abrahams
c2dd9fa833 Fix auto-link to look at the right variable.
[SVN r36319]
2006-12-11 03:00:26 +00:00
Dave Abrahams
b085121369 merged from trunk
[SVN r36292]
2006-12-07 17:45:17 +00:00
Beman Dawes
fa219bce9b Merged copyright and license addition
[SVN r35907]
2006-11-07 19:27:00 +00:00
Rene Rivera
10b85d67e7 Remove obsolete Boost.Build v1 files.
[SVN r35880]
2006-11-06 17:10:46 +00:00
Stefan Seefeld
ca91dc828e Fix symbol visibility.
[SVN r35754]
2006-10-27 21:19:47 +00:00
Dave Abrahams
3a53c1dec0 Add fixes somehow missed for darwin
[SVN r35612]
2006-10-14 19:10:30 +00:00
nobody
da8e309957 This commit was manufactured by cvs2svn to create branch 'RC_1_34_0'.
[SVN r35598]
2006-10-13 21:34:27 +00:00
Dave Abrahams
2bd9141d4a make numpy tests portable to Darwin with older docutils
[SVN r35597]
2006-10-13 21:34:26 +00:00
Dave Abrahams
c3bda6a903 Fix some problems with testing on old docutils installations
[SVN r35594]
2006-10-13 19:35:28 +00:00
Dave Abrahams
d61909d3ea Make object comparison operators return object instead of bool, to
accomodate strange beasts like numarray arrays that return arrays that
can't be used as truth values from their comparison ops.

Fix numpy test for portability with old doctest (again!)


[SVN r35572]
2006-10-12 09:07:07 +00:00
Dave Abrahams
1755dad7e6 merged from trunk
[SVN r35569]
2006-10-12 06:42:20 +00:00
Dave Abrahams
3b392c99be Adjust tests to account for numarray behavior differences
[SVN r35539]
2006-10-10 22:44:09 +00:00
Dave Abrahams
24ba93607b Try for backward compatibility with older versions of doctest
[SVN r35535]
2006-10-10 18:12:43 +00:00
Dave Abrahams
49d4aac8ec Fix lots of bugs in the numeric interface and tests.
Tests:
* Coerce a result to bool to deal with Python's new Bool type
* Better reporting of mismatches in expected and received results
* Remove bogus nullary y.astype() call
* Fix all uses of trace and diagonal so they don't cause errors
* Use appropriate typecodes
* Use doctest detailed API to run just the relevant tests
* Factor out error handling from macro

API:
* Added get_module_name() function to get current numeric module
* new_(x) now returns an array instead of object
* Fixed the signatures of the factory() family of functions
* Updated docs accordingly.


[SVN r35528]
2006-10-09 04:05:25 +00:00
Dave Abrahams
545be29ad3 (hopefully) grab the last bit of logic from HEAD for a bugfix I've been trying to apply to the branch for days(!)
[SVN r35436]
2006-10-01 18:25:44 +00:00
Dave Abrahams
8553c109c7 merged from HEAD
[SVN r35429]
2006-09-29 22:27:57 +00:00
Dave Abrahams
315c3d50ee Apply missing elements of previously-"applied" bug fix.
[SVN r35421]
2006-09-29 15:45:29 +00:00
Dave Abrahams
d5219979a4 Fix bugs uncovered by Roman Yakovenko
[SVN r35410]
2006-09-29 02:09:13 +00:00
Dave Abrahams
d42054f3a0 Cleans up license/copyright warnings
[SVN r35409]
2006-09-29 02:08:32 +00:00
nobody
72b06e70ee This commit was manufactured by cvs2svn to create branch 'RC_1_34_0'.
[SVN r35366]
2006-09-28 14:41:02 +00:00
Dave Abrahams
375cc3aa93 Fix broken links
[SVN r35330]
2006-09-26 04:25:49 +00:00
Ralf W. Grosse-Kunstleve
4eb286a034 ssize_t patches merged from HEAD
[SVN r35327]
2006-09-26 00:48:44 +00:00
nobody
a824230155 This commit was manufactured by cvs2svn to create branch 'RC_1_34_0'.
[SVN r35326]
2006-09-26 00:25:08 +00:00
Gottfried Ganßauge
1bc3750ab3 repaired broken links
[SVN r35315]
2006-09-25 07:35:57 +00:00
Dave Abrahams
36abcee847 merged from HEAD
[SVN r35277]
2006-09-22 15:13:30 +00:00
Gottfried Ganßauge
b8b7768eb7 Test for cross module support of opaque
[SVN r35256]
2006-09-21 16:47:49 +00:00
Gottfried Ganßauge
7ad9dc6c64 Changed references to opaque_pointer_converter.html to point to opaque.html instead
[SVN r35255]
2006-09-21 16:47:31 +00:00
Gottfried Ganßauge
decc34551a Renamed to opaque.html because class name changed
[SVN r35254]
2006-09-21 16:47:00 +00:00
Gottfried Ganßauge
5acb44ede0 Renamed from opaque_pointer_converter.html because class name changed
[SVN r35253]
2006-09-21 16:46:42 +00:00
Gottfried Ganßauge
ef62f87963 type object gets initialized. Cross module support works
[SVN r35252]
2006-09-21 16:46:21 +00:00
Joel de Guzman
b5c893381f merge from head
[SVN r35246]
2006-09-21 10:52:01 +00:00
Vladimir Prus
815969bf8b Merge: Add tests
[SVN r35245]
2006-09-21 07:27:11 +00:00
nobody
0d57e9e808 This commit was manufactured by cvs2svn to create branch 'RC_1_34_0'.
[SVN r35243]
2006-09-21 07:07:15 +00:00
Dave Abrahams
7ba6a00617 Apply Boost license, with permission from Prabhu Ramachandran.
[SVN r35240]
2006-09-21 03:43:59 +00:00
Dave Abrahams
e70bbe4791 Fix license/copyright.
Also port some "glaringly obvious" bugfixes from HEAD.  Hope it
doesn't cause problems.


[SVN r35237]
2006-09-20 22:49:18 +00:00
Stefan Seefeld
7ff0f62729 Fix copyright issues.
[SVN r35236]
2006-09-20 22:30:39 +00:00
Dave Abrahams
95f0b39c90 merged from HEAD
[SVN r35185]
2006-09-18 22:22:31 +00:00
nobody
23057688f9 This commit was manufactured by cvs2svn to create branch 'RC_1_34_0'.
[SVN r35170]
2006-09-18 19:56:20 +00:00
Dave Abrahams
029618f719 merged from HEAD
[SVN r35165]
2006-09-18 18:25:57 +00:00
Dave Abrahams
38f7a4e9b6 merge from HEAD
[SVN r35141]
2006-09-17 02:42:51 +00:00
Dave Abrahams
326c871224 attempt unverified workaround for http://tinyurl.com/gvrgd
[SVN r35103]
2006-09-13 22:47:11 +00:00
Dave Abrahams
924eeccd53 merged from trunk
[SVN r35080]
2006-09-13 00:02:56 +00:00
Dave Abrahams
4a63cf4843 Move definition of BOOST_PYTHON_SUPPRESS_REGISTRY_INITIALIZATION back
where it belongs.


[SVN r35076]
2006-09-12 22:37:09 +00:00
Dave Abrahams
1d65b74273 Add missing license/copyright
[SVN r35070]
2006-09-11 22:27:29 +00:00
Dave Abrahams
3c1ae689a7 merged from trunk
[SVN r34943]
2006-08-24 19:04:23 +00:00
Dave Abrahams
a99bd50e52 merged from trunk
[SVN r34940]
2006-08-24 13:05:30 +00:00
Dave Abrahams
8b178594ff merged from trunk
[SVN r34915]
2006-08-22 11:51:18 +00:00
Dave Abrahams
786aeef998 merged from trunk
[SVN r34872]
2006-08-11 15:51:09 +00:00
Dave Abrahams
45e4cf506f merged from trunk
[SVN r34865]
2006-08-11 00:48:19 +00:00
Gennaro Prota
8fb6e1f48d (merge from head)
removed tabs (inspect tool)


[SVN r34723]
2006-07-24 22:28:41 +00:00
Gennaro Prota
ecf70b05f2 (merge from head)
removed tabs (inspect tool)


[SVN r34721]
2006-07-24 22:21:39 +00:00
Gennaro Prota
c54acdb9db (merge from head)
minor fix: violation of min/max guidelines


[SVN r34718]
2006-07-24 22:06:09 +00:00
Vladimir Prus
489dae2b58 Clarify comment
[SVN r34668]
2006-07-22 12:53:49 +00:00
Vladimir Prus
f852ce6f7b Windows
[SVN r34667]
2006-07-22 12:28:43 +00:00
Vladimir Prus
e500919d25 Merge: Don't link Boost.Python to python library
[SVN r34663]
2006-07-22 07:16:18 +00:00
Markus Schöpflin
7a645a6d8a Merged header inclusion order fix from trunk to release branch.
[SVN r34195]
2006-06-06 09:44:35 +00:00
Markus Schöpflin
fa2185e5ab Merged header inclusion order fix from trunk to release branch.
[SVN r34194]
2006-06-06 09:39:16 +00:00
Vladimir Prus
5cc33461dd Merge from trunk
[SVN r33626]
2006-04-10 09:02:57 +00:00
Markus Schöpflin
7b93f2fdc5 Merged fix from HEAD for Tru64/CXX compilation error.
[SVN r33455]
2006-03-23 09:40:38 +00:00
nobody
219743964d This commit was manufactured by cvs2svn to create branch 'RC_1_34_0'.
[SVN r33417]
2006-03-21 02:26:31 +00:00
Ralf W. Grosse-Kunstleve
e7927ef4ea HP-UX aCC support
[SVN r33399]
2006-03-20 00:00:39 +00:00
Dave Abrahams
8c1f04bd4c Fix bug in example.
[SVN r33328]
2006-03-13 06:39:41 +00:00
Vladimir Prus
136587c96f Make select_from_python_test have Python includes when compiling.
[SVN r33281]
2006-03-09 15:27:01 +00:00
Vladimir Prus
23664ec448 Specify <define>BOOST_PYTHON_STATIC_LIB for the select_from_python_test,
just like V1 does.


[SVN r33246]
2006-03-07 07:37:45 +00:00
Vladimir Prus
6b1a3c4489 Change Jamfile.v2 to use static linking to Boost.Python for 'exec' test.
V1 uses static linking, so let's do the same.


[SVN r33226]
2006-03-06 08:10:38 +00:00
Markus Schöpflin
fa4ebe5c53 Disabled pointer_vector test on Tru64/CXX as it runs forever and keeps hanging
the regression tests.


[SVN r33207]
2006-03-03 09:08:39 +00:00
Markus Schöpflin
28ef4a9e38 Reorder includes to make sure that python headers are included first, this
makes the test pass on hp_cxx_71_006_tru64.


[SVN r33202]
2006-03-02 17:12:18 +00:00
Ralf W. Grosse-Kunstleve
5d1053552c missing const added (MIPSpro 7.3 warning)
[SVN r33165]
2006-02-28 01:32:33 +00:00
Markus Schöpflin
0a38ca1660 Disable pointer_vector test on HP-CXX for now.
[SVN r33147]
2006-02-27 15:26:45 +00:00
Dave Abrahams
5791e3b58e Added VPython
[SVN r33102]
2006-02-25 12:35:48 +00:00
Dave Abrahams
2bfd2fa0fd Add missing exception specification.
[SVN r33090]
2006-02-23 17:14:59 +00:00
Vladimir Prus
0793267bf0 Add BOOST_PYTHON_STATIC_LIB and BOOST_PYTHON_DYNAMIC_LIB to usage
requirements, as appropriate.


[SVN r33053]
2006-02-21 07:38:14 +00:00
Vladimir Prus
eca25c0b7d Extra project-level requirements.
[SVN r33052]
2006-02-21 07:36:46 +00:00
Dave Abrahams
a8bad65556 Fix mistaken dependency on lightweight_test.hpp
[SVN r33032]
2006-02-20 19:21:59 +00:00
Dave Abrahams
6ef31ba33a Stop using assert() in tests so we can test with NDEBUG defined.
[SVN r33026]
2006-02-20 15:45:40 +00:00
Jim Douglas
c15216b385 Changes to ensure QNX/QCC compatability
[SVN r32943]
2006-02-15 19:57:56 +00:00
Joel de Guzman
a1ff35769b Doc Tweaks
[SVN r32910]
2006-02-14 02:24:32 +00:00
Dave Abrahams
22e82ae30f void pointer conversion support, from Niall Douglas, then heavily
edited by DWA.  Merged from python-voidptr


[SVN r32857]
2006-02-12 16:09:08 +00:00
Dave Abrahams
2d117bc4ad void pointer conversion support, from Niall Douglas, then heavily
edited by DWA.


[SVN r32836]
2006-02-11 22:29:33 +00:00
Dave Abrahams
6347ca8065 vc7 workaround
[SVN r32835]
2006-02-11 22:26:45 +00:00
239 changed files with 4948 additions and 3419 deletions

View File

@@ -1,99 +0,0 @@
# (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.
#
# Boost.Python library Jamfile
# declare the location of this subproject relative to the root
subproject libs/python/build ;
# bring in the rules for python
import python ;
if [ check-python-config ]
{
local bpl-linkflags ;
if $(UNIX) && ( $(OS) = AIX )
{
bpl-linkflags = <linkflags>"-e initlibboost_python" ;
}
# Enabling intrinsics (/0i) or maximize speed (/02) seem to cause
# internal compiler errors with this toolset.
local msvc-stlport-workarounds
= <optimization>off "<cxxflags>-Ogty -O1 -Gs" ;
local sources =
numeric.cpp
list.cpp
long.cpp
dict.cpp
tuple.cpp
str.cpp
slice.cpp
aix_init_module.cpp
converter/from_python.cpp
converter/registry.cpp
converter/type_id.cpp
object/enum.cpp
object/class.cpp
object/function.cpp
object/inheritance.cpp
object/life_support.cpp
object/pickle_support.cpp
errors.cpp
module.cpp
converter/builtin_converters.cpp
converter/arg_to_python_base.cpp
object/iterator.cpp
object/stl_iterator.cpp
object_protocol.cpp
object_operators.cpp
wrapper.cpp
exec.cpp
import.cpp
;
dll boost_python
: ../src/$(sources)
: $(BOOST_PYTHON_V2_PROPERTIES)
<define>BOOST_PYTHON_SOURCE
$(bpl-linkflags)
<msvc-stlport><release>$(msvc-stlport-workarounds)
<darwin><*><linkflags>-bind_at_load
<gcc-3_3-darwin><*><linkflags>-bind_at_load
;
template extension
: <dll>boost_python
: <sysinclude>../../..
;
lib boost_python
: # sources
../src/$(sources)
: # requirements
$(BOOST_PYTHON_V2_PROPERTIES)
<define>BOOST_PYTHON_SOURCE
<define>BOOST_STATIC_LIB
$(bpl-linkflags)
<msvc-stlport><release>$(msvc-stlport-workarounds)
;
stage bin-stage : <dll>boost_python <lib>boost_python
: <tag><debug>"_debug"
<tag><debug-python>"_pydebug"
:
debug release
;
install python lib
: <dll>boost_python <lib>boost_python
;
}

View File

@@ -1,32 +1,35 @@
# Copyright David Abrahams 2001-2006. Distributed under the Boost
# Software License, Version 1.0. (See accompanying
# file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
import os ; import os ;
import modules ; import modules ;
import python ; import python ;
if [ python.configured ] { if ! [ python.configured ] && ! ( --without-python in [ modules.peek : ARGV ] )
{
# Attempt default configuration of python
import toolset : using ;
using python ;
if ! [ python.configured ]
{
ECHO "WARNING: No python installation configured and autoconfiguration" ;
ECHO " failed. See http://www.boost.org/libs/python/doc/building.html" ;
ECHO " for configuration instructions or pass --without-python to" ;
ECHO " suppress this message and silently skip all Boost.Python targets" ;
}
}
if [ python.configured ] {
project boost/python project boost/python
: source-location ../src : source-location ../src
: requirements
#<include>$(PYTHON_PATH)/include
# $(lib_condition)<library-path>$(PYTHON_PATH)/libs
# <link>shared:<library>$(PYTHON_LIB)
# <define>$(defines)
#: usage-requirements # requirement that will be propageted to *users* of this library
# <include>$(PYTHON_PATH)/include
# We have a bug which causes us to conclude that conditionalized
# properties in this section are not free.
# $(lib_condition)<library-path>$(PYTHON_PATH)/lib/python2.2/config
# <shared>true:<find-library>$(PYTHON_LIB)
# <library-path>$(PYTHON_PATH)/lib/python2.2/config
# <library>$(PYTHON_LIB)
; ;
lib boost_python lib boost_python
: : # sources
numeric.cpp numeric.cpp
list.cpp list.cpp
long.cpp long.cpp
@@ -35,7 +38,6 @@ lib boost_python
str.cpp str.cpp
slice.cpp slice.cpp
aix_init_module.cpp
converter/from_python.cpp converter/from_python.cpp
converter/registry.cpp converter/registry.cpp
converter/type_id.cpp converter/type_id.cpp
@@ -56,10 +58,31 @@ lib boost_python
wrapper.cpp wrapper.cpp
import.cpp import.cpp
exec.cpp exec.cpp
: <link>static:<define>BOOST_PYTHON_STATIC_LIB : # requirements
<link>static:<define>BOOST_PYTHON_STATIC_LIB
<define>BOOST_PYTHON_SOURCE <define>BOOST_PYTHON_SOURCE
<library>/python//python
: <link>shared # On Windows, all code using Python has to link to the Python
# import library.
#
# On *nix we never link libboost_python to libpython. When
# extending Python, all Python symbols are provided by the
# Python interpreter executable. When embedding Python, the
# client executable is expected to explicitly link to
# /python//python (the target representing libpython) itself.
#
# python_for_extensions is a target defined by Boost.Build to
# provide the Python include paths, and on Windows, the Python
# import library, as usage requirements.
<library>/python//python_for_extensions
<python-debugging>on:<define>BOOST_DEBUG_PYTHON
: # default build
<link>shared
: # usage requirements
<link>static:<define>BOOST_PYTHON_STATIC_LIB
<python-debugging>on:<define>BOOST_DEBUG_PYTHON
; ;
} }
else else

View File

@@ -95,10 +95,6 @@ LINK32=link.exe
# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat" # PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
# Begin Source File # Begin Source File
SOURCE=..\..\src\aix_init_module.cpp
# End Source File
# Begin Source File
SOURCE=..\..\src\converter\arg_to_python_base.cpp SOURCE=..\..\src\converter\arg_to_python_base.cpp
# End Source File # End Source File
# Begin Source File # Begin Source File
@@ -214,10 +210,6 @@ SOURCE=..\..\src\exec.cpp
# PROP Default_Filter "" # PROP Default_Filter ""
# Begin Source File # Begin Source File
SOURCE=..\..\..\..\boost\python\detail\aix_init_module.hpp
# End Source File
# Begin Source File
SOURCE=..\..\..\..\boost\python\detail\api_placeholder.hpp SOURCE=..\..\..\..\boost\python\detail\api_placeholder.hpp
# End Source File # End Source File
# Begin Source File # Begin Source File

Binary file not shown.

23
doc/Jamfile Normal file
View File

@@ -0,0 +1,23 @@
# Copyright David Abrahams 2006. Distributed under the Boost
# Software License, Version 1.0. (See accompanying
# file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
import docutils ;
import path ;
sources = building.rst ;
bases = $(sources:S=) ;
# This is a path relative to the html/ subdirectory where the
# generated output will eventually be moved.
stylesheet = "--stylesheet=../../../rst.css" ;
for local b in $(bases)
{
html $(b) : $(b).rst :
<docutils-html>"-gdt --source-url="./$(b).rst" --link-stylesheet --traceback --trim-footnote-reference-space --footnote-references=superscript "$(stylesheet)
;
}
alias htmls : $(bases) ;
stage . : $(bases) ;

View File

@@ -1,5 +1,11 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 3.2//EN"> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 3.2//EN">
<!-- Copyright David Abrahams 2006. Distributed under the Boost -->
<!-- Software License, Version 1.0. (See accompanying -->
<!-- file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -->
<!-- Copyright David Abrahams 2006. Distributed under the Boost -->
<!-- Software License, Version 1.0. (See accompanying -->
<!-- file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -->
<html> <html>
<head> <head>
<meta name="generator" content= <meta name="generator" content=

View File

@@ -1 +1,5 @@
.. Copyright David Abrahams 2006. Distributed under the Boost
.. Software License, Version 1.0. (See accompanying
.. file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
This file has been moved to http://www.boost-consulting.com/writing/bpl.txt. This file has been moved to http://www.boost-consulting.com/writing/bpl.txt.

View File

@@ -1,3 +1,7 @@
Copyright David Abrahams 2006. Distributed under the Boost
Software License, Version 1.0. (See accompanying
file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
.. This is a comment. Note how any initial comments are moved by .. This is a comment. Note how any initial comments are moved by
transforms to after the document title, subtitle, and docinfo. transforms to after the document title, subtitle, and docinfo.

View File

@@ -5,6 +5,8 @@
:version: $Revision$ :version: $Revision$
:copyright: This stylesheet has been placed in the public domain. :copyright: This stylesheet has been placed in the public domain.
boostinspect:nolicense
Default cascading style sheet for the HTML output of Docutils. Default cascading style sheet for the HTML output of Docutils.
*/ */

View File

@@ -1,3 +1,7 @@
/* Copyright David Abrahams 2006. Distributed under the Boost
Software License, Version 1.0. (See accompanying
file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
*/
H1 H1
{ {
FONT-SIZE: 200% FONT-SIZE: 200%

File diff suppressed because it is too large Load Diff

681
doc/building.rst Normal file
View File

@@ -0,0 +1,681 @@
.. Copyright David Abrahams 2006. Distributed under the Boost
.. Software License, Version 1.0. (See accompanying
.. file LICENSE_1_0.txt or copy at
.. http://www.boost.org/LICENSE_1_0.txt)
==============================================
|(logo)|__ Boost.Python Build and Test HOWTO
==============================================
.. |(logo)| image:: ../../../boost.png
:alt: Boost C++ Libraries:
:class: boost-logo
__ ../index.htm
.. section-numbering::
:depth: 2
.. contents:: Contents
:depth: 2
:class: sidebar small
.. |newer| replace:: *newer*
Requirements
============
Boost.Python requires `Python 2.2`_ [#2.2]_ *or* |newer|__.
.. _Python 2.2: http://www.python.org/2.2
__ http://www.python.org
Background
==========
There are two basic models for combining C++ and Python:
- extending_, in which the end-user launches the Python interpreter
executable and imports Python “extension modules” written in C++.
Think of taking a library written in C++ and giving it a Python
interface so Python programmers can use it. From Python, these
modules look just like regular Python modules.
- embedding_, in which the end-user launches a program written
in C++ that in turn invokes the Python interpreter as a library
subroutine. Think of adding scriptability to an existing
application.
.. _extending: http://www.python.org/doc/current/ext/intro.html
.. _embedding: http://www.python.org/doc/current/ext/embedding.html
The key distinction between extending and embedding is the location
of the C++ ``main()`` function: in the Python interpreter executable,
or in some other program, respectively. Note that even when
embedding Python in another program, `extension modules are often
the best way to make C/C++ functionality accessible to Python
code`__, so the use of extension modules is really at the heart of
both models.
__ http://www.python.org/doc/current/ext/extending-with-embedding.html
Except in rare cases, extension modules are built as
dynamically-loaded libraries with a single entry point, which means
you can change them without rebuilding either the other extension
modules or the executable containing ``main()``.
.. _quickstart:
No-Install Quickstart
=====================
There is no need to “install Boost” in order to get started using
Boost.Python. These instructions use Boost.Build_ projects,
which will build those binaries as soon as they're needed. Your
first tests may take a little longer while you wait for
Boost.Python to build, but doing things this way will save you from
worrying about build intricacies like which library binaries to use
for a specific compiler configuration and figuring out the right
compiler options to use yourself.
.. .. raw:: html
<div style="width:50%">
.. Note:: Of course it's possible to use other build systems to
build Boost.Python and its extensions, but they are not
officially supported by Boost. Moreover **99% of all “I can't
build Boost.Python” problems come from trying to use another
build system** without first following these instructions.
If you want to use another system anyway, we suggest that you
follow these instructions, and then invoke ``bjam`` with the
.. parsed-literal::
``-a -o``\ *filename*
options to dump the build commands it executes to a file, so
you can see what your alternate build system needs to do.
.. .. raw:: html
</div>
.. _Boost.Build: ../../../tools/build/index.html
Basic Procedure
---------------
1. Get Boost; see sections 1 and 2 [`Unix/Linux`__, `Windows`__\ ] of the
Boost `Getting Started Guide`_.
__ ../../../more/getting_started/unix-variants.html#get-boost
__ ../../../more/getting_started/windows.html#get-boost
2. Get the ``bjam`` build driver. See section 5 [`Unix/Linux`__,
`Windows`__\ ] of the Boost `Getting Started Guide`_.
__ ../../../more/getting_started/unix-variants.html#prepare-to-use-a-boost-library-binary
__ ../../../more/getting_started/windows.html#prepare-to-use-a-boost-library-binary
3. cd into the ``libs/python/example/quickstart/`` directory of your
Boost installation, which contains a small example project.
4. Invoke ``bjam``. Replace the “\ ``stage``\ “ argument from the
example invocation from section 5 of the `Getting Started
Guide`_ with “\ ``test``\ ,“ to build all the test targets. Also add
the argument “\ ``--verbose-test``\ ” to see the output generated by
the tests when they are run.
On Windows, your ``bjam`` invocation might look something like:
.. parsed-literal::
C:\\boost_1_34_0\\…\\quickstart> **bjam toolset=msvc --verbose-test test**
and on Unix variants, perhaps,
.. parsed-literal::
~/boost_1_34_0/…/quickstart$ **bjam toolset=gcc --verbose-test test**
.. Admonition:: Note to Windows Users
For the sake of concision, the rest of this guide will use
unix-style forward slashes in pathnames instead of the
backslashes with which you may be more familiar. The forward
slashes should work everywhere except in `Command Prompt`_
windows, where you should use backslashes.
.. _Command Prompt: ../../../more/getting_started/windows.html#command-prompt
If you followed this procedure successfully, you will have built an
extension module called ``extending`` and tested it by running a
Python script called ``test_extending.py``. You will also have
built and run a simple application called ``embedding`` that embeds
python.
.. _Getting Started Guide: ../../../more/getting_started/index.html
In Case of Trouble
------------------
If you're seeing lots of compiler and/or linker error messages,
it's probably because Boost.Build is having trouble finding your
Python installation. You might want to pass the
``--debug-configuration`` option to ``bjam`` the first few times
you invoke it, to make sure that Boost.Build is correctly locating
all the parts of your Python installation. If it isn't, consider
`Configuring Boost.Build`_ as detailed below.
If you're still having trouble, Someone on one of the following
mailing lists may be able to help:
* The `Boost.Build mailing list`__ for issues related to Boost.Build
* The Python `C++ Sig`__ for issues specifically related to Boost.Python
__ ../../../more/mailing_lists.htm#jamboost
__ ../../../more/mailing_lists.htm#cplussig
In Case Everything Seemed to Work
---------------------------------
Rejoice! If you're new to Boost.Python, at this point it might be
a good idea to ignore build issues for a while and concentrate on
learning the library by going through the tutorial_ and perhaps
some of the `reference documentation`_, trying out what you've
learned about the API by modifying the quickstart project.
.. _reference documentation: v2/reference.html
.. _tutorial: tutorial/index.html
Modifying the Example Project
-----------------------------
If you're content to keep your extension module forever in one
source file called |extending.cpp|_, inside your Boost
distribution, and import it forever as ``extending``, then you can
stop here. However, it's likely that you will want to make a few
changes. There are a few things you can do without having to learn
Boost.Build_ in depth.
The project you just built is specified in two files in the current
directory: |boost-build.jam|_, which tells ``bjam`` where it can
find the interpreted code of the Boost build system, and
|Jamroot|_, which describes the targets you just built. These
files are heavily commented, so they should be easy to modify.
Take care, however, to preserve whitespace. Punctuation such as
``;`` will not be recognized as intended by ``bjam`` if it is not
surrounded by whitespace.
.. |boost-build.jam| replace:: ``boost-build.jam``
.. _boost-build.jam: ../example/quickstart/boost-build.jam
.. |Jamroot| replace:: ``Jamroot``
.. _Jamroot: ../example/quickstart/Jamroot
.. |extending.cpp| replace:: ``extending.cpp``
.. _extending.cpp: ../example/quickstart/extending.cpp
Relocate the Project
....................
You'll probably want to copy this project elsewhere so you can
change it without modifying your Boost distribution. To do that,
simply
a. copy the entire ``libs/python/example/quickstart/`` directory
into a new directory.
b. In the new copies of |boost-build.jam|_ and |Jamroot|_, locate
the relative path near the top of the file that is clearly
marked by a comment, and edit that path so that it refers to the
same directory your Boost distribution as it referred to when
the file was in its original location in the
``libs/python/example/quickstart/`` directory.
For example, if you moved the project from
``/home/dave/boost_1_34_0/libs/python/example/quickstart`` to
``/home/dave/my-project``, you could change the first path in
|boost-build.jam|_ from
.. parsed-literal::
**../../../..**\ /tools/build/v2
to
.. parsed-literal::
**/home/dave/boost_1_34_0**\ /tools/build/v2
and change the first path in |Jamroot|_ from
.. parsed-literal::
**../../../..**
to
.. parsed-literal::
**/home/dave/boost_1_34_0**
Add New or Change Names of Existing Source Files
................................................
The names of additional source files involved in building your
extension module or embedding application can be listed in
|Jamroot|_ right alongside ``extending.cpp`` or ``embedding.cpp``
respectively. Just be sure to leave whitespace around each
filename::
… file1.cpp file2.cpp file3.cpp …
Naturally, if you want to change the name of a source file you can
tell Boost.Build about it by editing the name in |Jamroot|_.
Change the Name of your Extension Module
........................................
The name of the extension module is determined by two things:
1. the name in |Jamroot|_ immediately following ``python-extension``, and
2. the name passed to ``BOOST_PYTHON_MODULE`` in |extending.cpp|_.
To change the name of the extension module from ``extending`` to
``hello``, you'd edit |Jamroot|_, changing
.. parsed-literal::
python-extension **extending** : extending.cpp ;
to
.. parsed-literal::
python-extension **hello** : extending.cpp ;
and you'd edit extending.cpp, changing
.. parsed-literal::
BOOST_PYTHON_MODULE(\ **extending**\ )
to
.. parsed-literal::
BOOST_PYTHON_MODULE(\ **hello**\ )
Installing Boost.Python on your System
======================================
Since Boost.Python is a separately-compiled (as opposed to
`header-only`_) library, its user relies on the services of a
Boost.Python library binary.
.. _header-only: ../../../more/getting_started/windows.html#header-only-libraries
If you need a regular installation of the Boost.Python library
binaries on your system, the Boost `Getting Started Guide`_ will
walk you through the steps of creating one. If building binaries
from source, you might want to supply the ``--with-python``
argument to ``bjam`` (or the ``--with-libraries=python`` argument
to ``configure``), so only the Boost.Python binary will be built,
rather than all the Boost binaries.
Configuring Boost.Build
=======================
As described in the `Boost.Build reference manual`__, a file called
``user-config.jam`` in your home directory [#home-dir]_ is used to
specify the tools and libraries available to the build system. You
may need to create or edit ``user-config.jam`` to tell Boost.Build
how to invoke Python, ``#include`` its headers, and link with its
libraries.
__ http://www.boost.orgdoc/html/bbv2/advanced.html#bbv2.advanced.configuration
.. Admonition:: Users of Unix-Variant OSes
If you are using a unix-variant OS and you ran Boost's
``configure`` script, it may have generated a
``user-config.jam`` for you. [#overwrite]_ If your ``configure``\
/\ ``make`` sequence was successful and Boost.Python binaries
were built, your ``user-config.jam`` file is probably already
correct.
If you have one fairly “standard” python installation for your
platform, you might not need to do anything special to describe it. If
you haven't configured python in ``user-config.jam`` (and you don't
specify ``--without-python`` on the Boost.Build command line),
Boost.Build will automatically execute the equivalent of ::
import toolset : using ;
using python ;
which automatically looks for Python in the most likely places.
However, that only happens when using the Boost.Python project file
(e.g. when referred to by another project as in the quickstart_
method). If instead you are linking against separately-compiled
Boost.Python binaries, you should set up a ``user-config.jam`` file
with at least the minimal incantation above.
Python Configuration Parameters
-------------------------------
If you have several versions of Python installed, or Python is
installed in an unusual way, you may want to supply any or all of
the following optional parameters to ``using python``.
version
the version of Python to use. Should be in Major.Minor
format, for example, ``2.3``. Do not include the subminor
version (i.e. *not* ``2.5.1``). If you have multiple Python
versions installed, the version will usually be the only
configuration argument required.
cmd-or-prefix
preferably, a command that invokes a Python interpreter.
Alternatively, the installation prefix for Python libraries and
header files. Only use the alternative formulation if there is
no appropriate Python executable available.
includes
the ``#include`` paths for Python headers. Normally the correct
path(s) will be automatically deduced from ``version`` and/or
``cmd-or-prefix``.
libraries
the path to Python library binaries. On MacOS/Darwin,
you can also pass the path of the Python framework. Normally the
correct path(s) will be automatically deduced from ``version``
and/or ``cmd-or-prefix``.
condition
if specified, should be a set of Boost.Build
properties that are matched against the build configuration when
Boost.Build selects a Python configuration to use. See examples
below for details.
extension-suffix
A string to append to the name of extension
modules before the true filename extension. You almost certainly
don't need to use this. Usually this suffix is only used when
targeting a Windows debug build of Python, and will be set
automatically for you based on the value of the
|python-debugging|_ feature. However, at least one Linux
distribution (Ubuntu Feisty Fawn) has a specially configured
`python-dbg`__ package that claims to use such a suffix.
.. |python-debugging| replace:: ``<python-debugging>``
__ https://wiki.ubuntu.com/PyDbgBuilds
Examples
--------
Note that in the examples below, case and *especially whitespace* are
significant.
- If you have both python 2.5 and python 2.4 installed,
``user-config.jam`` might contain::
using python : 2.5 ; # Make both versions of Python available
using python : 2.4 ; # To build with python 2.4, add python=2.4
# to your command line.
The first version configured (2.5) becomes the default. To build
against python 2.4, add ``python=2.4`` to the ``bjam`` command line.
- If you have python installed in an unusual location, you might
supply the path to the interpreter in the ``cmd-or-prefix``
parameter::
using python : : /usr/local/python-2.6-beta/bin/python ;
- If you have a separate build of Python for use with a particular
toolset, you might supply that toolset in the ``condition``
parameter::
using python ; # use for most toolsets
# Use with Intel C++ toolset
using python
: # version
: c:\\Devel\\Python-2.5-IntelBuild\\PCBuild\\python # cmd-or-prefix
: # includes
: # libraries
: <toolset>intel # condition
;
- If you have downloaded the Python sources and built both the
normal and the “\ `python debugging`_\ ” builds from source on
Windows, you might see::
using python : 2.5 : C:\\src\\Python-2.5\\PCBuild\\python ;
using python : 2.5 : C:\\src\\Python-2.5\\PCBuild\\python_d
: # includes
: # libs
: <python-debugging>on ;
- You can set up your user-config.jam so a bjam built under Windows
can build/test both Windows and Cygwin_ python extensions. Just pass
``<target-os>cygwin`` in the ``condition`` parameter
for the cygwin python installation::
# windows installation
using python ;
# cygwin installation
using python : : c:\\cygwin\\bin\\python2.5 : : : <target-os>cygwin ;
when you put target-os=cygwin in your build request, it should build
with the cygwin version of python: [#flavor]_
bjam target-os=cygwin toolset=gcc
This is supposed to work the other way, too (targeting windows
python with a Cygwin_ bjam) but it seems as though the support in
Boost.Build's toolsets for building that way is broken at the
time of this writing.
- Note that because of `the way Boost.Build currently selects target
alternatives`__, you might have be very explicit in your build
requests. For example, given::
using python : 2.5 ; # a regular windows build
using python : 2.4 : : : : <target-os>cygwin ;
building with ::
bjam target-os=cygwin
will yield an error. Instead, you'll need to write::
bjam target-os=cygwin/python=2.4
.. _Cygwin: http://cygwin.com
__ http://zigzag.cs.msu.su/boost.build/wiki/AlternativeSelection
Choosing a Boost.Python Library Binary
======================================
If—instead of letting Boost.Build construct and link with the right
libraries automatically—you choose to use a pre-built Boost.Python
library, you'll need to think about which one to link with. The
Boost.Python binary comes in both static and dynamic flavors. Take
care to choose the right flavor for your application. [#naming]_
The Dynamic Binary
------------------
The dynamic library is the safest and most-versatile choice:
- A single copy of the library code is used by all extension
modules built with a given toolset. [#toolset-specific]_
- The library contains a type conversion registry. Because one
registry is shared among all extension modules, instances of a
class exposed to Python in one dynamically-loaded extension
module can be passed to functions exposed in another such module.
The Static Binary
-----------------
It might be appropriate to use the static Boost.Python library in
any of the following cases:
- You are extending_ python and the types exposed in your
dynamically-loaded extension module don't need to be used by any
other Boost.Python extension modules, and you don't care if the
core library code is duplicated among them.
- You are embedding_ python in your application and either:
- You are targeting a Unix variant OS other than MacOS or AIX,
where the dynamically-loaded extension modules can “see” the
Boost.Python library symbols that are part of the executable.
- Or, you have statically linked some Boost.Python extension
modules into your application and you don't care if any
dynamically-loaded Boost.Python extension modules are able to
use the types exposed by your statically-linked extension
modules (and vice-versa).
``#include`` Issues
===================
1. If you should ever have occasion to ``#include "python.h"``
directly in a translation unit of a program using Boost.Python,
use ``#include "boost/python/detail/wrap_python.hpp"`` instead.
It handles several issues necessary for use with Boost.Python,
one of which is mentioned in the next section.
2. Be sure not to ``#include`` any system headers before
``wrap_python.hpp``. This restriction is actually imposed by
Python, or more properly, by Python's interaction with your
operating system. See
http://docs.python.org/ext/simpleExample.html for details.
.. _python-debugging:
.. _python debugging:
Python Debugging Builds
=======================
Python can be built in a special “python debugging” configuration
that adds extra checks and instrumentation that can be very useful
for developers of extension modules. The data structures used by
the debugging configuration contain additional members, so **a
Python executable built with python debugging enabled cannot be
used with an extension module or library compiled without it, and
vice-versa.**
Since pre-built “python debugging” versions of the Python
executable and libraries are not supplied with most distributions
of Python, [#get-debug-build]_ and we didn't want to force our users
to build them, Boost.Build does not automatically enable python
debugging in its ``debug`` build variant (which is the default).
Instead there is a special build property called
``python-debugging`` that, when used as a build property, will
define the right preprocessor symbols and select the right
libraries to link with.
On unix-variant platforms, the debugging versions of Python's data
structures will only be used if the symbol ``Py_DEBUG`` is defined.
On many windows compilers, when extension modules are built with
the preprocessor symbol ``_DEBUG``, Python defaults to force
linking with a special debugging version of the Python DLL. Since
that symbol is very commonly used even when Python is not present,
Boost.Python temporarily undefines _DEBUG when Python.h
is #included from ``boost/python/detail/wrap_python.hpp`` - unless
``BOOST_DEBUG_PYTHON`` is defined. The upshot is that if you want
“python debugging”and you aren't using Boost.Build, you should make
sure ``BOOST_DEBUG_PYTHON`` is defined, or python debugging will be
suppressed.
Testing Boost.Python
====================
To run the full test suite for Boost.Python, invoke ``bjam`` in the
``libs/python/test`` subdirectory of your Boost distribution.
Notes for MinGW (and Cygwin with -mno-cygwin) GCC Users
=======================================================
If you are using a version of Python prior to 2.4.1 with a MinGW
prior to 3.0.0 (with binutils-2.13.90-20030111-1), you will need to
create a MinGW-compatible version of the Python library; the one
shipped with Python will only work with a Microsoft-compatible
linker. Follow the instructions in the “Non-Microsoft” section of
the “Building Extensions: Tips And Tricks” chapter in `Installing
Python Modules`__ to create ``libpythonXX.a``, where ``XX``
corresponds to the major and minor version numbers of your Python
installation.
__ http://www.python.org/doc/current/inst/index.html
-----------------------------
.. [#2.2] Note that although we tested earlier versions of
Boost.Python with Python 2.2, and we don't *think* we've done
anything to break compatibility, this release of Boost.Python
may not have been tested with versions of Python earlier than
2.4, so we're not 100% sure that python 2.2 and 2.3 are
supported.
.. [#naming] Information about how to identify the
static and dynamic builds of Boost.Python:
* `on Windows`__
* `on Unix variants`__
__ ../../../more/getting_started/windows.html#library-naming
__ ../../../more/getting_started/unix-variants.html#library-naming
.. [#toolset-specific] Because of the way most \*nix platforms
share symbols among dynamically-loaded objects, I'm not certain
that extension modules built with different compiler toolsets
will always use different copies of the Boost.Python library
when loaded into the same Python instance. Not using different
libraries could be a good thing if the compilers have compatible
ABIs, because extension modules built with the two libraries
would be interoperable. Otherwise, it could spell disaster,
since an extension module and the Boost.Python library would
have different ideas of such things as class layout. I would
appreciate someone doing the experiment to find out what
happens.
.. [#overwrite] ``configure`` overwrites the existing
``user-config.jam`` in your home directory
(if any) after making a backup of the old version.
.. [#flavor] Note that the ``<target-os>cygwin`` feature is
different from the ``<flavor>cygwin`` subfeature of the ``gcc``
toolset, and you might need handle both explicitly if you also
have a MinGW GCC installed.
.. [#home-dir] Windows users, your home directory can be
found by typing::
ECHO %HOMEDRIVE%%HOMEPATH%
into a `command prompt`_ window.
.. [#get-debug-build] On Unix and similar platforms, a debugging
python and associated libraries are built by adding
``--with-pydebug`` when configuring the Python build. On
Windows, the debugging version of Python is generated by
the "Win32 Debug" target of the Visual Studio project in the
PCBuild subdirectory of a full Python source code distribution.
You may also find

View File

@@ -1,5 +1,8 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<!-- Copyright David Abrahams 2006. Distributed under the Boost -->
<!-- Software License, Version 1.0. (See accompanying -->
<!-- file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -->
<html> <html>
<head> <head>
<meta name="generator" content= <meta name="generator" content=
@@ -144,7 +147,9 @@
<dt><a href="v2/faq.html">Frequently Asked Questions (FAQs)</a></dt> <dt><a href="v2/faq.html">Frequently Asked Questions (FAQs)</a></dt>
<dt><a href="../pyste/index.html">Pyste (Boost.Python code generator)</a></dt> <dt><a href="http://www.language-binding.net/pyplusplus/pyplusplus.html">Py++ Boost.Python code generator</a></dt>
<dt><a href="../pyste/index.html">Pyste Boost.Python code generator (no longer maintained)</a></dt>
<dt><a href="internals.html">Internals Documentation</a></dt> <dt><a href="internals.html">Internals Documentation</a></dt>

View File

@@ -1,5 +1,8 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<!-- Copyright David Abrahams 2006. Distributed under the Boost -->
<!-- Software License, Version 1.0. (See accompanying -->
<!-- file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -->
<html> <html>
<head> <head>
<meta name="generator" content= <meta name="generator" content=
@@ -39,6 +42,12 @@
<li>New <a href="v2/docstring_options.html" <li>New <a href="v2/docstring_options.html"
><code>docstring_options.hpp</code></a> header to ><code>docstring_options.hpp</code></a> header to
control the content of docstrings. control the content of docstrings.
<li>Support for converting <code>void*</code> to/from python,
with <code><a
href="v2/opaque.html">opaque_pointer_converter</a></code>
as the return value policy. Thanks to Niall Douglas for the
initial patch.
</ul> </ul>
</dd> </dd>
@@ -210,7 +219,7 @@ BOOST_PYTHON_MODULE(test)
<dd><a href="mailto:Gottfried.Ganssauge-at-haufe.de">Gottfried <dd><a href="mailto:Gottfried.Ganssauge-at-haufe.de">Gottfried
Gan&szlig;auge</a> has contributed <a href= Gan&szlig;auge</a> has contributed <a href=
"v2/opaque_pointer_converter.html">opaque pointer support</a>.<br> "v2/opaque.html">opaque pointer support</a>.<br>
<a href="mailto:nicodemus-at-globalite.com.br">Bruno da Silva de <a href="mailto:nicodemus-at-globalite.com.br">Bruno da Silva de
Oliveira</a> has contributed the exciting <a href= Oliveira</a> has contributed the exciting <a href=
"../pyste/index.html">Pyste</a> ("Pie-steh") package.</dd> "../pyste/index.html">Pyste</a> ("Pie-steh") package.</dd>

View File

@@ -1,3 +1,8 @@
.. Copyright David Abrahams 2006. Distributed under the Boost
.. Software License, Version 1.0. (See accompanying
.. file LICENSE_1_0.txt or copy at
.. http://www.boost.org/LICENSE_1_0.txt)
How Runtime Polymorphism is expressed in Boost.Python: How Runtime Polymorphism is expressed in Boost.Python:
----------------------------------------------------- -----------------------------------------------------

View File

@@ -1,436 +1,445 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<!-- Copyright David Abrahams 2006. Distributed under the Boost -->
<!-- Software License, Version 1.0. (See accompanying -->
<!-- file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -->
<html> <html>
<head> <head>
<meta name="generator" content= <meta name="generator" content=
"HTML Tidy for Cygwin (vers 1st April 2002), see www.w3.org"> "HTML Tidy for Cygwin (vers 1st September 2004), see www.w3.org">
<meta http-equiv="Content-Type" content="text/html; charset="utf-8"> <meta http-equiv="Content-Type" content="text/html">
<link rel="stylesheet" type="text/css" href="boost.css"> <link rel="stylesheet" type="text/css" href="boost.css">
<title>Boost.Python - Projects using Boost.Python</title> <title>Boost.Python - Projects using Boost.Python</title>
</head> </head>
<body link="#0000ff" vlink="#800080"> <body link="#0000FF" vlink="#800080">
<table border="0" cellpadding="7" cellspacing="0" width="100%" summary= <table border="0" cellpadding="7" cellspacing="0" width="100%" summary=
"header"> "header">
<tr> <tr>
<td valign="top" width="300"> <td valign="top" width="300">
<h3><a href="../../../index.htm"><img height="86" width="277" alt= <h3><a href="../../../index.htm"><img height="86" width="277" alt=
"C++ Boost" src="../../../boost.png" border="0"></a></h3> "C++ Boost" src="../../../boost.png" border="0"></a></h3>
</td> </td>
<td valign="top"> <td valign="top">
<h1 align="center"><a href="index.html">Boost.Python</a></h1> <h1 align="center"><a href="index.html">Boost.Python</a></h1>
<h2 align="center">Projects using Boost.Python</h2> <h2 align="center">Projects using Boost.Python</h2>
</td> </td>
</tr> </tr>
</table> </table>
<hr> <hr>
<h2>Introduction</h2> <h2>Introduction</h2>
<p>This is a partial list of projects using Boost.Python. If you are <p>This is a partial list of projects using Boost.Python. If you are using
using Boost.Python as your Python/C++ binding solution, we'd be proud to Boost.Python as your Python/C++ binding solution, we'd be proud to list
list your project on this page. Just <a href= your project on this page. Just <a href=
"mailto:c++-sig@python.org">post</a> a short description of your project "mailto:c++-sig@python.org">post</a> a short description of your project
and how Boost.Python helps you get the job done, and we'll add it to this and how Boost.Python helps you get the job done, and we'll add it to this
page .</p> page .</p>
<hr> <hr>
<h3>Data Analysis</h3> <h3>Data Analysis</h3>
<dl class="page-index"> <dl class="page-index">
<dt><b><a href= <dt><b><a href="http://www.neuralynx.com">NeuraLab</a></b></dt>
"http://www.neuralynx.com">NeuraLab</a></b></dt>
<dd>Neuralab is a data analysis environment specifically tailored for
<dd>Neuralab is a data analysis environment specifically tailored for neural data from <a href="http://www.neuralynx.com">Neuralynx</a>
neural data from <a href="http://www.neuralynx.com">Neuralynx</a> acquisition systems. Neuralab combines presentation quality graphics, a
acquisition systems. Neuralab combines presentation quality graphics, a numerical analysis library, and the <a href=
numerical analysis library, and the <a href= "http://www.python.org">Python</a> scripting engine in a single
"http://www.python.org">Python</a> scripting engine in a single application. With Neuralab, Neuralynx users can perform common analysis
application. With Neuralab, Neuralynx users can perform common analysis tasks with just a few mouse clicks. More advanced users can create custom
tasks with just a few mouse clicks. More advanced users can create Python scripts, which can optionally be assigned to menus and mouse
custom Python scripts, which can optionally be assigned to menus and clicks.</dd>
mouse clicks.</dd> </dl>
</dl>
<dl class="page-index">
<dl class="page-index"> <dt><b>TSLib</b> - <a href="http://www.fortressinv.com">Fortress
<dt><b>TSLib</b> - <a href="http://www.fortressinv.com">Fortress Investment Group LLC</a></dt>
Investment Group LLC</a></dt>
<dd>
<dd> Fortress Investment Group has contracted <a href=
Fortress Investment Group has contracted <a href= "http://www.boost-consulting.com">Boost Consulting</a> to develop core
"http://www.boost-consulting.com">Boost Consulting</a> to develop internal financial analysis tools in C++ and to prepare Python bindings
core internal financial analysis tools in C++ and to prepare Python for them using Boost.Python.
bindings for them using Boost.Python.
<p>Tom Barket of Fortress writes:</p>
<p>Tom Barket of Fortress writes:</p>
<blockquote>
<blockquote> We have a large C++ analytical library specialized for research in
We have a large C++ analytical library specialized for research in finance and economics, built for speed and mission critical
finance and economics, built for speed and mission critical stability. Yet Python offers us the flexibility to test out new ideas
stability. Yet Python offers us the flexibility to test out new quickly and increase the productivity of our time versus working in
ideas quickly and increase the productivity of our time versus C++. There are several key features which make Python stand out. Its
working in C++. There are several key features which make Python elegance, stability, and breadth of resources on the web are all
stand out. Its elegance, stability, and breadth of resources on the valuable, but the most important is its extensibility, due to its
web are all valuable, but the most important is its extensibility, open source transparency. Boost.Python makes Python extensibility
due to its open source transparency. Boost.Python makes Python extremely simple and straightforward, yet preserves a great deal of
extensibility extremely simple and straightforward, yet preserves a power and control.
great deal of power and control. </blockquote>
</blockquote> </dd>
</dd> </dl>
</dl>
<h3>Educational</h3>
<h3>Educational</h3>
<dl class="page-index">
<dl class="page-index"> <dt><a href="http://edu.kde.org/kig"><b>Kig</b></a></dt>
<dt><a href="http://edu.kde.org/kig"><b>Kig</b></a></dt>
<dd>
<dd> <p>KDE Interactive Geometry is a high-school level educational tool,
<p>KDE Interactive Geometry is a high-school level educational tool, built for the KDE desktop. It is a nice tool to let students work with
built for the KDE desktop. It is a nice tool to let students work geometrical constructions. It is meant to be the most intuitive, yet
with geometrical constructions. It is meant to be the most intuitive, featureful application of its kind.</p>
yet featureful application of its kind.</p>
<p>Versions after 0.6.x (will) support objects built by the user
<p>Versions after 0.6.x (will) support objects built by the user himself in the Python language. The exporting of the relevant internal
himself in the Python language. The exporting of the relevant API's were done using Boost.Python, which made the process very
internal API's were done using Boost.Python, which made the process easy.</p>
very easy.</p> </dd>
</dd> </dl>
</dl>
<h3>Enterprise Software</h3>
<h3>Enterprise Software</h3>
<dl class="page-index">
<dl class="page-index"> <dt><b><a href="http://openwbem.sourceforge.net">OpenWBEM</a></b></dt>
<dt><b><a href="http://openwbem.sourceforge.net">OpenWBEM</a></b></dt>
<dd>
<dd> The OpenWBEM project is an effort to develop an open-source
The OpenWBEM project is an effort to develop an open-source implementation of Web Based Enterprise Management suitable for
implementation of Web Based Enterprise Management suitable for commercial and non-commercial application
commercial and non-commercial application
<p><a href="mailto:dnuffer@sco.com">Dan Nuffer</a> writes:</p>
<p><a href="mailto:dnuffer@sco.com">Dan Nuffer</a> writes:</p>
<blockquote>
<blockquote> I'm using Boost.Python to wrap the client API of OpenWBEM.This will
I'm using Boost.Python to wrap the client API of OpenWBEM.This will make it easier to do rapid prototyping, testing, and scripting when
make it easier to do rapid prototyping, testing, and scripting when developing management solutions that use WBEM.
developing management solutions that use WBEM. </blockquote>
</blockquote> </dd>
</dd>
<dt><b><a href="http://www.transversal.com">Metafaq</a></b></dt>
<dt><b><a href="http://www.transversal.com">Metafaq</a></b></dt>
<dd>
<dd> Metafaq, from <a href="http://www.transversal.com">Transversal,
Metafaq, from <a href="http://www.transversal.com">Transversal, Inc.</a>, is an enterprise level online knowledge base management
Inc.</a>, is an enterprise level online knowledge base management system.
system.
<p><a href="mailto:ben.young-at-transversal.com">Ben Young</a>
<p><a href="mailto:ben.young-at-transversal.com">Ben Young</a> writes:</p>
writes:</p>
<blockquote>
<blockquote> Boost.Python is used in an automated process to generate python
Boost.Python is used in an automated process to generate python bindings to our api which is exposed though multiple backends and
bindings to our api which is exposed though multiple backends and frontends. This allows us to write quick tests and bespoke scripts to
frontends. This allows us to write quick tests and bespoke scripts perform one off tasks without having to go through the full
to perform one off tasks without having to go through the full compilation cycle.
compilation cycle. </blockquote>
</blockquote> </dd>
</dd> </dl>
</dl>
<h3>Games</h3>
<h3>Games</h3>
<dl>
<dl> <dt><b><a href="http://www.firaxis.com">Civilization IV</a></b></dt>
<dt><b><a href="http://www.firaxis.com">Civilization IV</a></b></dt> </dl>
</dl>
<blockquote>
<blockquote> &ldquo;The fourth game in the PC strategy series that has sold over five
“The fourth game in the PC strategy series that has million copies, Sid Meier's Civilization IV is a bold step forward for
sold over five million copies, Sid Meier's Civilization IV is a bold the franchise, with spectacular new 3D graphics and all-new single and
step forward for the franchise, with spectacular new 3D graphics and multiplayer content. Civilization IV will also set a new standard for
all-new single and multiplayer content. Civilization IV will also set a user-modification, allowing gamers to create their own add-ons using
new standard for user-modification, allowing gamers to create their own Python and XML.
add-ons using Python and XML.
<p>Sid Meier's Civilization IV will be released for PC in late 2005. For
<p>Sid Meier's Civilization IV will be released for PC in late 2005. more information please visit <a href=
For more information please visit <a href= "http://www.firaxis.com">http://www.firaxis.com</a> or write <a href=
"http://www.firaxis.com">http://www.firaxis.com</a> or write <a href= "mailto:kgilmore@firaxis.com">kgilmore@firaxis.com</a>&rdquo;</p>
"mailto:kgilmore@firaxis.com">kgilmore@firaxis.com</a></p> </blockquote>
</blockquote>
<p>Boost.Python is used as the interface layer between the C++ game code
<p>Boost.Python is used as the interface layer between the C++ game code and Python. Python is used for many purposes in the game, including map
and Python. Python is used for many purposes in the game, including map generation, interface screens, game events, tools, tutorials, etc. Most
generation, interface screens, game events, tools, tutorials, etc. Most high-level game operations have been exposed to Python in order to give
high-level game operations have been exposed to Python in order to give modders the power they need to customize the game.</p>
modders the power they need to customize the game.</p>
<blockquote>
<blockquote> -Mustafa Thamer, Civ4 Lead Programmer
-Mustafa Thamer, Civ4 Lead Programmer </blockquote>
</blockquote>
<dl class="page-index">
<dl class="page-index"> <dt><b><a href="http://vegastrike.sourceforge.net">Vega
<dt><b><a href="http://vegastrike.sourceforge.net">Vega Strike</a></b></dt>
Strike</a></b></dt>
<dd>
<dd> <a href="http://vegastrike.sourceforge.net">Vega Strike</a> is the 3D
<a href="http://vegastrike.sourceforge.net">Vega Strike</a> is the 3D Space Simulator that allows you to trade and bounty hunt in a vast
Space Simulator that allows you to trade and bounty hunt in a vast universe. Players face dangers, decisions, piracy, and aliens.
universe. Players face dangers, decisions, piracy, and aliens.
<p><a href="http://vegastrike.sourceforge.net">Vega Strike</a> has
<p><a href="http://vegastrike.sourceforge.net">Vega Strike</a> has decided to base its scripting on python, using boost as the layer
decided to base its scripting on python, using boost as the layer between the class hierarchy in python and the class hierarchy in C++.
between the class hierarchy in python and the class hierarchy in C++. The result is a very flexible scripting system that treats units as
The result is a very flexible scripting system that treats units as native python classes when designing missions or writing AI's.</p>
native python classes when designing missions or writing AI's.</p>
<p>A large economic and planetary simulation is currently being run in
<p>A large economic and planetary simulation is currently being run the background in python and the results are returned back into C++ in
in the background in python and the results are returned back into the form of various factions' spaceships appearing near worlds that
C++ in the form of various factions' spaceships appearing near worlds they are simulated to be near in python if the player is in the general
that they are simulated to be near in python if the player is in the neighborhood.</p>
general neighborhood.</p> </dd>
</dd> </dl>
</dl>
<h3>Graphics</h3>
<h3>Graphics</h3>
<dl class="page-index">
<dl class="page-index"> <dt><b><a href="http://sourceforge.net/projects/pyosg">OpenSceneGraph
<dt><b><a href="http://sourceforge.net/projects/pyosg">OpenSceneGraph Bindings</a></b></dt>
Bindings</a></b></dt>
<dd><a href="mailto:gideon@computer.org">Gideon May</a> has created a set
<dd><a href="mailto:gideon@computer.org">Gideon May</a> has created a of bindings for <a href=
set of bindings for <a href= "http://www.openscenegraph.org">OpenSceneGraph</a>, a cross-platform
"http://www.openscenegraph.org">OpenSceneGraph</a>, a cross-platform C++/OpenGL library for the real-time visualization.<br>
C++/OpenGL library for the real-time visualization.<br> &nbsp;</dd>
&nbsp;</dd>
<dt><b><a href=
<dt><b><a href= "http://www.slac.stanford.edu/grp/ek/hippodraw/index.html">HippoDraw</a></b></dt>
"http://www.slac.stanford.edu/grp/ek/hippodraw/index.html">HippoDraw</a></b></dt>
<dd>
<dd> HippoDraw is a data analysis environment consisting of a canvas upon
HippoDraw is a data analysis environment consisting of a canvas upon which graphs such as histograms, scattter plots, etc, are prsented. It
which graphs such as histograms, scattter plots, etc, are prsented. has a highly interactive GUI interface, but some things you need to do
It has a highly interactive GUI interface, but some things you need with scripts. HippoDraw can be run as Python extension module so that
to do with scripts. HippoDraw can be run as Python extension module all the manipulation can be done from either Python or the GUI.
so that all the manipulation can be done from either Python or the
GUI. <p>Before the web page came online, <a href=
"mailto:Paul_Kunz@SLAC.Stanford.EDU">Paul F. Kunz</a> wrote:</p>
<p>Before the web page came online, <a href=
"mailto:Paul_Kunz@SLAC.Stanford.EDU">Paul F. Kunz</a> wrote:</p> <blockquote>
Don't have a web page for the project, but the organization's is
<blockquote> <a href=
Don't have a web page for the project, but the organization's is <a "http://www.slac.stanford.edu">http://www.slac.stanford.edu</a> (the
href= first web server site in America, I installed it).
"http://www.slac.stanford.edu">http://www.slac.stanford.edu</a> </blockquote>Which was just too cool a piece of trivia to omit.<br>
(the first web server site in America, I installed it). &nbsp;
</blockquote> </dd>
Which was just too cool a piece of trivia to omit.<br>
&nbsp; <dt><a href="http://www.iplt.org"><b>IPLT</b></a></dt>
</dd>
<dd>
<dt><a href="http://www.iplt.org"><b>IPLT</b></a></dt> <a href="mailto:ansgar.philippsen-at-unibas.ch">Ansgar Philippsen</a>
writes:
<dd>
<a href="mailto:ansgar.philippsen-at-unibas.ch">Ansgar Philippsen</a> <blockquote>
writes: IPLT is an image processing library and toolbox for the structural
biology electron microscopy community. I would call it a
<blockquote> budding/evolving project, since it is currently not in production
IPLT is an image processing library and toolbox for the structural stage, but rather under heavy development. Python is used as the main
biology electron microscopy community. I would call it a scripting/interaction level, but also for rapid prototyping, since
budding/evolving project, since it is currently not in production the underlying C++ class library is pretty much fully exposed via
stage, but rather under heavy development. Python is used as the boost.python (at least the high-level interface). The combined power
main scripting/interaction level, but also for rapid prototyping, of C++ and Python for this project turned out to be just awesome.
since the underlying C++ class library is pretty much fully exposed </blockquote><br>
via boost.python (at least the high-level interface). The combined &nbsp;
power of C++ and Python for this project turned out to be just </dd>
awesome.
</blockquote> <dt><a href=
<br> "http://www.procoders.net/pythonmagick"><b>PythonMagick</b></a></dt>
&nbsp;
</dd> <dd>PythonMagick binds the <a href=
"http://www.graphicsmagick.org">GraphicsMagick</a> image manipulation
<dt><a href= library to Python.<br>
"http://www.procoders.net/pythonmagick"><b>PythonMagick</b></a></dt> &nbsp;</dd>
<dd>PythonMagick binds the <a href= <dt><a href="http://www.vpython.org"><b>VPython</b></a></dt>
"http://www.graphicsmagick.org">GraphicsMagick</a> image manipulation
library to Python.<br> <dd>
&nbsp;</dd> <a href="mailto:Bruce_Sherwood-at-ncsu.edu">Bruce Sherwood</a> writes:
</dl>
<blockquote>
<h3>Scientific Computing</h3> VPython is an extension for Python that makes it easy to create
navigable 3D animations, which are generated as a side effect of
<dl class="page index"> computational code. VPython is used in education for various
<dt><a href="http://camfr.sourceforge.net"><b>CAMFR</b></a></dt> purposes, including teaching physics and programming, but it has also
been used by research scientists to visualize systems or data in 3D.
<dd> </blockquote><br>
CAMFR is a photonics and electromagnetics modelling tool. Python is &nbsp;
used for computational steering. </dd>
</dl>
<p><a href="mailto:Peter.Bienstman@rug.ac.be">Peter Bienstman</a>
writes:</p> <h3>Scientific Computing</h3>
<blockquote> <dl class="page index">
Thanks for providing such a great tool! <dt><a href="http://camfr.sourceforge.net"><b>CAMFR</b></a></dt>
</blockquote>
</dd> <dd>
CAMFR is a photonics and electromagnetics modelling tool. Python is
<dt><a href="http://cctbx.sourceforge.net"><b>cctbx - Computational used for computational steering.
Crystallography Toolbox</b></a></dt>
<p><a href="mailto:Peter.Bienstman@rug.ac.be">Peter Bienstman</a>
<dd> writes:</p>
Computational Crystallography is concerned with the derivation of
atomic models of crystal structures, given experimental X-ray <blockquote>
diffraction data. The cctbx is an open-source library of fundamental Thanks for providing such a great tool!
algorithms for crystallographic computations. The core algorithms are </blockquote>
implemented in C++ and accessed through higher-level Python </dd>
interfaces.
<dt><a href="http://cctbx.sourceforge.net"><b>cctbx - Computational
<p>The cctbx grew together with Boost.Python and is designed from the Crystallography Toolbox</b></a></dt>
ground up as a hybrid Python/C++ system. With one minor exception,
run-time polymorphism is completely handled by Python. C++ <dd>
compile-time polymorphism is used to implement performance critical Computational Crystallography is concerned with the derivation of
algorithms. The Python and C++ layers are seamlessly integrated using atomic models of crystal structures, given experimental X-ray
Boost.Python.</p> diffraction data. The cctbx is an open-source library of fundamental
algorithms for crystallographic computations. The core algorithms are
<p>The SourceForge cctbx project is organized in modules to implemented in C++ and accessed through higher-level Python interfaces.
facilitate use in non-crystallographic applications. The scitbx
module implements a general purpose array family for scientific <p>The cctbx grew together with Boost.Python and is designed from the
applications and pure C++ ports of FFTPACK and the LBFGS conjugate ground up as a hybrid Python/C++ system. With one minor exception,
gradient minimizer.</p> run-time polymorphism is completely handled by Python. C++ compile-time
</dd> polymorphism is used to implement performance critical algorithms. The
Python and C++ layers are seamlessly integrated using Boost.Python.</p>
<dt><a href="http://www.llnl.gov/CASC/emsolve"><b>EMSolve</b></a></dt>
<p>The SourceForge cctbx project is organized in modules to facilitate
<dd>EMSolve is a provably stable, charge conserving, and energy use in non-crystallographic applications. The scitbx module implements
conserving solver for Maxwell's equations.<br> a general purpose array family for scientific applications and pure C++
&nbsp;</dd> ports of FFTPACK and the L-BFGS quasi-Newton minimizer.</p>
</dd>
<dt><b><a href="http://cern.ch/gaudi">Gaudi</a></b> and <b><a href=
"http://cern.ch/Gaudi/RootPython/">RootPython</a></b></dt> <dt><a href="http://www.llnl.gov/CASC/emsolve"><b>EMSolve</b></a></dt>
<dd> <dd>EMSolve is a provably stable, charge conserving, and energy
Gaudi is a framework for particle physics collision data processing conserving solver for Maxwell's equations.<br>
applications developed in the context of the LHCb and ATLAS &nbsp;</dd>
experiments at CERN.
<dt><b><a href="http://cern.ch/gaudi">Gaudi</a></b> and <b><a href=
<p><a href="mailto:Pere.Mato@cern.ch">Pere Mato Vila</a> writes:</p> "http://cern.ch/Gaudi/RootPython/">RootPython</a></b></dt>
<blockquote> <dd>
We are using Boost.Python to provide scripting/interactive Gaudi is a framework for particle physics collision data processing
capability to our framework. We have a module called "GaudiPython" applications developed in the context of the LHCb and ATLAS experiments
implemented using Boost.Python that allows the interaction with any at CERN.
framework service or algorithm from python. RootPython also uses
Boost.Python to provide a generic "gateway" between the <a href= <p><a href="mailto:Pere.Mato@cern.ch">Pere Mato Vila</a> writes:</p>
"http://root.cern.ch">ROOT</a> framework and python
<blockquote>
<p>Boost.Python is great. We managed very quickly to interface our We are using Boost.Python to provide scripting/interactive capability
framework to python, which is great language. We are trying to to our framework. We have a module called "GaudiPython" implemented
facilitate to our physicists (end-users) a rapid analysis using Boost.Python that allows the interaction with any framework
application development environment based on python. For that, service or algorithm from python. RootPython also uses Boost.Python
Boost.Python plays and essential role.</p> to provide a generic "gateway" between the <a href=
</blockquote> "http://root.cern.ch">ROOT</a> framework and python
</dd>
<p>Boost.Python is great. We managed very quickly to interface our
<dt><b><a href="http://www.esss.com.br">ESSS</a></b></dt> framework to python, which is great language. We are trying to
facilitate to our physicists (end-users) a rapid analysis application
<dd> development environment based on python. For that, Boost.Python plays
ESSS (Engineering Simulation and Scientific Software) is a company and essential role.</p>
that provides engineering solutions and acts in the brazilian and </blockquote>
south-american market providing products and services related to </dd>
Computational Fluid Dynamics and Image Analysis.
<dt><b><a href="http://www.esss.com.br">ESSS</a></b></dt>
<p><a href="mailto:bruno@esss.com.br">Bruno da Silva de Oliveira</a>
writes:</p> <dd>
ESSS (Engineering Simulation and Scientific Software) is a company that
<blockquote> provides engineering solutions and acts in the brazilian and
Recently we moved our work from working exclusively with C++ to an south-american market providing products and services related to
hybrid-language approach, using Python and C++, with Boost.Python Computational Fluid Dynamics and Image Analysis.
providing the layer between the two. The results are great so far!
</blockquote> <p><a href="mailto:bruno@esss.com.br">Bruno da Silva de Oliveira</a>
writes:</p>
<p>Two projects have been developed so far with this technology:</p>
<blockquote>
<p><b><a href="http://www.esss.com.br/index.php?pg=dev_projetos">Simba</a></b> Recently we moved our work from working exclusively with C++ to an
provides 3D visualization of geological formations gattered from the hybrid-language approach, using Python and C++, with Boost.Python
simulation of the evolution of oil systems, allowing the user to providing the layer between the two. The results are great so far!
analyse various aspects of the simulation, like deformation, pressure </blockquote>
and fluids, along the time of the simulation.</p>
<p>Two projects have been developed so far with this technology:</p>
<p><b><a href="http://www.esss.com.br/index.php?pg=dev_projetos">Aero</a></b>
aims to construct a CFD with brazilian technology, which involves <p><b><a href=
various companies and universities. ESSS is responsible for various "http://www.esss.com.br/index.php?pg=dev_projetos">Simba</a></b>
of the application modules, including GUI and post-processing of provides 3D visualization of geological formations gattered from the
results.</p> simulation of the evolution of oil systems, allowing the user to
</dd> analyse various aspects of the simulation, like deformation, pressure
and fluids, along the time of the simulation.</p>
<dt><b><a href="http://www.rationaldiscovery.com">Rational Discovery
LLC</a></b></dt> <p><b><a href=
"http://www.esss.com.br/index.php?pg=dev_projetos">Aero</a></b> aims to
<dd> construct a CFD with brazilian technology, which involves various
Rational Discovery provides computational modeling, combinatorial companies and universities. ESSS is responsible for various of the
library design and custom software development services to the application modules, including GUI and post-processing of results.</p>
pharmaceutical, biotech and chemical industries. We do a substantial </dd>
amount of internal research to develop new approaches for applying
machine-learning techniques to solve chemical problems. Because we're <dt><b><a href="http://www.rationaldiscovery.com">Rational Discovery
a small organization and chemistry is a large and complex field, it LLC</a></b></dt>
is essential that we be able to quickly and easily prototype and test
new algorithms. <dd>
Rational Discovery provides computational modeling, combinatorial
<p>For our internal software, we implement core data structures in C library design and custom software development services to the
and expose them to Python using Boost.Python. Algorithm development pharmaceutical, biotech and chemical industries. We do a substantial
is done in Python and then translated to C if required (often it's amount of internal research to develop new approaches for applying
not). This hybrid development approach not only greatly increases our machine-learning techniques to solve chemical problems. Because we're a
productivity, but it also allows "non-developers" (people without C small organization and chemistry is a large and complex field, it is
experience) to take part in method development. Learning C is a essential that we be able to quickly and easily prototype and test new
daunting task, but "Python fits your brain." (Thanks to Bruce Eckel algorithms.
for the quote.)</p>
</dd> <p>For our internal software, we implement core data structures in C
</dl> and expose them to Python using Boost.Python. Algorithm development is
done in Python and then translated to C if required (often it's not).
<h3>Systems Libraries</h3> This hybrid development approach not only greatly increases our
productivity, but it also allows "non-developers" (people without C
<dl> experience) to take part in method development. Learning C is a
<dt><a href="http://itamarst.org/software"><b>Fusion</b></a></dt> daunting task, but "Python fits your brain." (Thanks to Bruce Eckel for
the quote.)</p>
<dd> </dd>
<p>Fusion is a library that supports implementing protocols in C++ </dl>
for use with Twisted, allowing control over memory allocation
strategies, fast method calls internally, etc.. Fusion supports TCP, <h3>Systems Libraries</h3>
UDP and multicast, and is implemented using the Boost.Python python
bindings.</p> <dl>
<dt><a href="http://itamarst.org/software"><b>Fusion</b></a></dt>
<p>Fusion is licensed under the MIT license, and available for
download from <a href= <dd>
"http://itamarst.org/software">http://itamarst.org/software</a>.</p> <p>Fusion is a library that supports implementing protocols in C++ for
</dd> use with Twisted, allowing control over memory allocation strategies,
</dl> fast method calls internally, etc.. Fusion supports TCP, UDP and
multicast, and is implemented using the Boost.Python python
<h3>Tools</h3> bindings.</p>
<dl> <p>Fusion is licensed under the MIT license, and available for download
<dt><a href="http://www.jayacard.org"><b>Jayacard</b></a></dt> from <a href=
"http://itamarst.org/software">http://itamarst.org/software</a>.</p>
<dd> </dd>
Jayacard aims at developing a secure portable open source operating </dl>
system for contactless smart cards and a complete suite of high
quality development tools to ease smart card OS and application <h3>Tools</h3>
development.
<dl>
<p>The core of the smart card reader management is written in C++ but <dt><a href="http://www.jayacard.org"><b>Jayacard</b></a></dt>
all the development tools are written in the friendly Python
language. Boost plays the fundamental role of binding the tools to <dd>
our core smart card reader library.</p> Jayacard aims at developing a secure portable open source operating
</dd> system for contactless smart cards and a complete suite of high quality
</dl> development tools to ease smart card OS and application development.
<hr>
<p>The core of the smart card reader management is written in C++ but
<p>Revised all the development tools are written in the friendly Python language.
<!--webbot bot="Timestamp" S-Type="EDITED" S-Format="%d %B, %Y" startspan --> Boost plays the fundamental role of binding the tools to our core smart
15 July, 2003</p> card reader library.</p>
</dd>
<p><i>&copy; Copyright <a href="../../../people/dave_abrahams.htm">Dave </dl>
Abrahams</a> 2002-2003.</i></p> <hr>
</body>
<p>Revised
<!--webbot bot="Timestamp" S-Type="EDITED" S-Format="%d %B, %Y" startspan -->
15 July, 2003</p>
<p><i>&copy; Copyright <a href="../../../people/dave_abrahams.htm">Dave
Abrahams</a> 2002-2003.</i></p>
</body>
</html> </html>

View File

@@ -1,5 +1,8 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<!-- Copyright David Abrahams 2006. Distributed under the Boost -->
<!-- Software License, Version 1.0. (See accompanying -->
<!-- file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -->
<html> <html>
<head> <head>
<meta name="generator" content= <meta name="generator" content=

View File

@@ -1,3 +1,6 @@
# Copyright Joel de Guzman 2006. Distributed under the Boost
# Software License, Version 1.0. (See accompanying
# file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
project boost/libs/python/doc/tutorial/doc ; project boost/libs/python/doc/tutorial/doc ;
import boostbook : boostbook ; import boostbook : boostbook ;

View File

@@ -23,23 +23,24 @@
p p
{ {
text-align: justify; text-align: left;
font-size: 11pt; font-size: 10pt;
line-height: 1.2; line-height: 1.15;
} }
/*============================================================================= /*=============================================================================
Program listings Program listings
=============================================================================*/ =============================================================================*/
tt.computeroutput /* Code on paragraphs */
p tt.computeroutput
{ {
font-size: 10pt; font-size: 9pt;
} }
pre.synopsis pre.synopsis
{ {
font-size: 10pt; font-size: 90%;
margin: 1pc 4% 0pc 4%; margin: 1pc 4% 0pc 4%;
padding: 0.5pc 0.5pc 0.5pc 0.5pc; padding: 0.5pc 0.5pc 0.5pc 0.5pc;
} }
@@ -47,32 +48,36 @@
.programlisting, .programlisting,
.screen .screen
{ {
font-size: 10pt; font-size: 9pt;
display: block; display: block;
margin: 1pc 4% 0pc 4%; margin: 1pc 4% 0pc 4%;
padding: 0.5pc 0.5pc 0.5pc 0.5pc; padding: 0.5pc 0.5pc 0.5pc 0.5pc;
} }
/* Program listings in tables don't get borders */
td .programlisting,
td .screen
{
margin: 0pc 0pc 0pc 0pc;
padding: 0pc 0pc 0pc 0pc;
}
/*============================================================================= /*=============================================================================
Headings Headings
=============================================================================*/ =============================================================================*/
h1, h1, h2, h3, h4, h5, h6
h2,
h3,
h4,
h5,
h6
{ {
text-align: left; text-align: left;
margin-top: 2pc; margin: 1em 0em 0.5em 0em;
font-weight: bold;
} }
h1 { font: 170% } h1 { font: 140% }
h2 { font: bold 140% } h2 { font: bold 140% }
h3 { font: bold 120% } h3 { font: bold 130% }
h4 { font: bold 100% } h4 { font: bold 120% }
h5 { font: italic 100% } h5 { font: italic 110% }
h6 { font: italic 100% } h6 { font: italic 100% }
/* Top page titles */ /* Top page titles */
@@ -89,12 +94,41 @@
margin-bottom: 1pc; margin-bottom: 1pc;
} }
h1.title { font-size: 220% } h1.title { font-size: 140% }
h2.title { font-size: 220% } h2.title { font-size: 140% }
h3.title { font-size: 170% } h3.title { font-size: 130% }
h4.title { font-size: 140% } h4.title { font-size: 120% }
h5.title { font-size: 120% } h5.title { font-size: 110% }
h6.title { font-size: 120% } h6.title { font-size: 100% }
.section h1
{
margin: 0em 0em 0.5em 0em;
font-size: 140%;
}
.section h2 { font-size: 140% }
.section h3 { font-size: 130% }
.section h4 { font-size: 120% }
.section h5 { font-size: 110% }
.section h6 { font-size: 100% }
/* Code on titles */
h1 tt.computeroutput { font-size: 140% }
h2 tt.computeroutput { font-size: 140% }
h3 tt.computeroutput { font-size: 130% }
h4 tt.computeroutput { font-size: 120% }
h5 tt.computeroutput { font-size: 110% }
h6 tt.computeroutput { font-size: 100% }
/*=============================================================================
Author
=============================================================================*/
h3.author
{
font-size: 100%
}
/*============================================================================= /*=============================================================================
Lists Lists
@@ -102,20 +136,20 @@
li li
{ {
font-size: 11pt; font-size: 10pt;
line-height: 1.3; line-height: 1.3;
} }
/* Unordered lists */ /* Unordered lists */
ul ul
{ {
text-align: justify; text-align: left;
} }
/* Ordered lists */ /* Ordered lists */
ol ol
{ {
text-align: justify; text-align: left;
} }
/*============================================================================= /*=============================================================================
@@ -159,9 +193,9 @@
.toc .toc
{ {
margin: 1pc 4% 0pc 4%; margin: 1pc 4% 0pc 4%;
padding: 0.5pc; padding: 0.1pc 1pc 0.1pc 1pc;
font-size: 11pt; font-size: 80%;
line-height: 1.3; line-height: 1.15;
} }
.boost-toc .boost-toc
@@ -180,7 +214,6 @@
margin-left: 4%; margin-left: 4%;
padding-right: 0.5em; padding-right: 0.5em;
padding-left: 0.5em; padding-left: 0.5em;
font-size: 120%;
} }
.informaltable table, .informaltable table,
@@ -202,8 +235,8 @@
div.table table tr td div.table table tr td
{ {
padding: 0.5em; padding: 0.5em;
text-align: justify; text-align: left;
font-size: 11pt; font-size: 9pt;
} }
div.informaltable table tr th, div.informaltable table tr th,
@@ -211,51 +244,76 @@
{ {
padding: 0.5em 0.5em 0.5em 0.5em; padding: 0.5em 0.5em 0.5em 0.5em;
border: 1pt solid white; border: 1pt solid white;
font-size: 80%;
} }
/*============================================================================= /*=============================================================================
Blurbs Blurbs
=============================================================================*/ =============================================================================*/
div.informaltable table tr td.blurb div.note,
div.tip,
div.important,
div.caution,
div.warning,
p.blurb
{ {
font-size: 10pt; /* A little bit smaller than the main text */ font-size: 9pt; /* A little bit smaller than the main text */
line-height: 1.2; line-height: 1.2;
display: block;
margin: 1pc 4% 0pc 4%;
padding: 0.5pc 0.5pc 0.5pc 0.5pc;
} }
td.blurb img p.blurb img
{ {
padding: 1pt; padding: 1pt;
} }
/*============================================================================= /*=============================================================================
Misc Variable Lists
=============================================================================*/ =============================================================================*/
/* Tone down the title of Parameter lists */ /* Make the terms in definition lists bold */
div.variablelist p.title div.variablelist dl dt,
span.term
{ {
font-weight: bold; font-weight: bold;
font-size: 100%; font-size: 10pt;
text-align: left;
} }
/* Tabularize parameter lists */ div.variablelist table tbody tr td
{
text-align: left;
vertical-align: top;
padding: 0em 2em 0em 0em;
font-size: 10pt;
margin: 0em 0em 0.5em 0em;
line-height: 1;
}
div.variablelist dl dt div.variablelist dl dt
{ {
float: left; margin-bottom: 0.2em;
clear: left;
display: block;
font-style: italic;
} }
div.variablelist dl dd div.variablelist dl dd
{ {
display: block; margin: 0em 0em 0.5em 2em;
clear: right; font-size: 10pt;
padding-left: 8pc;
} }
div.variablelist table tbody tr td p,
div.variablelist dl dd p
{
margin: 0em 0em 0.5em 0em;
line-height: 1;
}
/*=============================================================================
Misc
=============================================================================*/
/* Title of books and articles in bibliographies */ /* Title of books and articles in bibliographies */
span.title span.title
{ {
@@ -294,6 +352,14 @@
{ {
color: #9c5a9c; color: #9c5a9c;
} }
h1 a, h2 a, h3 a, h4 a, h5 a, h6 a,
h1 a:hover, h2 a:hover, h3 a:hover, h4 a:hover, h5 a:hover, h6 a:hover,
h1 a:visited, h2 a:visited, h3 a:visited, h4 a:visited, h5 a:visited, h6 a:visited
{
text-decoration: none; /* no underline */
color: #000000;
}
/* Syntax Highlighting */ /* Syntax Highlighting */
.keyword { color: #0000AA; } .keyword { color: #0000AA; }
@@ -322,41 +388,50 @@
/* Program listing */ /* Program listing */
pre.synopsis pre.synopsis
{ {
background-color: #F3F3F3; border: 1px solid #DCDCDC;
border: 1pt solid #C0C0C0;
} }
.programlisting, .programlisting,
.screen .screen
{ {
background-color: #F3F3F3; border: 1px solid #DCDCDC;
border: 1pt solid #C0C0C0; }
td .programlisting,
td .screen
{
border: 0px solid #DCDCDC;
} }
/* Blurbs */ /* Blurbs */
div.informaltable table tr td.blurb div.note,
div.tip,
div.important,
div.caution,
div.warning,
p.blurb
{ {
background-color: #FFFFF0; border: 1px solid #DCDCDC;
border: 1pt solid #707070;
} }
/* Table of contents */ /* Table of contents */
.toc .toc
{ {
background-color: #F3F3F3; border: 1px solid #DCDCDC;
} }
/* Tables */ /* Tables */
div.informaltable table tr td, div.informaltable table tr td,
div.table table tr td div.table table tr td
{ {
background-color: #F0F0F0; border: 1px solid #DCDCDC;
} }
div.informaltable table tr th, div.informaltable table tr th,
div.table table tr th div.table table tr th
{ {
background-color: #E4E4E4; background-color: #F0F0F0;
border: 1px solid #DCDCDC;
} }
/* Misc */ /* Misc */
@@ -396,6 +471,12 @@
border: 1px solid gray; border: 1px solid gray;
} }
td .programlisting,
td .screen
{
border: 0px solid #DCDCDC;
}
/* Table of contents */ /* Table of contents */
.toc .toc
{ {

View File

@@ -3,13 +3,13 @@
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Chapter 1. python 1.0</title> <title>Chapter 1. python 1.0</title>
<link rel="stylesheet" href="boostbook.css" type="text/css"> <link rel="stylesheet" href="boostbook.css" type="text/css">
<meta name="generator" content="DocBook XSL Stylesheets V1.66.1"> <meta name="generator" content="DocBook XSL Stylesheets V1.72.0">
<link rel="start" href="index.html" title="Chapter 1. python 1.0"> <link rel="start" href="index.html" title="Chapter 1. python 1.0">
<link rel="next" href="python/hello.html" title=" Building Hello World"> <link rel="next" href="python/hello.html" title="Building Hello World">
</head> </head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"> <body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<table cellpadding="2" width="100%"> <table cellpadding="2" width="100%">
<td valign="top"><img alt="boost.png (6897 bytes)" width="277" height="86" src="../../../../../../boost.png"></td> <td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../../../../boost.png"></td>
<td align="center"><a href="../../../../../../index.htm">Home</a></td> <td align="center"><a href="../../../../../../index.htm">Home</a></td>
<td align="center"><a href="../../../../../../libs/libraries.htm">Libraries</a></td> <td align="center"><a href="../../../../../../libs/libraries.htm">Libraries</a></td>
<td align="center"><a href="../../../../../../people/people.htm">People</a></td> <td align="center"><a href="../../../../../../people/people.htm">People</a></td>
@@ -31,7 +31,7 @@
<div><p class="copyright">Copyright © 2002-2005 Joel <div><p class="copyright">Copyright © 2002-2005 Joel
de Guzman, David Abrahams</p></div> de Guzman, David Abrahams</p></div>
<div><div class="legalnotice"> <div><div class="legalnotice">
<a name="id427816"></a><p> <a name="id3128483"></a><p>
Distributed under the Boost Software License, Version 1.0. (See accompanying Distributed under the Boost Software License, Version 1.0. (See accompanying
file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top"> file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">
http://www.boost.org/LICENSE_1_0.txt </a>) http://www.boost.org/LICENSE_1_0.txt </a>)
@@ -83,20 +83,20 @@
<div class="titlepage"><div><div><h2 class="title" style="clear: both"> <div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="python.quickstart"></a>QuickStart</h2></div></div></div> <a name="python.quickstart"></a>QuickStart</h2></div></div></div>
<p> <p>
QuickStartThe Boost Python Library is a framework for interfacing Python and The Boost Python Library is a framework for interfacing Python and C++. It
C++. It allows you to quickly and seamlessly expose C++ classes functions and allows you to quickly and seamlessly expose C++ classes functions and objects
objects to Python, and vice-versa, using no special tools -- just your C++ to Python, and vice-versa, using no special tools -- just your C++ compiler.
compiler. It is designed to wrap C++ interfaces non-intrusively, so that you It is designed to wrap C++ interfaces non-intrusively, so that you should not
should not have to change the C++ code at all in order to wrap it, making Boost.Python have to change the C++ code at all in order to wrap it, making Boost.Python
ideal for exposing 3rd-party libraries to Python. The library's use of advanced ideal for exposing 3rd-party libraries to Python. The library's use of advanced
metaprogramming techniques simplifies its syntax for users, so that wrapping metaprogramming techniques simplifies its syntax for users, so that wrapping
code takes on the look of a kind of declarative interface definition language code takes on the look of a kind of declarative interface definition language
(IDL). (IDL).
</p> </p>
<a name="quickstart.hello_world"></a><h2> <a name="quickstart.hello_world"></a><h3>
<a name="id372244"></a> <a name="id3090903"></a>
Hello World Hello World
</h2> </h3>
<p> <p>
Following C/C++ tradition, let's start with the "hello, world". A Following C/C++ tradition, let's start with the "hello, world". A
C++ Function: C++ Function:
@@ -123,19 +123,23 @@
That's it. We're done. We can now build this as a shared library. The resulting That's it. We're done. We can now build this as a shared library. The resulting
DLL is now visible to Python. Here's a sample Python session: DLL is now visible to Python. Here's a sample Python session:
</p> </p>
<p></p> <p>
</p>
<pre class="programlisting"> <pre class="programlisting">
<span class="special">&gt;&gt;&gt;</span> <span class="keyword">import</span> <span class="identifier">hello</span> <span class="special">&gt;&gt;&gt;</span> <span class="keyword">import</span> <span class="identifier">hello</span>
<span class="special">&gt;&gt;&gt;</span> <span class="keyword">print</span> <span class="identifier">hello</span><span class="special">.</span><span class="identifier">greet</span><span class="special">()</span> <span class="special">&gt;&gt;&gt;</span> <span class="keyword">print</span> <span class="identifier">hello</span><span class="special">.</span><span class="identifier">greet</span><span class="special">()</span>
<span class="identifier">hello</span><span class="special">,</span> <span class="identifier">world</span> <span class="identifier">hello</span><span class="special">,</span> <span class="identifier">world</span>
</pre> </pre>
<p></p> <p>
<div class="blockquote"><blockquote class="blockquote"><p><span class="emphasis"><em><span class="bold"><b>Next stop... Building your Hello World module </p>
from start to finish...</b></span></em></span></p></blockquote></div> <div class="blockquote"><blockquote class="blockquote"><p>
<span class="emphasis"><em><span class="bold"><strong>Next stop... Building your Hello World module
from start to finish...</strong></span></em></span>
</p></blockquote></div>
</div> </div>
</div> </div>
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr> <table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
<td align="left"><small><p>Last revised: October 31, 2005 at 18:46:06 GMT</p></small></td> <td align="left"><small><p>Last revised: May 18, 2007 at 15:45:45 GMT</p></small></td>
<td align="right"><small></small></td> <td align="right"><small></small></td>
</tr></table> </tr></table>
<hr> <hr>

View File

@@ -3,15 +3,15 @@
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Embedding</title> <title>Embedding</title>
<link rel="stylesheet" href="../boostbook.css" type="text/css"> <link rel="stylesheet" href="../boostbook.css" type="text/css">
<meta name="generator" content="DocBook XSL Stylesheets V1.66.1"> <meta name="generator" content="DocBook XSL Stylesheets V1.72.0">
<link rel="start" href="../index.html" title="Chapter 1. python 1.0"> <link rel="start" href="../index.html" title="Chapter 1. python 1.0">
<link rel="up" href="../index.html" title="Chapter 1. python 1.0"> <link rel="up" href="../index.html" title="Chapter 1. python 1.0">
<link rel="prev" href="object.html" title=" Object Interface"> <link rel="prev" href="object.html" title="Object Interface">
<link rel="next" href="iterators.html" title="Iterators"> <link rel="next" href="iterators.html" title="Iterators">
</head> </head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"> <body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<table cellpadding="2" width="100%"> <table cellpadding="2" width="100%">
<td valign="top"><img alt="boost.png (6897 bytes)" width="277" height="86" src="../../../../../../../boost.png"></td> <td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../../../../../boost.png"></td>
<td align="center"><a href="../../../../../../../index.htm">Home</a></td> <td align="center"><a href="../../../../../../../index.htm">Home</a></td>
<td align="center"><a href="../../../../../../../libs/libraries.htm">Libraries</a></td> <td align="center"><a href="../../../../../../../libs/libraries.htm">Libraries</a></td>
<td align="center"><a href="../../../../../../../people/people.htm">People</a></td> <td align="center"><a href="../../../../../../../people/people.htm">People</a></td>
@@ -27,41 +27,40 @@
<a name="python.embedding"></a>Embedding</h2></div></div></div> <a name="python.embedding"></a>Embedding</h2></div></div></div>
<div class="toc"><dl><dt><span class="section"><a href="embedding.html#python.using_the_interpreter">Using the interpreter</a></span></dt></dl></div> <div class="toc"><dl><dt><span class="section"><a href="embedding.html#python.using_the_interpreter">Using the interpreter</a></span></dt></dl></div>
<p> <p>
EmbeddingBy now you should know how to use Boost.Python to call your C++ code By now you should know how to use Boost.Python to call your C++ code from Python.
from Python. However, sometimes you may need to do the reverse: call Python However, sometimes you may need to do the reverse: call Python code from the
code from the C++-side. This requires you to <span class="emphasis"><em>embed</em></span> the C++-side. This requires you to <span class="emphasis"><em>embed</em></span> the Python interpreter
Python interpreter into your C++ program. into your C++ program.
</p> </p>
<p> <p>
Currently, Boost.Python does not directly support everything you'll need when Currently, Boost.Python does not directly support everything you'll need when
embedding. Therefore you'll need to use the <a href="http://www.python.org/doc/current/api/api.html" target="_top">Python/C embedding. Therefore you'll need to use the <a href="http://www.python.org/doc/current/api/api.html" target="_top">Python/C
API</a> to fill in the gaps. However, Boost.Python already makes embedding API</a> to fill in the gaps. However, Boost.Python already makes embedding
a lot easier and, in a future version, it may become unnecessary to touch the a lot easier and, in a future version, it may become unnecessary to touch the
Python/C API at all. So stay tuned... <span class="inlinemediaobject"><img src="../images/smiley.png"></span></p> Python/C API at all. So stay tuned... <span class="inlinemediaobject"><img src="../images/smiley.png" alt="smiley"></span>
<a name="embedding.building_embedded_programs"></a><h2> </p>
<a name="id457321"></a> <a name="embedding.building_embedded_programs"></a><h3>
<a name="id3150903"></a>
Building embedded programs Building embedded programs
</h2> </h3>
<p> <p>
To be able to use embedding in your programs, they have to be linked to both To be able to embed python into your programs, you have to link to both Boost.Python's
Boost.Python's and Python's static link library. as well as Python's own runtime library.
</p> </p>
<p> <p>
Boost.Python's static link library comes in two variants. Both are located Boost.Python's library comes in two variants. Both are located in Boost's
in Boost's <tt class="literal">/libs/python/build/bin-stage</tt> subdirectory. On <code class="literal">/libs/python/build/bin-stage</code> subdirectory. On Windows, the
Windows, the variants are called <tt class="literal">boost_python.lib</tt> (for release variants are called <code class="literal">boost_python.lib</code> (for release builds)
builds) and <tt class="literal">boost_python_debug.lib</tt> (for debugging). If you and <code class="literal">boost_python_debug.lib</code> (for debugging). If you can't
can't find the libraries, you probably haven't built Boost.Python yet. See find the libraries, you probably haven't built Boost.Python yet. See <a href="../../../../building.html" target="_top">Building and Testing</a> on how to do this.
<a href="../../../../building.html" target="_top">Building and Testing</a> on how to
do this.
</p> </p>
<p> <p>
Python's static link library can be found in the <tt class="literal">/libs</tt> subdirectory Python's library can be found in the <code class="literal">/libs</code> subdirectory
of your Python directory. On Windows it is called pythonXY.lib where X.Y is of your Python directory. On Windows it is called pythonXY.lib where X.Y is
your major Python version number. your major Python version number.
</p> </p>
<p> <p>
Additionally, Python's <tt class="literal">/include</tt> subdirectory has to be added Additionally, Python's <code class="literal">/include</code> subdirectory has to be added
to your include path. to your include path.
</p> </p>
<p> <p>
@@ -82,288 +81,156 @@ exe embedded_program # name of the executable
&lt;library-path&gt;$(PYTHON_LIB_PATH) &lt;library-path&gt;$(PYTHON_LIB_PATH)
&lt;find-library&gt;$(PYTHON_EMBEDDED_LIBRARY) ; &lt;find-library&gt;$(PYTHON_EMBEDDED_LIBRARY) ;
</pre> </pre>
<a name="embedding.getting_started"></a><h2> <a name="embedding.getting_started"></a><h3>
<a name="id457409"></a> <a name="id3150996"></a>
Getting started Getting started
</h2> </h3>
<p> <p>
Being able to build is nice, but there is nothing to build yet. Embedding the Being able to build is nice, but there is nothing to build yet. Embedding the
Python interpreter into one of your C++ programs requires these 4 steps: Python interpreter into one of your C++ programs requires these 4 steps:
</p> </p>
<div class="orderedlist"><ol type="1"> <div class="orderedlist"><ol type="1">
<li> <li>
#include <tt class="literal">&lt;boost/python.hpp&gt;</tt><br><br>
#include
 <code class="literal">&lt;boost/python.hpp&gt;</code><br><br>
</li> </li>
<li> <li>
Call <a href="http://www.python.org/doc/current/api/initialization.html#l2h-652" target="_top">Py_Initialize</a>() Call <a href="http://www.python.org/doc/current/api/initialization.html#l2h-652" target="_top">Py_Initialize</a>()
to start the interpreter and create the <tt class="literal"><span class="underline">_main</span>_</tt> to start the interpreter and create the <code class="literal"><span class="underline">_main</span>_</code>
module.<br><br> module.<br><br>
</li> </li>
<li> <li>
Call other Python C API routines to use the interpreter.<br><br> Call other Python C API routines to use the interpreter.<br><br>
</li> </li>
<li>
Call <a href="http://www.python.org/doc/current/api/initialization.html#l2h-656" target="_top">Py_Finalize</a>()
to stop the interpreter and release its resources.
</li>
</ol></div> </ol></div>
<div class="informaltable"><table class="table">
<colgroup><col></colgroup>
<tbody><tr><td class="blurb"> <span class="inlinemediaobject"><img src="../images/note.png" alt="note"></span> <span class="bold"><strong>Note that at this time
you must not call <a href="http://www.python.org/doc/current/api/initialization.html#l2h-656" target="_top">Py_Finalize</a>()
to stop the interpreter. This may be fixed in a future version of boost.python.</strong></span>
</td></tr></tbody>
</table></div>
<p> <p>
(Of course, there can be other C++ code between all of these steps.) (Of course, there can be other C++ code between all of these steps.)
</p> </p>
<div class="blockquote"><blockquote class="blockquote"><p><span class="emphasis"><em><span class="bold"><b>Now that we can embed the interpreter in <div class="blockquote"><blockquote class="blockquote"><p>
our programs, lets see how to put it to use...</b></span></em></span></p></blockquote></div> <span class="emphasis"><em><span class="bold"><strong>Now that we can embed the interpreter in
our programs, lets see how to put it to use...</strong></span></em></span>
</p></blockquote></div>
<div class="section" lang="en"> <div class="section" lang="en">
<div class="titlepage"><div><div><h3 class="title"> <div class="titlepage"><div><div><h3 class="title">
<a name="python.using_the_interpreter"></a>Using the interpreter</h3></div></div></div> <a name="python.using_the_interpreter"></a>Using the interpreter</h3></div></div></div>
<p> <p>
Using the interpreterAs you probably already know, objects in Python are As you probably already know, objects in Python are reference-counted. Naturally,
reference-counted. Naturally, the <tt class="literal">PyObject</tt>s of the Python/C the <code class="literal">PyObject</code>s of the Python/C API are also reference-counted.
API are also reference-counted. There is a difference however. While the There is a difference however. While the reference-counting is fully automatic
reference-counting is fully automatic in Python, the Python/C API requires in Python, the Python/C API requires you to do it <a href="http://www.python.org/doc/current/api/refcounts.html" target="_top">by
you to do it <a href="http://www.python.org/doc/current/api/refcounts.html" target="_top">by
hand</a>. This is messy and especially hard to get right in the presence hand</a>. This is messy and especially hard to get right in the presence
of C++ exceptions. Fortunately Boost.Python provides the <a href="../../../../v2/handle.html" target="_top">handle</a> of C++ exceptions. Fortunately Boost.Python provides the <a href="../../../../v2/handle.html" target="_top">handle</a>
and <a href="../../../../v2/object.html" target="_top">object</a> class templates to and <a href="../../../../v2/object.html" target="_top">object</a> class templates to
automate the process. automate the process.
</p> </p>
<a name="using_the_interpreter.reference_counting_handles_and_objects"></a><h2> <a name="using_the_interpreter.running_python_code"></a><h3>
<a name="id457544"></a> <a name="id3151190"></a>
Reference-counting handles and objects
</h2>
<p>
There are two ways in which a function in the Python/C API can return a
<tt class="literal">PyObject*</tt>: as a <span class="emphasis"><em>borrowed reference</em></span>
or as a <span class="emphasis"><em>new reference</em></span>. Which of these a function uses,
is listed in that function's documentation. The two require slightely different
approaches to reference-counting but both can be 'handled' by Boost.Python.
</p>
<p>
For a function returning a <span class="emphasis"><em>borrowed reference</em></span> we'll
have to tell the <tt class="literal">handle</tt> that the <tt class="literal">PyObject*</tt>
is borrowed with the aptly named <a href="../../../../v2/handle.html#borrowed-spec" target="_top">borrowed</a>
function. Two functions returning borrowed references are <a href="http://www.python.org/doc/current/api/importing.html#l2h-125" target="_top">PyImport_AddModule</a>
and <a href="http://www.python.org/doc/current/api/moduleObjects.html#l2h-594" target="_top">PyModule_GetDict</a>.
The former returns a reference to an already imported module, the latter
retrieves a module's namespace dictionary. Let's use them to retrieve the
namespace of the <tt class="literal"><span class="underline">_main</span>_</tt>
module:
</p>
<pre class="programlisting">
<span class="identifier">object</span> <span class="identifier">main_module</span><span class="special">((</span>
<span class="identifier">handle</span><span class="special">&lt;&gt;(</span><span class="identifier">borrowed</span><span class="special">(</span><a href="http://www.python.org/doc/current/api/importing.html#l2h-125" target="_top">PyImport_AddModule</a><span class="special">(</span><span class="string">"__main__"</span><span class="special">)))));</span>
<span class="identifier">object</span> <span class="identifier">main_namespace</span> <span class="special">=</span> <span class="identifier">main_module</span><span class="special">.</span><span class="identifier">attr</span><span class="special">(</span><span class="string">"__dict__"</span><span class="special">);</span>
</pre>
<p>
For a function returning a <span class="emphasis"><em>new reference</em></span> we can just
create a <tt class="literal">handle</tt> out of the raw <tt class="literal">PyObject*</tt>
without wrapping it in a call to borrowed. One such function that returns
a new reference is <a href="http://www.python.org/doc/current/api/veryhigh.html#l2h-55" target="_top">PyRun_String</a>
which we'll discuss in the next section.
</p>
<div class="informaltable"><table class="table">
<colgroup><col></colgroup>
<tbody><tr><td class="blurb">
<span class="inlinemediaobject"><img src="../images/note.png"></span> <span class="bold"><b>Handle is a class <span class="emphasis"><em>template</em></span>, so why
haven't we been using any template parameters?</b></span><br><br><tt class="literal">handle</tt> has a single template parameter specifying
the type of the managed object. This type is <tt class="literal">PyObject</tt>
99% of the time, so the parameter was defaulted to <tt class="literal">PyObject</tt>
for convenience. Therefore we can use the shorthand <tt class="literal">handle&lt;&gt;</tt>
instead of the longer, but equivalent, <tt class="literal">handle&lt;PyObject&gt;</tt>.
</td></tr></tbody>
</table></div>
<a name="using_the_interpreter.running_python_code"></a><h2>
<a name="id457863"></a>
Running Python code Running Python code
</h2> </h3>
<p> <p>
To run Python code from C++ there is a family of functions in the API starting Boost.python provides three related functions to run Python code from C++.
with the PyRun prefix. You can find the full list of these functions <a href="http://www.python.org/doc/current/api/veryhigh.html" target="_top">here</a>. They
all work similarly so we will look at only one of them, namely:
</p> </p>
<pre class="programlisting"> <pre class="programlisting">
<span class="identifier">PyObject</span><span class="special">*</span> <a href="http://www.python.org/doc/current/api/veryhigh.html#l2h-55" target="_top">PyRun_String</a><span class="special">(</span><span class="keyword">char</span> <span class="special">*</span><span class="identifier">str</span><span class="special">,</span> <span class="keyword">int</span> <span class="identifier">start</span><span class="special">,</span> <span class="identifier">PyObject</span> <span class="special">*</span><span class="identifier">globals</span><span class="special">,</span> <span class="identifier">PyObject</span> <span class="special">*</span><span class="identifier">locals</span><span class="special">)</span> <span class="identifier">object</span> <span class="identifier">eval</span><span class="special">(</span><span class="identifier">str</span> <span class="identifier">expression</span><span class="special">,</span> <span class="identifier">object</span> <span class="identifier">globals</span> <span class="special">=</span> <span class="identifier">object</span><span class="special">(),</span> <span class="identifier">object</span> <span class="identifier">locals</span> <span class="special">=</span> <span class="identifier">object</span><span class="special">())</span>
<span class="identifier">object</span> <span class="identifier">exec</span><span class="special">(</span><span class="identifier">str</span> <span class="identifier">code</span><span class="special">,</span> <span class="identifier">object</span> <span class="identifier">globals</span> <span class="special">=</span> <span class="identifier">object</span><span class="special">(),</span> <span class="identifier">object</span> <span class="identifier">locals</span> <span class="special">=</span> <span class="identifier">object</span><span class="special">())</span>
<span class="identifier">object</span> <span class="identifier">exec_file</span><span class="special">(</span><span class="identifier">str</span> <span class="identifier">filename</span><span class="special">,</span> <span class="identifier">object</span> <span class="identifier">globals</span> <span class="special">=</span> <span class="identifier">object</span><span class="special">(),</span> <span class="identifier">object</span> <span class="identifier">locals</span> <span class="special">=</span> <span class="identifier">object</span><span class="special">())</span>
</pre> </pre>
<p><a href="http://www.python.org/doc/current/api/veryhigh.html#l2h-55" target="_top">PyRun_String</a> <p>
takes the code to execute as a null-terminated (C-style) string in its <tt class="literal">str</tt> eval evaluates the given expression and returns the resulting value. exec
parameter. The function returns a new reference to a Python object. Which executes the given code (typically a set of statements) returning the result,
object is returned depends on the <tt class="literal">start</tt> paramater. and exec_file executes the code contained in the given file.
</p> </p>
<p> <p>
The <tt class="literal">start</tt> parameter is the start symbol from the Python The <code class="literal">globals</code> and <code class="literal">locals</code> parameters are
grammar to use for interpreting the code. The possible values are: Python dictionaries containing the globals and locals of the context in which
</p> to run the code. For most intents and purposes you can use the namespace
<div class="informaltable"> dictionary of the <code class="literal"><span class="underline">_main</span>_</code>
<h4>
<a name="id458033"></a><span class="table-title">Start symbols</span>
</h4>
<table class="table">
<colgroup>
<col>
<col>
</colgroup>
<thead><tr>
<th><a href="http://www.python.org/doc/current/api/veryhigh.html#l2h-58" target="_top">Py_eval_input</a></th>
<th>for
interpreting isolated expressions</th>
</tr></thead>
<tbody>
<tr>
<td><a href="http://www.python.org/doc/current/api/veryhigh.html#l2h-59" target="_top">Py_file_input</a></td>
<td>for
interpreting sequences of statements</td>
</tr>
<tr>
<td><a href="http://www.python.org/doc/current/api/veryhigh.html#l2h-60" target="_top">Py_single_input</a></td>
<td>for
interpreting a single statement</td>
</tr>
</tbody>
</table>
</div>
<p>
When using <a href="http://www.python.org/doc/current/api/veryhigh.html#l2h-58" target="_top">Py_eval_input</a>,
the input string must contain a single expression and its result is returned.
When using <a href="http://www.python.org/doc/current/api/veryhigh.html#l2h-59" target="_top">Py_file_input</a>,
the string can contain an abitrary number of statements and None is returned.
<a href="http://www.python.org/doc/current/api/veryhigh.html#l2h-60" target="_top">Py_single_input</a>
works in the same way as <a href="http://www.python.org/doc/current/api/veryhigh.html#l2h-59" target="_top">Py_file_input</a>
but only accepts a single statement.
</p>
<p>
Lastly, the <tt class="literal">globals</tt> and <tt class="literal">locals</tt> parameters
are Python dictionaries containing the globals and locals of the context
in which to run the code. For most intents and purposes you can use the namespace
dictionary of the <tt class="literal"><span class="underline">_main</span>_</tt>
module for both parameters. module for both parameters.
</p> </p>
<p> <p>
We have already seen how to get the <tt class="literal"><span class="underline">_main</span>_</tt> Boost.python provides a function to import a module:
module's namespace so let's run some Python code in it:
</p> </p>
<pre class="programlisting"> <pre class="programlisting">
<span class="identifier">object</span> <span class="identifier">main_module</span><span class="special">((</span> <span class="identifier">object</span> <span class="identifier">import</span><span class="special">(</span><span class="identifier">str</span> <span class="identifier">name</span><span class="special">)</span>
<span class="identifier">handle</span><span class="special">&lt;&gt;(</span><span class="identifier">borrowed</span><span class="special">(</span><a href="http://www.python.org/doc/current/api/importing.html#l2h-125" target="_top">PyImport_AddModule</a><span class="special">(</span><span class="string">"__main__"</span><span class="special">)))));</span>
<span class="identifier">object</span> <span class="identifier">main_namespace</span> <span class="special">=</span> <span class="identifier">main_module</span><span class="special">.</span><span class="identifier">attr</span><span class="special">(</span><span class="string">"__dict__"</span><span class="special">);</span>
<span class="identifier">handle</span><span class="special">&lt;&gt;</span> <span class="identifier">ignored</span><span class="special">((</span><a href="http://www.python.org/doc/current/api/veryhigh.html#l2h-55" target="_top">PyRun_String</a><span class="special">(</span>
<span class="string">"hello = file('hello.txt', 'w')\n"</span>
<span class="string">"hello.write('Hello world!')\n"</span>
<span class="string">"hello.close()"</span>
<span class="special">,</span> <a href="http://www.python.org/doc/current/api/veryhigh.html#l2h-59" target="_top">Py_file_input</a>
<span class="special">,</span> <span class="identifier">main_namespace</span><span class="special">.</span><span class="identifier">ptr</span><span class="special">()</span>
<span class="special">,</span> <span class="identifier">main_namespace</span><span class="special">.</span><span class="identifier">ptr</span><span class="special">())</span>
<span class="special">));</span>
</pre> </pre>
<p> <p>
Because the Python/C API doesn't know anything about <tt class="literal">object</tt>s, import imports a python module (potentially loading it into the running process
we used the object's <tt class="literal">ptr</tt> member function to retrieve the first), and returns it.
<tt class="literal">PyObject*</tt>.
</p> </p>
<p>
Let's import the <code class="literal"><span class="underline">_main</span>_</code>
module and run some Python code in its namespace:
</p>
<pre class="programlisting">
<span class="identifier">object</span> <span class="identifier">main_module</span> <span class="special">=</span> <span class="identifier">import</span><span class="special">(</span><span class="string">"__main__"</span><span class="special">);</span>
<span class="identifier">object</span> <span class="identifier">main_namespace</span> <span class="special">=</span> <span class="identifier">main_module</span><span class="special">.</span><span class="identifier">attr</span><span class="special">(</span><span class="string">"__dict__"</span><span class="special">);</span>
<span class="identifier">object</span> <span class="identifier">ignored</span> <span class="special">=</span> <span class="identifier">exec</span><span class="special">(</span><span class="string">"hello = file('hello.txt', 'w')\n"</span>
<span class="string">"hello.write('Hello world!')\n"</span>
<span class="string">"hello.close()"</span><span class="special">,</span>
<span class="identifier">main_namespace</span><span class="special">);</span>
</pre>
<p> <p>
This should create a file called 'hello.txt' in the current directory containing This should create a file called 'hello.txt' in the current directory containing
a phrase that is well-known in programming circles. a phrase that is well-known in programming circles.
</p> </p>
<div class="informaltable"><table class="table"> <a name="using_the_interpreter.manipulating_python_objects"></a><h3>
<colgroup><col></colgroup> <a name="id3151717"></a>
<tbody><tr><td class="blurb"> Manipulating Python objects
<span class="inlinemediaobject"><img src="../images/note.png"></span> <span class="bold"><b>Note</b></span> that we wrap the return value of <a href="http://www.python.org/doc/current/api/veryhigh.html#l2h-55" target="_top">PyRun_String</a> </h3>
in a (nameless) <tt class="literal">handle</tt> even though we are not interested
in it. If we didn't do this, the the returned object would be kept
alive unnecessarily. Unless you want to be a Dr. Frankenstein, always
wrap <tt class="literal">PyObject*</tt>s in <tt class="literal">handle</tt>s.
</td></tr></tbody>
</table></div>
<a name="using_the_interpreter.beyond_handles"></a><h2>
<a name="id458506"></a>
Beyond handles
</h2>
<p> <p>
It's nice that <tt class="literal">handle</tt> manages the reference counting details Often we'd like to have a class to manipulate Python objects. But we have
for us, but other than that it doesn't do much. Often we'd like to have a already seen such a class above, and in the <a href="object.html" target="_top">previous
more useful class to manipulate Python objects. But we have already seen section</a>: the aptly named <code class="literal">object</code> class and its
such a class above, and in the <a href="object.html" target="_top">previous section</a>: derivatives. We've already seen that they can be constructed from a <code class="literal">handle</code>.
the aptly named <tt class="literal">object</tt> class and it's derivatives. We've
already seen that they can be constructed from a <tt class="literal">handle</tt>.
The following examples should further illustrate this fact: The following examples should further illustrate this fact:
</p> </p>
<pre class="programlisting"> <pre class="programlisting">
<span class="identifier">object</span> <span class="identifier">main_module</span><span class="special">((</span> <span class="identifier">object</span> <span class="identifier">main_module</span> <span class="special">=</span> <span class="identifier">import</span><span class="special">(</span><span class="string">"__main__"</span><span class="special">);</span>
<span class="identifier">handle</span><span class="special">&lt;&gt;(</span><span class="identifier">borrowed</span><span class="special">(</span><a href="http://www.python.org/doc/current/api/importing.html#l2h-125" target="_top">PyImport_AddModule</a><span class="special">(</span><span class="string">"__main__"</span><span class="special">)))));</span>
<span class="identifier">object</span> <span class="identifier">main_namespace</span> <span class="special">=</span> <span class="identifier">main_module</span><span class="special">.</span><span class="identifier">attr</span><span class="special">(</span><span class="string">"__dict__"</span><span class="special">);</span> <span class="identifier">object</span> <span class="identifier">main_namespace</span> <span class="special">=</span> <span class="identifier">main_module</span><span class="special">.</span><span class="identifier">attr</span><span class="special">(</span><span class="string">"__dict__"</span><span class="special">);</span>
<span class="identifier">object</span> <span class="identifier">ignored</span> <span class="special">=</span> <span class="identifier">exec</span><span class="special">(</span><span class="string">"result = 5 ** 2"</span><span class="special">,</span> <span class="identifier">main_namespace</span><span class="special">);</span>
<span class="identifier">handle</span><span class="special">&lt;&gt;</span> <span class="identifier">ignored</span><span class="special">((</span><a href="http://www.python.org/doc/current/api/veryhigh.html#l2h-55" target="_top">PyRun_String</a><span class="special">(</span>
<span class="string">"result = 5 ** 2"</span>
<span class="special">,</span> <a href="http://www.python.org/doc/current/api/veryhigh.html#l2h-59" target="_top">Py_file_input</a>
<span class="special">,</span> <span class="identifier">main_namespace</span><span class="special">.</span><span class="identifier">ptr</span><span class="special">()</span>
<span class="special">,</span> <span class="identifier">main_namespace</span><span class="special">.</span><span class="identifier">ptr</span><span class="special">())</span>
<span class="special">));</span>
<span class="keyword">int</span> <span class="identifier">five_squared</span> <span class="special">=</span> <span class="identifier">extract</span><span class="special">&lt;</span><span class="keyword">int</span><span class="special">&gt;(</span><span class="identifier">main_namespace</span><span class="special">[</span><span class="string">"result"</span><span class="special">]);</span> <span class="keyword">int</span> <span class="identifier">five_squared</span> <span class="special">=</span> <span class="identifier">extract</span><span class="special">&lt;</span><span class="keyword">int</span><span class="special">&gt;(</span><span class="identifier">main_namespace</span><span class="special">[</span><span class="string">"result"</span><span class="special">]);</span>
</pre> </pre>
<p> <p>
Here we create a dictionary object for the <tt class="literal"><span class="underline">_main</span>_</tt> Here we create a dictionary object for the <code class="literal"><span class="underline">_main</span>_</code>
module's namespace. Then we assign 5 squared to the result variable and read module's namespace. Then we assign 5 squared to the result variable and read
this variable from the dictionary. Another way to achieve the same result this variable from the dictionary. Another way to achieve the same result
is to let <a href="http://www.python.org/doc/current/api/veryhigh.html#l2h-55" target="_top">PyRun_String</a> is to use eval instead, which returns the result directly:
return the result directly with <a href="http://www.python.org/doc/current/api/veryhigh.html#l2h-58" target="_top">Py_eval_input</a>:
</p> </p>
<pre class="programlisting"> <pre class="programlisting">
<span class="identifier">object</span> <span class="identifier">result</span><span class="special">((</span><span class="identifier">handle</span><span class="special">&lt;&gt;(</span> <span class="identifier">object</span> <span class="identifier">result</span> <span class="special">=</span> <span class="identifier">eval</span><span class="special">(</span><span class="string">"5 ** 2"</span><span class="special">);</span>
<a href="http://www.python.org/doc/current/api/veryhigh.html#l2h-55" target="_top">PyRun_String</a><span class="special">(</span><span class="string">"5 ** 2"</span>
<span class="special">,</span> <a href="http://www.python.org/doc/current/api/veryhigh.html#l2h-58" target="_top">Py_eval_input</a>
<span class="special">,</span> <span class="identifier">main_namespace</span><span class="special">.</span><span class="identifier">ptr</span><span class="special">()</span>
<span class="special">,</span> <span class="identifier">main_namespace</span><span class="special">.</span><span class="identifier">ptr</span><span class="special">()))</span>
<span class="special">));</span>
<span class="keyword">int</span> <span class="identifier">five_squared</span> <span class="special">=</span> <span class="identifier">extract</span><span class="special">&lt;</span><span class="keyword">int</span><span class="special">&gt;(</span><span class="identifier">result</span><span class="special">);</span> <span class="keyword">int</span> <span class="identifier">five_squared</span> <span class="special">=</span> <span class="identifier">extract</span><span class="special">&lt;</span><span class="keyword">int</span><span class="special">&gt;(</span><span class="identifier">result</span><span class="special">);</span>
</pre> </pre>
<div class="informaltable"><table class="table"> <a name="using_the_interpreter.exception_handling"></a><h3>
<colgroup><col></colgroup> <a name="id3152050"></a>
<tbody><tr><td class="blurb">
<span class="inlinemediaobject"><img src="../images/note.png"></span> <span class="bold"><b>Note</b></span> that <tt class="literal">object</tt>'s member
function to return the wrapped <tt class="literal">PyObject*</tt> is called
<tt class="literal">ptr</tt> instead of <tt class="literal">get</tt>. This makes
sense if you take into account the different functions that <tt class="literal">object</tt>
and <tt class="literal">handle</tt> perform. </td></tr></tbody>
</table></div>
<a name="using_the_interpreter.exception_handling"></a><h2>
<a name="id459120"></a>
Exception handling Exception handling
</h2> </h3>
<p> <p>
If an exception occurs in the execution of some Python code, the <a href="http://www.python.org/doc/current/api/veryhigh.html#l2h-55" target="_top">PyRun_String</a> If an exception occurs in the evaluation of the python expression, <a href="../../../../v2/errors.html#error_already_set-spec" target="_top">error_already_set</a>
function returns a null pointer. Constructing a <tt class="literal">handle</tt> is thrown:
out of this null pointer throws <a href="../../../../v2/errors.html#error_already_set-spec" target="_top">error_already_set</a>,
so basically, the Python exception is automatically translated into a C++
exception when using <tt class="literal">handle</tt>:
</p> </p>
<pre class="programlisting"> <pre class="programlisting">
<span class="keyword">try</span> <span class="keyword">try</span>
<span class="special">{</span> <span class="special">{</span>
<span class="identifier">object</span> <span class="identifier">result</span><span class="special">((</span><span class="identifier">handle</span><span class="special">&lt;&gt;(</span><a href="http://www.python.org/doc/current/api/veryhigh.html#l2h-55" target="_top">PyRun_String</a><span class="special">(</span> <span class="identifier">object</span> <span class="identifier">result</span> <span class="special">=</span> <span class="identifier">eval</span><span class="special">(</span><span class="string">"5/0"</span><span class="special">);</span>
<span class="string">"5/0"</span>
<span class="special">,</span> <a href="http://www.python.org/doc/current/api/veryhigh.html#l2h-58" target="_top">Py_eval_input</a>
<span class="special">,</span> <span class="identifier">main_namespace</span><span class="special">.</span><span class="identifier">ptr</span><span class="special">()</span>
<span class="special">,</span> <span class="identifier">main_namespace</span><span class="special">.</span><span class="identifier">ptr</span><span class="special">()))</span>
<span class="special">));</span>
<span class="comment">// execution will never get here: <span class="comment">// execution will never get here:
</span> <span class="keyword">int</span> <span class="identifier">five_divided_by_zero</span> <span class="special">=</span> <span class="identifier">extract</span><span class="special">&lt;</span><span class="keyword">int</span><span class="special">&gt;(</span><span class="identifier">result</span><span class="special">);</span> </span> <span class="keyword">int</span> <span class="identifier">five_divided_by_zero</span> <span class="special">=</span> <span class="identifier">extract</span><span class="special">&lt;</span><span class="keyword">int</span><span class="special">&gt;(</span><span class="identifier">result</span><span class="special">);</span>
<span class="special">}</span> <span class="special">}</span>
<span class="keyword">catch</span><span class="special">(</span><span class="identifier">error_already_set</span><span class="special">)</span> <span class="keyword">catch</span><span class="special">(</span><span class="identifier">error_already_set</span> <span class="keyword">const</span> <span class="special">&amp;)</span>
<span class="special">{</span> <span class="special">{</span>
<span class="comment">// handle the exception in some way <span class="comment">// handle the exception in some way
</span><span class="special">}</span> </span><span class="special">}</span>
</pre> </pre>
<p> <p>
The <tt class="literal">error_already_set</tt> exception class doesn't carry any The <code class="literal">error_already_set</code> exception class doesn't carry any
information in itself. To find out more about the Python exception that occurred, information in itself. To find out more about the Python exception that occurred,
you need to use the <a href="http://www.python.org/doc/api/exceptionHandling.html" target="_top">exception you need to use the <a href="http://www.python.org/doc/api/exceptionHandling.html" target="_top">exception
handling functions</a> of the Python/C API in your catch-statement. This handling functions</a> of the Python/C API in your catch-statement. This
@@ -373,7 +240,7 @@ exe embedded_program # name of the executable
exceptions</a>: exceptions</a>:
</p> </p>
<pre class="programlisting"> <pre class="programlisting">
<span class="keyword">catch</span><span class="special">(</span><span class="identifier">error_already_set</span><span class="special">)</span> <span class="keyword">catch</span><span class="special">(</span><span class="identifier">error_already_set</span> <span class="keyword">const</span> <span class="special">&amp;)</span>
<span class="special">{</span> <span class="special">{</span>
<span class="keyword">if</span> <span class="special">(</span><span class="identifier">PyErr_ExceptionMatches</span><span class="special">(</span><span class="identifier">PyExc_ZeroDivisionError</span><span class="special">))</span> <span class="keyword">if</span> <span class="special">(</span><span class="identifier">PyErr_ExceptionMatches</span><span class="special">(</span><span class="identifier">PyExc_ZeroDivisionError</span><span class="special">))</span>
<span class="special">{</span> <span class="special">{</span>
@@ -390,23 +257,6 @@ exe embedded_program # name of the executable
(To retrieve even more information from the exception you can use some of (To retrieve even more information from the exception you can use some of
the other exception handling functions listed <a href="http://www.python.org/doc/api/exceptionHandling.html" target="_top">here</a>.) the other exception handling functions listed <a href="http://www.python.org/doc/api/exceptionHandling.html" target="_top">here</a>.)
</p> </p>
<p>
If you'd rather not have <tt class="literal">handle</tt> throw a C++ exception
when it is constructed, you can use the <a href="../../../../v2/handle.html#allow_null-spec" target="_top">allow_null</a>
function in the same way you'd use borrowed:
</p>
<pre class="programlisting">
<span class="identifier">handle</span><span class="special">&lt;&gt;</span> <span class="identifier">result</span><span class="special">((</span><span class="identifier">allow_null</span><span class="special">(</span><a href="http://www.python.org/doc/current/api/veryhigh.html#l2h-55" target="_top">PyRun_String</a><span class="special">(</span>
<span class="string">"5/0"</span>
<span class="special">,</span> <a href="http://www.python.org/doc/current/api/veryhigh.html#l2h-58" target="_top">Py_eval_input</a>
<span class="special">,</span> <span class="identifier">main_namespace</span><span class="special">.</span><span class="identifier">ptr</span><span class="special">()</span>
<span class="special">,</span> <span class="identifier">main_namespace</span><span class="special">.</span><span class="identifier">ptr</span><span class="special">()))));</span>
<span class="keyword">if</span> <span class="special">(!</span><span class="identifier">result</span><span class="special">)</span>
<span class="comment">// Python exception occurred
</span><span class="keyword">else</span>
<span class="comment">// everything went okay, it's safe to use the result
</span></pre>
</div> </div>
</div> </div>
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr> <table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>

View File

@@ -1,17 +1,17 @@
<html> <html>
<head> <head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title> Exception Translation</title> <title>Exception Translation</title>
<link rel="stylesheet" href="../boostbook.css" type="text/css"> <link rel="stylesheet" href="../boostbook.css" type="text/css">
<meta name="generator" content="DocBook XSL Stylesheets V1.66.1"> <meta name="generator" content="DocBook XSL Stylesheets V1.72.0">
<link rel="start" href="../index.html" title="Chapter 1. python 1.0"> <link rel="start" href="../index.html" title="Chapter 1. python 1.0">
<link rel="up" href="../index.html" title="Chapter 1. python 1.0"> <link rel="up" href="../index.html" title="Chapter 1. python 1.0">
<link rel="prev" href="iterators.html" title="Iterators"> <link rel="prev" href="iterators.html" title="Iterators">
<link rel="next" href="techniques.html" title=" General Techniques"> <link rel="next" href="techniques.html" title="General Techniques">
</head> </head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"> <body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<table cellpadding="2" width="100%"> <table cellpadding="2" width="100%">
<td valign="top"><img alt="boost.png (6897 bytes)" width="277" height="86" src="../../../../../../../boost.png"></td> <td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../../../../../boost.png"></td>
<td align="center"><a href="../../../../../../../index.htm">Home</a></td> <td align="center"><a href="../../../../../../../index.htm">Home</a></td>
<td align="center"><a href="../../../../../../../libs/libraries.htm">Libraries</a></td> <td align="center"><a href="../../../../../../../libs/libraries.htm">Libraries</a></td>
<td align="center"><a href="../../../../../../../people/people.htm">People</a></td> <td align="center"><a href="../../../../../../../people/people.htm">People</a></td>
@@ -26,10 +26,9 @@
<div class="titlepage"><div><div><h2 class="title" style="clear: both"> <div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="python.exception"></a> Exception Translation</h2></div></div></div> <a name="python.exception"></a> Exception Translation</h2></div></div></div>
<p> <p>
Exception TranslationAll C++ exceptions must be caught at the boundary with All C++ exceptions must be caught at the boundary with Python code. This boundary
Python code. This boundary is the point where C++ meets Python. Boost.Python is the point where C++ meets Python. Boost.Python provides a default exception
provides a default exception handler that translates selected standard exceptions, handler that translates selected standard exceptions, then gives up:
then gives up:
</p> </p>
<pre class="programlisting"> <pre class="programlisting">
<span class="keyword">raise</span> <span class="identifier">RuntimeError</span><span class="special">,</span> <span class="string">'unidentifiable C++ Exception'</span> <span class="keyword">raise</span> <span class="identifier">RuntimeError</span><span class="special">,</span> <span class="string">'unidentifiable C++ Exception'</span>

View File

@@ -1,17 +1,17 @@
<html> <html>
<head> <head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title> Exposing Classes</title> <title>Exposing Classes</title>
<link rel="stylesheet" href="../boostbook.css" type="text/css"> <link rel="stylesheet" href="../boostbook.css" type="text/css">
<meta name="generator" content="DocBook XSL Stylesheets V1.66.1"> <meta name="generator" content="DocBook XSL Stylesheets V1.72.0">
<link rel="start" href="../index.html" title="Chapter 1. python 1.0"> <link rel="start" href="../index.html" title="Chapter 1. python 1.0">
<link rel="up" href="../index.html" title="Chapter 1. python 1.0"> <link rel="up" href="../index.html" title="Chapter 1. python 1.0">
<link rel="prev" href="hello.html" title=" Building Hello World"> <link rel="prev" href="hello.html" title="Building Hello World">
<link rel="next" href="functions.html" title="Functions"> <link rel="next" href="functions.html" title="Functions">
</head> </head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"> <body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<table cellpadding="2" width="100%"> <table cellpadding="2" width="100%">
<td valign="top"><img alt="boost.png (6897 bytes)" width="277" height="86" src="../../../../../../../boost.png"></td> <td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../../../../../boost.png"></td>
<td align="center"><a href="../../../../../../../index.htm">Home</a></td> <td align="center"><a href="../../../../../../../index.htm">Home</a></td>
<td align="center"><a href="../../../../../../../libs/libraries.htm">Libraries</a></td> <td align="center"><a href="../../../../../../../libs/libraries.htm">Libraries</a></td>
<td align="center"><a href="../../../../../../../people/people.htm">People</a></td> <td align="center"><a href="../../../../../../../people/people.htm">People</a></td>
@@ -35,7 +35,7 @@
<dt><span class="section"><a href="exposing.html#python.class_operators_special_functions">Class Operators/Special Functions</a></span></dt> <dt><span class="section"><a href="exposing.html#python.class_operators_special_functions">Class Operators/Special Functions</a></span></dt>
</dl></div> </dl></div>
<p> <p>
Exposing ClassesNow let's expose a C++ class to Python. Now let's expose a C++ class to Python.
</p> </p>
<p> <p>
Consider a C++ class/struct that we want to expose to Python: Consider a C++ class/struct that we want to expose to Python:
@@ -64,12 +64,13 @@
<span class="special">}</span> <span class="special">}</span>
</pre> </pre>
<p> <p>
Here, we wrote a C++ class wrapper that exposes the member functions <tt class="literal">greet</tt> Here, we wrote a C++ class wrapper that exposes the member functions <code class="literal">greet</code>
and <tt class="literal">set</tt>. Now, after building our module as a shared library, and <code class="literal">set</code>. Now, after building our module as a shared library,
we may use our class <tt class="literal">World</tt> in Python. Here's a sample Python we may use our class <code class="literal">World</code> in Python. Here's a sample Python
session: session:
</p> </p>
<p></p> <p>
</p>
<pre class="programlisting"> <pre class="programlisting">
<span class="special">&gt;&gt;&gt;</span> <span class="keyword">import</span> <span class="identifier">hello</span> <span class="special">&gt;&gt;&gt;</span> <span class="keyword">import</span> <span class="identifier">hello</span>
<span class="special">&gt;&gt;&gt;</span> <span class="identifier">planet</span> <span class="special">=</span> <span class="identifier">hello</span><span class="special">.</span><span class="identifier">World</span><span class="special">()</span> <span class="special">&gt;&gt;&gt;</span> <span class="identifier">planet</span> <span class="special">=</span> <span class="identifier">hello</span><span class="special">.</span><span class="identifier">World</span><span class="special">()</span>
@@ -81,10 +82,10 @@
<div class="titlepage"><div><div><h3 class="title"> <div class="titlepage"><div><div><h3 class="title">
<a name="python.constructors"></a>Constructors</h3></div></div></div> <a name="python.constructors"></a>Constructors</h3></div></div></div>
<p> <p>
ConstructorsOur previous example didn't have any explicit constructors. Since Our previous example didn't have any explicit constructors. Since <code class="literal">World</code>
<tt class="literal">World</tt> is declared as a plain struct, it has an implicit is declared as a plain struct, it has an implicit default constructor. Boost.Python
default constructor. Boost.Python exposes the default constructor by default, exposes the default constructor by default, which is why we were able to
which is why we were able to write write
</p> </p>
<pre class="programlisting"> <pre class="programlisting">
<span class="special">&gt;&gt;&gt;</span> <span class="identifier">planet</span> <span class="special">=</span> <span class="identifier">hello</span><span class="special">.</span><span class="identifier">World</span><span class="special">()</span> <span class="special">&gt;&gt;&gt;</span> <span class="identifier">planet</span> <span class="special">=</span> <span class="identifier">hello</span><span class="special">.</span><span class="identifier">World</span><span class="special">()</span>
@@ -93,7 +94,8 @@
We may wish to wrap a class with a non-default constructor. Let us build We may wish to wrap a class with a non-default constructor. Let us build
on our previous example: on our previous example:
</p> </p>
<p></p> <p>
</p>
<pre class="programlisting"> <pre class="programlisting">
<span class="keyword">struct</span> <span class="identifier">World</span> <span class="keyword">struct</span> <span class="identifier">World</span>
<span class="special">{</span> <span class="special">{</span>
@@ -104,9 +106,9 @@
<span class="special">};</span> <span class="special">};</span>
</pre> </pre>
<p> <p>
This time <tt class="literal">World</tt> has no default constructor; our previous This time <code class="literal">World</code> has no default constructor; our previous
wrapping code would fail to compile when the library tried to expose it. wrapping code would fail to compile when the library tried to expose it.
We have to tell <tt class="literal">class_&lt;World&gt;</tt> about the constructor We have to tell <code class="literal">class_&lt;World&gt;</code> about the constructor
we want to expose instead. we want to expose instead.
</p> </p>
<pre class="programlisting"> <pre class="programlisting">
@@ -121,13 +123,14 @@
<span class="special">;</span> <span class="special">;</span>
<span class="special">}</span> <span class="special">}</span>
</pre> </pre>
<p><tt class="literal">init&lt;std::string&gt;()</tt> exposes the constructor taking <p>
in a <tt class="literal">std::string</tt> (in Python, constructors are spelled <code class="literal">init&lt;std::string&gt;()</code> exposes the constructor taking
"<tt class="literal">"<span class="underline">_init</span>_"</tt>"). in a <code class="literal">std::string</code> (in Python, constructors are spelled
"<code class="literal">"<span class="underline">_init</span>_"</code>").
</p> </p>
<p> <p>
We can expose additional constructors by passing more <tt class="literal">init&lt;...&gt;</tt>s We can expose additional constructors by passing more <code class="literal">init&lt;...&gt;</code>s
to the <tt class="literal">def()</tt> member function. Say for example we have to the <code class="literal">def()</code> member function. Say for example we have
another World constructor taking in two doubles: another World constructor taking in two doubles:
</p> </p>
<pre class="programlisting"> <pre class="programlisting">
@@ -139,13 +142,13 @@
</pre> </pre>
<p> <p>
On the other hand, if we do not wish to expose any constructors at all, we On the other hand, if we do not wish to expose any constructors at all, we
may use <tt class="literal">no_init</tt> instead: may use <code class="literal">no_init</code> instead:
</p> </p>
<pre class="programlisting"> <pre class="programlisting">
<span class="identifier">class_</span><span class="special">&lt;</span><span class="identifier">Abstract</span><span class="special">&gt;(</span><span class="string">"Abstract"</span><span class="special">,</span> <span class="identifier">no_init</span><span class="special">)</span> <span class="identifier">class_</span><span class="special">&lt;</span><span class="identifier">Abstract</span><span class="special">&gt;(</span><span class="string">"Abstract"</span><span class="special">,</span> <span class="identifier">no_init</span><span class="special">)</span>
</pre> </pre>
<p> <p>
This actually adds an <tt class="literal"><span class="underline">_init</span>_</tt> This actually adds an <code class="literal"><span class="underline">_init</span>_</code>
method which always raises a Python RuntimeError exception. method which always raises a Python RuntimeError exception.
</p> </p>
</div> </div>
@@ -153,10 +156,10 @@
<div class="titlepage"><div><div><h3 class="title"> <div class="titlepage"><div><div><h3 class="title">
<a name="python.class_data_members"></a>Class Data Members</h3></div></div></div> <a name="python.class_data_members"></a>Class Data Members</h3></div></div></div>
<p> <p>
Class Data MembersData members may also be exposed to Python so that they Data members may also be exposed to Python so that they can be accessed as
can be accessed as attributes of the corresponding Python class. Each data attributes of the corresponding Python class. Each data member that we wish
member that we wish to be exposed may be regarded as <span class="bold"><b>read-only</b></span> to be exposed may be regarded as <span class="bold"><strong>read-only</strong></span>
or <span class="bold"><b>read-write</b></span>. Consider this class <tt class="literal">Var</tt>: or <span class="bold"><strong>read-write</strong></span>. Consider this class <code class="literal">Var</code>:
</p> </p>
<pre class="programlisting"> <pre class="programlisting">
<span class="keyword">struct</span> <span class="identifier">Var</span> <span class="keyword">struct</span> <span class="identifier">Var</span>
@@ -167,7 +170,7 @@
<span class="special">};</span> <span class="special">};</span>
</pre> </pre>
<p> <p>
Our C++ <tt class="literal">Var</tt> class and its data members can be exposed Our C++ <code class="literal">Var</code> class and its data members can be exposed
to Python: to Python:
</p> </p>
<pre class="programlisting"> <pre class="programlisting">
@@ -179,7 +182,8 @@
Then, in Python, assuming we have placed our Var class inside the namespace Then, in Python, assuming we have placed our Var class inside the namespace
hello as we did before: hello as we did before:
</p> </p>
<p></p> <p>
</p>
<pre class="programlisting"> <pre class="programlisting">
<span class="special">&gt;&gt;&gt;</span> <span class="identifier">x</span> <span class="special">=</span> <span class="identifier">hello</span><span class="special">.</span><span class="identifier">Var</span><span class="special">(</span><span class="string">'pi'</span><span class="special">)</span> <span class="special">&gt;&gt;&gt;</span> <span class="identifier">x</span> <span class="special">=</span> <span class="identifier">hello</span><span class="special">.</span><span class="identifier">Var</span><span class="special">(</span><span class="string">'pi'</span><span class="special">)</span>
<span class="special">&gt;&gt;&gt;</span> <span class="identifier">x</span><span class="special">.</span><span class="identifier">value</span> <span class="special">=</span> <span class="number">3.14</span> <span class="special">&gt;&gt;&gt;</span> <span class="identifier">x</span><span class="special">.</span><span class="identifier">value</span> <span class="special">=</span> <span class="number">3.14</span>
@@ -187,8 +191,8 @@
<span class="identifier">pi</span> <span class="keyword">is</span> <span class="identifier">around</span> <span class="number">3.14</span> <span class="identifier">pi</span> <span class="keyword">is</span> <span class="identifier">around</span> <span class="number">3.14</span>
</pre> </pre>
<p> <p>
Note that <tt class="literal">name</tt> is exposed as <span class="bold"><b>read-only</b></span> Note that <code class="literal">name</code> is exposed as <span class="bold"><strong>read-only</strong></span>
while <tt class="literal">value</tt> is exposed as <span class="bold"><b>read-write</b></span>. while <code class="literal">value</code> is exposed as <span class="bold"><strong>read-write</strong></span>.
</p> </p>
<pre class="programlisting"> <pre class="programlisting">
<span class="special">&gt;&gt;&gt;</span> <span class="identifier">x</span><span class="special">.</span><span class="identifier">name</span> <span class="special">=</span> <span class="string">'e'</span> <span class="comment"># can't change name <span class="special">&gt;&gt;&gt;</span> <span class="identifier">x</span><span class="special">.</span><span class="identifier">name</span> <span class="special">=</span> <span class="string">'e'</span> <span class="comment"># can't change name
@@ -201,13 +205,13 @@
<div class="titlepage"><div><div><h3 class="title"> <div class="titlepage"><div><div><h3 class="title">
<a name="python.class_properties"></a>Class Properties</h3></div></div></div> <a name="python.class_properties"></a>Class Properties</h3></div></div></div>
<p> <p>
Class PropertiesIn C++, classes with public data members are usually frowned In C++, classes with public data members are usually frowned upon. Well designed
upon. Well designed classes that take advantage of encapsulation hide the classes that take advantage of encapsulation hide the class' data members.
class' data members. The only way to access the class' data is through access The only way to access the class' data is through access (getter/setter)
(getter/setter) functions. Access functions expose class properties. Here's functions. Access functions expose class properties. Here's an example:
an example: </p>
<p>
</p> </p>
<p></p>
<pre class="programlisting"> <pre class="programlisting">
<span class="keyword">struct</span> <span class="identifier">Num</span> <span class="keyword">struct</span> <span class="identifier">Num</span>
<span class="special">{</span> <span class="special">{</span>
@@ -220,7 +224,7 @@
<p> <p>
However, in Python attribute access is fine; it doesn't neccessarily break However, in Python attribute access is fine; it doesn't neccessarily break
encapsulation to let users handle attributes directly, because the attributes encapsulation to let users handle attributes directly, because the attributes
can just be a different syntax for a method call. Wrapping our <tt class="literal">Num</tt> can just be a different syntax for a method call. Wrapping our <code class="literal">Num</code>
class using Boost.Python: class using Boost.Python:
</p> </p>
<pre class="programlisting"> <pre class="programlisting">
@@ -231,7 +235,8 @@
<p> <p>
And at last, in Python: And at last, in Python:
</p> </p>
<p></p> <p>
</p>
<pre class="programlisting"> <pre class="programlisting">
<span class="special">&gt;&gt;&gt;</span> <span class="identifier">x</span> <span class="special">=</span> <span class="identifier">Num</span><span class="special">()</span> <span class="special">&gt;&gt;&gt;</span> <span class="identifier">x</span> <span class="special">=</span> <span class="identifier">Num</span><span class="special">()</span>
<span class="special">&gt;&gt;&gt;</span> <span class="identifier">x</span><span class="special">.</span><span class="identifier">value</span> <span class="special">=</span> <span class="number">3.14</span> <span class="special">&gt;&gt;&gt;</span> <span class="identifier">x</span><span class="special">.</span><span class="identifier">value</span> <span class="special">=</span> <span class="number">3.14</span>
@@ -240,11 +245,12 @@
<span class="special">&gt;&gt;&gt;</span> <span class="identifier">x</span><span class="special">.</span><span class="identifier">rovalue</span> <span class="special">=</span> <span class="number">2.17</span> <span class="comment"># error! <span class="special">&gt;&gt;&gt;</span> <span class="identifier">x</span><span class="special">.</span><span class="identifier">rovalue</span> <span class="special">=</span> <span class="number">2.17</span> <span class="comment"># error!
</span></pre> </span></pre>
<p> <p>
Take note that the class property <tt class="literal">rovalue</tt> is exposed as Take note that the class property <code class="literal">rovalue</code> is exposed as
<span class="bold"><b>read-only</b></span> since the <tt class="literal">rovalue</tt> <span class="bold"><strong>read-only</strong></span> since the <code class="literal">rovalue</code>
setter member function is not passed in: setter member function is not passed in:
</p> </p>
<p></p> <p>
</p>
<pre class="programlisting"> <pre class="programlisting">
<span class="special">.</span><span class="identifier">add_property</span><span class="special">(</span><span class="string">"rovalue"</span><span class="special">,</span> <span class="special">&amp;</span><span class="identifier">Num</span><span class="special">::</span><span class="identifier">get</span><span class="special">)</span> <span class="special">.</span><span class="identifier">add_property</span><span class="special">(</span><span class="string">"rovalue"</span><span class="special">,</span> <span class="special">&amp;</span><span class="identifier">Num</span><span class="special">::</span><span class="identifier">get</span><span class="special">)</span>
</pre> </pre>
@@ -253,7 +259,7 @@
<div class="titlepage"><div><div><h3 class="title"> <div class="titlepage"><div><div><h3 class="title">
<a name="python.inheritance"></a>Inheritance</h3></div></div></div> <a name="python.inheritance"></a>Inheritance</h3></div></div></div>
<p> <p>
InheritanceIn the previous examples, we dealt with classes that are not polymorphic. In the previous examples, we dealt with classes that are not polymorphic.
This is not often the case. Much of the time, we will be wrapping polymorphic This is not often the case. Much of the time, we will be wrapping polymorphic
classes and class hierarchies related by inheritance. We will often have classes and class hierarchies related by inheritance. We will often have
to write Boost.Python wrappers for classes that are derived from abstract to write Boost.Python wrappers for classes that are derived from abstract
@@ -267,7 +273,7 @@
<span class="keyword">struct</span> <span class="identifier">Derived</span> <span class="special">:</span> <span class="identifier">Base</span> <span class="special">{};</span> <span class="keyword">struct</span> <span class="identifier">Derived</span> <span class="special">:</span> <span class="identifier">Base</span> <span class="special">{};</span>
</pre> </pre>
<p> <p>
And a set of C++ functions operating on <tt class="literal">Base</tt> and <tt class="literal">Derived</tt> And a set of C++ functions operating on <code class="literal">Base</code> and <code class="literal">Derived</code>
object instances: object instances:
</p> </p>
<pre class="programlisting"> <pre class="programlisting">
@@ -276,7 +282,7 @@
<span class="identifier">Base</span><span class="special">*</span> <span class="identifier">factory</span><span class="special">()</span> <span class="special">{</span> <span class="keyword">return</span> <span class="keyword">new</span> <span class="identifier">Derived</span><span class="special">;</span> <span class="special">}</span> <span class="identifier">Base</span><span class="special">*</span> <span class="identifier">factory</span><span class="special">()</span> <span class="special">{</span> <span class="keyword">return</span> <span class="keyword">new</span> <span class="identifier">Derived</span><span class="special">;</span> <span class="special">}</span>
</pre> </pre>
<p> <p>
We've seen how we can wrap the base class <tt class="literal">Base</tt>: We've seen how we can wrap the base class <code class="literal">Base</code>:
</p> </p>
<pre class="programlisting"> <pre class="programlisting">
<span class="identifier">class_</span><span class="special">&lt;</span><span class="identifier">Base</span><span class="special">&gt;(</span><span class="string">"Base"</span><span class="special">)</span> <span class="identifier">class_</span><span class="special">&lt;</span><span class="identifier">Base</span><span class="special">&gt;(</span><span class="string">"Base"</span><span class="special">)</span>
@@ -284,8 +290,8 @@
<span class="special">;</span> <span class="special">;</span>
</pre> </pre>
<p> <p>
Now we can inform Boost.Python of the inheritance relationship between <tt class="literal">Derived</tt> Now we can inform Boost.Python of the inheritance relationship between <code class="literal">Derived</code>
and its base class <tt class="literal">Base</tt>. Thus: and its base class <code class="literal">Base</code>. Thus:
</p> </p>
<pre class="programlisting"> <pre class="programlisting">
<span class="identifier">class_</span><span class="special">&lt;</span><span class="identifier">Derived</span><span class="special">,</span> <span class="identifier">bases</span><span class="special">&lt;</span><span class="identifier">Base</span><span class="special">&gt;</span> <span class="special">&gt;(</span><span class="string">"Derived"</span><span class="special">)</span> <span class="identifier">class_</span><span class="special">&lt;</span><span class="identifier">Derived</span><span class="special">,</span> <span class="identifier">bases</span><span class="special">&lt;</span><span class="identifier">Base</span><span class="special">&gt;</span> <span class="special">&gt;(</span><span class="string">"Derived"</span><span class="special">)</span>
@@ -301,15 +307,15 @@
member functions) member functions)
</li> </li>
<li> <li>
<span class="bold"><b>If</b></span> Base is polymorphic, <tt class="literal">Derived</tt> <span class="bold"><strong>If</strong></span> Base is polymorphic, <code class="literal">Derived</code>
objects which have been passed to Python via a pointer or reference to objects which have been passed to Python via a pointer or reference to
<tt class="literal">Base</tt> can be passed where a pointer or reference to <code class="literal">Base</code> can be passed where a pointer or reference to
<tt class="literal">Derived</tt> is expected. <code class="literal">Derived</code> is expected.
</li> </li>
</ol></div> </ol></div>
<p> <p>
Now, we shall expose the C++ free functions <tt class="literal">b</tt> and <tt class="literal">d</tt> Now, we shall expose the C++ free functions <code class="literal">b</code> and <code class="literal">d</code>
and <tt class="literal">factory</tt>: and <code class="literal">factory</code>:
</p> </p>
<pre class="programlisting"> <pre class="programlisting">
<span class="identifier">def</span><span class="special">(</span><span class="string">"b"</span><span class="special">,</span> <span class="identifier">b</span><span class="special">);</span> <span class="identifier">def</span><span class="special">(</span><span class="string">"b"</span><span class="special">,</span> <span class="identifier">b</span><span class="special">);</span>
@@ -317,11 +323,11 @@
<span class="identifier">def</span><span class="special">(</span><span class="string">"factory"</span><span class="special">,</span> <span class="identifier">factory</span><span class="special">);</span> <span class="identifier">def</span><span class="special">(</span><span class="string">"factory"</span><span class="special">,</span> <span class="identifier">factory</span><span class="special">);</span>
</pre> </pre>
<p> <p>
Note that free function <tt class="literal">factory</tt> is being used to generate Note that free function <code class="literal">factory</code> is being used to generate
new instances of class <tt class="literal">Derived</tt>. In such cases, we use new instances of class <code class="literal">Derived</code>. In such cases, we use
<tt class="literal">return_value_policy&lt;manage_new_object&gt;</tt> to instruct <code class="literal">return_value_policy&lt;manage_new_object&gt;</code> to instruct
Python to adopt the pointer to <tt class="literal">Base</tt> and hold the instance Python to adopt the pointer to <code class="literal">Base</code> and hold the instance
in a new Python <tt class="literal">Base</tt> object until the the Python object in a new Python <code class="literal">Base</code> object until the the Python object
is destroyed. We shall see more of Boost.Python <a href="functions.html#python.call_policies" title="Call Policies">call is destroyed. We shall see more of Boost.Python <a href="functions.html#python.call_policies" title="Call Policies">call
policies</a> later. policies</a> later.
</p> </p>
@@ -335,9 +341,9 @@
<div class="titlepage"><div><div><h3 class="title"> <div class="titlepage"><div><div><h3 class="title">
<a name="python.class_virtual_functions"></a>Class Virtual Functions</h3></div></div></div> <a name="python.class_virtual_functions"></a>Class Virtual Functions</h3></div></div></div>
<p> <p>
Class Virtual FunctionsIn this section, we shall learn how to make functions In this section, we shall learn how to make functions behave polymorphically
behave polymorphically through virtual functions. Continuing our example, through virtual functions. Continuing our example, let us add a virtual function
let us add a virtual function to our <tt class="literal">Base</tt> class: to our <code class="literal">Base</code> class:
</p> </p>
<pre class="programlisting"> <pre class="programlisting">
<span class="keyword">struct</span> <span class="identifier">Base</span> <span class="keyword">struct</span> <span class="identifier">Base</span>
@@ -350,11 +356,11 @@
One of the goals of Boost.Python is to be minimally intrusive on an existing One of the goals of Boost.Python is to be minimally intrusive on an existing
C++ design. In principle, it should be possible to expose the interface for C++ design. In principle, it should be possible to expose the interface for
a 3rd party library without changing it. It is not ideal to add anything a 3rd party library without changing it. It is not ideal to add anything
to our class <tt class="computeroutput"><span class="identifier">Base</span></tt>. Yet, when to our class <code class="computeroutput"><span class="identifier">Base</span></code>. Yet, when
you have a virtual function that's going to be overridden in Python and called you have a virtual function that's going to be overridden in Python and called
polymorphically <span class="bold"><b>from C++</b></span>, we'll need to polymorphically <span class="bold"><strong>from C++</strong></span>, we'll need to
add some scaffoldings to make things work properly. What we'll do is write add some scaffoldings to make things work properly. What we'll do is write
a class wrapper that derives from <tt class="computeroutput"><span class="identifier">Base</span></tt> a class wrapper that derives from <code class="computeroutput"><span class="identifier">Base</span></code>
that will unintrusively hook into the virtual functions so that a Python that will unintrusively hook into the virtual functions so that a Python
override may be called: override may be called:
</p> </p>
@@ -368,40 +374,41 @@
<span class="special">};</span> <span class="special">};</span>
</pre> </pre>
<p> <p>
Notice too that in addition to inheriting from <tt class="computeroutput"><span class="identifier">Base</span></tt>, Notice too that in addition to inheriting from <code class="computeroutput"><span class="identifier">Base</span></code>,
we also multiply- inherited <tt class="computeroutput"><span class="identifier">wrapper</span><span class="special">&lt;</span><span class="identifier">Base</span><span class="special">&gt;</span></tt> (See <a href="../../../../v2/wrapper.html" target="_top">Wrapper</a>). we also multiply- inherited <code class="computeroutput"><span class="identifier">wrapper</span><span class="special">&lt;</span><span class="identifier">Base</span><span class="special">&gt;</span></code> (See <a href="../../../../v2/wrapper.html" target="_top">Wrapper</a>).
The <tt class="computeroutput"><span class="identifier">wrapper</span></tt> template makes The <code class="computeroutput"><span class="identifier">wrapper</span></code> template makes
the job of wrapping classes that are meant to overridden in Python, easier. the job of wrapping classes that are meant to overridden in Python, easier.
</p> </p>
<div class="informaltable"><table class="table"> <div class="informaltable"><table class="table">
<colgroup><col></colgroup> <colgroup><col></colgroup>
<tbody><tr><td class="blurb"> <tbody><tr><td class="blurb"> <span class="inlinemediaobject"><img src="../images/alert.png" alt="alert"></span> <span class="bold"><strong>MSVC6/7 Workaround</strong></span><br>
<span class="inlinemediaobject"><img src="../images/alert.png"></span> <span class="bold"><b>MSVC6/7 Workaround</b></span><br><br> If you are using <br> If you are using Microsoft Visual C++ 6 or 7, you have to write
Microsoft Visual C++ 6 or 7, you have to write <tt class="computeroutput"><span class="identifier">f</span></tt> <code class="computeroutput"><span class="identifier">f</span></code> as:<br> <br>
as:<br><br><tt class="computeroutput"><span class="keyword">return</span> <span class="identifier">call</span><span class="special">&lt;</span><span class="keyword">int</span><span class="special">&gt;(</span><span class="keyword">this</span><span class="special">-&gt;</span><span class="identifier">get_override</span><span class="special">(</span><span class="string">"f"</span><span class="special">).</span><span class="identifier">ptr</span><span class="special">());</span></tt>.</td></tr></tbody> <code class="computeroutput"><span class="keyword">return</span> <span class="identifier">call</span><span class="special">&lt;</span><span class="keyword">int</span><span class="special">&gt;(</span><span class="keyword">this</span><span class="special">-&gt;</span><span class="identifier">get_override</span><span class="special">(</span><span class="string">"f"</span><span class="special">).</span><span class="identifier">ptr</span><span class="special">());</span></code>.</td></tr></tbody>
</table></div> </table></div>
<p> <p>
BaseWrap's overridden virtual member function <tt class="computeroutput"><span class="identifier">f</span></tt> BaseWrap's overridden virtual member function <code class="computeroutput"><span class="identifier">f</span></code>
in effect calls the corresponding method of the Python object through <tt class="computeroutput"><span class="identifier">get_override</span></tt>. in effect calls the corresponding method of the Python object through <code class="computeroutput"><span class="identifier">get_override</span></code>.
</p> </p>
<p> <p>
Finally, exposing <tt class="computeroutput"><span class="identifier">Base</span></tt>: Finally, exposing <code class="computeroutput"><span class="identifier">Base</span></code>:
</p> </p>
<pre class="programlisting"> <pre class="programlisting">
<span class="identifier">class_</span><span class="special">&lt;</span><span class="identifier">BaseWrap</span><span class="special">,</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">noncopyable</span><span class="special">&gt;(</span><span class="string">"Base"</span><span class="special">)</span> <span class="identifier">class_</span><span class="special">&lt;</span><span class="identifier">BaseWrap</span><span class="special">,</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">noncopyable</span><span class="special">&gt;(</span><span class="string">"Base"</span><span class="special">)</span>
<span class="special">.</span><span class="identifier">def</span><span class="special">(</span><span class="string">"f"</span><span class="special">,</span> <span class="identifier">pure_virtual</span><span class="special">(&amp;</span><span class="identifier">Base</span><span class="special">::</span><span class="identifier">f</span><span class="special">))</span> <span class="special">.</span><span class="identifier">def</span><span class="special">(</span><span class="string">"f"</span><span class="special">,</span> <span class="identifier">pure_virtual</span><span class="special">(&amp;</span><span class="identifier">Base</span><span class="special">::</span><span class="identifier">f</span><span class="special">))</span>
<span class="special">;</span> <span class="special">;</span>
</pre> </pre>
<p><tt class="computeroutput"><span class="identifier">pure_virtual</span></tt> signals Boost.Python <p>
that the function <tt class="computeroutput"><span class="identifier">f</span></tt> is a <code class="computeroutput"><span class="identifier">pure_virtual</span></code> signals Boost.Python
that the function <code class="computeroutput"><span class="identifier">f</span></code> is a
pure virtual function. pure virtual function.
</p> </p>
<div class="informaltable"><table class="table"> <div class="informaltable"><table class="table">
<colgroup><col></colgroup> <colgroup><col></colgroup>
<tbody><tr><td class="blurb"> <tbody><tr><td class="blurb"> <span class="inlinemediaobject"><img src="../images/note.png" alt="note"></span> <span class="bold"><strong>member function and
<span class="inlinemediaobject"><img src="../images/note.png"></span> <span class="bold"><b>member function and methods</b></span><br><br> Python, methods</strong></span><br> <br> Python, like many object oriented languages
like many object oriented languages uses the term <span class="bold"><b>methods</b></span>. uses the term <span class="bold"><strong>methods</strong></span>. Methods correspond
Methods correspond roughly to C++'s <span class="bold"><b>member functions</b></span> roughly to C++'s <span class="bold"><strong>member functions</strong></span>
</td></tr></tbody> </td></tr></tbody>
</table></div> </table></div>
</div> </div>
@@ -409,11 +416,10 @@
<div class="titlepage"><div><div><h3 class="title"> <div class="titlepage"><div><div><h3 class="title">
<a name="python.virtual_functions_with_default_implementations"></a>Virtual Functions with Default Implementations</h3></div></div></div> <a name="python.virtual_functions_with_default_implementations"></a>Virtual Functions with Default Implementations</h3></div></div></div>
<p> <p>
Virtual Functions with Default ImplementationsWe've seen in the previous We've seen in the previous section how classes with pure virtual functions
section how classes with pure virtual functions are wrapped using Boost.Python's are wrapped using Boost.Python's <a href="../../../../v2/wrapper.html" target="_top">class
<a href="../../../../v2/wrapper.html" target="_top">class wrapper</a> facilities. If wrapper</a> facilities. If we wish to wrap <span class="bold"><strong>non</strong></span>-pure-virtual
we wish to wrap <span class="bold"><b>non</b></span>-pure-virtual functions functions instead, the mechanism is a bit different.
instead, the mechanism is a bit different.
</p> </p>
<p> <p>
Recall that in the <a href="exposing.html#python.class_virtual_functions" title="Class Virtual Functions">previous Recall that in the <a href="exposing.html#python.class_virtual_functions" title="Class Virtual Functions">previous
@@ -427,8 +433,8 @@
<span class="special">};</span> <span class="special">};</span>
</pre> </pre>
<p> <p>
had a pure virtual function <tt class="literal">f</tt>. If, however, its member had a pure virtual function <code class="literal">f</code>. If, however, its member
function <tt class="literal">f</tt> was not declared as pure virtual: function <code class="literal">f</code> was not declared as pure virtual:
</p> </p>
<pre class="programlisting"> <pre class="programlisting">
<span class="keyword">struct</span> <span class="identifier">Base</span> <span class="keyword">struct</span> <span class="identifier">Base</span>
@@ -454,16 +460,15 @@
<span class="special">};</span> <span class="special">};</span>
</pre> </pre>
<p> <p>
Notice how we implemented <tt class="computeroutput"><span class="identifier">BaseWrap</span><span class="special">::</span><span class="identifier">f</span></tt>. Now, Notice how we implemented <code class="computeroutput"><span class="identifier">BaseWrap</span><span class="special">::</span><span class="identifier">f</span></code>. Now,
we have to check if there is an override for <tt class="computeroutput"><span class="identifier">f</span></tt>. we have to check if there is an override for <code class="computeroutput"><span class="identifier">f</span></code>.
If none, then we call <tt class="computeroutput"><span class="identifier">Base</span><span class="special">::</span><span class="identifier">f</span><span class="special">()</span></tt>. If none, then we call <code class="computeroutput"><span class="identifier">Base</span><span class="special">::</span><span class="identifier">f</span><span class="special">()</span></code>.
</p> </p>
<div class="informaltable"><table class="table"> <div class="informaltable"><table class="table">
<colgroup><col></colgroup> <colgroup><col></colgroup>
<tbody><tr><td class="blurb"> <tbody><tr><td class="blurb"> <span class="inlinemediaobject"><img src="../images/alert.png" alt="alert"></span> <span class="bold"><strong>MSVC6/7 Workaround</strong></span><br>
<span class="inlinemediaobject"><img src="../images/alert.png"></span> <span class="bold"><b>MSVC6/7 Workaround</b></span><br><br> If you are using <br> If you are using Microsoft Visual C++ 6 or 7, you have to rewrite
Microsoft Visual C++ 6 or 7, you have to rewrite the line with the the line with the <code class="computeroutput"><span class="special">*</span><span class="identifier">note</span><span class="special">*</span></code> as:<br> <br> <code class="computeroutput"><span class="keyword">return</span> <span class="identifier">call</span><span class="special">&lt;</span><span class="keyword">char</span> <span class="keyword">const</span><span class="special">*&gt;(</span><span class="identifier">f</span><span class="special">.</span><span class="identifier">ptr</span><span class="special">());</span></code>.</td></tr></tbody>
<tt class="computeroutput"><span class="special">*</span><span class="identifier">note</span><span class="special">*</span></tt> as:<br><br><tt class="computeroutput"><span class="keyword">return</span> <span class="identifier">call</span><span class="special">&lt;</span><span class="keyword">char</span> <span class="keyword">const</span><span class="special">*&gt;(</span><span class="identifier">f</span><span class="special">.</span><span class="identifier">ptr</span><span class="special">());</span></tt>.</td></tr></tbody>
</table></div> </table></div>
<p> <p>
Finally, exposing: Finally, exposing:
@@ -474,15 +479,16 @@
<span class="special">;</span> <span class="special">;</span>
</pre> </pre>
<p> <p>
Take note that we expose both <tt class="computeroutput"><span class="special">&amp;</span><span class="identifier">Base</span><span class="special">::</span><span class="identifier">f</span></tt> and <tt class="computeroutput"><span class="special">&amp;</span><span class="identifier">BaseWrap</span><span class="special">::</span><span class="identifier">default_f</span></tt>. Boost.Python needs to keep track Take note that we expose both <code class="computeroutput"><span class="special">&amp;</span><span class="identifier">Base</span><span class="special">::</span><span class="identifier">f</span></code> and <code class="computeroutput"><span class="special">&amp;</span><span class="identifier">BaseWrap</span><span class="special">::</span><span class="identifier">default_f</span></code>. Boost.Python needs to keep track
of 1) the dispatch function <tt class="literal">f</tt> and 2) the forwarding function of 1) the dispatch function <code class="literal">f</code> and 2) the forwarding function
to its default implementation <tt class="literal">default_f</tt>. There's a special to its default implementation <code class="literal">default_f</code>. There's a special
<tt class="literal">def</tt> function for this purpose. <code class="literal">def</code> function for this purpose.
</p> </p>
<p> <p>
In Python, the results would be as expected: In Python, the results would be as expected:
</p> </p>
<p></p> <p>
</p>
<pre class="programlisting"> <pre class="programlisting">
<span class="special">&gt;&gt;&gt;</span> <span class="identifier">base</span> <span class="special">=</span> <span class="identifier">Base</span><span class="special">()</span> <span class="special">&gt;&gt;&gt;</span> <span class="identifier">base</span> <span class="special">=</span> <span class="identifier">Base</span><span class="special">()</span>
<span class="special">&gt;&gt;&gt;</span> <span class="keyword">class</span> <span class="identifier">Derived</span><span class="special">(</span><span class="identifier">Base</span><span class="special">):</span> <span class="special">&gt;&gt;&gt;</span> <span class="keyword">class</span> <span class="identifier">Derived</span><span class="special">(</span><span class="identifier">Base</span><span class="special">):</span>
@@ -492,14 +498,14 @@
<span class="special">&gt;&gt;&gt;</span> <span class="identifier">derived</span> <span class="special">=</span> <span class="identifier">Derived</span><span class="special">()</span> <span class="special">&gt;&gt;&gt;</span> <span class="identifier">derived</span> <span class="special">=</span> <span class="identifier">Derived</span><span class="special">()</span>
</pre> </pre>
<p> <p>
Calling <tt class="literal">base.f()</tt>: Calling <code class="literal">base.f()</code>:
</p> </p>
<pre class="programlisting"> <pre class="programlisting">
<span class="special">&gt;&gt;&gt;</span> <span class="identifier">base</span><span class="special">.</span><span class="identifier">f</span><span class="special">()</span> <span class="special">&gt;&gt;&gt;</span> <span class="identifier">base</span><span class="special">.</span><span class="identifier">f</span><span class="special">()</span>
<span class="number">0</span> <span class="number">0</span>
</pre> </pre>
<p> <p>
Calling <tt class="literal">derived.f()</tt>: Calling <code class="literal">derived.f()</code>:
</p> </p>
<pre class="programlisting"> <pre class="programlisting">
<span class="special">&gt;&gt;&gt;</span> <span class="identifier">derived</span><span class="special">.</span><span class="identifier">f</span><span class="special">()</span> <span class="special">&gt;&gt;&gt;</span> <span class="identifier">derived</span><span class="special">.</span><span class="identifier">f</span><span class="special">()</span>
@@ -509,20 +515,21 @@
<div class="section" lang="en"> <div class="section" lang="en">
<div class="titlepage"><div><div><h3 class="title"> <div class="titlepage"><div><div><h3 class="title">
<a name="python.class_operators_special_functions"></a>Class Operators/Special Functions</h3></div></div></div> <a name="python.class_operators_special_functions"></a>Class Operators/Special Functions</h3></div></div></div>
<a name="class_operators_special_functions.class_operators_special_functionspython_operators"></a><h2> <a name="class_operators_special_functions.python_operators"></a><h3>
<a name="id447955"></a> <a name="id3142031"></a>
Class Operators/Special FunctionsPython Operators Python Operators
</h2> </h3>
<p> <p>
C is well known for the abundance of operators. C++ extends this to the extremes C is well known for the abundance of operators. C++ extends this to the extremes
by allowing operator overloading. Boost.Python takes advantage of this and by allowing operator overloading. Boost.Python takes advantage of this and
makes it easy to wrap C++ operator-powered classes. makes it easy to wrap C++ operator-powered classes.
</p> </p>
<p> <p>
Consider a file position class <tt class="literal">FilePos</tt> and a set of operators Consider a file position class <code class="literal">FilePos</code> and a set of operators
that take on FilePos instances: that take on FilePos instances:
</p> </p>
<p></p> <p>
</p>
<pre class="programlisting"> <pre class="programlisting">
<span class="keyword">class</span> <span class="identifier">FilePos</span> <span class="special">{</span> <span class="comment">/*...*/</span> <span class="special">};</span> <span class="keyword">class</span> <span class="identifier">FilePos</span> <span class="special">{</span> <span class="comment">/*...*/</span> <span class="special">};</span>
@@ -551,16 +558,16 @@
<p> <p>
The code snippet above is very clear and needs almost no explanation at all. The code snippet above is very clear and needs almost no explanation at all.
It is virtually the same as the operators' signatures. Just take note that It is virtually the same as the operators' signatures. Just take note that
<tt class="literal">self</tt> refers to FilePos object. Also, not every class <code class="literal">self</code> refers to FilePos object. Also, not every class
<tt class="literal">T</tt> that you might need to interact with in an operator <code class="literal">T</code> that you might need to interact with in an operator
expression is (cheaply) default-constructible. You can use <tt class="literal">other&lt;T&gt;()</tt> expression is (cheaply) default-constructible. You can use <code class="literal">other&lt;T&gt;()</code>
in place of an actual <tt class="literal">T</tt> instance when writing "self in place of an actual <code class="literal">T</code> instance when writing "self
expressions". expressions".
</p> </p>
<a name="class_operators_special_functions.special_methods"></a><h2> <a name="class_operators_special_functions.special_methods"></a><h3>
<a name="id448698"></a> <a name="id3142715"></a>
Special Methods Special Methods
</h2> </h3>
<p> <p>
Python has a few more <span class="emphasis"><em>Special Methods</em></span>. Boost.Python Python has a few more <span class="emphasis"><em>Special Methods</em></span>. Boost.Python
supports all of the standard special method names supported by real Python supports all of the standard special method names supported by real Python
@@ -588,10 +595,8 @@
</p> </p>
<div class="informaltable"><table class="table"> <div class="informaltable"><table class="table">
<colgroup><col></colgroup> <colgroup><col></colgroup>
<tbody><tr><td class="blurb"> <tbody><tr><td class="blurb"> <span class="inlinemediaobject"><img src="../images/note.png" alt="note"></span> What is the business of <code class="computeroutput"><span class="keyword">operator</span><span class="special">&lt;&lt;</span></code>? Well, the method <code class="computeroutput"><span class="identifier">str</span></code> requires the <code class="computeroutput"><span class="keyword">operator</span><span class="special">&lt;&lt;</span></code> to do its work (i.e. <code class="computeroutput"><span class="keyword">operator</span><span class="special">&lt;&lt;</span></code>
<span class="inlinemediaobject"><img src="../images/note.png"></span> is used by the method defined by <code class="computeroutput"><span class="identifier">def</span><span class="special">(</span><span class="identifier">str</span><span class="special">(</span><span class="identifier">self</span><span class="special">))</span></code>.</td></tr></tbody>
What is the business of <tt class="computeroutput"><span class="keyword">operator</span><span class="special">&lt;&lt;</span></tt>? Well, the method <tt class="computeroutput"><span class="identifier">str</span></tt> requires the <tt class="computeroutput"><span class="keyword">operator</span><span class="special">&lt;&lt;</span></tt> to do its work (i.e. <tt class="computeroutput"><span class="keyword">operator</span><span class="special">&lt;&lt;</span></tt>
is used by the method defined by <tt class="computeroutput"><span class="identifier">def</span><span class="special">(</span><span class="identifier">str</span><span class="special">(</span><span class="identifier">self</span><span class="special">))</span></tt>.</td></tr></tbody>
</table></div> </table></div>
</div> </div>
</div> </div>

View File

@@ -3,15 +3,15 @@
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Functions</title> <title>Functions</title>
<link rel="stylesheet" href="../boostbook.css" type="text/css"> <link rel="stylesheet" href="../boostbook.css" type="text/css">
<meta name="generator" content="DocBook XSL Stylesheets V1.66.1"> <meta name="generator" content="DocBook XSL Stylesheets V1.72.0">
<link rel="start" href="../index.html" title="Chapter 1. python 1.0"> <link rel="start" href="../index.html" title="Chapter 1. python 1.0">
<link rel="up" href="../index.html" title="Chapter 1. python 1.0"> <link rel="up" href="../index.html" title="Chapter 1. python 1.0">
<link rel="prev" href="exposing.html" title=" Exposing Classes"> <link rel="prev" href="exposing.html" title="Exposing Classes">
<link rel="next" href="object.html" title=" Object Interface"> <link rel="next" href="object.html" title="Object Interface">
</head> </head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"> <body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<table cellpadding="2" width="100%"> <table cellpadding="2" width="100%">
<td valign="top"><img alt="boost.png (6897 bytes)" width="277" height="86" src="../../../../../../../boost.png"></td> <td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../../../../../boost.png"></td>
<td align="center"><a href="../../../../../../../index.htm">Home</a></td> <td align="center"><a href="../../../../../../../index.htm">Home</a></td>
<td align="center"><a href="../../../../../../../libs/libraries.htm">Libraries</a></td> <td align="center"><a href="../../../../../../../libs/libraries.htm">Libraries</a></td>
<td align="center"><a href="../../../../../../../people/people.htm">People</a></td> <td align="center"><a href="../../../../../../../people/people.htm">People</a></td>
@@ -32,16 +32,18 @@
<dt><span class="section"><a href="functions.html#python.auto_overloading">Auto-Overloading</a></span></dt> <dt><span class="section"><a href="functions.html#python.auto_overloading">Auto-Overloading</a></span></dt>
</dl></div> </dl></div>
<p> <p>
FunctionsIn this chapter, we'll look at Boost.Python powered functions in closer In this chapter, we'll look at Boost.Python powered functions in closer detail.
detail. We shall see some facilities to make exposing C++ functions to Python We shall see some facilities to make exposing C++ functions to Python safe
safe from potential pifalls such as dangling pointers and references. We shall from potential pifalls such as dangling pointers and references. We shall also
also see facilities that will make it even easier for us to expose C++ functions see facilities that will make it even easier for us to expose C++ functions
that take advantage of C++ features such as overloading and default arguments. that take advantage of C++ features such as overloading and default arguments.
</p> </p>
<div class="blockquote"><blockquote class="blockquote"><p><span class="emphasis"><em>Read on...</em></span></p></blockquote></div> <div class="blockquote"><blockquote class="blockquote"><p>
<span class="emphasis"><em>Read on...</em></span>
</p></blockquote></div>
<p> <p>
But before you do, you might want to fire up Python 2.2 or later and type But before you do, you might want to fire up Python 2.2 or later and type
<tt class="literal">&gt;&gt;&gt; import this</tt>. <code class="literal">&gt;&gt;&gt; import this</code>.
</p> </p>
<pre class="programlisting">&gt;&gt;&gt; import this <pre class="programlisting">&gt;&gt;&gt; import this
The Zen of Python, by Tim Peters The Zen of Python, by Tim Peters
@@ -60,7 +62,7 @@ In the face of ambiguity, refuse the temptation to guess.
There should be one-- and preferably only one --obvious way to do it There should be one-- and preferably only one --obvious way to do it
Although that way may not be obvious at first unless you're Dutch. Although that way may not be obvious at first unless you're Dutch.
Now is better than never. Now is better than never.
Although never is often better than <span class="bold"><b>right</b></span> now. Although never is often better than <span class="bold"><strong>right</strong></span> now.
If the implementation is hard to explain, it's a bad idea. If the implementation is hard to explain, it's a bad idea.
If the implementation is easy to explain, it may be a good idea. If the implementation is easy to explain, it may be a good idea.
Namespaces are one honking great idea -- let's do more of those! Namespaces are one honking great idea -- let's do more of those!
@@ -69,15 +71,15 @@ Namespaces are one honking great idea -- let's do more of those!
<div class="titlepage"><div><div><h3 class="title"> <div class="titlepage"><div><div><h3 class="title">
<a name="python.call_policies"></a>Call Policies</h3></div></div></div> <a name="python.call_policies"></a>Call Policies</h3></div></div></div>
<p> <p>
Call PoliciesIn C++, we often deal with arguments and return types such as In C++, we often deal with arguments and return types such as pointers and
pointers and references. Such primitive types are rather, ummmm, low level references. Such primitive types are rather, ummmm, low level and they really
and they really don't tell us much. At the very least, we don't know the don't tell us much. At the very least, we don't know the owner of the pointer
owner of the pointer or the referenced object. No wonder languages such as or the referenced object. No wonder languages such as Java and Python never
Java and Python never deal with such low level entities. In C++, it's usually deal with such low level entities. In C++, it's usually considered a good
considered a good practice to use smart pointers which exactly describe ownership practice to use smart pointers which exactly describe ownership semantics.
semantics. Still, even good C++ interfaces use raw references and pointers Still, even good C++ interfaces use raw references and pointers sometimes,
sometimes, so Boost.Python must deal with them. To do this, it may need your so Boost.Python must deal with them. To do this, it may need your help. Consider
help. Consider the following C++ function: the following C++ function:
</p> </p>
<pre class="programlisting"> <pre class="programlisting">
<span class="identifier">X</span><span class="special">&amp;</span> <span class="identifier">f</span><span class="special">(</span><span class="identifier">Y</span><span class="special">&amp;</span> <span class="identifier">y</span><span class="special">,</span> <span class="identifier">Z</span><span class="special">*</span> <span class="identifier">z</span><span class="special">);</span> <span class="identifier">X</span><span class="special">&amp;</span> <span class="identifier">f</span><span class="special">(</span><span class="identifier">Y</span><span class="special">&amp;</span> <span class="identifier">y</span><span class="special">,</span> <span class="identifier">Z</span><span class="special">*</span> <span class="identifier">z</span><span class="special">);</span>
@@ -118,24 +120,25 @@ Namespaces are one honking great idea -- let's do more of those!
</p> </p>
<div class="orderedlist"><ol type="1"> <div class="orderedlist"><ol type="1">
<li> <li>
<tt class="literal">f</tt> is called passing in a reference to <tt class="literal">y</tt> <code class="literal">f</code> is called passing in a reference to <code class="literal">y</code>
and a pointer to <tt class="literal">z</tt> and a pointer to <code class="literal">z</code>
</li> </li>
<li> <li>
A reference to <tt class="literal">y.x</tt> is returned A reference to <code class="literal">y.x</code> is returned
</li> </li>
<li> <li>
<tt class="literal">y</tt> is deleted. <tt class="literal">x</tt> is a dangling reference <code class="literal">y</code> is deleted. <code class="literal">x</code> is a dangling reference
</li> </li>
<li> <li>
<tt class="literal">x.some_method()</tt> is called <code class="literal">x.some_method()</code> is called
</li> </li>
<li><span class="bold"><b>BOOM!</b></span></li> <li><span class="bold"><strong>BOOM!</strong></span></li>
</ol></div> </ol></div>
<p> <p>
We could copy result into a new object: We could copy result into a new object:
</p> </p>
<p></p> <p>
</p>
<pre class="programlisting"> <pre class="programlisting">
<span class="special">&gt;&gt;&gt;</span> <span class="identifier">f</span><span class="special">(</span><span class="identifier">y</span><span class="special">,</span> <span class="identifier">z</span><span class="special">).</span><span class="identifier">set</span><span class="special">(</span><span class="number">42</span><span class="special">)</span> <span class="comment"># Result disappears <span class="special">&gt;&gt;&gt;</span> <span class="identifier">f</span><span class="special">(</span><span class="identifier">y</span><span class="special">,</span> <span class="identifier">z</span><span class="special">).</span><span class="identifier">set</span><span class="special">(</span><span class="number">42</span><span class="special">)</span> <span class="comment"># Result disappears
</span><span class="special">&gt;&gt;&gt;</span> <span class="identifier">y</span><span class="special">.</span><span class="identifier">x</span><span class="special">.</span><span class="identifier">get</span><span class="special">()</span> <span class="comment"># No crash, but still bad </span><span class="special">&gt;&gt;&gt;</span> <span class="identifier">y</span><span class="special">.</span><span class="identifier">x</span><span class="special">.</span><span class="identifier">get</span><span class="special">()</span> <span class="comment"># No crash, but still bad
@@ -149,7 +152,8 @@ Namespaces are one honking great idea -- let's do more of those!
<p> <p>
Our problems do not end there. Suppose Y is implemented as follows: Our problems do not end there. Suppose Y is implemented as follows:
</p> </p>
<p></p> <p>
</p>
<pre class="programlisting"> <pre class="programlisting">
<span class="keyword">struct</span> <span class="identifier">Y</span> <span class="keyword">struct</span> <span class="identifier">Y</span>
<span class="special">{</span> <span class="special">{</span>
@@ -158,7 +162,7 @@ Namespaces are one honking great idea -- let's do more of those!
<span class="special">};</span> <span class="special">};</span>
</pre> </pre>
<p> <p>
Notice that the data member <tt class="literal">z</tt> is held by class Y using Notice that the data member <code class="literal">z</code> is held by class Y using
a raw pointer. Now we have a potential dangling pointer problem inside Y: a raw pointer. Now we have a potential dangling pointer problem inside Y:
</p> </p>
<pre class="programlisting"> <pre class="programlisting">
@@ -167,7 +171,7 @@ Namespaces are one honking great idea -- let's do more of those!
<span class="special">&gt;&gt;&gt;</span> <span class="identifier">y</span><span class="special">.</span><span class="identifier">z_value</span><span class="special">()</span> # <span class="identifier">CRASH</span><span class="special">!</span> <span class="special">&gt;&gt;&gt;</span> <span class="identifier">y</span><span class="special">.</span><span class="identifier">z_value</span><span class="special">()</span> # <span class="identifier">CRASH</span><span class="special">!</span>
</pre> </pre>
<p> <p>
For reference, here's the implementation of <tt class="literal">f</tt> again: For reference, here's the implementation of <code class="literal">f</code> again:
</p> </p>
<pre class="programlisting"> <pre class="programlisting">
<span class="identifier">X</span><span class="special">&amp;</span> <span class="identifier">f</span><span class="special">(</span><span class="identifier">Y</span><span class="special">&amp;</span> <span class="identifier">y</span><span class="special">,</span> <span class="identifier">Z</span><span class="special">*</span> <span class="identifier">z</span><span class="special">)</span> <span class="identifier">X</span><span class="special">&amp;</span> <span class="identifier">f</span><span class="special">(</span><span class="identifier">Y</span><span class="special">&amp;</span> <span class="identifier">y</span><span class="special">,</span> <span class="identifier">Z</span><span class="special">*</span> <span class="identifier">z</span><span class="special">)</span>
@@ -181,33 +185,33 @@ Namespaces are one honking great idea -- let's do more of those!
</p> </p>
<div class="orderedlist"><ol type="1"> <div class="orderedlist"><ol type="1">
<li> <li>
<tt class="literal">f</tt> is called passing in a reference to <tt class="literal">y</tt> <code class="literal">f</code> is called passing in a reference to <code class="literal">y</code>
and a pointer to <tt class="literal">z</tt> and a pointer to <code class="literal">z</code>
</li> </li>
<li> <li>
A pointer to <tt class="literal">z</tt> is held by <tt class="literal">y</tt> A pointer to <code class="literal">z</code> is held by <code class="literal">y</code>
</li> </li>
<li> <li>
A reference to <tt class="literal">y.x</tt> is returned A reference to <code class="literal">y.x</code> is returned
</li> </li>
<li> <li>
<tt class="literal">z</tt> is deleted. <tt class="literal">y.z</tt> is a dangling pointer <code class="literal">z</code> is deleted. <code class="literal">y.z</code> is a dangling pointer
</li> </li>
<li> <li>
<tt class="literal">y.z_value()</tt> is called <code class="literal">y.z_value()</code> is called
</li> </li>
<li> <li>
<tt class="literal">z-&gt;value()</tt> is called <code class="literal">z-&gt;value()</code> is called
</li> </li>
<li><span class="bold"><b>BOOM!</b></span></li> <li><span class="bold"><strong>BOOM!</strong></span></li>
</ol></div> </ol></div>
<a name="call_policies.call_policies"></a><h2> <a name="call_policies.call_policies"></a><h3>
<a name="id450599"></a> <a name="id3144432"></a>
Call Policies Call Policies
</h2> </h3>
<p> <p>
Call Policies may be used in situations such as the example detailed above. Call Policies may be used in situations such as the example detailed above.
In our example, <tt class="literal">return_internal_reference</tt> and <tt class="literal">with_custodian_and_ward</tt> In our example, <code class="literal">return_internal_reference</code> and <code class="literal">with_custodian_and_ward</code>
are our friends: are our friends:
</p> </p>
<pre class="programlisting"> <pre class="programlisting">
@@ -216,27 +220,27 @@ Namespaces are one honking great idea -- let's do more of those!
<span class="identifier">with_custodian_and_ward</span><span class="special">&lt;</span><span class="number">1</span><span class="special">,</span> <span class="number">2</span><span class="special">&gt;</span> <span class="special">&gt;());</span> <span class="identifier">with_custodian_and_ward</span><span class="special">&lt;</span><span class="number">1</span><span class="special">,</span> <span class="number">2</span><span class="special">&gt;</span> <span class="special">&gt;());</span>
</pre> </pre>
<p> <p>
What are the <tt class="literal">1</tt> and <tt class="literal">2</tt> parameters, you What are the <code class="literal">1</code> and <code class="literal">2</code> parameters, you
ask? ask?
</p> </p>
<pre class="programlisting"> <pre class="programlisting">
<span class="identifier">return_internal_reference</span><span class="special">&lt;</span><span class="number">1</span> <span class="identifier">return_internal_reference</span><span class="special">&lt;</span><span class="number">1</span>
</pre> </pre>
<p> <p>
Informs Boost.Python that the first argument, in our case <tt class="literal">Y&amp; Informs Boost.Python that the first argument, in our case <code class="literal">Y&amp;
y</tt>, is the owner of the returned reference: <tt class="literal">X&amp;</tt>. y</code>, is the owner of the returned reference: <code class="literal">X&amp;</code>.
The "<tt class="literal">1</tt>" simply specifies the first argument. The "<code class="literal">1</code>" simply specifies the first argument.
In short: "return an internal reference <tt class="literal">X&amp;</tt> owned In short: "return an internal reference <code class="literal">X&amp;</code> owned
by the 1st argument <tt class="literal">Y&amp; y</tt>". by the 1st argument <code class="literal">Y&amp; y</code>".
</p> </p>
<pre class="programlisting"> <pre class="programlisting">
<span class="identifier">with_custodian_and_ward</span><span class="special">&lt;</span><span class="number">1</span><span class="special">,</span> <span class="number">2</span><span class="special">&gt;</span> <span class="identifier">with_custodian_and_ward</span><span class="special">&lt;</span><span class="number">1</span><span class="special">,</span> <span class="number">2</span><span class="special">&gt;</span>
</pre> </pre>
<p> <p>
Informs Boost.Python that the lifetime of the argument indicated by ward Informs Boost.Python that the lifetime of the argument indicated by ward
(i.e. the 2nd argument: <tt class="literal">Z* z</tt>) is dependent on the lifetime (i.e. the 2nd argument: <code class="literal">Z* z</code>) is dependent on the lifetime
of the argument indicated by custodian (i.e. the 1st argument: <tt class="literal">Y&amp; of the argument indicated by custodian (i.e. the 1st argument: <code class="literal">Y&amp;
y</tt>). y</code>).
</p> </p>
<p> <p>
It is also important to note that we have defined two policies above. Two It is also important to note that we have defined two policies above. Two
@@ -253,52 +257,51 @@ Namespaces are one honking great idea -- let's do more of those!
</p> </p>
<div class="itemizedlist"><ul type="disc"> <div class="itemizedlist"><ul type="disc">
<li> <li>
<span class="bold"><b>with_custodian_and_ward</b></span><br> Ties lifetimes <span class="bold"><strong>with_custodian_and_ward</strong></span><br> Ties lifetimes
of the arguments of the arguments
</li> </li>
<li> <li>
<span class="bold"><b>with_custodian_and_ward_postcall</b></span><br> <span class="bold"><strong>with_custodian_and_ward_postcall</strong></span><br>
Ties lifetimes of the arguments and results Ties lifetimes of the arguments and results
</li> </li>
<li> <li>
<span class="bold"><b>return_internal_reference</b></span><br> Ties lifetime <span class="bold"><strong>return_internal_reference</strong></span><br> Ties lifetime
of one argument to that of result of one argument to that of result
</li> </li>
<li> <li>
<span class="bold"><b>return_value_policy&lt;T&gt; with T one of:</b></span><br> <span class="bold"><strong>return_value_policy&lt;T&gt; with T one of:</strong></span><br>
</li> </li>
<li> <li>
<span class="bold"><b>reference_existing_object</b></span><br> naive <span class="bold"><strong>reference_existing_object</strong></span><br> naive
(dangerous) approach (dangerous) approach
</li> </li>
<li> <li>
<span class="bold"><b>copy_const_reference</b></span><br> Boost.Python <span class="bold"><strong>copy_const_reference</strong></span><br> Boost.Python
v1 approach v1 approach
</li> </li>
<li> <li>
<span class="bold"><b>copy_non_const_reference</b></span><br> <span class="bold"><strong>copy_non_const_reference</strong></span><br>
</li> </li>
<li> <li>
<span class="bold"><b>manage_new_object</b></span><br> Adopt a pointer <span class="bold"><strong>manage_new_object</strong></span><br> Adopt a pointer
and hold the instance and hold the instance
</li> </li>
</ul></div> </ul></div>
<div class="informaltable"><table class="table"> <div class="informaltable"><table class="table">
<colgroup><col></colgroup> <colgroup><col></colgroup>
<tbody><tr><td class="blurb"> <tbody><tr><td class="blurb"> <span class="inlinemediaobject"><img src="../images/smiley.png" alt="smiley"></span> <span class="bold"><strong>Remember the Zen, Luke:</strong></span><br>
<span class="inlinemediaobject"><img src="../images/smiley.png"></span> <span class="bold"><b>Remember the Zen, Luke:</b></span><br><br> "Explicit <br> "Explicit is better than implicit"<br> "In
is better than implicit"<br> "In the face of ambiguity, the face of ambiguity, refuse the temptation to guess"<br>
refuse the temptation to guess"<br> </td></tr></tbody>
</td></tr></tbody>
</table></div> </table></div>
</div> </div>
<div class="section" lang="en"> <div class="section" lang="en">
<div class="titlepage"><div><div><h3 class="title"> <div class="titlepage"><div><div><h3 class="title">
<a name="python.overloading"></a>Overloading</h3></div></div></div> <a name="python.overloading"></a>Overloading</h3></div></div></div>
<p> <p>
OverloadingThe following illustrates a scheme for manually wrapping an overloaded The following illustrates a scheme for manually wrapping an overloaded member
member functions. Of course, the same technique can be applied to wrapping functions. Of course, the same technique can be applied to wrapping overloaded
overloaded non-member functions. non-member functions.
</p> </p>
<p> <p>
We have here our C++ class: We have here our C++ class:
@@ -351,22 +354,22 @@ Namespaces are one honking great idea -- let's do more of those!
<div class="titlepage"><div><div><h3 class="title"> <div class="titlepage"><div><div><h3 class="title">
<a name="python.default_arguments"></a>Default Arguments</h3></div></div></div> <a name="python.default_arguments"></a>Default Arguments</h3></div></div></div>
<p> <p>
Default ArgumentsBoost.Python wraps (member) function pointers. Unfortunately, Boost.Python wraps (member) function pointers. Unfortunately, C++ function
C++ function pointers carry no default argument info. Take a function <tt class="literal">f</tt> pointers carry no default argument info. Take a function <code class="literal">f</code>
with default arguments: with default arguments:
</p> </p>
<pre class="programlisting"> <pre class="programlisting">
<span class="keyword">int</span> <span class="identifier">f</span><span class="special">(</span><span class="keyword">int</span><span class="special">,</span> <span class="keyword">double</span> <span class="special">=</span> <span class="number">3.14</span><span class="special">,</span> <span class="keyword">char</span> <span class="keyword">const</span><span class="special">*</span> <span class="special">=</span> <span class="string">"hello"</span><span class="special">);</span> <span class="keyword">int</span> <span class="identifier">f</span><span class="special">(</span><span class="keyword">int</span><span class="special">,</span> <span class="keyword">double</span> <span class="special">=</span> <span class="number">3.14</span><span class="special">,</span> <span class="keyword">char</span> <span class="keyword">const</span><span class="special">*</span> <span class="special">=</span> <span class="string">"hello"</span><span class="special">);</span>
</pre> </pre>
<p> <p>
But the type of a pointer to the function <tt class="literal">f</tt> has no information But the type of a pointer to the function <code class="literal">f</code> has no information
about its default arguments: about its default arguments:
</p> </p>
<pre class="programlisting"> <pre class="programlisting">
<span class="keyword">int</span><span class="special">(*</span><span class="identifier">g</span><span class="special">)(</span><span class="keyword">int</span><span class="special">,</span><span class="keyword">double</span><span class="special">,</span><span class="keyword">char</span> <span class="keyword">const</span><span class="special">*)</span> <span class="special">=</span> <span class="identifier">f</span><span class="special">;</span> <span class="comment">// defaults lost! <span class="keyword">int</span><span class="special">(*</span><span class="identifier">g</span><span class="special">)(</span><span class="keyword">int</span><span class="special">,</span><span class="keyword">double</span><span class="special">,</span><span class="keyword">char</span> <span class="keyword">const</span><span class="special">*)</span> <span class="special">=</span> <span class="identifier">f</span><span class="special">;</span> <span class="comment">// defaults lost!
</span></pre> </span></pre>
<p> <p>
When we pass this function pointer to the <tt class="literal">def</tt> function, When we pass this function pointer to the <code class="literal">def</code> function,
there is no way to retrieve the default arguments: there is no way to retrieve the default arguments:
</p> </p>
<pre class="programlisting"> <pre class="programlisting">
@@ -400,10 +403,10 @@ Namespaces are one honking great idea -- let's do more of those!
are overloaded with a common sequence of initial arguments are overloaded with a common sequence of initial arguments
</li> </li>
</ul></div> </ul></div>
<a name="default_arguments.boost_python_function_overloads"></a><h2> <a name="default_arguments.boost_python_function_overloads"></a><h3>
<a name="id452559"></a> <a name="id3146300"></a>
BOOST_PYTHON_FUNCTION_OVERLOADS BOOST_PYTHON_FUNCTION_OVERLOADS
</h2> </h3>
<p> <p>
Boost.Python now has a way to make it easier. For instance, given a function: Boost.Python now has a way to make it easier. For instance, given a function:
</p> </p>
@@ -421,19 +424,19 @@ Namespaces are one honking great idea -- let's do more of those!
</pre> </pre>
<p> <p>
will automatically create the thin wrappers for us. This macro will create will automatically create the thin wrappers for us. This macro will create
a class <tt class="literal">foo_overloads</tt> that can be passed on to <tt class="literal">def(...)</tt>. a class <code class="literal">foo_overloads</code> that can be passed on to <code class="literal">def(...)</code>.
The third and fourth macro argument are the minimum arguments and maximum The third and fourth macro argument are the minimum arguments and maximum
arguments, respectively. In our <tt class="literal">foo</tt> function the minimum arguments, respectively. In our <code class="literal">foo</code> function the minimum
number of arguments is 1 and the maximum number of arguments is 4. The <tt class="literal">def(...)</tt> number of arguments is 1 and the maximum number of arguments is 4. The <code class="literal">def(...)</code>
function will automatically add all the foo variants for us: function will automatically add all the foo variants for us:
</p> </p>
<pre class="programlisting"> <pre class="programlisting">
<span class="identifier">def</span><span class="special">(</span><span class="string">"foo"</span><span class="special">,</span> <span class="identifier">foo</span><span class="special">,</span> <span class="identifier">foo_overloads</span><span class="special">());</span> <span class="identifier">def</span><span class="special">(</span><span class="string">"foo"</span><span class="special">,</span> <span class="identifier">foo</span><span class="special">,</span> <span class="identifier">foo_overloads</span><span class="special">());</span>
</pre> </pre>
<a name="default_arguments.boost_python_member_function_overloads"></a><h2> <a name="default_arguments.boost_python_member_function_overloads"></a><h3>
<a name="id452863"></a> <a name="id3146587"></a>
BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS
</h2> </h3>
<p> <p>
Objects here, objects there, objects here there everywhere. More frequently Objects here, objects there, objects here there everywhere. More frequently
than anything else, we need to expose member functions of our classes to than anything else, we need to expose member functions of our classes to
@@ -442,7 +445,7 @@ Namespaces are one honking great idea -- let's do more of those!
play. Another macro is provided to make this a breeze. play. Another macro is provided to make this a breeze.
</p> </p>
<p> <p>
Like <tt class="literal">BOOST_PYTHON_FUNCTION_OVERLOADS</tt>, <tt class="literal">BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS</tt> Like <code class="literal">BOOST_PYTHON_FUNCTION_OVERLOADS</code>, <code class="literal">BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS</code>
may be used to automatically create the thin wrappers for wrapping member may be used to automatically create the thin wrappers for wrapping member
functions. Let's have an example: functions. Let's have an example:
</p> </p>
@@ -463,11 +466,11 @@ Namespaces are one honking great idea -- let's do more of those!
<span class="identifier">BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS</span><span class="special">(</span><span class="identifier">george_overloads</span><span class="special">,</span> <span class="identifier">wack_em</span><span class="special">,</span> <span class="number">1</span><span class="special">,</span> <span class="number">3</span><span class="special">)</span> <span class="identifier">BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS</span><span class="special">(</span><span class="identifier">george_overloads</span><span class="special">,</span> <span class="identifier">wack_em</span><span class="special">,</span> <span class="number">1</span><span class="special">,</span> <span class="number">3</span><span class="special">)</span>
</pre> </pre>
<p> <p>
will generate a set of thin wrappers for george's <tt class="literal">wack_em</tt> will generate a set of thin wrappers for george's <code class="literal">wack_em</code>
member function accepting a minimum of 1 and a maximum of 3 arguments (i.e. member function accepting a minimum of 1 and a maximum of 3 arguments (i.e.
the third and fourth macro argument). The thin wrappers are all enclosed the third and fourth macro argument). The thin wrappers are all enclosed
in a class named <tt class="literal">george_overloads</tt> that can then be used in a class named <code class="literal">george_overloads</code> that can then be used
as an argument to <tt class="literal">def(...)</tt>: as an argument to <code class="literal">def(...)</code>:
</p> </p>
<pre class="programlisting"> <pre class="programlisting">
<span class="special">.</span><span class="identifier">def</span><span class="special">(</span><span class="string">"wack_em"</span><span class="special">,</span> <span class="special">&amp;</span><span class="identifier">george</span><span class="special">::</span><span class="identifier">wack_em</span><span class="special">,</span> <span class="identifier">george_overloads</span><span class="special">());</span> <span class="special">.</span><span class="identifier">def</span><span class="special">(</span><span class="string">"wack_em"</span><span class="special">,</span> <span class="special">&amp;</span><span class="identifier">george</span><span class="special">::</span><span class="identifier">wack_em</span><span class="special">,</span> <span class="identifier">george_overloads</span><span class="special">());</span>
@@ -476,13 +479,13 @@ Namespaces are one honking great idea -- let's do more of those!
See the <a href="../../../../v2/overloads.html#BOOST_PYTHON_FUNCTION_OVERLOADS-spec" target="_top">overloads See the <a href="../../../../v2/overloads.html#BOOST_PYTHON_FUNCTION_OVERLOADS-spec" target="_top">overloads
reference</a> for details. reference</a> for details.
</p> </p>
<a name="default_arguments.init_and_optional"></a><h2> <a name="default_arguments.init_and_optional"></a><h3>
<a name="id453212"></a> <a name="id3146923"></a>
init and optional init and optional
</h2> </h3>
<p> <p>
A similar facility is provided for class constructors, again, with default A similar facility is provided for class constructors, again, with default
arguments or a sequence of overloads. Remember <tt class="literal">init&lt;...&gt;</tt>? arguments or a sequence of overloads. Remember <code class="literal">init&lt;...&gt;</code>?
For example, given a class X with a constructor: For example, given a class X with a constructor:
</p> </p>
<pre class="programlisting"> <pre class="programlisting">
@@ -499,7 +502,7 @@ Namespaces are one honking great idea -- let's do more of those!
<span class="special">.</span><span class="identifier">def</span><span class="special">(</span><span class="identifier">init</span><span class="special">&lt;</span><span class="keyword">int</span><span class="special">,</span> <span class="identifier">optional</span><span class="special">&lt;</span><span class="keyword">char</span><span class="special">,</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">string</span><span class="special">,</span> <span class="keyword">double</span><span class="special">&gt;</span> <span class="special">&gt;())</span> <span class="special">.</span><span class="identifier">def</span><span class="special">(</span><span class="identifier">init</span><span class="special">&lt;</span><span class="keyword">int</span><span class="special">,</span> <span class="identifier">optional</span><span class="special">&lt;</span><span class="keyword">char</span><span class="special">,</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">string</span><span class="special">,</span> <span class="keyword">double</span><span class="special">&gt;</span> <span class="special">&gt;())</span>
</pre> </pre>
<p> <p>
Notice the use of <tt class="literal">init&lt;...&gt;</tt> and <tt class="literal">optional&lt;...&gt;</tt> Notice the use of <code class="literal">init&lt;...&gt;</code> and <code class="literal">optional&lt;...&gt;</code>
to signify the default (optional arguments). to signify the default (optional arguments).
</p> </p>
</div> </div>
@@ -507,10 +510,10 @@ Namespaces are one honking great idea -- let's do more of those!
<div class="titlepage"><div><div><h3 class="title"> <div class="titlepage"><div><div><h3 class="title">
<a name="python.auto_overloading"></a>Auto-Overloading</h3></div></div></div> <a name="python.auto_overloading"></a>Auto-Overloading</h3></div></div></div>
<p> <p>
Auto-OverloadingIt was mentioned in passing in the previous section that It was mentioned in passing in the previous section that <code class="literal">BOOST_PYTHON_FUNCTION_OVERLOADS</code>
<tt class="literal">BOOST_PYTHON_FUNCTION_OVERLOADS</tt> and <tt class="literal">BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS</tt> and <code class="literal">BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS</code> can also be
can also be used for overloaded functions and member functions with a common used for overloaded functions and member functions with a common sequence
sequence of initial arguments. Here is an example: of initial arguments. Here is an example:
</p> </p>
<pre class="programlisting"> <pre class="programlisting">
<span class="keyword">void</span> <span class="identifier">foo</span><span class="special">()</span> <span class="keyword">void</span> <span class="identifier">foo</span><span class="special">()</span>
@@ -544,30 +547,30 @@ Namespaces are one honking great idea -- let's do more of those!
Then... Then...
</p> </p>
<pre class="programlisting"> <pre class="programlisting">
<span class="special">.</span><span class="identifier">def</span><span class="special">(</span><span class="string">"foo"</span><span class="special">,</span> <span class="identifier">foo</span><span class="special">,</span> <span class="identifier">foo_overloads</span><span class="special">());</span> <span class="special">.</span><span class="identifier">def</span><span class="special">(</span><span class="string">"foo"</span><span class="special">,</span> <span class="special">(</span><span class="keyword">void</span><span class="special">(*)(</span><span class="keyword">bool</span><span class="special">,</span> <span class="keyword">int</span><span class="special">,</span> <span class="keyword">char</span><span class="special">))</span><span class="number">0</span><span class="special">,</span> <span class="identifier">foo_overloads</span><span class="special">());</span>
</pre> </pre>
<p> <p>
Notice though that we have a situation now where we have a minimum of zero Notice though that we have a situation now where we have a minimum of zero
(0) arguments and a maximum of 3 arguments. (0) arguments and a maximum of 3 arguments.
</p> </p>
<a name="auto_overloading.manual_wrapping"></a><h2> <a name="auto_overloading.manual_wrapping"></a><h3>
<a name="id453917"></a> <a name="id3147627"></a>
Manual Wrapping Manual Wrapping
</h2> </h3>
<p> <p>
It is important to emphasize however that <span class="bold"><b>the overloaded It is important to emphasize however that <span class="bold"><strong>the overloaded
functions must have a common sequence of initial arguments</b></span>. Otherwise, functions must have a common sequence of initial arguments</strong></span>. Otherwise,
our scheme above will not work. If this is not the case, we have to wrap our scheme above will not work. If this is not the case, we have to wrap
our functions <a href="functions.html#python.overloading" title="Overloading">manually</a>. our functions <a href="functions.html#python.overloading" title="Overloading">manually</a>.
</p> </p>
<p> <p>
Actually, we can mix and match manual wrapping of overloaded functions and Actually, we can mix and match manual wrapping of overloaded functions and
automatic wrapping through <tt class="literal">BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS</tt> automatic wrapping through <code class="literal">BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS</code>
and its sister, <tt class="literal">BOOST_PYTHON_FUNCTION_OVERLOADS</tt>. Following and its sister, <code class="literal">BOOST_PYTHON_FUNCTION_OVERLOADS</code>. Following
up on our example presented in the section <a href="functions.html#python.overloading" title="Overloading">on up on our example presented in the section <a href="functions.html#python.overloading" title="Overloading">on
overloading</a>, since the first 4 overload functins have a common sequence overloading</a>, since the first 4 overload functins have a common sequence
of initial arguments, we can use <tt class="literal">BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS</tt> of initial arguments, we can use <code class="literal">BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS</code>
to automatically wrap the first three of the <tt class="literal">def</tt>s and to automatically wrap the first three of the <code class="literal">def</code>s and
manually wrap just the last. Here's how we'll do this: manually wrap just the last. Here's how we'll do this:
</p> </p>
<pre class="programlisting"> <pre class="programlisting">

View File

@@ -1,17 +1,17 @@
<html> <html>
<head> <head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title> Building Hello World</title> <title>Building Hello World</title>
<link rel="stylesheet" href="../boostbook.css" type="text/css"> <link rel="stylesheet" href="../boostbook.css" type="text/css">
<meta name="generator" content="DocBook XSL Stylesheets V1.66.1"> <meta name="generator" content="DocBook XSL Stylesheets V1.72.0">
<link rel="start" href="../index.html" title="Chapter 1. python 1.0"> <link rel="start" href="../index.html" title="Chapter 1. python 1.0">
<link rel="up" href="../index.html" title="Chapter 1. python 1.0"> <link rel="up" href="../index.html" title="Chapter 1. python 1.0">
<link rel="prev" href="../index.html" title="Chapter 1. python 1.0"> <link rel="prev" href="../index.html" title="Chapter 1. python 1.0">
<link rel="next" href="exposing.html" title=" Exposing Classes"> <link rel="next" href="exposing.html" title="Exposing Classes">
</head> </head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"> <body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<table cellpadding="2" width="100%"> <table cellpadding="2" width="100%">
<td valign="top"><img alt="boost.png (6897 bytes)" width="277" height="86" src="../../../../../../../boost.png"></td> <td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../../../../../boost.png"></td>
<td align="center"><a href="../../../../../../../index.htm">Home</a></td> <td align="center"><a href="../../../../../../../index.htm">Home</a></td>
<td align="center"><a href="../../../../../../../libs/libraries.htm">Libraries</a></td> <td align="center"><a href="../../../../../../../libs/libraries.htm">Libraries</a></td>
<td align="center"><a href="../../../../../../../people/people.htm">People</a></td> <td align="center"><a href="../../../../../../../people/people.htm">People</a></td>
@@ -25,23 +25,23 @@
<div class="section" lang="en"> <div class="section" lang="en">
<div class="titlepage"><div><div><h2 class="title" style="clear: both"> <div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="python.hello"></a> Building Hello World</h2></div></div></div> <a name="python.hello"></a> Building Hello World</h2></div></div></div>
<a name="hello._building_hello_worldfrom_start_to_finish"></a><h2> <a name="hello.from_start_to_finish"></a><h3>
<a name="id442456"></a> <a name="id3091224"></a>
Building Hello WorldFrom Start To Finish From Start To Finish
</h2> </h3>
<p> <p>
Now the first thing you'd want to do is to build the Hello World module and Now the first thing you'd want to do is to build the Hello World module and
try it for yourself in Python. In this section, we shall outline the steps try it for yourself in Python. In this section, we shall outline the steps
necessary to achieve that. We shall use the build tool that comes bundled with necessary to achieve that. We shall use the build tool that comes bundled with
every boost distribution: <span class="bold"><b>bjam</b></span>. every boost distribution: <span class="bold"><strong>bjam</strong></span>.
</p> </p>
<div class="informaltable"><table class="table"> <div class="informaltable"><table class="table">
<colgroup><col></colgroup> <colgroup><col></colgroup>
<tbody><tr><td class="blurb"> <tbody><tr><td class="blurb"> <span class="inlinemediaobject"><img src="../images/note.png" alt="note"></span> <span class="bold"><strong>Building without bjam</strong></span><br>
<span class="inlinemediaobject"><img src="../images/note.png"></span> <span class="bold"><b>Building without bjam</b></span><br><br> Besides bjam, <br> Besides bjam, there are of course other ways to get your module
there are of course other ways to get your module built. What's written built. What's written here should not be taken as "the one and only
here should not be taken as "the one and only way". There are way". There are of course other build tools apart from <code class="literal">bjam</code>.<br>
of course other build tools apart from <tt class="literal">bjam</tt>.<br><br> Take note however that the preferred build tool for Boost.Python <br> Take note however that the preferred build tool for Boost.Python
is bjam. There are so many ways to set up the build incorrectly. Experience is bjam. There are so many ways to set up the build incorrectly. Experience
shows that 90% of the "I can't build Boost.Python" problems shows that 90% of the "I can't build Boost.Python" problems
come from people who had to use a different tool. </td></tr></tbody> come from people who had to use a different tool. </td></tr></tbody>
@@ -76,7 +76,7 @@
if you are on Unix. if you are on Unix.
</p> </p>
<p> <p>
The tutorial example can be found in the directory: <tt class="literal">libs/python/example/tutorial</tt>. The tutorial example can be found in the directory: <code class="literal">libs/python/example/tutorial</code>.
There, you can find: There, you can find:
</p> </p>
<div class="itemizedlist"><ul type="disc"> <div class="itemizedlist"><ul type="disc">
@@ -88,21 +88,23 @@
</li> </li>
</ul></div> </ul></div>
<p> <p>
The <tt class="literal">hello.cpp</tt> file is our C++ hello world example. The The <code class="literal">hello.cpp</code> file is our C++ hello world example. The
<tt class="literal">Jamfile</tt> is a minimalist <span class="emphasis"><em>bjam</em></span> script <code class="literal">Jamfile</code> is a minimalist <span class="emphasis"><em>bjam</em></span> script
that builds the DLLs for us. that builds the DLLs for us.
</p> </p>
<p> <p>
Before anything else, you should have the bjam executable in your boost directory Before anything else, you should have the bjam executable in your boost directory
or somewhere in your path such that <tt class="literal">bjam</tt> can be executed or somewhere in your path such that <code class="literal">bjam</code> can be executed
in the command line. Pre-built Boost.Jam executables are available for most in the command line. Pre-built Boost.Jam executables are available for most
platforms. The complete list of Bjam executables can be found <a href="http://sourceforge.net/project/showfiles.php?group_id=7586" target="_top">here</a>. platforms. The complete list of Bjam executables can be found <a href="http://sourceforge.net/project/showfiles.php?group_id=7586" target="_top">here</a>.
</p> </p>
<a name="hello.let_s_jam_"></a><h2> <a name="hello.let_s_jam_"></a><h3>
<a name="id373799"></a> <a name="id3091427"></a>
Let's Jam! Let's Jam!
</h2> </h3>
<p><span class="inlinemediaobject"><img src="../images/jam.png"></span></p> <p>
<span class="inlinemediaobject"><img src="../images/jam.png" alt="jam"></span>
</p>
<p> <p>
Here is our minimalist Jamfile: Here is our minimalist Jamfile:
</p> </p>
@@ -119,13 +121,13 @@ extension hello # Declare a Python extension called hello
</pre> </pre>
<p> <p>
First, we need to specify our location. You may place your project anywhere. First, we need to specify our location. You may place your project anywhere.
<tt class="literal">project-root</tt> allows you to do that. <code class="literal">project-root</code> allows you to do that.
</p> </p>
<pre class="programlisting">project-root ; <pre class="programlisting">project-root ;
</pre> </pre>
<p> <p>
By doing so, you'll need a Jamrules file. Simply copy the one in the <a href="../../../../../example/tutorial/Jamrules" target="_top">example/tutorial directory</a> By doing so, you'll need a Jamrules file. Simply copy the one in the <a href="../../../../../example/tutorial/Jamrules" target="_top">example/tutorial directory</a>
and tweak the <tt class="literal">path-global BOOST_ROOT</tt> to where your boost and tweak the <code class="literal">path-global BOOST_ROOT</code> to where your boost
root directory is. The file has <a href="../../../../../example/tutorial/Jamrules" target="_top">detailed root directory is. The file has <a href="../../../../../example/tutorial/Jamrules" target="_top">detailed
instructions</a> you can follow. instructions</a> you can follow.
</p> </p>
@@ -135,7 +137,7 @@ extension hello # Declare a Python extension called hello
<pre class="programlisting">import python ; <pre class="programlisting">import python ;
</pre> </pre>
<p> <p>
Finally we declare our <tt class="literal">hello</tt> extension: Finally we declare our <code class="literal">hello</code> extension:
</p> </p>
<pre class="programlisting">extension hello # Declare a Python extension called hello <pre class="programlisting">extension hello # Declare a Python extension called hello
: hello.cpp # source : hello.cpp # source
@@ -147,11 +149,12 @@ extension hello # Declare a Python extension called hello
<p> <p>
The last part tells BJam that we are depending on the Boost Python Library. The last part tells BJam that we are depending on the Boost Python Library.
</p> </p>
<a name="hello.running_bjam"></a><h2> <a name="hello.running_bjam"></a><h3>
<a name="id373910"></a> <a name="id3091556"></a>
Running bjam Running bjam
</h2> </h3>
<p><span class="emphasis"><em>bjam</em></span> is run using your operating system's command line <p>
<span class="emphasis"><em>bjam</em></span> is run using your operating system's command line
interpreter. interpreter.
</p> </p>
<div class="blockquote"><blockquote class="blockquote"><p> <div class="blockquote"><blockquote class="blockquote"><p>
@@ -159,7 +162,7 @@ extension hello # Declare a Python extension called hello
</p></blockquote></div> </p></blockquote></div>
<p> <p>
Make sure that the environment is set so that we can invoke the C++ compiler. Make sure that the environment is set so that we can invoke the C++ compiler.
With MSVC, that would mean running the <tt class="literal">Vcvars32.bat</tt> batch With MSVC, that would mean running the <code class="literal">Vcvars32.bat</code> batch
file. For instance: file. For instance:
</p> </p>
<pre class="programlisting">C:\Program Files\Microsoft Visual Studio .NET 2003\Common7\Tools\vsvars32.bat <pre class="programlisting">C:\Program Files\Microsoft Visual Studio .NET 2003\Common7\Tools\vsvars32.bat
@@ -172,15 +175,13 @@ extension hello # Declare a Python extension called hello
set PYTHON_VERSION=2.2 set PYTHON_VERSION=2.2
</pre> </pre>
<p> <p>
The above assumes that the Python installation is in <tt class="literal">c:/dev/tools/python</tt> The above assumes that the Python installation is in <code class="literal">c:/dev/tools/python</code>
and that we are using Python version 2.2. You'll have to tweak these appropriately. and that we are using Python version 2.2. You'll have to tweak these appropriately.
</p> </p>
<div class="informaltable"><table class="table"> <div class="informaltable"><table class="table">
<colgroup><col></colgroup> <colgroup><col></colgroup>
<tbody><tr><td class="blurb"> <tbody><tr><td class="blurb"> <span class="inlinemediaobject"><img src="../images/tip.png" alt="tip"></span> Be sure not to include a third number, e.g. <span class="bold"><strong>not</strong></span> "2.2.1", even if that's the version
<span class="inlinemediaobject"><img src="../images/tip.png"></span> you have.</td></tr></tbody>
Be sure not to include a third number, e.g. <span class="bold"><b>not</b></span>
"2.2.1", even if that's the version you have.</td></tr></tbody>
</table></div> </table></div>
<p> <p>
Take note that you may also do that through the Jamrules file we put in our Take note that you may also do that through the Jamrules file we put in our
@@ -188,8 +189,8 @@ set PYTHON_VERSION=2.2
instructions</a> you can follow. instructions</a> you can follow.
</p> </p>
<p> <p>
Now we are ready... Be sure to <tt class="literal">cd</tt> to <tt class="literal">libs/python/example/tutorial</tt> Now we are ready... Be sure to <code class="literal">cd</code> to <code class="literal">libs/python/example/tutorial</code>
where the tutorial <tt class="literal">"hello.cpp"</tt> and the <tt class="literal">"Jamfile"</tt> where the tutorial <code class="literal">"hello.cpp"</code> and the <code class="literal">"Jamfile"</code>
is situated. is situated.
</p> </p>
<p> <p>
@@ -251,23 +252,29 @@ b and object bin\tutorial\hello.pyd\vc-7_1\debug\threading-multi\hello.exp
<p> <p>
if you are on Unix. if you are on Unix.
</p> </p>
<p><tt class="literal">boost_python.dll</tt> and <tt class="literal">hello.pyd</tt> can be <p>
found somewhere in your project's <tt class="literal">bin</tt> directory. After a <code class="literal">boost_python.dll</code> and <code class="literal">hello.pyd</code> can be
successful build, you can just link in these DLLs with the Python interpreter. found somewhere in your project's <code class="literal">bin</code> directory. After a
In Windows for example, you can simply put these libraries inside the directory successful build, you make it possible for the system to find boost_python.dll
where the Python executable is. or libboost_python.so (usually done with LD_LIBRARY_PATH, DYLD_LIBRARY_PATH,
or some other variable on *nix and with PATH on Windows) and for Python to
find the hello module (Done with PYTHONPATH on all systems.)
</p> </p>
<p> <p>
You may now fire up Python and run our hello module: You may now fire up Python and run our hello module:
</p> </p>
<p></p> <p>
</p>
<pre class="programlisting"> <pre class="programlisting">
<span class="special">&gt;&gt;&gt;</span> <span class="keyword">import</span> <span class="identifier">hello</span> <span class="special">&gt;&gt;&gt;</span> <span class="keyword">import</span> <span class="identifier">hello</span>
<span class="special">&gt;&gt;&gt;</span> <span class="keyword">print</span> <span class="identifier">hello</span><span class="special">.</span><span class="identifier">greet</span><span class="special">()</span> <span class="special">&gt;&gt;&gt;</span> <span class="keyword">print</span> <span class="identifier">hello</span><span class="special">.</span><span class="identifier">greet</span><span class="special">()</span>
<span class="identifier">hello</span><span class="special">,</span> <span class="identifier">world</span> <span class="identifier">hello</span><span class="special">,</span> <span class="identifier">world</span>
</pre> </pre>
<p></p> <p>
<div class="blockquote"><blockquote class="blockquote"><p><span class="bold"><b>There you go... Have fun!</b></span></p></blockquote></div> </p>
<div class="blockquote"><blockquote class="blockquote"><p>
<span class="bold"><strong>There you go... Have fun!</strong></span>
</p></blockquote></div>
</div> </div>
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr> <table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
<td align="left"></td> <td align="left"></td>

View File

@@ -3,15 +3,15 @@
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Iterators</title> <title>Iterators</title>
<link rel="stylesheet" href="../boostbook.css" type="text/css"> <link rel="stylesheet" href="../boostbook.css" type="text/css">
<meta name="generator" content="DocBook XSL Stylesheets V1.66.1"> <meta name="generator" content="DocBook XSL Stylesheets V1.72.0">
<link rel="start" href="../index.html" title="Chapter 1. python 1.0"> <link rel="start" href="../index.html" title="Chapter 1. python 1.0">
<link rel="up" href="../index.html" title="Chapter 1. python 1.0"> <link rel="up" href="../index.html" title="Chapter 1. python 1.0">
<link rel="prev" href="embedding.html" title="Embedding"> <link rel="prev" href="embedding.html" title="Embedding">
<link rel="next" href="exception.html" title=" Exception Translation"> <link rel="next" href="exception.html" title="Exception Translation">
</head> </head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"> <body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<table cellpadding="2" width="100%"> <table cellpadding="2" width="100%">
<td valign="top"><img alt="boost.png (6897 bytes)" width="277" height="86" src="../../../../../../../boost.png"></td> <td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../../../../../boost.png"></td>
<td align="center"><a href="../../../../../../../index.htm">Home</a></td> <td align="center"><a href="../../../../../../../index.htm">Home</a></td>
<td align="center"><a href="../../../../../../../libs/libraries.htm">Libraries</a></td> <td align="center"><a href="../../../../../../../libs/libraries.htm">Libraries</a></td>
<td align="center"><a href="../../../../../../../people/people.htm">People</a></td> <td align="center"><a href="../../../../../../../people/people.htm">People</a></td>
@@ -26,10 +26,12 @@
<div class="titlepage"><div><div><h2 class="title" style="clear: both"> <div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="python.iterators"></a>Iterators</h2></div></div></div> <a name="python.iterators"></a>Iterators</h2></div></div></div>
<p> <p>
IteratorsIn C++, and STL in particular, we see iterators everywhere. Python In C++, and STL in particular, we see iterators everywhere. Python also has
also has iterators, but these are two very different beasts. iterators, but these are two very different beasts.
</p>
<p>
<span class="bold"><strong>C++ iterators:</strong></span>
</p> </p>
<p><span class="bold"><b>C++ iterators:</b></span></p>
<div class="itemizedlist"><ul type="disc"> <div class="itemizedlist"><ul type="disc">
<li> <li>
C++ has 5 type categories (random-access, bidirectional, forward, input, C++ has 5 type categories (random-access, bidirectional, forward, input,
@@ -42,7 +44,9 @@
A pair of iterators is needed to represent a (first/last) range. A pair of iterators is needed to represent a (first/last) range.
</li> </li>
</ul></div> </ul></div>
<p><span class="bold"><b>Python Iterators:</b></span></p> <p>
<span class="bold"><strong>Python Iterators:</strong></span>
</p>
<div class="itemizedlist"><ul type="disc"> <div class="itemizedlist"><ul type="disc">
<li> <li>
1 category (forward) 1 category (forward)
@@ -55,10 +59,11 @@
</li> </li>
</ul></div> </ul></div>
<p> <p>
The typical Python iteration protocol: <tt class="literal"><span class="bold"><b>for y The typical Python iteration protocol: <code class="literal"><span class="bold"><strong>for y
in x...</b></span></tt> is as follows: in x...</strong></span></code> is as follows:
</p>
<p>
</p> </p>
<p></p>
<pre class="programlisting"> <pre class="programlisting">
<span class="identifier">iter</span> <span class="special">=</span> <span class="identifier">x</span><span class="special">.</span><span class="identifier">__iter__</span><span class="special">()</span> <span class="comment"># get iterator <span class="identifier">iter</span> <span class="special">=</span> <span class="identifier">x</span><span class="special">.</span><span class="identifier">__iter__</span><span class="special">()</span> <span class="comment"># get iterator
</span><span class="keyword">try</span><span class="special">:</span> </span><span class="keyword">try</span><span class="special">:</span>
@@ -69,10 +74,11 @@
</span></pre> </span></pre>
<p> <p>
Boost.Python provides some mechanisms to make C++ iterators play along nicely Boost.Python provides some mechanisms to make C++ iterators play along nicely
as Python iterators. What we need to do is to produce appropriate <tt class="computeroutput"><span class="identifier">__iter__</span></tt> function from C++ iterators that as Python iterators. What we need to do is to produce appropriate <code class="computeroutput"><span class="identifier">__iter__</span></code> function from C++ iterators that
is compatible with the Python iteration protocol. For example: is compatible with the Python iteration protocol. For example:
</p> </p>
<p></p> <p>
</p>
<pre class="programlisting"> <pre class="programlisting">
<span class="identifier">object</span> <span class="identifier">get_iterator</span> <span class="special">=</span> <span class="identifier">iterator</span><span class="special">&lt;</span><span class="identifier">vector</span><span class="special">&lt;</span><span class="keyword">int</span><span class="special">&gt;</span> <span class="special">&gt;();</span> <span class="identifier">object</span> <span class="identifier">get_iterator</span> <span class="special">=</span> <span class="identifier">iterator</span><span class="special">&lt;</span><span class="identifier">vector</span><span class="special">&lt;</span><span class="keyword">int</span><span class="special">&gt;</span> <span class="special">&gt;();</span>
<span class="identifier">object</span> <span class="identifier">iter</span> <span class="special">=</span> <span class="identifier">get_iterator</span><span class="special">(</span><span class="identifier">v</span><span class="special">);</span> <span class="identifier">object</span> <span class="identifier">iter</span> <span class="special">=</span> <span class="identifier">get_iterator</span><span class="special">(</span><span class="identifier">v</span><span class="special">);</span>
@@ -84,7 +90,9 @@
<pre class="programlisting"> <pre class="programlisting">
<span class="special">.</span><span class="identifier">def</span><span class="special">(</span><span class="string">"__iter__"</span><span class="special">,</span> <span class="identifier">iterator</span><span class="special">&lt;</span><span class="identifier">vector</span><span class="special">&lt;</span><span class="keyword">int</span><span class="special">&gt;</span> <span class="special">&gt;())</span> <span class="special">.</span><span class="identifier">def</span><span class="special">(</span><span class="string">"__iter__"</span><span class="special">,</span> <span class="identifier">iterator</span><span class="special">&lt;</span><span class="identifier">vector</span><span class="special">&lt;</span><span class="keyword">int</span><span class="special">&gt;</span> <span class="special">&gt;())</span>
</pre> </pre>
<p><span class="bold"><b>range</b></span></p> <p>
<span class="bold"><strong>range</strong></span>
</p>
<p> <p>
We can create a Python savvy iterator using the range function: We can create a Python savvy iterator using the range function:
</p> </p>
@@ -110,19 +118,22 @@
adaptable function object (use Target parameter) adaptable function object (use Target parameter)
</li> </li>
</ul></div> </ul></div>
<p><span class="bold"><b>iterator</b></span></p> <p>
<span class="bold"><strong>iterator</strong></span>
</p>
<div class="itemizedlist"><ul type="disc"><li> <div class="itemizedlist"><ul type="disc"><li>
iterator&lt;T, Policies&gt;() iterator&lt;T, Policies&gt;()
</li></ul></div> </li></ul></div>
<p> <p>
Given a container <tt class="literal">T</tt>, iterator is a shortcut that simply Given a container <code class="literal">T</code>, iterator is a shortcut that simply
calls <tt class="literal">range</tt> with &amp;T::begin, &amp;T::end. calls <code class="literal">range</code> with &amp;T::begin, &amp;T::end.
</p> </p>
<p> <p>
Let's put this into action... Here's an example from some hypothetical bogon Let's put this into action... Here's an example from some hypothetical bogon
Particle accelerator code: Particle accelerator code:
</p> </p>
<p></p> <p>
</p>
<pre class="programlisting"> <pre class="programlisting">
<span class="identifier">f</span> <span class="special">=</span> <span class="identifier">Field</span><span class="special">()</span> <span class="identifier">f</span> <span class="special">=</span> <span class="identifier">Field</span><span class="special">()</span>
<span class="keyword">for</span> <span class="identifier">x</span> <span class="keyword">in</span> <span class="identifier">f</span><span class="special">.</span><span class="identifier">pions</span><span class="special">:</span> <span class="keyword">for</span> <span class="identifier">x</span> <span class="keyword">in</span> <span class="identifier">f</span><span class="special">.</span><span class="identifier">pions</span><span class="special">:</span>
@@ -133,21 +144,25 @@
<p> <p>
Now, our C++ Wrapper: Now, our C++ Wrapper:
</p> </p>
<p></p> <p>
</p>
<pre class="programlisting"> <pre class="programlisting">
<span class="identifier">class_</span><span class="special">&lt;</span><span class="identifier">F</span><span class="special">&gt;(</span><span class="string">"Field"</span><span class="special">)</span> <span class="identifier">class_</span><span class="special">&lt;</span><span class="identifier">F</span><span class="special">&gt;(</span><span class="string">"Field"</span><span class="special">)</span>
<span class="special">.</span><span class="identifier">property</span><span class="special">(</span><span class="string">"pions"</span><span class="special">,</span> <span class="identifier">range</span><span class="special">(&amp;</span><span class="identifier">F</span><span class="special">::</span><span class="identifier">p_begin</span><span class="special">,</span> <span class="special">&amp;</span><span class="identifier">F</span><span class="special">::</span><span class="identifier">p_end</span><span class="special">))</span> <span class="special">.</span><span class="identifier">property</span><span class="special">(</span><span class="string">"pions"</span><span class="special">,</span> <span class="identifier">range</span><span class="special">(&amp;</span><span class="identifier">F</span><span class="special">::</span><span class="identifier">p_begin</span><span class="special">,</span> <span class="special">&amp;</span><span class="identifier">F</span><span class="special">::</span><span class="identifier">p_end</span><span class="special">))</span>
<span class="special">.</span><span class="identifier">property</span><span class="special">(</span><span class="string">"bogons"</span><span class="special">,</span> <span class="identifier">range</span><span class="special">(&amp;</span><span class="identifier">F</span><span class="special">::</span><span class="identifier">b_begin</span><span class="special">,</span> <span class="special">&amp;</span><span class="identifier">F</span><span class="special">::</span><span class="identifier">b_end</span><span class="special">));</span> <span class="special">.</span><span class="identifier">property</span><span class="special">(</span><span class="string">"bogons"</span><span class="special">,</span> <span class="identifier">range</span><span class="special">(&amp;</span><span class="identifier">F</span><span class="special">::</span><span class="identifier">b_begin</span><span class="special">,</span> <span class="special">&amp;</span><span class="identifier">F</span><span class="special">::</span><span class="identifier">b_end</span><span class="special">));</span>
</pre> </pre>
<p><span class="bold"><b>stl_input_iterator</b></span></p> <p>
<span class="bold"><strong>stl_input_iterator</strong></span>
</p>
<p> <p>
So far, we have seen how to expose C++ iterators and ranges to Python. Sometimes So far, we have seen how to expose C++ iterators and ranges to Python. Sometimes
we wish to go the other way, though: we'd like to pass a Python sequence to we wish to go the other way, though: we'd like to pass a Python sequence to
an STL algorithm or use it to initialize an STL container. We need to make an STL algorithm or use it to initialize an STL container. We need to make
a Python iterator look like an STL iterator. For that, we use <tt class="computeroutput"><span class="identifier">stl_input_iterator</span><span class="special">&lt;&gt;</span></tt>. a Python iterator look like an STL iterator. For that, we use <code class="computeroutput"><span class="identifier">stl_input_iterator</span><span class="special">&lt;&gt;</span></code>.
Consider how we might implement a function that exposes <tt class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">list</span><span class="special">&lt;</span><span class="keyword">int</span><span class="special">&gt;::</span><span class="identifier">assign</span><span class="special">()</span></tt> to Python: Consider how we might implement a function that exposes <code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">list</span><span class="special">&lt;</span><span class="keyword">int</span><span class="special">&gt;::</span><span class="identifier">assign</span><span class="special">()</span></code> to Python:
</p>
<p>
</p> </p>
<p></p>
<pre class="programlisting"> <pre class="programlisting">
<span class="keyword">template</span><span class="special">&lt;</span><span class="keyword">typename</span> <span class="identifier">T</span><span class="special">&gt;</span> <span class="keyword">template</span><span class="special">&lt;</span><span class="keyword">typename</span> <span class="identifier">T</span><span class="special">&gt;</span>
<span class="keyword">void</span> <span class="identifier">list_assign</span><span class="special">(</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">list</span><span class="special">&lt;</span><span class="identifier">T</span><span class="special">&gt;&amp;</span> <span class="identifier">l</span><span class="special">,</span> <span class="identifier">object</span> <span class="identifier">o</span><span class="special">)</span> <span class="special">{</span> <span class="keyword">void</span> <span class="identifier">list_assign</span><span class="special">(</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">list</span><span class="special">&lt;</span><span class="identifier">T</span><span class="special">&gt;&amp;</span> <span class="identifier">l</span><span class="special">,</span> <span class="identifier">object</span> <span class="identifier">o</span><span class="special">)</span> <span class="special">{</span>
@@ -163,10 +178,11 @@
</span> <span class="special">;</span> </span> <span class="special">;</span>
</pre> </pre>
<p> <p>
Now in Python, we can assign any integer sequence to <tt class="computeroutput"><span class="identifier">list_int</span></tt> Now in Python, we can assign any integer sequence to <code class="computeroutput"><span class="identifier">list_int</span></code>
objects: objects:
</p> </p>
<p></p> <p>
</p>
<pre class="programlisting"> <pre class="programlisting">
<span class="identifier">x</span> <span class="special">=</span> <span class="identifier">list_int</span><span class="special">();</span> <span class="identifier">x</span> <span class="special">=</span> <span class="identifier">list_int</span><span class="special">();</span>
<span class="identifier">x</span><span class="special">.</span><span class="identifier">assign</span><span class="special">([</span><span class="number">1</span><span class="special">,</span><span class="number">2</span><span class="special">,</span><span class="number">3</span><span class="special">,</span><span class="number">4</span><span class="special">,</span><span class="number">5</span><span class="special">])</span> <span class="identifier">x</span><span class="special">.</span><span class="identifier">assign</span><span class="special">([</span><span class="number">1</span><span class="special">,</span><span class="number">2</span><span class="special">,</span><span class="number">3</span><span class="special">,</span><span class="number">4</span><span class="special">,</span><span class="number">5</span><span class="special">])</span>

View File

@@ -1,9 +1,9 @@
<html> <html>
<head> <head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title> Object Interface</title> <title>Object Interface</title>
<link rel="stylesheet" href="../boostbook.css" type="text/css"> <link rel="stylesheet" href="../boostbook.css" type="text/css">
<meta name="generator" content="DocBook XSL Stylesheets V1.66.1"> <meta name="generator" content="DocBook XSL Stylesheets V1.72.0">
<link rel="start" href="../index.html" title="Chapter 1. python 1.0"> <link rel="start" href="../index.html" title="Chapter 1. python 1.0">
<link rel="up" href="../index.html" title="Chapter 1. python 1.0"> <link rel="up" href="../index.html" title="Chapter 1. python 1.0">
<link rel="prev" href="functions.html" title="Functions"> <link rel="prev" href="functions.html" title="Functions">
@@ -11,7 +11,7 @@
</head> </head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"> <body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<table cellpadding="2" width="100%"> <table cellpadding="2" width="100%">
<td valign="top"><img alt="boost.png (6897 bytes)" width="277" height="86" src="../../../../../../../boost.png"></td> <td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../../../../../boost.png"></td>
<td align="center"><a href="../../../../../../../index.htm">Home</a></td> <td align="center"><a href="../../../../../../../index.htm">Home</a></td>
<td align="center"><a href="../../../../../../../libs/libraries.htm">Libraries</a></td> <td align="center"><a href="../../../../../../../libs/libraries.htm">Libraries</a></td>
<td align="center"><a href="../../../../../../../people/people.htm">People</a></td> <td align="center"><a href="../../../../../../../people/people.htm">People</a></td>
@@ -32,33 +32,36 @@
<dt><span class="section"><a href="object.html#python.enums">Enums</a></span></dt> <dt><span class="section"><a href="object.html#python.enums">Enums</a></span></dt>
</dl></div> </dl></div>
<p> <p>
Object InterfacePython is dynamically typed, unlike C++ which is statically Python is dynamically typed, unlike C++ which is statically typed. Python variables
typed. Python variables may hold an integer, a float, list, dict, tuple, str, may hold an integer, a float, list, dict, tuple, str, long etc., among other
long etc., among other things. In the viewpoint of Boost.Python and C++, these things. In the viewpoint of Boost.Python and C++, these Pythonic variables
Pythonic variables are just instances of class <tt class="literal">object</tt>. We are just instances of class <code class="literal">object</code>. We shall see in this
shall see in this chapter how to deal with Python objects. chapter how to deal with Python objects.
</p> </p>
<p> <p>
As mentioned, one of the goals of Boost.Python is to provide a bidirectional As mentioned, one of the goals of Boost.Python is to provide a bidirectional
mapping between C++ and Python while maintaining the Python feel. Boost.Python mapping between C++ and Python while maintaining the Python feel. Boost.Python
C++ <tt class="literal">object</tt>s are as close as possible to Python. This should C++ <code class="literal">object</code>s are as close as possible to Python. This should
minimize the learning curve significantly. minimize the learning curve significantly.
</p> </p>
<p><span class="inlinemediaobject"><img src="../images/python.png"></span></p> <p>
<span class="inlinemediaobject"><img src="../images/python.png" alt="python"></span>
</p>
<div class="section" lang="en"> <div class="section" lang="en">
<div class="titlepage"><div><div><h3 class="title"> <div class="titlepage"><div><div><h3 class="title">
<a name="python.basic_interface"></a>Basic Interface</h3></div></div></div> <a name="python.basic_interface"></a>Basic Interface</h3></div></div></div>
<p> <p>
Basic InterfaceClass <tt class="literal">object</tt> wraps <tt class="literal">PyObject*</tt>. Class <code class="literal">object</code> wraps <code class="literal">PyObject*</code>. All the
All the intricacies of dealing with <tt class="literal">PyObject</tt>s such as intricacies of dealing with <code class="literal">PyObject</code>s such as managing
managing reference counting are handled by the <tt class="literal">object</tt> reference counting are handled by the <code class="literal">object</code> class. C++
class. C++ object interoperability is seamless. Boost.Python C++ <tt class="literal">object</tt>s object interoperability is seamless. Boost.Python C++ <code class="literal">object</code>s
can in fact be explicitly constructed from any C++ object. can in fact be explicitly constructed from any C++ object.
</p> </p>
<p> <p>
To illustrate, this Python code snippet: To illustrate, this Python code snippet:
</p> </p>
<p></p> <p>
</p>
<pre class="programlisting"> <pre class="programlisting">
<span class="keyword">def</span> <span class="identifier">f</span><span class="special">(</span><span class="identifier">x</span><span class="special">,</span> <span class="identifier">y</span><span class="special">):</span> <span class="keyword">def</span> <span class="identifier">f</span><span class="special">(</span><span class="identifier">x</span><span class="special">,</span> <span class="identifier">y</span><span class="special">):</span>
<span class="keyword">if</span> <span class="special">(</span><span class="identifier">y</span> <span class="special">==</span> <span class="string">'foo'</span><span class="special">):</span> <span class="keyword">if</span> <span class="special">(</span><span class="identifier">y</span> <span class="special">==</span> <span class="string">'foo'</span><span class="special">):</span>
@@ -73,7 +76,8 @@
<p> <p>
Can be rewritten in C++ using Boost.Python facilities this way: Can be rewritten in C++ using Boost.Python facilities this way:
</p> </p>
<p></p> <p>
</p>
<pre class="programlisting"> <pre class="programlisting">
<span class="identifier">object</span> <span class="identifier">f</span><span class="special">(</span><span class="identifier">object</span> <span class="identifier">x</span><span class="special">,</span> <span class="identifier">object</span> <span class="identifier">y</span><span class="special">)</span> <span class="special">{</span> <span class="identifier">object</span> <span class="identifier">f</span><span class="special">(</span><span class="identifier">object</span> <span class="identifier">x</span><span class="special">,</span> <span class="identifier">object</span> <span class="identifier">y</span><span class="special">)</span> <span class="special">{</span>
<span class="keyword">if</span> <span class="special">(</span><span class="identifier">y</span> <span class="special">==</span> <span class="string">"foo"</span><span class="special">)</span> <span class="keyword">if</span> <span class="special">(</span><span class="identifier">y</span> <span class="special">==</span> <span class="string">"foo"</span><span class="special">)</span>
@@ -95,8 +99,8 @@
<div class="titlepage"><div><div><h3 class="title"> <div class="titlepage"><div><div><h3 class="title">
<a name="python.derived_object_types"></a>Derived Object types</h3></div></div></div> <a name="python.derived_object_types"></a>Derived Object types</h3></div></div></div>
<p> <p>
Derived Object typesBoost.Python comes with a set of derived <tt class="literal">object</tt> Boost.Python comes with a set of derived <code class="literal">object</code> types
types corresponding to that of Python's: corresponding to that of Python's:
</p> </p>
<div class="itemizedlist"><ul type="disc"> <div class="itemizedlist"><ul type="disc">
<li> <li>
@@ -119,31 +123,32 @@
</li> </li>
</ul></div> </ul></div>
<p> <p>
These derived <tt class="literal">object</tt> types act like real Python types. These derived <code class="literal">object</code> types act like real Python types.
For instance: For instance:
</p> </p>
<pre class="programlisting"> <pre class="programlisting">
<span class="identifier">str</span><span class="special">(</span><span class="number">1</span><span class="special">)</span> <span class="special">==&gt;</span> <span class="string">"1"</span> <span class="identifier">str</span><span class="special">(</span><span class="number">1</span><span class="special">)</span> <span class="special">==&gt;</span> <span class="string">"1"</span>
</pre> </pre>
<p> <p>
Wherever appropriate, a particular derived <tt class="literal">object</tt> has Wherever appropriate, a particular derived <code class="literal">object</code> has
corresponding Python type's methods. For instance, <tt class="literal">dict</tt> corresponding Python type's methods. For instance, <code class="literal">dict</code>
has a <tt class="literal">keys()</tt> method: has a <code class="literal">keys()</code> method:
</p> </p>
<pre class="programlisting"> <pre class="programlisting">
<span class="identifier">d</span><span class="special">.</span><span class="identifier">keys</span><span class="special">()</span> <span class="identifier">d</span><span class="special">.</span><span class="identifier">keys</span><span class="special">()</span>
</pre> </pre>
<p><tt class="literal">make_tuple</tt> is provided for declaring <span class="emphasis"><em>tuple literals</em></span>. <p>
<code class="literal">make_tuple</code> is provided for declaring <span class="emphasis"><em>tuple literals</em></span>.
Example: Example:
</p> </p>
<pre class="programlisting"> <pre class="programlisting">
<span class="identifier">make_tuple</span><span class="special">(</span><span class="number">123</span><span class="special">,</span> <span class="char">'D'</span><span class="special">,</span> <span class="string">"Hello, World"</span><span class="special">,</span> <span class="number">0.0</span><span class="special">);</span> <span class="identifier">make_tuple</span><span class="special">(</span><span class="number">123</span><span class="special">,</span> <span class="char">'D'</span><span class="special">,</span> <span class="string">"Hello, World"</span><span class="special">,</span> <span class="number">0.0</span><span class="special">);</span>
</pre> </pre>
<p> <p>
In C++, when Boost.Python <tt class="literal">object</tt>s are used as arguments In C++, when Boost.Python <code class="literal">object</code>s are used as arguments
to functions, subtype matching is required. For example, when a function to functions, subtype matching is required. For example, when a function
<tt class="literal">f</tt>, as declared below, is wrapped, it will only accept <code class="literal">f</code>, as declared below, is wrapped, it will only accept
instances of Python's <tt class="literal">str</tt> type and subtypes. instances of Python's <code class="literal">str</code> type and subtypes.
</p> </p>
<pre class="programlisting"> <pre class="programlisting">
<span class="keyword">void</span> <span class="identifier">f</span><span class="special">(</span><span class="identifier">str</span> <span class="identifier">name</span><span class="special">)</span> <span class="keyword">void</span> <span class="identifier">f</span><span class="special">(</span><span class="identifier">str</span> <span class="identifier">name</span><span class="special">)</span>
@@ -167,16 +172,15 @@
<span class="identifier">object</span> <span class="identifier">msg</span> <span class="special">=</span> <span class="string">"%s is bigger than %s"</span> <span class="special">%</span> <span class="identifier">make_tuple</span><span class="special">(</span><span class="identifier">NAME</span><span class="special">,</span><span class="identifier">name</span><span class="special">);</span> <span class="identifier">object</span> <span class="identifier">msg</span> <span class="special">=</span> <span class="string">"%s is bigger than %s"</span> <span class="special">%</span> <span class="identifier">make_tuple</span><span class="special">(</span><span class="identifier">NAME</span><span class="special">,</span><span class="identifier">name</span><span class="special">);</span>
</pre> </pre>
<p> <p>
Demonstrates that you can write the C++ equivalent of <tt class="literal">"format" Demonstrates that you can write the C++ equivalent of <code class="literal">"format"
% x,y,z</tt> in Python, which is useful since there's no easy way to % x,y,z</code> in Python, which is useful since there's no easy way to
do that in std C++. do that in std C++.
</p> </p>
<div class="informaltable"><table class="table"> <div class="informaltable"><table class="table">
<colgroup><col></colgroup> <colgroup><col></colgroup>
<tbody><tr><td class="blurb"> <tbody><tr><td class="blurb"> <span class="inlinemediaobject"><img src="../images/alert.png" alt="alert"></span> <span class="bold"><strong>Beware</strong></span> the
<span class="inlinemediaobject"><img src="../images/alert.png"></span> <span class="bold"><b>Beware</b></span> the common pitfall of forgetting that common pitfall of forgetting that the constructors of most of Python's
the constructors of most of Python's mutable types make copies, just mutable types make copies, just as in Python. </td></tr></tbody>
as in Python. </td></tr></tbody>
</table></div> </table></div>
<p> <p>
Python: Python:
@@ -192,12 +196,12 @@
<span class="identifier">dict</span> <span class="identifier">d</span><span class="special">(</span><span class="identifier">x</span><span class="special">.</span><span class="identifier">attr</span><span class="special">(</span><span class="string">"__dict__"</span><span class="special">));</span> <span class="comment">// copies x.__dict__ <span class="identifier">dict</span> <span class="identifier">d</span><span class="special">(</span><span class="identifier">x</span><span class="special">.</span><span class="identifier">attr</span><span class="special">(</span><span class="string">"__dict__"</span><span class="special">));</span> <span class="comment">// copies x.__dict__
</span><span class="identifier">d</span><span class="special">[</span><span class="char">'whatever'</span><span class="special">]</span> <span class="special">=</span> <span class="number">3</span><span class="special">;</span> <span class="comment">// modifies the copy </span><span class="identifier">d</span><span class="special">[</span><span class="char">'whatever'</span><span class="special">]</span> <span class="special">=</span> <span class="number">3</span><span class="special">;</span> <span class="comment">// modifies the copy
</span></pre> </span></pre>
<a name="derived_object_types.class__lt_t_gt__as_objects"></a><h2> <a name="derived_object_types.class__lt_t_gt__as_objects"></a><h3>
<a name="id455806"></a> <a name="id3149441"></a>
class_&lt;T&gt; as objects class_&lt;T&gt; as objects
</h2> </h3>
<p> <p>
Due to the dynamic nature of Boost.Python objects, any <tt class="literal">class_&lt;T&gt;</tt> Due to the dynamic nature of Boost.Python objects, any <code class="literal">class_&lt;T&gt;</code>
may also be one of these types! The following code snippet wraps the class may also be one of these types! The following code snippet wraps the class
(type) object. (type) object.
</p> </p>
@@ -218,16 +222,16 @@
<div class="titlepage"><div><div><h3 class="title"> <div class="titlepage"><div><div><h3 class="title">
<a name="python.extracting_c___objects"></a>Extracting C++ objects</h3></div></div></div> <a name="python.extracting_c___objects"></a>Extracting C++ objects</h3></div></div></div>
<p> <p>
Extracting C++ objectsAt some point, we will need to get C++ values out of At some point, we will need to get C++ values out of object instances. This
object instances. This can be achieved with the <tt class="literal">extract&lt;T&gt;</tt> can be achieved with the <code class="literal">extract&lt;T&gt;</code> function. Consider
function. Consider the following: the following:
</p> </p>
<pre class="programlisting"> <pre class="programlisting">
<span class="keyword">double</span> <span class="identifier">x</span> <span class="special">=</span> <span class="identifier">o</span><span class="special">.</span><span class="identifier">attr</span><span class="special">(</span><span class="string">"length"</span><span class="special">);</span> <span class="comment">// compile error <span class="keyword">double</span> <span class="identifier">x</span> <span class="special">=</span> <span class="identifier">o</span><span class="special">.</span><span class="identifier">attr</span><span class="special">(</span><span class="string">"length"</span><span class="special">);</span> <span class="comment">// compile error
</span></pre> </span></pre>
<p> <p>
In the code above, we got a compiler error because Boost.Python <tt class="literal">object</tt> In the code above, we got a compiler error because Boost.Python <code class="literal">object</code>
can't be implicitly converted to <tt class="literal">double</tt>s. Instead, what can't be implicitly converted to <code class="literal">double</code>s. Instead, what
we wanted to do above can be achieved by writing: we wanted to do above can be achieved by writing:
</p> </p>
<pre class="programlisting"> <pre class="programlisting">
@@ -237,14 +241,14 @@
</pre> </pre>
<p> <p>
The first line attempts to extract the "length" attribute of the The first line attempts to extract the "length" attribute of the
Boost.Python <tt class="literal">object</tt>. The second line attempts to <span class="emphasis"><em>extract</em></span> Boost.Python <code class="literal">object</code>. The second line attempts to <span class="emphasis"><em>extract</em></span>
the <tt class="literal">Vec2</tt> object from held by the Boost.Python <tt class="literal">object</tt>. the <code class="literal">Vec2</code> object from held by the Boost.Python <code class="literal">object</code>.
</p> </p>
<p> <p>
Take note that we said "attempt to" above. What if the Boost.Python Take note that we said "attempt to" above. What if the Boost.Python
<tt class="literal">object</tt> does not really hold a <tt class="literal">Vec2</tt> <code class="literal">object</code> does not really hold a <code class="literal">Vec2</code>
type? This is certainly a possibility considering the dynamic nature of Python type? This is certainly a possibility considering the dynamic nature of Python
<tt class="literal">object</tt>s. To be on the safe side, if the C++ type can't <code class="literal">object</code>s. To be on the safe side, if the C++ type can't
be extracted, an appropriate exception is thrown. To avoid an exception, be extracted, an appropriate exception is thrown. To avoid an exception,
we need to test for extractibility: we need to test for extractibility:
</p> </p>
@@ -253,8 +257,8 @@
<span class="keyword">if</span> <span class="special">(</span><span class="identifier">x</span><span class="special">.</span><span class="identifier">check</span><span class="special">())</span> <span class="special">{</span> <span class="keyword">if</span> <span class="special">(</span><span class="identifier">x</span><span class="special">.</span><span class="identifier">check</span><span class="special">())</span> <span class="special">{</span>
<span class="identifier">Vec2</span><span class="special">&amp;</span> <span class="identifier">v</span> <span class="special">=</span> <span class="identifier">x</span><span class="special">();</span> <span class="special">...</span> <span class="identifier">Vec2</span><span class="special">&amp;</span> <span class="identifier">v</span> <span class="special">=</span> <span class="identifier">x</span><span class="special">();</span> <span class="special">...</span>
</pre> </pre>
<p><span class="inlinemediaobject"><img src="../images/tip.png"></span> <p>
The astute reader might have noticed that the <tt class="literal">extract&lt;T&gt;</tt> <span class="inlinemediaobject"><img src="../images/tip.png" alt="tip"></span> The astute reader might have noticed that the <code class="literal">extract&lt;T&gt;</code>
facility in fact solves the mutable copying problem: facility in fact solves the mutable copying problem:
</p> </p>
<pre class="programlisting"> <pre class="programlisting">
@@ -266,12 +270,12 @@
<div class="titlepage"><div><div><h3 class="title"> <div class="titlepage"><div><div><h3 class="title">
<a name="python.enums"></a>Enums</h3></div></div></div> <a name="python.enums"></a>Enums</h3></div></div></div>
<p> <p>
EnumsBoost.Python has a nifty facility to capture and wrap C++ enums. While Boost.Python has a nifty facility to capture and wrap C++ enums. While Python
Python has no <tt class="literal">enum</tt> type, we'll often want to expose our has no <code class="literal">enum</code> type, we'll often want to expose our C++ enums
C++ enums to Python as an <tt class="literal">int</tt>. Boost.Python's enum facility to Python as an <code class="literal">int</code>. Boost.Python's enum facility makes
makes this easy while taking care of the proper conversions from Python's this easy while taking care of the proper conversions from Python's dynamic
dynamic typing to C++'s strong static typing (in C++, ints cannot be implicitly typing to C++'s strong static typing (in C++, ints cannot be implicitly converted
converted to enums). To illustrate, given a C++ enum: to enums). To illustrate, given a C++ enum:
</p> </p>
<pre class="programlisting"> <pre class="programlisting">
<span class="keyword">enum</span> <span class="identifier">choice</span> <span class="special">{</span> <span class="identifier">red</span><span class="special">,</span> <span class="identifier">blue</span> <span class="special">};</span> <span class="keyword">enum</span> <span class="identifier">choice</span> <span class="special">{</span> <span class="identifier">red</span><span class="special">,</span> <span class="identifier">blue</span> <span class="special">};</span>
@@ -287,22 +291,23 @@
</pre> </pre>
<p> <p>
can be used to expose to Python. The new enum type is created in the current can be used to expose to Python. The new enum type is created in the current
<tt class="literal">scope()</tt>, which is usually the current module. The snippet <code class="literal">scope()</code>, which is usually the current module. The snippet
above creates a Python class derived from Python's <tt class="literal">int</tt> above creates a Python class derived from Python's <code class="literal">int</code>
type which is associated with the C++ type passed as its first parameter. type which is associated with the C++ type passed as its first parameter.
</p> </p>
<div class="informaltable"><table class="table"> <div class="informaltable"><table class="table">
<colgroup><col></colgroup> <colgroup><col></colgroup>
<tbody><tr><td class="blurb"> <tbody><tr><td class="blurb"> <span class="inlinemediaobject"><img src="../images/note.png" alt="note"></span> <span class="bold"><strong>what is a scope?</strong></span><br>
<span class="inlinemediaobject"><img src="../images/note.png"></span> <span class="bold"><b>what is a scope?</b></span><br><br> The scope is a <br> The scope is a class that has an associated global Python object
class that has an associated global Python object which controls the which controls the Python namespace in which new extension classes
Python namespace in which new extension classes and wrapped functions and wrapped functions will be defined as attributes. Details can be
will be defined as attributes. Details can be found <a href="../../../../v2/scope.html" target="_top">here</a>.</td></tr></tbody> found <a href="../../../../v2/scope.html" target="_top">here</a>.</td></tr></tbody>
</table></div> </table></div>
<p> <p>
You can access those values in Python as You can access those values in Python as
</p> </p>
<p></p> <p>
</p>
<pre class="programlisting"> <pre class="programlisting">
<span class="special">&gt;&gt;&gt;</span> <span class="identifier">my_module</span><span class="special">.</span><span class="identifier">choice</span><span class="special">.</span><span class="identifier">red</span> <span class="special">&gt;&gt;&gt;</span> <span class="identifier">my_module</span><span class="special">.</span><span class="identifier">choice</span><span class="special">.</span><span class="identifier">red</span>
<span class="identifier">my_module</span><span class="special">.</span><span class="identifier">choice</span><span class="special">.</span><span class="identifier">red</span> <span class="identifier">my_module</span><span class="special">.</span><span class="identifier">choice</span><span class="special">.</span><span class="identifier">red</span>
@@ -311,7 +316,8 @@
where my_module is the module where the enum is declared. You can also create where my_module is the module where the enum is declared. You can also create
a new scope around a class: a new scope around a class:
</p> </p>
<p></p> <p>
</p>
<pre class="programlisting"> <pre class="programlisting">
<span class="identifier">scope</span> <span class="identifier">in_X</span> <span class="special">=</span> <span class="identifier">class_</span><span class="special">&lt;</span><span class="identifier">X</span><span class="special">&gt;(</span><span class="string">"X"</span><span class="special">)</span> <span class="identifier">scope</span> <span class="identifier">in_X</span> <span class="special">=</span> <span class="identifier">class_</span><span class="special">&lt;</span><span class="identifier">X</span><span class="special">&gt;(</span><span class="string">"X"</span><span class="special">)</span>
<span class="special">.</span><span class="identifier">def</span><span class="special">(</span> <span class="special">...</span> <span class="special">)</span> <span class="special">.</span><span class="identifier">def</span><span class="special">(</span> <span class="special">...</span> <span class="special">)</span>

View File

@@ -1,16 +1,16 @@
<html> <html>
<head> <head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title> General Techniques</title> <title>General Techniques</title>
<link rel="stylesheet" href="../boostbook.css" type="text/css"> <link rel="stylesheet" href="../boostbook.css" type="text/css">
<meta name="generator" content="DocBook XSL Stylesheets V1.66.1"> <meta name="generator" content="DocBook XSL Stylesheets V1.72.0">
<link rel="start" href="../index.html" title="Chapter 1. python 1.0"> <link rel="start" href="../index.html" title="Chapter 1. python 1.0">
<link rel="up" href="../index.html" title="Chapter 1. python 1.0"> <link rel="up" href="../index.html" title="Chapter 1. python 1.0">
<link rel="prev" href="exception.html" title=" Exception Translation"> <link rel="prev" href="exception.html" title="Exception Translation">
</head> </head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"> <body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<table cellpadding="2" width="100%"> <table cellpadding="2" width="100%">
<td valign="top"><img alt="boost.png (6897 bytes)" width="277" height="86" src="../../../../../../../boost.png"></td> <td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../../../../../boost.png"></td>
<td align="center"><a href="../../../../../../../index.htm">Home</a></td> <td align="center"><a href="../../../../../../../index.htm">Home</a></td>
<td align="center"><a href="../../../../../../../libs/libraries.htm">Libraries</a></td> <td align="center"><a href="../../../../../../../libs/libraries.htm">Libraries</a></td>
<td align="center"><a href="../../../../../../../people/people.htm">People</a></td> <td align="center"><a href="../../../../../../../people/people.htm">People</a></td>
@@ -30,16 +30,16 @@
<dt><span class="section"><a href="techniques.html#python.reducing_compiling_time">Reducing Compiling Time</a></span></dt> <dt><span class="section"><a href="techniques.html#python.reducing_compiling_time">Reducing Compiling Time</a></span></dt>
</dl></div> </dl></div>
<p> <p>
General TechniquesHere are presented some useful techniques that you can use Here are presented some useful techniques that you can use while wrapping code
while wrapping code with Boost.Python. with Boost.Python.
</p> </p>
<div class="section" lang="en"> <div class="section" lang="en">
<div class="titlepage"><div><div><h3 class="title"> <div class="titlepage"><div><div><h3 class="title">
<a name="python.creating_packages"></a>Creating Packages</h3></div></div></div> <a name="python.creating_packages"></a>Creating Packages</h3></div></div></div>
<p> <p>
Creating PackagesA Python package is a collection of modules that provide A Python package is a collection of modules that provide to the user a certain
to the user a certain functionality. If you're not familiar on how to create functionality. If you're not familiar on how to create packages, a good introduction
packages, a good introduction to them is provided in the <a href="http://www.python.org/doc/current/tut/node8.html" target="_top">Python to them is provided in the <a href="http://www.python.org/doc/current/tut/node8.html" target="_top">Python
Tutorial</a>. Tutorial</a>.
</p> </p>
<p> <p>
@@ -50,7 +50,7 @@
<p> <p>
We have a C++ library that works with sounds: reading and writing various We have a C++ library that works with sounds: reading and writing various
formats, applying filters to the sound data, etc. It is named (conveniently) formats, applying filters to the sound data, etc. It is named (conveniently)
<tt class="literal">sounds</tt>. Our library already has a neat C++ namespace hierarchy, <code class="literal">sounds</code>. Our library already has a neat C++ namespace hierarchy,
like so: like so:
</p> </p>
<pre class="programlisting"> <pre class="programlisting">
@@ -93,17 +93,15 @@
<span class="special">}</span> <span class="special">}</span>
</pre> </pre>
<p> <p>
Compiling these files will generate the following Python extensions: <tt class="literal">core.pyd</tt>, Compiling these files will generate the following Python extensions: <code class="literal">core.pyd</code>,
<tt class="literal">io.pyd</tt> and <tt class="literal">filters.pyd</tt>. <code class="literal">io.pyd</code> and <code class="literal">filters.pyd</code>.
</p> </p>
<div class="informaltable"><table class="table"> <div class="informaltable"><table class="table">
<colgroup><col></colgroup> <colgroup><col></colgroup>
<tbody><tr><td class="blurb"> <tbody><tr><td class="blurb"> <span class="inlinemediaobject"><img src="../images/note.png" alt="note"></span> The extension <code class="literal">.pyd</code> is used
<span class="inlinemediaobject"><img src="../images/note.png"></span> for python extension modules, which are just shared libraries. Using
The extension <tt class="literal">.pyd</tt> is used for python extension the default for your system, like <code class="literal">.so</code> for Unix and
modules, which are just shared libraries. Using the default for your <code class="literal">.dll</code> for Windows, works just as well.</td></tr></tbody>
system, like <tt class="literal">.so</tt> for Unix and <tt class="literal">.dll</tt>
for Windows, works just as well.</td></tr></tbody>
</table></div> </table></div>
<p> <p>
Now, we create this directory structure for our Python package: Now, we create this directory structure for our Python package:
@@ -115,16 +113,17 @@
io.pyd io.pyd
</pre> </pre>
<p> <p>
The file <tt class="literal">__init__.py</tt> is what tells Python that the directory The file <code class="literal">__init__.py</code> is what tells Python that the directory
<tt class="literal">sounds/</tt> is actually a Python package. It can be a empty <code class="literal">sounds/</code> is actually a Python package. It can be a empty
file, but can also perform some magic, that will be shown later. file, but can also perform some magic, that will be shown later.
</p> </p>
<p> <p>
Now our package is ready. All the user has to do is put <tt class="literal">sounds</tt> Now our package is ready. All the user has to do is put <code class="literal">sounds</code>
into his <a href="http://www.python.org/doc/current/tut/node8.html#SECTION008110000000000000000" target="_top">PYTHONPATH</a> into his <a href="http://www.python.org/doc/current/tut/node8.html#SECTION008110000000000000000" target="_top">PYTHONPATH</a>
and fire up the interpreter: and fire up the interpreter:
</p> </p>
<p></p> <p>
</p>
<pre class="programlisting"> <pre class="programlisting">
<span class="special">&gt;&gt;&gt;</span> <span class="keyword">import</span> <span class="identifier">sounds</span><span class="special">.</span><span class="identifier">io</span> <span class="special">&gt;&gt;&gt;</span> <span class="keyword">import</span> <span class="identifier">sounds</span><span class="special">.</span><span class="identifier">io</span>
<span class="special">&gt;&gt;&gt;</span> <span class="keyword">import</span> <span class="identifier">sounds</span><span class="special">.</span><span class="identifier">filters</span> <span class="special">&gt;&gt;&gt;</span> <span class="keyword">import</span> <span class="identifier">sounds</span><span class="special">.</span><span class="identifier">filters</span>
@@ -146,7 +145,8 @@
If we want this flexibility, we will have to complicate our package hierarchy If we want this flexibility, we will have to complicate our package hierarchy
a little. First, we will have to change the name of the extension modules: a little. First, we will have to change the name of the extension modules:
</p> </p>
<p></p> <p>
</p>
<pre class="programlisting"> <pre class="programlisting">
<span class="comment">/* file core.cpp */</span> <span class="comment">/* file core.cpp */</span>
<span class="identifier">BOOST_PYTHON_MODULE</span><span class="special">(</span><span class="identifier">_core</span><span class="special">)</span> <span class="identifier">BOOST_PYTHON_MODULE</span><span class="special">(</span><span class="identifier">_core</span><span class="special">)</span>
@@ -157,7 +157,7 @@
</pre> </pre>
<p> <p>
Note that we added an underscore to the module name. The filename will have Note that we added an underscore to the module name. The filename will have
to be changed to <tt class="literal">_core.pyd</tt> as well, and we do the same to be changed to <code class="literal">_core.pyd</code> as well, and we do the same
to the other extension modules. Now, we change our package hierarchy like to the other extension modules. Now, we change our package hierarchy like
so: so:
</p> </p>
@@ -178,17 +178,18 @@
to each one. But if we leave it that way, the user will have to access the to each one. But if we leave it that way, the user will have to access the
functions in the core module with this syntax: functions in the core module with this syntax:
</p> </p>
<p></p> <p>
</p>
<pre class="programlisting"> <pre class="programlisting">
<span class="special">&gt;&gt;&gt;</span> <span class="keyword">import</span> <span class="identifier">sounds</span><span class="special">.</span><span class="identifier">core</span><span class="special">.</span><span class="identifier">_core</span> <span class="special">&gt;&gt;&gt;</span> <span class="keyword">import</span> <span class="identifier">sounds</span><span class="special">.</span><span class="identifier">core</span><span class="special">.</span><span class="identifier">_core</span>
<span class="special">&gt;&gt;&gt;</span> <span class="identifier">sounds</span><span class="special">.</span><span class="identifier">core</span><span class="special">.</span><span class="identifier">_core</span><span class="special">.</span><span class="identifier">foo</span><span class="special">(...)</span> <span class="special">&gt;&gt;&gt;</span> <span class="identifier">sounds</span><span class="special">.</span><span class="identifier">core</span><span class="special">.</span><span class="identifier">_core</span><span class="special">.</span><span class="identifier">foo</span><span class="special">(...)</span>
</pre> </pre>
<p> <p>
which is not what we want. But here enters the <tt class="literal">__init__.py</tt> which is not what we want. But here enters the <code class="literal">__init__.py</code>
magic: everything that is brought to the <tt class="literal">__init__.py</tt> namespace magic: everything that is brought to the <code class="literal">__init__.py</code> namespace
can be accessed directly by the user. So, all we have to do is bring the can be accessed directly by the user. So, all we have to do is bring the
entire namespace from <tt class="literal">_core.pyd</tt> to <tt class="literal">core/__init__.py</tt>. entire namespace from <code class="literal">_core.pyd</code> to <code class="literal">core/__init__.py</code>.
So add this line of code to <tt class="literal">sounds<span class="emphasis"><em>core</em></span>__init__.py</tt>: So add this line of code to <code class="literal">sounds<span class="emphasis"><em>core</em></span>__init__.py</code>:
</p> </p>
<pre class="programlisting"> <pre class="programlisting">
<span class="keyword">from</span> <span class="identifier">_core</span> <span class="keyword">import</span> <span class="special">*</span> <span class="keyword">from</span> <span class="identifier">_core</span> <span class="keyword">import</span> <span class="special">*</span>
@@ -205,10 +206,10 @@
with the additional benefit that we can easily add pure Python functions with the additional benefit that we can easily add pure Python functions
to any module, in a way that the user can't tell the difference between a to any module, in a way that the user can't tell the difference between a
C++ function and a Python function. Let's add a <span class="emphasis"><em>pure</em></span> C++ function and a Python function. Let's add a <span class="emphasis"><em>pure</em></span>
Python function, <tt class="literal">echo_noise</tt>, to the <tt class="literal">filters</tt> Python function, <code class="literal">echo_noise</code>, to the <code class="literal">filters</code>
package. This function applies both the <tt class="literal">echo</tt> and <tt class="literal">noise</tt> package. This function applies both the <code class="literal">echo</code> and <code class="literal">noise</code>
filters in sequence in the given <tt class="literal">sound</tt> object. We create filters in sequence in the given <code class="literal">sound</code> object. We create
a file named <tt class="literal">sounds/filters/echo_noise.py</tt> and code our a file named <code class="literal">sounds/filters/echo_noise.py</code> and code our
function: function:
</p> </p>
<pre class="programlisting"> <pre class="programlisting">
@@ -219,14 +220,14 @@
<span class="keyword">return</span> <span class="identifier">s</span> <span class="keyword">return</span> <span class="identifier">s</span>
</pre> </pre>
<p> <p>
Next, we add this line to <tt class="literal">sounds<span class="emphasis"><em>filters</em></span>__init__.py</tt>: Next, we add this line to <code class="literal">sounds<span class="emphasis"><em>filters</em></span>__init__.py</code>:
</p> </p>
<pre class="programlisting"> <pre class="programlisting">
<span class="keyword">from</span> <span class="identifier">echo_noise</span> <span class="keyword">import</span> <span class="identifier">echo_noise</span> <span class="keyword">from</span> <span class="identifier">echo_noise</span> <span class="keyword">import</span> <span class="identifier">echo_noise</span>
</pre> </pre>
<p> <p>
And that's it. The user now accesses this function like any other function And that's it. The user now accesses this function like any other function
from the <tt class="literal">filters</tt> package: from the <code class="literal">filters</code> package:
</p> </p>
<pre class="programlisting"> <pre class="programlisting">
<span class="special">&gt;&gt;&gt;</span> <span class="keyword">import</span> <span class="identifier">sounds</span><span class="special">.</span><span class="identifier">filters</span> <span class="special">&gt;&gt;&gt;</span> <span class="keyword">import</span> <span class="identifier">sounds</span><span class="special">.</span><span class="identifier">filters</span>
@@ -237,8 +238,8 @@
<div class="titlepage"><div><div><h3 class="title"> <div class="titlepage"><div><div><h3 class="title">
<a name="python.extending_wrapped_objects_in_python"></a>Extending Wrapped Objects in Python</h3></div></div></div> <a name="python.extending_wrapped_objects_in_python"></a>Extending Wrapped Objects in Python</h3></div></div></div>
<p> <p>
Extending Wrapped Objects in PythonThanks to Python's flexibility, you can Thanks to Python's flexibility, you can easily add new methods to a class,
easily add new methods to a class, even after it was already created: even after it was already created:
</p> </p>
<pre class="programlisting"> <pre class="programlisting">
<span class="special">&gt;&gt;&gt;</span> <span class="keyword">class</span> <span class="identifier">C</span><span class="special">(</span><span class="identifier">object</span><span class="special">):</span> <span class="keyword">pass</span> <span class="special">&gt;&gt;&gt;</span> <span class="keyword">class</span> <span class="identifier">C</span><span class="special">(</span><span class="identifier">object</span><span class="special">):</span> <span class="keyword">pass</span>
@@ -256,12 +257,14 @@
<span class="identifier">A</span> <span class="identifier">C</span> <span class="identifier">instance</span><span class="special">!</span> <span class="identifier">A</span> <span class="identifier">C</span> <span class="identifier">instance</span><span class="special">!</span>
</pre> </pre>
<p> <p>
Yes, Python rox. <span class="inlinemediaobject"><img src="../images/smiley.png"></span></p> Yes, Python rox. <span class="inlinemediaobject"><img src="../images/smiley.png" alt="smiley"></span>
</p>
<p> <p>
We can do the same with classes that were wrapped with Boost.Python. Suppose We can do the same with classes that were wrapped with Boost.Python. Suppose
we have a class <tt class="literal">point</tt> in C++: we have a class <code class="literal">point</code> in C++:
</p>
<p>
</p> </p>
<p></p>
<pre class="programlisting"> <pre class="programlisting">
<span class="keyword">class</span> <span class="identifier">point</span> <span class="special">{...};</span> <span class="keyword">class</span> <span class="identifier">point</span> <span class="special">{...};</span>
@@ -272,9 +275,10 @@
</pre> </pre>
<p> <p>
If we are using the technique from the previous session, <a href="techniques.html#python.creating_packages" title="Creating Packages">Creating If we are using the technique from the previous session, <a href="techniques.html#python.creating_packages" title="Creating Packages">Creating
Packages</a>, we can code directly into <tt class="literal">geom/__init__.py</tt>: Packages</a>, we can code directly into <code class="literal">geom/__init__.py</code>:
</p>
<p>
</p> </p>
<p></p>
<pre class="programlisting"> <pre class="programlisting">
<span class="keyword">from</span> <span class="identifier">_geom</span> <span class="keyword">import</span> <span class="special">*</span> <span class="keyword">from</span> <span class="identifier">_geom</span> <span class="keyword">import</span> <span class="special">*</span>
@@ -285,7 +289,8 @@
<span class="comment"># now we turn it into a member function <span class="comment"># now we turn it into a member function
</span><span class="identifier">point</span><span class="special">.</span><span class="identifier">__str__</span> <span class="special">=</span> <span class="identifier">point_str</span> </span><span class="identifier">point</span><span class="special">.</span><span class="identifier">__str__</span> <span class="special">=</span> <span class="identifier">point_str</span>
</pre> </pre>
<p><span class="bold"><b>All</b></span> point instances created from C++ will <p>
<span class="bold"><strong>All</strong></span> point instances created from C++ will
also have this member function! This technique has several advantages: also have this member function! This technique has several advantages:
</p> </p>
<div class="itemizedlist"><ul type="disc"> <div class="itemizedlist"><ul type="disc">
@@ -357,12 +362,13 @@
<div class="titlepage"><div><div><h3 class="title"> <div class="titlepage"><div><div><h3 class="title">
<a name="python.reducing_compiling_time"></a>Reducing Compiling Time</h3></div></div></div> <a name="python.reducing_compiling_time"></a>Reducing Compiling Time</h3></div></div></div>
<p> <p>
Reducing Compiling TimeIf you have ever exported a lot of classes, you know If you have ever exported a lot of classes, you know that it takes quite
that it takes quite a good time to compile the Boost.Python wrappers. Plus a good time to compile the Boost.Python wrappers. Plus the memory consumption
the memory consumption can easily become too high. If this is causing you can easily become too high. If this is causing you problems, you can split
problems, you can split the class_ definitions in multiple files: the class_ definitions in multiple files:
</p>
<p>
</p> </p>
<p></p>
<pre class="programlisting"> <pre class="programlisting">
<span class="comment">/* file point.cpp */</span> <span class="comment">/* file point.cpp */</span>
<span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">point</span><span class="special">.</span><span class="identifier">h</span><span class="special">&gt;</span> <span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">point</span><span class="special">.</span><span class="identifier">h</span><span class="special">&gt;</span>
@@ -383,7 +389,7 @@
<span class="special">}</span> <span class="special">}</span>
</pre> </pre>
<p> <p>
Now you create a file <tt class="literal">main.cpp</tt>, which contains the <tt class="literal">BOOST_PYTHON_MODULE</tt> Now you create a file <code class="literal">main.cpp</code>, which contains the <code class="literal">BOOST_PYTHON_MODULE</code>
macro, and call the various export functions inside it. macro, and call the various export functions inside it.
</p> </p>
<pre class="programlisting"> <pre class="programlisting">
@@ -421,19 +427,16 @@
</p> </p>
<div class="informaltable"><table class="table"> <div class="informaltable"><table class="table">
<colgroup><col></colgroup> <colgroup><col></colgroup>
<tbody><tr><td class="blurb"> <tbody><tr><td class="blurb"> <span class="inlinemediaobject"><img src="../images/note.png" alt="note"></span> If you're exporting your classes with <a href="../../../../../pyste/index.html" target="_top">Pyste</a>,
<span class="inlinemediaobject"><img src="../images/note.png"></span> take a look at the <code class="literal">--multiple</code> option, that generates
If you're exporting your classes with <a href="../../../../../pyste/index.html" target="_top">Pyste</a>,
take a look at the <tt class="literal">--multiple</tt> option, that generates
the wrappers in various files as demonstrated here.</td></tr></tbody> the wrappers in various files as demonstrated here.</td></tr></tbody>
</table></div> </table></div>
<div class="informaltable"><table class="table"> <div class="informaltable"><table class="table">
<colgroup><col></colgroup> <colgroup><col></colgroup>
<tbody><tr><td class="blurb"> <tbody><tr><td class="blurb"> <span class="inlinemediaobject"><img src="../images/note.png" alt="note"></span> This method is useful too if you are getting the
<span class="inlinemediaobject"><img src="../images/note.png"></span> error message <span class="emphasis"><em>"fatal error C1204:Compiler limit:internal
This method is useful too if you are getting the error message <span class="emphasis"><em>"fatal structure overflow"</em></span> when compiling a large source file,
error C1204:Compiler limit:internal structure overflow"</em></span> as explained in the <a href="../../../../v2/faq.html#c1204" target="_top">FAQ</a>.</td></tr></tbody>
when compiling a large source file, as explained in the <a href="../../../../v2/faq.html#c1204" target="_top">FAQ</a>.</td></tr></tbody>
</table></div> </table></div>
</div> </div>
</div> </div>

View File

@@ -252,9 +252,10 @@ if you are on Windows, and
if you are on Unix. if you are on Unix.
[^boost_python.dll] and [^hello.pyd] can be found somewhere in your project's [^boost_python.dll] and [^hello.pyd] can be found somewhere in your project's
[^bin] directory. After a successful build, you can just link in these DLLs with [^bin] directory. After a successful build, you make it possible for the system
the Python interpreter. In Windows for example, you can simply put these libraries to find boost_python.dll or libboost_python.so (usually done with LD_LIBRARY_PATH,
inside the directory where the Python executable is. DYLD_LIBRARY_PATH, or some other variable on *nix and with PATH on Windows) and
for Python to find the hello module (Done with PYTHONPATH on all systems.)
You may now fire up Python and run our hello module: You may now fire up Python and run our hello module:
@@ -1099,7 +1100,7 @@ overloaded functions in one-shot:
Then... Then...
.def("foo", foo, foo_overloads()); .def("foo", (void(*)(bool, int, char))0, foo_overloads());
Notice though that we have a situation now where we have a minimum of zero Notice though that we have a situation now where we have a minimum of zero
(0) arguments and a maximum of 3 arguments. (0) arguments and a maximum of 3 arguments.
@@ -1364,11 +1365,6 @@ create a new scope around a class:
[def Py_Initialize [@http://www.python.org/doc/current/api/initialization.html#l2h-652 Py_Initialize]] [def Py_Initialize [@http://www.python.org/doc/current/api/initialization.html#l2h-652 Py_Initialize]]
[def Py_Finalize [@http://www.python.org/doc/current/api/initialization.html#l2h-656 Py_Finalize]] [def Py_Finalize [@http://www.python.org/doc/current/api/initialization.html#l2h-656 Py_Finalize]]
[def PyRun_String [@http://www.python.org/doc/current/api/veryhigh.html#l2h-55 PyRun_String]]
[def PyRun_File [@http://www.python.org/doc/current/api/veryhigh.html#l2h-56 PyRun_File]]
[def Py_eval_input [@http://www.python.org/doc/current/api/veryhigh.html#l2h-58 Py_eval_input]]
[def Py_file_input [@http://www.python.org/doc/current/api/veryhigh.html#l2h-59 Py_file_input]]
[def Py_single_input [@http://www.python.org/doc/current/api/veryhigh.html#l2h-60 Py_single_input]]
[def Py_XINCREF [@http://www.python.org/doc/current/api/countingRefs.html#l2h-65 Py_XINCREF]] [def Py_XINCREF [@http://www.python.org/doc/current/api/countingRefs.html#l2h-65 Py_XINCREF]]
[def Py_XDECREF [@http://www.python.org/doc/current/api/countingRefs.html#l2h-67 Py_XDECREF]] [def Py_XDECREF [@http://www.python.org/doc/current/api/countingRefs.html#l2h-67 Py_XDECREF]]
[def PyImport_AppendInittab [@http://www.python.org/doc/current/api/importing.html#l2h-137 PyImport_AppendInittab]] [def PyImport_AppendInittab [@http://www.python.org/doc/current/api/importing.html#l2h-137 PyImport_AppendInittab]]
@@ -1395,17 +1391,17 @@ all. So stay tuned... :-)
[h2 Building embedded programs] [h2 Building embedded programs]
To be able to use embedding in your programs, they have to be linked to To be able to embed python into your programs, you have to link to
both Boost.Python's and Python's static link library. both Boost.Python's as well as Python's own runtime library.
Boost.Python's static link library comes in two variants. Both are located Boost.Python's library comes in two variants. Both are located
in Boost's [^/libs/python/build/bin-stage] subdirectory. On Windows, the in Boost's [^/libs/python/build/bin-stage] subdirectory. On Windows, the
variants are called [^boost_python.lib] (for release builds) and variants are called [^boost_python.lib] (for release builds) and
[^boost_python_debug.lib] (for debugging). If you can't find the libraries, [^boost_python_debug.lib] (for debugging). If you can't find the libraries,
you probably haven't built Boost.Python yet. See you probably haven't built Boost.Python yet. See
[@../../../building.html Building and Testing] on how to do this. [@../../../building.html Building and Testing] on how to do this.
Python's static link library can be found in the [^/libs] subdirectory of Python's library can be found in the [^/libs] subdirectory of
your Python directory. On Windows it is called pythonXY.lib where X.Y is your Python directory. On Windows it is called pythonXY.lib where X.Y is
your major Python version number. your major Python version number.
@@ -1443,7 +1439,11 @@ steps:
# Call other Python C API routines to use the interpreter.\n\n # Call other Python C API routines to use the interpreter.\n\n
# Call Py_Finalize() to stop the interpreter and release its resources. [/ # Call Py_Finalize() to stop the interpreter and release its resources.]
[blurb __note__ [*Note that at this time you must not call Py_Finalize() to stop the
interpreter. This may be fixed in a future version of boost.python.]
]
(Of course, there can be other C++ code between all of these steps.) (Of course, there can be other C++ code between all of these steps.)
@@ -1460,171 +1460,76 @@ messy and especially hard to get right in the presence of C++ exceptions.
Fortunately Boost.Python provides the [@../../../v2/handle.html handle] and Fortunately Boost.Python provides the [@../../../v2/handle.html handle] and
[@../../../v2/object.html object] class templates to automate the process. [@../../../v2/object.html object] class templates to automate the process.
[h2 Reference-counting handles and objects]
There are two ways in which a function in the Python/C API can return a
[^PyObject*]: as a ['borrowed reference] or as a ['new reference]. Which of
these a function uses, is listed in that function's documentation. The two
require slightely different approaches to reference-counting but both can
be 'handled' by Boost.Python.
For a function returning a ['borrowed reference] we'll have to tell the
[^handle] that the [^PyObject*] is borrowed with the aptly named
[@../../../v2/handle.html#borrowed-spec borrowed] function. Two functions
returning borrowed references are PyImport_AddModule and PyModule_GetDict.
The former returns a reference to an already imported module, the latter
retrieves a module's namespace dictionary. Let's use them to retrieve the
namespace of the [^__main__] module:
object main_module((
handle<>(borrowed(PyImport_AddModule("__main__")))));
object main_namespace = main_module.attr("__dict__");
For a function returning a ['new reference] we can just create a [^handle]
out of the raw [^PyObject*] without wrapping it in a call to borrowed. One
such function that returns a new reference is PyRun_String which we'll
discuss in the next section.
[blurb __note__ [*Handle is a class ['template], so why haven't we been using any template parameters?]\n
\n
[^handle] has a single template parameter specifying the type of the managed object. This type is [^PyObject] 99% of the time, so the parameter was defaulted to [^PyObject] for convenience. Therefore we can use the shorthand [^handle<>] instead of the longer, but equivalent, [^handle<PyObject>].
]
[h2 Running Python code] [h2 Running Python code]
To run Python code from C++ there is a family of functions in the API Boost.python provides three related functions to run Python code from C++.
starting with the PyRun prefix. You can find the full list of these
functions [@http://www.python.org/doc/current/api/veryhigh.html here]. They
all work similarly so we will look at only one of them, namely:
PyObject* PyRun_String(char *str, int start, PyObject *globals, PyObject *locals) object eval(str expression, object globals = object(), object locals = object())
object exec(str code, object globals = object(), object locals = object())
object exec_file(str filename, object globals = object(), object locals = object())
PyRun_String takes the code to execute as a null-terminated (C-style) eval evaluates the given expression and returns the resulting value.
string in its [^str] parameter. The function returns a new reference to a exec executes the given code (typically a set of statements) returning the result,
Python object. Which object is returned depends on the [^start] paramater. and exec_file executes the code contained in the given file.
The [^start] parameter is the start symbol from the Python grammar to use The [^globals] and [^locals] parameters are Python dictionaries
for interpreting the code. The possible values are:
[table Start symbols
[[Py_eval_input] [for interpreting isolated expressions]]
[[Py_file_input] [for interpreting sequences of statements]]
[[Py_single_input] [for interpreting a single statement]]
]
When using Py_eval_input, the input string must contain a single expression
and its result is returned. When using Py_file_input, the string can
contain an abitrary number of statements and None is returned.
Py_single_input works in the same way as Py_file_input but only accepts a
single statement.
Lastly, the [^globals] and [^locals] parameters are Python dictionaries
containing the globals and locals of the context in which to run the code. containing the globals and locals of the context in which to run the code.
For most intents and purposes you can use the namespace dictionary of the For most intents and purposes you can use the namespace dictionary of the
[^__main__] module for both parameters. [^__main__] module for both parameters.
We have already seen how to get the [^__main__] module's namespace so let's Boost.python provides a function to import a module:
run some Python code in it:
object main_module(( object import(str name)
handle<>(borrowed(PyImport_AddModule("__main__")))));
import imports a python module (potentially loading it into the running process
first), and returns it.
Let's import the [^__main__] module and run some Python code in its namespace:
object main_module = import("__main__");
object main_namespace = main_module.attr("__dict__"); object main_namespace = main_module.attr("__dict__");
handle<> ignored((PyRun_String( object ignored = exec("hello = file('hello.txt', 'w')\n"
"hello.write('Hello world!')\n"
"hello = file('hello.txt', 'w')\n" "hello.close()",
"hello.write('Hello world!')\n" main_namespace);
"hello.close()"
, Py_file_input
, main_namespace.ptr()
, main_namespace.ptr())
));
Because the Python/C API doesn't know anything about [^object]s, we used
the object's [^ptr] member function to retrieve the [^PyObject*].
This should create a file called 'hello.txt' in the current directory This should create a file called 'hello.txt' in the current directory
containing a phrase that is well-known in programming circles. containing a phrase that is well-known in programming circles.
[blurb [h2 Manipulating Python objects]
__note__ [*Note] that we wrap the return value of PyRun_String in a
(nameless) [^handle] even though we are not interested in it. If we didn't
do this, the the returned object would be kept alive unnecessarily. Unless
you want to be a Dr. Frankenstein, always wrap [^PyObject*]s in [^handle]s.
]
[h2 Beyond handles] Often we'd like to have a class to manipulate Python objects.
But we have already seen such a class above, and in the
It's nice that [^handle] manages the reference counting details for us, but [@python/object.html previous section]: the aptly named [^object] class
other than that it doesn't do much. Often we'd like to have a more useful and its derivatives. We've already seen that they can be constructed from
class to manipulate Python objects. But we have already seen such a class a [^handle]. The following examples should further illustrate this fact:
above, and in the [@python/object.html previous section]: the aptly
named [^object] class and it's derivatives. We've already seen that they
can be constructed from a [^handle]. The following examples should further
illustrate this fact:
object main_module((
handle<>(borrowed(PyImport_AddModule("__main__")))));
object main_module = import("__main__");
object main_namespace = main_module.attr("__dict__"); object main_namespace = main_module.attr("__dict__");
object ignored = exec("result = 5 ** 2", main_namespace);
handle<> ignored((PyRun_String(
"result = 5 ** 2"
, Py_file_input
, main_namespace.ptr()
, main_namespace.ptr())
));
int five_squared = extract<int>(main_namespace["result"]); int five_squared = extract<int>(main_namespace["result"]);
Here we create a dictionary object for the [^__main__] module's namespace. Here we create a dictionary object for the [^__main__] module's namespace.
Then we assign 5 squared to the result variable and read this variable from Then we assign 5 squared to the result variable and read this variable from
the dictionary. Another way to achieve the same result is to let the dictionary. Another way to achieve the same result is to use eval instead,
PyRun_String return the result directly with Py_eval_input: which returns the result directly:
object result((handle<>(
PyRun_String("5 ** 2"
, Py_eval_input
, main_namespace.ptr()
, main_namespace.ptr()))
));
object result = eval("5 ** 2");
int five_squared = extract<int>(result); int five_squared = extract<int>(result);
[blurb
__note__ [*Note] that [^object]'s member function to return the wrapped
[^PyObject*] is called [^ptr] instead of [^get]. This makes sense if you
take into account the different functions that [^object] and [^handle]
perform.
]
[h2 Exception handling] [h2 Exception handling]
If an exception occurs in the execution of some Python code, the PyRun_String If an exception occurs in the evaluation of the python expression,
function returns a null pointer. Constructing a [^handle] out of this null [@../../../v2/errors.html#error_already_set-spec error_already_set] is thrown:
pointer throws [@../../../v2/errors.html#error_already_set-spec error_already_set],
so basically, the Python exception is automatically translated into a
C++ exception when using [^handle]:
try try
{ {
object result((handle<>(PyRun_String( object result = eval("5/0");
"5/0"
, Py_eval_input
, main_namespace.ptr()
, main_namespace.ptr()))
));
// execution will never get here: // execution will never get here:
int five_divided_by_zero = extract<int>(result); int five_divided_by_zero = extract<int>(result);
} }
catch(error_already_set) catch(error_already_set const &)
{ {
// handle the exception in some way // handle the exception in some way
} }
@@ -1638,7 +1543,7 @@ print the exception's traceback to the console, or comparing the type of the
exception with those of the [@http://www.python.org/doc/api/standardExceptions.html exception with those of the [@http://www.python.org/doc/api/standardExceptions.html
standard exceptions]: standard exceptions]:
catch(error_already_set) catch(error_already_set const &)
{ {
if (PyErr_ExceptionMatches(PyExc_ZeroDivisionError)) if (PyErr_ExceptionMatches(PyExc_ZeroDivisionError))
{ {
@@ -1654,21 +1559,6 @@ standard exceptions]:
(To retrieve even more information from the exception you can use some of the other (To retrieve even more information from the exception you can use some of the other
exception handling functions listed [@http://www.python.org/doc/api/exceptionHandling.html here].) exception handling functions listed [@http://www.python.org/doc/api/exceptionHandling.html here].)
If you'd rather not have [^handle] throw a C++ exception when it is constructed, you
can use the [@../../../v2/handle.html#allow_null-spec allow_null] function in the same
way you'd use borrowed:
handle<> result((allow_null(PyRun_String(
"5/0"
, Py_eval_input
, main_namespace.ptr()
, main_namespace.ptr()))));
if (!result)
// Python exception occurred
else
// everything went okay, it's safe to use the result
[endsect] [endsect]
[endsect] [/ Embedding] [endsect] [/ Embedding]

View File

@@ -1,10 +1,18 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<!-- Copyright David Abrahams 2006. Distributed under the Boost -->
<!-- Software License, Version 1.0. (See accompanying -->
<!-- file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -->
<html> <html>
<head> <head>
<meta http-equiv="refresh" content="0; URL=doc/html/index.html"> <meta http-equiv="refresh" content="0; URL=doc/html/index.html">
</head> </head>
<body> <body>
Automatic redirection failed, click this Automatic redirection failed, click this
<a href="doc/html/index.html">link</a> <a href="doc/html/index.html">link</a> &nbsp;<hr>
<p>© Copyright Beman Dawes, 2001</p>
<p>Distributed under the Boost Software License, Version 1.0. (See
accompanying file <a href="../../../LICENSE_1_0.txt">
LICENSE_1_0.txt</a> or copy at
<a href="http://www.boost.org/LICENSE_1_0.txt">www.boost.org/LICENSE_1_0.txt</a>)</p>
</body> </body>
</html> </html>

View File

@@ -1,3 +1,6 @@
<!-- Copyright David Abrahams 2006. Distributed under the Boost -->
<!-- Software License, Version 1.0. (See accompanying -->
<!-- file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -->
<html> <html>
<head> <head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

View File

@@ -1,5 +1,8 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<!-- Copyright David Abrahams 2006. Distributed under the Boost -->
<!-- Software License, Version 1.0. (See accompanying -->
<!-- file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -->
<html> <html>
<head> <head>
<meta name="generator" content= <meta name="generator" content=

View File

@@ -1,3 +1,6 @@
<!-- Copyright David Abrahams 2006. Distributed under the Boost -->
<!-- Software License, Version 1.0. (See accompanying -->
<!-- file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -->
<html> <html>
<head> <head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

View File

@@ -1,3 +1,6 @@
<!-- Copyright David Abrahams 2006. Distributed under the Boost -->
<!-- Software License, Version 1.0. (See accompanying -->
<!-- file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -->
<html> <html>
<head> <head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

View File

@@ -1,3 +1,6 @@
<!-- Copyright David Abrahams 2006. Distributed under the Boost -->
<!-- Software License, Version 1.0. (See accompanying -->
<!-- file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -->
<html> <html>
<head> <head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

View File

@@ -1,3 +1,6 @@
<!-- Copyright David Abrahams 2006. Distributed under the Boost -->
<!-- Software License, Version 1.0. (See accompanying -->
<!-- file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -->
<html> <html>
<head> <head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

View File

@@ -1,3 +1,6 @@
<!-- Copyright David Abrahams 2006. Distributed under the Boost -->
<!-- Software License, Version 1.0. (See accompanying -->
<!-- file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -->
<html> <html>
<head> <head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

View File

@@ -1,3 +1,6 @@
<!-- Copyright David Abrahams 2006. Distributed under the Boost -->
<!-- Software License, Version 1.0. (See accompanying -->
<!-- file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -->
<html> <html>
<head> <head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

View File

@@ -1,5 +1,8 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<!-- Copyright David Abrahams 2006. Distributed under the Boost -->
<!-- Software License, Version 1.0. (See accompanying -->
<!-- file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -->
<html> <html>
<head> <head>
<meta name="generator" content= <meta name="generator" content=

View File

@@ -1,3 +1,6 @@
<!-- Copyright David Abrahams 2006. Distributed under the Boost -->
<!-- Software License, Version 1.0. (See accompanying -->
<!-- file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -->
<html> <html>
<head> <head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

View File

@@ -1,5 +1,8 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<!-- Copyright David Abrahams 2006. Distributed under the Boost -->
<!-- Software License, Version 1.0. (See accompanying -->
<!-- file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -->
<html> <html>
<head> <head>
<meta name="generator" content= <meta name="generator" content=

View File

@@ -1,5 +1,8 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<!-- Copyright David Abrahams 2006. Distributed under the Boost -->
<!-- Software License, Version 1.0. (See accompanying -->
<!-- file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -->
<html> <html>
<head> <head>
<meta name="generator" content= <meta name="generator" content=

View File

@@ -1,3 +1,6 @@
<!-- Copyright David Abrahams 2006. Distributed under the Boost -->
<!-- Software License, Version 1.0. (See accompanying -->
<!-- file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -->
<html> <html>
<head> <head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

View File

@@ -1,5 +1,8 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<!-- Copyright David Abrahams 2006. Distributed under the Boost -->
<!-- Software License, Version 1.0. (See accompanying -->
<!-- file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -->
<html> <html>
<head> <head>
<meta name="generator" content= <meta name="generator" content=

View File

@@ -1,5 +1,8 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<!-- Copyright David Abrahams 2006. Distributed under the Boost -->
<!-- Software License, Version 1.0. (See accompanying -->
<!-- file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -->
<html> <html>
<head> <head>
<meta name="generator" content= <meta name="generator" content=

View File

@@ -1,3 +1,7 @@
.. Copyright David Abrahams 2006. Distributed under the Boost
.. Software License, Version 1.0. (See accompanying
.. file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
Here's the plan: Here's the plan:
I aim to provide an interface similar to that of Boost.Python v1's I aim to provide an interface similar to that of Boost.Python v1's

View File

@@ -1,5 +1,8 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<!-- Copyright David Abrahams 2006. Distributed under the Boost -->
<!-- Software License, Version 1.0. (See accompanying -->
<!-- file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -->
<html> <html>
<head> <head>
<meta name="generator" content= <meta name="generator" content=

View File

@@ -1,5 +1,8 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<!-- Copyright David Abrahams 2006. Distributed under the Boost -->
<!-- Software License, Version 1.0. (See accompanying -->
<!-- file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -->
<html> <html>
<head> <head>
<meta name="generator" content= <meta name="generator" content=

View File

@@ -1,5 +1,8 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<!-- Copyright David Abrahams 2006. Distributed under the Boost -->
<!-- Software License, Version 1.0. (See accompanying -->
<!-- file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -->
<html> <html>
<head> <head>
<meta name="generator" content= <meta name="generator" content=

View File

@@ -1,5 +1,8 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<!-- Copyright David Abrahams 2006. Distributed under the Boost -->
<!-- Software License, Version 1.0. (See accompanying -->
<!-- file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -->
<html> <html>
<head> <head>
<meta name="generator" content= <meta name="generator" content=

View File

@@ -1,5 +1,8 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<!-- Copyright David Abrahams 2006. Distributed under the Boost -->
<!-- Software License, Version 1.0. (See accompanying -->
<!-- file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -->
<html> <html>
<head> <head>
<meta name="generator" content= <meta name="generator" content=

View File

@@ -1,5 +1,8 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<!-- Copyright David Abrahams 2006. Distributed under the Boost -->
<!-- Software License, Version 1.0. (See accompanying -->
<!-- file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -->
<html> <html>
<head> <head>
<meta name="generator" content= <meta name="generator" content=

View File

@@ -132,4 +132,6 @@ BOOST_PYTHON_MODULE(my_ext)
</p> </p>
<p><i>&copy; Copyright Joel de Guzman 2003. </i> <p><i>&copy; Copyright Joel de Guzman 2003. </i> Distributed under the Boost
Software License, Version 1.0. (See accompanying
file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)

View File

@@ -165,6 +165,8 @@ struct return_value_policy : Base
<!--webbot bot="Timestamp" endspan i-checksum="39359" --> <!--webbot bot="Timestamp" endspan i-checksum="39359" -->
<p><i>&copy; Copyright <a href="../../../../people/dave_abrahams.htm">Dave <p><i>&copy; Copyright <a href="../../../../people/dave_abrahams.htm">Dave
Abrahams</a> 2002. </i> Abrahams</a> 2002.</i> Distributed under the Boost Software License,
Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
http://www.boost.org/LICENSE_1_0.txt)</p>

View File

@@ -1,5 +1,8 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<!-- Copyright David Abrahams 2006. Distributed under the Boost -->
<!-- Software License, Version 1.0. (See accompanying -->
<!-- file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -->
<html> <html>
<head> <head>
<meta name="generator" content= <meta name="generator" content=

View File

@@ -1,5 +1,8 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<!-- Copyright David Abrahams 2006. Distributed under the Boost -->
<!-- Software License, Version 1.0. (See accompanying -->
<!-- file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -->
<html> <html>
<head> <head>
<meta name="generator" content= <meta name="generator" content=

View File

@@ -1,5 +1,8 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<!-- Copyright David Abrahams 2006. Distributed under the Boost -->
<!-- Software License, Version 1.0. (See accompanying -->
<!-- file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -->
<html> <html>
<head> <head>
<meta name="generator" content= <meta name="generator" content=

View File

@@ -1,5 +1,8 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<!-- Copyright David Abrahams 2006. Distributed under the Boost -->
<!-- Software License, Version 1.0. (See accompanying -->
<!-- file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -->
<html> <html>
<head> <head>
<meta name="generator" content= <meta name="generator" content=

View File

@@ -1,5 +1,8 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<!-- Copyright David Abrahams 2006. Distributed under the Boost -->
<!-- Software License, Version 1.0. (See accompanying -->
<!-- file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -->
<html> <html>
<head> <head>
<meta name="generator" content= <meta name="generator" content=

View File

@@ -1,5 +1,8 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<!-- Copyright David Abrahams 2006. Distributed under the Boost -->
<!-- Software License, Version 1.0. (See accompanying -->
<!-- file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -->
<html> <html>
<head> <head>
<meta name="generator" content= <meta name="generator" content=

View File

@@ -1,5 +1,8 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<!-- Copyright David Abrahams 2006. Distributed under the Boost -->
<!-- Software License, Version 1.0. (See accompanying -->
<!-- file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -->
<html> <html>
<head> <head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
@@ -35,6 +38,7 @@
<dd> <dd>
<dl class="page-index"> <dl class="page-index">
<dt><a href="#eval-spec"><code>eval</code></a></dt>
<dt><a href="#exec-spec"><code>exec</code></a></dt> <dt><a href="#exec-spec"><code>exec</code></a></dt>
<dt><a href="#exec_file-spec"><code>exec_file</code></a></dt> <dt><a href="#exec_file-spec"><code>exec_file</code></a></dt>
</dl> </dl>
@@ -49,6 +53,23 @@
<h2><a name="functions"></a>Functions</h2> <h2><a name="functions"></a>Functions</h2>
<h3><a name="eval-spec"></a><code>eval</code></h3>
<pre>
object eval(str expression,
object globals = object(),
object locals = object());
</pre>
<dl class="function-semantics">
<dt><b>Effects:</b>
Evaluate Python expression from <code>expression</code> in the context
specified by the dictionaries <code>globals</code> and <code>locals</code>.
</dt>
<dt><b>Returns:</b>
An instance of <a href="object.html#object-spec">object</a>
which holds the value of the expression.
</dt>
</dl>
<h3><a name="exec-spec"></a><code>exec</code></h3> <h3><a name="exec-spec"></a><code>exec</code></h3>
<pre> <pre>
object exec(str code, object exec(str code,

View File

@@ -1,5 +1,8 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<!-- Copyright David Abrahams 2006. Distributed under the Boost -->
<!-- Software License, Version 1.0. (See accompanying -->
<!-- file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -->
<html> <html>
<head> <head>
<meta name="generator" content= <meta name="generator" content=

View File

@@ -1,5 +1,8 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<!-- Copyright David Abrahams 2006. Distributed under the Boost -->
<!-- Software License, Version 1.0. (See accompanying -->
<!-- file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -->
<html> <html>
<head> <head>
<meta name="generator" content= <meta name="generator" content=
@@ -67,8 +70,6 @@
>error C2064: term does not evaluate to a function taking 2 arguments</a> >error C2064: term does not evaluate to a function taking 2 arguments</a>
</dt> </dt>
<dt><a href="#voidptr">How do I handle <tt>void *</tt> conversion?</a></dt>
<dt><a href="#custom_string" <dt><a href="#custom_string"
>How can I automatically convert my custom string type to >How can I automatically convert my custom string type to
and from a Python string?</a></dt> and from a Python string?</a></dt>
@@ -568,7 +569,7 @@ handle&lt;&gt; f_wrap()
... ...
def("f", f_wrap()); def("f", f_wrap());
class_&lt;X,X_wrap&gt;("X", init&lt;int&gt;()) class_&lt;X,X_wrap,boost::noncopyable&gt;("X", init&lt;int&gt;())
... ...
; ;
</pre> </pre>
@@ -693,29 +694,6 @@ void Export_FXThread()
.def("setAutoDelete", (bool (FXThread::*)(bool)) &amp;FXThread::setAutoDelete)</pre> .def("setAutoDelete", (bool (FXThread::*)(bool)) &amp;FXThread::setAutoDelete)</pre>
<p>(The bug has been reported to Microsoft.)</p> <p>(The bug has been reported to Microsoft.)</p>
<hr>
<h2><a name="voidptr"></a>How do I handle <tt>void *</tt> conversion?</h2>
<font size="-1"><i>Niall Douglas provides these notes:</i></font><p>
For several reasons Boost.Python does not support <tt>void *</tt> as
an argument or as a return value. However, it is possible to wrap
functions with <tt>void *</tt> arguments or return values using
thin wrappers and the <i>opaque pointer</i> facility. E.g.:
<pre>// Declare the following in each translation unit
struct void_ {};
BOOST_PYTHON_OPAQUE_SPECIALIZED_TYPE_ID(void_);
void *foo(int par1, void *par2);
void_ *foo_wrapper(int par1, void_ *par2)
{
return (void_ *) foo(par1, par2);
}
...
BOOST_PYTHON_MODULE(bar)
{
def("foo", &amp;foo_wrapper);
}</pre>
<hr> <hr>
<h2><a name="custom_string"></a>How can I automatically <h2><a name="custom_string"></a>How can I automatically
convert my custom string type to and from a Python string?</h2> convert my custom string type to and from a Python string?</h2>
@@ -873,11 +851,11 @@ BOOST_PYTHON_MODULE(custom_string)
<p>Revised <p>Revised
<!--webbot bot="Timestamp" S-Type="EDITED" S-Format="%d %B, %Y" startspan --> <!--webbot bot="Timestamp" S-Type="EDITED" S-Format="%d %B, %Y" startspan -->
28 January, 2004 12 March, 2006
<!--webbot bot="Timestamp" endspan i-checksum="39359" --> <!--webbot bot="Timestamp" endspan i-checksum="39359" -->
</p> </p>
<p><i>&copy; Copyright <a href= <p><i>&copy; Copyright <a href=
"../../../../people/dave_abrahams.htm">Dave Abrahams</a> 2002-2003.</i></p> "../../../../people/dave_abrahams.htm">Dave Abrahams</a> 2002-2006.</i></p>
</body> </body>
</html> </html>

View File

@@ -360,7 +360,8 @@
<!--webbot bot="Timestamp" endspan i-checksum="39359" --> <!--webbot bot="Timestamp" endspan i-checksum="39359" -->
<p class="c3">&copy; Copyright <a href= <p class="c3">&copy; Copyright <a href=
"../../../../people/dave_abrahams.htm">Dave Abrahams</a> "../../../../people/dave_abrahams.htm">Dave Abrahams</a> 2002. Distributed
2002. under the Boost Software License, Version 1.0. (See accompanying file
LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)</p>

View File

@@ -1,5 +1,8 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<!-- Copyright David Abrahams 2006. Distributed under the Boost -->
<!-- Software License, Version 1.0. (See accompanying -->
<!-- file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -->
<html> <html>
<head> <head>
<meta name="generator" content= <meta name="generator" content=

View File

@@ -1,5 +1,8 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<!-- Copyright David Abrahams 2006. Distributed under the Boost -->
<!-- Software License, Version 1.0. (See accompanying -->
<!-- file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -->
<html> <html>
<head> <head>
<meta name="generator" content= <meta name="generator" content=

View File

@@ -1,5 +1,8 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<!-- Copyright David Abrahams 2006. Distributed under the Boost -->
<!-- Software License, Version 1.0. (See accompanying -->
<!-- file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -->
<html> <html>
<head> <head>
<meta name="generator" content= <meta name="generator" content=

View File

@@ -1,5 +1,8 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<!-- Copyright David Abrahams 2006. Distributed under the Boost -->
<!-- Software License, Version 1.0. (See accompanying -->
<!-- file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -->
<html> <html>
<head> <head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

View File

@@ -1,5 +1,8 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 3.2//EN"> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 3.2//EN">
<!-- Copyright David Abrahams 2006. Distributed under the Boost -->
<!-- Software License, Version 1.0. (See accompanying -->
<!-- file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -->
<html> <html>
<head> <head>
<meta name="generator" content= <meta name="generator" content=

View File

@@ -1,4 +1,7 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<!-- Copyright David Abrahams 2006. Distributed under the Boost -->
<!-- Software License, Version 1.0. (See accompanying -->
<!-- file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -->
<html> <html>
<head> <head>
<meta name="generator" content= <meta name="generator" content=

View File

@@ -1,5 +1,8 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<!-- Copyright David Abrahams 2006. Distributed under the Boost -->
<!-- Software License, Version 1.0. (See accompanying -->
<!-- file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -->
<html> <html>
<head> <head>
<meta name="generator" content= <meta name="generator" content=

View File

@@ -1,6 +1,9 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<!-- Copyright David Abrahams 2006. Distributed under the Boost -->
<!-- Software License, Version 1.0. (See accompanying -->
<!-- file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -->
<html> <html>
<head> <head>
<meta name="generator" content="HTML Tidy, see www.w3.org"> <meta name="generator" content="HTML Tidy, see www.w3.org">

View File

@@ -1,5 +1,8 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<!-- Copyright David Abrahams 2006. Distributed under the Boost -->
<!-- Software License, Version 1.0. (See accompanying -->
<!-- file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -->
<html> <html>
<head> <head>
<meta name="generator" content= <meta name="generator" content=

View File

@@ -1,5 +1,8 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<!-- Copyright David Abrahams 2006. Distributed under the Boost -->
<!-- Software License, Version 1.0. (See accompanying -->
<!-- file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -->
<html> <html>
<head> <head>
<meta name="generator" content= <meta name="generator" content=

View File

@@ -1,5 +1,8 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<!-- Copyright David Abrahams 2006. Distributed under the Boost -->
<!-- Software License, Version 1.0. (See accompanying -->
<!-- file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -->
<html> <html>
<head> <head>
<meta name="generator" content= <meta name="generator" content=

View File

@@ -1,5 +1,8 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<!-- Copyright David Abrahams 2006. Distributed under the Boost -->
<!-- Software License, Version 1.0. (See accompanying -->
<!-- file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -->
<html> <html>
<head> <head>
<meta name="generator" content= <meta name="generator" content=

View File

@@ -1,5 +1,8 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<!-- Copyright David Abrahams 2006. Distributed under the Boost -->
<!-- Software License, Version 1.0. (See accompanying -->
<!-- file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -->
<html> <html>
<head> <head>
<meta name="generator" content= <meta name="generator" content=

View File

@@ -1,5 +1,8 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<!-- Copyright David Abrahams 2006. Distributed under the Boost -->
<!-- Software License, Version 1.0. (See accompanying -->
<!-- file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -->
<html> <html>
<head> <head>
<meta name="generator" content= <meta name="generator" content=

View File

@@ -104,5 +104,7 @@ RuntimeError: Unidentifiable C++ Exception
<p><i>&copy; Copyright <a href="../../../../people/dave_abrahams.htm">Dave <p><i>&copy; Copyright <a href="../../../../people/dave_abrahams.htm">Dave
Abrahams</a> 2002. </i> Abrahams</a> 2002. </i> Distributed
under the Boost Software License, Version 1.0. (See accompanying file
LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)</p>

View File

@@ -1,102 +1,105 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<!-- Copyright David Abrahams 2006. Distributed under the Boost -->
<!-- Software License, Version 1.0. (See accompanying -->
<!-- file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -->
<html> <html>
<head> <head>
<meta name="generator" content= <meta name="generator" content=
"HTML Tidy for Windows (vers 1st August 2002), see www.w3.org"> "HTML Tidy for Linux/x86 (vers 1 September 2005), see www.w3.org">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
<link rel="stylesheet" type="text/css" href="../boost.css"> <link rel="stylesheet" type="text/css" href="../boost.css">
<title>Boost.Python - &lt;boost/python/numeric.hpp&gt;</title> <title>Boost.Python - &lt;boost/python/numeric.hpp&gt;</title>
</head> </head>
<body> <body>
<table border="0" cellpadding="7" cellspacing="0" width="100%" summary= <table border="0" cellpadding="7" cellspacing="0" width="100%" summary=
"header"> "header">
<tr> <tr>
<td valign="top" width="300"> <td valign="top" width="300">
<h3><a href="../../../../index.htm"><img height="86" width="277" <h3><a href="../../../../index.htm"><img height="86" width="277" alt=
alt="C++ Boost" src="../../../../boost.png" border="0"></a></h3> "C++ Boost" src="../../../../boost.png" border="0"></a></h3>
</td> </td>
<td valign="top"> <td valign="top">
<h1 align="center"><a href="../index.html">Boost.Python</a></h1> <h1 align="center"><a href="../index.html">Boost.Python</a></h1>
<h2 align="center">Header &lt;boost/python/numeric.hpp&gt;</h2> <h2 align="center">Header &lt;boost/python/numeric.hpp&gt;</h2>
</td> </td>
</tr> </tr>
</table> </table>
<hr> <hr>
<h2>Contents</h2> <h2>Contents</h2>
<dl class="page-index"> <dl class="page-index">
<dt><a href="#introduction">Introduction</a></dt> <dt><a href="#introduction">Introduction</a></dt>
<dt><a href="#classes">Classes</a></dt> <dt><a href="#classes">Classes</a></dt>
<dd> <dd>
<dl class="page-index"> <dl class="page-index">
<dt><a href="#array-spec">Class <code>array</code></a></dt> <dt><a href="#array-spec">Class <code>array</code></a></dt>
<dd> <dd>
<dl class="page-index"> <dl class="page-index">
<dt><a href="#array-spec-synopsis">Class <code>array</code> <dt><a href="#array-spec-synopsis">Class <code>array</code>
synopsis</a></dt> synopsis</a></dt>
<dt><a href="#array-spec-observers">Class <code>array</code> <dt><a href="#array-spec-observers">Class <code>array</code>
observer functions</a></dt> observer functions</a></dt>
<dt><a href="#array-spec-statics">Class <code>array</code> <dt><a href="#array-spec-statics">Class <code>array</code> static
static functions</a></dt> functions</a></dt>
</dl> </dl>
</dd> </dd>
</dl> </dl>
</dd> </dd>
<dt><a href="#examples">Example(s)</a></dt> <dt><a href="#examples">Example(s)</a></dt>
</dl> </dl>
<hr> <hr>
<h2><a name="introduction"></a>Introduction</h2> <h2><a name="introduction" id="introduction"></a>Introduction</h2>
<p>Exposes a <a href= <p>Exposes a <a href=
"ObjectWrapper.html#TypeWrapper-concept">TypeWrapper</a> for the Python "ObjectWrapper.html#TypeWrapper-concept">TypeWrapper</a> for the Python
<a href= <a href=
"http://www.python.org/dev/doc/devel/lib/typesmapping.html">array</a> "http://www.python.org/dev/doc/devel/lib/typesmapping.html">array</a>
type.</p> type.</p>
<h2><a name="classes"></a>Classes</h2> <h2><a name="classes" id="classes"></a>Classes</h2>
<h3><a name="array-spec"></a>Class <code>array</code></h3> <h3><a name="array-spec" id="array-spec"></a>Class <code>array</code></h3>
<p>Provides access to the array types of <a href= <p>Provides access to the array types of <a href=
"http://www.pfdubois.com/numpy/">Numerical Python</a>'s <a href= "http://www.pfdubois.com/numpy/">Numerical Python</a>'s <a href=
"http://www.pfdubois.com/numpy/#Numeric">Numeric</a> and <a href= "http://www.pfdubois.com/numpy/#Numeric">Numeric</a> and <a href=
"http://stsdas.stsci.edu/numarray/index.html">NumArray</a> modules. With "http://stsdas.stsci.edu/numarray/index.html">NumArray</a> modules. With
the exception of the functions documented <a href= the exception of the functions documented <a href=
"#array-spec-observers">below</a>, the semantics of the constructors and "#array-spec-observers">below</a>, the semantics of the constructors and
member functions defined below can be fully understood by reading the <a member functions defined below can be fully understood by reading the
href="ObjectWrapper.html#TypeWrapper-concept">TypeWrapper</a> concept <a href="ObjectWrapper.html#TypeWrapper-concept">TypeWrapper</a> concept
definition. Since <code>array</code> is publicly derived from <code><a definition. Since <code>array</code> is publicly derived from
href="object.html#object-spec">object</a></code>, the public object <code><a href="object.html#object-spec">object</a></code>, the public
interface applies to <code>array</code> instances as well.</p> object interface applies to <code>array</code> instances as well.</p>
<p><a name="default_search"></a>The default behavior is to use <p><a name="default_search" id="default_search"></a>The default behavior is
<code>numarray.NDArray</code> as the associated Python type if the to use <code>numarray.NDArray</code> as the associated Python type if the
<code>numarray</code> module is installed in the default location. <code>numarray</code> module is installed in the default location.
Otherwise it falls back to use <code>Numeric.ArrayType</code>. If neither Otherwise it falls back to use <code>Numeric.ArrayType</code>. If neither
extension module is installed, conversions to arguments of type extension module is installed, overloads of wrapped C++ functions with
<code>numeric::array</code> will cause overload resolution to reject the <code>numeric::array</code> parameters will never be matched, and other
overload, and other attempted uses of <code>numeric::array</code> will <a attempted uses of <code>numeric::array</code> will <a href=
href="definitions.html#raise">raise</a> an appropriate Python exception. "definitions.html#raise">raise</a> an appropriate Python exception. The
The associated Python type can be set manually using the <code><a href= associated Python type can be set manually using the <code><a href=
"#array-spec-statics">set_module_and_type</a>(...)</code> static "#array-spec-statics">set_module_and_type</a>(...)</code> static
function.</p> function.</p>
<h4><a name="array-spec-synopsis"></a>Class <code>array</code> <h4><a name="array-spec-synopsis" id="array-spec-synopsis"></a>Class
synopsis</h4> <code>array</code> synopsis</h4>
<pre> <pre>
namespace boost { namespace python { namespace numeric namespace boost { namespace python { namespace numeric
{ {
class array : public object class array : public object
@@ -107,7 +110,7 @@ namespace boost { namespace python { namespace numeric
object astype(Type const&amp; type_); object astype(Type const&amp; type_);
template &lt;class Type&gt; template &lt;class Type&gt;
object new_(Type const&amp; type_) const; array new_(Type const&amp; type_) const;
template &lt;class Sequence&gt; template &lt;class Sequence&gt;
void resize(Sequence const&amp; x); void resize(Sequence const&amp; x);
@@ -133,14 +136,14 @@ namespace boost { namespace python { namespace numeric
void tofile(File const&amp; f) const; void tofile(File const&amp; f) const;
object factory(); object factory();
template &lt;class Buffer&gt; template &lt;class Sequence&gt;
object factory(Buffer const&amp;); object factory(Sequence const&amp;);
template &lt;class Buffer, class Type&gt; template &lt;class Sequence, class Typecode&gt;
object factory(Buffer const&amp;, Type const&amp;); object factory(Sequence const&amp;, Typecode const&amp;, bool copy = true, bool savespace = false);
template &lt;class Buffer, class Type, class Shape&gt; template &lt;class Sequence, class Typecode, class Type&gt;
object factory(Buffer const&amp;, Type const&amp;, Shape const&amp;, bool copy = true, bool savespace = false); object factory(Sequence const&amp;, Typecode const&amp;, bool copy, bool savespace, Type const&amp;);
template &lt;class Buffer, class Type, class Shape&gt; template &lt;class Sequence, class Typecode, class Type, class Shape&gt;
object factory(Buffer const&amp;, Type const&amp;, Shape const&amp;, bool copy, bool savespace, char typecode); object factory(Sequence const&amp;, Typecode const&amp;, bool copy, bool savespace, Type const&amp;, Shape const&amp;);
template &lt;class T1&gt; template &lt;class T1&gt;
explicit array(T1 const&amp; x1); explicit array(T1 const&amp; x1);
@@ -152,6 +155,7 @@ namespace boost { namespace python { namespace numeric
static void set_module_and_type(); static void set_module_and_type();
static void set_module_and_type(char const* package_path = 0, char const* type_name = 0); static void set_module_and_type(char const* package_path = 0, char const* type_name = 0);
static void get_module_name();
object argmax(long axis=-1); object argmax(long axis=-1);
@@ -200,54 +204,60 @@ namespace boost { namespace python { namespace numeric
}}} }}}
</pre> </pre>
<h4><a name="array-spec-observers"></a>Class <code>array</code> observer <h4><a name="array-spec-observers" id="array-spec-observers"></a>Class
functions</h4> <code>array</code> observer functions</h4>
<pre> <pre>
object factory(); object factory();
template &lt;class Buffer&gt; template &lt;class Sequence&gt;
object factory(Buffer const&amp;); object factory(Sequence const&amp;);
template &lt;class Buffer, class Type&gt; template &lt;class Sequence, class Typecode&gt;
object factory(Buffer const&amp;, Type const&amp;); object factory(Sequence const&amp;, Typecode const&amp;, bool copy = true, bool savespace = false);
template &lt;class Buffer, class Type, class Shape&gt; template &lt;class Sequence, class Typecode, class Type&gt;
object factory(Buffer const&amp;, Type const&amp;, Shape const&amp;, bool copy = true, bool savespace = false); object factory(Sequence const&amp;, Typecode const&amp;, bool copy, bool savespace, Type const&amp;);
template &lt;class Buffer, class Type, class Shape&gt; template &lt;class Sequence, class Typecode, class Type, class Shape&gt;
object factory(Buffer const&amp;, Type const&amp;, Shape const&amp;, bool copy, bool savespace, char typecode); object factory(Sequence const&amp;, Typecode const&amp;, bool copy, bool savespace, Type const&amp;, Shape const&amp;);
</pre> </pre>These functions map to the underlying array type's <code>array()</code>
These functions map to the underlying array type's <code>array()</code> function family. They are not called "<code>array</code>" because of the C++
function family. They are not called "<code>array</code>" because of the limitation that you can't define a member function with the same name as its
C++ limitation that you can't define a member function with the same name enclosing class.
as its enclosing class. <pre>
<pre>
template &lt;class Type&gt; template &lt;class Type&gt;
object new_(Type const&amp;) const; array new_(Type const&amp;) const;
</pre> </pre>This function maps to the underlying array type's <code>new()</code>
This function maps to the underlying array type's <code>new()</code> function. It is not called "<code>new</code>" because that is a keyword in
function. It is not called "<code>new</code>" because that is a keyword C++.
in C++.
<h4><a name="array-spec-statics"></a>Class <code>array</code> static <h4><a name="array-spec-statics" id="array-spec-statics"></a>Class
functions</h4> <code>array</code> static functions</h4>
<pre> <pre>
static void set_module_and_type(char const* package_path, char const* type_name); static void set_module_and_type(char const* package_path, char const* type_name);
static void set_module_and_type(); static void set_module_and_type();
</pre> </pre>
<dl class="function-semantics"> <dl class="function-semantics">
<dt><b>Requires:</b> <code>package_path</code> and <dt><b>Requires:</b> <code>package_path</code> and
<code>type_name</code>, if supplied, is an <a href= <code>type_name</code>, if supplied, is an <a href=
"definitions.html#ntbs">ntbs</a>.</dt> "definitions.html#ntbs">ntbs</a>.</dt>
<dt><b>Effects:</b> The first form sets the package path of the module <dt><b>Effects:</b> The first form sets the package path of the module
which supplies the type named by <code>type_name</code> to that supplies the type named by <code>type_name</code> to
<code>package_path</code>. The second form restores the <a href= <code>package_path</code>. The second form restores the <a href=
"#default_search">default search behavior</a>. The associated Python "#default_search">default search behavior</a>. The associated Python type
type will be searched for only the first time it is needed, and will be searched for only the first time it is needed, and thereafter the
thereafter the first time it is needed after an invocation of first time it is needed after an invocation of
<code>set_module_and_type</code>.</dt> <code>set_module_and_type</code>.</dt>
</dl> </dl>
<pre>
static std::string get_module_name()
</pre>
<h2><a name="examples"></a>Example</h2> <dl class="function-semantics">
<pre> <dt><b>Effects:</b> Returns the name of the module containing the class
that will be held by new <code>numeric::array</code> instances.</dt>
</dl>
<h2><a name="examples" id="examples"></a>Example</h2>
<pre>
#include &lt;boost/python/numeric.hpp&gt; #include &lt;boost/python/numeric.hpp&gt;
#include &lt;boost/python/tuple.hpp&gt; #include &lt;boost/python/tuple.hpp&gt;
@@ -258,10 +268,9 @@ void set_first_element(numeric::array&amp; y, double value)
} }
</pre> </pre>
<p>Revised 03 October, 2002</p> <p>Revised 07 October, 2006</p>
<p><i>&copy; Copyright <a href= <p><i>&copy; Copyright <a href="../../../../people/dave_abrahams.htm">Dave
"../../../../people/dave_abrahams.htm">Dave Abrahams</a> 2002.</i></p> Abrahams</a> 2002-2006.</i></p>
</body> </body>
</html> </html>

View File

@@ -1,5 +1,8 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<!-- Copyright David Abrahams 2006. Distributed under the Boost -->
<!-- Software License, Version 1.0. (See accompanying -->
<!-- file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -->
<html> <html>
<head> <head>
<meta name="generator" content= <meta name="generator" content=
@@ -851,12 +854,12 @@ void del(proxy&lt;T&gt; const&amp; x);
</dl> </dl>
<pre> <pre>
<a name="comparisons-spec"></a> <a name="comparisons-spec"></a>
template&lt;class L,class R&gt; bool operator&gt;(L const&amp;l,R const&amp;r); template&lt;class L,class R&gt; object operator&gt;(L const&amp;l,R const&amp;r);
template&lt;class L,class R&gt; bool operator&gt;=(L const&amp;l,R const&amp;r); template&lt;class L,class R&gt; object operator&gt;=(L const&amp;l,R const&amp;r);
template&lt;class L,class R&gt; bool operator&lt;(L const&amp;l,R const&amp;r); template&lt;class L,class R&gt; object operator&lt;(L const&amp;l,R const&amp;r);
template&lt;class L,class R&gt; bool operator&lt;=(L const&amp;l,R const&amp;r); template&lt;class L,class R&gt; object operator&lt;=(L const&amp;l,R const&amp;r);
template&lt;class L,class R&gt; bool operator==(L const&amp;l,R const&amp;r); template&lt;class L,class R&gt; object operator==(L const&amp;l,R const&amp;r);
template&lt;class L,class R&gt; bool operator!=(L const&amp;l,R const&amp;r); template&lt;class L,class R&gt; object operator!=(L const&amp;l,R const&amp;r);
</pre> </pre>
<dl class="function-semantics"> <dl class="function-semantics">

138
doc/v2/opaque.html Normal file
View File

@@ -0,0 +1,138 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<!-- Copyright 2003..2006 Haufe Mediengruppe. Distributed under the Boost -->
<!-- Software License, Version 1.0. (See accompanying -->
<!-- file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -->
<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 - &lt;boost/python/opaque_pointer_converter.hpp&gt;</title>
</head>
<body>
<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="../../../../boost.png" border="0"></a></h3>
</td>
<td valign="top">
<h1 align="center"><a href="../index.html">Boost.Python</a></h1>
<h2 align="center">Header
&lt;boost/python/opaque_pointer_converter.hpp&gt;</h2>
</td>
</tr>
</table>
<hr>
<h2>Contents</h2>
<dl class="page-index">
<dt><a href="#classes">Classes</a></dt>
<dd>
<dl class="page-index">
<dt><a href="#opaque-spec">Class template
<code>opaque&lt;Pointee&gt;</code></a></dt>
<dd>
<dl class="page-index">
<dt><a href="#opaque-spec-synopsis">Class template
<code>opaque</code> synopsis</a></dt>
</dl>
</dd>
</dl>
</dd>
<dt><a href="#macros">Macros</a></dt>
<dd>
<dl class="page-index">
<dt><a href="#BOOST_PYTHON_OPAQUE_SPECIALIZED_TYPE_ID-spec">Macro
<code>BOOST_PYTHON_OPAQUE_SPECIALIZED_TYPE_ID</code></a></dt>
</dl>
</dd>
<dt><a href="#see-also">See Also</a></dt>
</dl>
<hr>
<h2><a name="classes"></a>Classes</h2>
<h3><a name="opaque-spec"></a>Class template
<code>opaque&lt;P&gt;</code></h3>
<p><code>opaque&lt;&gt;</code> registers itself as a converter from
Python objects to pointers to undefined types and vice versa.</p>
<h4><a name="opaque-spec-synopsis"></a>Class template
<code>opaque</code> synopsis</h4>
<pre>
namespace boost { namespace python
{
template&lt;class Pointee&gt;
struct opaque
{
opaque();
};
}}
</pre>
<h4><a name="opaque-spec-constructor"></a>Class template
<code>opaque</code> constructor</h4>
<pre>
opaque();
</pre>
<dl class="function-semantics">
<dt><b>Effects:</b>
<ul>
<li>Registers the instance as a
<a href="lvalue_from_pytype.html#lvalue_from_pytype-spec"> <code>lvalue_from_pytype</code></a>
converter from Python objects into opaque pointers.</p>
<p>The Python Objects created are named after the type pointed to
by the opaque pointer being wrapped.</p></li>
<li>Registers the instance as a
<a href="to_python_converter.html#to_python_converter-spec"> <code>to_python_converter</code></a>
from opaque pointers to Python objects.</p></li>
</ul>
<p>If there is already an instance registered by another module, this
instance doesn't try to register again in order to avoid warnings
about multiple registrations.</p>
<h4>Note</h4>
<p>Normally only a single instance of this class is created for every
Pointee.</p>
</dt>
</dl>
<h2><a name="macros"></a>Macros</h2>
<h3><a name="BOOST_PYTHON_OPAQUE_SPECIALIZED_TYPE_ID-spec"></a>
Macro BOOST_PYTHON_OPAQUE_SPECIALIZED_TYPE_ID(Pointee)</h3>
<p>This macro must be used to define specializations of the
<a href="type_id.html#type_id-spec">type_id</a> function
which can't be instantiated for incomplete types.</p>
<h4>Note</h4>
<p>The macro must be invoked in every translation unit which uses the
opaque converter.</p>
<h2><a name="see-also"></a>See Also</h2>
<p>
<a href="return_opaque_pointer.html">return_opaque_pointer</a>
</p>
<p>Revised
10 September, 2006
</p>
<p><i>&copy; Copyright 2003..2006 Haufe Mediengruppe. All Rights
Reserved.</i></p>
</body>
</html>

View File

@@ -1,142 +0,0 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<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 - &lt;boost/python/opaque_pointer_converter.hpp&gt;</title>
</head>
<body>
<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="../../../../boost.png" border="0"></a></h3>
</td>
<td valign="top">
<h1 align="center"><a href="../index.html">Boost.Python</a></h1>
<h2 align="center">Header
&lt;boost/python/opaque_pointer_converter.hpp&gt;</h2>
</td>
</tr>
</table>
<hr>
<h2>Contents</h2>
<dl class="page-index">
<dt><a href="#classes">Classes</a></dt>
<dd>
<dl class="page-index">
<dt><a href="#opaque_pointer_converter-spec">Class template
<code>opaque_pointer_converter&lt;P&gt;</code></a></dt>
<dd>
<dl class="page-index">
<dt><a href="#opaque_pointer_converter-spec-synopsis">Class template
<code>opaque_pointer_converter</code> synopsis</a></dt>
</dl>
</dd>
</dl>
</dd>
<dt><a href="#macros">Macros</a></dt>
<dd>
<dl class="page-index">
<dt><a href="#BOOST_PYTHON_OPAQUE_SPECIALIZED_TYPE_ID-spec">Macro
<code>BOOST_PYTHON_OPAQUE_SPECIALIZED_TYPE_ID</code></a></dt>
</dl>
</dd>
<dt><a href="#examples">Example</a></dt>
<dt><a href="#see-also">See Also</a></dt>
</dl>
<hr>
<h2><a name="classes"></a>Classes</h2>
<h3><a name="opaque_pointer_converter-spec"></a>Class template
<code>opaque_pointer_converter&lt;P&gt;</code></h3>
<p><code>opaque_pointer_converter&lt;&gt;</code> is derived from
<a href="to_python_converter.html#to_python_converter-spec">
<code>to_python_converter</code></a>
and registers itself as an
<a href="lvalue_from_pytype.html#lvalue_from_pytype-spec">
<code>lvalue_from_pytype</code></a> converter from Python objects
into pointers to undefined types.
Thus it may be used as a converter from opaque pointers into
Python objects and vice versa.</p>
<h4><a name="opaque_pointer_converter-spec-synopsis"></a>Class template
<code>opaque_pointer_converter</code> synopsis</h4>
<pre>
namespace boost { namespace python
{
template&lt;class Pointer&gt;
struct opaque_pointer_converter
: to_python_converter&lt;
Pointer, opaque_pointer_converter&lt;Pointer&gt; &gt;
{
explicit opaque_pointer_converter(char const* name);
};
}}
</pre>
<h4><a name="opaque_pointer_converter-spec-constructor"></a>Class template
<code>opaque_pointer_converter</code> constructor</h4>
<pre>
explicit opaque_pointer_converter(char const* name);
</pre>
<dl class="function-semantics">
<dt><b>Effects:</b>
<p>Registers the instance as a
<a href="lvalue_from_pytype.html#lvalue_from_pytype-spec">
<code>lvalue_from_pytype</code></a> converter from Python objects
into opaque pointers.</p>
<p>The name is used for the type of the Python Objects created;
it should be printable but needn't be an
<a href="definitions.html#ntbs">ntbs</a> because the object type is
not supposed to be user constructible within python scripts.</p>
</dt>
</dl>
<h2><a name="macros"></a>Macros</h2>
<h3><a name="BOOST_PYTHON_OPAQUE_SPECIALIZED_TYPE_ID-spec"></a>
Macro BOOST_PYTHON_OPAQUE_SPECIALIZED_TYPE_ID(Pointee)</h3>
<p>This macro must be used to define specializations of the
<a href="type_id.html#type_id-spec">type_id</a> function
which can't be instantiated for incomplete types.</p>
<h4>Note</h4>
<p>In order for this to work in a cross-module environment the macro must
be invoked in every translation unit which uses the
opaque_pointer_converter.</p>
<h2><a name="examples"></a>Example</h2>
please see example for <a href="return_opaque_pointer.html#examples">
return_opaque_pointer</a>.
<h2><a name="see-also"></a>See Also</h2>
<p>
<a href="return_opaque_pointer.html">return_opaque_pointer</a>
</p>
<p>Revised
10 March, 2003
</p>
<p><i>&copy; Copyright 2003 Haufe Mediengruppe. All Rights
Reserved.</i></p>
</body>
</html>

View File

@@ -1,5 +1,8 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<!-- Copyright David Abrahams 2006. Distributed under the Boost -->
<!-- Software License, Version 1.0. (See accompanying -->
<!-- file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -->
<html> <html>
<head> <head>
<meta name="generator" content= <meta name="generator" content=

View File

@@ -1,5 +1,8 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<!-- Copyright David Abrahams 2006. Distributed under the Boost -->
<!-- Software License, Version 1.0. (See accompanying -->
<!-- file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -->
<html> <html>
<head> <head>
<meta name="generator" content= <meta name="generator" content=

View File

@@ -320,11 +320,9 @@ See also the
<hr> <hr>
&copy; Copyright Ralf W. Grosse-Kunstleve 2001-2004. Permission to copy, &copy; Copyright Ralf W. Grosse-Kunstleve 2001-2004. Distributed under
use, modify, sell and distribute this document is granted provided this the Boost Software License, Version 1.0. (See accompanying file
copyright notice appears in all copies. This document is provided "as LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
is" without express or implied warranty, and with no claim as to its
suitability for any purpose.
<p> <p>
Updated: Feb 2004. Updated: Feb 2004.

View File

@@ -1,5 +1,8 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<!-- Copyright David Abrahams 2006. Distributed under the Boost -->
<!-- Software License, Version 1.0. (See accompanying -->
<!-- file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -->
<html> <html>
<head> <head>
<meta name="generator" content= <meta name="generator" content=

View File

@@ -112,5 +112,8 @@ BOOST_PYTHON_MODULE(pointee_demo)
<p><i>&copy; Copyright <a href="../../../../people/dave_abrahams.htm">Dave <p><i>&copy; Copyright <a href="../../../../people/dave_abrahams.htm">Dave
Abrahams</a> 2002. </i> Abrahams</a> 2002. </i> Distributed
under the Boost Software License, Version 1.0. (See accompanying file
LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)</p>

View File

@@ -1,3 +1,6 @@
<!-- Copyright David Abrahams 2006. Distributed under the Boost -->
<!-- Software License, Version 1.0. (See accompanying -->
<!-- file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -->
<html> <html>
<head> <head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

View File

@@ -259,5 +259,7 @@ void pass_as_arg(expensive_to_copy* x, PyObject* f)
<p><i>&copy; Copyright <a href="../../../../people/dave_abrahams.htm">Dave <p><i>&copy; Copyright <a href="../../../../people/dave_abrahams.htm">Dave
Abrahams</a> 2002. </i> Abrahams</a> 2002. </i> Distributed
under the Boost Software License, Version 1.0. (See accompanying file
LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)</p>

View File

@@ -1,5 +1,8 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<!-- Copyright David Abrahams 2006. Distributed under the Boost -->
<!-- Software License, Version 1.0. (See accompanying -->
<!-- file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -->
<html> <html>
<head> <head>
<meta name="generator" content= <meta name="generator" content=

View File

@@ -1,5 +1,8 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<!-- Copyright David Abrahams 2006. Distributed under the Boost -->
<!-- Software License, Version 1.0. (See accompanying -->
<!-- file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -->
<html> <html>
<head> <head>
<meta name="generator" content= <meta name="generator" content=

View File

@@ -1,5 +1,8 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<!-- Copyright David Abrahams 2006. Distributed under the Boost -->
<!-- Software License, Version 1.0. (See accompanying -->
<!-- file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -->
<html> <html>
<head> <head>
<meta name="generator" content= <meta name="generator" content=
@@ -904,26 +907,26 @@
</dd> </dd>
<dt><a href= <dt><a href=
"opaque_pointer_converter.html">opaque_pointer_converter.hpp</a></dt> "opaque.html">opaque_pointer_converter.hpp</a></dt>
<dd> <dd>
<dl class="index"> <dl class="index">
<dt><a href= <dt><a href=
"opaque_pointer_converter.html#classes">Classes</a></dt> "opaque.html#classes">Classes</a></dt>
<dd> <dd>
<dl class="index"> <dl class="index">
<dt><a href= <dt><a href=
"opaque_pointer_converter.html#opaque_pointer_converter-spec">opaque_pointer_converter</a></dt> "opaque.html#opaque-spec">opaque</a></dt>
</dl> </dl>
</dd> </dd>
<dt><a href="opaque_pointer_converter.html#macros">Macros</a></dt> <dt><a href="opaque.html#macros">Macros</a></dt>
<dd> <dd>
<dl class="index"> <dl class="index">
<dt><a href= <dt><a href=
"opaque_pointer_converter.html#BOOST_PYTHON_OPAQUE_SPECIALIZED_TYPE_ID-spec"> "opaque.html#BOOST_PYTHON_OPAQUE_SPECIALIZED_TYPE_ID-spec">
BOOST_PYTHON_OPAQUE_SPECIALIZED_TYPE_ID</a></dt> BOOST_PYTHON_OPAQUE_SPECIALIZED_TYPE_ID</a></dt>
</dl> </dl>
</dd> </dd>
@@ -974,6 +977,7 @@
<dd> <dd>
<dl class="index"> <dl class="index">
<dt><a href="exec.html#eval-spec">eval</a></dt>
<dt><a href="exec.html#exec-spec">exec</a></dt> <dt><a href="exec.html#exec-spec">exec</a></dt>
<dt><a href="exec.html#exec_file-spec">exec_file</a></dt> <dt><a href="exec.html#exec_file-spec">exec_file</a></dt>
</dl> </dl>
@@ -1091,6 +1095,16 @@
</dd> </dd>
</dl> </dl>
</dd> </dd>
<dt><a href="ssize_t.html">ssize_t.hpp</a></dt>
<dd>
<dl class="index">
<dt><a href="ssize_t.html#typedefs">Typedefs</a></dt>
<dt><a href="ssize_t.html#constants">Constants</a></dt>
</dl>
</dd>
</dl> </dl>
<h2><a name="topics">Topics</a></h2> <h2><a name="topics">Topics</a></h2>

View File

@@ -1,5 +1,8 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<!-- Copyright David Abrahams 2006. Distributed under the Boost -->
<!-- Software License, Version 1.0. (See accompanying -->
<!-- file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -->
<html> <html>
<head> <head>
<meta name="generator" content= <meta name="generator" content=

View File

@@ -1,3 +1,6 @@
<!-- Copyright David Abrahams 2006. Distributed under the Boost -->
<!-- Software License, Version 1.0. (See accompanying -->
<!-- file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -->
<html> <html>
<head> <head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

View File

@@ -1,5 +1,8 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<!-- Copyright David Abrahams 2006. Distributed under the Boost -->
<!-- Software License, Version 1.0. (See accompanying -->
<!-- file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -->
<html> <html>
<head> <head>
<meta name="generator" content= <meta name="generator" content=

View File

@@ -1,5 +1,8 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<!-- Copyright David Abrahams 2006. Distributed under the Boost -->
<!-- Software License, Version 1.0. (See accompanying -->
<!-- file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -->
<html> <html>
<head> <head>
<meta name="generator" content= <meta name="generator" content=

View File

@@ -1,5 +1,8 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<!-- Copyright David Abrahams 2006. Distributed under the Boost -->
<!-- Software License, Version 1.0. (See accompanying -->
<!-- file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -->
<html> <html>
<head> <head>
<meta name="generator" content= <meta name="generator" content=

View File

@@ -1,5 +1,8 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<!-- Copyright David Abrahams 2006. Distributed under the Boost -->
<!-- Software License, Version 1.0. (See accompanying -->
<!-- file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -->
<html> <html>
<head> <head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
@@ -67,7 +70,7 @@
undefined types such that the return value is copied into a undefined types such that the return value is copied into a
new Python object.</p> new Python object.</p>
<p>In addition to specifying the <code>return_opaque_pointer</code> <p>In addition to specifying the <code>return_opaque_pointer</code>
policy the <a href="opaque_pointer_converter.html#BOOST_PYTHON_OPAQUE_SPECIALIZED_TYPE_ID-spec"> policy the <a href="opaque.html#BOOST_PYTHON_OPAQUE_SPECIALIZED_TYPE_ID-spec">
<code>BOOST_PYTHON_OPAQUE_SPECIALIZED_TYPE_ID</code></a> macro must be <code>BOOST_PYTHON_OPAQUE_SPECIALIZED_TYPE_ID</code></a> macro must be
used to define specializations for the used to define specializations for the
<a href="type_id.html#type_id-spec">type_id</a> function <a href="type_id.html#type_id-spec">type_id</a> function
@@ -174,8 +177,8 @@ if __name__ == '__main__':
<h2><a name="see-also"></a>See Also</h2> <h2><a name="see-also"></a>See Also</h2>
<p> <p>
<a href="opaque_pointer_converter.html"> <a href="opaque.html">
opaque_pointer_converter</a> opaque</a>
</p> </p>
<p>Revised <p>Revised

View File

@@ -1,5 +1,8 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<!-- Copyright David Abrahams 2006. Distributed under the Boost -->
<!-- Software License, Version 1.0. (See accompanying -->
<!-- file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -->
<html> <html>
<head> <head>
<meta name="generator" content= <meta name="generator" content=

Some files were not shown because too many files have changed in this diff Show More