2
0
mirror of https://github.com/boostorg/python.git synced 2026-01-19 16:32:16 +00:00

Compare commits

...

260 Commits

Author SHA1 Message Date
nobody
8e0553b310 This commit was manufactured by cvs2svn to create tag
'Version_1_31_0'.

[SVN r22162]
2004-02-04 15:24:32 +00:00
Joel de Guzman
ccc17a791a small typo
[SVN r22067]
2004-01-30 06:15:32 +00:00
Dave Abrahams
385fe03956 Improved and alphabetized news format, added Python news, updated
iterator news.

Corrections in the Python documentation


[SVN r22038]
2004-01-29 03:01:19 +00:00
Dave Abrahams
1727aa33b3 merged from HEAD
[SVN r22028]
2004-01-28 22:52:26 +00:00
Joel de Guzman
4c7694d81e small typo
[SVN r22026]
2004-01-28 22:45:35 +00:00
Ralf W. Grosse-Kunstleve
36751a0e0a merged from trun
[SVN r21716]
2004-01-14 01:39:40 +00:00
Ralf W. Grosse-Kunstleve
ccd909e98d previous revision (1.10) of this file restored because http://gcc.gnu.org/bugzilla/show_bug.cgi?id=13530 is fixed
[SVN r21633]
2004-01-12 18:02:28 +00:00
Joel de Guzman
01b25510ff fix typo
[SVN r21571]
2004-01-10 02:53:06 +00:00
Ralf W. Grosse-Kunstleve
06beca39af merged from trunk
[SVN r21559]
2004-01-09 07:26:47 +00:00
Dave Abrahams
65c10f8f08 merged from trunk
[SVN r21530]
2004-01-07 14:08:10 +00:00
Ralf W. Grosse-Kunstleve
3c1a4b13b7 merged from trunk: Test full slicing.
[SVN r21508]
2004-01-06 13:09:29 +00:00
Ralf W. Grosse-Kunstleve
157343241c merged from trunk: Workaround for gcc-3.4 quirks
[SVN r21507]
2004-01-06 13:08:25 +00:00
Dave Abrahams
11df3bc2d3 merged from trunk
[SVN r21473]
2004-01-04 13:41:34 +00:00
Dave Abrahams
469094ee45 merged from trunk
[SVN r21450]
2004-01-02 18:34:56 +00:00
Ralf W. Grosse-Kunstleve
ce3d43bb06 merged from trunk
[SVN r21448]
2004-01-02 18:06:01 +00:00
Dave Abrahams
3a3f5631b9 merged from trunk
[SVN r21443]
2004-01-01 12:46:39 +00:00
Ralf W. Grosse-Kunstleve
b6707c8e61 Merged from trunk: workaround for Visual C++ 6 internal compiler error
[SVN r21441]
2004-01-01 01:51:49 +00:00
Ralf W. Grosse-Kunstleve
3b25d2a78d Merged from trunk: workaround for g++ (GCC) 3.4.0 20031230 (experimental) problem
[SVN r21440]
2004-01-01 01:50:07 +00:00
Dave Abrahams
dba4d7bf72 merged from trunk
[SVN r21438]
2003-12-31 19:21:19 +00:00
Ralf W. Grosse-Kunstleve
bf86306f8b work around g++ (GCC) 3.4.0 20031230 (experimental) internal compiler error; http://gcc.gnu.org/bugzilla/show_bug.cgi?id=13530; in case this bug is not fixed before the gcc 3.4 release the boost 1.31.0 release should still compile
[SVN r21431]
2003-12-31 08:45:42 +00:00
Dave Abrahams
e782dd7e02 merged from trunk
[SVN r21430]
2003-12-31 00:25:37 +00:00
nobody
bd4fd372a0 This commit was manufactured by cvs2svn to create branch 'RC_1_31_0'.
[SVN r21427]
2003-12-30 12:10:04 +00:00
Ralf W. Grosse-Kunstleve
1102fec2a0 links to pickle and indexing suites
[SVN r21423]
2003-12-30 03:54:21 +00:00
Ralf W. Grosse-Kunstleve
589fefe4b9 tabs -> spaces
[SVN r21405]
2003-12-27 06:22:29 +00:00
Rene Rivera
cfc867bd18 Fix broken links.
[SVN r21404]
2003-12-27 02:37:02 +00:00
Rene Rivera
5bc28e3016 Fix broken links.
[SVN r21403]
2003-12-27 01:46:04 +00:00
Rene Rivera
23b7ccca7f Fix broken links. And some minor consistency changes.
[SVN r21402]
2003-12-27 01:31:00 +00:00
Dave Abrahams
e9d6286a1d Fix Dereferenceable concept to require pointee, and
register_ptr_to_python to require Dereferenceable.


[SVN r21327]
2003-12-18 19:25:14 +00:00
Dave Abrahams
48321857e4 consistent use of get_pointer
[SVN r21326]
2003-12-18 19:23:38 +00:00
Ralf W. Grosse-Kunstleve
156da15715 unused member function removed (to avoid Linux Intel C++ 8.0 warning)
[SVN r21278]
2003-12-16 04:14:28 +00:00
Ralf W. Grosse-Kunstleve
4a0d7965cb consolidation of workarounds for missing "not" keyword
[SVN r21276]
2003-12-15 17:55:38 +00:00
Dave Abrahams
1f522823ff gcc2 workaround
[SVN r21274]
2003-12-15 14:45:07 +00:00
Beman Dawes
6795a280fd tabs to spaces
[SVN r21080]
2003-12-02 13:32:47 +00:00
Dave Abrahams
f369e22638 Cleaner code using object instead of handle
[SVN r21018]
2003-11-30 21:12:30 +00:00
Dave Abrahams
a278da2eba correct get_pointer usage
[SVN r21017]
2003-11-30 21:10:15 +00:00
Dave Abrahams
37b2bdba79 Workaround gcc-2.x ICE
[SVN r21016]
2003-11-30 21:08:19 +00:00
Dave Abrahams
e9519db974 Make Dereferenceable use get_pointer
Re-enable map_indexing_suite iteration for vc6.


[SVN r21008]
2003-11-29 22:12:18 +00:00
Ralf W. Grosse-Kunstleve
dd7a24ebce links to newly generated tutorial sections
[SVN r20934]
2003-11-24 05:53:13 +00:00
Bruno da Silva de Oliveira
bc92a7d155 - added new "General Techniques" section
[SVN r20927]
2003-11-23 21:24:54 +00:00
Dave Abrahams
a68db84df6 * Fixed Boost.Thread jamfile to add the missing #include paths
* Modified Python testing code to use the facilities of testing.jam,
  so that it can be processed with process_jam_log

* Updated Python library tests to use a test suite

* Added Python test suite to status/Jamfile

* Added --run-all-tests option to force tests to run even when up-to-date.


Also,
boost-base.jam:

    Added some missing rule signatures

    RUN_LD_LIBRARY_PATH became LINK_LIBPATH because it was only really
    used during linking.

    Reformed the movement of path variables up the dependency graph

    Removed the defunct Run rule

    Set up generalized constants for path manipulation

darwin-tools.jam, gcc-tools.jam:

   use LINK_LIBPATH

python.jam:

   Reformed the choice of Python executable

testing.jam:

   Refactored testing code so it could be used for Python

   Now building all environment variable setup code ahead of time

   RUN_TEST became TEST_EXE


[SVN r20815]
2003-11-15 15:41:41 +00:00
Dave Abrahams
7b9bba3190 vc6 workaround
[SVN r20814]
2003-11-15 15:16:27 +00:00
Ralf W. Grosse-Kunstleve
bcec0af232 minor fix for otherwise confusing debug output
[SVN r20796]
2003-11-12 19:55:22 +00:00
Ralf W. Grosse-Kunstleve
0d437c4102 MIPSpro 7.41 workaround
[SVN r20795]
2003-11-12 19:49:18 +00:00
Raoul Gough
feff7bccd3 Fix MSVC6 duplicate comdat (LNK1179) with multiple python::range instances
[SVN r20794]
2003-11-12 16:50:17 +00:00
Ralf W. Grosse-Kunstleve
b12de3f01b additions by Niall Douglas with heavy edits by Ralf
[SVN r20780]
2003-11-10 20:39:13 +00:00
Dave Abrahams
0d108f12e4 Better error reporting for overload resolution failures, ideas thanks
to Nikolay Mladenov.


[SVN r20770]
2003-11-10 01:02:45 +00:00
Dave Abrahams
4aca2ca33b change to binary
[SVN r20689]
2003-11-06 01:14:50 +00:00
Dave Abrahams
9a967ae514 change to binary
[SVN r20688]
2003-11-06 01:13:26 +00:00
Ralf W. Grosse-Kunstleve
9481c39874 explain workaround for a bug in Apple's compiler
[SVN r20684]
2003-11-05 19:19:50 +00:00
Dave Abrahams
1e02065982 Fix Mike Rovner's warning suppression.
[SVN r20673]
2003-11-05 00:43:13 +00:00
Ralf W. Grosse-Kunstleve
1fee0da689 patch by Mike Rovner: work around gcc 3.3.1 bug (http://gcc.gnu.org/PR12163)
[SVN r20672]
2003-11-05 00:30:46 +00:00
Ralf W. Grosse-Kunstleve
c760cf8418 workaround for MIPSpro 7.3.1; old workaround for VC7.1 visible only to that particular compiler
[SVN r20668]
2003-11-04 20:20:07 +00:00
Ralf W. Grosse-Kunstleve
cdee5997af obsolete MIPSpro workaround removed
[SVN r20667]
2003-11-04 20:17:48 +00:00
Ralf W. Grosse-Kunstleve
4289280cdc Mac OS 10 answer updated
[SVN r20666]
2003-11-04 20:05:09 +00:00
Rene Rivera
962dfa17c5 Add -bind_at_load option for MacOSX Darwin build, this prevents semaphore_wait_trap erros when loaded by extensions.
[SVN r20665]
2003-11-04 18:30:37 +00:00
Ralf W. Grosse-Kunstleve
0a21aef601 fix expected output; tested with Python 2.2.1 (Redhat8) and Python 2.3 (Mac OS 10.2.8)
[SVN r20658]
2003-11-04 17:38:13 +00:00
Rene Rivera
8cbbd504cf Point to the new location for Boost.Build v1; tools/build/v1.
[SVN r20654]
2003-11-04 17:07:15 +00:00
Dave Abrahams
91b23c8367 Warning suppression thanks to Mike Rovner <mike-at-bindkey.com>
[SVN r20617]
2003-11-03 20:45:21 +00:00
Dave Abrahams
3729be263f Bug fix
[SVN r20566]
2003-10-30 18:40:37 +00:00
Dave Abrahams
ea91f4217a suppress a warning
[SVN r20555]
2003-10-29 23:16:36 +00:00
Raoul Gough
7fab3ce0b1 Add info on using gdb under Windows
[SVN r20554]
2003-10-29 21:38:06 +00:00
Dave Abrahams
ef7d675d67 bug fix for a single use of arg with no comma operator
[SVN r20533]
2003-10-29 00:46:08 +00:00
Rene Rivera
2b9d29a0fc Improve unused variable warning supperssion with multi-compiler friendly code.
[SVN r20466]
2003-10-24 01:19:16 +00:00
Bruno da Silva de Oliveira
95b95d012c - Fixed bug where a class would appear more than one in the generated code.
[SVN r20464]
2003-10-23 22:56:33 +00:00
Rene Rivera
4af7d5bca7 Remove unused var warning on non-debug compilation.
[SVN r20463]
2003-10-23 20:15:50 +00:00
Rene Rivera
d879eb235f Add install definitions for new common install configuration.
[SVN r20409]
2003-10-19 19:52:56 +00:00
Dave Abrahams
4f129d035b Bug fix, thanks to Nicolas LELONG, nlelong-at-mgdesign.org for the report.
[SVN r20401]
2003-10-17 14:13:48 +00:00
Dave Abrahams
7a354c4ff4 Warning suppression for GCC.
[SVN r20396]
2003-10-15 23:19:48 +00:00
Dave Abrahams
364826b3b3 Include @group directives for Synopsis
[SVN r20364]
2003-10-13 21:04:11 +00:00
Raoul Gough
e9b308da46 Use msvc_typeid only if _MSV_VER is set, to avoid problems with Intel compiler on Linux
[SVN r20340]
2003-10-10 14:55:13 +00:00
Dave Abrahams
94cfa2602f Fix typo
[SVN r20324]
2003-10-09 14:15:20 +00:00
Bruno da Silva de Oliveira
3533bd0504 no message
[SVN r20266]
2003-10-06 19:10:50 +00:00
Bruno da Silva de Oliveira
1a51a7df9e - added missing <boost/python/return_arg.hpp>
[SVN r20257]
2003-10-04 21:44:24 +00:00
Dave Abrahams
615be89951 Support for logical negation operator via __nonzero__
[SVN r20256]
2003-10-04 15:40:09 +00:00
Dave Abrahams
912ca36a1f fixed broken link
[SVN r20255]
2003-10-04 12:06:19 +00:00
Dave Abrahams
fba93805dc Work with gcc2
[SVN r20168]
2003-09-23 23:57:23 +00:00
Dave Abrahams
96d66f4624 Correct integral constant overflow
[SVN r20136]
2003-09-21 18:49:04 +00:00
Dave Abrahams
c3bae63e41 Fix const-correctness problem
[SVN r20135]
2003-09-21 17:24:37 +00:00
Bruno da Silva de Oliveira
6c22aceabc - added return_by_value
[SVN r20127]
2003-09-21 02:07:07 +00:00
Dave Abrahams
92a77dfe7f Implemented injected constructors.
Eliminated _DEBUG redefinition warning for CWPro8.


[SVN r20126]
2003-09-21 01:35:19 +00:00
Bruno da Silva de Oliveira
4f2dbeda28 bugs in Enum and export_values option
[SVN r20121]
2003-09-19 23:07:14 +00:00
Dave Abrahams
bec2de08fe Use make_function uniformly to build callable objects.
Fix wstring support so it doesn't break gcc2.95.x, which has no wstring.

Modify CallPolicies protocol so it can safely adjust the argument tuple.


[SVN r20090]
2003-09-17 21:36:53 +00:00
Raoul Gough
db192e1e01 Remove incref of Py_None in make_nurse_and_patient - inc already done in detail::none()
[SVN r20079]
2003-09-16 17:31:06 +00:00
Dave Abrahams
454654a9cc Try to ward off personal emails
[SVN r20041]
2003-09-12 20:08:05 +00:00
Dave Abrahams
1018bc56eb put newlines in the list of links
[SVN r20037]
2003-09-12 14:54:34 +00:00
Dave Abrahams
f920dc87d0 Added std::wstring conversion support
Added std::out_of_range => Python IndexError exception conversion,
thanks to Raoul Gough


[SVN r20027]
2003-09-11 19:19:55 +00:00
Dave Abrahams
8b97caae46 Warn about duplicate to-python converters and show the name of the
offending type.


[SVN r20023]
2003-09-11 15:09:11 +00:00
Dave Abrahams
3b74aab818 add pyfinalize safety
[SVN r20022]
2003-09-11 11:07:05 +00:00
Dave Abrahams
e78b4939b3 Added new str constructors which take a range of characters, allowing
strings containing nul ('\0') characters.


[SVN r20006]
2003-09-11 02:57:24 +00:00
Bruno da Silva de Oliveira
621b5fc2db - added INTERFACE_FILE
[SVN r20005]
2003-09-10 21:55:50 +00:00
Dave Abrahams
6ada069d5a Update for cross-project capability
[SVN r20002]
2003-09-10 16:08:41 +00:00
Joel de Guzman
50db384be1 Used BOOST_WORKAROUND
[SVN r19980]
2003-09-09 13:13:44 +00:00
Dave Abrahams
ae7225ae83 Updates for cross-project dependencies
[SVN r19977]
2003-09-09 03:14:01 +00:00
Dave Abrahams
911ba333a2 restored python test drivers
[SVN r19976]
2003-09-09 02:55:39 +00:00
Dave Abrahams
5cd8cce531 Set up BOOST_ROOT before import python has a chance to use it.
[SVN r19974]
2003-09-09 02:42:17 +00:00
Dave Abrahams
6a2a76cea9 Use new cross-project feature
[SVN r19969]
2003-09-08 19:36:06 +00:00
Dave Abrahams
7a9a3d30c9 Use the import rule
[SVN r19968]
2003-09-08 17:38:49 +00:00
Joel de Guzman
034ca4d5eb mscv workaround
[SVN r19962]
2003-09-08 12:56:33 +00:00
Dave Abrahams
00e3fa32fb Fix typo
[SVN r19949]
2003-09-07 19:45:21 +00:00
Dave Abrahams
0133bdfbe3 Removed unused ConverterGenerators arguments.
Updated arg_from_python<T> so that its operator() is nullary -- it
already gets everything it needs in its constructor.


[SVN r19948]
2003-09-07 19:44:44 +00:00
Dave Abrahams
e563def5ba Update documentation for the use of function objects.
[SVN r19947]
2003-09-07 18:03:20 +00:00
Dave Abrahams
b3910f4e4d Support for wrapping function objects and classes which use virtual
inheritance.  Completely killed off member_function_cast!


[SVN r19945]
2003-09-07 16:56:05 +00:00
Bruno da Silva de Oliveira
4a7b8fe839 - Wrapper for protected and private pure virtual functions are now generated
[SVN r19922]
2003-09-04 22:47:04 +00:00
Joel de Guzman
fc56544da4 added note to use bjam as the preferred build tool
[SVN r19889]
2003-09-01 03:12:34 +00:00
Dave Abrahams
c839d25722 Add module_tail for JIT debugging
[SVN r19863]
2003-08-29 19:42:39 +00:00
Dave Abrahams
c6b5ecbbdb Update for select_holder changes
[SVN r19862]
2003-08-29 19:03:14 +00:00
Joel de Guzman
d3473afa23 Take 2
[SVN r19805]
2003-08-27 12:10:49 +00:00
Joel de Guzman
379b28eb85 Some more tweaks
[SVN r19803]
2003-08-27 10:18:37 +00:00
Joel de Guzman
7f5bd33ead Tweaks
[SVN r19802]
2003-08-27 10:14:14 +00:00
Joel de Guzman
eef6fb9891 def_visitor linked in the reference
[SVN r19801]
2003-08-27 10:09:08 +00:00
Joel de Guzman
4a7f52ab2c Initial commit of def_visitor doc
[SVN r19800]
2003-08-27 10:00:23 +00:00
Bruno da Silva de Oliveira
10b249a162 - Using the new Boost.Python facility for wrapping pure virtual functions
[SVN r19792]
2003-08-26 23:24:02 +00:00
Dave Abrahams
5fc5fce663 removed intro text
[SVN r19790]
2003-08-26 15:49:50 +00:00
Dave Abrahams
f00fe3c0b1 Added reference to TODO list
[SVN r19789]
2003-08-26 15:48:36 +00:00
Dave Abrahams
3047d51613 revised, ReST-ized HTML-ized
[SVN r19788]
2003-08-26 15:47:41 +00:00
Dave Abrahams
f9f7146960 revised, ReST-ized HTML-ized
[SVN r19787]
2003-08-26 15:42:51 +00:00
Ralf W. Grosse-Kunstleve
ca9dc3103a print running... Done.
[SVN r19785]
2003-08-26 13:19:51 +00:00
Ralf W. Grosse-Kunstleve
c03afa379c print Done before sys.exit; this allows us to detect fatal crashes like segmentation faults on import
[SVN r19784]
2003-08-26 13:11:51 +00:00
Ralf W. Grosse-Kunstleve
cbacc98e3f MIPSpro workaround
[SVN r19783]
2003-08-26 12:52:21 +00:00
Dave Abrahams
84daf14f1b Added missing #includes
[SVN r19782]
2003-08-26 11:45:47 +00:00
Dave Abrahams
4af28b2a46 Added missing #includes
[SVN r19778]
2003-08-26 02:25:33 +00:00
Bruno da Silva de Oliveira
acbc01933c - Fixed a bug where the code for a virtual method wrapper defined inside a Pyste file was not being declared in the generated code
[SVN r19776]
2003-08-26 00:43:09 +00:00
Dave Abrahams
7ec78eecbd Implemented pure_virtual(...)
[SVN r19774]
2003-08-25 18:44:26 +00:00
Dave Abrahams
87c5e37f5e vc6 workaround for nested enums
[SVN r19773]
2003-08-25 18:41:26 +00:00
Dave Abrahams
d02959e3ed Remove cwpro7 workarounds; simplified select_holder
[SVN r19772]
2003-08-25 18:41:02 +00:00
Dave Abrahams
b844d8b750 Refactoring and cleanups
[SVN r19770]
2003-08-25 18:38:39 +00:00
Bruno da Silva de Oliveira
0a3010b29f no message
[SVN r19761]
2003-08-23 20:53:33 +00:00
Bruno da Silva de Oliveira
2b380d03c9 - Make the cache files be rebuilt only when the declarations' version changes, instead o pyste's version
[SVN r19759]
2003-08-23 19:18:52 +00:00
Bruno da Silva de Oliveira
3f70253a3f - Fixed bug where Include was not writing the #include in some situations
- Rebuild cache files if pyste version changes


[SVN r19757]
2003-08-23 17:06:37 +00:00
Dave Abrahams
165e294298 Fix #ifdef
[SVN r19745]
2003-08-23 11:41:00 +00:00
Ralf W. Grosse-Kunstleve
f7c9f45508 simple fix for MIPSpro after a long struggle; thanks to Stephen Adamczyk and John Spicer at EDG!
[SVN r19724]
2003-08-21 21:27:38 +00:00
Joel de Guzman
af2a924301 more workaround fixes for VC6 linker bug
[SVN r19714]
2003-08-20 13:15:41 +00:00
Joel de Guzman
3981e83de5 workaround MSVC linker bug
[SVN r19713]
2003-08-20 12:07:48 +00:00
Bruno da Silva de Oliveira
88b9721e3f - Fixed bug related to bases<> template generation in the new system
[SVN r19700]
2003-08-20 01:40:43 +00:00
Joel de Guzman
4946af1448 Map indexing fix for VC6.5
[SVN r19699]
2003-08-19 20:32:56 +00:00
Dave Abrahams
9959dcfa49 Always #include prefix.h first of all.
[SVN r19694]
2003-08-19 15:44:30 +00:00
Joel de Guzman
cfb13fad22 fix for wrapping vector<bool>
[SVN r19692]
2003-08-19 03:28:53 +00:00
Joel de Guzman
4e3f3a052d chaned struct def_visitor; to class def_visitor;
[SVN r19691]
2003-08-19 02:23:16 +00:00
Bruno da Silva de Oliveira
dc7ae9ed20 - removed "header_code", since we already have Include().
[SVN r19670]
2003-08-17 21:11:07 +00:00
Bruno da Silva de Oliveira
929badf4c6 Added support for insertion of user code in the generated code
[SVN r19664]
2003-08-17 19:35:00 +00:00
Bruno da Silva de Oliveira
c4a3f2c04f no message
[SVN r19652]
2003-08-16 21:11:50 +00:00
Bruno da Silva de Oliveira
a933e458b3 - Fixed a bug in the pure virtual functions
[SVN r19648]
2003-08-16 19:13:45 +00:00
Bruno da Silva de Oliveira
06b8320815 - Added exception specifiers (patch by Gottfried).
[SVN r19645]
2003-08-16 18:21:44 +00:00
Dave Abrahams
7f3aceafd2 Fix public/private error.
[SVN r19636]
2003-08-16 13:56:52 +00:00
Dave Abrahams
da5979931c class.hpp, object/select_holder.hpp, object/pointer_holder.hpp -
fix a problem which was causing value_holder<T> to be instantiated
   on abstract classes.  Now we compute the held_type at an outer
   level thereby avoiding the inner instantiation.

object_core.hpp -

   workarounds for GCC 2.x bugs

suite/indexing/detail/indexing_suite_detail.hpp -

   workaround for a CWPro8 bug


[SVN r19635]
2003-08-16 13:48:34 +00:00
Dave Abrahams
d8c7e75095 Fix the fix... again!
[SVN r19617]
2003-08-15 03:45:34 +00:00
Joel de Guzman
187506c97f added map value type (std::pair) wrapper to map_indexing_suite.hpp
[SVN r19616]
2003-08-15 03:03:27 +00:00
Joel de Guzman
145c6d1e4f moved map value type (std::pair) wrapper to map_indexing_suite.hpp
[SVN r19615]
2003-08-15 03:01:32 +00:00
Dave Abrahams
e2973f27f9 Fix the fix ;-)
[SVN r19613]
2003-08-14 22:53:30 +00:00
Dave Abrahams
976b8180ae Workaround a VC7 bug with nested enums
[SVN r19611]
2003-08-14 22:48:01 +00:00
Joel de Guzman
37acf41d43 Added map_indexing_suite test
[SVN r19600]
2003-08-14 15:05:02 +00:00
Joel de Guzman
6f26778491 Initial commit map_indexing_suite tests
[SVN r19599]
2003-08-14 15:04:25 +00:00
Joel de Guzman
834d815c87 mapping suite update
[SVN r19598]
2003-08-14 15:03:14 +00:00
Joel de Guzman
57e58c445b Tweaks to accomodate map_indexing_suite
[SVN r19588]
2003-08-14 12:14:25 +00:00
Joel de Guzman
8a1a8342d6 Initial commit map_indexing_suite
[SVN r19587]
2003-08-14 12:13:15 +00:00
Joel de Guzman
fa70ddc2c5 Preparing for std::map suite
[SVN r19566]
2003-08-12 21:21:47 +00:00
Joel de Guzman
8ca32bb494 Minor tweak in preparation for map_indexing_suite.hpp
[SVN r19565]
2003-08-12 18:36:55 +00:00
Joel de Guzman
f6c82eba0c changed def_arg to def_visitor
[SVN r19564]
2003-08-12 18:35:00 +00:00
Joel de Guzman
344044a315 updated the include path to vector_indexing_suite.hpp
[SVN r19563]
2003-08-12 18:13:19 +00:00
Joel de Guzman
b10805dc4c moved to new "suite" directory
[SVN r19562]
2003-08-12 18:09:21 +00:00
Joel de Guzman
07f397e2ed Moved to new "suite" directory
[SVN r19561]
2003-08-12 18:07:11 +00:00
Dave Abrahams
054dc439d2 Workaround msvc bug
[SVN r19553]
2003-08-12 14:17:52 +00:00
Dave Abrahams
5008dcbdd4 Make sure the class object and cast relationships are registered for
virtual function dispatch classes.


[SVN r19543]
2003-08-12 04:36:42 +00:00
Dave Abrahams
9c6650963f Use def_visitor to simplify class def(...) handling.
Workarounds for intel6 and vc6.


[SVN r19533]
2003-08-11 14:56:30 +00:00
Dave Abrahams
d482d57689 added properties tests
[SVN r19532]
2003-08-11 14:30:04 +00:00
Dave Abrahams
edf6516085 Python 2.3 compatibility.
[SVN r19530]
2003-08-11 11:07:28 +00:00
Dave Abrahams
957ac66e14 Added missing #include
Use BOOST_EXPLICIT_TEMPLATE_TYPE


[SVN r19529]
2003-08-11 02:21:34 +00:00
Dave Abrahams
07ce84c4e7 Repair bugs introduced during previous workaround
[SVN r19526]
2003-08-11 02:01:15 +00:00
Bruno da Silva de Oliveira
918636ff03 - Fixed a bug where in some classes the virtual methods were being definied incorrectly
[SVN r19525]
2003-08-10 23:21:25 +00:00
Dave Abrahams
83a6adbfa9 Added properties news item
changed the name of the static property class to
Boost.Python.StaticProperty (was Boost.Python.Class).


[SVN r19521]
2003-08-10 22:56:58 +00:00
Dave Abrahams
fcbc1d562f Added properties unit test from Roman Yakovenko
<romany-at-actimize.com>.


[SVN r19520]
2003-08-10 22:51:51 +00:00
Dave Abrahams
c3b4b58075 Extended CWPro8 overload ambiguity workaround to cover make_setter as
well as make_getter.


[SVN r19519]
2003-08-10 22:50:38 +00:00
Bruno da Silva de Oliveira
568b62a8a4 - Little bug where the memory cache was not being used
[SVN r19517]
2003-08-10 21:51:28 +00:00
Bruno da Silva de Oliveira
da34e7f507 - Abstract methods fix
- converts \ to / on windows


[SVN r19516]
2003-08-10 21:47:50 +00:00
Joel de Guzman
a0c31b47e5 refactored code + cleanup
[SVN r19508]
2003-08-10 15:20:10 +00:00
Joel de Guzman
5fb677c0c5 initial commit of container utils
[SVN r19507]
2003-08-10 15:19:23 +00:00
Bruno da Silva de Oliveira
168476382a - incremental code and some fixes
[SVN r19499]
2003-08-09 21:18:12 +00:00
Bruno da Silva de Oliveira
7fa6a29814 no message
[SVN r19498]
2003-08-09 20:57:04 +00:00
Bruno da Silva de Oliveira
f2b51da0ab - Fix a bug where a declaration was appearing more than once in an intermediate class in an hierarchy not fully-exported
[SVN r19489]
2003-08-08 02:56:04 +00:00
Joel de Guzman
53726746b8 Clean-up, refactored and added NoSlice option.
[SVN r19488]
2003-08-07 17:16:07 +00:00
Joel de Guzman
fe0b59f559 some trivial fixes.
[SVN r19485]
2003-08-07 12:29:54 +00:00
Joel de Guzman
c014dee6dc Fixed no proxy handling for containers of primitive types.
[SVN r19484]
2003-08-07 08:45:57 +00:00
Joel de Guzman
90c69d961e Added named visitor .def facility.
[SVN r19483]
2003-08-07 03:07:20 +00:00
Dave Abrahams
342f7db678 Workaround vc7.1 typeid problem with cv-qualified arrays.
[SVN r19474]
2003-08-06 13:51:03 +00:00
Joel de Guzman
9eb704f85a fixed iteration scheme and added append and extend methods
[SVN r19469]
2003-08-06 08:06:09 +00:00
Dave Abrahams
7754a91929 Update docs for static data support.
[SVN r19462]
2003-08-05 13:41:21 +00:00
Dave Abrahams
e4dc639e54 Allow mutating operations on self for all operators
[SVN r19454]
2003-08-05 03:15:37 +00:00
Ralf W. Grosse-Kunstleve
5d90101671 workaround for MIPSpro, thanks to John Spicer
[SVN r19453]
2003-08-05 03:03:49 +00:00
Ralf W. Grosse-Kunstleve
437fb70852 Tru64 cxx requires X::operator!=
[SVN r19450]
2003-08-05 00:49:33 +00:00
Dave Abrahams
d598404c48 initial commit
[SVN r19449]
2003-08-04 23:52:01 +00:00
Joel de Guzman
32c7088600 added missing typename and include file
[SVN r19448]
2003-08-04 23:34:52 +00:00
Joel de Guzman
ccede29816 added missing line feed at end of source
[SVN r19447]
2003-08-04 23:34:02 +00:00
Ralf W. Grosse-Kunstleve
b55b7e2f7b workaround for Mac OS 10 gcc 3.3 static initialization bug
[SVN r19446]
2003-08-04 22:09:16 +00:00
Ralf W. Grosse-Kunstleve
9217a6a253 avoid (incorrect) Tru64 cxx 6.5.1 warning
[SVN r19445]
2003-08-04 20:54:07 +00:00
Dave Abrahams
07c1319b99 Added the new arg class from
"nickm-at-sitius.com" (Nikolay Mladenov) which supplies the
ability to wrap functions that can be called with ommitted
arguments in the middle.


[SVN r19441]
2003-08-04 17:46:48 +00:00
Dave Abrahams
714b5dc26e missing checkin
[SVN r19439]
2003-08-04 17:36:49 +00:00
Joel de Guzman
1f715958f9 Fixed get_slice
[SVN r19421]
2003-08-04 05:09:23 +00:00
Joel de Guzman
0922aca873 Better usage of handle<>.
[SVN r19420]
2003-08-04 03:24:41 +00:00
Joel de Guzman
30ec6181b5 Fixed negative ref count bug
[SVN r19419]
2003-08-04 02:36:47 +00:00
Dave Abrahams
b28d586612 Move assignment operator inline as a workaround for a vc7 bug.
[SVN r19416]
2003-08-03 14:19:09 +00:00
Dave Abrahams
f48aacf477 added internals
[SVN r19390]
2003-07-31 18:03:17 +00:00
Dave Abrahams
bfa868a440 Workarounds for VC6 bugs
[SVN r19389]
2003-07-31 15:56:10 +00:00
Dave Abrahams
f01ff3a277 Prune #includes
[SVN r19382]
2003-07-31 01:04:51 +00:00
Dave Abrahams
d88e6bf688 object_core.hpp - use detail/is_xxx to generate template identifiers
object_operators.hpp - use SFINAE to prevent ADL from finding
        generalized operators inappropriately


[SVN r19377]
2003-07-30 23:48:06 +00:00
Dave Abrahams
a3cdacd088 Bug fix -- we weren't handling NULL keywords dictionaries in raw_function
[SVN r19359]
2003-07-30 11:34:50 +00:00
Joel de Guzman
81d99c855f Minor tweaks
[SVN r19335]
2003-07-29 04:47:34 +00:00
Joel de Guzman
5cd110f625 Comments from Dave + Editing + Proof reading and stuff
[SVN r19334]
2003-07-29 04:30:37 +00:00
Joel de Guzman
416895ff30 linked in the indexing suite documentation
[SVN r19315]
2003-07-26 05:49:57 +00:00
Joel de Guzman
e41abb6e92 Initial commit of indexing suite documentation
[SVN r19314]
2003-07-26 05:48:59 +00:00
Joel de Guzman
a6440a3fa6 Minor tweaks
[SVN r19313]
2003-07-26 05:47:11 +00:00
Joel de Guzman
2dece7ecaf added __iter__ and __contains__
[SVN r19311]
2003-07-26 01:50:35 +00:00
Dave Abrahams
7aae525587 Added RationalDiscovery
[SVN r19300]
2003-07-24 16:38:23 +00:00
Ralf W. Grosse-Kunstleve
ac5314093b fixing some trivial bugs (missing or misplaced typename); work around gcc 3.2 bug
[SVN r19299]
2003-07-24 15:07:05 +00:00
Ralf W. Grosse-Kunstleve
1524fb9fa9 flotsam removed
[SVN r19297]
2003-07-24 13:51:06 +00:00
Joel de Guzman
957549460b Initial Commit of Indexing Suite
[SVN r19296]
2003-07-24 12:02:57 +00:00
Joel de Guzman
3b33f54fb8 Added generic visitation mechanism.
[SVN r19288]
2003-07-24 01:44:18 +00:00
Ralf W. Grosse-Kunstleve
42ab6b6b66 unused variable removed (to avoid MIPSpro warning)
[SVN r19287]
2003-07-23 19:00:55 +00:00
Dave Abrahams
f59a5bbabc Stop printing return types in error messages.
[SVN r19286]
2003-07-23 17:04:05 +00:00
Dave Abrahams
0be371d747 Added cross-module exception test
[SVN r19282]
2003-07-23 15:17:03 +00:00
Dave Abrahams
2b52210291 remove (again!) extra diagnostic info
[SVN r19281]
2003-07-23 14:14:00 +00:00
Dave Abrahams
96a7bce78e Give feedback about the name and namespace of functions in error messages.
[SVN r19280]
2003-07-23 13:08:59 +00:00
Dave Abrahams
c1e1ea697c Added Metafaq link
[SVN r19278]
2003-07-23 11:43:06 +00:00
Dave Abrahams
874d6ebf2c Kill off nasty diagnostic printing.
[SVN r19277]
2003-07-23 11:11:56 +00:00
Dave Abrahams
77f5eb703c Attempt to work around a GCC EH problem by sticking a virtual function
in error_already_set and defining it in the library.

Removed some flotsam


[SVN r19274]
2003-07-23 03:00:48 +00:00
Dave Abrahams
af53ae8329 Implemented better error reporting for argument match errors.
[SVN r19271]
2003-07-23 01:31:34 +00:00
Dave Abrahams
8f76b8880e Remove bad #includes
[SVN r19269]
2003-07-22 23:55:09 +00:00
Dave Abrahams
fa398734be initial commit
[SVN r19267]
2003-07-22 23:53:06 +00:00
Dave Abrahams
362d20a8c7 Fixed editing error
[SVN r19265]
2003-07-22 20:12:39 +00:00
Dave Abrahams
6a33b8aeeb Implemented better error reporting for argument match errors.
[SVN r19264]
2003-07-22 20:12:07 +00:00
Dave Abrahams
d4e06ac436 Preparation for delivering nicely-formatted error messages in
Boost.Python.  The major change is that, instead of being
boost::function2<PyObject*,PyObject*,PyObject*>, py_function is now a
runtime-polymorphic wrapper for compile-time polymorphic
behavior (just like function) of our own which carries more
information/behaviors.  In particular, you can retrieve an array of
c-strings describing the types in the function signature.
Additionally, the minimum and maximum arity are stored in the
py_function object instead of in the 'function' object which wraps it.

* data_members.hpp -

     Adjustments for the new py_function.  Workarounds for CodeWarrior
     Pro 8.3 bugs in function template argument deduction with
     pointers-to-members.

* has_back_reference.hpp, test/back_reference.cpp,
  test/select_holder.cpp -

     Updated to follow the metafunction protocol

* init.hpp, detail/defaults_gen.hpp -

     Make Keywords a more-specific type in function signatures to
     prevent string literals that show up as char[N] from binding to
     the wrong argument (at least Intel 7.1 for Windows does this).

* make_function.hpp -

     Adjustments for the new py_function.  Arities are now computed
     by caller<>.

* opaque_pointer_converter.hpp, type_id.hpp -

     Use BOOST_NO_EXPLICIT_FUNCTION_TEMPLATE_ARGUMENTS facilities;
     generate specializations that all compilers can handle.

* raw_function.hpp -

     Adjustments for the new py_function.

* caller.hpp -

     Added arity and signature type name reporting.

* detail/config.hpp

     Enable __declspec(dllexport) for Cygwin, thereby fixing the
     recent horrible Cygwin linking problems.


* detail/msvc_typeinfo.hpp -

     Always pass boost::type<T>* explicitly, thereby working around
     incompatible notions of how to specialize function templates with
     default arguments on various compilers.

*   object/function.hpp
  , object/function_handle.hpp
  , object/function_object.hpp
  , object/function_object.cpp

     Adjustments for the new py_function.  Arities are carried by
     py_function.

* object/iterator.hpp, object/iterator.cpp

     Adjustments for the new py_function; we have to compute a
     signature of types to construct it with.

* object/py_function.hpp

     Removed dependency on boost::function; see the comment at the
     top of this entry for more details.

* object/select_holder.hpp

     Clean up to more closely follow MPL idioms.

* test/Jamfile -

     Adjust the embedding test for the new Cygwin use of declspec.
     Update bases and pointee tests with missing properties.

* test/input_iterator.cpp -

     Updates for the new iterator adaptors.

* test/opaque.py -

     Add Python encoding comment to suppress PendinDeprecationWarning
     with recent Python builds.

* test/str.cpp

     Pass a Python long instead of a float to string.expandtabs,
     suppressing a PendinDeprecationWarning with recent Python builds.

* libs/utility/counting_iterator_example.cpp

     Borland workaround

* libs/utility/indirect_iterator_example.cpp

     const-correctness fix.

*


[SVN r19247]
2003-07-22 00:06:41 +00:00
Dave Abrahams
817dcd37e0 Get Cygwin linking again
User-readable type name printing for GCC


[SVN r19236]
2003-07-21 02:14:58 +00:00
Dave Abrahams
25bfd3c50f Suppress a GCC 2.x ICE
[SVN r19235]
2003-07-21 02:12:04 +00:00
Dave Abrahams
b13c902fb0 * added return_arg policy from Nikolay Mladenov
* removed duplication from reference.html

* improved automatic redirection messages


[SVN r19226]
2003-07-19 23:49:06 +00:00
Dave Abrahams
c95ef44b02 Added Kig
[SVN r19154]
2003-07-16 15:40:27 +00:00
Bruno da Silva de Oliveira
162727590c - moved register_ptr_to_python up one level.
[SVN r19123]
2003-07-15 01:05:07 +00:00
Vladimir Prus
7e159844fb Update for current Boost.Build V2.
[SVN r19037]
2003-07-11 06:04:35 +00:00
Dave Abrahams
787b79cc2c Added NeuraLab
[SVN r18979]
2003-07-08 13:10:59 +00:00
Bruno da Silva de Oliveira
b77652b499 - fixed staticmethod bug
- fixed hierarchies bug when using AllFromHeader


[SVN r18971]
2003-07-07 20:00:40 +00:00
Bruno da Silva de Oliveira
0c8444b8ed - fixed bug of --multiple
- new function: hold_with_shared_ptr
- SPECIALIZE_TYPE_ID bug


[SVN r18969]
2003-07-07 19:00:52 +00:00
Bruno da Silva de Oliveira
3e6ee799ba - --multiple now generates one cpp per pyste file.
[SVN r18945]
2003-07-06 01:16:27 +00:00
Bruno da Silva de Oliveira
dd14ccb115 - --multiple now generates one cpp per pyste file.
[SVN r18944]
2003-07-06 01:12:26 +00:00
Bruno da Silva de Oliveira
ba0fcd27c3 - Various bug fixes
- Changed the internal code to the way it was


[SVN r18941]
2003-07-04 22:47:27 +00:00
Bruno da Silva de Oliveira
d476e67067 - Fixed "char**" bug
- Lots of internal changes: phase 1 of Meta-Programming complete.


[SVN r18919]
2003-07-03 00:00:23 +00:00
Bruno da Silva de Oliveira
4588f5e9ab no message
[SVN r18884]
2003-06-29 17:47:45 +00:00
Bruno da Silva de Oliveira
68f54d364b - register_ptr_to_python addition
[SVN r18880]
2003-06-27 18:34:25 +00:00
Dave Abrahams
7dba18e7b9 Test that shared_ptr<Derived> can be converted to shared_ptr<Base>
[SVN r18851]
2003-06-20 22:57:37 +00:00
Dave Abrahams
67b265fe96 Remove duplicated sections
[SVN r18835]
2003-06-18 12:22:28 +00:00
Bruno da Silva de Oliveira
8289269a86 *** empty log message ***
[SVN r18828]
2003-06-18 00:05:01 +00:00
Bruno da Silva de Oliveira
9f711ed821 - Changed "no_override" to "final"
[SVN r18826]
2003-06-17 23:25:16 +00:00
Bruno da Silva de Oliveira
73e2ab5125 - Added a new test exercising the new automatic inheritation
[SVN r18815]
2003-06-17 01:56:45 +00:00
Bruno da Silva de Oliveira
7ea2ab1672 - If you export a derived class without exporting its base classes, the derived class will explicitly export the bases's methods and attributes. Before, if you were interested in the bases's methods, you had to export the base classes too.
- Added a new function, no_override. When a member function is specified as "no_override", no virtual wrappers are generated for it, improving performance and letting the code more clean.

- There was a bug in which the policy of virtual member functions was being ignored (patch by Roman Sulzhyk).


[SVN r18814]
2003-06-17 01:34:26 +00:00
Bruno da Silva de Oliveira
c821e903f8 Added tests for linux.
[SVN r18809]
2003-06-16 20:36:36 +00:00
Ralf W. Grosse-Kunstleve
54db04521a MIPSpro workaround
[SVN r18744]
2003-06-09 13:10:34 +00:00
Bruno da Silva de Oliveira
91fdecd76f - Changed the filename of one of the doc files to limit it to 32 chars.
[SVN r18709]
2003-06-08 22:51:37 +00:00
Dave Abrahams
f140a74a13 Added MinGW tips
[SVN r18695]
2003-06-06 11:18:34 +00:00
Bruno da Silva de Oliveira
4854a2a81b - Added another entry, about ESSS.
[SVN r18685]
2003-06-06 00:04:51 +00:00
Bruno da Silva de Oliveira
d94bb65006 - Major improvements in memory usage.
[SVN r18681]
2003-06-05 15:14:52 +00:00
Bruno da Silva de Oliveira
6ca5280b2c - Fixed bug in GCCXMLParser
[SVN r18672]
2003-06-04 22:07:27 +00:00
Dave Abrahams
5da3e1deea Leak bug fixed thanks to gideon may <gideon-at-computer.org> for
reporting it.


[SVN r18671]
2003-06-04 20:47:39 +00:00
Dave Abrahams
1ae85d0e39 Added Jayacard
[SVN r18660]
2003-06-04 02:23:13 +00:00
310 changed files with 13863 additions and 4552 deletions

View File

@@ -10,8 +10,7 @@
subproject libs/python/build ;
# bring in the rules for python
SEARCH on <module@>python.jam = $(BOOST_BUILD_PATH) ;
include <module@>python.jam ;
import python ;
if [ check-python-config ]
{
@@ -61,8 +60,14 @@ if [ check-python-config ]
<define>BOOST_PYTHON_SOURCE
$(bpl-linkflags)
<msvc-stlport><release>$(msvc-stlport-workarounds)
<darwin><*><linkflags>-bind_at_load
;
template extension
: <dll>boost_python
: <sysinclude>../../..
;
lib boost_python
: # sources
../src/$(sources)
@@ -81,4 +86,8 @@ if [ check-python-config ]
:
debug release
;
}
install python lib
: <dll>boost_python <lib>boost_python
;
}

View File

@@ -1,8 +1,11 @@
import os ;
import modules ;
# Use a very crude way to sense there python is locatted
local PYTHON_PATH ;
local PYTHON_PATH = [ modules.peek : PYTHON_PATH ] ;
ECHO "XXX" $(PYTHON_PATH) ;
if [ GLOB /usr/local/include/python2.2 : * ]
{
@@ -19,7 +22,7 @@ if [ os.name ] in CYGWIN NT
defines = USE_DL_IMPORT ;
# Declare a target for the python interpreter library
lib python : : <name>python2.2.dll ;
lib python : : <name>python22 <search>$(PYTHON_PATH)/libs ;
PYTHON_LIB = python ;
}
else
@@ -35,12 +38,12 @@ if $(PYTHON_PATH) {
project boost/python
: source-location ../src
: requirements <include>$(PYTHON_PATH)/include/python2.2
$(lib_condition)<library-path>$(PYTHON_PATH)/lib/python2.2/config
: 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/python2.2
<include>$(PYTHON_PATH)/include
# We have a bug which causes us to conclude that conditionalized
# properties in this section are not free.

Binary file not shown.

View File

@@ -46,21 +46,15 @@
<dt><a href="#cygwin">Notes for Cygwin GCC Users</a></dt>
<dt><a href="#mingw">Notes for MinGW (and Cygwin with -mno-cygwin)
GCC Users</a></dt>
<dt><a href="#testing">Testing</a></dt>
</dl>
</dd>
<dt><a href="#building_ext">Building your Extension Module</a></dt>
<dd>
<dl>
<dt><a href="#easy">The Easy Way</a></dt>
<dt><a href="#outside">Building your module outside the Boost
project tree</a></dt>
</dl>
</dd>
<dt><a href="#variants">Build Variants</a></dt>
<dt><a href="#VisualStudio">Building Using the Microsoft Visual Studio
@@ -80,10 +74,10 @@
<p>Normally, Boost.Python extension modules must be linked with the
<code>boost_python</code> shared library. In special circumstances you
may want to link to a static version of the <code>boost_python</code>
library, but if multiple Boost.Pythone extension modules are used
library, but if multiple Boost.Python extension modules are used
together, it will prevent sharing of types across extension modules, and
consume extra code space. To build <code>boost_python</code>, use <a
href="../../../tools/build/index.html">Boost.Build</a> in the usual way
href="../../../tools/build/v1/build_system.htm">Boost.Build</a> in the usual way
from the <code>libs/python/build</code> subdirectory of your boost
installation (if you have already built boost from the top level this may
have no effect, since the work is already done).</p>
@@ -222,6 +216,19 @@
build of bjam to build and test Boost.Python and Boost.Python extensions
using Cygwin GCC and targeting a Cygwin build of Python.</p>
<h3><a name="mingw">Notes for MinGW (and Cygwin with -mno-cygwin) GCC
Users</a></h3>
<p>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 <a href=
"http://www.python.org/doc/current/inst/index.html">Installing Python
Modules</a> to create <code>libpythonXX.a</code>, where <code>XX</code>
corresponds to the major and minor version numbers of your Python
installation.</p>
<h3><a name="results">Results</a></h3>
<p>The build process will create a
@@ -242,7 +249,7 @@
<blockquote>
<pre>
bjam -sTOOLS=<i><a href=
"../../../tools/build/index.html#Tools">toolset</a></i> test
"../../../more/getting_started.html#Tools">toolset</a></i> test
</pre>
</blockquote>
This will update all of the Boost.Python v1 test and example targets. The
@@ -252,58 +259,62 @@ bjam -sTOOLS=<i><a href=
<blockquote>
<pre>
bjam -sTOOLS=<i><a href=
"../../../tools/build/index.html#Tools">toolset</a></i> -sPYTHON_TEST_ARGS=-v test
"../../../more/getting_started.html#Tools">toolset</a></i> -sPYTHON_TEST_ARGS=-v test
</pre>
</blockquote>
which will print each test's Python code with the expected output as it
passes.
<h2><a name="building_ext">Building your Extension Module</a></h2>
Though there are other approaches, the best way to build an extension
module using Boost.Python is with Boost.Build. If you have to use another
build system, you should use Boost.Build at least once with the
Though there are other approaches, the smoothest and most reliable
way to build an extension module using Boost.Python is with
Boost.Build. If you have to use another build system, you should
use Boost.Build at least once with the
"<code><b>-n</b></code>" option so you can see the command-lines it uses,
and replicate them. You are likely to run into compilation or linking
problems otherwise.
<h3><a name="easy">The Easy Way</a></h3>
Until Boost.Build v2 is released, cross-project build dependencies are
not supported, so it works most smoothly if you add a new subproject to
your boost installation. The <code>libs/python/example</code>
subdirectory of your boost installation contains a minimal example (along
with many extra sources). To copy the example subproject:
The <code><a href="../example">libs/python/example</a></code>
subdirectory of your boost installation contains a small example
which builds and tests two extensions. To build your own
extensions copy the example subproject and make the following two edits:
<ol>
<li>Create a new subdirectory in, <code>libs/python</code>, say
<code>libs/python/my_project</code>.</li>
<ol>
<li><code><a
href="../example/boost-build.jam"><b>boost-build.jam</b></a></code> -
edit the line which reads
<li>Copy <code><a href=
"../example/Jamfile">libs/python/example/Jamfile</a></code> to your new
directory.</li>
<blockquote>
<pre>
boost-build ../../../tools/build/v1 ;
</pre>
</blockquote>
<li>Edit the Jamfile as appropriate for your project. You'll want to
change the "<code>subproject</code>" rule invocation at the top, and
the names of some of the source files and/or targets.</li>
</ol>
so that the path refers to the <code>tools/build/v1</code> subdirectory
of your Boost installation.
<li><code><a href="../example/Jamrules"><b>Jamrules</b></a></code> -
edit the line which reads
<blockquote>
<pre>
path-global BOOST_ROOT : ../../.. ;
</pre>
</blockquote>
so that the path refers to the root directory of your Boost installation.
</ol>
<p>
The instructions <a href="#testing">above</a> for testing Boost.Python
apply equally to your new extension modules in this subproject.
<h3><a name="outside">Building your module outside the Boost project
tree</a></h3>
If you can't (or don't wish to) modify your boost installation, the
alternative is to create your own Boost.Build project. A similar example
you can use as a starting point is available in <code><a href=
"../example/project.zip">this archive</a></code>. You'll need to edit the
Jamfile and Jamrules files, depending on the relative location of your
Boost installation and the new project. Note that automatic testing of
extension modules is not available in this configuration.
<h2><a name="variants">Build Variants</a></h2>
Three <a href=
"../../../tools/build/build_system.htm#variants">variant</a>
"../../../tools/build/v1/build_system.htm#variants">variant</a>
configurations of all python-related targets are supported, and can be
selected by setting the <code><a href=
"../../../tools/build/build_system.htm#user_globals">BUILD</a></code>
"../../../tools/build/v1/build_system.htm#user_globals">BUILD</a></code>
variable:
<ul>

View File

@@ -73,6 +73,14 @@
<dt><a href="v2/reference.html">Reference Manual</a></dt>
<dt>Suites:</dt>
<dd>
<ul>
<li><a href="v2/pickle.html">Pickle</a></li>
<li><a href="v2/indexing.html">Indexing</a></li>
</ul>
</dd>
<dt><a href="v2/configuration.html">Configuration Information</a></dt>
<dt><a href="v2/platforms.html">Known Working Platforms and
@@ -88,9 +96,13 @@
<dt><a href="../pyste/index.html">Pyste (Boost.Python code generator)</a></dt>
<dt><a href="news.html">News/Change Log</a></dt>
<dt><a href="internals.html">Internals Documentation</a></dt>
<dt><a href="v2/progress_reports.html">LLNL Progress Reports</a></dt>
<dt><a href="news.html">News/Change Log</a></dt>
<dt><a href="../todo.html">TODO list</a></dt>
<dt><a href="v2/progress_reports.html">LLNL Progress Reports</a></dt>
<dt><a href="v2/acknowledgments.html">Acknowledgments</a></dt>
</dl>
@@ -106,12 +118,12 @@
<p>Revised
<!--webbot bot="Timestamp" S-Type="EDITED" S-Format="%d %B, %Y" startspan -->
18 March, 2003
26 August, 2003
<!--webbot bot="Timestamp" endspan i-checksum="39359" -->
</p>
<p><i>&copy; Copyright <a href="../../people/dave_abrahams.htm">Dave
Abrahams</a> 2002. All Rights Reserved.</i></p>
<p><i>&copy; Copyright <a href="../../../people/dave_abrahams.htm">Dave
Abrahams</a> 2002-2003. All Rights Reserved.</i></p>
</body>
</html>

186
doc/internals.html Executable file
View File

@@ -0,0 +1,186 @@
<?xml version="1.0" encoding="utf-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="generator" content="Docutils 0.3.0: http://docutils.sourceforge.net/" />
<title>Boost.Python Internals Boost</title>
<link rel="stylesheet" href="../../../rst.css" type="text/css" />
</head>
<body>
<div class="document" id="boost-python-internals-logo">
<h1 class="title"><a class="reference" href="index.html">Boost.Python</a> Internals <a class="reference" href="../../../index.htm"><img alt="Boost" src="../../../c++boost.gif" /></a></h1>
<div class="section" id="a-conversation-between-brett-calcott-and-david-abrahams">
<h1><a name="a-conversation-between-brett-calcott-and-david-abrahams">A conversation between Brett Calcott and David Abrahams</a></h1>
<table class="field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field"><th class="field-name">copyright:</th><td class="field-body">Copyright David Abrahams and Brett Calcott 2003. See
accompanying <a class="reference" href="../../../LICENSE_1_0.txt">license</a> for terms of use.</td>
</tr>
</tbody>
</table>
<p>In both of these cases, I'm quite capable of reading code - but the
thing I don't get from scanning the source is a sense of the
architecture, both structurally, and temporally (er, I mean in what
order things go on).</p>
<ol class="arabic">
<li><p class="first">What happens when you do the following:</p>
<pre class="literal-block">
struct boring {};
...etc...
class_&lt;boring&gt;(&quot;boring&quot;)
;
</pre>
</li>
</ol>
<p>There seems to be a fair bit going on.</p>
<blockquote>
<ul class="simple">
<li>Python needs a new ClassType to be registered.</li>
<li>We need to construct a new type that can hold our boring struct.</li>
<li>Inward and outward converters need to be registered for the type.</li>
</ul>
</blockquote>
<p>Can you gesture in the general direction where these things are done?</p>
<blockquote>
<p>I only have time for a &quot;off-the-top-of-my-head&quot; answer at the moment;
I suggest you step through the code with a debugger after reading this
to see how it works, fill in details, and make sure I didn't forget
anything.</p>
<blockquote>
<p>A new (Python) subclass of Boost.Python.Instance (see
libs/python/src/object/class.cpp) is created by invoking
Boost.Python.class, the metatype:</p>
<pre class="literal-block">
&gt;&gt;&gt; boring = Boost.Python.class(
... 'boring'
... , bases_tuple # in this case, just ()
... , {
... '__module__' : module_name
... , '__doc__' : doc_string # optional
... }
... )
</pre>
<p>A handle to this object is stuck in the m_class_object field
of the registration associated with <tt class="literal"><span class="pre">typeid(boring)</span></tt>. The
registry will keep that object alive forever, even if you
wipe out the 'boring' attribute of the extension module
(probably not a good thing).</p>
<p>Because you didn't specify <tt class="literal"><span class="pre">class&lt;boring,</span> <span class="pre">non_copyable,</span>
<span class="pre">...&gt;</span></tt>, a to-python converter for boring is registered which
copies its argument into a value_holder held by the the
Python boring object.</p>
<p>Because you didn't specify <tt class="literal"><span class="pre">class&lt;boring</span> <span class="pre">...&gt;(no_init)</span></tt>,
an <tt class="literal"><span class="pre">__init__</span></tt> function object is added to the class
dictionary which default-constructs a boring in a
value_holder (because you didn't specify some smart pointer
or derived wrapper class as a holder) held by the Python
boring object.</p>
<p><tt class="literal"><span class="pre">register_class_from_python</span></tt> is used to register a
from-python converter for <tt class="literal"><span class="pre">shared_ptr&lt;boring&gt;</span></tt>.
<tt class="literal"><span class="pre">boost::shared_ptr</span></tt>s are special among smart pointers
because their Deleter argument can be made to manage the
whole Python object, not just the C++ object it contains, no
matter how the C++ object is held.</p>
<p>If there were any <tt class="literal"><span class="pre">bases&lt;&gt;</span></tt>, we'd also be registering the
relationship between these base classes and boring in the
up/down cast graph (<tt class="literal"><span class="pre">inheritance.[hpp/cpp]</span></tt>).</p>
<p>In earlier versions of the code, we'd be registering lvalue
from-python converters for the class here, but now
from-python conversion for wrapped classes is handled as a
special case, before consulting the registry, if the source
Python object's metaclass is the Boost.Python metaclass.</p>
<p>Hmm, that from-python converter probably ought to be handled
the way class converters are, with no explicit conversions
registered.</p>
</blockquote>
</blockquote>
<ol class="arabic" start="2">
<li><p class="first">Can you give a brief overview of the data structures that are
present in the registry</p>
<blockquote>
<p>The registry is simple: it's just a map from typeid -&gt;
registration (see boost/python/converter/registrations.hpp).
<tt class="literal"><span class="pre">lvalue_chain</span></tt> and <tt class="literal"><span class="pre">rvalue_chain</span></tt> are simple endogenous
linked lists.</p>
<p>If you want to know more, just ask.</p>
<p>If you want to know about the cast graph, ask me something specific in
a separate message.</p>
</blockquote>
<p>and an overview of the process that happens as a type makes its
way from c++ to python and back again.</p>
</li>
</ol>
<blockquote>
<p>Big subject. I suggest some background reading: look for relevant
info in the LLNL progress reports and the messages they link to.
Also,</p>
<blockquote>
<p><a class="reference" href="http://mail.python.org/pipermail/c++-sig/2002-May/001023.html">http://mail.python.org/pipermail/c++-sig/2002-May/001023.html</a></p>
<p><a class="reference" href="http://mail.python.org/pipermail/c++-sig/2002-December/003115.html">http://mail.python.org/pipermail/c++-sig/2002-December/003115.html</a></p>
<p><a class="reference" href="http://aspn.activestate.com/ASPN/Mail/Message/1280898">http://aspn.activestate.com/ASPN/Mail/Message/1280898</a></p>
<p><a class="reference" href="http://mail.python.org/pipermail/c++-sig/2002-July/001755.html">http://mail.python.org/pipermail/c++-sig/2002-July/001755.html</a></p>
</blockquote>
<p>from c++ to python:</p>
<blockquote>
<p>It depends on the type and the call policies in use or, for
<tt class="literal"><span class="pre">call&lt;&gt;(...)</span></tt>, <tt class="literal"><span class="pre">call_method&lt;&gt;(...)</span></tt>, or <tt class="literal"><span class="pre">object(...)</span></tt>, if
<tt class="literal"><span class="pre">ref</span></tt> or <tt class="literal"><span class="pre">ptr</span></tt> is used. There are also two basic
categories to to-python conversion, &quot;return value&quot; conversion
(for Python-&gt;C++ calls) and &quot;argument&quot; conversion (for
C++-&gt;Python calls and explicit <tt class="literal"><span class="pre">object()</span></tt> conversions). The
behavior of these two categories differs subtly in various ways
whose details I forget at the moment. You can probably find
the answers in the above references, and certainly in the code.</p>
<p>The &quot;default&quot; case is by-value (copying) conversion, which uses
to_python_value as a to-python converter.</p>
<blockquote>
<p>Since there can sensibly be only one way to convert any type
to python (disregarding the idea of scoped registries for the
moment), it makes sense that to-python conversions can be
handled by specializing a template. If the type is one of
the types handled by a built-in conversion
(builtin_converters.hpp), the corresponding template
specialization of to_python_value gets used.</p>
<p>Otherwise, to_python_value uses the <tt class="literal"><span class="pre">m_to_python</span></tt>
function in the registration for the C++ type.</p>
</blockquote>
<p>Other conversions, like by-reference conversions, are only
available for wrapped classes, and are requested explicitly by
using <tt class="literal"><span class="pre">ref(...)</span></tt>, <tt class="literal"><span class="pre">ptr(...)</span></tt>, or by specifying different
CallPolicies for a call, which can cause a different to-python
converter to be used. These conversions are never registered
anywhere, though they do need to use the registration to find
the Python class corresponding to the C++ type being referred
to. They just build a new Python instance and stick the
appropriate Holder instance in it.</p>
</blockquote>
<p>from python to C++:</p>
<blockquote>
<p>Once again I think there is a distinction between &quot;return value&quot;
and &quot;argument&quot; conversions, and I forget exactly what that is.</p>
<p>What happens depends on whether an lvalue conversion is needed
(see <a class="reference" href="http://mail.python.org/pipermail/c++-sig/2002-May/001023.html">http://mail.python.org/pipermail/c++-sig/2002-May/001023.html</a>)
All lvalue conversions are also registered in a type's rvalue
conversion chain, since when an rvalue will do, an lvalue is
certainly good enough.</p>
<p>An lvalue conversion can be done in one step (just get me the
pointer to the object - it can be <tt class="literal"><span class="pre">NULL</span></tt> if no conversion is
possible) while an rvalue conversion requires two steps to
support wrapped function overloading and multiple converters for
a given C++ target type: first tell me if a conversion is
possible, then construct the converted object as a second step.</p>
</blockquote>
</blockquote>
</div>
</div>
<hr class="footer"/>
<div class="footer">
<a class="reference" href="internals.rst">View document source</a>.
Generated on: 2003-09-12 14:51 UTC.
Generated by <a class="reference" href="http://docutils.sourceforge.net/">Docutils</a> from <a class="reference" href="http://docutils.sourceforge.net/rst.html">reStructuredText</a> source.
</div>
</body>
</html>

181
doc/internals.rst Executable file
View File

@@ -0,0 +1,181 @@
===================================
Boost.Python_ Internals |(logo)|__
===================================
.. |(logo)| image:: ../../../c++boost.gif
:alt: Boost
__ ../../../index.htm
.. _`Boost.Python`: index.html
.. _license: ../../../LICENSE_1_0.txt
-------------------------------------------------------
A conversation between Brett Calcott and David Abrahams
-------------------------------------------------------
:copyright: Copyright David Abrahams and Brett Calcott 2003. See
accompanying license_ for terms of use.
In both of these cases, I'm quite capable of reading code - but the
thing I don't get from scanning the source is a sense of the
architecture, both structurally, and temporally (er, I mean in what
order things go on).
1) What happens when you do the following::
struct boring {};
...etc...
class_<boring>("boring")
;
There seems to be a fair bit going on.
- Python needs a new ClassType to be registered.
- We need to construct a new type that can hold our boring struct.
- Inward and outward converters need to be registered for the type.
Can you gesture in the general direction where these things are done?
I only have time for a "off-the-top-of-my-head" answer at the moment;
I suggest you step through the code with a debugger after reading this
to see how it works, fill in details, and make sure I didn't forget
anything.
A new (Python) subclass of Boost.Python.Instance (see
libs/python/src/object/class.cpp) is created by invoking
Boost.Python.class, the metatype::
>>> boring = Boost.Python.class(
... 'boring'
... , bases_tuple # in this case, just ()
... , {
... '__module__' : module_name
... , '__doc__' : doc_string # optional
... }
... )
A handle to this object is stuck in the m_class_object field
of the registration associated with ``typeid(boring)``. The
registry will keep that object alive forever, even if you
wipe out the 'boring' attribute of the extension module
(probably not a good thing).
Because you didn't specify ``class<boring, non_copyable,
...>``, a to-python converter for boring is registered which
copies its argument into a value_holder held by the the
Python boring object.
Because you didn't specify ``class<boring ...>(no_init)``,
an ``__init__`` function object is added to the class
dictionary which default-constructs a boring in a
value_holder (because you didn't specify some smart pointer
or derived wrapper class as a holder) held by the Python
boring object.
``register_class_from_python`` is used to register a
from-python converter for ``shared_ptr<boring>``.
``boost::shared_ptr``\ s are special among smart pointers
because their Deleter argument can be made to manage the
whole Python object, not just the C++ object it contains, no
matter how the C++ object is held.
If there were any ``bases<>``, we'd also be registering the
relationship between these base classes and boring in the
up/down cast graph (``inheritance.[hpp/cpp]``).
In earlier versions of the code, we'd be registering lvalue
from-python converters for the class here, but now
from-python conversion for wrapped classes is handled as a
special case, before consulting the registry, if the source
Python object's metaclass is the Boost.Python metaclass.
Hmm, that from-python converter probably ought to be handled
the way class converters are, with no explicit conversions
registered.
2) Can you give a brief overview of the data structures that are
present in the registry
The registry is simple: it's just a map from typeid ->
registration (see boost/python/converter/registrations.hpp).
``lvalue_chain`` and ``rvalue_chain`` are simple endogenous
linked lists.
If you want to know more, just ask.
If you want to know about the cast graph, ask me something specific in
a separate message.
and an overview of the process that happens as a type makes its
way from c++ to python and back again.
Big subject. I suggest some background reading: look for relevant
info in the LLNL progress reports and the messages they link to.
Also,
http://mail.python.org/pipermail/c++-sig/2002-May/001023.html
http://mail.python.org/pipermail/c++-sig/2002-December/003115.html
http://aspn.activestate.com/ASPN/Mail/Message/1280898
http://mail.python.org/pipermail/c++-sig/2002-July/001755.html
from c++ to python:
It depends on the type and the call policies in use or, for
``call<>(...)``, ``call_method<>(...)``, or ``object(...)``, if
``ref`` or ``ptr`` is used. There are also two basic
categories to to-python conversion, "return value" conversion
(for Python->C++ calls) and "argument" conversion (for
C++->Python calls and explicit ``object()`` conversions). The
behavior of these two categories differs subtly in various ways
whose details I forget at the moment. You can probably find
the answers in the above references, and certainly in the code.
The "default" case is by-value (copying) conversion, which uses
to_python_value as a to-python converter.
Since there can sensibly be only one way to convert any type
to python (disregarding the idea of scoped registries for the
moment), it makes sense that to-python conversions can be
handled by specializing a template. If the type is one of
the types handled by a built-in conversion
(builtin_converters.hpp), the corresponding template
specialization of to_python_value gets used.
Otherwise, to_python_value uses the ``m_to_python``
function in the registration for the C++ type.
Other conversions, like by-reference conversions, are only
available for wrapped classes, and are requested explicitly by
using ``ref(...)``, ``ptr(...)``, or by specifying different
CallPolicies for a call, which can cause a different to-python
converter to be used. These conversions are never registered
anywhere, though they do need to use the registration to find
the Python class corresponding to the C++ type being referred
to. They just build a new Python instance and stick the
appropriate Holder instance in it.
from python to C++:
Once again I think there is a distinction between "return value"
and "argument" conversions, and I forget exactly what that is.
What happens depends on whether an lvalue conversion is needed
(see http://mail.python.org/pipermail/c++-sig/2002-May/001023.html)
All lvalue conversions are also registered in a type's rvalue
conversion chain, since when an rvalue will do, an lvalue is
certainly good enough.
An lvalue conversion can be done in one step (just get me the
pointer to the object - it can be ``NULL`` if no conversion is
possible) while an rvalue conversion requires two steps to
support wrapped function overloading and multiple converters for
a given C++ target type: first tell me if a conversion is
possible, then construct the converted object as a second step.

View File

@@ -3,7 +3,7 @@
<html>
<head>
<meta name="generator" content=
"HTML Tidy for Windows (vers 1st August 2002), see www.w3.org">
"HTML Tidy for Cygwin (vers 1st April 2002), see www.w3.org">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link rel="stylesheet" type="text/css" href="boost.css">
@@ -29,30 +29,100 @@
<hr>
<dl class="page-index">
<dt>18 March, 2003
<dt>11 Sept 2003</dt>
<dd>
<ul>
<li>Changed the response to multiple to-python converters being
registered for the same type from a hard error into warning;
Boost.Python now reports the offending type in the message.</li>
<li>Added builtin <code>std::wstring</code> conversions</li>
<li>Added <code>std::out_of_range</code> =&gt; Python
<code>IndexError</code> exception conversion, thanks to <a href=
"mailto:RaoulGough-at-yahoo.co.uk">Raoul Gough</a></li>
</ul>
</dd>
<dt>9 Sept 2003</dt>
<dd>Added new <code><a href="v2/str.html#str-spec">str</a></code></dd>
<dt>constructors which take a range of characters, allowing strings
containing nul (<code>'\0'</code>) characters.</dt>
<dt>8 Sept 2003</dt>
<dd>Added the ability to create methods from function objects (with an
<code>operator()</code>); see the <a href=
"v2/make_function.html#make_function-spec">make_function</a> docs for
more info.</dd>
<dt>10 August 2003</dt>
<dd>Added the new <code>properties</code> unit tests contributed by <a
href="mailto:romany-at-actimize.com">Roman Yakovenko</a> and documented
<code>add_static_property</code> at his urging.</dd>
<dt>1 August 2003</dt>
<dd>
Added the new <code>arg</code> class contributed by <a href=
"mailto:nickm-at-sitius.com">Nikolay Mladenov</a> which supplies the
ability to wrap functions that can be called with ommitted arguments
in the middle:
<pre>
void f(int x = 0, double y = 3.14, std::string z = std::string("foo"));
BOOST_PYTHON_MODULE(test)
{
def("f", f
, (arg("x", 0), arg("y", 3.14), arg("z", "foo")));
}
</pre>
And in Python:
<pre>
&gt;&gt;&gt; import test
&gt;&gt;&gt; f(0, z = "bar")
&gt;&gt;&gt; f(z = "bar", y = 0.0)
</pre>
Thanks, Nikolay!
</dd>
<dt>22 July 2003</dt>
<dd>Killed the dreaded "bad argument type for builtin operation" error.
Argument errors now show the actual and expected argument types!</dd>
<dt>19 July 2003</dt>
<dd>Added the new <code><a href=
"v2/return_arg.html">return_arg</a></code> policy from <a href=
"mailto:nickm-at-sitius.com">Nikolay Mladenov</a>. Thanks,
Nikolay!</dd>
<dt>18 March, 2003</dt>
<dd><a href="mailto:Gottfried.Ganssauge-at-haufe.de">Gottfried
Ganßauge</a> has contributed <a
href="v2/opaque_pointer_converter.html">opaque pointer
support</a>.
<br>
<a href="nicodemus-at-globalite.com.br">Bruno da Silva de
Oliveira</a> has contributed the exciting <a
href="../pyste/index.html">Pyste</a> (&quot;Pie-steh&quot;)
package.
Gan&szlig;auge</a> has contributed <a href=
"v2/opaque_pointer_converter.html">opaque pointer support</a>.<br>
<a href="mailto:nicodemus-at-globalite.com.br">Bruno da Silva de Oliveira</a>
has contributed the exciting <a href="../pyste/index.html">Pyste</a>
("Pie-steh") package.</dd>
<dt>24 February 2003</dt>
<dd>Finished improved support
for <code>boost::shared_ptr</code>. Now any wrapped object of
C++ class <code>X</code> can be converted automatically
to <code>shared_ptr&lt;X&gt;</code>, regardless of how it was
wrapped. The <code>shared_ptr</code> will manage the lifetime
of the Python object which supplied the <code>X</code>, rather
than just the <code>X</code> object itself, and when such
a <code>shared_ptr</code> is converted back to Python, the
original Python object will be returned.</dd>
<dd>Finished improved support for <code>boost::shared_ptr</code>. Now
any wrapped object of C++ class <code>X</code> can be converted
automatically to <code>shared_ptr&lt;X&gt;</code>, regardless of how it
was wrapped. The <code>shared_ptr</code> will manage the lifetime of
the Python object which supplied the <code>X</code>, rather than just
the <code>X</code> object itself, and when such a
<code>shared_ptr</code> is converted back to Python, the original
Python object will be returned.</dd>
<dt>19 January 2003</dt>
<dd>Integrated <code>staticmethod</code> support from <a href=
@@ -110,7 +180,7 @@
<p>Revised
<!--webbot bot="Timestamp" S-Type="EDITED" S-Format="%d %B, %Y" startspan -->
18 March, 2003
11 September 2003
<!--webbot bot="Timestamp" endspan i-checksum="39359" -->
</p>

View File

@@ -38,28 +38,23 @@
page .</p>
<hr>
<h3>Enterprise Software</h3>
<h3>Data Analysis</h3>
<dl class="page-index">
<dt><b><a href="http://openwbem.sourceforge.net">OpenWBEM</a></b></dt>
<dt><b><a href=
"http://www.neuralynx.com/neuralab/index.htm">NeuraLab</a></b></dt>
<dd>
The OpenWBEM project is an effort to develop an open-source
implementation of Web Based Enterprise Management suitable for
commercial and non-commercial application
<p><a href="mailto:dnuffer@sco.com">Dan Nuffer</a> writes:</p>
<blockquote>
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
developing management solutions that use WBEM.
</blockquote>
</dd>
<dd>Neuralab is a data analysis environment specifically tailored for
neural data from <a href="http://www.neuralynx.com">Neuralynx</a>
acquisition systems. Neuralab combines presentation quality graphics, a
numerical analysis library, and the <a href=
"http://www.python.org">Python</a> scripting engine in a single
application. With Neuralab, Neuralynx users can perform common analysis
tasks with just a few mouse clicks. More advanced users can create
custom Python scripts, which can optionally be assigned to menus and
mouse clicks.</dd>
</dl>
<h3>Financial Analysis</h3>
<dl class="page-index">
<dt><b>TSLib</b> - <a href="http://www.fortressinv.com">Fortress
Investment Group LLC</a></dt>
@@ -87,25 +82,82 @@
</dd>
</dl>
<h3>Educational</h3>
<dl class="page-index">
<dt><a href="http://edu.kde.org/kig"><b>Kig</b></a></dt>
<dd>
<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 geometrical constructions. It is meant to be the most intuitive,
yet featureful application of its kind.</p>
<p>Versions after 0.6.x (will) support objects built by the user
himself in the Python language. The exporting of the relevant
internal API's were done using Boost.Python, which made the process
very easy.</p>
</dd>
</dl>
<h3>Enterprise Software</h3>
<dl class="page-index">
<dt><b><a href="http://openwbem.sourceforge.net">OpenWBEM</a></b></dt>
<dd>
The OpenWBEM project is an effort to develop an open-source
implementation of Web Based Enterprise Management suitable for
commercial and non-commercial application
<p><a href="mailto:dnuffer@sco.com">Dan Nuffer</a> writes:</p>
<blockquote>
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
developing management solutions that use WBEM.
</blockquote>
</dd>
<dt><b><a href="http://www.transversal.com">Metafaq</a></b></dt>
<dd>
Metafaq, from <a href="http://www.transversal.com">Transversal,
Inc.</a>, is an enterprise level online knowledge base management
system.
<p><a href="mailto:ben.young-at-transversal.com">Ben Young</a>
writes:</p>
<blockquote>
Boost.Python is used in an automated process to generate python
bindings to our api which is exposed though multiple backends and
frontends. This allows us to write quick tests and bespoke scripts
to perform one off tasks without having to go through the full
compilation cycle.
</blockquote>
</dd>
</dl>
<h3>Graphics</h3>
<dl class="page-index">
<dt><b><a href=
"http://sourceforge.net/projects/pyosg">OpenSceneGraph Bindings</a></b></dt>
<dt><b><a href="http://sourceforge.net/projects/pyosg">OpenSceneGraph
Bindings</a></b></dt>
<dd><a href="mailto:gideon@computer.org">Gideon May</a> has
created a set of bindings for <a
href="http://www.openscenegraph.org">OpenSceneGraph</a>, a
cross-platform C++/OpenGL library for the real-time
visualization.<br>
<dd><a href="mailto:gideon@computer.org">Gideon May</a> has created a
set of bindings for <a href=
"http://www.openscenegraph.org">OpenSceneGraph</a>, a cross-platform
C++/OpenGL library for the real-time visualization.<br>
&nbsp;</dd>
<dt><a href=
"http://www.procoders.net/pythonmagick"><b>PythonMagick</b></a></dt>
<dd>PythonMagick binds the <a href=
"http://www.graphicsmagick.org">GraphicsMagick</a> image
manipulation library to Python.<br> &nbsp;</dd>
"http://www.graphicsmagick.org">GraphicsMagick</a> image manipulation
library to Python.<br>
&nbsp;</dd>
<dt><b><a href=
"http://www.slac.stanford.edu/grp/ek/hippodraw/index.html">HippoDraw</a></b></dt>
@@ -118,9 +170,8 @@
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 <a
@@ -206,14 +257,85 @@
Boost.Python plays and essential role.</p>
</blockquote>
</dd>
<dt><b><a href="http://www.esss.com.br">ESSS</a></b></dt>
<dd>
ESSS (Engineering Simulation and Scientific Software) is a company
that provides engineering solutions and acts in the brazilian and
south-american market providing products and services related to
Computational Fluid Dynamics and Image Analysis.
<p><a href="mailto:bruno@esss.com.br">Bruno da Silva de Oliveira</a>
writes:</p>
<blockquote>
Recently we moved our work from working exclusively with C++ to an
hybrid-language approach, using Python and C++, with Boost.Python
providing the layer between the two. The results are great so far!
</blockquote>
<p>Two projects have been developed so far with this technology:</p>
<p><b><a href="http://www.esss.com.br/dev_simba.phtml">Simba</a></b>
provides 3D visualization of geological formations gattered from the
simulation of the evolution of oil systems, allowing the user to
analyse various aspects of the simulation, like deformation, pressure
and fluids, along the time of the simulation.</p>
<p><b><a href="http://www.esss.com.br/dev_aero.phtml">Aero</a></b>
aims to construct a CFD with brazilian technology, which involves
various companies and universities. ESSS is responsible for various
of the application modules, including GUI and post-processing of
results.</p>
</dd>
<dt><b><a href="http://www.rationaldiscovery.com">Rational Discovery
LLC</a></b></dt>
<dd>
Rational Discovery provides computational modeling, combinatorial
library design and custom software development services to the
pharmaceutical, biotech and chemical industries. We do a substantial
amount of internal research to develop new approaches for applying
machine-learning techniques to solve chemical problems. Because we're
a small organization and chemistry is a large and complex field, it
is essential that we be able to quickly and easily prototype and test
new algorithms.
<p>For our internal software, we implement core data structures in C
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). This hybrid development approach not only greatly increases our
productivity, but it also allows "non-developers" (people without C
experience) to take part in method development. Learning C is a
daunting task, but "Python fits your brain." (Thanks to Bruce Eckel
for the quote.)</p>
</dd>
</dl>
<h3>Tools</h3>
<dl>
<dt><a href="http://www.jayacard.org"><b>Jayacard</b></a></dt>
<dd>
Jayacard aims at developing a secure portable open source operating
system for contactless smart cards and a complete suite of high
quality development tools to ease smart card OS and application
development.
<p>The core of the smart card reader management is written in C++ but
all the development tools are written in the friendly Python
language. Boost plays the fundamental role of binding the tools to
our core smart card reader library.</p>
</dd>
</dl>
<hr>
<p>Revised
<!--webbot bot="Timestamp" S-Type="EDITED" S-Format="%d %B, %Y" startspan -->
29 May, 2003
<!--webbot bot="Timestamp" endspan i-checksum="39359" -->
</p>
15 July, 2003</p>
<p><i>&copy; Copyright <a href="../../../people/dave_abrahams.htm">Dave
Abrahams</a> 2002-2003. All Rights Reserved.</i></p>

View File

@@ -3,7 +3,7 @@
<html>
<head>
<meta name="generator" content=
"HTML Tidy for Windows (vers 1st August 2002), see www.w3.org">
"HTML Tidy for Cygwin (vers 1st April 2002), see www.w3.org">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link rel="stylesheet" type="text/css" href="boost.css">
@@ -31,7 +31,9 @@
<h2>Synopsis</h2>
<p>This is a list of available resources for support with Boost.Python
problems and feature requests.</p>
problems and feature requests. <b>Please try to resist emailing the
Boost.Python developers directly for support.</b> Use the following
resources instead; the developers are listening!</p>
<hr>
<dl class="page-index">
@@ -41,9 +43,11 @@
you Boost.Python.<br>
&nbsp;</dt>
<dt><b><a href="http://www.python.org/sigs/c++-sig/">The Python
<dt><b><a href=
"http://www.boost.org/more/mailing_lists.htm#cplussig">The Python
C++-sig</a></b> mailing list is a forum for discussing Python/C++
interoperability, and Boost.Python in particular.<br>
interoperability, and Boost.Python in particular. Post your
Boost.Python questions here.<br>
&nbsp;</dt>
<dt>The <b>Boost.Python <a href=
@@ -51,18 +55,17 @@
Pages</a></b> established by Mike Rovner as part of the <a href=
"http://www.python.org/cgi-bin/moinmoin">PythonInfo Wiki</a> serves as
a forum to gather peoples' experience and as a cookbook.<br>
&nbsp;</dt>
&nbsp;</dt>
</dl>
<hr>
<p>Revised
<!--webbot bot="Timestamp" S-Type="EDITED" S-Format="%d %B, %Y" startspan -->
17 November, 2002
<!--webbot bot="Timestamp" endspan i-checksum="39359" -->
12 Sept, 2003 <!--webbot bot="Timestamp" endspan i-checksum="39359" -->
</p>
<p><i>&copy; Copyright <a href="../../../people/dave_abrahams.htm">Dave
Abrahams</a> 2002. All Rights Reserved.</i></p>
Abrahams</a> 2003.</i></p>
</body>
</html>

View File

@@ -26,7 +26,7 @@
</table>
<p>
It was mentioned in passing in the previous section that
<tt>BOOST_PYTHON_FUNCTION_OVERLOADS</tt> and <tt>BOOST_PYTHON_FUNCTION_OVERLOADS</tt>
<tt>BOOST_PYTHON_FUNCTION_OVERLOADS</tt> and <tt>BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS</tt>
can also be used for overloaded functions and member functions with a
common sequence of initial arguments. Here is an example:</p>
<code><pre>

View File

@@ -37,6 +37,11 @@ with every boost distribution: <b>bjam</b>.</p>
Besides bjam, there are of course other ways to get your module built.
What's written here should not be taken as &quot;the one and only way&quot;.
There are of course other build tools apart from <tt>bjam</tt>.
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 shows
that 90% of the &quot;I can't build Boost.Python&quot; problems come from people
who had to use a different tool.
</td>
</tr>
</table>

View File

@@ -0,0 +1,210 @@
<html>
<head>
<!-- Generated by the Spirit (http://spirit.sf.net) QuickDoc -->
<title>Creating Packages</title>
<link rel="stylesheet" href="theme/style.css" type="text/css">
<link rel="prev" href="general_techniques.html">
<link rel="next" href="extending_wrapped_objects_in_python.html">
</head>
<body>
<table width="100%" height="48" border="0" cellspacing="2">
<tr>
<td><img src="theme/c%2B%2Bboost.gif">
</td>
<td width="85%">
<font size="6" face="Verdana, Arial, Helvetica, sans-serif"><b>Creating Packages</b></font>
</td>
</tr>
</table>
<br>
<table border="0">
<tr>
<td width="30"><a href="../index.html"><img src="theme/u_arr.gif" border="0"></a></td>
<td width="30"><a href="general_techniques.html"><img src="theme/l_arr.gif" border="0"></a></td>
<td width="20"><a href="extending_wrapped_objects_in_python.html"><img src="theme/r_arr.gif" border="0"></a></td>
</tr>
</table>
<p>
A Python package is a collection of modules that provide to the user a certain
functionality. If you're not familiar on how to create packages, a good
introduction to them is provided in the
<a href="http://www.python.org/doc/current/tut/node8.html">
Python Tutorial</a>.</p>
<p>
But we are wrapping C++ code, using Boost.Python. How can we provide a nice
package interface to our users? To better explain some concepts, let's work
with an example.</p>
<p>
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)
<tt>sounds</tt>. Our library already has a neat C++ namespace hierarchy, like so: </p>
<code><pre>
<span class=identifier>sounds</span><span class=special>::</span><span class=identifier>core
</span><span class=identifier>sounds</span><span class=special>::</span><span class=identifier>io
</span><span class=identifier>sounds</span><span class=special>::</span><span class=identifier>filters
</span></pre></code>
<p>
We would like to present this same hierarchy to the Python user, allowing him
to write code like this:</p>
<code><pre>
<span class=identifier>import </span><span class=identifier>sounds</span><span class=special>.</span><span class=identifier>filters
</span><span class=identifier>sounds</span><span class=special>.</span><span class=identifier>filters</span><span class=special>.</span><span class=identifier>echo</span><span class=special>(...) </span>##<span class=identifier>echo </span><span class=identifier>is </span><span class=identifier>a </span><span class=identifier>C</span><span class=special>++ </span><span class=identifier>function
</span></pre></code>
<p>
The first step is to write the wrapping code. We have to export each module
separately with Boost.Python, like this:</p>
<code><pre>
<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=keyword>export </span><span class=identifier>everything </span><span class=identifier>in </span><span class=identifier>the </span><span class=identifier>sounds</span><span class=special>::</span><span class=identifier>core </span><span class=keyword>namespace </span><span class=special>*/
...
}
/* </span><span class=identifier>file </span><span class=identifier>io</span><span class=special>.</span><span class=identifier>cpp </span><span class=special>*/
</span><span class=identifier>BOOST_PYTHON_MODULE</span><span class=special>(</span><span class=identifier>io</span><span class=special>)
{
/* </span><span class=keyword>export </span><span class=identifier>everything </span><span class=identifier>in </span><span class=identifier>the </span><span class=identifier>sounds</span><span class=special>::</span><span class=identifier>io </span><span class=keyword>namespace </span><span class=special>*/
...
}
/* </span><span class=identifier>file </span><span class=identifier>filters</span><span class=special>.</span><span class=identifier>cpp </span><span class=special>*/
</span><span class=identifier>BOOST_PYTHON_MODULE</span><span class=special>(</span><span class=identifier>filters</span><span class=special>)
{
/* </span><span class=keyword>export </span><span class=identifier>everything </span><span class=identifier>in </span><span class=identifier>the </span><span class=identifier>sounds</span><span class=special>::</span><span class=identifier>filters </span><span class=keyword>namespace </span><span class=special>*/
...
}
</span></pre></code>
<p>
Compiling these files will generate the following Python extensions:
<tt>core.pyd</tt>, <tt>io.pyd</tt> and <tt>filters.pyd</tt>.</p>
<table width="80%" border="0" align="center">
<tr>
<td class="note_box">
<img src="theme/note.gif"></img> The extension <tt>.pyd</tt> is used for python extension modules, which
are just shared libraries. Using the default for your system, like <tt>.so</tt> for
Unix and <tt>.dll</tt> for Windows, works just as well. </td>
</tr>
</table>
<p>
Now, we create this directory structure for our Python package:</p>
<code><pre>
sounds/
__init__.py
core.pyd
filters.pyd
io.pyd
</pre></code><p>
The file <tt>__init__.py</tt> is what tells Python that the directory <tt>sounds/</tt> is
actually a Python package. It can be a empty file, but can also perform some
magic, that will be shown later. </p>
<p>
Now our package is ready. All the user has to do is put <tt>sounds</tt> into his
<a href="http://www.python.org/doc/current/tut/node8.html#SECTION008110000000000000000">
PYTHONPATH</a> and fire up the interpreter:</p>
<code><pre>
<span class=special>&gt;&gt;&gt; </span><span class=identifier>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=identifier>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=identifier>sound </span><span class=special>= </span><span class=identifier>sounds</span><span class=special>.</span><span class=identifier>io</span><span class=special>.</span><span class=identifier>open</span><span class=special>(</span><span class=literal>'file.mp3'</span><span class=special>)
&gt;&gt;&gt; </span><span class=identifier>new_sound </span><span class=special>= </span><span class=identifier>sounds</span><span class=special>.</span><span class=identifier>filters</span><span class=special>.</span><span class=identifier>echo</span><span class=special>(</span><span class=identifier>sound</span><span class=special>, </span><span class=number>1.0</span><span class=special>)
</span></pre></code>
<p>
Nice heh? </p>
<p>
This is the simplest way to create hierarchies of packages, but it is not very
flexible. What if we want to add a <i>pure</i> Python function to the filters
package, for instance, one that applies 3 filters in a sound object at once?
Sure, you can do this in C++ and export it, but why not do so in Python? You
don't have to recompile the extension modules, plus it will be easier to write
it.</p>
<p>
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:</p>
<code><pre>
<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=keyword>export </span><span class=identifier>everything </span><span class=identifier>in </span><span class=identifier>the </span><span class=identifier>sounds</span><span class=special>::</span><span class=identifier>core </span><span class=keyword>namespace </span><span class=special>*/
}
</span></pre></code>
<p>
Note that we added an underscore to the module name. The filename will have to
be changed to <tt>_core.pyd</tt> as well, and we do the same to the other extension modules.
Now, we change our package hierarchy like so:</p>
<code><pre>
sounds/
__init__.py
core/
__init__.py
_core.pyd
filters/
__init__.py
_filters.pyd
io/
__init__.py
_io.pyd
</pre></code><p>
Note that we created a directory for each extension module, and added a
__init__.py 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: </p>
<code><pre>
<span class=special>&gt;&gt;&gt; </span><span class=identifier>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></pre></code>
<p>
which is not what we want. But here enters the <tt>__init__.py</tt> magic: everything
that is brought to the <tt>__init__.py</tt> namespace can be accessed directly by the
user. So, all we have to do is bring the entire namespace from <tt>_core.pyd</tt>
to <tt>core/__init__.py</tt>. So add this line of code to <tt>sounds/core/__init__.py</tt>:</p>
<code><pre>
<span class=identifier>from </span><span class=identifier>_core </span><span class=identifier>import </span><span class=special>*
</span></pre></code>
<p>
We do the same for the other packages. Now the user accesses the functions and
classes in the extension modules like before:</p>
<code><pre>
<span class=special>&gt;&gt;&gt; </span><span class=identifier>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=identifier>sounds</span><span class=special>.</span><span class=identifier>filters</span><span class=special>.</span><span class=identifier>echo</span><span class=special>(...)
</span></pre></code>
<p>
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 C++
function and a Python function. Let's add a <i>pure</i> Python function,
<tt>echo_noise</tt>, to the <tt>filters</tt> package. This function applies both the
<tt>echo</tt> and <tt>noise</tt> filters in sequence in the given <tt>sound</tt> object. We
create a file named <tt>sounds/filters/echo_noise.py</tt> and code our function:</p>
<code><pre>
<span class=identifier>import </span><span class=identifier>_filters
</span><span class=identifier>def </span><span class=identifier>echo_noise</span><span class=special>(</span><span class=identifier>sound</span><span class=special>):
</span><span class=identifier>s </span><span class=special>= </span><span class=identifier>_filters</span><span class=special>.</span><span class=identifier>echo</span><span class=special>(</span><span class=identifier>sound</span><span class=special>)
</span><span class=identifier>s </span><span class=special>= </span><span class=identifier>_filters</span><span class=special>.</span><span class=identifier>noise</span><span class=special>(</span><span class=identifier>sound</span><span class=special>)
</span><span class=keyword>return </span><span class=identifier>s
</span></pre></code>
<p>
Next, we add this line to <tt>sounds/filters/__init__.py</tt>:</p>
<code><pre>
<span class=identifier>from </span><span class=identifier>echo_noise </span><span class=identifier>import </span><span class=identifier>echo_noise
</span></pre></code>
<p>
And that's it. The user now accesses this function like any other function
from the <tt>filters</tt> package:</p>
<code><pre>
<span class=special>&gt;&gt;&gt; </span><span class=identifier>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=identifier>sounds</span><span class=special>.</span><span class=identifier>filters</span><span class=special>.</span><span class=identifier>echo_noise</span><span class=special>(...)
</span></pre></code>
<table border="0">
<tr>
<td width="30"><a href="../index.html"><img src="theme/u_arr.gif" border="0"></a></td>
<td width="30"><a href="general_techniques.html"><img src="theme/l_arr.gif" border="0"></a></td>
<td width="20"><a href="extending_wrapped_objects_in_python.html"><img src="theme/r_arr.gif" border="0"></a></td>
</tr>
</table>
<br>
<hr size="1"><p class="copyright">Copyright &copy; 2002-2003 David Abrahams<br>Copyright &copy; 2002-2003 Joel de Guzman<br><br>
<font size="2">Permission to copy, use, modify, sell and distribute this document
is granted provided this copyright notice appears in all copies. This document
is provided &quot;as is&quot; without express or implied warranty, and with
no claim as to its suitability for any purpose. </font> </p>
</body>
</html>

View File

@@ -93,7 +93,7 @@ arguments or overloads with a common sequence of initial arguments come
into play. Another macro is provided to make this a breeze.</p>
<p>
Like <tt>BOOST_PYTHON_FUNCTION_OVERLOADS</tt>,
<tt>BOOST_PYTHON_FUNCTION_OVERLOADS</tt> may be used to automatically create
<tt>BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS</tt> may be used to automatically create
the thin wrappers for wrapping member functions. Let's have an example:</p>
<code><pre>
<span class=keyword>struct </span><span class=identifier>george

View File

@@ -44,10 +44,9 @@ both Boost.Python's and Python's static link library.</p>
Boost.Python's static link library comes in two variants. Both are located
in Boost's <tt>/libs/python/build/bin-stage</tt> subdirectory. On Windows, the
variants are called <tt>boost_python.lib</tt> (for release builds) and
<tt>boost_python_debug.lib</tt> (for debugging). If you can't find the
libraries, you probably haven't built Boost.Python yet. See <a
href="../../building.html">Building and Testing</a> on how to do
this.</p>
<tt>boost_python_debug.lib</tt> (for debugging). If you can't find the libraries,
you probably haven't built Boost.Python yet. See <a href="../../building.html">
Building and Testing</a> on how to do this.</p>
<p>
Python's static link library can be found in the <tt>/libs</tt> subdirectory of
your Python directory. On Windows it is called pythonXY.lib where X.Y is
@@ -88,7 +87,7 @@ Py_Finalize</a>() to stop the interpreter and release its resources.</li></ol><p
</tr>
</table>
<br>
<hr size="1"><p class="copyright">Copyright &copy; 2002-2003 Dirk Gerrits<br><br>
<hr size="1"><p class="copyright">Copyright &copy; 2002-2003 David Abrahams<br>Copyright &copy; 2002-2003 Joel de Guzman<br><br>
<font size="2">Permission to copy, use, modify, sell and distribute this document
is granted provided this copyright notice appears in all copies. This document
is provided &quot;as is&quot; without express or implied warranty, and with

View File

@@ -4,6 +4,7 @@
<title>Exception Translation</title>
<link rel="stylesheet" href="theme/style.css" type="text/css">
<link rel="prev" href="iterators.html">
<link rel="next" href="general_techniques.html">
</head>
<body>
<table width="100%" height="48" border="0" cellspacing="2">
@@ -20,7 +21,7 @@
<tr>
<td width="30"><a href="../index.html"><img src="theme/u_arr.gif" border="0"></a></td>
<td width="30"><a href="iterators.html"><img src="theme/l_arr.gif" border="0"></a></td>
<td width="20"><img src="theme/r_arr_disabled.gif" border="0"></td>
<td width="20"><a href="general_techniques.html"><img src="theme/r_arr.gif" border="0"></a></td>
</tr>
</table>
<p>
@@ -47,7 +48,7 @@ Users may provide custom translation. Here's an example:</p>
<tr>
<td width="30"><a href="../index.html"><img src="theme/u_arr.gif" border="0"></a></td>
<td width="30"><a href="iterators.html"><img src="theme/l_arr.gif" border="0"></a></td>
<td width="20"><img src="theme/r_arr_disabled.gif" border="0"></td>
<td width="20"><a href="general_techniques.html"><img src="theme/r_arr.gif" border="0"></a></td>
</tr>
</table>
<br>

View File

@@ -0,0 +1,134 @@
<html>
<head>
<!-- Generated by the Spirit (http://spirit.sf.net) QuickDoc -->
<title>Extending Wrapped Objects in Python</title>
<link rel="stylesheet" href="theme/style.css" type="text/css">
<link rel="prev" href="creating_packages.html">
<link rel="next" href="reducing_compiling_time.html">
</head>
<body>
<table width="100%" height="48" border="0" cellspacing="2">
<tr>
<td><img src="theme/c%2B%2Bboost.gif">
</td>
<td width="85%">
<font size="6" face="Verdana, Arial, Helvetica, sans-serif"><b>Extending Wrapped Objects in Python</b></font>
</td>
</tr>
</table>
<br>
<table border="0">
<tr>
<td width="30"><a href="../index.html"><img src="theme/u_arr.gif" border="0"></a></td>
<td width="30"><a href="creating_packages.html"><img src="theme/l_arr.gif" border="0"></a></td>
<td width="20"><a href="reducing_compiling_time.html"><img src="theme/r_arr.gif" border="0"></a></td>
</tr>
</table>
<p>
Thanks to Python's flexibility, you can easily add new methods to a class,
even after it was already created:</p>
<code><pre>
<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=identifier>pass
</span><span class=special>&gt;&gt;&gt;
&gt;&gt;&gt; </span>##<span class=identifier>a </span><span class=identifier>regular </span><span class=identifier>function
</span><span class=special>&gt;&gt;&gt; </span><span class=identifier>def </span><span class=identifier>C_str</span><span class=special>(</span><span class=identifier>self</span><span class=special>): </span><span class=keyword>return </span><span class=literal>'A C instance!'
</span><span class=special>&gt;&gt;&gt;
&gt;&gt;&gt; </span>##<span class=identifier>now </span><span class=identifier>we </span><span class=identifier>turn </span><span class=identifier>it </span><span class=identifier>in </span><span class=identifier>a </span><span class=identifier>member </span><span class=identifier>function
</span><span class=special>&gt;&gt;&gt; </span><span class=identifier>C</span><span class=special>.</span><span class=identifier>__str__ </span><span class=special>= </span><span class=identifier>C_str
</span><span class=special>&gt;&gt;&gt;
&gt;&gt;&gt; </span><span class=identifier>c </span><span class=special>= </span><span class=identifier>C</span><span class=special>()
&gt;&gt;&gt; </span><span class=identifier>print </span><span class=identifier>c
</span><span class=identifier>A </span><span class=identifier>C </span><span class=identifier>instance</span><span class=special>!
&gt;&gt;&gt; </span><span class=identifier>C_str</span><span class=special>(</span><span class=identifier>c</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></code>
<p>
Yes, Python rox. <img src="theme/smiley.gif"></img></p>
<p>
We can do the same with classes that were wrapped with Boost.Python. Suppose
we have a class <tt>point</tt> in C++:</p>
<code><pre>
<span class=keyword>class </span><span class=identifier>point </span><span class=special>{...};
</span><span class=identifier>BOOST_PYTHON_MODULE</span><span class=special>(</span><span class=identifier>_geom</span><span class=special>)
{
</span><span class=identifier>class_</span><span class=special>&lt;</span><span class=identifier>point</span><span class=special>&gt;(</span><span class=string>&quot;point&quot;</span><span class=special>)...;
}
</span></pre></code>
<p>
If we are using the technique from the previous session, <a href="creating_packages.html">
Creating Packages</a>, we can code directly into <tt>geom/__init__.py</tt>:</p>
<code><pre>
<span class=identifier>from </span><span class=identifier>_geom </span><span class=identifier>import </span><span class=special>*
</span>##<span class=identifier>a </span><span class=identifier>regular </span><span class=identifier>function
</span><span class=identifier>def </span><span class=identifier>point_str</span><span class=special>(</span><span class=identifier>self</span><span class=special>):
</span><span class=keyword>return </span><span class=identifier>str</span><span class=special>((</span><span class=identifier>self</span><span class=special>.</span><span class=identifier>x</span><span class=special>, </span><span class=identifier>self</span><span class=special>.</span><span class=identifier>y</span><span class=special>))
</span>##<span class=identifier>now </span><span class=identifier>we </span><span class=identifier>turn </span><span class=identifier>it </span><span class=identifier>into </span><span class=identifier>a </span><span class=identifier>member </span><span class=identifier>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></pre></code>
<p>
<b>All</b> point instances created from C++ will also have this member function!
This technique has several advantages:</p>
<ul><li>Cut down compile times to zero for these additional functions</li><li>Reduce the memory footprint to virtually zero</li><li>Minimize the need to recompile</li><li>Rapid prototyping (you can move the code to C++ if required without changing the interface)</li></ul><p>
You can even add a little syntactic sugar with the use of metaclasses. Let's
create a special metaclass that &quot;injects&quot; methods in other classes.</p>
<code><pre>
##<span class=identifier>The </span><span class=identifier>one </span><span class=identifier>Boost</span><span class=special>.</span><span class=identifier>Python </span><span class=identifier>uses </span><span class=keyword>for </span><span class=identifier>all </span><span class=identifier>wrapped </span><span class=identifier>classes</span><span class=special>.
</span>##<span class=identifier>You </span><span class=identifier>can </span><span class=identifier>use </span><span class=identifier>here </span><span class=identifier>any </span><span class=keyword>class </span><span class=identifier>exported </span><span class=identifier>by </span><span class=identifier>Boost </span><span class=identifier>instead </span><span class=identifier>of </span><span class=string>&quot;point&quot;
</span><span class=identifier>BoostPythonMetaclass </span><span class=special>= </span><span class=identifier>point</span><span class=special>.</span><span class=identifier>__class__
</span><span class=keyword>class </span><span class=identifier>injector</span><span class=special>(</span><span class=identifier>object</span><span class=special>):
</span><span class=keyword>class </span><span class=identifier>__metaclass__</span><span class=special>(</span><span class=identifier>BoostPythonMetaclass</span><span class=special>):
</span><span class=identifier>def </span><span class=identifier>__init__</span><span class=special>(</span><span class=identifier>self</span><span class=special>, </span><span class=identifier>name</span><span class=special>, </span><span class=identifier>bases</span><span class=special>, </span><span class=identifier>dict</span><span class=special>):
</span><span class=keyword>for </span><span class=identifier>b </span><span class=identifier>in </span><span class=identifier>bases</span><span class=special>:
</span><span class=keyword>if </span><span class=identifier>type</span><span class=special>(</span><span class=identifier>b</span><span class=special>) </span><span class=keyword>not </span><span class=identifier>in </span><span class=special>(</span><span class=identifier>self</span><span class=special>, </span><span class=identifier>type</span><span class=special>):
</span><span class=keyword>for </span><span class=identifier>k</span><span class=special>,</span><span class=identifier>v </span><span class=identifier>in </span><span class=identifier>dict</span><span class=special>.</span><span class=identifier>items</span><span class=special>():
</span><span class=identifier>setattr</span><span class=special>(</span><span class=identifier>b</span><span class=special>,</span><span class=identifier>k</span><span class=special>,</span><span class=identifier>v</span><span class=special>)
</span><span class=keyword>return </span><span class=identifier>type</span><span class=special>.</span><span class=identifier>__init__</span><span class=special>(</span><span class=identifier>self</span><span class=special>, </span><span class=identifier>name</span><span class=special>, </span><span class=identifier>bases</span><span class=special>, </span><span class=identifier>dict</span><span class=special>)
</span>##<span class=identifier>inject </span><span class=identifier>some </span><span class=identifier>methods </span><span class=identifier>in </span><span class=identifier>the </span><span class=identifier>point </span><span class=identifier>foo
</span><span class=keyword>class </span><span class=identifier>more_point</span><span class=special>(</span><span class=identifier>injector</span><span class=special>, </span><span class=identifier>point</span><span class=special>):
</span><span class=identifier>def </span><span class=identifier>__repr__</span><span class=special>(</span><span class=identifier>self</span><span class=special>):
</span><span class=keyword>return </span><span class=literal>'Point(x=%s, y=%s)' </span><span class=special>% (</span><span class=identifier>self</span><span class=special>.</span><span class=identifier>x</span><span class=special>, </span><span class=identifier>self</span><span class=special>.</span><span class=identifier>y</span><span class=special>)
</span><span class=identifier>def </span><span class=identifier>foo</span><span class=special>(</span><span class=identifier>self</span><span class=special>):
</span><span class=identifier>print </span><span class=literal>'foo!'
</span></pre></code>
<p>
Now let's see how it got:</p>
<code><pre>
<span class=special>&gt;&gt;&gt; </span><span class=identifier>print </span><span class=identifier>point</span><span class=special>()
</span><span class=identifier>Point</span><span class=special>(</span><span class=identifier>x</span><span class=special>=</span><span class=number>10</span><span class=special>, </span><span class=identifier>y</span><span class=special>=</span><span class=number>10</span><span class=special>)
&gt;&gt;&gt; </span><span class=identifier>point</span><span class=special>().</span><span class=identifier>foo</span><span class=special>()
</span><span class=identifier>foo</span><span class=special>!
</span></pre></code>
<p>
Another useful idea is to replace constructors with factory functions:</p>
<code><pre>
<span class=identifier>_point </span><span class=special>= </span><span class=identifier>point
</span><span class=identifier>def </span><span class=identifier>point</span><span class=special>(</span><span class=identifier>x</span><span class=special>=</span><span class=number>0</span><span class=special>, </span><span class=identifier>y</span><span class=special>=</span><span class=number>0</span><span class=special>):
</span><span class=keyword>return </span><span class=identifier>_point</span><span class=special>(</span><span class=identifier>x</span><span class=special>, </span><span class=identifier>y</span><span class=special>)
</span></pre></code>
<p>
In this simple case there is not much gained, but for constructurs with
many overloads and/or arguments this is often a great simplification, again
with virtually zero memory footprint and zero compile-time overhead for
the keyword support.</p>
<table border="0">
<tr>
<td width="30"><a href="../index.html"><img src="theme/u_arr.gif" border="0"></a></td>
<td width="30"><a href="creating_packages.html"><img src="theme/l_arr.gif" border="0"></a></td>
<td width="20"><a href="reducing_compiling_time.html"><img src="theme/r_arr.gif" border="0"></a></td>
</tr>
</table>
<br>
<hr size="1"><p class="copyright">Copyright &copy; 2002-2003 David Abrahams<br>Copyright &copy; 2002-2003 Joel de Guzman<br><br>
<font size="2">Permission to copy, use, modify, sell and distribute this document
is granted provided this copyright notice appears in all copies. This document
is provided &quot;as is&quot; without express or implied warranty, and with
no claim as to its suitability for any purpose. </font> </p>
</body>
</html>

View File

@@ -0,0 +1,43 @@
<html>
<head>
<!-- Generated by the Spirit (http://spirit.sf.net) QuickDoc -->
<title>General Techniques</title>
<link rel="stylesheet" href="theme/style.css" type="text/css">
<link rel="prev" href="exception_translation.html">
<link rel="next" href="creating_packages.html">
</head>
<body>
<table width="100%" height="48" border="0" cellspacing="2">
<tr>
<td><img src="theme/c%2B%2Bboost.gif">
</td>
<td width="85%">
<font size="6" face="Verdana, Arial, Helvetica, sans-serif"><b>General Techniques</b></font>
</td>
</tr>
</table>
<br>
<table border="0">
<tr>
<td width="30"><a href="../index.html"><img src="theme/u_arr.gif" border="0"></a></td>
<td width="30"><a href="exception_translation.html"><img src="theme/l_arr.gif" border="0"></a></td>
<td width="20"><a href="creating_packages.html"><img src="theme/r_arr.gif" border="0"></a></td>
</tr>
</table>
<p>
Here are presented some useful techniques that you can use while wrapping code with Boost.Python.</p>
<table border="0">
<tr>
<td width="30"><a href="../index.html"><img src="theme/u_arr.gif" border="0"></a></td>
<td width="30"><a href="exception_translation.html"><img src="theme/l_arr.gif" border="0"></a></td>
<td width="20"><a href="creating_packages.html"><img src="theme/r_arr.gif" border="0"></a></td>
</tr>
</table>
<br>
<hr size="1"><p class="copyright">Copyright &copy; 2002-2003 David Abrahams<br>Copyright &copy; 2002-2003 Joel de Guzman<br><br>
<font size="2">Permission to copy, use, modify, sell and distribute this document
is granted provided this copyright notice appears in all copies. This document
is provided &quot;as is&quot; without express or implied warranty, and with
no claim as to its suitability for any purpose. </font> </p>
</body>
</html>

View File

@@ -62,6 +62,11 @@ with every boost distribution: [*bjam].
Besides bjam, there are of course other ways to get your module built.
What's written here should not be taken as "the one and only way".
There are of course other build tools apart from [^bjam].
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 shows
that 90% of the "I can't build Boost.Python" problems come from people
who had to use a different tool.
]
We shall skip over the details. Our objective will be to simply create the
@@ -1005,7 +1010,7 @@ arguments or overloads with a common sequence of initial arguments come
into play. Another macro is provided to make this a breeze.
Like [^BOOST_PYTHON_FUNCTION_OVERLOADS],
[^BOOST_PYTHON_FUNCTION_OVERLOADS] may be used to automatically create
[^BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS] may be used to automatically create
the thin wrappers for wrapping member functions. Let's have an example:
struct george
@@ -1053,7 +1058,7 @@ Notice the use of [^init<...>] and [^optional<...>] to signify the default
[page:1 Auto-Overloading]
It was mentioned in passing in the previous section that
[^BOOST_PYTHON_FUNCTION_OVERLOADS] and [^BOOST_PYTHON_FUNCTION_OVERLOADS]
[^BOOST_PYTHON_FUNCTION_OVERLOADS] and [^BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS]
can also be used for overloaded functions and member functions with a
common sequence of initial arguments. Here is an example:
@@ -1693,7 +1698,7 @@ with an example.
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)
[^sounds]. Our library already has a neat C++ namespace hierarchy, like so:
[^sounds]. Our library already has a neat C++ namespace hierarchy, like so:
sounds::core
sounds::io
@@ -1713,21 +1718,21 @@ separately with Boost.Python, like this:
{
/* export everything in the sounds::core namespace */
...
}
}
/* file io.cpp */
BOOST_PYTHON_MODULE(io)
{
/* export everything in the sounds::io namespace */
...
}
}
/* file filters.cpp */
BOOST_PYTHON_MODULE(filters)
{
/* export everything in the sounds::filters namespace */
...
}
}
Compiling these files will generate the following Python extensions:
[^core.pyd], [^io.pyd] and [^filters.pyd].
@@ -1748,7 +1753,7 @@ Now, we create this directory structure for our Python package:
The file [^__init__.py] is what tells Python that the directory [^sounds/] is
actually a Python package. It can be a empty file, but can also perform some
magic, that will be shown later.
magic, that will be shown later.
Now our package is ready. All the user has to do is put [^sounds] into his
[@http://www.python.org/doc/current/tut/node8.html#SECTION008110000000000000000 PYTHONPATH] and fire up the interpreter:
@@ -1758,7 +1763,7 @@ Now our package is ready. All the user has to do is put [^sounds] into his
>>> sound = sounds.io.open('file.mp3')
>>> new_sound = sounds.filters.echo(sound, 1.0)
Nice heh?
Nice heh?
This is the simplest way to create hierarchies of packages, but it is not very
flexible. What if we want to add a ['pure] Python function to the filters
@@ -1775,7 +1780,7 @@ little. First, we will have to change the name of the extension modules:
{
...
/* export everything in the sounds::core namespace */
}
}
Note that we added an underscore to the module name. The filename will have to
be changed to [^_core.pyd] as well, and we do the same to the other extension modules.
@@ -1797,7 +1802,7 @@ Now, we change our package hierarchy like so:
Note that we created a directory for each extension module, and added a
__init__.py 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:
access the functions in the core module with this syntax:
>>> import sounds.core._core
>>> sounds.core._core.foo(...)
@@ -1849,7 +1854,7 @@ even after it was already created:
>>> def C_str(self): return 'A C instance!'
>>>
>>> # now we turn it in a member function
>>> C.__str__ = C_str
>>> C.__str__ = C_str
>>>
>>> c = C()
>>> print c
@@ -1869,7 +1874,7 @@ we have a class [^point] in C++:
class_<point>("point")...;
}
If we are using the technique from the previous session, [@creating_packages.html
If we are using the technique from the previous session, [@creating_packages.html
Creating Packages], we can code directly into [^geom/__init__.py]:
from _geom import *
@@ -1877,7 +1882,7 @@ Creating Packages], we can code directly into [^geom/__init__.py]:
# a regular function
def point_str(self):
return str((self.x, self.y))
# now we turn it into a member function
point.__str__ = point_str
@@ -1892,9 +1897,9 @@ This technique has several advantages:
You can even add a little syntactic sugar with the use of metaclasses. Let's
create a special metaclass that "injects" methods in other classes.
# The one Boost.Python uses for all wrapped classes.
# The one Boost.Python uses for all wrapped classes.
# You can use here any class exported by Boost instead of "point"
BoostPythonMetaclass = point.__class__
BoostPythonMetaclass = point.__class__
class injector(object):
class __metaclass__(BoostPythonMetaclass):
@@ -1941,10 +1946,10 @@ class_ definitions in multiple files:
/* file point.cpp */
#include <point.h>
#include <boost/python.hpp>
void export_point()
{
class_<point>("point")...;
class_<point>("point")...;
}
/* file triangle.cpp */
@@ -1957,11 +1962,11 @@ class_ definitions in multiple files:
}
Now you create a file [^main.cpp], which contains the [^BOOST_PYTHON_MODULE]
macro, and call the various export functions inside it.
macro, and call the various export functions inside it.
void export_point();
void export_triangle();
BOOST_PYTHON_MODULE(_geom)
{
export_point();
@@ -1979,15 +1984,15 @@ usual approach:
{
class_<point>("point")...;
class_<triangle>("triangle")...;
}
}
but the memory is kept under control.
but the memory is kept under control.
This method is recommended too if you are developing the C++ library and
exporting it to Python at the same time: changes in a class will only demand
the compilation of a single cpp, instead of the entire wrapper code.
[blurb __note__ If you're exporting your classes with [@../../../pyste/index.html Pyste],
[blurb __note__ If you're exporting your classes with [@../../../pyste/index.html Pyste],
take a look at the [^--multiple] option, that generates the wrappers in
various files as demonstrated here.]

View File

@@ -0,0 +1,115 @@
<html>
<head>
<!-- Generated by the Spirit (http://spirit.sf.net) QuickDoc -->
<title>Reducing Compiling Time</title>
<link rel="stylesheet" href="theme/style.css" type="text/css">
<link rel="prev" href="extending_wrapped_objects_in_python.html">
</head>
<body>
<table width="100%" height="48" border="0" cellspacing="2">
<tr>
<td><img src="theme/c%2B%2Bboost.gif">
</td>
<td width="85%">
<font size="6" face="Verdana, Arial, Helvetica, sans-serif"><b>Reducing Compiling Time</b></font>
</td>
</tr>
</table>
<br>
<table border="0">
<tr>
<td width="30"><a href="../index.html"><img src="theme/u_arr.gif" border="0"></a></td>
<td width="30"><a href="extending_wrapped_objects_in_python.html"><img src="theme/l_arr.gif" border="0"></a></td>
<td width="20"><img src="theme/r_arr_disabled.gif" border="0"></td>
</tr>
</table>
<p>
If you have ever exported a lot of classes, you know that it takes quite a good
time to compile the Boost.Python wrappers. Plus the memory consumption can
easily become too high. If this is causing you problems, you can split the
class_ definitions in multiple files:</p>
<code><pre>
<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>boost</span><span class=special>/</span><span class=identifier>python</span><span class=special>.</span><span class=identifier>hpp</span><span class=special>&gt;
</span><span class=keyword>void </span><span class=identifier>export_point</span><span class=special>()
{
</span><span class=identifier>class_</span><span class=special>&lt;</span><span class=identifier>point</span><span class=special>&gt;(</span><span class=string>&quot;point&quot;</span><span class=special>)...;
}
/* </span><span class=identifier>file </span><span class=identifier>triangle</span><span class=special>.</span><span class=identifier>cpp </span><span class=special>*/
</span><span class=preprocessor>#include </span><span class=special>&lt;</span><span class=identifier>triangle</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>boost</span><span class=special>/</span><span class=identifier>python</span><span class=special>.</span><span class=identifier>hpp</span><span class=special>&gt;
</span><span class=keyword>void </span><span class=identifier>export_triangle</span><span class=special>()
{
</span><span class=identifier>class_</span><span class=special>&lt;</span><span class=identifier>triangle</span><span class=special>&gt;(</span><span class=string>&quot;triangle&quot;</span><span class=special>)...;
}
</span></pre></code>
<p>
Now you create a file <tt>main.cpp</tt>, which contains the <tt>BOOST_PYTHON_MODULE</tt>
macro, and call the various export functions inside it. </p>
<code><pre>
<span class=keyword>void </span><span class=identifier>export_point</span><span class=special>();
</span><span class=keyword>void </span><span class=identifier>export_triangle</span><span class=special>();
</span><span class=identifier>BOOST_PYTHON_MODULE</span><span class=special>(</span><span class=identifier>_geom</span><span class=special>)
{
</span><span class=identifier>export_point</span><span class=special>();
</span><span class=identifier>export_triangle</span><span class=special>();
}
</span></pre></code>
<p>
Compiling and linking together all this files produces the same result as the
usual approach:</p>
<code><pre>
<span class=preprocessor>#include </span><span class=special>&lt;</span><span class=identifier>boost</span><span class=special>/</span><span class=identifier>python</span><span class=special>.</span><span class=identifier>hpp</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><span class=preprocessor>#include </span><span class=special>&lt;</span><span class=identifier>triangle</span><span class=special>.</span><span class=identifier>h</span><span class=special>&gt;
</span><span class=identifier>BOOST_PYTHON_MODULE</span><span class=special>(</span><span class=identifier>_geom</span><span class=special>)
{
</span><span class=identifier>class_</span><span class=special>&lt;</span><span class=identifier>point</span><span class=special>&gt;(</span><span class=string>&quot;point&quot;</span><span class=special>)...;
</span><span class=identifier>class_</span><span class=special>&lt;</span><span class=identifier>triangle</span><span class=special>&gt;(</span><span class=string>&quot;triangle&quot;</span><span class=special>)...;
}
</span></pre></code>
<p>
but the memory is kept under control. </p>
<p>
This method is recommended too if you are developing the C++ library and
exporting it to Python at the same time: changes in a class will only demand
the compilation of a single cpp, instead of the entire wrapper code.</p>
<table width="80%" border="0" align="center">
<tr>
<td class="note_box">
<img src="theme/note.gif"></img> If you're exporting your classes with <a href="../../../pyste/index.html">
Pyste</a>,
take a look at the <tt>--multiple</tt> option, that generates the wrappers in
various files as demonstrated here. </td>
</tr>
</table>
<table width="80%" border="0" align="center">
<tr>
<td class="note_box">
<img src="theme/note.gif"></img> This method is useful too if you are getting the error message
<i>&quot;fatal error C1204:Compiler limit:internal structure overflow&quot;</i> when compiling
a large source file, as explained in the <a href="../../v2/faq.html#c1204">
FAQ</a>. </td>
</tr>
</table>
<table border="0">
<tr>
<td width="30"><a href="../index.html"><img src="theme/u_arr.gif" border="0"></a></td>
<td width="30"><a href="extending_wrapped_objects_in_python.html"><img src="theme/l_arr.gif" border="0"></a></td>
<td width="20"><img src="theme/r_arr_disabled.gif" border="0"></td>
</tr>
</table>
<br>
<hr size="1"><p class="copyright">Copyright &copy; 2002-2003 David Abrahams<br>Copyright &copy; 2002-2003 Joel de Guzman<br><br>
<font size="2">Permission to copy, use, modify, sell and distribute this document
is granted provided this copyright notice appears in all copies. This document
is provided &quot;as is&quot; without express or implied warranty, and with
no claim as to its suitability for any purpose. </font> </p>
</body>
</html>

View File

@@ -145,15 +145,13 @@ previous section</a>: the aptly named <tt>object</tt>
class and it's derivatives. What we haven't seen, is that they can be
constructed from a <tt>handle</tt>. The following examples should illustrate this
fact:</p>
<code>
<pre>
<code><pre>
<span class=identifier>handle</span><span class=special>&lt;&gt; </span><span class=identifier>main_module</span><span class=special>(</span><span class=identifier>borrowed</span><span class=special>( </span><span class=identifier>PyImport_AddModule</span><span class=special>(</span><span class=string>&quot;__main__&quot;</span><span class=special>) ));
</span><span class=identifier>dict </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>borrowed</span><span class=special>( </span><span class=identifier>PyModule_GetDict</span><span class=special>(</span><span class=identifier>main_module</span><span class=special>.</span><span class=identifier>get</span><span class=special>()) )));
</span><span class=identifier>handle</span><span class=special>&lt;&gt;( </span><span class=identifier>PyRun_String</span><span class=special>(</span><span class=string>&quot;result = 5 ** 2&quot;</span><span class=special>, </span><span class=identifier>Py_file_input</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=identifier>main_namespace</span><span class=special>.</span><span class=identifier>ptr</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>&quot;result&quot;</span><span class=special>] );
</span></pre>
</code>
</span></pre></code>
<p>
Here we create a dictionary object for the <tt>__main__</tt> module's namespace.
Then we assign 5 squared to the result variable and read this variable from
@@ -229,7 +227,7 @@ allow_null</a> function in the same way you'd use borrowed:</p>
</tr>
</table>
<br>
<hr size="1"><p class="copyright">Copyright &copy; 2002-2003 Dirk Gerrits<br><br>
<hr size="1"><p class="copyright">Copyright &copy; 2002-2003 David Abrahams<br>Copyright &copy; 2002-2003 Joel de Guzman<br><br>
<font size="2">Permission to copy, use, modify, sell and distribute this document
is granted provided this copyright notice appears in all copies. This document
is provided &quot;as is&quot; without express or implied warranty, and with

View File

@@ -145,6 +145,26 @@
<a href="doc/exception_translation.html">Exception Translation</a>
</td>
</tr>
<tr>
<td class="toc_cells_L0">
<a href="doc/general_techniques.html">General Techniques</a>
</td>
</tr>
<tr>
<td class="toc_cells_L1">
<a href="doc/creating_packages.html">Creating Packages</a>
</td>
</tr>
<tr>
<td class="toc_cells_L1">
<a href="doc/extending_wrapped_objects_in_python.html">Extending Wrapped Objects in Python</a>
</td>
</tr>
<tr>
<td class="toc_cells_L1">
<a href="doc/reducing_compiling_time.html">Reducing Compiling Time</a>
</td>
</tr>
</table>
<br>
<hr size="1"><p class="copyright">Copyright &copy; 2002-2003 David Abrahams<br>Copyright &copy; 2002-2003 Joel de Guzman<br><br>

View File

@@ -45,7 +45,7 @@ of work got done...
<h3><a name="arity">Arbitrary Arity Support</a></h3>
I began using the <a
href="../../../preprocessor/doc/index.htm">Boost.Preprocessor</a>
href="../../../preprocessor/doc/index.html">Boost.Preprocessor</a>
metaprogramming library to generate support for functions and member
functions of arbitrary arity, which was, to say the least, quite an
adventure. The feedback cycle resulting from my foray into

View File

@@ -28,50 +28,40 @@
<h2><a name="introduction"></a>Introduction</h2>
<p>Instances of a dereferenceable type can be used like a pointer to access an lvalue.
<p>Instances of a Dereferenceable type can be used like a pointer to access an lvalue.
<h2><a name="concept-requirements"></a>Concept Requirements</h2>
<h3><a name="Dereferenceable-concept"></a>Dereferenceable Concept</h3>
<p>In the table below, <code><b>x</b></code> denotes an object whose
type is a model of Dereferenceable.
<table summary="Dereferenceable expressions" border="1" cellpadding="5">
<tr>
<td><b>Expression</b></td>
<td><b>Requirements</b></td>
</tr>
<tr>
<td valign="top"><code>*x</code></td>
<td>An lvalue
</tr>
</table>
If <code><b>x</b></code> is not a pointer type, it also must satsify the following expression:
<p>In the table below, <code><b>T</b></code> is a model of
Dereferenceable, and <code><b>x</b></code> denotes an object of
type <code>T</code>. In addition, all pointers are Dereferenceable.
<table summary="Dereferenceable expressions" border="1" cellpadding="5">
<tr>
<td><b>Expression</b></td>
<td><b>Result</b></td>
<td><b>Operational Semantics</b></td>
</tr>
<tr>
<td valign="top"><code>x.get()</code></td>
<td><code>get_pointer(x)</code></td>
<td>convertible to <code><a href="pointee.html#pointee-spec">pointee</a>&lt;T&gt;::type*</code>
<td><code>&amp;*x</code>, or a null pointer
</tr>
<tr>
</table>
<hr>
<p>Revised
<!--webbot bot="Timestamp" S-Type="EDITED" S-Format="%d %B, %Y" startspan -->
29 November, 2002
18 December, 2003
<!--webbot bot="Timestamp" endspan i-checksum="39359" -->
</p>
<p><i>&copy; Copyright <a href="../../../../people/dave_abrahams.htm">Dave
Abrahams</a> 2002. All Rights Reserved.</i>
Abrahams</a> 2002-2003. All Rights Reserved.</i>
<p>Permission to copy, use, modify, sell
and distribute this software is granted provided this copyright notice appears

View File

@@ -54,7 +54,7 @@ focused on reducing the support burden. In recent weeks, responding to
requests for support, espcially surrounding building the library, had
begun to impede progress on development. There was a major push to
release a stable 1.28.0 of Boost, including documentation of <a
href="../../../../tools/build/index.html">Boost.Build</a> and specific
href="../../../../tools/build/v1/build_system.htm">Boost.Build</a> and specific
<a href="../building.html">instructions</a> for building Boost.Python
v1. The documentation for Boost.Python v2 was also updated as
described <a href="#documentation">here</a>.
@@ -70,7 +70,7 @@ described <a href="#documentation">here</a>.
Martin Casado which uncovered the key mechanism required to allow
shared libraries to use functions from the Python executable. The
current solution used in Boost.Build relies on a <a
href="../../../../tools/build/gen_aix_import_file.py">Python
href="../../../../tools/build/v1/gen_aix_import_file.py">Python
Script</a> as part of the build process. This is not a problem for
Boost.Python, as Python will be available. However, the commands
issued by the script are so simple that a 100%-pure-Boost.Jam
@@ -84,8 +84,7 @@ described <a href="#documentation">here</a>.
Support for exposing C++ operators and functions as the corresponding
Python special methods was added. Thinking that the Boost.Python
<a href="../special.html#numeric">v1 interface</a> was a little too
esoteric (especially the use of
v1 interface was a little too esoteric (especially the use of
<code>left_operand&lt;...&gt;/right_operand&lt;...&gt;</code> for
asymmetric operands), I introduced a simple form of <a
href="http://osl.iu.edu/~tveldhui/papers/Expression-Templates/exprtmpl.html">expression
@@ -155,7 +154,7 @@ This forced the exposure of the <a
href="http://www.python.org/2.2/descrintro.html#property"><code>property</code></a>
interface used internally to implement the data member exposure
facility described in <a
href="Mar2002#data_members">March</a>. Properties are an
href="Mar2002.html#data_members">March</a>. Properties are an
incredibly useful idiom, so it's good to be able to provide them
at little new development cost.
@@ -212,7 +211,7 @@ Major updates were made to the following pages:
<blockquote>
<dl>
<dt><a href="call.html">call.html</a><dd> <dt><a href="updated">updated</a><dd>
<dt><a href="call.html">call.html</a><dd> <dt>updated<dd>
<dt><a href="class.html">class.html</a><dd>
<dt><a href="reference.html">reference.html</a><dd>
</dl>

View File

@@ -72,7 +72,7 @@
use the new preproccessor metaprogramming constructs and helping us to
work around buggy and slow C++ preprocessors.</p>
<p><a href="nicodemus-at-globalite.com.br">Bruno da Silva de
<p><a href="mailto:nicodemus-at-globalite.com.br">Bruno da Silva de
Oliveira</a> contributed the ingenious <a
href="../../pyste/index.html">Pyste</a> (&quot;Pie-Steh&quot;)
code generator.

View File

@@ -3,7 +3,7 @@
<html>
<head>
<meta name="generator" content=
"HTML Tidy for Windows (vers 1st August 2002), see www.w3.org">
"HTML Tidy for Cygwin (vers 1st April 2002), see www.w3.org">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link rel="stylesheet" type="text/css" href="../boost.css">
@@ -35,7 +35,31 @@
<dt><a href="#keyword-expression"><i>keyword-expressions</i></a></dt>
<dt><a href="#functions">Functions</a></dt>
<dt><a href="#classes">Classes</a></dt>
<dd>
<dl class="page-index">
<dt><a href="#arg-spec">class <code>arg</code></a></dt>
<dd>
<dl class="page-index">
<dt><a href="#arg-synopsis">class <code>arg</code>
synopsis</a></dt>
<dt><a href="#arg-ctor">class <code>arg</code>
constructor</a></dt>
<dt><a href="#arg-operator">class <code>arg</code> template
<code>operator =</code></a></dt>
</dl>
</dd>
</dl>
</dd>
<dt><a href="#keyword-expression-operators"><i>Keyword-expression</i>
operator <code>,</code></a></dt>
<dt><a href="#functions">Functions (deprecated)</a></dt>
<dd>
<dl class="page-index">
@@ -57,27 +81,95 @@
<p>A <b>keyword-expression</b> results in an object which holds a
sequence of <a href="definitions.html#ntbs">ntbs</a>es, and whose type
encodes the number of keywords specified.</p>
encodes the number of keywords specified. The <b>keyword-expression</b>
may contain default values for some or all of the keywords it holds</p>
<h2><a name="functions"></a>Functions</h2>
<h2><a name="classes"></a>Classes</h2>
<h3><a name="args-spec"></a><code>args(</code>...<code>)</code></h3>
<h3><a name="arg-spec"></a><code>class arg;</code></h3>
<p>The objects of class arg are keyword-expressions holding one keyword (
size one )</p>
<h4><a name="arg-synopsis"></a>Class <code>arg</code> synopsis</h4>
<pre>
<i>unspecified1</i> args(char const*);
<i>unspecified2</i> args(char const*, char const*);
.
.
.
<i>unspecifiedN</i> args(char const*, char const*, ... char const*);
namespace boost { namespace python
{
struct arg
{
template &lt;class T&gt;
arg &amp;perator = (T const &amp;value);
explicit arg (char const *name){elements[0].name = name;}
};
}}
</pre>
<h4><a name="arg-ctor"></a>Class <code>arg</code> constructor</h4>
<pre>
arg(char const* name);
</pre>
<dl class="function-semantics">
<dt><b>Requires:</b> Every argument must be a <a href=
<dt><b>Requires:</b> The argument must be a <a href=
"definitions.html#ntbs">ntbs</a>.</dt>
<dt><b>Returns:</b> an object representing a <a href=
"#keyword-expression"><i>keyword-expression</i></a> encapsulating the
arguments passed.</dt>
<dt><b>Effects:</b> Constructs an <code>arg</code> object holding a
keyword with name <code>name</code>.</dt>
</dl>
<h4><a name="arg-operator"></a>Class <code>arg</code> operator =</h4>
<pre>
template &lt;class T&gt; arg &amp;operator = (T const &amp;value);
</pre>
<dl class="function-semantics">
<dt><b>Requires:</b> The argument must convertible to python.</dt>
<dt><b>Effects:</b> Assigns default value for the keyword.</dt>
<dt><b>Returns:</b> Reference to <code>this</code>.</dt>
</dl>
<h2><a name="keyword-expression-operators"><i>Keyword-expression</i>
operator <code>,</code></a></h2>
<pre>
<i>keyword-expression</i> operator , (<i>keyword-expression</i>, const arg &amp;kw) const
<i>keyword-expression</i> operator , (<i>keyword-expression</i>, const char *name) const;
</pre>
<dl class="function-semantics">
<dt><b>Requires:</b> The argument <code>name</code> must be a <a href=
"definitions.html#ntbs">ntbs</a>.</dt>
<dt><b>Effects:</b> Extends the <i>keyword-expression</i> argument with
one more keyword.</dt>
<dt><b>Returns:</b> The extended <i>keyword-expression</i>.</dt>
</dl>
<h2><font color="#7F7F7F"><a name="functions"></a>Functions
(deprecated)</font></h2>
<h3><a name="args-spec"></a><code><font color=
"#7F7F7F">args</font>(</code>...<code>)</code></h3>
<pre>
<font color="#7F7F7F"> <i>unspecified1</i> args(char const*);
<i>unspecified2</i> args(char const*, char const*);
.
.
.
<i>unspecifiedN</i> args(char const*, char const*, ... char const*);
</font>
</pre>
<dl class="function-semantics">
<dt><font color="#7F7F7F"><b>Requires:</b> Every argument must be a <a
href="definitions.html#ntbs">ntbs</a>.</font></dt>
<dt><font color="#7F7F7F"><b>Returns:</b> an object representing a <a
href="#keyword-expression"><i>keyword-expression</i></a> encapsulating
the arguments passed.</font></dt>
</dl>
<h2><a name="examples"></a>Example</h2>
@@ -85,19 +177,21 @@
#include &lt;boost/python/def.hpp&gt;
using namespace boost::python;
int f(int x, int y, int z);
int f(double x, double y, double z=0.0, double w=1.0);
BOOST_PYTHON_MODULE(xxx)
{
def("f", f, args("x", "y", "z"));
def("f", f
, ( arg("x"), "y", arg("z")=0.0, arg("w")=1.0 )
);
}
</pre>
<p>Revised 05 November, 2001</p>
<p>Revised 01 August, 2003</p>
<p><i>&copy; Copyright <a href=
"../../../../people/dave_abrahams.htm">Dave Abrahams</a> 2002. All Rights
Reserved.</i></p>
"../../../../people/dave_abrahams.htm">Dave Abrahams</a> 2002-2003. All
Rights Reserved.</i></p>
</body>
</html>

View File

@@ -3,7 +3,7 @@
<html>
<head>
<meta name="generator" content=
"HTML Tidy for Windows (vers 1st August 2002), see www.w3.org">
"HTML Tidy for Cygwin (vers 1st April 2002), see www.w3.org">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link rel="stylesheet" type="text/css" href="../boost.css">
@@ -212,7 +212,7 @@
namespace boost { namespace python
{
template &lt;class T
<font color="#007F00"> , class Bases = bases&lt;&gt;
<font color="#007F00"> , class Bases = bases&lt;&gt;
, class HeldType = T
, class NonCopyable = <i>unspecified</i>
&gt;
@@ -261,12 +261,23 @@ namespace boost { namespace python
template &lt;class D&gt;
class_&amp; def_readwrite(char const* name, D T::*pm);
// exposing static data members
template &lt;class D&gt;
class_&amp; def_readonly(char const* name, D const&amp; d);
template &lt;class D&gt;
class_&amp; def_readwrite(char const* name, D&amp; d);
// property creation
template &lt;class Get&gt;
void add_property(char const* name, Get const&amp; fget);
template &lt;class Get, class Set&gt;
void add_property(char const* name, Get const&amp; fget, Set const&amp; fset);
template &lt;class Get&gt;
void add_static_property(char const* name, Get const&amp; fget);
template &lt;class Get, class Set&gt;
void add_static_property(char const* name, Get const&amp; fget, Set const&amp; fset);
// pickle support
template &lt;typename PickleSuite&gt;
self&amp; def_pickle(PickleSuite const&amp;);
@@ -579,8 +590,40 @@ void add_property(char const* name, Get const&amp; fget, Set const&amp; fset);
</dl>
<br>
<pre>
template &lt;class Get&gt;
void add_static_property(char const* name, Get const&amp; fget);
template &lt;class Get, class Set&gt;
void add_static_property(char const* name, Get const&amp; fget, Set const&amp; fset);
</pre>
<dl class="function-semantics">
<dt><b>Requires:</b> <code>name</code> is an <a href=
"definitions.html#ntbs">ntbs</a> which conforms to Python's <a href=
"http://www.python.org/doc/current/ref/identifiers.html">identifier
naming rules</a>.</dt>
<dt><b>Effects:</b> Creates a Boost.Python.StaticProperty object,
passing <code><a href=
"object.html#object-spec-ctors">object</a>(fget)</code> (and <code><a
href="object.html#object-spec-ctors">object</a>(fset)</code> in the
second form) to its constructor, then adds that property to the Python
class under construction with the given attribute <code>name</code>.
StaticProperty is a special subclass of Python's <a href=
"http://www.python.org/2.2.2/descrintro.html#property"><code>property</code></a>
class which can be called without an initial <code>self</code>
argument.</dt>
<dt><b>Returns:</b> <code>*this</code></dt>
<dt><b>Rationale:</b> Allows users to easily expose functions that can
be invoked from Python with static attribute access syntax.</dt>
</dl>
<br>
<pre>
template &lt;class D&gt;
class_&amp; def_readonly(char const* name, D T::*pm);
template &lt;class D&gt;
class_&amp; def_readonly(char const* name, D const&amp; d);
</pre>
<dl class="function-semantics">
@@ -596,17 +639,26 @@ class_&amp; def_readonly(char const* name, D T::*pm);
this-&gt;add_property(name, <a href=
"data_members.html#make_getter-spec">make_getter</a>(pm));
</pre>
and
<pre>
this-&gt;add_static_property(name, <a href=
"data_members.html#make_getter-spec">make_getter</a>(pm));
</pre>
respectively.<br>
<br>
</dd>
<dt><b>Returns:</b> <code>*this</code></dt>
<dt><b>Rationale:</b> Allows users to easily expose a class' data
member such that it can be inspected from Python with a natural
syntax.</dt>
member or free variable such that it can be inspected from Python with
a natural syntax.</dt>
</dl>
<pre>
template &lt;class D&gt;
class_&amp; def_readwrite(char const* name, D T::*pm);
template &lt;class D&gt;
class_&amp; def_readwrite(char const* name, D&amp; d);
</pre>
<dl class="function-semantics">
@@ -618,13 +670,21 @@ this-&gt;add_property(name, <a href=
"data_members.html#make_getter-spec">make_getter</a>(pm), <a href=
"data_members.html#make_setter-spec">make_setter</a>(pm));
</pre>
and
<pre>
this-&gt;add_static_property(name, <a href=
"data_members.html#make_getter-spec">make_getter</a>(pm), <a href=
"data_members.html#make_setter-spec">make_setter</a>(pm));
</pre>
respectively.<br>
<br>
</dd>
<dt><b>Returns:</b> <code>*this</code></dt>
<dt><b>Rationale:</b> Allows users to easily expose a class' data
member such that it can be inspected and set from Python with a natural
syntax.</dt>
<dt><b>Rationale:</b> Allows users to easily expose a class' data or
free variable member such that it can be inspected and set from Python
with a natural syntax.</dt>
</dl>
<pre>
template &lt;typename PickleSuite&gt;
@@ -714,8 +774,7 @@ class_&lt;Derived, bases&lt;Base&gt; &gt;("Derived");
</pre>
Revised
<!--webbot bot="Timestamp" S-Type="EDITED" S-Format="%d %B, %Y" startspan -->
13 November, 2002
<!--webbot bot="Timestamp" endspan i-checksum="39359" -->
5 August, 2002 <!--webbot bot="Timestamp" endspan i-checksum="39359" -->
<p><i>&copy; Copyright <a href=

View File

@@ -3,7 +3,7 @@
<html>
<head>
<meta name="generator" content=
"HTML Tidy for Windows (vers 1st August 2002), see www.w3.org">
"HTML Tidy for Cygwin (vers 1st April 2002), see www.w3.org">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link rel="stylesheet" type="text/css" href="../boost.css">
@@ -92,6 +92,39 @@ template &lt;class C, class D, class Policies&gt;
callable object.</dt>
</dl>
<pre>
template &lt;class D&gt;
<a href="object.html#object-spec">object</a> make_getter(D const&amp; d);
template &lt;class D, class Policies&gt;
<a href=
"object.html#object-spec">object</a> make_getter(D const&amp; d, Policies const&amp; policies);
template &lt;class D&gt;
<a href="object.html#object-spec">object</a> make_getter(D const* p);
template &lt;class D, class Policies&gt;
<a href=
"object.html#object-spec">object</a> make_getter(D const* p, Policies const&amp; policies);
</pre>
<dl class="function-semantics">
<dt><b>Requires:</b> <code>Policies</code> is a model of <a href=
"CallPolicies.html">CallPolicies</a>.</dt>
<dt><b>Effects:</b> Creates a Python callable object which accepts no
arguments and returns <code>d</code> or <code>*p</code>, converted
<code>to_python</code> on demand. If <code>policies</code> is supplied,
it will be applied to the function as described <a href=
"CallPolicies.html">here</a>. Otherwise, the library attempts to
determine whether <code>D</code> is a user-defined class type, and if
so uses <code><a href=
"reference_existing_object.html#reference_existing_object-spec">reference_existing_object</a></code></dt>
<dt>for <code>Policies</code>.</dt>
<dt><b>Returns:</b> An instance of <a href=
"object.html#object-spec">object</a> which holds the new Python
callable object.</dt>
</dl>
<pre>
<a name="make_setter-spec">template &lt;class C, class D&gt;</a>
<a href="object.html#object-spec">object</a> make_setter(D C::*pm);
@@ -116,6 +149,34 @@ template &lt;class C, class D, class Policies&gt;
"object.html#object-spec">object</a> which holds the new Python
callable object.</dt>
</dl>
<pre>
template &lt;class D&gt;
<a href="object.html#object-spec">object</a> make_setter(D&amp; d);
template &lt;class D, class Policies&gt;
<a href=
"object.html#object-spec">object</a> make_setter(D&amp; d, Policies const&amp; policies);
template &lt;class D&gt;
<a href="object.html#object-spec">object</a> make_setter(D* p);
template &lt;class D, class Policies&gt;
<a href=
"object.html#object-spec">object</a> make_setter(D* p, Policies const&amp; policies);
</pre>
<dl class="function-semantics">
<dt><b>Requires:</b> <code>Policies</code> is a model of <a href=
"CallPolicies.html">CallPolicies</a>.</dt>
<dt><b>Effects:</b> Creates a Python callable object which accepts one
argument, which is converted from Python to <code>D const&amp;</code>
and written into <code>d</code> or <code>*p</code>, respectively. If
<code>policies</code> is supplied, it will be applied to the function
as described <a href="CallPolicies.html">here</a>.</dt>
<dt><b>Returns:</b> An instance of <a href=
"object.html#object-spec">object</a> which holds the new Python
callable object.</dt>
</dl>
<h2><a name="examples"></a>Example</h2>
@@ -155,8 +216,7 @@ BOOST_PYTHON_MODULE_INIT(data_members_example)
<p>
<!--webbot bot="Timestamp" S-Type="EDITED" S-Format="%d %B, %Y" startspan -->
13 November, 2002
<!--webbot bot="Timestamp" endspan i-checksum="39359" -->
5 August, 2003 <!--webbot bot="Timestamp" endspan i-checksum="39359" -->
</p>
<p><i>&copy; Copyright <a href=

135
doc/v2/def_visitor.html Normal file
View File

@@ -0,0 +1,135 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<meta name="generator" content="Microsoft FrontPage 5.0">
<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/def_visitor.hpp&gt;</title>
<table border="0" cellpadding="7" cellspacing="0" width="100%" summary=
"header">
<tr>
<td valign="top" width="300">
<h3><a href="../../../../index.htm"><img height="86" width="277" alt=
"C++ Boost" src="../../../../c++boost.gif" border="0"></a></h3>
<td valign="top">
<h1 align="center"><a href="../index.html"><font size="7">Boost.Python</font></a></h1>
<h2 align="center">Header &lt;boost/python/def_visitor.hpp&gt;</h2>
</table>
<hr>
<h2>Contents</h2>
<dl class="page-index">
<dt><a href="#introduction">Introduction</a>
<dt><a href="#classes">Classes</a>
<dd>
<dl class="page-index">
<dt><a href="#def_visitor-spec">Class <code>def_visitor</code></a>
<dd> <a href="#def_visitor-synopsis">Class <code>def_visitor</code>
synopsis</a></dd>
<dd> <a href="#def_visitor-requirements">Class <code>def_visitor</code>
requirements</a></dd>
</dl>
<dt><a href="#examples">Example</a>
</dl>
<hr>
<h2><a name="introduction"></a>Introduction</h2>
<p><code>&lt;boost/python/def_visitor.hpp&gt;</code> provides a generic visitation
interface through which the <a href="class.html">class_</a> <b>def</b> member
functionality can be extended non-intrusively to avoid cluttering the <a href="class.html">class_</a>
interface. It declares the <code>def_visitor&lt;T&gt; </code>class template,
which is parameterized on the derived type <tt>DerivedVisitor</tt>, which provides
the actual <b>def</b> functionality through its <b>visit</b> member functions.
<h2><a name="classes"></a>Classes</h2>
<h3><a name="def_visitor-spec"></a>Class template <code>def_visitor&lt;DerivedVisitor&gt;</code></h3>
<p>The class def_visitor is a base class paramaterized by its derived class. The
def_visitor class is a protocol class. Its derived class, DerivedVisitor, is
expected to have a member function visit. The def_visitor class is never instantiated
directly. Instead, an instance of its subclass, DerivedVisitor,&nbsp; is passed
on as an argument to the <a href="class.html">class_</a> def member function.
<h4>
<a name="def_visitor-synopsis" id="def_visitor-synopsis"></a>Class <code>def_visitor </code>synopsis</h4>
<pre>namespace boost { namespace python {
template &lt;class DerivedVisitor&gt;
class def_visitor {};
}</pre>
<h3><a name="def_visitor-requirements"></a><code>def_visitor </code>requirements</h3>
<p>The <span class="pre">client supplied class </span><span class="pre"></span><tt class="literal"><span class="pre">DerivedVisitor</span></tt>
template parameter is expected to:
<ul>
<li>be privately derived from def_visitor</li>
<li>grant friend access to class def_visitor_access</li>
<li>define either or both visit member functions listed in the table below:</li>
</ul>
<table border class="table">
<tr>
<td width="181" nowrap><b>Expression</b></td>
<td width="85"><b>Return Type</b></td>
<td width="330"><b>Requirements</b></td>
<td width="259"><b>Effects</b></td>
</tr>
<tr>
<td nowrap>visitor.visit(cls)</td>
<td>void</td>
<td>cls is an instance of a <a href="class.html">class_</a>&nbsp; being wrapped
to Python. visitor is a def_visitor derived class.</td>
<td>A call to cls.def(visitor) forwards to this member function.</td>
</tr>
<tr>
<td nowrap>visitor.visit(cls, name, options)</td>
<td>void</td>
<td>cls is a class_ instance, name is a C string. visitor is a def_visitor
derived class. options is a context specific optional argument.</td>
<td>A call to cls.def(name, visitor) or cls.def(name, visitor, options) forwards
to this member function. </td>
</tr>
</table>
<h2><a name="examples"></a>Example</h2>
<pre>class X {/*...*/};<br>
class my_def_visitor : boost::python::def_visitor&lt;my_def_visitor&gt;
{
friend class def_visitor_access;
template &lt;class classT&gt;
void visit(classT&amp; c) const
{
c
.def(&quot;foo&quot;, &amp;my_def_visitor::foo)
.def(&quot;bar&quot;, &amp;my_def_visitor::bar)
;
}
static void foo(X&amp; self);
static void bar(X&amp; self);
};
BOOST_PYTHON_MODULE(my_ext)
{
class_&lt;X&gt;(&quot;X&quot;)
.def(my_def_visitor())
;
}
</pre>
<p>Revised
<!--webbot bot="Timestamp" S-Type="EDITED" S-Format="%d %B, %Y" startspan -->27 August, 2003<!--webbot bot="Timestamp" endspan i-checksum="34484" -->
</p>
<p><i>&copy; Copyright Joel de Guzman 2003. All Rights Reserved.</i>

View File

@@ -58,10 +58,25 @@
<dt><a href="#ownership">How can I wrap a function which needs to take
ownership of a raw pointer?</a></dt>
<dt><a href="#slow_compilation">Compilation takes too much time and eats too much memory!
<dt><a href="#slow_compilation">Compilation takes too much time and eats too much memory!
What can I do to make it faster?</a></dt>
<dt><a href="#packages">How do I create sub-packages using Boost.Python?</a></dt>
<dt><a href="#packages">How do I create sub-packages using Boost.Python?</a></dt>
<dt><a href="#msvcthrowbug"
>error C2064: term does not evaluate to a function taking 2 arguments</a>
</dt>
<dt><a href="#voidptr">How do I handle <tt>void *</tt> conversion?</a></dt>
<dt><a href="#custom_string"
>How can I automatically convert my custom string type to
and from a Python string?</a></dt>
<dt><a href="#topythonconversionfailed">Why is my automatic to-python conversion not being
found?</a></dt>
<dt><a href="#threadsupport">Is Boost.Python thread-aware/compatible with multiple interpreters?</a></dt>
</dl>
<hr>
@@ -87,7 +102,7 @@ And then:
<pre>
&gt;&gt;&gt; def hello(s):
... print s
... print s
...
&gt;&gt;&gt; foo(hello)
hello, world!
@@ -119,7 +134,7 @@ hello, world!
<h2><a name="dangling">I'm getting the "attempt to return dangling
reference" error. What am I doing wrong?</a></h2>
That exception is protecting you from causing a nasty crash. It usually
happens in response to some code like this:
happens in response to some code like this:
<pre>
period const&amp; get_floating_frequency() const
{
@@ -127,7 +142,7 @@ period const&amp; get_floating_frequency() const
m_self,"get_floating_frequency");
}
</pre>
And you get:
And you get:
<pre>
ReferenceError: Attempt to return dangling reference to object of type:
class period
@@ -158,7 +173,7 @@ class period
I have the choice of using copy_const_reference or
return_internal_reference. Are there considerations that would lead me
to prefer one over the other, such as size of generated code or memory
overhead?</i>
overhead?</i>
<p><b>A:</b> copy_const_reference will make an instance with storage
for one of your objects, size = base_size + 12 * sizeof(double).
@@ -180,7 +195,7 @@ class period
<ol>
<li>
Using the regular <code>class_&lt;&gt;</code> wrapper:
Using the regular <code>class_&lt;&gt;</code> wrapper:
<pre>
class_&lt;std::vector&lt;double&gt; &gt;("std_vector_double")
.def(...)
@@ -189,13 +204,13 @@ class_&lt;std::vector&lt;double&gt; &gt;("std_vector_double")
</pre>
This can be moved to a template so that several types (double, int,
long, etc.) can be wrapped with the same code. This technique is used
in the file
in the file
<blockquote>
scitbx/include/scitbx/array_family/boost_python/flex_wrapper.h
</blockquote>
in the "scitbx" package. The file could easily be modified for
wrapping std::vector&lt;&gt; instantiations.
wrapping std::vector&lt;&gt; instantiations.
<p>This type of C++/Python binding is most suitable for containers
that may contain a large number of elements (&gt;10000).</p>
@@ -203,19 +218,19 @@ class_&lt;std::vector&lt;double&gt; &gt;("std_vector_double")
<li>
Using custom rvalue converters. Boost.Python "rvalue converters"
match function signatures such as:
match function signatures such as:
<pre>
void foo(std::vector&lt;double&gt; const&amp; array); // pass by const-reference
void foo(std::vector&lt;double&gt; array); // pass by value
</pre>
Some custom rvalue converters are implemented in the file
Some custom rvalue converters are implemented in the file
<blockquote>
scitbx/include/scitbx/boost_python/container_conversions.h
</blockquote>
This code can be used to convert from C++ container types such as
std::vector&lt;&gt; or std::list&lt;&gt; to Python tuples and vice
versa. A few simple examples can be found in the file
versa. A few simple examples can be found in the file
<blockquote>
scitbx/array_family/boost_python/regression_test_module.cpp
@@ -230,7 +245,7 @@ void foo(std::vector&lt;double&gt; array); // pass by value
rvalue converters that convert to a "math_array" type instead of tuples.
This is currently not implemented but is possible within the framework of
Boost.Python V2 as it will be released in the next couple of weeks. [ed.:
this was posted on 2002/03/10]
this was posted on 2002/03/10]
<p>It would also be useful to also have "custom lvalue converters" such
as std::vector&lt;&gt; &lt;-&gt; Python list. These converters would
@@ -245,7 +260,7 @@ void foo(std::vector&lt;double&gt;&amp; array)
}
}
</pre>
Python:
Python:
<pre>
&gt;&gt;&gt; l = [1, 2, 3]
&gt;&gt;&gt; foo(l)
@@ -253,7 +268,7 @@ void foo(std::vector&lt;double&gt;&amp; array)
[2, 4, 6]
</pre>
Custom lvalue converters require changes to the Boost.Python core library
and are currently not available.
and are currently not available.
<p>P.S.:</p>
@@ -270,7 +285,7 @@ cvs -d:pserver:anonymous@cvs.cctbx.sourceforge.net:/cvsroot/cctbx co scitbx
<blockquote>
<b>Q:</b> <i>I get this error message when compiling a large source
file. What can I do?</i>
file. What can I do?</i>
<p><b>A:</b> You have two choices:</p>
@@ -278,7 +293,7 @@ cvs -d:pserver:anonymous@cvs.cctbx.sourceforge.net:/cvsroot/cctbx co scitbx
<li>Upgrade your compiler (preferred)</li>
<li>
Break your source file up into multiple translation units.
Break your source file up into multiple translation units.
<p><code><b>my_module.cpp</b></code>:</p>
<pre>
@@ -292,7 +307,7 @@ BOOST_PYTHON_MODULE(my_module)
more_of_my_module();
}
</pre>
<code><b>more_of_my_module.cpp</b></code>:
<code><b>more_of_my_module.cpp</b></code>:
<pre>
void more_of_my_module()
{
@@ -306,7 +321,7 @@ void more_of_my_module()
can always pass a reference to the <code>class_</code> object to a
function in another source file, and call some of its member
functions (e.g. <code>.def(...)</code>) in the auxilliary source
file:
file:
<p><code><b>more_of_my_class.cpp</b></code>:</p>
<pre>
@@ -337,7 +352,7 @@ void more_of_my_class(class&lt;my_class&gt;&amp; x)
library that is under test, given that python code is minimal and
boost::python either works or it doesn't. (ie. While errors can occur
when the wrapping method is invalid, most errors are caught by the
compiler ;-).
compiler ;-).
<p>The basic steps required to initiate a gdb session to debug a c++
library via python are shown here. Note, however that you should start
@@ -368,20 +383,69 @@ Current language: auto; currently c++
solid and "just works" without requiring any special tricks from the
user.</p>
<p>Unfortunately for Cygwin and MinGW users, as of this writing gdb on
Windows has a very hard time dealing with shared libraries, which could
make Greg's approach next to useless for you. My best advice for you is
to use Metrowerks C++ for compiler conformance and Microsoft Visual
Studio as a debugger when you need one.</p>
<p>Raoul Gough has provided the following for gdb on Windows:</p>
<blockquote>
<p>gdb support for Windows DLLs has improved lately, so it is
now possible to debug Python extensions using a few
tricks. Firstly, you will need an up-to-date gdb with support
for minimal symbol extraction from a DLL. Any gdb from version 6
onwards, or Cygwin gdb-20030214-1 and onwards should do. A
suitable release will have a section in the gdb.info file under
Configuration &ndash; Native &ndash; Cygwin Native &ndash;
Non-debug DLL symbols. Refer to that info section for more
details of the procedures outlined here.</p>
<p>Secondly, it seems necessary to set a breakpoint in the
Python interpreter, rather than using ^C to break execution. A
good place to set this breakpoint is PyOS_Readline, which will
stop execution immediately before reading each interactive
Python command. You have to let Python start once under the
debugger, so that it loads its own DLL, before you can set the
breakpoint:</p>
<p>
<pre>
$ gdb python
GNU gdb 2003-09-02-cvs (cygwin-special)
[...]
(gdb) run
Starting program: /cygdrive/c/Python22/python.exe
Python 2.2.2 (#37, Oct 14 2002, 17:02:34) [MSC 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
&gt;&gt;&gt; ^Z
Program exited normally.
(gdb) break *&amp;PyOS_Readline
Breakpoint 1 at 0x1e04eff0
(gdb) run
Starting program: /cygdrive/c/Python22/python.exe
Python 2.2.2 (#37, Oct 14 2002, 17:02:34) [MSC 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
Breakpoint 1, 0x1e04eff0 in python22!PyOS_Readline ()
from /cygdrive/c/WINNT/system32/python22.dll
(gdb) cont
Continuing.
&gt;&gt;&gt; from my_ext import *
Breakpoint 1, 0x1e04eff0 in python22!PyOS_Readline ()
from /cygdrive/c/WINNT/system32/python22.dll
(gdb) # my_ext now loaded (with any debugging symbols it contains)
</pre>
</blockquote>
<h3>Debugging extensions through Boost.Build</h3>
If you are launching your extension module tests with <a href=
"../../../tools/build">Boost.Build</a> using the
"../../../../tools/build/v1/build_system.htm">Boost.Build</a> using the
<code>boost-python-runtest</code> rule, you can ask it to launch your
debugger for you by adding "-sPYTHON_LAUNCH=<i>debugger</i>" to your bjam
command-line:
debugger for you by adding "--debugger=<i>debugger</i>" to your bjam
command-line:
<pre>
bjam -sTOOLS=metrowerks "-sPYTHON_LAUNCH=devenv /debugexe" test
bjam -sTOOLS=vc7.1 "--debugger=devenv /debugexe" test
bjam -sTOOLS=gcc -sPYTHON_LAUNCH=gdb test
</pre>
It can also be extremely useful to add the <code>-d+2</code> option when
@@ -389,7 +453,7 @@ bjam -sTOOLS=gcc -sPYTHON_LAUNCH=gdb test
commands it uses to invoke it. This will invariably involve setting up
PYTHONPATH and other important environment variables such as
LD_LIBRARY_PATH which may be needed by your debugger in order to get
things to work right.
things to work right.
<hr>
<h2><a name="imul"></a>Why doesn't my <code>*=</code> operator work?</h2>
@@ -400,7 +464,7 @@ bjam -sTOOLS=gcc -sPYTHON_LAUNCH=gdb test
<i>operator. It always tells me "can't multiply sequence with non int
type". If I use</i> <code>p1.__imul__(p2)</code> <i>instead of</i>
<code>p1 *= p2</code><i>, it successfully executes my code. What's
wrong with me?</i>
wrong with me?</i>
<p><b>A:</b> There's nothing wrong with you. This is a bug in Python
2.2. You can see the same effect in Pure Python (you can learn a lot
@@ -421,24 +485,54 @@ bjam -sTOOLS=gcc -sPYTHON_LAUNCH=gdb test
<h2><a name="macosx"></a>Does Boost.Python work with Mac OS X?</h2>
<blockquote>
<p>The short answer: as of January 2003, unfortunately not.</p>
It is known to work under 10.2.8 and 10.3 using
Apple's gcc 3.3 compiler:
<pre>gcc (GCC) 3.3 20030304 (Apple Computer, Inc. build 1493)</pre>
Under 10.2.8 get the August 2003 gcc update (free at
<a href="http://connect.apple.com/">http://connect.apple.com/</a>).
Under 10.3 get the Xcode Tools v1.0 (also free).
<p>
Python 2.3 is required. The Python that ships with 10.3 is
fine. Under 10.2.8 use these commands to install Python
as a framework:
<pre>./configure --enable-framework
make
make frameworkinstall</pre>
The last command requires root privileges because the target
directory is
<tt>/Library/Frameworks/Python.framework/Versions/2.3</tt>.
However, the installation does not interfere with the Python
version that ships with 10.2.8.
<p>
It is also crucial to increase the <tt>stacksize</tt> before
starting compilations, e.g.:
<pre>limit stacksize 8192k</pre>
If the <tt>stacksize</tt> is too small the build might crash with
internal compiler errors.
<p>
Sometimes Apple's compiler exhibits a bug by printing an error
like the following while compiling a
<tt>boost::python::class_&lt;your_type&gt;</tt>
template instantiation:
<pre>.../inheritance.hpp:44: error: cannot
dynamic_cast `p' (of type `struct cctbx::boost_python::&lt;unnamed&gt;::add_pair*
') to type `void*' (source type is not polymorphic)</pre>
<p>The longer answer: using Mac OS 10.2.3 with the December Developer's
Kit, Python 2.3a1, and bjam's darwin-tools.jam, Boost.Python compiles
fine, including the examples. However, there are problems at runtime
(see <a href=
"http://mail.python.org/pipermail/c++-sig/2003-January/003267.html">http://mail.python.org/pipermail/c++-sig/2003-January/003267.html</a>).
Solutions are currently unknown.</p>
We do not know a general workaround, but if the definition of
<tt>your_type</tt> can be modified the following was found
to work in all cases encountered so far:<pre>struct your_type
{
// before defining any member data
#if defined(__MACH__) &amp;&amp; defined(__APPLE_CC__) &amp;&amp; __APPLE_CC__ == 1493
bool dummy_;
#endif
// now your member data, e.g.
double x;
int j;
// etc.
};</pre>
<p>It is known that under certain circumstances objects are
double-destructed. See <a href=
"http://mail.python.org/pipermail/c++-sig/2003-January/003278.html">http://mail.python.org/pipermail/c++-sig/2003-January/003278.html</a>
for details. It is not clear however if this problem is related to the
Boost.Python runtime issues.</p>
</blockquote>
<hr>
<h2><a name="xref">How can I find the existing PyObject that holds a C++
object?</a></h2>
@@ -450,7 +544,7 @@ bjam -sTOOLS=gcc -sPYTHON_LAUNCH=gdb test
with virtual functions. If you make a wrapper class with an initial
PyObject* constructor argument and store that PyObject* as "self", you
can get back to it by casting down to that wrapper type in a thin wrapper
function. For example:
function. For example:
<pre>
class X { X(int); virtual ~X(); ... };
X* f(); // known to return Xs that are managed by Python objects
@@ -483,7 +577,7 @@ class_&lt;X,X_wrap&gt;("X", init&lt;int&gt;())
runtime check that it's valid. This approach also only works if the
<code>X</code> object was constructed from Python, because
<code>X</code>s constructed from C++ are of course never
<code>X_wrap</code> objects.
<code>X_wrap</code> objects.
<p>Another approach to this requires you to change your C++ code a bit;
if that's an option for you it might be a better way to go. work we've
@@ -502,11 +596,13 @@ class_&lt;X,X_wrap&gt;("X", init&lt;int&gt;())
its containing Python object, and you could have your f_wrap function
look in that mapping to get the Python object out.</p>
<hr>
<h2><a name="ownership">How can I wrap a function which needs to take
ownership of a raw pointer?</a></h2>
<blockquote>
<i>Part of an API that I'm wrapping goes something like this:</i>
<i>Part of an API that I'm wrapping goes something like this:</i>
<pre>
struct A {}; struct B { void add( A* ); }
where B::add() takes ownership of the pointer passed to it.
@@ -517,9 +613,9 @@ where B::add() takes ownership of the pointer passed to it.
a = mod.A()
b = mod.B()
b.add( a )
del a
del a
del b
# python interpreter crashes
# python interpreter crashes
# later due to memory corruption.
</pre>
@@ -530,13 +626,13 @@ del b
<p><i>--Bruce Lowery</i></p>
</blockquote>
Yes: Make sure the C++ object is held by auto_ptr:
Yes: Make sure the C++ object is held by auto_ptr:
<pre>
class_&lt;A, std::auto_ptr&lt;A&gt; &gt;("A")
...
;
</pre>
Then make a thin wrapper function which takes an auto_ptr parameter:
Then make a thin wrapper function which takes an auto_ptr parameter:
<pre>
void b_insert(B&amp; b, std::auto_ptr&lt;A&gt; a)
{
@@ -547,26 +643,237 @@ void b_insert(B&amp; b, std::auto_ptr&lt;A&gt; a)
Wrap that as B.add. Note that pointers returned via <code><a href=
"manage_new_object.html#manage_new_object-spec">manage_new_object</a></code>
will also be held by <code>auto_ptr</code>, so this transfer-of-ownership
will also work correctly.
will also work correctly.
<hr>
<h2><a name="slow_compilation">Compilation takes too much time and eats too
much memory! What can I do to make it faster?</a></h2>
much memory! What can I do to make it faster?</a></h2>
<p>
Please refer to the <a href="../tutorial/doc/reducing_compiling_time.html">Techniques</a>
section in the tutorial.
Please refer to the <a href="../tutorial/doc/reducing_compiling_time.html"
>Reducing Compiling Time</a> section in the tutorial.
</p>
<h2><a name="packages">How do I create sub-packages using Boost.Python?</a></h2>
<hr>
<h2><a name="packages">How do I create sub-packages using Boost.Python?</a></h2>
<p>
In the <a href="../tutorial/doc/creating_packages.html">Techniques</a>
section of the tutorial this topic is explored.
Please refer to the <a href="../tutorial/doc/creating_packages.html"
>Creating Packages</a> section in the tutorial.
</p>
<hr>
<h2><a name="msvcthrowbug"></a>error C2064: term does
not evaluate to a function taking 2 arguments</h2>
<font size="-1"><i>Niall Douglas provides these notes:</i></font><p>
If you see Microsoft Visual C++ 7.1 (MS Visual Studio .NET 2003) issue
an error message like the following it is most likely due to a bug
in the compiler:
<pre>boost\boost\python\detail\invoke.hpp(76):
error C2064: term does not evaluate to a function taking 2 arguments"</pre>
This message is triggered by code like the following:
<pre>#include &lt;boost/python.hpp&gt;
using namespace boost::python;
class FXThread
{
public:
bool setAutoDelete(bool doso) throw();
};
void Export_FXThread()
{
class_< FXThread >("FXThread")
.def("setAutoDelete", &amp;FXThread::setAutoDelete)
;
}
</pre>
The bug is related to the <code>throw()</code> modifier.
As a workaround cast off the modifier. E.g.:
<pre>
.def("setAutoDelete", (bool (FXThread::*)(bool)) &amp;FXThread::setAutoDelete)</pre>
<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_; // Deliberately do not define
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>
<h2><a name="custom_string"></a>How can I automatically
convert my custom string type to and from a Python string?</h2>
<font size="-1"><i>Ralf W. Grosse-Kunstleve provides these
notes:</i></font><p>
Below is a small, self-contained demo extension module that shows
how to do this. Here is the corresponding trivial test:
<pre>import custom_string
assert custom_string.hello() == "Hello world."
assert custom_string.size("california") == 10</pre>
If you look at the code you will find:
<ul>
<li>A custom <tt>to_python</tt> converter (easy):
<tt>custom_string_to_python_str</tt>
<li>A custom lvalue converter (needs more code):
<tt>custom_string_from_python_str</tt>
</ul>
The custom converters are registered in the global Boost.Python
registry near the top of the module initialization function. Once
flow control has passed through the registration code the automatic
conversions from and to Python strings will work in any module
imported in the same process.
<pre>#include &lt;boost/python/module.hpp&gt;
#include &lt;boost/python/def.hpp&gt;
#include &lt;boost/python/to_python_converter.hpp&gt;
namespace sandbox { namespace {
class custom_string
{
public:
custom_string() {}
custom_string(std::string const&amp; value) : value_(value) {}
std::string const&amp; value() const { return value_; }
private:
std::string value_;
};
struct custom_string_to_python_str
{
static PyObject* convert(custom_string const&amp; s)
{
return boost::python::incref(boost::python::object(s.value()).ptr());
}
};
struct custom_string_from_python_str
{
custom_string_from_python_str()
{
boost::python::converter::registry::push_back(
&amp;convertible,
&amp;construct,
boost::python::type_id&lt;custom_string&gt;());
}
static void* convertible(PyObject* obj_ptr)
{
if (!PyString_Check(obj_ptr)) return 0;
return obj_ptr;
}
static void construct(
PyObject* obj_ptr,
boost::python::converter::rvalue_from_python_stage1_data* data)
{
const char* value = PyString_AsString(obj_ptr);
if (value == 0) boost::python::throw_error_already_set();
void* storage = (
(boost::python::converter::rvalue_from_python_storage&lt;custom_string&gt;*)
data)-&gt;storage.bytes;
new (storage) custom_string(value);
data-&gt;convertible = storage;
}
};
custom_string hello() { return custom_string(&quot;Hello world.&quot;); }
std::size_t size(custom_string const&amp; s) { return s.value().size(); }
void init_module()
{
using namespace boost::python;
boost::python::to_python_converter&lt;
custom_string,
custom_string_to_python_str&gt;();
custom_string_from_python_str();
def(&quot;hello&quot;, hello);
def(&quot;size&quot;, size);
}
}} // namespace sandbox::&lt;anonymous&gt;
BOOST_PYTHON_MODULE(custom_string)
{
sandbox::init_module();
}</pre>
<hr>
<h2><a name="topythonconversionfailed"></a
>Why is my automatic to-python conversion not being found?</h2>
<font size="-1"><i>Niall Douglas provides these notes:</i></font><p>
If you define custom converters similar to the ones
shown above the <tt>def_readonly()</tt> and <tt>def_readwrite()</tt>
member functions provided by <tt>boost::python::class_</tt> for
direct access to your member data will not work as expected.
This is because <tt>def_readonly("bar",&nbsp;&amp;foo::bar)</tt> is
equivalent to:
<pre>.add_property("bar", make_getter(&amp;foo::bar, return_internal_reference()))</pre>
Similarly, <tt>def_readwrite("bar",&nbsp;&amp;foo::bar)</tt> is
equivalent to:
<pre>.add_property("bar", make_getter(&amp;foo::bar, return_internal_reference()),
make_setter(&amp;foo::bar, return_internal_reference())</pre>
In order to define return value policies compatible with the
custom conversions replace <tt>def_readonly()</tt> and
<tt>def_readwrite()</tt> by <tt>add_property()</tt>. E.g.:
<pre>.add_property("bar", make_getter(&amp;foo::bar, return_value_policy&lt;return_by_value&gt;()),
make_setter(&amp;foo::bar, return_value_policy&lt;return_by_value&gt;()))</pre>
<hr>
<h2><a name="threadsupport"></a
>Is Boost.Python thread-aware/compatible with multiple interpreters?</h2>
<font size="-1"><i>Niall Douglas provides these notes:</i></font><p>
The quick answer to this is: no.</p>
<p>
The longer answer is that it can be patched to be so, but it's
complex. You will need to add custom lock/unlock wrapping of every
time your code enters Boost.Python (particularly every virtual
function override) plus heavily modify
<tt>boost/python/detail/invoke.hpp</tt> with custom unlock/lock
wrapping of every time Boost.Python enters your code. You must
furthermore take care to <i>not</i> unlock/lock when Boost.Python
is invoking iterator changes via <tt>invoke.hpp</tt>.</p>
<p>
There is a patched <tt>invoke.hpp</tt> posted on the C++-SIG
mailing list archives and you can find a real implementation of all
the machinery necessary to fully implement this in the TnFOX
project at <a href="http://sourceforge.net/projects/tnfox/"> this
SourceForge project location</a>.</p>
<hr>
<p>Revised
<p>Revised
<!--webbot bot="Timestamp" S-Type="EDITED" S-Format="%d %B, %Y" startspan -->
18 March, 2003
28 January, 2004
<!--webbot bot="Timestamp" endspan i-checksum="39359" -->
</p>
@@ -575,4 +882,3 @@ void b_insert(B&amp; b, std::auto_ptr&lt;A&gt; a)
Rights Reserved.</i></p>
</body>
</html>

View File

@@ -71,9 +71,8 @@ namespace boost { namespace python
{
template &lt;class T&gt;
struct from_python : private <a href=
"../../../utility/utility.htm#Class noncopyable">boost::noncopyable</a> // Exposition only.
// from_python&lt;T&gt; meets the <a href=
"NonCopyable.html">NonCopyable</a> requirements
"../../../utility/utility.htm#Class_noncopyable">boost::noncopyable</a> // Exposition only.
// from_python&lt;T&gt; meets the NonCopyable requirements
{
from_python(PyObject*);
bool convertible() const;

View File

@@ -10,7 +10,7 @@
</head>
<body>
Automatic redirection failed, please go to <a href=
Loading index page; if nothing happens, please go to <a href=
"../index.html">../index.html</a>.
</body>
</html>

636
doc/v2/indexing.html Normal file
View File

@@ -0,0 +1,636 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta name="generator" content=
"HTML Tidy for Windows (vers 1st February 2003), see www.w3.org">
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
<link rel="stylesheet" type="text/css" href="../boost.css">
<title>
Indexing Support
</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="../../../../c++boost.gif" border=
"0"></a>
</h3>
</td>
<td valign="top">
<h1 align="center">
<a href="../index.html">Boost.Python</a>
</h1>
<h2> Headers &lt;boost/python/indexing/indexing_suite.hpp&gt;<br>
&lt;boost/python/indexing/vector_indexing_suite.hpp&gt;</h2>
</td>
</tr>
</table>
<hr>
<h2>
Contents
</h2>
<dl class="page-index">
<dt>
<a href="#introduction">Introduction</a>
</dt>
<dt>
<a href="#interface">Interface</a>
</dt>
<dd>
<dl class="page-index">
<dt>
<a href="#indexing_suite">indexing_suite</a>
</dt>
<dt>
<a href="#indexing_suite_subclasses">indexing_suite
sub-classes</a>
</dt>
<dd>
<dl class="page-index">
<dt>
<a href="#vector_indexing_suite">vector_indexing_suite</a>
</dt>
</dl>
</dd>
</dl>
</dd>
</dl>
<dl>
<dt>
<a href="#indexing_suite_class">indexing_suite class</a>
</dt>
<dt>
<a href="#vector_indexing_suite_class">vector_indexing_suite
class</a>
</dt>
</dl>
<hr>
<h2>
<a name="introduction" id="introduction"></a>Introduction
</h2>
<p>
Indexing is a Boost Python facility for easy exportation of indexable
C++ containers to Python. Indexable containers are containers that
allow random access through the operator[] (e.g. std::vector).
</p>
<p>
While Boost Python has all the facilities needed to expose indexable
C++ containers such as the ubiquitous std::vector to Python, the
procedure is not as straightforward as we'd like it to be. Python
containers do not map easily to C++ containers. Emulating Python
containers in C++ (see Python Reference Manual, <a href=
"http://www.python.org/doc/current/ref/sequence-types.html">Emulating
container types</a>) using Boost Python is non trivial. There are a lot
of issues to consider before we can map a C++ container to Python.
These involve implementing wrapper functions for the methods
<strong>__len__</strong>, <strong>__getitem__</strong>,
<strong>__setitem__</strong>, <strong>__delitem__,</strong>
<strong>__iter__</strong> and <strong>__contains</strong>.
</p>
<p>
The goals:
</p>
<ul>
<li>
<div>
Make indexable C++ containers behave exactly as one would expect a
Python container to behave.
</div>
</li>
<li>
Provide default reference semantics for container element indexing
(<tt>__getitem__</tt>) such that <tt>c[i]</tt> can be mutable.
Require:
<div>
<pre>
val = c[i]
c[i].m()
val == c[i]
</pre>
</div>where <tt>m</tt> is a non-const (mutating) member function
(method).
</li>
<li>
Return safe references from <tt>__getitem__</tt> such that subsequent
adds and deletes to and from the container will not result in
dangling references (will not crash Python).
</li>
<li>
Support slice indexes.
</li>
<li>
Accept Python container arguments (e.g. lists, tuples) wherever
appropriate.
</li>
<li>
Allow for extensibility through re-definable policy classes.
</li>
<li>
Provide predefined support for the most common STL and STL like
indexable containers.
</li>
</ul>
<hr>
<h2> <a name="interface"></a>The Boost.Python Indexing Interface</h2>
<h3> <a name="indexing_suite"></a>indexing_suite [ Header &lt;boost/python/indexing/indexing_suite.hpp&gt;
]</h3>
<p>
The <tt>indexing_suite</tt> class is the base protocol class for the
management of C++ containers intended to be integrated to Python. The
objective is make a C++ container look and feel and behave exactly as
we'd expect a Python container. The class automatically wraps these
special Python methods (taken from the Python reference: <a href=
"http://www.python.org/doc/current/ref/sequence-types.html">Emulating
container types</a>):
</p>
<dl>
<dd>
<dl>
<dt>
<b><a name="l2h-126"><tt class=
"method">__len__</tt></a></b>(<var>self</var>)
</dt>
<dd>
Called to implement the built-in function <tt class=
"function">len()</tt><a name="l2h-134">&nbsp;</a> Should return
the length of the object, an integer <code>&gt;=</code> 0. Also,
an object that doesn't define a <tt class=
"method">__nonzero__()</tt> method and whose <tt class=
"method">__len__()</tt> method returns zero is considered to be
false in a Boolean context. <a name="l2h-128">&nbsp;</a>
</dd>
</dl>
<dl>
<dt>
<b><a name="l2h-129"><tt class=
"method">__getitem__</tt></a></b>(<var>self, key</var>)
</dt>
<dd>
Called to implement evaluation of
<code><var>self</var>[<var>key</var>]</code>. For sequence types,
the accepted keys should be integers and slice
objects.<a name="l2h-135">&nbsp;</a> Note that the special
interpretation of negative indexes (if the class wishes to
emulate a sequence type) is up to the <tt class=
"method">__getitem__()</tt> method. If <var>key</var> is of
an inappropriate type, <tt class="exception">TypeError</tt>
may be raised; if of a value outside the set of indexes for
the sequence (after any special interpretation of negative
values), <tt class="exception">IndexError</tt> should be
raised. <span class="note"><b class="label">Note:</b>
<tt class="keyword">for</tt> loops expect that an <tt class=
"exception">IndexError</tt> will be raised for illegal
indexes to allow proper detection of the end of the
sequence.</span>
</dd>
</dl>
<dl>
<dt>
<b><a name="l2h-130"><tt class=
"method">__setitem__</tt></a></b>(<var>self, key, value</var>)
</dt>
<dd>
Called to implement assignment to
<code><var>self</var>[<var>key</var>]</code>. Same note as for
<tt class="method">__getitem__()</tt>. This should only be
implemented for mappings if the objects support changes to the
values for keys, or if new keys can be added, or for sequences if
elements can be replaced. The same exceptions should be raised
for improper <var>key</var> values as for the <tt class=
"method">__getitem__()</tt> method.
</dd>
</dl>
<dl>
<dt>
<b><a name="l2h-131"><tt class=
"method">__delitem__</tt></a></b>(<var>self, key</var>)
</dt>
<dd>
Called to implement deletion of
<code><var>self</var>[<var>key</var>]</code>. Same note as for
<tt class="method">__getitem__()</tt>. This should only be
implemented for mappings if the objects support removal of keys,
or for sequences if elements can be removed from the sequence.
The same exceptions should be raised for improper <var>key</var>
values as for the <tt class="method">__getitem__()</tt> method.
</dd>
</dl>
<dl>
<dt>
<b><a name="l2h-132"><tt class=
"method">__iter__</tt></a></b>(<var>self</var>)
</dt>
<dd>
This method is called when an iterator is required for a
container. This method should return a new iterator object that
can iterate over all the objects in the container. For mappings,
it should iterate over the keys of the container, and should also
be made available as the method <tt class=
"method">iterkeys()</tt>.
<p>
Iterator objects also need to implement this method; they are
required to return themselves. For more information on iterator
objects, see ``<a class="ulink" href=
"http://www.python.org/doc/current/lib/typeiter.html">Iterator
Types</a>'' in the <em class="citetitle"><a href=
"http://www.python.org/doc/current/lib/lib.html" title=
"Python Library Reference">Python Library Reference</a></em>.
</p>
</dd>
</dl>
<dl>
<dt>
<b><a name="l2h-133"><tt class=
"method">__contains__</tt></a></b>(<var>self, item</var>)
</dt>
<dd>
Called to implement membership test operators. Should return true
if <var>item</var> is in <var>self</var>, false otherwise. For
mapping objects, this should consider the keys of the mapping
rather than the values or the key-item pairs.
</dd>
</dl>
</dd>
</dl>
<h3> <a name="indexing_suite_subclasses"></a>indexing_suite sub-classes</h3>
<p>
The <tt>indexing_suite</tt> is not meant to be used as is. A couple of
policy functions must be supplied by subclasses of
<tt>indexing_suite</tt>. However, a set of <tt>indexing_suite</tt>
subclasses for the standard indexable STL containers will be provided,
In most cases, we can simply use the available predefined suites. In
some cases, we can refine the predefined suites to suit our needs.
</p>
<h3> <a name="vector_indexing_suite"></a>vector_indexing_suite [ Header &lt;boost/python/indexing/vector_indexing_suite.hpp&gt;
] </h3>
<p>
The <tt>vector_indexing_suite</tt> class is a predefined
<tt>indexing_suite</tt> derived class designed to wrap
<tt>std::vector</tt> (and <tt>std::vector</tt> like [i.e. a class with
std::vector interface]) classes (currently, this is the only predefined
suite available). It provides all the policies required by the
<tt>indexing_suite</tt>.
</p>
<p>
Example usage:
</p>
<pre>
class X {...};
...
class_&lt;std::vector&lt;X&gt; &gt;("XVec")
.def(vector_indexing_suite&lt;std::vector&lt;X&gt; &gt;())
;
</pre>
<p>
<tt>XVec</tt> is now a full-fledged Python container (see the
<a href="../../test/vector_indexing_suite.cpp">example in full</a>,
along with its <a href="../../test/vector_indexing_suite.py">python
test</a>).
</p>
<hr>
<h2>
<a name="indexing_suite_class"></a>indexing_suite class
</h2>
<h3>
<br>
<tt>indexing_suite&lt;<br>
class Container<br>
, class DerivedPolicies<font color="#007F00"><br>
</font></tt> <tt>,
bool NoProxy<br>
, class Element<br>
, class Key<br>
, class Index</tt>
</h3>
<table width="100%" border="1">
<tr>
<td>
<strong>Template Parameter</strong><br>
</td>
<td>
<strong>Requirements</strong>
</td>
<td>
<strong>Semantics</strong>
</td>
<td>
<strong>Default</strong>
</td>
</tr>
<tr>
<td>
<font color="#007F00"><tt>Container</tt></font>
</td>
<td>
A class type
</td>
<td>
The container type to be wrapped to Python.
</td>
<td>&nbsp;
</td>
</tr>
<tr>
<td>
<font color="#007F00"><tt>DerivedPolicies</tt></font>
</td>
<td>
A subclass of indexing_suite
</td>
<td>
Derived classes provide the policy hooks. See <a href=
"#DerivedPolicies">DerivedPolicies</a> below.
</td>
<td>&nbsp;
</td>
</tr>
<tr>
<td>
<font color="#007F00"><tt>NoProxy</tt></font>
</td>
<td>
A boolean
</td>
<td>
By default indexed elements have Python reference semantics and are
returned by proxy. This can be disabled by supplying
<strong>true</strong> in the <tt>NoProxy</tt> template parameter.
</td>
<td>
false
</td>
</tr>
<tr>
<td>
<font color="#007F00"><tt>Element</tt></font>
</td>
<td>&nbsp;
</td>
<td>
The container's element type.
</td>
<td>
<tt>Container::value_type</tt>
</td>
</tr>
<tr>
<td>
<font color="#007F00"><tt>Key</tt></font>
</td>
<td>&nbsp;
</td>
<td>
The container's key type.
</td>
<td>
<tt>Container::value_type</tt>
</td>
</tr>
<tr>
<td>
<font color="#007F00"><tt>Index</tt></font>
</td>
<td>&nbsp;
</td>
<td>
The container's index type.
</td>
<td>
<tt>Container::size_type</tt>
</td>
</tr>
</table>
<pre>
template &lt;<br> class Container
, class DerivedPolicies
, bool NoProxy = false
, class Element = typename Container::value_type
, class Key = typename Container::value_type
, class Index = typename Container::size_type
&gt;<br> class indexing_suite
: unspecified
{
public:
indexing_suite(); // default constructor
}
</pre>
<h2>
<tt><a name="DerivedPolicies"></a>DerivedPolicies</tt>
</h2>
<dl>
<dd>
Derived classes provide the hooks needed by
the<tt>indexing_suite:</tt>
</dd>
</dl>
<pre>
static element_type&amp;
get_item(Container&amp; container, index_type i);
static object
get_slice(Container&amp; container, index_type from, index_type to);
static void
set_item(Container&amp; container, index_type i, element_type const&amp; v);
static void
set_slice(
Container&amp; container, index_type from,
index_type to, element_type const&amp; v
);
template &lt;class Iter&gt;
static void<br> set_slice(Container&amp; container, index_type from,
index_type to, Iter first, Iter last
);
static void
delete_item(Container&amp; container, index_type i);
static void
delete_slice(Container&amp; container, index_type from, index_type to);
static size_t
size(Container&amp; container);
template &lt;class T&gt;
static bool
contains(Container&amp; container, T const&amp; val);
static index_type
convert_index(Container&amp; container, PyObject* i);
static index_type
adjust_index(index_type current, index_type from,
index_type to, size_type len
);
</pre>
<blockquote>
<p>
Most of these policies are self explanatory. <tt>However,
<strong>convert_index</strong></tt> and
<tt><strong>adjust_index</strong></tt> deserve some explanation.
</p>
<p>
<strong><tt>convert_index</tt></strong> converts a Python index into
a C++ index that the container can handle. For instance, negative
indexes in Python, by convention, start counting from the right(e.g.
<tt>C[-1]</tt> indexes the rightmost element in <tt>C</tt>).
<strong><tt>convert_index</tt></strong> should handle the necessary
conversion for the C++ container (e.g. convert <tt>-1</tt> to
<tt>C.size()-1</tt>). <tt><strong>convert_index</strong></tt> should
also be able to convert the type of the index (A dynamic Python type)
to the actual type that the C++ container expects.
</p>
<p>
When a container expands or contracts, held indexes to its elements
must be adjusted to follow the movement of data. For instance, if we
erase 3 elements, starting from index 0 from a 5 element vector, what
used to be at index 4 will now be at index 1:
</p>
<pre>
[a][b][c][d][e] ---&gt; [d][e]
^ ^
4 1
</pre>
<p>
<strong><tt>adjust_index</tt></strong> takes care of the adjustment.
Given a current index, the function should return the adjusted index
when data in the container at index <tt>from</tt>..<tt>to</tt> is
replaced by <tt>len</tt> elements.
</p>
</blockquote>
<div>
<hr>
<h2>
<a name="vector_indexing_suite_class"></a>vector_indexing_suite class
</h2>
<h3>
Class template <tt><br>
vector_indexing_suite&lt;<br>
class <font color="#007F00">Container</font><br>
, bool <font color="#007F00">NoProxy</font><br>
, class <font color="#007F00">DerivedPolicies</font>&gt;</tt>
</h3>
<table width="100%" border="1">
<tr>
<td>
<strong>Template Parameter</strong><br>
</td>
<td>
<strong>Requirements</strong>
</td>
<td>
<strong>Semantics</strong>
</td>
<td>
<strong>Default</strong>
</td>
</tr>
<tr>
<td>
<font color="#007F00"><tt>Container</tt></font>
</td>
<td>
A class type
</td>
<td>
The container type to be wrapped to Python.
</td>
<td>&nbsp;
</td>
</tr>
<tr>
<td>
<font color="#007F00"><tt>NoProxy</tt></font>
</td>
<td>
A boolean
</td>
<td>
By default indexed elements have Python reference semantics and
are returned by proxy. This can be disabled by supplying
<strong>true</strong> in the <tt>NoProxy</tt> template parameter.
</td>
<td>
false
</td>
</tr>
<tr>
<td>
<font color="#007F00"><tt>DerivedPolicies</tt></font>
</td>
<td>
A subclass of indexing_suite
</td>
<td>
The <tt>vector_indexing_suite</tt> may still be derived to
further tweak any of the predefined policies. Static polymorphism
through CRTP (James Coplien. "Curiously Recurring Template
Pattern". C++ Report, Feb. 1995) enables the base
<tt>indexing_suite</tt> class to call policy function of the most
derived class
</td>
<td>&nbsp;
</td>
</tr>
</table>
<pre>
template &lt;<br> class Container,<br> bool NoProxy = false,<br> class DerivedPolicies = unspecified_default<br> class vector_indexing_suite<br> : public indexing_suite&lt;Container, DerivedPolicies, NoProxy&gt;<br> {<br> public:<br><br> typedef typename Container::value_type element_type;<br> typedef typename Container::value_type key_type;<br> typedef typename Container::size_type index_type;<br> typedef typename Container::size_type size_type;<br> typedef typename Container::difference_type difference_type;<br> <br> static element_type&amp;<br> get_item(Container&amp; container, index_type i);
static object
get_slice(Container&amp; container, index_type from, index_type to);
static void<br> set_item(Container&amp; container, index_type i, element_type const&amp; v);
static void
set_slice(Container&amp; container, index_type from,
index_type to, element_type const&amp; v);
template &lt;class Iter&gt;<br> static void<br> set_slice(Container&amp; container, index_type from,<br> index_type to, Iter first, Iter last);
static void
delete_item(Container&amp; container, index_type i);
static void
delete_slice(Container&amp; container, index_type from, index_type to);<br>
static size_t
size(Container&amp; container);
static bool
contains(Container&amp; container, key_type const&amp; key);
static index_type
convert_index(Container&amp; container, PyObject* i);
static index_type
adjust_index(index_type current, index_type from,
index_type to, size_type len);
};
</pre>
<hr>
&copy; Copyright Joel de Guzman 2003. Permission to copy, use, modify,
sell and distribute this document is granted provided this copyright
notice appears in all copies. This document is provided "as is" without
express or implied warranty, and with no claim as to its suitability
for any purpose.
</div>
</body>
</html>

View File

@@ -97,7 +97,7 @@
<pre>
namespace boost { namespace python
{
class instance_holder : <a href="../../../utility/utility.htm#Class noncopyable">noncopyable</a>
class instance_holder : <a href="../../../utility/utility.htm#Class_noncopyable">noncopyable</a>
{
public:
// destructor

View File

@@ -66,9 +66,13 @@ template &lt;class F, class Policies&gt;
<a href=
"object.html#object-spec">object</a> make_function(F f, Policies const&amp; policies)
template &lt;class F, class Policies, class Keywords&gt;
template &lt;class F, class Policies, class KeywordsOrSignature&gt;
<a href=
"object.html#object-spec">object</a> make_function(F f, Policies const&amp; policies, Keywords const&amp; keywords)
"object.html#object-spec">object</a> make_function(F f, Policies const&amp; policies, KeywordsOrSignature const&amp; ks)
template &lt;class F, class Policies, class Keywords, class Signature&gt;
<a href=
"object.html#object-spec">object</a> make_function(F f, Policies const&amp; policies, Keywords const&amp; kw, Signature const&amp; sig)
</pre>
<dl class="function-semantics">
@@ -82,19 +86,41 @@ template &lt;class F, class Policies, class Keywords&gt;
<dt><b>Effects:</b> Creates a Python callable object which, when called
from Python, converts its arguments to C++ and calls <code>f</code>. If
<code>F</code> is a pointer-to-member-function type, the target object
of the function call (<code>*this</code>) will be taken from the first
Python argument, and subsequent Python arguments will be used as the
arguments to <code>f</code>. If <code>policies</code> are supplied, it
<code>F</code> is a pointer-to-member-function type, the target
object of the function call (<code>*this</code>) will be taken
from the first Python argument, and subsequent Python arguments
will be used as the arguments
to <code>f</code>. <ul>
<li> If <code>policies</code> are supplied, it
will be applied to the function as described <a href=
"CallPolicies.html">here</a>. If <code>keywords</code> are
"CallPolicies.html">here</a>.
<li>If <code>keywords</code> are
supplied, the keywords will be applied in order to the final
arguments of the resulting function.</dt>
arguments of the resulting function.
<li>If <code>Signature</code>
is supplied, it should be an instance of an <a
href="../../../mpl/doc/ref/Sequence.html">MPL front-extensible
sequence</a> representing the function's return type followed by
its argument types. Pass a <code>Signature</code> when wrapping
function object types whose signatures can't be deduced, or when
you wish to override the types which will be passed to the
wrapped function.
</ul></dt>
<dt><b>Returns:</b> An instance of <a href=
"object.html#object-spec">object</a> which holds the new Python
callable object.</dt>
<dt><b>Caveats:</b> An argument of pointer type may
be <code>0</code> if <code>None</code> is passed from Python.
An argument type which is a constant reference may refer to a
temporary which was created from the Python object for just the
duration of the call to the wrapped function, for example
a <code>std::vector</code> conjured up by the conversion process
from a Python list. Use a non-<code>const</code> reference
argument when a persistent lvalue is required.
</dl>
<pre>
<a name=
"make_constructor-spec"></a>template &lt;class T, class ArgList, class Generator&gt;
@@ -109,7 +135,7 @@ template &lt;class ArgList, class Generator, class Policies&gt;
<dt><b>Requires:</b> <code>T</code> is a class type.
<code>Policies</code> is a model of <a href=
"CallPolicies.html">CallPolicies</a>. <code>ArgList</code> is an <a
href="../../../mpl/doc/Sequences.html">MPL sequence</a> of C++ argument
href="../../../mpl/doc/ref/Sequences.html">MPL sequence</a> of C++ argument
types (<i>A1,&nbsp;A2,...&nbsp;AN</i>) such that if
<code>a1,&nbsp;a2</code>...&nbsp;<code>aN</code> are objects of type
<i>A1,&nbsp;A2,...&nbsp;AN</i> respectively, the expression <code>new

View File

@@ -196,6 +196,8 @@ namespace boost { namespace python { namespace self_ns {
"#operator_-spec">operator_</a>&lt;<i>unspecified</i>&gt; operator+(self_t);
<a href=
"#operator_-spec">operator_</a>&lt;<i>unspecified</i>&gt; operator~(self_t);
<a href=
"#operator_-spec">operator_</a>&lt;<i>unspecified</i>&gt; operator!(self_t);
// value operations
<a href=
@@ -349,123 +351,123 @@ namespace boost { namespace python { namespace self_ns {
</tr>
<tr>
<td>self&nbsp;==&nbsp;r</td>
<td><code>self&nbsp;==&nbsp;r</code></td>
<td>__eq__</td>
<td><code>__eq__</code></td>
<td>x&nbsp;==&nbsp;y</td>
<td><code>x&nbsp;==&nbsp;y</code></td>
<td>x&nbsp;==&nbsp;y, y&nbsp;==&nbsp;x</td>
<td><code>x&nbsp;==&nbsp;y, y&nbsp;==&nbsp;x</code></td>
</tr>
<tr>
<td>l&nbsp;==&nbsp;self</td>
<td><code>l&nbsp;==&nbsp;self</code></td>
<td>__eq__</td>
<td><code>__eq__</code></td>
<td>y&nbsp;==&nbsp;x</td>
<td><code>y&nbsp;==&nbsp;x</code></td>
<td>y&nbsp;==&nbsp;x, x&nbsp;==&nbsp;y</td>
<td><code>y&nbsp;==&nbsp;x, x&nbsp;==&nbsp;y</code></td>
</tr>
<tr>
<td>self&nbsp;!=&nbsp;r</td>
<td><code>self&nbsp;!=&nbsp;r</code></td>
<td>__ne__</td>
<td><code>__ne__</code></td>
<td>x&nbsp;!=&nbsp;y</td>
<td><code>x&nbsp;!=&nbsp;y</code></td>
<td>x&nbsp;!=&nbsp;y, y&nbsp;!=&nbsp;x</td>
<td><code>x&nbsp;!=&nbsp;y, y&nbsp;!=&nbsp;x</code></td>
</tr>
<tr>
<td>l&nbsp;!=&nbsp;self</td>
<td><code>l&nbsp;!=&nbsp;self</code></td>
<td>__ne__</td>
<td><code>__ne__</code></td>
<td>y&nbsp;!=&nbsp;x</td>
<td><code>y&nbsp;!=&nbsp;x</code></td>
<td>y&nbsp;!=&nbsp;x, x&nbsp;!=&nbsp;y</td>
<td><code>y&nbsp;!=&nbsp;x, x&nbsp;!=&nbsp;y</code></td>
</tr>
<tr>
<td>self&nbsp;&lt;&nbsp;r</td>
<td><code>self&nbsp;&lt;&nbsp;r</code></td>
<td>__lt__</td>
<td><code>__lt__</code></td>
<td>x&nbsp;&lt;&nbsp;y</td>
<td><code>x&nbsp;&lt;&nbsp;y</code></td>
<td>x&nbsp;&lt;&nbsp;y, y&nbsp;&gt;&nbsp;x</td>
<td><code>x&nbsp;&lt;&nbsp;y, y&nbsp;&gt;&nbsp;x</code></td>
</tr>
<tr>
<td>l&nbsp;&lt;&nbsp;self</td>
<td><code>l&nbsp;&lt;&nbsp;self</code></td>
<td>__gt__</td>
<td><code>__gt__</code></td>
<td>y&nbsp;&lt;&nbsp;x</td>
<td><code>y&nbsp;&lt;&nbsp;x</code></td>
<td>y&nbsp;&gt;&nbsp;x, x&nbsp;&lt;&nbsp;y</td>
<td><code>y&nbsp;&gt;&nbsp;x, x&nbsp;&lt;&nbsp;y</code></td>
</tr>
<tr>
<td>self&nbsp;&gt;&nbsp;r</td>
<td><code>self&nbsp;&gt;&nbsp;r</code></td>
<td>__gt__</td>
<td><code>__gt__</code></td>
<td>x&nbsp;&gt;&nbsp;y</td>
<td><code>x&nbsp;&gt;&nbsp;y</code></td>
<td>x&nbsp;&gt;&nbsp;y, y&nbsp;&lt;&nbsp;x</td>
<td><code>x&nbsp;&gt;&nbsp;y, y&nbsp;&lt;&nbsp;x</code></td>
</tr>
<tr>
<td>l&nbsp;&gt;&nbsp;self</td>
<td><code>l&nbsp;&gt;&nbsp;self</code></td>
<td>__lt__</td>
<td><code>__lt__</code></td>
<td>y&nbsp;&gt;&nbsp;x</td>
<td><code>y&nbsp;&gt;&nbsp;x</code></td>
<td>y&nbsp;&lt;&nbsp;x, x&nbsp;&gt;&nbsp;y</td>
<td><code>y&nbsp;&lt;&nbsp;x, x&nbsp;&gt;&nbsp;y</code></td>
</tr>
<tr>
<td>self&nbsp;&lt;=&nbsp;r</td>
<td><code>self&nbsp;&lt;=&nbsp;r</code></td>
<td>__le__</td>
<td><code>__le__</code></td>
<td>x&nbsp;&lt;=&nbsp;y</td>
<td><code>x&nbsp;&lt;=&nbsp;y</code></td>
<td>x&nbsp;&lt;=&nbsp;y, y&nbsp;&gt;=&nbsp;x</td>
<td><code>x&nbsp;&lt;=&nbsp;y, y&nbsp;&gt;=&nbsp;x</code></td>
</tr>
<tr>
<td>l&nbsp;&lt;=&nbsp;self</td>
<td><code>l&nbsp;&lt;=&nbsp;self</code></td>
<td>__ge__</td>
<td><code>__ge__</code></td>
<td>y&nbsp;&lt;=&nbsp;x</td>
<td><code>y&nbsp;&lt;=&nbsp;x</code></td>
<td>y&nbsp;&gt;=&nbsp;x, x&nbsp;&lt;=&nbsp;y</td>
<td><code>y&nbsp;&gt;=&nbsp;x, x&nbsp;&lt;=&nbsp;y</code></td>
</tr>
<tr>
<td>self&nbsp;&gt;=&nbsp;r</td>
<td><code>self&nbsp;&gt;=&nbsp;r</code></td>
<td>__ge__</td>
<td><code>__ge__</code></td>
<td>x&nbsp;&gt;=&nbsp;y</td>
<td><code>x&nbsp;&gt;=&nbsp;y</code></td>
<td>x&nbsp;&gt;=&nbsp;y, y&nbsp;&lt;=&nbsp;x</td>
<td><code>x&nbsp;&gt;=&nbsp;y, y&nbsp;&lt;=&nbsp;x</code></td>
</tr>
<tr>
<td>l&nbsp;&gt;=&nbsp;self</td>
<td><code>l&nbsp;&gt;=&nbsp;self</code></td>
<td>__le__</td>
<td><code>__le__</code></td>
<td>y&nbsp;&gt;=&nbsp;x</td>
<td><code>y&nbsp;&gt;=&nbsp;x</code></td>
<td>y&nbsp;&lt;=&nbsp;x, x&nbsp;&gt;=&nbsp;y</td>
<td><code>y&nbsp;&lt;=&nbsp;x, x&nbsp;&gt;=&nbsp;y</code></td>
</tr>
</table>
@@ -487,183 +489,183 @@ namespace boost { namespace python { namespace self_ns {
</tr>
<tr>
<td>self&nbsp;+&nbsp;r</td>
<td><code>self&nbsp;+&nbsp;r</code></td>
<td>__add__</td>
<td><code>__add__</code></td>
<td>x&nbsp;+&nbsp;y</td>
<td><code>x&nbsp;+&nbsp;y</code></td>
</tr>
<tr>
<td>l&nbsp;+&nbsp;self</td>
<td><code>l&nbsp;+&nbsp;self</code></td>
<td>__radd__</td>
<td><code>__radd__</code></td>
<td>y&nbsp;+&nbsp;x</td>
<td><code>y&nbsp;+&nbsp;x</code></td>
</tr>
<tr>
<td>self&nbsp;-&nbsp;r</td>
<td><code>self&nbsp;-&nbsp;r</code></td>
<td>__sub__</td>
<td><code>__sub__</code></td>
<td>x&nbsp;-&nbsp;y</td>
<td><code>x&nbsp;-&nbsp;y</code></td>
</tr>
<tr>
<td>l&nbsp;-&nbsp;self</td>
<td><code>l&nbsp;-&nbsp;self</code></td>
<td>__rsub__</td>
<td><code>__rsub__</code></td>
<td>y&nbsp;-&nbsp;x</td>
<td><code>y&nbsp;-&nbsp;x</code></td>
</tr>
<tr>
<td>self&nbsp;*&nbsp;r</td>
<td><code>self&nbsp;*&nbsp;r</code></td>
<td>__mul__</td>
<td><code>__mul__</code></td>
<td>x&nbsp;*&nbsp;y</td>
<td><code>x&nbsp;*&nbsp;y</code></td>
</tr>
<tr>
<td>l&nbsp;*&nbsp;self</td>
<td><code>l&nbsp;*&nbsp;self</code></td>
<td>__rmul__</td>
<td><code>__rmul__</code></td>
<td>y&nbsp;*&nbsp;x</td>
<td><code>y&nbsp;*&nbsp;x</code></td>
</tr>
<tr>
<td>self&nbsp;/&nbsp;r</td>
<td><code>self&nbsp;/&nbsp;r</code></td>
<td>__div__</td>
<td><code>__div__</code></td>
<td>x&nbsp;/&nbsp;y</td>
<td><code>x&nbsp;/&nbsp;y</code></td>
</tr>
<tr>
<td>l&nbsp;/&nbsp;self</td>
<td><code>l&nbsp;/&nbsp;self</code></td>
<td>__rdiv__</td>
<td><code>__rdiv__</code></td>
<td>y&nbsp;/&nbsp;x</td>
<td><code>y&nbsp;/&nbsp;x</code></td>
</tr>
<tr>
<td>self&nbsp;%&nbsp;r</td>
<td><code>self&nbsp;%&nbsp;r</code></td>
<td>__mod__</td>
<td><code>__mod__</code></td>
<td>x&nbsp;%&nbsp;y</td>
<td><code>x&nbsp;%&nbsp;y</code></td>
</tr>
<tr>
<td>l&nbsp;%&nbsp;self</td>
<td><code>l&nbsp;%&nbsp;self</code></td>
<td>__rmod__</td>
<td><code>__rmod__</code></td>
<td>y&nbsp;%&nbsp;x</td>
<td><code>y&nbsp;%&nbsp;x</code></td>
</tr>
<tr>
<td>self&nbsp;&gt;&gt;&nbsp;r</td>
<td><code>self&nbsp;&gt;&gt;&nbsp;r</code></td>
<td>__rshift__</td>
<td><code>__rshift__</code></td>
<td>x&nbsp;&gt;&gt;&nbsp;y</td>
<td><code>x&nbsp;&gt;&gt;&nbsp;y</code></td>
</tr>
<tr>
<td>l&nbsp;&gt;&gt;&nbsp;self</td>
<td><code>l&nbsp;&gt;&gt;&nbsp;self</code></td>
<td>__rrshift__</td>
<td><code>__rrshift__</code></td>
<td>y&nbsp;&gt;&gt;&nbsp;x</td>
<td><code>y&nbsp;&gt;&gt;&nbsp;x</code></td>
</tr>
<tr>
<td>self&nbsp;&lt;&lt;&nbsp;r</td>
<td><code>self&nbsp;&lt;&lt;&nbsp;r</code></td>
<td>__lshift__</td>
<td><code>__lshift__</code></td>
<td>x&nbsp;&lt;&lt;&nbsp;y</td>
<td><code>x&nbsp;&lt;&lt;&nbsp;y</code></td>
</tr>
<tr>
<td>l&nbsp;&lt;&lt;&nbsp;self</td>
<td><code>l&nbsp;&lt;&lt;&nbsp;self</code></td>
<td>__rlshift__</td>
<td><code>__rlshift__</code></td>
<td>y&nbsp;&lt;&lt;&nbsp;x</td>
<td><code>y&nbsp;&lt;&lt;&nbsp;x</code></td>
</tr>
<tr>
<td>self&nbsp;&amp;&nbsp;r</td>
<td><code>self&nbsp;&amp;&nbsp;r</code></td>
<td>__and__</td>
<td><code>__and__</code></td>
<td>x&nbsp;&amp;&nbsp;y</td>
<td><code>x&nbsp;&amp;&nbsp;y</code></td>
</tr>
<tr>
<td>l&nbsp;&amp;&nbsp;self</td>
<td><code>l&nbsp;&amp;&nbsp;self</code></td>
<td>__rand__</td>
<td><code>__rand__</code></td>
<td>y&nbsp;&amp;&nbsp;x</td>
<td><code>y&nbsp;&amp;&nbsp;x</code></td>
</tr>
<tr>
<td>self&nbsp;^&nbsp;r</td>
<td><code>self&nbsp;^&nbsp;r</code></td>
<td>__xor__</td>
<td><code>__xor__</code></td>
<td>x&nbsp;^&nbsp;y</td>
<td><code>x&nbsp;^&nbsp;y</code></td>
</tr>
<tr>
<td>l&nbsp;^&nbsp;self</td>
<td><code>l&nbsp;^&nbsp;self</code></td>
<td>__rxor__</td>
<td><code>__rxor__</code></td>
<td>y&nbsp;^&nbsp;x</td>
<td><code>y&nbsp;^&nbsp;x</code></td>
</tr>
<tr>
<td>self&nbsp;|&nbsp;r</td>
<td><code>self&nbsp;|&nbsp;r</code></td>
<td>__or__</td>
<td><code>__or__</code></td>
<td>x&nbsp;|&nbsp;y</td>
<td><code>x&nbsp;|&nbsp;y</code></td>
</tr>
<tr>
<td>l&nbsp;|&nbsp;self</td>
<td><code>l&nbsp;|&nbsp;self</code></td>
<td>__ror__</td>
<td><code>__ror__</code></td>
<td>y&nbsp;|&nbsp;x</td>
<td><code>y&nbsp;|&nbsp;x</code></td>
</tr>
<tr>
<td>pow(self,&nbsp;r)</td>
<td><code>pow(self,&nbsp;r)</code></td>
<td>__pow__</td>
<td><code>__pow__</code></td>
<td>pow(x,&nbsp;y)</td>
<td><code>pow(x,&nbsp;y)</code></td>
</tr>
<tr>
<td>pow(l,&nbsp;self)</td>
<td><code>pow(l,&nbsp;self)</code></td>
<td>__rpow__</td>
<td><code>__rpow__</code></td>
<td>pow(y,&nbsp;x)</td>
<td><code>pow(y,&nbsp;x)</code></td>
</tr>
</table>
<h4><a name="self_t-spec-unary-ops"></a>Class <code>self_t</code> unary
<h4><a name="self_t-spec-value-unary-ops"></a>Class <code>self_t</code> unary
operations</h4>
<table border="1" summary="self_t unary operations">
@@ -676,27 +678,35 @@ namespace boost { namespace python { namespace self_ns {
</tr>
<tr>
<td>-self</td>
<td><code>-self</code></td>
<td>__neg__</td>
<td><code>__neg__</code></td>
<td>-x</td>
<td><code>-x</code></td>
</tr>
<tr>
<td>+self</td>
<td><code>+self</code></td>
<td>__pos__</td>
<td><code>__pos__</code></td>
<td>+x</td>
<td><code>+x</code></td>
</tr>
<tr>
<td>~self</td>
<td><code>~self</code></td>
<td>__invert__</td>
<td><code>__invert__</code></td>
<td>~x</td>
<td><code>~x</code></td>
</tr>
<tr>
<td><code>not self</code><br><i>or</i><br><code>!self</code></td>
<td><code>__nonzero__</code></td>
<td><code>!!x</code></td>
</tr>
</table>
@@ -713,44 +723,44 @@ namespace boost { namespace python { namespace self_ns {
</tr>
<tr>
<td>int_(self)</td>
<td><code>int_(self)</code></td>
<td>__int__</td>
<td><code>__int__</code></td>
<td>long(x)</td>
<td><code>long(x)</code></td>
</tr>
<tr>
<td>long_</td>
<td><code>long_</code></td>
<td>__long__</td>
<td><code>__long__</code></td>
<td>PyLong_FromLong(x)</td>
<td><code>PyLong_FromLong(x)</code></td>
</tr>
<tr>
<td>float_</td>
<td><code>float_</code></td>
<td>__float__</td>
<td><code>__float__</code></td>
<td>double(x)</td>
<td><code>double(x)</code></td>
</tr>
<tr>
<td>complex_</td>
<td><code>complex_</code></td>
<td>__complex__</td>
<td><code>__complex__</code></td>
<td>std::complex&lt;double&gt;(x)</td>
<td><code>std::complex&lt;double&gt;(x)</code></td>
</tr>
<tr>
<td>str</td>
<td><code>str</code></td>
<td>__str__</td>
<td><code>__str__</code></td>
<td><a href=
"../../../conversion/lexical_cast.htm#lexical_cast">lexical_cast</a>&lt;std::string&gt;(x)</td>
<td><code><a href=
"../../../conversion/lexical_cast.htm#lexical_cast">lexical_cast</a>&lt;std::string&gt;(x)</code></td>
</tr>
</table>
@@ -876,7 +886,7 @@ BOOST_PYTHON_MODULE(demo)
<p>Revised
<!--webbot bot="Timestamp" S-Type="EDITED" S-Format="%d %B, %Y" startspan -->
13 November, 2002
3 October, 2003
<!--webbot bot="Timestamp" endspan i-checksum="39359" -->
</p>

View File

@@ -27,8 +27,15 @@
</tr>
</table>
<hr>
<b>Boost.Python</b> has been successfully tested on the following
platforms and compilers:
Please see
our <a
href="http://boost.sourceforge.net/regression-logs">regression
logs</a> for up-to-date information. Note that logs not marked
otherwise reflect the CVS state, not the condition of the release.
<p>
Earlier versions of <b>Boost.Python</b> have been successfully
tested on the following platforms and compilers.
<dl class="page-index">
<dt>Unix Platforms:</dt>

View File

@@ -13,7 +13,7 @@
p.c3 {font-style: italic}
h2.c2 {text-align: center}
h1.c1 {text-align: center}
</style>
</style>
</head>
<body>
@@ -96,193 +96,158 @@
<h2><a name="high_level">High Level Components</a></h2>
<dl>
<dt><a href="class.html">class.hpp/class_fwd.hpp</a></dt>
<dd>
<dl>
<dt><a href="class.html">class.hpp/class_fwd.hpp</a></dt>
<dd>
<dl class="index">
<dt><a href="class.html#classes">Classes</a></dt>
<dd>
<dl class="index">
<dt><a href="class.html#classes">Classes</a></dt>
<dd>
<dl class="index">
<dt><a href="class.html#class_-spec">class_</a></dt>
<dt><a href="class.html#bases-spec">bases</a></dt>
</dl>
</dd>
</dl>
</dd>
<dt><a href="def.html">def.hpp</a></dt>
<dd>
<dl class="index">
<dt><a href="def.html#functions">Functions</a></dt>
<dd>
<dl class="page-index">
<dt><a href="def.html#def-spec">def</a></dt>
</dl>
</dd>
</dl>
</dd>
<dt><a href="enum.html">enum.hpp</a></dt>
<dd>
<dl class="index">
<dt><a href="enum.html#classes">Classes</a></dt>
<dd>
<dl class="index">
<dt><a href="enum.html#enum_-spec">enum_</a></dt>
</dl>
</dd>
</dl>
</dd>
<dt><a href="errors.html">errors.hpp</a></dt>
<dd>
<dl class="index">
<dt><a href="errors.html#classes">Classes</a></dt>
<dd>
<dl class="index">
<dt><a href=
"errors.html#error_already_set-spec">error_already_set</a></dt>
</dl>
</dd>
<dt><a href="errors.html#functions">Functions</a></dt>
<dd>
<dl class="index">
<dt><a href=
"errors.html#handle_exception-spec">handle_exception</a></dt>
<dt><a href=
"errors.html#expect_non_null-spec">expect_non_null</a></dt>
<dt><a href=
"errors.html#throw_error_already_set-spec">throw_error_already_set</a></dt>
</dl>
</dd>
</dl>
</dd>
<dt><a href=
"exception_translator.html">exception_translator.hpp</a></dt>
<dd>
<dl class="index">
<dt><a href=
"exception_translator.html#functions">Functions</a></dt>
<dd>
<dl class="index">
<dt><a href=
"exception_translator.html#register_exception_translator-spec">register_exception_translator</a></dt>
</dl>
</dd>
</dl>
</dd>
<dt><a href="init.html">init.hpp</a></dt>
<dd>
<dl class="index">
<dt><a href="init.html#classes">Classes</a></dt>
<dd>
<dl class="index">
<dt><a href="init.html#init-spec">init</a></dt>
<dt><a href="init.html#optional-spec">optional</a></dt>
</dl>
</dd>
</dl>
</dd>
<dt><a href="iterator.html">iterator.hpp</a></dt>
<dd>
<dl class="index">
<dt><a href="iterator.html#classes">Classes</a></dt>
<dd>
<dl class="index">
<dt><a href="iterator.html#iterator-spec">iterator</a></dt>
<dt><a href="iterator.html#iterators-spec">iterators</a></dt>
</dl>
</dd>
<dt><a href="iterator.html#functions">Functions</a></dt>
<dd>
<dl class="index">
<dt><a href="iterator.html#range-spec">range</a></dt>
</dl>
</dd>
</dl>
</dd>
<dt><a href="module.html">module.hpp</a></dt>
<dd>
<dl class="index">
<dt><a href="module.html#macros">Macros</a></dt>
<dd>
<dl class="index">
<dt><a href=
"module.html#BOOST_PYTHON_MODULE-spec">BOOST_PYTHON_MODULE</a></dt>
</dl>
</dd>
</dl>
</dd>
<dt><a href="operators.html">operators.hpp</a></dt>
<dd>
<dl class="index">
<dt><a href="operators.html#classes">Classes</a></dt>
<dd>
<dl class="index">
<dt><a href="operators.html#self_t-spec">self_t</a></dt>
<dt><a href="operators.html#other-spec">other</a></dt>
<dt><a href="operators.html#operator_-spec">operator_</a></dt>
</dl>
</dd>
<dt><a href="operators.html#objects">Objects</a></dt>
<dd>
<dl class="index">
<dt><a href="operators.html#self-spec">self</a></dt>
</dl>
</dd>
</dl>
</dd>
<dt><a href="scope.html">scope.hpp</a></dt>
<dd>
<dl class="index">
<dt><a href="scope.html#classes">Classes</a></dt>
<dd>
<dl class="index">
<dt><a href="scope.html#scope-spec">scope</a></dt>
</dl>
</dd>
<dt><a href="class.html#class_-spec">class_</a></dt>
<dt><a href="class.html#bases-spec">bases</a></dt>
</dl>
</dd>
</dl>
</dd>
<dt><a href="def.html">def.hpp</a></dt>
<dd>
<dl class="index">
<dt><a href="def.html#functions">Functions</a></dt>
<dd>
<dl class="page-index">
<dt><a href="def.html#def-spec">def</a></dt>
</dl>
</dd>
</dl>
</dd>
<dt><a href="def_visitor.html">def_visitor.hpp</a></dt>
<dd>
<dl class="index">
<dt><a href="def_visitor.html#classes">Classes</a></dt>
</dl>
</dd>
<dt><a href="enum.html">enum.hpp</a></dt>
<dd>
<dl class="index">
<dt><a href="enum.html#classes">Classes</a></dt>
<dd>
<dl class="index">
<dt><a href="enum.html#enum_-spec">enum_</a></dt>
</dl>
</dd>
</dl>
</dd>
<dt><a href="errors.html">errors.hpp</a></dt>
<dd>
<dl class="index">
<dt><a href="errors.html#classes">Classes</a></dt>
<dd>
<dl class="index">
<dt><a href=
"errors.html#error_already_set-spec">error_already_set</a></dt>
</dl>
</dd>
<dt><a href="errors.html#functions">Functions</a></dt>
<dd>
<dl class="index">
<dt><a href=
"errors.html#handle_exception-spec">handle_exception</a></dt>
<dt><a href=
"errors.html#expect_non_null-spec">expect_non_null</a></dt>
<dt><a href=
"errors.html#throw_error_already_set-spec">throw_error_already_set</a></dt>
</dl>
</dd>
</dl>
</dd>
<dt><a href=
"exception_translator.html">exception_translator.hpp</a></dt>
<dd>
<dl class="index">
<dt><a href=
"exception_translator.html#functions">Functions</a></dt>
<dd>
<dl class="index">
<dt><a href=
"exception_translator.html#register_exception_translator-spec">register_exception_translator</a></dt>
</dl>
</dd>
</dl>
</dd>
<dt><a href="init.html">init.hpp</a></dt>
<dd>
<dl class="index">
<dt><a href="init.html#classes">Classes</a></dt>
<dd>
<dl class="index">
<dt><a href="init.html#init-spec">init</a></dt>
<dt><a href="init.html#optional-spec">optional</a></dt>
</dl>
</dd>
</dl>
</dd>
<dt><a href="iterator.html">iterator.hpp</a></dt>
<dd>
<dl class="index">
<dt><a href="iterator.html#classes">Classes</a></dt>
<dd>
<dl class="index">
<dt><a href="iterator.html#iterator-spec">iterator</a></dt>
<dt><a href="iterator.html#iterators-spec">iterators</a></dt>
</dl>
</dd>
<dt><a href="iterator.html#functions">Functions</a></dt>
<dd>
<dl class="index">
<dt><a href="iterator.html#range-spec">range</a></dt>
</dl>
</dd>
</dl>
</dd>
<dt><a href="module.html">module.hpp</a></dt>
<dd>
<dl class="index">
<dt><a href="module.html#macros">Macros</a></dt>
<dd>
<dl class="index">
<dt><a href=
"module.html#BOOST_PYTHON_MODULE-spec">BOOST_PYTHON_MODULE</a></dt>
</dl>
</dd>
</dl>
</dd>
<dt><a href="operators.html">operators.hpp</a></dt>
<dd>
<dl class="index">
<dt><a href="operators.html#classes">Classes</a></dt>
<dd>
<dl class="index">
<dt><a href="operators.html#self_t-spec">self_t</a></dt>
<dt><a href="operators.html#other-spec">other</a></dt>
<dt><a href="operators.html#operator_-spec">operator_</a></dt>
</dl>
</dd>
<dt><a href="operators.html#objects">Objects</a></dt>
<dd>
<dl class="index">
<dt><a href="operators.html#self-spec">self</a></dt>
</dl>
</dd>
</dl>
</dd>
<dt><a href="scope.html">scope.hpp</a></dt>
<dd>
<dl class="index">
<dt><a href="scope.html#classes">Classes</a></dt>
<dd>
<dl class="index">
<dt><a href="scope.html#scope-spec">scope</a></dt>
</dl>
</dd>
</dl>
</dd>
</dl>
<h2><a name="object_wrappers">Object Wrappers</a></h2>
@@ -371,7 +336,7 @@
</dl>
</dd>
<dt><a href="str.html">tuple.hpp</a></dt>
<dt><a href="tuple.html">tuple.hpp</a></dt>
<dd>
<dl class="index">
@@ -570,6 +535,24 @@
</dl>
</dd>
<dt><a href="return_arg.html">return_arg.hpp</a></dt>
<dd>
<dl class="index">
<dt><a href="return_arg.html#classes">Classes</a></dt>
<dd>
<dl class="index">
<dt><a href=
"return_arg.html#return_arg-spec">return_arg</a></dt>
<dt><a href=
"return_arg.html#return_self-spec">return_self</a></dt>
</dl>
</dd>
</dl>
</dd>
<dt><a href=
"return_internal_reference.html">return_internal_reference.hpp</a></dt>
@@ -750,91 +733,18 @@
</dl>
</dd>
<dt><a href="return_opaque_pointer.html">return_opaque_pointer.hpp</a></dt>
<dt><a href=
"return_opaque_pointer.html">return_opaque_pointer.hpp</a></dt>
<dd>
<dl class="index">
<dt><a href="return_opaque_pointer.html#classes">Classes</a></dt>
<dt><a href=
"return_opaque_pointer.html#classes">Classes</a></dt>
<dd>
<dl class="index">
<dt><a href="return_opaque_pointer.html#return_opaque_pointer-spec">
return_opaque_pointer</a></dt>
</dl>
</dd>
</dl>
</dd>
<dt><a href="return_opaque_pointer.html">return_opaque_pointer.hpp</a></dt>
<dd>
<dl class="index">
<dt><a href="return_opaque_pointer.html#classes">Classes</a></dt>
<dd>
<dl class="index">
<dt><a href="return_opaque_pointer.html#return_opaque_pointer-spec">
return_opaque_pointer</a></dt>
</dl>
</dd>
</dl>
</dd>
<dt><a href="return_opaque_pointer.html">return_opaque_pointer.hpp</a></dt>
<dd>
<dl class="index">
<dt><a href="return_opaque_pointer.html#classes">Classes</a></dt>
<dd>
<dl class="index">
<dt><a href="return_opaque_pointer.html#return_opaque_pointer-spec">
return_opaque_pointer</a></dt>
</dl>
</dd>
</dl>
</dd>
<dt><a href="return_opaque_pointer.html">return_opaque_pointer.hpp</a></dt>
<dd>
<dl class="index">
<dt><a href="return_opaque_pointer.html#classes">Classes</a></dt>
<dd>
<dl class="index">
<dt><a href="return_opaque_pointer.html#return_opaque_pointer-spec">
return_opaque_pointer</a></dt>
</dl>
</dd>
</dl>
</dd>
<dt><a href="return_opaque_pointer.html">return_opaque_pointer.hpp</a></dt>
<dd>
<dl class="index">
<dt><a href="return_opaque_pointer.html#classes">Classes</a></dt>
<dd>
<dl class="index">
<dt><a href="return_opaque_pointer.html#return_opaque_pointer-spec">
return_opaque_pointer</a></dt>
</dl>
</dd>
</dl>
</dd>
<dt><a href="return_opaque_pointer.html">return_opaque_pointer.hpp</a></dt>
<dd>
<dl class="index">
<dt><a href="return_opaque_pointer.html#classes">Classes</a></dt>
<dd>
<dl class="index">
<dt><a href="return_opaque_pointer.html#return_opaque_pointer-spec">
return_opaque_pointer</a></dt>
<dt><a href=
"return_opaque_pointer.html#return_opaque_pointer-spec">return_opaque_pointer</a></dt>
</dl>
</dd>
</dl>
@@ -896,139 +806,28 @@
</dl>
</dd>
<dt><a href="opaque_pointer_converter.html">opaque_pointer_converter.hpp</a></dt>
<dt><a href=
"opaque_pointer_converter.html">opaque_pointer_converter.hpp</a></dt>
<dd>
<dl class="index">
<dt><a href="opaque_pointer_converter.html#classes">Classes</a></dt>
<dt><a href=
"opaque_pointer_converter.html#classes">Classes</a></dt>
<dd>
<dl class="index">
<dt><a href="opaque_pointer_converter.html#opaque_pointer_converter-spec">
opaque_pointer_converter</a></dt>
<dt><a href=
"opaque_pointer_converter.html#opaque_pointer_converter-spec">opaque_pointer_converter</a></dt>
</dl>
</dd>
<dt><a href="opaque_pointer_converter.html#macros">Macros</a></dt>
<dd>
<dl class="index">
<dt><a href="opaque_pointer_converter.html#BOOST_PYTHON_OPAQUE_SPECIALIZED_TYPE_ID-spec">
BOOST_PYTHON_OPAQUE_SPECIALIZED_TYPE_ID</a></dt>
</dl>
</dd>
</dl>
</dd>
<dt><a href="opaque_pointer_converter.html">opaque_pointer_converter.hpp</a></dt>
<dd>
<dl class="index">
<dt><a href="opaque_pointer_converter.html#classes">Classes</a></dt>
<dd>
<dl class="index">
<dt><a href="opaque_pointer_converter.html#opaque_pointer_converter-spec">
opaque_pointer_converter</a></dt>
</dl>
</dd>
<dt><a href="opaque_pointer_converter.html#macros">Macros</a></dt>
<dd>
<dl class="index">
<dt><a href="opaque_pointer_converter.html#BOOST_PYTHON_OPAQUE_SPECIALIZED_TYPE_ID-spec">
BOOST_PYTHON_OPAQUE_SPECIALIZED_TYPE_ID</a></dt>
</dl>
</dd>
</dl>
</dd>
<dt><a href="opaque_pointer_converter.html">opaque_pointer_converter.hpp</a></dt>
<dd>
<dl class="index">
<dt><a href="opaque_pointer_converter.html#classes">Classes</a></dt>
<dd>
<dl class="index">
<dt><a href="opaque_pointer_converter.html#opaque_pointer_converter-spec">
opaque_pointer_converter</a></dt>
</dl>
</dd>
<dt><a href="opaque_pointer_converter.html#macros">Macros</a></dt>
<dd>
<dl class="index">
<dt><a href="opaque_pointer_converter.html#BOOST_PYTHON_OPAQUE_SPECIALIZED_TYPE_ID-spec">
BOOST_PYTHON_OPAQUE_SPECIALIZED_TYPE_ID</a></dt>
</dl>
</dd>
</dl>
</dd>
<dt><a href="opaque_pointer_converter.html">opaque_pointer_converter.hpp</a></dt>
<dd>
<dl class="index">
<dt><a href="opaque_pointer_converter.html#classes">Classes</a></dt>
<dd>
<dl class="index">
<dt><a href="opaque_pointer_converter.html#opaque_pointer_converter-spec">
opaque_pointer_converter</a></dt>
</dl>
</dd>
<dt><a href="opaque_pointer_converter.html#macros">Macros</a></dt>
<dd>
<dl class="index">
<dt><a href="opaque_pointer_converter.html#BOOST_PYTHON_OPAQUE_SPECIALIZED_TYPE_ID-spec">
BOOST_PYTHON_OPAQUE_SPECIALIZED_TYPE_ID</a></dt>
</dl>
</dd>
</dl>
</dd>
<dt><a href="opaque_pointer_converter.html">opaque_pointer_converter.hpp</a></dt>
<dd>
<dl class="index">
<dt><a href="opaque_pointer_converter.html#classes">Classes</a></dt>
<dd>
<dl class="index">
<dt><a href="opaque_pointer_converter.html#opaque_pointer_converter-spec">
opaque_pointer_converter</a></dt>
</dl>
</dd>
<dt><a href="opaque_pointer_converter.html#macros">Macros</a></dt>
<dd>
<dl class="index">
<dt><a href="opaque_pointer_converter.html#BOOST_PYTHON_OPAQUE_SPECIALIZED_TYPE_ID-spec">
BOOST_PYTHON_OPAQUE_SPECIALIZED_TYPE_ID</a></dt>
</dl>
</dd>
</dl>
</dd>
<dt><a href="opaque_pointer_converter.html">opaque_pointer_converter.hpp</a></dt>
<dd>
<dl class="index">
<dt><a href="opaque_pointer_converter.html#classes">Classes</a></dt>
<dd>
<dl class="index">
<dt><a href="opaque_pointer_converter.html#opaque_pointer_converter-spec">
opaque_pointer_converter</a></dt>
</dl>
</dd>
<dt><a href="opaque_pointer_converter.html#macros">Macros</a></dt>
<dd>
<dl class="index">
<dt><a href="opaque_pointer_converter.html#BOOST_PYTHON_OPAQUE_SPECIALIZED_TYPE_ID-spec">
BOOST_PYTHON_OPAQUE_SPECIALIZED_TYPE_ID</a></dt>
<dt><a href=
"opaque_pointer_converter.html#BOOST_PYTHON_OPAQUE_SPECIALIZED_TYPE_ID-spec">
BOOST_PYTHON_OPAQUE_SPECIALIZED_TYPE_ID</a></dt>
</dl>
</dd>
</dl>
@@ -1048,6 +847,23 @@
</dd>
</dl>
</dd>
<dt><a href=
"register_ptr_to_python.html">register_ptr_to_python.hpp</a></dt>
<dd>
<dl class="index">
<dt><a href=
"register_ptr_to_python.html#functions">Functions</a></dt>
<dd>
<dl class="index">
<dt><a href=
"register_ptr_to_python.html#register_ptr_to_python-spec">register_ptr_to_python</a></dt>
</dl>
</dd>
</dl>
</dd>
</dl>
<h2><a name="utility">Utility and Infrastructure</a></h2>
@@ -1149,18 +965,17 @@
<h2><a name="topics">Topics</a></h2>
<dl>
<dt><a href="callbacks.html">Calling Python Functions and
Methods</a></dt>
<dt><a href="pickle.html">Pickle Support</a></dt>
</dl>
<dl>
<dt><a href="callbacks.html">Calling Python Functions and Methods</a></dt>
<dt><a href="pickle.html">Pickle Support</a><br>
<a href="indexing.html">Indexing Support</a></dt>
</dl>
<hr>
<p>Revised
<!--webbot bot="Timestamp" S-Type="EDITED" S-Format="%d %B, %Y" startspan -->
7 March, 2003
<!--webbot bot="Timestamp" endspan i-checksum="39359" -->
19 July, 2003 <!--webbot bot="Timestamp" endspan i-checksum="39359" -->
</p>
<p class="c3">&copy; Copyright <a href=

View File

@@ -0,0 +1,159 @@
<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;register_ptr_to_python.hpp&gt;</title>
</head>
<body link="#0000ff" vlink="#800080">
<table border="0" cellpadding="7" cellspacing="0" width="100%" summary=
"header">
<tr>
<td valign="top" width="300">
<h3><a href="../../../../index.htm"><img height="86" width="277" alt=
"C++ Boost" src="../../../../c++boost.gif" border="0"></a></h3>
</td>
<td valign="top">
<h1 align="center"><a href="../index.html">Boost.Python</a></h1>
<h2 align="center">Header &lt;register_ptr_to_python.hpp&gt;</h2>
</td>
</tr>
</table>
<hr>
<h2>Contents</h2>
<dl class="page-index">
<dt><a href="#introduction">Introduction</a></dt>
<dt><a href="#functions">Functions</a></dt>
<dl class="page-index">
<dt><a href="#register_ptr_to_python-spec">register_ptr_to_python</a></dt>
</dl>
<dt><a href="#examples">Example(s)</a></dt>
</dl>
<hr>
<h2><a name="introduction"></a>Introduction</h2>
<p>
<code>&lt;boost/python/register_ptr_to_python.hpp&gt;</code>
supplies <code>register_ptr_to_python</code>, a function template
which registers a conversion for smart pointers to Python. The
resulting Python object holds a copy of the converted smart pointer,
but behaves as though it were a wrapped copy of the pointee. If
the pointee type has virtual functions and the class representing
its dynamic (most-derived) type has been wrapped, the Python object
will be an instance of the wrapper for the most-derived type. More than
one smart pointer type for a pointee's class can be registered.
</p>
<p>
Note that in order to convert a Python <code>X</code> object to a
<code>smart_ptr&lt;X&gt;&amp;</code> (non-const reference), the embedded C++
object must be held by <code>smart_ptr&lt;X&gt;</code>, and that when wrapped
objects are created by calling the constructor from Python, how they are held
is determined by the <code>HeldType</code> parameter to
<code>class_&lt;...&gt;</code> instances.
</p>
<h2><a name="functions"></a>Functions</h2>
<pre>
<a name="register_ptr_to_python-spec">template &lt;class P&gt;
void register_ptr_to_python()
</pre>
<dl class="function-semantics">
<dt><b>Requires:</b> <code>P</code> is <a href="Dereferenceable.html#Dereferenceable-concept">Dereferenceable</a>.
</dt>
<dt><b>Effects:</b> Allows conversions to-python of <code>P</code>
instances.
</dt>
</dl>
<h2><a name="examples"></a>Example(s)</h2>
<h3>C++ Wrapper Code</h3>
Here is an example of a module that contains a class <code>A</code> with
virtual functions and some functions that work with
<code>boost::shared_ptr&lt;A&gt;</code>.
<pre>
struct A
{
virtual int f() { return 0; }
};
shared_ptr&lt;A&gt; New() { return shared_ptr&lt;A&gt;( new A() ); }
int Ok( const shared_ptr&lt;A&gt;&amp; a ) { return a-&gt;f(); }
int Fail( shared_ptr&lt;A&gt;&amp; a ) { return a-&gt;f(); }
struct A_Wrapper: A
{
A_Wrapper(PyObject* self_): self(self_) {}
int f() { return call_method&lt;int&gt;(self, "f"); }
int default_f() { return A::f(); }
PyObject* self;
};
BOOST_PYTHON_MODULE(register_ptr)
{
class_&lt;A, A_Wrapper&gt;("A")
.def("f", &amp;A::f, &amp;A_Wrapper::default_f)
;
def("New", &amp;New);
def("Ok", &amp;Call);
def("Fail", &amp;Fail);
register_ptr_to_python&lt; shared_ptr&lt;A&gt; &gt;();
}
</pre>
<h3>Python Code</h3>
<pre>
&gt;&gt;&gt; from register_ptr import *
&gt;&gt;&gt; a = A()
&gt;&gt;&gt; Ok(a) # ok, passed as shared_ptr&lt;A&gt;
0
&gt;&gt;&gt; Fail(a) # passed as shared_ptr&lt;A&gt;&amp;, and was created in Python!
Traceback (most recent call last):
File "&lt;stdin&gt;", line 1, in ?
TypeError: bad argument type for built-in operation
&gt;&gt;&gt;
&gt;&gt;&gt; na = New() # now "na" is actually a shared_ptr&lt;A&gt;
&gt;&gt;&gt; Ok(a)
0
&gt;&gt;&gt; Fail(a)
0
&gt;&gt;&gt;
</pre>
If <code>shared_ptr&lt;A&gt;</code> is registered as follows:
<pre>
class_&lt;A, A_Wrapper, shared_ptr&lt;A&gt; &gt;("A")
.def("f", &amp;A::f, &amp;A_Wrapper::default_f)
;
</pre>
There will be an error when trying to convert <code>shared_ptr&lt;A&gt;</code> to
<code>shared_ptr&lt;A_Wrapper&gt;</code>:
<pre>
&gt;&gt;&gt; a = New()
Traceback (most recent call last):
File "&lt;stdin&gt;", line 1, in ?
TypeError: No to_python (by-value) converter found for C++ type: class boost::shared_ptr&lt;struct A&gt;
&gt;&gt;&gt;
</pre>
<p>Revised
<!--webbot bot="Timestamp" S-Type="EDITED" S-Format="%d %B, %Y" startspan -->
24 Jun, 2003
<!--webbot bot="Timestamp" endspan i-checksum="39359" -->
</p>
<p><i>&copy; Copyright <a href="../../../../people/dave_abrahams.htm">Dave Abrahams</a>
2002. All Rights Reserved.</i></p>
</body>
</html>

219
doc/v2/return_arg.html Executable file
View File

@@ -0,0 +1,219 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta name="generator" content=
"HTML Tidy for Cygwin (vers 1st April 2002), see www.w3.org">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link rel="stylesheet" type="text/css" href="../boost.css">
<title>Boost.Python - &lt;boost/python/return_arg.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="../../../../c++boost.gif" 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/return_arg.hpp&gt;</h2>
</td>
</tr>
</table>
<hr>
<h2>Contents</h2>
<dl class="page-index">
<dt><a href="#introduction">Introduction</a></dt>
<dt><a href="#classes">Classes</a></dt>
<dd>
<dl class="page-index">
<dt><a href="#return_arg-spec">Class Template
<code>return_arg</code></a></dt>
<dd>
<dl class="page-index">
<dt><a href="#return_arg-spec-synopsis">Class Template
<code>return_arg</code> synopsis</a></dt>
<dt><a href="#return_arg-spec-statics">Class
<code>return_arg</code> static functions</a></dt>
</dl>
</dd>
<dt><a href="#return_self-spec">Class Template
<code>return_self</code></a></dt>
</dl>
</dd>
<dt><a href="#examples">Example</a></dt>
</dl>
<hr>
<h2><a name="introduction"></a>Introduction</h2>
<code>return_arg</code> and <code>return_self</code> instantiations are
models of <a href="CallPolicies.html">CallPolicies</a> which return the
specified argument parameter (usually <code>*this</code>) of a wrapped
(member) function.
<h2><a name="classes"></a>Classes</h2>
<h3><a name="return_arg-spec"></a>Class template
<code>return_arg</code></h3>
<table border="1" summary="return_arg template parameters">
<caption>
<b><code>return_arg</code> template parameters</b>
</caption>
<tr>
<th>Parameter</th>
<th>Requirements</th>
<th>Description</th>
<th>Default</th>
</tr>
<tr>
<td><code>arg_pos</code></td>
<td>A positive compile-time constant of type
<code>std::size_t</code>.</td>
<td>the position of the argument to be returned.</td>
<td>1</td>
</tr>
<tr>
<td><code>Base</code></td>
<td>A model of <a href="CallPolicies.html">CallPolicies</a></td>
<td>Used for policy composition. Any <code>result_converter</code> it
supplies will be overridden by <code>return_arg</code>, but its
<code>precall</code> and <code>postcall</code> policies are composed
as described here <a href=
"CallPolicies.html#composition">CallPolicies</a>.</td>
<td><code><a href=
"default_call_policies.html#default_call_policies-spec">default_call_policies</a></code></td>
</tr>
</table>
<h4><a name="return_arg-spec-synopsis"></a>Class template
<code>return_arg</code> synopsis</h4>
<pre>
namespace boost { namespace python
{
template &lt;size_t arg_pos=1, class Base = default_call_policies&gt;
struct return_arg : Base
{
static PyObject* postcall(PyObject*, PyObject* result);
struct result_converter{ template &lt;class T&gt; struct apply; };
};
}}
</pre>
<h4><a name="return_arg-spec-statics"></a>Class <code>return_arg</code>
static functions</h4>
<pre>
PyObject* postcall(PyObject* args, PyObject* result);
</pre>
<dl class="function-semantics">
<dt><b>Requires:</b> <code><a href=
"http://www.python.org/doc/2.2/api/tupleObjects.html#l2h-476">PyTuple_Check</a>(args)
!= 0</code> and <code>PyTuple_Size(args) != 0</code></dt>
<dt><b>Returns:</b> <code>PyTuple_GetItem(args,arg_pos-1)</code></dt>
</dl>
<h3><a name="return_self-spec"></a>Class template
<code>return_self</code></h3>
<h4>Class template <code>return_self</code> synopsis:</h4>
<pre>
namespace boost { namespace python
{
template &lt;class Base = default_call_policies&gt;
struct return_self
: return_arg&lt;1,Base&gt;
{};
}}
</pre>
<h2><a name="examples"></a>Example</h2>
<h3>C++ module definition</h3>
<pre>
#include &lt;boost/python/module.hpp&gt;
#include &lt;boost/python/class.hpp&gt;
#include &lt;boost/python/return_arg.hpp&gt;
struct Widget
{
Widget() :sensitive_(true){}
bool get_sensitive() const { return sensitive_; }
void set_sensitive(bool s) { this-&gt;sensitive_ = s; }
private:
bool sensitive_;
};
struct Label : Widget
{
Label() {}
std::string get_label() const { return label_; }
void set_label(const std::string &amp;l){ label_ = l; }
private:
std::string label_;
};
using namespace boost::python;
BOOST_PYTHON_MODULE(return_self_ext)
{
class_&lt;widget&gt;("Widget")
.def("sensitive", &amp;Widget::get_sensitive)
.def("sensitive", &amp;Widget::set_sensitive, return_self&lt;&gt;())
;
class_&lt;Label, bases&lt;Widget&gt; &gt;("Label")
.def("label", &amp;Label::get_label)
.def("label", &amp;Label::set_label, return_self&lt;&gt;())
;
}
</pre>
<h3>Python code</h3>
<pre>
&gt;&gt;&gt; from return_self_ext import *
&gt;&gt;&gt; l1 = Label().label("foo").sensitive(false)
&gt;&gt;&gt; l2 = Label().sensitive(false).label("foo")
</pre>
<p>Revised
<!--webbot bot="Timestamp" S-Type="EDITED" S-Format="%d %B, %Y" startspan -->
19 July, 2003 <!--webbot bot="Timestamp" endspan i-checksum="39359" -->
</p>
<p><i>&copy; Copyright <a href=
"../../../../people/dave_abrahams.htm">Dave Abrahams</a> and Nikolay
Mladenov 2003. All Rights Reserved.</i></p>
</body>
</html>

View File

@@ -86,7 +86,7 @@
"ResultConverter.html#ResultConverterGenerator-concept">ResultConverterGenerator</a></td>
<td>A model of <a href=
"ResultConverterGenerator.html">ResultConverterGenerator</a>.</td>
"ResultConverter.html#ResultConverterGenerator-concept">ResultConverterGenerator</a>.</td>
</tr>
<tr>

View File

@@ -67,8 +67,10 @@
<p>Exposes the <a href=
"http://www.python.org/dev/doc/devel/lib/string-methods.html">string
methods</a> of Python's built-in <code>str</code> type. The
semantics of the constructors and member functions defined below
can be fully understood by reading the <a href=
semantics of the constructors and member functions defined below,
except for the two-argument constructors which construct str
objects from a range of characters, can be fully understood by
reading the <a href=
"ObjectWrapper.html#TypeWrapper-concept">TypeWrapper</a> concept
definition. Since <code>str</code> is publicly derived from
<code><a href="object.html#object-spec">object</a></code>, the
@@ -85,7 +87,10 @@ namespace boost { namespace python
public:
str(); // new str
str(const char* s); // new str
str(char const* s); // new str
str(char const* start, char const* finish); // new str
str(char const* start, std::size_t length); // new str
template &lt;class T&gt;
explicit str(T const&amp; other);

View File

@@ -60,8 +60,8 @@ namespace boost { namespace python
template &lt;class T&gt;
struct to_python_value
{
typedef typename <a href="../../../type_traits/index.htm#transformations">add_reference</a>&lt;
typename <a href="../../../type_traits/index.htm#transformations">add_const</a>&lt;T&gt;::type
typedef typename <a href="../../../type_traits/index.html#transformations">add_reference</a>&lt;
typename <a href="../../../type_traits/index.html#transformations">add_const</a>&lt;T&gt;::type
&gt;::type argument_type;
static bool convertible();

View File

@@ -1,5 +1,8 @@
# Specify our location in the boost project hierarchy
subproject libs/python/example ;
# Copyright David Abrahams 2003. See accompanying LICENSE for terms
# and conditions of use.
# This is the top of our own project tree
project-root ;
# Declares the following targets:
#
@@ -19,18 +22,17 @@ subproject libs/python/example ;
#
# Include definitions needed for Python modules
SEARCH on python.jam = $(BOOST_BUILD_PATH) ;
include python.jam ;
import python ;
# ----- getting_started1 -------
# Declare a Python extension called getting_started1
extension getting_started1
: # sources
getting_started1.cpp
: # sources
getting_started1.cpp
# dependencies
<dll>../build/boost_python
# requirements and dependencies for Boost.Python extensions
<template>@boost/libs/python/build/extension
;
# Declare a test for the extension module
@@ -49,8 +51,8 @@ extension getting_started2
: # sources
getting_started2.cpp
# dependencies
<dll>../build/boost_python
# requirements and dependencies for Boost.Python extensions
<template>@boost/libs/python/build/extension
;
# Declare a test for the extension module

View File

@@ -2,11 +2,9 @@
use-project /boost/python : ../build ;
project
: requirements <library>@/boost/python/boost_python
: requirements <library>/boost/python//boost_python
;
python-extension getting_started1 : getting_started1.cpp : <shared>true ;
python-extension getting_started2 : getting_started2.cpp : <shared>true ;
python-extension getting_started1 : getting_started1.cpp : <link>shared ;
python-extension getting_started2 : getting_started2.cpp : <link>shared ;
exe embedding_test : embedding_test.cpp : <define>BOOST_PYTHON_DYNAMIC_LIB <shared>true ;

7
example/Jamrules Executable file
View File

@@ -0,0 +1,7 @@
# Copyright David Abrahams 2003. See accompanying LICENSE for terms
# and conditions of use.
# Edit this path to point at the root directory of your Boost
# installation. Absolute paths work, too.
path-global BOOST_ROOT : ../../.. ;
project boost : $(BOOST_ROOT) ;

6
example/boost-build.jam Executable file
View File

@@ -0,0 +1,6 @@
# Copyright David Abrahams 2003. See accompanying LICENSE for terms
# and conditions of use.
# Edit this path to point at the tools/build/v1 subdirectory of your
# Boost installation. Absolute paths work, too.
boost-build ../../../tools/build/v1 ;

View File

@@ -0,0 +1,18 @@
r'''>>> import getting_started1
>>> print getting_started1.greet()
hello, world
>>> number = 11
>>> print number, '*', number, '=', getting_started1.square(number)
11 * 11 = 121
'''
def run(args = None):
if args is not None:
import sys
sys.argv = args
import doctest, test_getting_started1
return doctest.testmod(test_getting_started1)
if __name__ == '__main__':
import sys
sys.exit(run()[0])

View File

@@ -0,0 +1,31 @@
r'''>>> from getting_started2 import *
>>> hi = hello('California')
>>> hi.greet()
'Hello from California'
>>> invite(hi)
'Hello from California! Please come soon!'
>>> hi.invite()
'Hello from California! Please come soon!'
>>> class wordy(hello):
... def greet(self):
... return hello.greet(self) + ', where the weather is fine'
...
>>> hi2 = wordy('Florida')
>>> hi2.greet()
'Hello from Florida, where the weather is fine'
>>> invite(hi2)
'Hello from Florida! Please come soon!'
'''
def run(args = None):
if args is not None:
import sys
sys.argv = args
import doctest, test_getting_started2
return doctest.testmod(test_getting_started2)
if __name__ == '__main__':
import sys
sys.exit(run()[0])

View File

@@ -5,8 +5,7 @@
subproject libs/python/example/tutorial ;
# Include definitions needed for Python modules
SEARCH on python.jam = $(BOOST_BUILD_PATH) ;
include python.jam ;
import python ;
extension hello # Declare a Python extension called hello
: hello.cpp # source

View File

@@ -43,13 +43,16 @@
# include <boost/python/object.hpp>
# include <boost/python/object_protocol.hpp>
# include <boost/python/object_protocol_core.hpp>
# include <boost/python/operators.hpp>
# include <boost/python/opaque_pointer_converter.hpp>
# include <boost/python/operators.hpp>
# include <boost/python/other.hpp>
# include <boost/python/overloads.hpp>
# include <boost/python/pointee.hpp>
# include <boost/python/pure_virtual.hpp>
# include <boost/python/ptr.hpp>
# include <boost/python/reference_existing_object.hpp>
# include <boost/python/register_ptr_to_python.hpp>
# include <boost/python/return_arg.hpp>
# include <boost/python/return_internal_reference.hpp>
# include <boost/python/return_opaque_pointer.hpp>
# include <boost/python/return_value_policy.hpp>

View File

@@ -26,51 +26,25 @@ struct arg_from_python<PyObject*>
{
typedef PyObject* result_type;
arg_from_python(PyObject*) {}
arg_from_python(PyObject* p) : m_source(p) {}
bool convertible() const { return true; }
PyObject* operator()(PyObject* source) const { return source; }
PyObject* operator()() const { return m_source; }
private:
PyObject* m_source;
};
template <>
struct arg_from_python<PyObject* const&>
{
typedef PyObject* const& result_type;
arg_from_python(PyObject*) {}
arg_from_python(PyObject* p) : m_source(p) {}
bool convertible() const { return true; }
PyObject*const& operator()(PyObject*const& source) const { return source; }
PyObject*const& operator()() const { return m_source; }
private:
PyObject* m_source;
};
namespace detail
{
//
// Meta-iterators for use with caller<>
//
// temporary hack
template <class T> struct nullary : T
{
nullary(PyObject* x) : T(x), m_p(x) {}
typename T::result_type operator()() { return this->T::operator()(m_p); }
PyObject* m_p;
};
// An MPL metafunction class which returns arg_from_python<ArgType>
struct gen_arg_from_python
{
template <class ArgType> struct apply
{
typedef nullary<arg_from_python<ArgType> > type;
};
};
// An MPL iterator over an endless sequence of gen_arg_from_python
struct args_from_python
{
typedef gen_arg_from_python type;
typedef args_from_python next;
};
}
//
// implementations
//

View File

@@ -23,18 +23,21 @@
# include <boost/preprocessor/iteration/local.hpp>
# include <boost/python/detail/mpl_lambda.hpp>
# include <boost/python/object_core.hpp>
# include <boost/mpl/bool.hpp>
# include <cstddef>
# include <algorithm>
namespace boost { namespace python {
typedef detail::keywords<1> arg;
namespace detail
{
template <std::size_t nkeywords>
struct keywords
struct keywords_base
{
BOOST_STATIC_CONSTANT(std::size_t, size = nkeywords);
@@ -42,9 +45,62 @@ namespace detail
{
return keyword_range(elements, elements + nkeywords);
}
keyword elements[nkeywords];
keywords<nkeywords+1>
operator,(arg const &k) const;
keywords<nkeywords + 1>
operator,(char const *name) const;
};
template <std::size_t nkeywords>
struct keywords : keywords_base<nkeywords>
{
};
template <>
struct keywords<1> : keywords_base<1>
{
explicit keywords(char const *name)
{
elements[0].name = name;
}
template <class T>
arg& operator=(T const& value)
{
object z(value);
elements[0].default_value = handle<>(python::borrowed(object(value).ptr()));
return *this;
}
operator detail::keyword const&() const
{
return elements[0];
}
};
template <std::size_t nkeywords>
inline
keywords<nkeywords+1>
keywords_base<nkeywords>::operator,(arg const &k) const
{
keywords<nkeywords> const& l = *static_cast<keywords<nkeywords> const*>(this);
python::detail::keywords<nkeywords+1> res;
std::copy(l.elements, l.elements+nkeywords, res.elements);
res.elements[nkeywords] = k.elements[0];
return res;
}
template <std::size_t nkeywords>
inline
keywords<nkeywords + 1>
keywords_base<nkeywords>::operator,(char const *name) const
{
return this->operator,(python::arg(name));
}
# ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
template<typename T>
@@ -97,6 +153,11 @@ namespace detail
# endif
}
inline detail::keywords<1> args(char const* name)
{
return detail::keywords<1>(name);
}
# define BOOST_PYTHON_ASSIGN_NAME(z, n, _) result.elements[n].name = name##n;
# define BOOST_PP_LOCAL_MACRO(n) \
inline detail::keywords<n> args(BOOST_PP_ENUM_PARAMS_Z(1, n, char const* name)) \
@@ -105,7 +166,7 @@ inline detail::keywords<n> args(BOOST_PP_ENUM_PARAMS_Z(1, n, char const* name))
BOOST_PP_REPEAT_1(n, BOOST_PYTHON_ASSIGN_NAME, _) \
return result; \
}
# define BOOST_PP_LOCAL_LIMITS (1, BOOST_PYTHON_MAX_ARITY)
# define BOOST_PP_LOCAL_LIMITS (2, BOOST_PYTHON_MAX_ARITY)
# include BOOST_PP_LOCAL_ITERATE()
}} // namespace boost::python

View File

@@ -19,6 +19,10 @@ namespace detail
{
struct keyword
{
keyword(char const* name_=0)
: name(name_)
{}
char const* name;
handle<> default_value;
};

View File

@@ -40,7 +40,10 @@ namespace boost { namespace python {
# endif // CALL_DWA2002411_HPP
#elif BOOST_PP_ITERATION_DEPTH() == 1
# line BOOST_PP_LINE(__LINE__, call.hpp)
# if !(BOOST_WORKAROUND(__MWERKS__, > 0x3100) \
&& BOOST_WORKAROUND(__MWERKS__, BOOST_TESTED_AT(0x3201)))
# line BOOST_PP_LINE(__LINE__, call.hpp)
# endif
# define N BOOST_PP_ITERATION()

View File

@@ -39,7 +39,10 @@ namespace boost { namespace python {
# endif // CALL_METHOD_DWA2002411_HPP
#elif BOOST_PP_ITERATION_DEPTH() == 1
# line BOOST_PP_LINE(__LINE__, call_method.hpp)
# if !(BOOST_WORKAROUND(__MWERKS__, > 0x3100) \
&& BOOST_WORKAROUND(__MWERKS__, BOOST_TESTED_AT(0x3201)))
# line BOOST_PP_LINE(__LINE__, call_method.hpp)
# endif
# define N BOOST_PP_ITERATION()

View File

@@ -20,6 +20,18 @@
# include <boost/python/init.hpp>
# include <boost/python/args_fwd.hpp>
# include <boost/python/object/select_holder.hpp>
# include <boost/python/object/class_wrapper.hpp>
# include <boost/python/object/make_instance.hpp>
# include <boost/python/object/pickle_support.hpp>
# include <boost/python/object/add_to_namespace.hpp>
# include <boost/python/object/class_converters.hpp>
# include <boost/python/detail/overloads_fwd.hpp>
# include <boost/python/detail/operator_id.hpp>
# include <boost/python/detail/def_helper.hpp>
# include <boost/python/detail/force_instantiate.hpp>
# include <boost/type_traits/is_same.hpp>
# include <boost/type_traits/is_convertible.hpp>
# include <boost/type_traits/is_member_function_pointer.hpp>
@@ -30,26 +42,19 @@
# include <boost/mpl/bool.hpp>
# include <boost/mpl/not.hpp>
# include <boost/mpl/or.hpp>
# include <boost/python/object/select_holder.hpp>
# include <boost/python/object/class_wrapper.hpp>
# include <boost/python/object/make_instance.hpp>
# include <boost/python/object/pickle_support.hpp>
# include <boost/python/object/add_to_namespace.hpp>
# include <boost/python/object/class_converters.hpp>
# include <boost/python/detail/string_literal.hpp>
# include <boost/python/detail/overloads_fwd.hpp>
# include <boost/python/detail/operator_id.hpp>
# include <boost/python/detail/member_function_cast.hpp>
# include <boost/python/detail/def_helper.hpp>
# include <boost/python/detail/force_instantiate.hpp>
# include <boost/mpl/vector/vector10.hpp>
# include <boost/utility.hpp>
# include <boost/detail/workaround.hpp>
# if BOOST_WORKAROUND(__MWERKS__, <= 0x3004) || BOOST_WORKAROUND(__GNUC__, < 3)
# if BOOST_WORKAROUND(__MWERKS__, <= 0x3004) \
/* pro9 reintroduced the bug */ \
|| (BOOST_WORKAROUND(__MWERKS__, > 0x3100) \
&& BOOST_WORKAROUND(__MWERKS__, BOOST_TESTED_AT(0x3201))) \
|| BOOST_WORKAROUND(__GNUC__, < 3)
# define BOOST_PYTHON_NO_MEMBER_POINTER_ORDERING 1
# endif
# ifdef BOOST_PYTHON_NO_MEMBER_POINTER_ORDERING
@@ -59,6 +64,8 @@
namespace boost { namespace python {
template <class DerivedVisitor> class def_visitor;
enum no_init_t { no_init };
namespace detail
@@ -86,9 +93,6 @@ namespace detail
template <class T1, class T2, class T3>
struct has_noncopyable;
template <detail::operator_id, class L, class R>
struct operator_;
// Register to_python converters for a class T. The first argument
// will be mpl::true_ unless noncopyable was specified as a
// class_<...> template parameter. The 2nd argument is a pointer to
@@ -108,7 +112,27 @@ namespace detail
SelectHolder::register_();
}
# ifdef BOOST_PYTHON_NO_MEMBER_POINTER_ORDERING
//
// register_wrapper_class -- register the relationship between a
// virtual function callback wrapper class and the class being
// wrapped.
//
template <class T>
inline void register_wrapper_class_impl(T*, T*, int) {}
template <class Wrapper, class T>
inline void register_wrapper_class_impl(Wrapper*, T*, ...)
{
objects::register_class_from_python<Wrapper, mpl::vector1<T> >();
objects::copy_class_object(type_id<T>(), type_id<Wrapper>());
}
template <class Held, class T>
inline void register_wrapper_class(Held* = 0, T* = 0)
{
register_wrapper_class_impl((Held*)0, (T*)0, 0);
}
template <class T>
struct is_data_member_pointer
: mpl::and_<
@@ -116,15 +140,17 @@ namespace detail
, mpl::not_<is_member_function_pointer<T> >
>
{};
# define BOOST_PYTHON_DATA_MEMBER_HELPER , detail::is_data_member_pointer<D>()
# ifdef BOOST_PYTHON_NO_MEMBER_POINTER_ORDERING
# define BOOST_PYTHON_DATA_MEMBER_HELPER(D) , detail::is_data_member_pointer<D>()
# define BOOST_PYTHON_YES_DATA_MEMBER , mpl::true_
# define BOOST_PYTHON_NO_DATA_MEMBER , mpl::false_
# elif defined(BOOST_NO_FUNCTION_TEMPLATE_ORDERING)
# define BOOST_PYTHON_DATA_MEMBER_HELPER , 0
# define BOOST_PYTHON_DATA_MEMBER_HELPER(D) , 0
# define BOOST_PYTHON_YES_DATA_MEMBER , int
# define BOOST_PYTHON_NO_DATA_MEMBER , ...
# else
# define BOOST_PYTHON_DATA_MEMBER_HELPER
# define BOOST_PYTHON_DATA_MEMBER_HELPER(D)
# define BOOST_PYTHON_YES_DATA_MEMBER
# define BOOST_PYTHON_NO_DATA_MEMBER
# endif
@@ -191,14 +217,16 @@ class class_ : public objects::class_base
typedef class_<T,X1,X2,X3> self;
BOOST_STATIC_CONSTANT(bool, is_copyable = (!detail::has_noncopyable<X1,X2,X3>::value));
// held_type - either T, a class derived from T or a smart pointer
// to a (class derived from) T.
typedef typename detail::select_held_type<
X1, typename detail::select_held_type<
X2, typename detail::select_held_type<
X3
>::type>::type>::type held_type;
typedef objects::select_holder<T,held_type> holder_selector;
typedef objects::select_holder<T,held_type> select_holder;
private: // types
typedef typename detail::select_bases<X1
@@ -244,9 +272,8 @@ class class_ : public objects::class_base
inline class_(char const* name, init_base<DerivedT> const& i)
: base(name, id_vector::size, id_vector().ids)
{
this->register_();
define_init(*this, i.derived());
this->set_instance_size(holder_selector::additional_size());
this->register_holder();
this->def(i);
}
// Construct with class name, docstring and init<> function
@@ -254,24 +281,23 @@ class class_ : public objects::class_base
inline class_(char const* name, char const* doc, init_base<DerivedT> const& i)
: base(name, id_vector::size, id_vector().ids, doc)
{
this->register_();
define_init(*this, i.derived());
this->set_instance_size(holder_selector::additional_size());
this->register_holder();
this->def(i);
}
public: // member functions
// Define additional constructors
template <class DerivedT>
self& def(init_base<DerivedT> const& i)
// Generic visitation
template <class Derived>
self& def(def_visitor<Derived> const& visitor)
{
define_init(*this, i.derived());
visitor.visit(*this);
return *this;
}
// Wrap a member function or a non-member function which can take
// a T, T cv&, or T cv* as its first parameter, or a callable
// python object.
// a T, T cv&, or T cv* as its first parameter, a callable
// python object, or a generic visitor.
template <class F>
self& def(char const* name, F f)
{
@@ -312,94 +338,59 @@ class class_ : public objects::class_base
return *this;
}
template <detail::operator_id id, class L, class R>
self& def(detail::operator_<id,L,R> const& op)
{
typedef detail::operator_<id,L,R> op_t;
return this->def(op.name(), &op_t::template apply<T>::execute);
}
//
// Data member access
//
template <class D>
self& def_readonly(char const* name, D const& d)
{
return this->def_readonly_impl(name, d BOOST_PYTHON_DATA_MEMBER_HELPER);
return this->def_readonly_impl(name, d BOOST_PYTHON_DATA_MEMBER_HELPER(D));
}
template <class D>
self& def_readwrite(char const* name, D const& d)
{
return this->def_readwrite_impl(name, d BOOST_PYTHON_DATA_MEMBER_HELPER);
return this->def_readwrite_impl(name, d BOOST_PYTHON_DATA_MEMBER_HELPER(D));
}
template <class D>
self& def_readonly(char const* name, D& d)
{
return this->def_readonly_impl(name, d BOOST_PYTHON_DATA_MEMBER_HELPER);
return this->def_readonly_impl(name, d BOOST_PYTHON_DATA_MEMBER_HELPER(D));
}
template <class D>
self& def_readwrite(char const* name, D& d)
{
return this->def_readwrite_impl(name, d BOOST_PYTHON_DATA_MEMBER_HELPER);
return this->def_readwrite_impl(name, d BOOST_PYTHON_DATA_MEMBER_HELPER(D));
}
// Property creation
template <class Get>
self& add_property(char const* name, Get fget)
{
base::add_property(
name
, object(
detail::member_function_cast<T,Get>::stage1(fget).stage2((T*)0).stage3(fget)
)
);
base::add_property(name, this->make_getter(fget));
return *this;
}
template <class Get, class Set>
self& add_property(char const* name, Get fget, Set fset)
{
base::add_property(
name
, object(
detail::member_function_cast<T,Get>::stage1(fget).stage2((T*)0).stage3(fget)
)
, object(
detail::member_function_cast<T,Set>::stage1(fset).stage2((T*)0).stage3(fset)
)
);
base::add_property(name, this->make_getter(fget), this->make_setter(fset));
return *this;
}
template <class Get>
self& add_static_property(char const* name, Get fget)
{
base::add_static_property(
name
, object(
detail::member_function_cast<T,Get>::stage1(fget).stage2((T*)0).stage3(fget)
)
);
base::add_static_property(name, object(fget));
return *this;
}
template <class Get, class Set>
self& add_static_property(char const* name, Get fget, Set fset)
{
base::add_static_property(
name
, object(
detail::member_function_cast<T,Get>::stage1(fget).stage2((T*)0).stage3(fget)
)
, object(
detail::member_function_cast<T,Set>::stage1(fset).stage2((T*)0).stage3(fset)
)
);
base::add_static_property(name, object(fget), object(fset));
return *this;
}
@@ -431,82 +422,137 @@ class class_ : public objects::class_base
}
private: // helper functions
// Builds a method for this class around the given [member]
// function pointer or object, appropriately adjusting the type of
// the first signature argument so that if f is a member of a
// (possibly not wrapped) base class of T, an lvalue argument of
// type T will be required.
//
// @group PropertyHelpers {
template <class F>
object make_getter(F f)
{
typedef typename api::is_object_operators<F>::type is_obj_or_proxy;
return this->make_fn_impl(
f, is_obj_or_proxy(), (char*)0, detail::is_data_member_pointer<F>()
);
}
template <class F>
object make_setter(F f)
{
typedef typename api::is_object_operators<F>::type is_obj_or_proxy;
return this->make_fn_impl(
f, is_obj_or_proxy(), (int*)0, detail::is_data_member_pointer<F>()
);
}
template <class F>
object make_fn_impl(F const& f, mpl::false_, void*, mpl::false_)
{
return python::make_function(f, default_call_policies(), detail::get_signature(f, (T*)0));
}
template <class D, class B>
object make_fn_impl(D B::*pm_, mpl::false_, char*, mpl::true_)
{
D T::*pm = pm_;
return python::make_getter(pm);
}
template <class D, class B>
object make_fn_impl(D B::*pm_, mpl::false_, int*, mpl::true_)
{
D T::*pm = pm_;
return python::make_setter(pm);
}
template <class F>
object make_fn_impl(F const& x, mpl::true_, void*, mpl::false_)
{
return x;
}
// }
template <class D, class B>
self& def_readonly_impl(
char const* name, D B::*pm_ BOOST_PYTHON_YES_DATA_MEMBER)
{
D T::*pm = pm_;
return this->add_property(name, make_getter(pm));
return this->add_property(name, pm_);
}
template <class D, class B>
self& def_readwrite_impl(
char const* name, D B::*pm_ BOOST_PYTHON_YES_DATA_MEMBER)
{
D T::*pm = pm_;
return this->add_property(name, make_getter(pm), make_setter(pm));
return this->add_property(name, pm_, pm_);
}
template <class D>
self& def_readonly_impl(
char const* name, D& d BOOST_PYTHON_NO_DATA_MEMBER)
{
return this->add_static_property(name, make_getter(d));
return this->add_static_property(name, python::make_getter(d));
}
template <class D>
self& def_readwrite_impl(
char const* name, D& d BOOST_PYTHON_NO_DATA_MEMBER)
{
return this->add_static_property(name, make_getter(d), make_setter(d));
return this->add_static_property(name, python::make_getter(d), python::make_setter(d));
}
inline void register_() const;
inline void register_holder();
//
// These two overloads discriminate between def() as applied to
// things which are already wrapped into callable python::object
// instances and everything else.
// These two overloads discriminate between def() as applied to a
// generic visitor and everything else.
//
template <class F, class A1>
// @group def_impl {
template <class Helper, class LeafVisitor, class Visitor>
inline void def_impl(
char const* name
, F f
, detail::def_helper<A1> const& helper
, object const*)
, LeafVisitor
, Helper const& helper
, def_visitor<Visitor> const* v
)
{
// It's too late to specify anything other than docstrings, if
// the callable object is already wrapped.
BOOST_STATIC_ASSERT(
(is_same<char const*,A1>::value
|| detail::is_string_literal<A1>::value));
objects::add_to_namespace(*this, name, f, helper.doc());
v->visit(*this, name, helper);
}
template <class Fn, class Helper>
inline void def_impl(
char const* name
, Fn fn
, Helper const& helper
, ...)
, Fn fn
, Helper const& helper
, ...
)
{
objects::add_to_namespace(
*this, name,
make_function(
// This bit of nastiness casts F to a member function of T if possible.
detail::member_function_cast<T,Fn>::stage1(fn).stage2((T*)0).stage3(fn)
, helper.policies(), helper.keywords())
, helper.doc());
*this
, name
, make_function(
fn
, helper.policies()
, helper.keywords()
, detail::get_signature(fn, (T*)0)
)
, helper.doc()
);
this->def_default(name, fn, helper, mpl::bool_<Helper::has_default_implementation>());
}
// }
//
// These two overloads handle the definition of default
// implementation overloads for virtual functions. The second one
// handles the case where no default implementation was specified.
//
// @group def_default {
template <class Fn, class Helper>
inline void def_default(
char const* name
@@ -527,6 +573,7 @@ class class_ : public objects::class_base
template <class Fn, class Helper>
inline void def_default(char const*, Fn, Helper const&, mpl::bool_<false>)
{ }
// }
//
// These two overloads discriminate between def() as applied to
@@ -534,6 +581,7 @@ class class_ : public objects::class_base
// BOOST_PYTHON_FUNCTION_OVERLOADS(). The final argument is used to
// discriminate.
//
// @group def_maybe_overloads {
template <class OverloadsT, class SigT>
void def_maybe_overloads(
char const* name
@@ -556,11 +604,14 @@ class class_ : public objects::class_base
, ...)
{
this->def_impl(
name, fn
, detail::def_helper<A1>(a1)
, &fn);
name
, fn
, detail::def_helper<A1>(a1)
, &fn
);
}
// }
};
@@ -574,27 +625,31 @@ inline void class_<T,X1,X2,X3>::register_() const
{
objects::register_class_from_python<T,bases>();
typedef BOOST_DEDUCED_TYPENAME select_holder::held_type held_t;
detail::register_wrapper_class<held_t,T>();
detail::register_class_to_python<T>(
mpl::bool_<is_copyable>()
# if BOOST_WORKAROUND(__MWERKS__, <= 0x2407)
, holder_selector::execute((held_type*)0)
# else
, BOOST_DEDUCED_TYPENAME holder_selector::type()
# endif
);
, select_holder()
);
}
template <class T, class X1, class X2, class X3>
inline void class_<T,X1,X2,X3>::register_holder()
{
this->register_();
typedef typename select_holder::type holder;
this->set_instance_size(
objects::additional_instance_size<holder>::value
);
}
template <class T, class X1, class X2, class X3>
inline class_<T,X1,X2,X3>::class_(char const* name, char const* doc)
: base(name, id_vector::size, id_vector().ids, doc)
{
this->register_();
this->set_instance_size(holder_selector::additional_size());
# if BOOST_WORKAROUND(__MWERKS__, <= 0x2407)
holder_selector::execute((held_type*)0).assert_default_constructible();
# else
holder_selector::type::assert_default_constructible();
# endif
this->register_holder();
select_holder::assert_default_constructible();
this->def(init<>());
}
@@ -626,18 +681,18 @@ namespace detail
{};
template <class T, class Prev>
struct select_held_type
: mpl::if_<
mpl::or_<
specifies_bases<T>
, is_same<T,noncopyable>
>
, Prev
, T
>
{
};
template <class T, class Prev>
struct select_held_type
: mpl::if_<
mpl::or_<
specifies_bases<T>
, is_same<T,noncopyable>
>
, Prev
, T
>
{
};
}
}} // namespace boost::python

View File

@@ -44,7 +44,7 @@ struct pointer_cref_arg_from_python
typedef T result_type;
pointer_cref_arg_from_python(PyObject*);
T operator()(PyObject*) const;
T operator()() const;
bool convertible() const;
private: // storage for a U*
@@ -74,7 +74,7 @@ struct pointer_arg_from_python : arg_lvalue_from_python_base
typedef T result_type;
pointer_arg_from_python(PyObject*);
T operator()(PyObject*) const;
T operator()() const;
};
// Used when T == U& and (T != V const& or T == W volatile&)
@@ -84,7 +84,7 @@ struct reference_arg_from_python : arg_lvalue_from_python_base
typedef T result_type;
reference_arg_from_python(PyObject*);
T operator()(PyObject*) const;
T operator()() const;
};
// ===================
@@ -114,10 +114,11 @@ struct arg_rvalue_from_python
# if BOOST_MSVC < 1301 || _MSC_FULL_VER > 13102196
typename arg_rvalue_from_python<T>::
# endif
result_type operator()(PyObject*);
result_type operator()();
private:
rvalue_from_python_data<result_type> m_data;
PyObject* m_source;
};
@@ -132,9 +133,10 @@ struct back_reference_arg_from_python
typedef T result_type;
back_reference_arg_from_python(PyObject*);
T operator()(PyObject*);
T operator()();
private:
typedef boost::python::arg_from_python<typename T::type> base;
PyObject* m_source;
};
@@ -259,9 +261,9 @@ inline bool pointer_cref_arg_from_python<T>::convertible() const
return python::detail::void_ptr_to_reference(m_result.bytes, (T(*)())0) != 0;
}
template <class T>
inline T pointer_cref_arg_from_python<T>::operator()(PyObject* p) const
inline T pointer_cref_arg_from_python<T>::operator()() const
{
return (p == Py_None) // None ==> 0
return (*(void**)m_result.bytes == Py_None) // None ==> 0
? detail::null_ptr_reference((T(*)())0)
// Otherwise, return a U*const& to the m_result storage.
: python::detail::void_ptr_to_reference(m_result.bytes, (T(*)())0);
@@ -277,9 +279,9 @@ inline pointer_arg_from_python<T>::pointer_arg_from_python(PyObject* p)
}
template <class T>
inline T pointer_arg_from_python<T>::operator()(PyObject* p) const
inline T pointer_arg_from_python<T>::operator()() const
{
return (p == Py_None) ? 0 : T(result());
return (result() == Py_None) ? 0 : T(result());
}
// reference_arg_from_python
@@ -291,7 +293,7 @@ inline reference_arg_from_python<T>::reference_arg_from_python(PyObject* p)
}
template <class T>
inline T reference_arg_from_python<T>::operator()(PyObject*) const
inline T reference_arg_from_python<T>::operator()() const
{
return python::detail::void_ptr_to_reference(result(), (T(*)())0);
}
@@ -302,6 +304,7 @@ inline T reference_arg_from_python<T>::operator()(PyObject*) const
template <class T>
inline arg_rvalue_from_python<T>::arg_rvalue_from_python(PyObject* obj)
: m_data(converter::rvalue_from_python_stage1(obj, registered<T>::converters))
, m_source(obj)
{
}
@@ -313,10 +316,10 @@ inline bool arg_rvalue_from_python<T>::convertible() const
template <class T>
inline typename arg_rvalue_from_python<T>::result_type
arg_rvalue_from_python<T>::operator()(PyObject* p)
arg_rvalue_from_python<T>::operator()()
{
if (m_data.stage1.construct != 0)
m_data.stage1.construct(p, &m_data.stage1);
m_data.stage1.construct(m_source, &m_data.stage1);
return python::detail::void_ptr_to_reference(m_data.stage1.convertible, (result_type(*)())0);
}
@@ -325,15 +328,15 @@ arg_rvalue_from_python<T>::operator()(PyObject* p)
//
template <class T>
back_reference_arg_from_python<T>::back_reference_arg_from_python(PyObject* x)
: base(x)
: base(x), m_source(x)
{
}
template <class T>
inline T
back_reference_arg_from_python<T>::operator()(PyObject* x)
back_reference_arg_from_python<T>::operator()()
{
return T(x, base::operator()(x));
return T(m_source, base::operator()());
}
}}} // namespace boost::python::converter

View File

@@ -8,6 +8,7 @@
# include <boost/python/detail/prefix.hpp>
# include <boost/python/detail/none.hpp>
# include <boost/python/handle.hpp>
# include <boost/implicit_cast.hpp>
# include <string>
# include <complex>
# include <boost/limits.hpp>
@@ -82,16 +83,16 @@ namespace detail
// Specialize converters for signed and unsigned T to Python Int
# define BOOST_PYTHON_TO_INT(T) \
BOOST_PYTHON_TO_PYTHON_BY_VALUE(signed T, PyInt_FromLong(x)) \
BOOST_PYTHON_TO_PYTHON_BY_VALUE(signed T, ::PyInt_FromLong(x)) \
BOOST_PYTHON_TO_PYTHON_BY_VALUE( \
unsigned T \
, static_cast<unsigned long>(x) > static_cast<unsigned long>( \
std::numeric_limits<long>::max()) \
? PyLong_FromUnsignedLong(x) \
: PyInt_FromLong(x))
? ::PyLong_FromUnsignedLong(x) \
: ::PyInt_FromLong(x))
// Bool is not signed.
BOOST_PYTHON_TO_PYTHON_BY_VALUE(bool, PyInt_FromLong(x))
BOOST_PYTHON_TO_PYTHON_BY_VALUE(bool, ::PyInt_FromLong(x))
// note: handles signed char and unsigned char, but not char (see below)
BOOST_PYTHON_TO_INT(char)
@@ -103,23 +104,31 @@ BOOST_PYTHON_TO_INT(long)
// using Python's macro instead of Boost's - we don't seem to get the
// config right all the time.
# ifdef HAVE_LONG_LONG
BOOST_PYTHON_TO_PYTHON_BY_VALUE(signed BOOST_PYTHON_LONG_LONG, PyLong_FromLongLong(x))
BOOST_PYTHON_TO_PYTHON_BY_VALUE(unsigned BOOST_PYTHON_LONG_LONG, PyLong_FromUnsignedLongLong(x))
BOOST_PYTHON_TO_PYTHON_BY_VALUE(signed BOOST_PYTHON_LONG_LONG, ::PyLong_FromLongLong(x))
BOOST_PYTHON_TO_PYTHON_BY_VALUE(unsigned BOOST_PYTHON_LONG_LONG, ::PyLong_FromUnsignedLongLong(x))
# endif
# undef BOOST_TO_PYTHON_INT
BOOST_PYTHON_TO_PYTHON_BY_VALUE(char, converter::do_return_to_python(x))
BOOST_PYTHON_TO_PYTHON_BY_VALUE(char const*, converter::do_return_to_python(x))
BOOST_PYTHON_TO_PYTHON_BY_VALUE(std::string, PyString_FromStringAndSize(x.c_str(),x.size()))
BOOST_PYTHON_TO_PYTHON_BY_VALUE(float, PyFloat_FromDouble(x))
BOOST_PYTHON_TO_PYTHON_BY_VALUE(double, PyFloat_FromDouble(x))
BOOST_PYTHON_TO_PYTHON_BY_VALUE(long double, PyFloat_FromDouble(x))
BOOST_PYTHON_TO_PYTHON_BY_VALUE(std::string, ::PyString_FromStringAndSize(x.data(),implicit_cast<int>(x.size())))
# ifndef BOOST_NO_STD_WSTRING
BOOST_PYTHON_TO_PYTHON_BY_VALUE(std::wstring, ::PyUnicode_FromWideChar(x.data(),implicit_cast<int>(x.size())))
# endif
BOOST_PYTHON_TO_PYTHON_BY_VALUE(float, ::PyFloat_FromDouble(x))
BOOST_PYTHON_TO_PYTHON_BY_VALUE(double, ::PyFloat_FromDouble(x))
BOOST_PYTHON_TO_PYTHON_BY_VALUE(long double, ::PyFloat_FromDouble(x))
BOOST_PYTHON_RETURN_TO_PYTHON_BY_VALUE(PyObject*, converter::do_return_to_python(x))
BOOST_PYTHON_TO_PYTHON_BY_VALUE(std::complex<float>, PyComplex_FromDoubles(x.real(), x.imag()))
BOOST_PYTHON_TO_PYTHON_BY_VALUE(std::complex<double>, PyComplex_FromDoubles(x.real(), x.imag()))
BOOST_PYTHON_TO_PYTHON_BY_VALUE(std::complex<long double>, PyComplex_FromDoubles(x.real(), x.imag()))
BOOST_PYTHON_TO_PYTHON_BY_VALUE(std::complex<float>, ::PyComplex_FromDoubles(x.real(), x.imag()))
BOOST_PYTHON_TO_PYTHON_BY_VALUE(std::complex<double>, ::PyComplex_FromDoubles(x.real(), x.imag()))
BOOST_PYTHON_TO_PYTHON_BY_VALUE(std::complex<long double>, ::PyComplex_FromDoubles(x.real(), x.imag()))
# undef BOOST_PYTHON_RETURN_TO_PYTHON_BY_VALUE
# undef BOOST_PYTHON_ARG_TO_PYTHON_BY_VALUE
# undef BOOST_PYTHON_TO_PYTHON_BY_VALUE
# undef BOOST_PYTHON_TO_INT
namespace converter
{

View File

@@ -0,0 +1,18 @@
// Copyright David Abrahams 2003. Permission to copy, use,
// modify, sell and distribute this software is granted provided this
// copyright notice appears in all copies. This software is provided
// "as is" without express or implied warranty, and with no claim as
// to its suitability for any purpose.
#ifndef CONTEXT_RESULT_CONVERTER_DWA2003917_HPP
# define CONTEXT_RESULT_CONVERTER_DWA2003917_HPP
namespace boost { namespace python { namespace converter {
// A ResultConverter base class used to indicate that this result
// converter should be constructed with the original Python argument
// list.
struct context_result_converter {};
}}} // namespace boost::python::converter
#endif // CONTEXT_RESULT_CONVERTER_DWA2003917_HPP

View File

@@ -27,7 +27,7 @@ struct object_manager_value_arg_from_python
object_manager_value_arg_from_python(PyObject*);
bool convertible() const;
T operator()(PyObject*) const;
T operator()() const;
private:
PyObject* m_source;
};
@@ -48,7 +48,7 @@ struct object_manager_ref_arg_from_python
object_manager_ref_arg_from_python(PyObject*);
bool convertible() const;
Ref operator()(PyObject*) const;
Ref operator()() const;
~object_manager_ref_arg_from_python();
private:
typename python::detail::referent_storage<Ref>::type m_result;
@@ -71,9 +71,9 @@ inline bool object_manager_value_arg_from_python<T>::convertible() const
}
template <class T>
inline T object_manager_value_arg_from_python<T>::operator()(PyObject* x) const
inline T object_manager_value_arg_from_python<T>::operator()() const
{
return T(python::detail::borrowed_reference(x));
return T(python::detail::borrowed_reference(m_source));
}
template <class Ref>
@@ -111,7 +111,7 @@ inline bool object_manager_ref_arg_from_python<Ref>::convertible() const
}
template <class Ref>
inline Ref object_manager_ref_arg_from_python<Ref>::operator()(PyObject*) const
inline Ref object_manager_ref_arg_from_python<Ref>::operator()() const
{
return python::detail::void_ptr_to_reference(
this->m_result.bytes, (Ref(*)())0);

View File

@@ -1,99 +0,0 @@
// Copyright David Abrahams 2002. Permission to copy, use,
// modify, sell and distribute this software is granted provided this
// copyright notice appears in all copies. This software is provided
// "as is" without express or implied warranty, and with no claim as
// to its suitability for any purpose.
#ifndef PYTYPE_ARG_FROM_PYTHON_DWA2002628_HPP
# define PYTYPE_ARG_FROM_PYTHON_DWA2002628_HPP
# include <boost/python/detail/prefix.hpp>
//
// arg_from_python converters for Python type wrappers, to be used as
// base classes for specializations.
//
namespace boost { namespace python { namespace converter {
template <PyTypeObject* python_type>
struct pytype_arg_from_python
{
pytype_arg_from_python(PyObject*);
bool convertible() const;
private:
PyObject* m_src;
};
// rvalue converter base
template <class Wrapper, PyTypeObject* python_type>
struct pytype_wrapper_value_arg_from_python
: pytype_arg_from_python<python_type>
{
typedef Wrapper result_type;
pytype_wrapper_value_arg_from_python(PyObject*);
Wrapper operator()(PyObject*) const;
};
// Special case for Wrapper& - must store an lvalue internally. This
// OK because the entire state of the object is actually in the Python
// object.
template <class Wrapper, PyTypeObject* python_type>
struct pytype_wrapper_ref_arg_from_python
: pytype_arg_from_python<python_type>
{
typedef Wrapper& result_type;
pytype_wrapper_ref_arg_from_python(PyObject*);
Wrapper& operator()(PyObject*) const;
private:
mutable Wrapper m_result;
};
//
// implementations
//
template <PyTypeObject* python_type>
inline pytype_arg_from_python<python_type>::pytype_arg_from_python(PyObject* x)
: m_src(x)
{
}
template <PyTypeObject* python_type>
inline bool pytype_arg_from_python<python_type>::convertible() const
{
return PyObject_IsInstance(m_src, (PyObject*)python_type);
}
template <class Wrapper, PyTypeObject* python_type>
pytype_wrapper_value_arg_from_python<Wrapper,python_type>::pytype_wrapper_value_arg_from_python(
PyObject* p)
: pytype_arg_from_python<python_type>(p)
{
}
template <class Wrapper, PyTypeObject* python_type>
Wrapper pytype_wrapper_value_arg_from_python<Wrapper,python_type>::operator()(
PyObject* x) const
{
return Wrapper(python::detail::borrowed_reference(x));
}
template <class Wrapper, PyTypeObject* python_type>
pytype_wrapper_ref_arg_from_python<Wrapper,python_type>::pytype_wrapper_ref_arg_from_python(
PyObject* p)
: pytype_arg_from_python<python_type>(p)
, m_result(python::detail::borrowed_reference(p))
{
}
template <class Wrapper, PyTypeObject* python_type>
Wrapper& pytype_wrapper_ref_arg_from_python<Wrapper,python_type>::operator()(
PyObject* x) const
{
return m_result;
}
}}} // namespace boost::python::converter
#endif // PYTYPE_ARG_FROM_PYTHON_DWA2002628_HPP

View File

@@ -10,6 +10,7 @@
# include <boost/python/converter/registrations.hpp>
# include <boost/type_traits/transform_traits.hpp>
# include <boost/type_traits/cv_traits.hpp>
# include <boost/detail/workaround.hpp>
namespace boost { namespace python { namespace converter {
@@ -34,10 +35,15 @@ struct registered
{
};
# ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
// collapses a few more types to the same static instance
# if !defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION) \
&& !BOOST_WORKAROUND(BOOST_MSVC, BOOST_TESTED_AT(1310))
// collapses a few more types to the same static instance. MSVC7.1
// fails to strip cv-qualification from array types in typeid. For
// some reason we can't use this collapse there or array converters
// will not be found.
template <class T>
struct registered<T&> : registered<T> {};
struct registered<T&>
: registered<T> {};
# endif
//

View File

@@ -19,14 +19,13 @@ struct shared_ptr_from_python
converter::registry::insert(&convertible, &construct, type_id<shared_ptr<T> >());
}
static shared_ptr_from_python const registration;
private:
static void* convertible(PyObject* p)
{
return p == Py_None
? p
: converter::get_lvalue_from_python(p, registered<T>::converters)
;
if (p == Py_None)
return p;
return converter::get_lvalue_from_python(p, registered<T>::converters);
}
static void construct(PyObject* source, rvalue_from_python_stage1_data* data)
@@ -45,9 +44,6 @@ struct shared_ptr_from_python
}
};
template <class T>
shared_ptr_from_python<T> const shared_ptr_from_python<T>::registration;
}}} // namespace boost::python::converter
#endif // SHARED_PTR_FROM_PYTHON_DWA20021130_HPP

View File

@@ -9,6 +9,7 @@
# include <boost/python/refcount.hpp>
# include <boost/python/converter/shared_ptr_deleter.hpp>
# include <boost/shared_ptr.hpp>
# include <boost/get_pointer.hpp>
namespace boost { namespace python { namespace converter {
@@ -18,7 +19,7 @@ PyObject* shared_ptr_to_python(shared_ptr<T> const& x)
if (!x)
return python::detail::none();
else if (shared_ptr_deleter* d = boost::get_deleter<shared_ptr_deleter>(x))
return incref(d->owner.get());
return incref( get_pointer( d->owner ) );
else
return converter::registered<shared_ptr<T> const&>::converters.to_python(&x);
}

View File

@@ -8,106 +8,105 @@
# include <boost/python/detail/prefix.hpp>
# include <boost/python/handle.hpp>
# include <boost/python/return_value_policy.hpp>
# include <boost/python/return_by_value.hpp>
# include <boost/python/return_internal_reference.hpp>
# include <boost/python/arg_from_python.hpp>
# include <boost/python/object/function_object.hpp>
# include <boost/python/make_function.hpp>
# include <boost/python/converter/builtin_converters.hpp>
# include <boost/python/detail/indirect_traits.hpp>
# include <boost/python/detail/not_specified.hpp>
# include <boost/type_traits/transform_traits.hpp>
# include <boost/type_traits/add_const.hpp>
# include <boost/type_traits/add_reference.hpp>
# include <boost/type_traits/is_same.hpp>
# include <boost/type_traits/is_member_pointer.hpp>
# if BOOST_WORKAROUND(__MWERKS__, BOOST_TESTED_AT(0x3003))
# include <boost/type_traits/remove_cv.hpp>
# endif
# include <boost/mpl/apply_if.hpp>
# include <boost/mpl/if.hpp>
# include <boost/mpl/vector/vector10.hpp>
# include <boost/bind.hpp>
# include <boost/detail/workaround.hpp>
namespace boost { namespace python {
//
// This file defines the make_getter and make_setter function
// families, which are responsible for turning pointers, references,
// and pointers-to-data-members into callable Python objects which
// can be used for attribute access on wrapped classes.
//
namespace detail
{
template <class Data, class Class, class Policies>
// A small function object which handles the getting and setting of
// data members.
template <class Data, class Class>
struct member
{
static PyObject* get(Data Class::*pm, PyObject* args_, PyObject*, Policies const& policies)
{
arg_from_python<Class*> c0(PyTuple_GET_ITEM(args_, 0));
if (!c0.convertible()) return 0;
// find the result converter
typedef typename Policies::result_converter result_converter;
typedef typename boost::add_reference<Data>::type source;
typename mpl::apply1<result_converter,source>::type cr;
if (!policies.precall(args_)) return 0;
PyObject* result = cr( (c0(PyTuple_GET_ITEM(args_, 0)))->*pm );
return policies.postcall(args_, result);
}
static PyObject* set(Data Class::*pm, PyObject* args_, PyObject*, Policies const& policies)
{
// check that each of the arguments is convertible
arg_from_python<Class&> c0(PyTuple_GET_ITEM(args_, 0));
if (!c0.convertible()) return 0;
typedef typename add_const<Data>::type target1;
typedef typename add_reference<target1>::type target;
arg_from_python<target> c1(PyTuple_GET_ITEM(args_, 1));
private:
typedef typename add_const<Data>::type data_const;
typedef typename add_reference<data_const>::type data_cref;
if (!c1.convertible()) return 0;
if (!policies.precall(args_)) return 0;
(c0(PyTuple_GET_ITEM(args_, 0))).*pm = c1(PyTuple_GET_ITEM(args_, 1));
return policies.postcall(args_, detail::none());
public:
member(Data Class::*which) : m_which(which) {}
Data& operator()(Class& c) const
{
return c.*m_which;
}
void operator()(Class& c, data_cref d) const
{
c.*m_which = d;
}
private:
Data Class::*m_which;
};
template <class Data, class Policies>
// A small function object which handles the getting and setting of
// non-member objects.
template <class Data>
struct datum
{
static PyObject* get(Data *p, PyObject* args_, PyObject*, Policies const& policies)
{
// find the result converter
typedef typename Policies::result_converter result_converter;
typedef typename boost::add_reference<Data>::type source;
typename mpl::apply1<result_converter,source>::type cr;
if (!policies.precall(args_)) return 0;
PyObject* result = cr( *p );
return policies.postcall(args_, result);
}
static PyObject* set(Data* p, PyObject* args_, PyObject*, Policies const& policies)
{
// check that each of the arguments is convertible
typedef typename add_const<Data>::type target1;
typedef typename add_reference<target1>::type target;
arg_from_python<target> c0(PyTuple_GET_ITEM(args_, 0));
private:
typedef typename add_const<Data>::type data_const;
typedef typename add_reference<data_const>::type data_cref;
if (!c0.convertible()) return 0;
if (!policies.precall(args_)) return 0;
*p = c0(PyTuple_GET_ITEM(args_, 0));
return policies.postcall(args_, detail::none());
public:
datum(Data *which) : m_which(which) {}
Data& operator()() const
{
return *m_which;
}
};
void operator()(data_cref d) const
{
*m_which = d;
}
private:
Data *m_which;
};
//
// Helper metafunction for determining the default CallPolicy to use
// for attribute access. If T is a [reference to a] class type X
// whose conversion to python would normally produce a new copy of X
// in a wrapped X class instance (as opposed to types such as
// std::string, which are converted to native Python types, and
// smart pointer types which produce a wrapped class instance of the
// pointee type), to-python conversions will attempt to produce an
// object which refers to the original C++ object, rather than a
// copy. See default_member_getter_policy for rationale.
//
template <class T>
struct default_getter_by_ref
: mpl::and_<
@@ -123,6 +122,9 @@ namespace detail
{
};
// Metafunction computing the default CallPolicy to use for reading
// data members
//
// If it's a regular class type (not an object manager or other
// type for which we have to_python specializations, use
// return_internal_reference so that we can do things like
@@ -130,138 +132,190 @@ namespace detail
// and get the right result.
template <class T>
struct default_member_getter_policy
: mpl::if_<
default_getter_by_ref<T>
, return_internal_reference<>
, return_value_policy<return_by_value>
>
: mpl::if_<
default_getter_by_ref<T>
, return_internal_reference<>
, return_value_policy<return_by_value>
>
{};
// Metafunction computing the default CallPolicy to use for reading
// non-member data.
template <class T>
struct default_datum_getter_policy
: mpl::if_<
default_getter_by_ref<T>
, return_value_policy<reference_existing_object>
, return_value_policy<return_by_value>
>
: mpl::if_<
default_getter_by_ref<T>
, return_value_policy<reference_existing_object>
, return_value_policy<return_by_value>
>
{};
template <class D, class Policies>
inline object make_getter(D* p, Policies const& policies, int)
{
return objects::function_object(
::boost::bind(
&detail::datum<D,Policies>::get, p, _1, _2
, policies)
, 0);
}
//
// make_getter helper function family -- These helpers to
// boost::python::make_getter are used to dispatch behavior. The
// third argument is a workaround for a CWPro8 partial ordering bug
// with pointers to data members. It should be convertible to
// mpl::true_ iff the first argument is a pointer-to-member, and
// mpl::false_ otherwise. The fourth argument is for compilers
// which don't support partial ordering at all and should always be
// passed 0L.
//
#if BOOST_WORKAROUND(__EDG_VERSION__, <= 238)
template <class D, class P>
inline object make_getter(D& d, P& p, mpl::false_, ...);
#endif
// Handle non-member pointers with policies
template <class D, class Policies>
inline object make_getter(D* d, Policies const& policies, mpl::false_, int)
{
return python::make_function(
detail::datum<D>(d), policies, mpl::vector1<D&>()
);
}
// Handle non-member pointers without policies
template <class D>
inline object make_getter(D* p, not_specified, long)
inline object make_getter(D* d, not_specified, mpl::false_, long)
{
typedef typename default_datum_getter_policy<D>::type policies;
return make_getter(p, policies(), 0L);
return detail::make_getter(d, policies(), mpl::false_(), 0);
}
// Handle pointers-to-members with policies
template <class C, class D, class Policies>
inline object make_getter(D C::*pm, Policies const& policies, int)
inline object make_getter(D C::*pm, Policies const& policies, mpl::true_, int)
{
return objects::function_object(
::boost::bind(
&detail::member<D,C,Policies>::get, pm, _1, _2
, policies)
, 1);
#if BOOST_WORKAROUND(__MWERKS__, BOOST_TESTED_AT(0x3003))
typedef typename remove_cv<C>::type Class;
#else
typedef C Class;
#endif
return python::make_function(
detail::member<D,Class>(pm)
, policies
, mpl::vector2<D&,Class&>()
);
}
// Handle pointers-to-members without policies
template <class C, class D>
inline object make_getter(D C::*pm, not_specified, long)
inline object make_getter(D C::*pm, not_specified, mpl::true_, long)
{
typedef typename default_member_getter_policy<D>::type policies;
return make_getter(pm, policies(), 0L);
}
template <class D, class Policies>
inline object make_getter(D& d, Policies const& policies, ...)
{
return detail::make_getter(&d, policies, 0L);
return detail::make_getter(pm, policies(), mpl::true_(), 0);
}
template <class D, class Policies>
inline object make_setter(D* p, Policies const& policies, long)
// Handle references
template <class D, class P>
inline object make_getter(D& d, P& p, mpl::false_, ...)
{
return objects::function_object(
::boost::bind(
&detail::datum<D,Policies>::set, p, _1, _2
, policies)
, 1);
// Just dispatch to the handler for pointer types.
return detail::make_getter(&d, p, mpl::false_(), 0L);
}
//
// make_setter helper function family -- These helpers to
// boost::python::make_setter are used to dispatch behavior. The
// third argument is for compilers which don't support partial
// ordering at all and should always be passed 0.
//
// Handle non-member pointers
template <class D, class Policies>
inline object make_setter(D* p, Policies const& policies, mpl::false_, int)
{
return python::make_function(
detail::datum<D>(p), policies, mpl::vector2<void,D const&>()
);
}
// Handle pointers-to-members
template <class C, class D, class Policies>
inline object make_setter(D C::*pm, Policies const& policies, long)
inline object make_setter(D C::*pm, Policies const& policies, mpl::true_, int)
{
return objects::function_object(
::boost::bind(
&detail::member<D,C,Policies>::set, pm, _1, _2
, policies)
, 2);
return python::make_function(
detail::member<D,C>(pm)
, policies
, mpl::vector3<void, C&, D const&>()
);
}
// Handle references
template <class D, class Policies>
inline object make_setter(D& x, Policies const& policies, ...)
inline object make_setter(D& x, Policies const& policies, mpl::false_, ...)
{
return detail::make_setter(&x, policies, 0L);
return detail::make_setter(&x, policies, mpl::false_(), 0L);
}
}
//
// make_getter function family -- build a callable object which
// retrieves data through the first argument and is appropriate for
// use as the `get' function in Python properties . The second,
// policies argument, is optional. We need both D& and D const&
// overloads in order be able to handle rvalues.
//
template <class D, class Policies>
inline object make_getter(D& d, Policies const& policies)
{
return detail::make_getter(d, policies, 0L);
return detail::make_getter(d, policies, is_member_pointer<D>(), 0L);
}
template <class D, class Policies>
inline object make_getter(D const& d, Policies const& policies)
{
return detail::make_getter(d, policies, 0L);
return detail::make_getter(d, policies, is_member_pointer<D>(), 0L);
}
template <class D>
inline object make_getter(D& x)
{
return detail::make_getter(x, detail::not_specified(), 0L);
detail::not_specified policy;
return detail::make_getter(x, policy, is_member_pointer<D>(), 0L);
}
# if !BOOST_WORKAROUND(BOOST_MSVC, <= 1300)
# if !BOOST_WORKAROUND(__EDG_VERSION__, <= 238) && !BOOST_WORKAROUND(BOOST_MSVC, <= 1300)
template <class D>
inline object make_getter(D const& x)
inline object make_getter(D const& d)
{
return detail::make_getter(x, detail::not_specified(), 0L);
detail::not_specified policy;
return detail::make_getter(d, policy, is_member_pointer<D>(), 0L);
}
# endif
# endif
//
// make_setter function family -- build a callable object which
// writes data through the first argument and is appropriate for
// use as the `set' function in Python properties . The second,
// policies argument, is optional. We need both D& and D const&
// overloads in order be able to handle rvalues.
//
template <class D, class Policies>
inline object make_setter(D& x, Policies const& policies)
{
return detail::make_setter(x, policies, 0L);
return detail::make_setter(x, policies, is_member_pointer<D>(), 0);
}
template <class D, class Policies>
inline object make_setter(D const& x, Policies const& policies)
{
return detail::make_setter(x, policies, 0L);
return detail::make_setter(x, policies, is_member_pointer<D>(), 0);
}
template <class D>
inline object make_setter(D& x)
{
return detail::make_setter(x, default_call_policies(), 0L);
return detail::make_setter(x, default_call_policies(), is_member_pointer<D>(), 0);
}
# if !BOOST_WORKAROUND(BOOST_MSVC, <= 1300)
# if !(BOOST_WORKAROUND(BOOST_MSVC, <= 1300) || BOOST_WORKAROUND(__EDG_VERSION__, <= 238))
template <class D>
inline object make_setter(D const& x)
{
return detail::make_setter(x, default_call_policies(), 0L);
return detail::make_setter(x, default_call_policies(), is_member_pointer<D>(), 0);
}
# endif

View File

@@ -0,0 +1,87 @@
// Copyright David Abrahams 2003. Permission to copy, use,
// modify, sell and distribute this software is granted provided this
// copyright notice appears in all copies. This software is provided
// "as is" without express or implied warranty, and with no claim as
// to its suitability for any purpose.
#ifndef DEF_VISITOR_DWA2003810_HPP
# define DEF_VISITOR_DWA2003810_HPP
# include <boost/python/detail/prefix.hpp>
# include <boost/detail/workaround.hpp>
namespace boost { namespace python {
template <class DerivedVisitor> class def_visitor;
template <class T, class X1, class X2, class X3> class class_;
class def_visitor_access
{
# if defined(BOOST_NO_MEMBER_TEMPLATE_FRIENDS) \
|| BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x551))
// Tasteless as this may seem, making all members public allows member templates
// to work in the absence of member template friends.
public:
# else
template <class Derived> friend class def_visitor;
# endif
// unnamed visit, c.f. init<...>, container suites
template <class V, class classT>
static void visit(V const& v, classT& c)
{
v.derived_visitor().visit(c);
}
// named visit, c.f. object, pure_virtual
template <class V, class classT, class OptionalArgs>
static void visit(
V const& v
, classT& c
, char const* name
, OptionalArgs const& options
)
{
v.derived_visitor().visit(c, name, options);
}
};
template <class DerivedVisitor>
class def_visitor
{
friend class def_visitor_access;
# if defined(BOOST_NO_MEMBER_TEMPLATE_FRIENDS) \
|| BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x551))
// Tasteless as this may seem, making all members public allows member templates
// to work in the absence of member template friends.
public:
# else
template <class T, class X1, class X2, class X3> friend class class_;
# endif
// unnamed visit, c.f. init<...>, container suites
template <class classT>
void visit(classT& c) const
{
def_visitor_access::visit(*this, c);
}
// named visit, c.f. object, pure_virtual
template <class classT, class OptionalArgs>
void visit(classT& c, char const* name, OptionalArgs const& options) const
{
def_visitor_access::visit(*this, c, name, options);
}
protected:
DerivedVisitor const& derived_visitor() const
{
return static_cast<DerivedVisitor const&>(*this);
}
};
}} // namespace boost::python
#endif // DEF_VISITOR_DWA2003810_HPP

View File

@@ -29,19 +29,23 @@ struct default_result_converter;
struct default_call_policies
{
// Nothing to do
static bool precall(PyObject*)
// Ownership of this argument tuple will ultimately be adopted by
// the caller.
template <class ArgumentPackage>
static bool precall(ArgumentPackage const&)
{
return true;
}
// Pass the result through
static PyObject* postcall(PyObject*, PyObject* result)
template <class ArgumentPackage>
static PyObject* postcall(ArgumentPackage const&, PyObject* result)
{
return result;
}
typedef default_result_converter result_converter;
typedef PyObject* argument_package;
};
struct default_result_converter

View File

@@ -9,63 +9,99 @@
# ifndef CALLER_DWA20021121_HPP
# define CALLER_DWA20021121_HPP
# include <boost/compressed_pair.hpp>
# include <boost/mpl/apply.hpp>
# include <boost/mpl/if.hpp>
# include <boost/mpl/size.hpp>
# include <boost/type_traits/is_same.hpp>
# include <boost/python/type_id.hpp>
# include <boost/python/handle.hpp>
# include <boost/python/detail/invoke.hpp>
# include <boost/python/detail/signature.hpp>
# include <boost/python/detail/preprocessor.hpp>
# include <boost/python/arg_from_python.hpp>
# include <boost/python/converter/context_result_converter.hpp>
# include <boost/preprocessor/iterate.hpp>
# include <boost/preprocessor/iteration/local.hpp>
# include <boost/preprocessor/repetition/enum_trailing_params.hpp>
# include <boost/preprocessor/repetition/repeat.hpp>
# include <boost/preprocessor/cat.hpp>
# include <boost/preprocessor/dec.hpp>
# include <boost/preprocessor/if.hpp>
# include <boost/preprocessor/iteration/local.hpp>
# include <boost/preprocessor/repetition/enum_trailing_params.hpp>
# include <boost/preprocessor/repetition/repeat.hpp>
# include <boost/python/detail/invoke.hpp>
# include <boost/compressed_pair.hpp>
# include <boost/type_traits/is_same.hpp>
# include <boost/type_traits/is_convertible.hpp>
# include <boost/mpl/apply.hpp>
# include <boost/mpl/apply_if.hpp>
# include <boost/mpl/identity.hpp>
# include <boost/mpl/size.hpp>
# include <boost/mpl/at.hpp>
# include <boost/mpl/int.hpp>
namespace boost { namespace python { namespace detail {
template <int N>
inline PyObject* get(mpl::int_<N>, PyObject* const& args_)
{
return PyTuple_GET_ITEM(args_,N);
}
inline unsigned arity(PyObject* const& args_)
{
return PyTuple_GET_SIZE(args_);
}
// This "result converter" is really just used as
// a dispatch tag to invoke(...), selecting the appropriate
// implementation
typedef int void_result_to_python;
// A metafunction taking an iterator FunctionIter to a metafunction
// class and an iterator ArgIter to an argument, which applies the
// result of dereferencing FunctionIter to the result of dereferencing
// ArgIter
template <class FunctionIter, class ArgIter>
struct apply_iter1
: mpl::apply1<typename FunctionIter::type, typename ArgIter::type> {};
// Given a model of CallPolicies and a C++ result type, this
// metafunction selects the appropriate converter to use for
// converting the result to python.
template <class Policies, class Result>
struct select_result_converter
: mpl::if_<
: mpl::apply_if<
is_same<Result,void>
, void_result_to_python
, typename mpl::apply1<typename Policies::result_converter,Result>::type*
, mpl::identity<void_result_to_python>
, mpl::apply1<typename Policies::result_converter,Result>
>
{
};
template <class ArgPackage, class ResultConverter>
inline ResultConverter create_result_converter(
ArgPackage const& args_
, ResultConverter*
, converter::context_result_converter*
)
{
return ResultConverter(args_);
}
template <class ArgPackage, class ResultConverter>
inline ResultConverter create_result_converter(
ArgPackage const& args_
, ResultConverter*
, ...
)
{
return ResultConverter();
}
template <unsigned> struct caller_arity;
template <class F, class CallPolicies, class Sig>
struct caller;
# define BOOST_PYTHON_NEXT(init,name,n) \
typedef BOOST_PP_IF(n,typename BOOST_PP_CAT(name,BOOST_PP_DEC(n)) ::next, init) name##n;
# define BOOST_PYTHON_ARG_CONVERTER(n) \
BOOST_PYTHON_NEXT(typename first::next, arg_iter,n) \
BOOST_PYTHON_NEXT(ConverterGenerators, conv_iter,n) \
typedef typename apply_iter1<conv_iter##n,arg_iter##n>::type c_t##n; \
c_t##n c##n(PyTuple_GET_ITEM(args_, n)); \
BOOST_PYTHON_NEXT(typename first::next, arg_iter,n) \
typedef arg_from_python<BOOST_DEDUCED_TYPENAME arg_iter##n::type> c_t##n; \
c_t##n c##n(get(mpl::int_<n>(), inner_args)); \
if (!c##n.convertible()) \
return 0;
@@ -78,11 +114,11 @@ template <unsigned> struct caller_arity;
// A metafunction returning the base class used for caller<class F,
// class ConverterGenerators, class CallPolicies, class Sig>.
template <class F, class ConverterGenerators, class CallPolicies, class Sig>
template <class F, class CallPolicies, class Sig>
struct caller_base_select
{
enum { arity = mpl::size<Sig>::value - 1 };
typedef typename caller_arity<arity>::template impl<F,ConverterGenerators,CallPolicies,Sig> type;
typedef typename caller_arity<arity>::template impl<F,CallPolicies,Sig> type;
};
// A function object type which wraps C++ objects as Python callable
@@ -95,11 +131,6 @@ struct caller_base_select
// actually be any data for which an appropriate invoke_tag() can
// be generated. invoke(...) takes care of the actual invocation syntax.
//
// ConverterGenerators -
// An MPL iterator type over a sequence of metafunction classes
// that can be applied to element 1...N of Sig to produce
// argument from_python converters for the arguments
//
// CallPolicies -
// The precall, postcall, and what kind of resultconverter to
// generate for mpl::front<Sig>::type
@@ -108,19 +139,19 @@ struct caller_base_select
// The `intended signature' of the function. An MPL sequence
// beginning with a result type and continuing with a list of
// argument types.
template <class F, class ConverterGenerators, class CallPolicies, class Sig>
template <class F, class CallPolicies, class Sig>
struct caller
: caller_base_select<F,ConverterGenerators,CallPolicies,Sig>::type
: caller_base_select<F,CallPolicies,Sig>::type
{
typedef typename caller_base_select<
F,ConverterGenerators,CallPolicies,Sig
F,CallPolicies,Sig
>::type base;
typedef PyObject* result_type;
caller(F f, CallPolicies p) : base(f,p) {}
};
};
}}} // namespace boost::python::detail
@@ -133,7 +164,7 @@ struct caller
template <>
struct caller_arity<N>
{
template <class F, class ConverterGenerators, class Policies, class Sig>
template <class F, class Policies, class Sig>
struct impl
{
impl(F f, Policies p) : m_data(f,p) {}
@@ -146,6 +177,10 @@ struct caller_arity<N>
typedef typename mpl::begin<Sig>::type first;
typedef typename first::type result_t;
typedef typename select_result_converter<Policies, result_t>::type result_converter;
typedef typename Policies::argument_package argument_package;
argument_package inner_args(args_);
# if N
# define BOOST_PP_LOCAL_MACRO(i) BOOST_PYTHON_ARG_CONVERTER(i)
# define BOOST_PP_LOCAL_LIMITS (0, N-1)
@@ -153,16 +188,26 @@ struct caller_arity<N>
# endif
// all converters have been checked. Now we can do the
// precall part of the policy
if (!m_data.second().precall(args_))
if (!m_data.second().precall(inner_args))
return 0;
typedef typename detail::invoke_tag<F>::type tag;
PyObject* result = detail::invoke(
tag(), result_converter(), m_data.first() BOOST_PP_ENUM_TRAILING_PARAMS(N, c));
detail::invoke_tag<result_t,F>()
, create_result_converter(args_, (result_converter*)0, (result_converter*)0)
, m_data.first()
BOOST_PP_ENUM_TRAILING_PARAMS(N, c)
);
return m_data.second().postcall(args_, result);
return m_data.second().postcall(inner_args, result);
}
static unsigned min_arity() { return N; }
static signature_element const* signature()
{
return detail::signature<Sig>::elements();
}
private:
compressed_pair<F,Policies> m_data;
};

View File

@@ -71,7 +71,7 @@
# define BOOST_PYTHON_NO_TEMPLATE_EXPORT
#endif
#if defined(BOOST_PYTHON_DYNAMIC_LIB) && defined(_WIN32)
#if defined(BOOST_PYTHON_DYNAMIC_LIB) && (defined(_WIN32) || defined(__CYGWIN__))
# if defined(BOOST_PYTHON_SOURCE)
# define BOOST_PYTHON_DECL __declspec(dllexport)
# define BOOST_PYTHON_BUILD_DLL

View File

@@ -15,4 +15,4 @@ namespace boost { namespace python { namespace detail {
}
}
}}} // namespace boost::python::detail
# endif // BOOST_PYTHON_DETAIL_DEALLOC_HPP_
# endif // BOOST_PYTHON_DETAIL_DEALLOC_HPP_

View File

@@ -18,6 +18,7 @@
# include <boost/mpl/apply.hpp>
# include <boost/tuple/tuple.hpp>
# include <boost/python/detail/not_specified.hpp>
# include <boost/python/detail/def_helper_fwd.hpp>
namespace boost { namespace python {
@@ -143,7 +144,7 @@ namespace detail
// are expected to be the types of the actual (optional) arguments
// passed to def().
//
template <class T1, class T2 = not_specified, class T3 = not_specified, class T4 = not_specified>
template <class T1, class T2, class T3, class T4>
struct def_helper
{
// A tuple type which begins with references to the supplied

View File

@@ -0,0 +1,18 @@
// Copyright David Abrahams 2003. Permission to copy, use,
// modify, sell and distribute this software is granted provided this
// copyright notice appears in all copies. This software is provided
// "as is" without express or implied warranty, and with no claim as
// to its suitability for any purpose.
#ifndef DEF_HELPER_FWD_DWA2003810_HPP
# define DEF_HELPER_FWD_DWA2003810_HPP
# include <boost/python/detail/not_specified.hpp>
namespace boost { namespace python { namespace detail {
template <class T1, class T2 = not_specified, class T3 = not_specified, class T4 = not_specified>
struct def_helper;
}}} // namespace boost::python::detail
#endif // DEF_HELPER_FWD_DWA2003810_HPP

View File

@@ -37,8 +37,13 @@ namespace objects
namespace detail
{
template <class T, class F> struct member_function_cast;
// Called as::
//
// name_space_def(ns, "func", func, kw, policies, docstring, &ns)
//
// Dispatch to properly add f to namespace ns.
//
// @group define_stub_function helpers {
template <class Func, class CallPolicies, class NameSpaceT>
static void name_space_def(
NameSpaceT& name_space
@@ -55,10 +60,9 @@ namespace detail
objects::add_to_namespace(
name_space, name,
detail::make_keyword_range_function(
// This bit of nastiness casts F to a member function of T if possible.
member_function_cast<wrapped_type,Func>::stage1(f).stage2((wrapped_type*)0).stage3(f)
, policies, kw)
, doc);
f, policies, kw, get_signature(f, (wrapped_type*)0))
, doc
);
}
template <class Func, class CallPolicies>
@@ -80,7 +84,7 @@ namespace detail
, doc);
}
// For backward compatibility
// For backward compatibility -- is this obsolete?
template <class Func, class CallPolicies, class NameSpaceT>
static void name_space_def(
NameSpaceT& name_space
@@ -94,10 +98,10 @@ namespace detail
{
name_space.def(name, f, policies, doc);
}
// }
///////////////////////////////////////////////////////////////////////////////
//
// This Boost PP code generates expansions for
// Expansions of ::
//
// template <typename OverloadsT, typename NameSpaceT>
// inline void
@@ -107,7 +111,7 @@ namespace detail
// name_space.def(name, &OverloadsT::func_N);
// }
//
// where N runs from 0 to BOOST_PYTHON_MAX_ARITY
// where N runs from 0 to BOOST_PYTHON_MAX_ARITY.
//
// The set of overloaded functions (define_stub_function) expects:
//
@@ -118,7 +122,7 @@ namespace detail
// (see defaults_gen.hpp)
// 5. char const* name: doc string
//
///////////////////////////////////////////////////////////////////////////////
// @group define_stub_function<N> {
template <int N>
struct define_stub_function {};
@@ -126,129 +130,137 @@ namespace detail
(3, (0, BOOST_PYTHON_MAX_ARITY, <boost/python/detail/defaults_def.hpp>))
#include BOOST_PP_ITERATE()
// }
// This helper template struct does the actual recursive
// definition. There's a generic version
// define_with_defaults_helper<N> and a terminal case
// define_with_defaults_helper<0>. The struct and its
// specialization has a sole static member function def that
// expects:
//
// 1. char const* name: function name that will be
// visible to python
//
// 2. OverloadsT: a function overloads struct
// (see defaults_gen.hpp)
//
// 3. NameSpaceT& name_space: a python::class_ or
// python::module instance
//
// 4. char const* name: doc string
//
// The def static member function calls a corresponding
// define_stub_function<N>. The general case recursively calls
// define_with_defaults_helper<N-1>::def until it reaches the
// terminal case case define_with_defaults_helper<0>.
template <int N>
struct define_with_defaults_helper {
///////////////////////////////////////////////////////////////////////////////
//
// define_with_defaults_helper<N>
//
// This helper template struct does the actual recursive definition.
// There's a generic version define_with_defaults_helper<N> and a
// terminal case define_with_defaults_helper<0>. The struct and its
// specialization has a sole static member function def that expects:
//
// 1. char const* name: function name that will be visible to python
// 2. OverloadsT: a function overloads struct (see defaults_gen.hpp)
// 3. NameSpaceT& name_space: a python::class_ or python::module instance
// 4. char const* name: doc string
//
// The def static member function calls a corresponding
// define_stub_function<N>. The general case recursively calls
// define_with_defaults_helper<N-1>::def until it reaches the
// terminal case case define_with_defaults_helper<0>.
//
///////////////////////////////////////////////////////////////////////////////
template <int N>
struct define_with_defaults_helper {
template <class StubsT, class CallPolicies, class NameSpaceT>
static void
def(
char const* name,
StubsT stubs,
keyword_range kw,
CallPolicies const& policies,
NameSpaceT& name_space,
char const* doc)
{
// define the NTH stub function of stubs
define_stub_function<N>::define(name, stubs, kw, policies, name_space, doc);
template <class StubsT, class CallPolicies, class NameSpaceT>
static void
def(
char const* name,
StubsT stubs,
keyword_range kw,
CallPolicies const& policies,
NameSpaceT& name_space,
char const* doc)
{
// define the NTH stub function of stubs
define_stub_function<N>::define(name, stubs, kw, policies, name_space, doc);
if (kw.second > kw.first)
--kw.second;
// call the next define_with_defaults_helper
define_with_defaults_helper<N-1>::def(name, stubs, kw, policies, name_space, doc);
}
};
if (kw.second > kw.first)
--kw.second;
///////////////////////////////////////
template <>
struct define_with_defaults_helper<0> {
// call the next define_with_defaults_helper
define_with_defaults_helper<N-1>::def(name, stubs, kw, policies, name_space, doc);
}
};
template <class StubsT, class CallPolicies, class NameSpaceT>
static void
def(
char const* name,
StubsT stubs,
keyword_range const& kw,
CallPolicies const& policies,
NameSpaceT& name_space,
char const* doc)
{
// define the Oth stub function of stubs
define_stub_function<0>::define(name, stubs, kw, policies, name_space, doc);
// return
}
};
template <>
struct define_with_defaults_helper<0> {
///////////////////////////////////////////////////////////////////////////////
//
// define_with_defaults
//
// 1. char const* name: function name that will be visible to python
// 2. OverloadsT: a function overloads struct (see defaults_gen.hpp)
// 3. CallPolicies& policies: Call policies
// 4. NameSpaceT& name_space: a python::class_ or python::module instance
// 5. SigT sig: Function signature typelist (see defaults_gen.hpp)
// 6. char const* name: doc string
//
// This is the main entry point. This function recursively defines all
// stub functions of StubT (see defaults_gen.hpp) in NameSpaceT name_space which
// can be either a python::class_ or a python::module. The sig argument
// is a typelist that specifies the return type, the class (for member
// functions, and the arguments. Here are some SigT examples:
//
// int foo(int) mpl::list<int, int>
// void bar(int, int) mpl::list<void, int, int>
// void C::foo(int) mpl::list<void, C, int>
//
///////////////////////////////////////////////////////////////////////////////
template <class OverloadsT, class NameSpaceT, class SigT>
inline void
define_with_defaults(
char const* name,
OverloadsT const& overloads,
NameSpaceT& name_space,
SigT const&)
{
typedef typename mpl::front<SigT>::type return_type;
typedef typename OverloadsT::void_return_type void_return_type;
typedef typename OverloadsT::non_void_return_type non_void_return_type;
template <class StubsT, class CallPolicies, class NameSpaceT>
static void
def(
char const* name,
StubsT stubs,
keyword_range const& kw,
CallPolicies const& policies,
NameSpaceT& name_space,
char const* doc)
{
// define the Oth stub function of stubs
define_stub_function<0>::define(name, stubs, kw, policies, name_space, doc);
// return
}
};
typedef typename mpl::if_c<
boost::is_same<void, return_type>::value
, void_return_type
, non_void_return_type
>::type stubs_type;
// define_with_defaults
//
// 1. char const* name: function name that will be
// visible to python
//
// 2. OverloadsT: a function overloads struct
// (see defaults_gen.hpp)
//
// 3. CallPolicies& policies: Call policies
// 4. NameSpaceT& name_space: a python::class_ or
// python::module instance
//
// 5. SigT sig: Function signature typelist
// (see defaults_gen.hpp)
//
// 6. char const* name: doc string
//
// This is the main entry point. This function recursively
// defines all stub functions of StubT (see defaults_gen.hpp) in
// NameSpaceT name_space which can be either a python::class_ or
// a python::module. The sig argument is a typelist that
// specifies the return type, the class (for member functions,
// and the arguments. Here are some SigT examples:
//
// int foo(int) mpl::vector<int, int>
// void bar(int, int) mpl::vector<void, int, int>
// void C::foo(int) mpl::vector<void, C, int>
//
template <class OverloadsT, class NameSpaceT, class SigT>
inline void
define_with_defaults(
char const* name,
OverloadsT const& overloads,
NameSpaceT& name_space,
SigT const&)
{
typedef typename mpl::front<SigT>::type return_type;
typedef typename OverloadsT::void_return_type void_return_type;
typedef typename OverloadsT::non_void_return_type non_void_return_type;
BOOST_STATIC_ASSERT(
(stubs_type::max_args) <= mpl::size<SigT>::value);
typedef typename mpl::if_c<
boost::is_same<void, return_type>::value
, void_return_type
, non_void_return_type
>::type stubs_type;
typedef typename stubs_type::template gen<SigT> gen_type;
define_with_defaults_helper<stubs_type::n_funcs-1>::def(
name
, gen_type()
, overloads.keywords()
, overloads.call_policies()
, name_space
, overloads.doc_string());
}
BOOST_STATIC_ASSERT(
(stubs_type::max_args) <= mpl::size<SigT>::value);
typedef typename stubs_type::template gen<SigT> gen_type;
define_with_defaults_helper<stubs_type::n_funcs-1>::def(
name
, gen_type()
, overloads.keywords()
, overloads.call_policies()
, name_space
, overloads.doc_string());
}
} // namespace detail
}} // namespace boost::python
///////////////////////////////////////////////////////////////////////////////
#endif // DEFAULTS_DEF_JDG20020811_HPP
#else // defined(BOOST_PP_IS_ITERATING)

View File

@@ -27,6 +27,7 @@
#include <boost/mpl/begin_end.hpp>
#include <boost/mpl/next.hpp>
#include <boost/mpl/apply.hpp>
#include <cstddef>
namespace boost { namespace python {
@@ -203,26 +204,26 @@ namespace detail
}; \
};
#define BOOST_PYTHON_OVERLOAD_CONSTRUCTORS(fstubs_name, n_args, n_dflts) \
fstubs_name(char const* doc = 0) \
: ::boost::python::detail::overloads_common<fstubs_name>(doc) {} \
template <class Keywords> \
fstubs_name(char const* doc, Keywords const& keywords) \
: ::boost::python::detail::overloads_common<fstubs_name>( \
doc, keywords.range()) \
{ \
typedef typename ::boost::python::detail:: \
error::more_keywords_than_function_arguments< \
Keywords::size,n_args>::too_many_keywords assertion; \
} \
template <class Keywords> \
fstubs_name(Keywords const& keywords, char const* doc = 0) \
: ::boost::python::detail::overloads_common<fstubs_name>( \
doc, keywords.range()) \
{ \
typedef typename ::boost::python::detail:: \
error::more_keywords_than_function_arguments< \
Keywords::size,n_args>::too_many_keywords assertion; \
#define BOOST_PYTHON_OVERLOAD_CONSTRUCTORS(fstubs_name, n_args, n_dflts) \
fstubs_name(char const* doc = 0) \
: ::boost::python::detail::overloads_common<fstubs_name>(doc) {} \
template <std::size_t N> \
fstubs_name(char const* doc, ::boost::python::detail::keywords<N> const& keywords) \
: ::boost::python::detail::overloads_common<fstubs_name>( \
doc, keywords.range()) \
{ \
typedef typename ::boost::python::detail:: \
error::more_keywords_than_function_arguments< \
N,n_args>::too_many_keywords assertion; \
} \
template <std::size_t N> \
fstubs_name(::boost::python::detail::keywords<N> const& keywords, char const* doc = 0) \
: ::boost::python::detail::overloads_common<fstubs_name>( \
doc, keywords.range()) \
{ \
typedef typename ::boost::python::detail:: \
error::more_keywords_than_function_arguments< \
N,n_args>::too_many_keywords assertion; \
}
# if defined(BOOST_NO_VOID_RETURNS)

View File

@@ -45,23 +45,19 @@ namespace boost { namespace python { namespace detail {
// invoke(...), selecting the appropriate implementation
typedef int void_result_to_python;
// Trait forward declaration.
template <class T> struct is_defaulted_virtual_fn;
// Tag types describing invocation methods
struct fn_tag {};
struct mem_fn_tag {};
template <bool void_return, bool member>
struct invoke_tag_ {};
// A metafunction returning the appropriate tag type for invoking an
// object of type T.
template <class T>
// object of type F with return type R.
template <class R, class F>
struct invoke_tag
: mpl::if_<
is_member_function_pointer<T>
, mem_fn_tag
, fn_tag
: invoke_tag_<
is_same<R,void>::value
, is_member_function_pointer<F>::value
>
{};
{
};
# define BOOST_PP_ITERATION_PARAMS_1 \
(3, (0, BOOST_PYTHON_MAX_ARITY, <boost/python/detail/invoke.hpp>))
@@ -75,26 +71,26 @@ struct invoke_tag
# define N BOOST_PP_ITERATION()
template <class RC, class F BOOST_PP_ENUM_TRAILING_PARAMS_Z(1, N, class AC)>
inline PyObject* invoke(fn_tag, RC*, F& f BOOST_PP_ENUM_TRAILING_BINARY_PARAMS_Z(1, N, AC, & ac) )
inline PyObject* invoke(invoke_tag_<false,false>, RC const& rc, F& f BOOST_PP_ENUM_TRAILING_BINARY_PARAMS_Z(1, N, AC, & ac) )
{
return RC()(f( BOOST_PP_ENUM_BINARY_PARAMS_Z(1, N, ac, () BOOST_PP_INTERCEPT) ));
return rc(f( BOOST_PP_ENUM_BINARY_PARAMS_Z(1, N, ac, () BOOST_PP_INTERCEPT) ));
}
template <class F BOOST_PP_ENUM_TRAILING_PARAMS_Z(1, N, class AC)>
inline PyObject* invoke(fn_tag, void_result_to_python, F& f BOOST_PP_ENUM_TRAILING_BINARY_PARAMS_Z(1, N, AC, & ac) )
template <class RC, class F BOOST_PP_ENUM_TRAILING_PARAMS_Z(1, N, class AC)>
inline PyObject* invoke(invoke_tag_<true,false>, RC const&, F& f BOOST_PP_ENUM_TRAILING_BINARY_PARAMS_Z(1, N, AC, & ac) )
{
f( BOOST_PP_ENUM_BINARY_PARAMS_Z(1, N, ac, () BOOST_PP_INTERCEPT) );
return none();
}
template <class RC, class F, class TC BOOST_PP_ENUM_TRAILING_PARAMS_Z(1, N, class AC)>
inline PyObject* invoke(mem_fn_tag, RC*, F& f, TC& tc BOOST_PP_ENUM_TRAILING_BINARY_PARAMS_Z(1, N, AC, & ac) )
inline PyObject* invoke(invoke_tag_<false,true>, RC const& rc, F& f, TC& tc BOOST_PP_ENUM_TRAILING_BINARY_PARAMS_Z(1, N, AC, & ac) )
{
return RC()( (tc().*f)(BOOST_PP_ENUM_BINARY_PARAMS_Z(1, N, ac, () BOOST_PP_INTERCEPT)) );
return rc( (tc().*f)(BOOST_PP_ENUM_BINARY_PARAMS_Z(1, N, ac, () BOOST_PP_INTERCEPT)) );
}
template <class F, class TC BOOST_PP_ENUM_TRAILING_PARAMS_Z(1, N, class AC)>
inline PyObject* invoke(mem_fn_tag, void_result_to_python, F& f, TC& tc BOOST_PP_ENUM_TRAILING_BINARY_PARAMS_Z(1, N, AC, & ac) )
template <class RC, class F, class TC BOOST_PP_ENUM_TRAILING_PARAMS_Z(1, N, class AC)>
inline PyObject* invoke(invoke_tag_<true,true>, RC const&, F& f, TC& tc BOOST_PP_ENUM_TRAILING_BINARY_PARAMS_Z(1, N, AC, & ac) )
{
(tc().*f)(BOOST_PP_ENUM_BINARY_PARAMS_Z(1, N, ac, () BOOST_PP_INTERCEPT));
return none();

View File

@@ -14,36 +14,39 @@
# include <boost/type_traits/is_reference.hpp>
# include <boost/type_traits/add_reference.hpp>
# define BOOST_PYTHON_IS_XXX_DEF(name, qualified_name, nargs) \
template <class X_> \
struct is_##name \
{ \
typedef char yes; \
typedef char (&no)[2]; \
\
static typename add_reference<X_>::type dummy; \
\
template < BOOST_PP_ENUM_PARAMS_Z(1, nargs, class U) > \
static yes test( \
qualified_name< BOOST_PP_ENUM_PARAMS_Z(1, nargs, U) >&, int \
); \
\
template <class U> \
static no test(U&, ...); \
\
BOOST_STATIC_CONSTANT( \
bool, value \
= !is_reference<X_>::value \
& (sizeof(test(dummy, 0)) == sizeof(yes))); \
\
typedef mpl::bool_<value> type; \
# define BOOST_PYTHON_IS_XXX_DEF(name, qualified_name, nargs) \
template <class X_> \
struct is_##name \
{ \
typedef char yes; \
typedef char (&no)[2]; \
\
static typename add_reference<X_>::type dummy; \
\
struct helpers \
{ \
template < BOOST_PP_ENUM_PARAMS_Z(1, nargs, class U) > \
static yes test( \
qualified_name< BOOST_PP_ENUM_PARAMS_Z(1, nargs, U) >&, int \
); \
\
template <class U> \
static no test(U&, ...); \
}; \
\
BOOST_STATIC_CONSTANT( \
bool, value \
= !is_reference<X_>::value \
& (sizeof(helpers::test(dummy, 0)) == sizeof(yes))); \
\
typedef mpl::bool_<value> type; \
};
# else
# define BOOST_PYTHON_IS_XXX_DEF(name, qualified_name, nargs) \
template <class T> \
struct is_##name : mpl::false_ \
struct is_##name : mpl::false_ \
{ \
}; \
\
@@ -51,7 +54,7 @@ template < BOOST_PP_ENUM_PARAMS_Z(1, nargs, class T) > \
struct is_##name< \
qualified_name< BOOST_PP_ENUM_PARAMS_Z(1, nargs, T) > \
> \
: mpl::true_ \
: mpl::true_ \
{ \
};

View File

@@ -21,13 +21,30 @@ namespace boost { namespace python { namespace detail {
// F. This version is needed when defining functions with default
// arguments, because compile-time information about the number of
// keywords is missing for all but the initial function definition.
//
// @group make_keyword_range_function {
template <class F, class Policies>
object make_keyword_range_function(F f, Policies const& policies, keyword_range const& kw)
object make_keyword_range_function(
F f
, Policies const& policies
, keyword_range const& kw)
{
return detail::make_function_aux(
f, policies, args_from_python(), detail::get_signature(f), kw, mpl::int_<0>());
f, policies, detail::get_signature(f), kw, mpl::int_<0>());
}
template <class F, class Policies, class Signature>
object make_keyword_range_function(
F f
, Policies const& policies
, keyword_range const& kw
, Signature const& sig)
{
return detail::make_function_aux(
f, policies, sig, kw, mpl::int_<0>());
}
// }
// Builds an '__init__' function which inserts the given Holder type
// in a wrapped C++ class instance. ArgList is an MPL type sequence
// describing the C++ argument types to be passed to Holder's

View File

@@ -1,118 +0,0 @@
#if !defined(BOOST_PP_IS_ITERATING)
// Copyright David Abrahams 2002. Permission to copy, use,
// modify, sell and distribute this software is granted provided this
// copyright notice appears in all copies. This software is provided
// "as is" without express or implied warranty, and with no claim as
// to its suitability for any purpose.
# ifndef MEMBER_FUNCTION_CAST_DWA2002311_HPP
# define MEMBER_FUNCTION_CAST_DWA2002311_HPP
# include <boost/python/detail/preprocessor.hpp>
# include <boost/mpl/if.hpp>
# include <boost/type_traits/composite_traits.hpp>
# include <boost/preprocessor/comma_if.hpp>
# include <boost/preprocessor/iterate.hpp>
# include <boost/preprocessor/debug/line.hpp>
# include <boost/preprocessor/repetition/enum_params.hpp>
# include <boost/preprocessor/repetition/enum_trailing_params.hpp>
namespace boost { namespace python { namespace detail {
template <class S, class FT>
struct cast_helper
{
struct yes_helper
{
static FT stage3(FT x) { return x; }
};
struct no_helper
{
template <class T>
static T stage3(T x) { return x; }
};
static yes_helper stage2(S*) { return yes_helper(); }
static no_helper stage2(void*) { return no_helper(); }
};
struct non_member_function_cast_impl
{
template <class T>
static non_member_function_cast_impl stage1(T) { return non_member_function_cast_impl(); }
template <class T>
static non_member_function_cast_impl stage2(T) { return non_member_function_cast_impl(); }
template <class T>
T stage3(T x) { return x; }
};
template <class T>
struct member_function_cast_impl
{
# ifndef BOOST_NO_FUNCTION_TEMPLATE_ORDERING
template <class U>
static non_member_function_cast_impl stage1(U)
{
return non_member_function_cast_impl();
}
# endif
// Member functions
# define BOOST_PP_ITERATION_PARAMS_1 (3, (0, 3, <boost/python/detail/member_function_cast.hpp>))
# include BOOST_PP_ITERATE()
};
template <class T, class SF>
struct member_function_cast
# ifndef BOOST_NO_FUNCTION_TEMPLATE_ORDERING
: member_function_cast_impl<T>
# else
: mpl::if_c<
is_member_function_pointer<SF>::value
, member_function_cast_impl<T>
, non_member_function_cast_impl
>::type
# endif
{
};
}}} // namespace boost::python::detail
# endif // MEMBER_FUNCTION_CAST_DWA2002311_HPP
#elif BOOST_PP_ITERATION_DEPTH() == 1
// outer over cv-qualifiers
# define BOOST_PP_ITERATION_PARAMS_2 (3, (0, BOOST_PYTHON_MAX_ARITY, <boost/python/detail/member_function_cast.hpp>))
# include BOOST_PP_ITERATE()
#elif BOOST_PP_ITERATION_DEPTH() == 2
# line BOOST_PP_LINE(__LINE__, member_function_cast.hpp)
// inner over arities
# define N BOOST_PP_ITERATION()
# define Q BOOST_PYTHON_CV_QUALIFIER(BOOST_PP_RELATIVE_ITERATION(1))
# define P BOOST_PP_ENUM_PARAMS_Z(1, N, A)
template <
class S, class R
BOOST_PP_ENUM_TRAILING_PARAMS_Z(1, N, class A)
>
static cast_helper<S, R (T::*)( P ) Q>
stage1(R (S::*)( P ) Q)
{
return cast_helper<S, R (T::*)( P ) Q>();
}
# undef P
# undef N
# undef Q
#endif

View File

@@ -49,17 +49,24 @@ template< typename T > T&(* is_ref_tester1(type<T>) )(type<T>) { return 0; }
inline char BOOST_TT_DECL is_ref_tester1(...) { return 0; }
template <class T>
inline typeinfo msvc_typeid(boost::type<T>* = 0)
inline typeinfo msvc_typeid(boost::type<T>*)
{
return detail::typeid_ref(
(boost::type<T>*)0, detail::is_ref_tester1(type<T>())
);
}
template <>
inline typeinfo msvc_typeid<void>(boost::type<void>*)
{
return typeid(void);
}
# ifndef NDEBUG
inline typeinfo assert_array_typeid_compiles()
{
return msvc_typeid<char const[3]>(), msvc_typeid<char[3]>();
return msvc_typeid((boost::type<char const[3]>*)0)
, msvc_typeid((boost::type<char[3]>*)0);
}
# endif

View File

@@ -0,0 +1,47 @@
// Copyright David Abrahams 2003. Permission to copy, use,
// modify, sell and distribute this software is granted provided this
// copyright notice appears in all copies. This software is provided
// "as is" without express or implied warranty, and with no claim as
// to its suitability for any purpose.
#ifndef NULLARY_FUNCTION_ADAPTOR_DWA2003824_HPP
# define NULLARY_FUNCTION_ADAPTOR_DWA2003824_HPP
# include <boost/python/detail/prefix.hpp>
# include <boost/preprocessor/iteration/local.hpp>
# include <boost/preprocessor/facilities/intercept.hpp>
# include <boost/preprocessor/repetition/enum_params.hpp>
# include <boost/preprocessor/repetition/enum_binary_params.hpp>
namespace boost { namespace python { namespace detail {
// nullary_function_adaptor -- a class template which ignores its
// arguments and calls a nullary function instead. Used for building
// error-reporting functions, c.f. pure_virtual
template <class NullaryFunction>
struct nullary_function_adaptor
{
nullary_function_adaptor(NullaryFunction fn)
: m_fn(fn)
{}
void operator()() const { m_fn(); }
# define BOOST_PP_LOCAL_MACRO(i) \
template <BOOST_PP_ENUM_PARAMS_Z(1, i, class A)> \
void operator()( \
BOOST_PP_ENUM_BINARY_PARAMS_Z(1, i, A, const& BOOST_PP_INTERCEPT) \
) const \
{ \
m_fn(); \
}
# define BOOST_PP_LOCAL_LIMITS (1, BOOST_PYTHON_MAX_ARITY)
# include BOOST_PP_LOCAL_ITERATE()
private:
NullaryFunction m_fn;
};
}}} // namespace boost::python::detail
#endif // NULLARY_FUNCTION_ADAPTOR_DWA2003824_HPP

View File

@@ -47,7 +47,8 @@ enum operator_id
op_iand,
op_ixor,
op_ior,
op_complex
op_complex,
op_nonzero
};
}}} // namespace boost::python::detail

View File

@@ -18,7 +18,7 @@
/* Enable compiler features; switching on C lib defines doesn't work
here, because the symbols haven't necessarily been defined yet. */
#ifndef _GNU_SOURCE
# define _GNU_SOURCE 1
# define _GNU_SOURCE 1
#endif
/* Forcing SUSv2 compatibility still produces problems on some
@@ -26,7 +26,7 @@
define is switched off. */
#if 0
#ifndef _XOPEN_SOURCE
# define _XOPEN_SOURCE 500
# define _XOPEN_SOURCE 500
#endif
#endif
@@ -40,10 +40,10 @@
#endif
/* pyconfig.h may or may not define DL_IMPORT */
#ifndef DL_IMPORT /* declarations for DLL import/export */
#ifndef DL_IMPORT /* declarations for DLL import/export */
#define DL_IMPORT(RTYPE) RTYPE
#endif
#ifndef DL_EXPORT /* declarations for DLL import/export */
#ifndef DL_EXPORT /* declarations for DLL import/export */
#define DL_EXPORT(RTYPE) RTYPE
#endif
@@ -124,15 +124,15 @@ extern "C" { // Boost.Python modification: provide missing extern "C"
#include "abstract.h"
#define PyArg_GetInt(v, a) PyArg_Parse((v), "i", (a))
#define PyArg_NoArgs(v) PyArg_Parse(v, "")
#define PyArg_GetInt(v, a) PyArg_Parse((v), "i", (a))
#define PyArg_NoArgs(v) PyArg_Parse(v, "")
/* Convert a possibly signed character to a nonnegative int */
/* XXX This assumes characters are 8 bits wide */
#ifdef __CHAR_UNSIGNED__
#define Py_CHARMASK(c) (c)
#define Py_CHARMASK(c) (c)
#else
#define Py_CHARMASK(c) ((c) & 0xff)
#define Py_CHARMASK(c) ((c) & 0xff)
#endif
#include "pyfpe.h"

View File

@@ -88,7 +88,10 @@ result(X const&, short = 0) { return 0; }
/* --------------- function pointers --------------- */
#elif BOOST_PP_ITERATION_DEPTH() == 1 && BOOST_PP_ITERATION_FLAGS() == BOOST_PYTHON_FUNCTION_POINTER
# line BOOST_PP_LINE(__LINE__, result.hpp(function pointers))
# if !(BOOST_WORKAROUND(__MWERKS__, > 0x3100) \
&& BOOST_WORKAROUND(__MWERKS__, BOOST_TESTED_AT(0x3201)))
# line BOOST_PP_LINE(__LINE__, result.hpp(function pointers))
# endif
# define N BOOST_PP_ITERATION()
@@ -108,7 +111,10 @@ boost::type<R>* result(R (*pf)(BOOST_PP_ENUM_PARAMS_Z(1, N, A)), int = 0)
# include BOOST_PP_ITERATE()
#elif BOOST_PP_ITERATION_DEPTH() == 2
# line BOOST_PP_LINE(__LINE__, result.hpp(pointers-to-members))
# if !(BOOST_WORKAROUND(__MWERKS__, > 0x3100) \
&& BOOST_WORKAROUND(__MWERKS__, BOOST_TESTED_AT(0x3201)))
# line BOOST_PP_LINE(__LINE__, result.hpp(pointers-to-members))
# endif
// Inner over arities
# define N BOOST_PP_ITERATION()

View File

@@ -0,0 +1,89 @@
#if !defined(BOOST_PP_IS_ITERATING)
// Copyright David Abrahams 2002. Permission to copy, use,
// modify, sell and distribute this software is granted provided this
// copyright notice appears in all copies. This software is provided
// "as is" without express or implied warranty, and with no claim as
// to its suitability for any purpose.
# ifndef SIGNATURE_DWA20021121_HPP
# define SIGNATURE_DWA20021121_HPP
# include <boost/python/type_id.hpp>
# include <boost/python/detail/preprocessor.hpp>
# include <boost/python/detail/indirect_traits.hpp>
# include <boost/preprocessor/iterate.hpp>
# include <boost/preprocessor/iteration/local.hpp>
# include <boost/mpl/at.hpp>
# include <boost/mpl/size.hpp>
namespace boost { namespace python { namespace detail {
struct signature_element
{
char const* basename;
bool lvalue;
};
template <unsigned> struct signature_arity;
# define BOOST_PP_ITERATION_PARAMS_1 \
(3, (0, BOOST_PYTHON_MAX_ARITY + 1, <boost/python/detail/signature.hpp>))
# include BOOST_PP_ITERATE()
// A metafunction returning the base class used for
//
// signature<class F, class CallPolicies, class Sig>.
//
template <class Sig>
struct signature_base_select
{
enum { arity = mpl::size<Sig>::value - 1 };
typedef typename signature_arity<arity>::template impl<Sig> type;
};
template <class Sig>
struct signature
: signature_base_select<Sig>::type
{
};
}}} // namespace boost::python::detail
# endif // SIGNATURE_DWA20021121_HPP
#else
# define N BOOST_PP_ITERATION()
template <>
struct signature_arity<N>
{
template <class Sig>
struct impl
{
static signature_element const* elements()
{
static signature_element const result[N+2] = {
# define BOOST_PP_LOCAL_MACRO(i) \
{ \
type_id<BOOST_DEDUCED_TYPENAME mpl::at_c<Sig,i>::type>().name() \
, is_reference_to_non_const<BOOST_DEDUCED_TYPENAME mpl::at_c<Sig,i>::type>::value \
},
# define BOOST_PP_LOCAL_LIMITS (0, N)
# include BOOST_PP_LOCAL_ITERATE()
{0,0}
};
return result;
}
};
};
#endif // BOOST_PP_IS_ITERATING

View File

@@ -31,7 +31,7 @@ namespace boost { namespace python { namespace detail {
# include BOOST_PP_ITERATE()
template <class R, class T>
boost::type<T*>* target(R (T::*)) { return 0; }
T& (* target(R (T::*)) )() { return 0; }
}}} // namespace boost::python::detail
@@ -39,12 +39,15 @@ boost::type<T*>* target(R (T::*)) { return 0; }
/* --------------- function pointers --------------- */
#elif BOOST_PP_ITERATION_DEPTH() == 1 && BOOST_PP_ITERATION_FLAGS() == BOOST_PYTHON_FUNCTION_POINTER
# line BOOST_PP_LINE(__LINE__, target.hpp(function_pointers))
# if !(BOOST_WORKAROUND(__MWERKS__, > 0x3100) \
&& BOOST_WORKAROUND(__MWERKS__, BOOST_TESTED_AT(0x3201)))
# line BOOST_PP_LINE(__LINE__, target.hpp(function_pointers))
# endif
# define N BOOST_PP_ITERATION()
template <class R BOOST_PP_ENUM_TRAILING_PARAMS_Z(1, N, class A)>
boost::type<BOOST_PP_IF(N, A0, void)>* target(R (*)(BOOST_PP_ENUM_PARAMS_Z(1, N, A)))
BOOST_PP_IF(N, A0, void)(* target(R (*)(BOOST_PP_ENUM_PARAMS_Z(1, N, A))) )()
{
return 0;
}
@@ -59,14 +62,17 @@ boost::type<BOOST_PP_IF(N, A0, void)>* target(R (*)(BOOST_PP_ENUM_PARAMS_Z(1, N,
# include BOOST_PP_ITERATE()
#elif BOOST_PP_ITERATION_DEPTH() == 2
# line BOOST_PP_LINE(__LINE__, target.hpp(pointers-to-members))
# if !(BOOST_WORKAROUND(__MWERKS__, > 0x3100) \
&& BOOST_WORKAROUND(__MWERKS__, BOOST_TESTED_AT(0x3201)))
# line BOOST_PP_LINE(__LINE__, target.hpp(pointers-to-members))
# endif
// Inner over arities
# define N BOOST_PP_ITERATION()
# define Q BOOST_PYTHON_CV_QUALIFIER(BOOST_PP_RELATIVE_ITERATION(1))
template <class R, class T BOOST_PP_ENUM_TRAILING_PARAMS_Z(1, N, class A)>
boost::type<T Q*>* target(R (T::*)(BOOST_PP_ENUM_PARAMS_Z(1, N, A)) Q)
T& (* target(R (T::*)(BOOST_PP_ENUM_PARAMS_Z(1, N, A)) Q) )()
{
return 0;
}

View File

@@ -13,7 +13,7 @@
# if BOOST_PYTHON_MAX_ARITY + 2 > BOOST_PYTHON_MAX_BASES
# define BOOST_PYTHON_LIST_SIZE BOOST_PP_INC(BOOST_PP_INC(BOOST_PYTHON_MAX_ARITY))
# else
# define BOOST_PYTHON_BASE_LIST_SIZE BOOST_PYTHON_MAX_BASES
# define BOOST_PYTHON_LIST_SIZE BOOST_PYTHON_MAX_BASES
# endif
// Compute the MPL vector header to use for lists up to BOOST_PYTHON_LIST_SIZE in length

View File

@@ -14,8 +14,10 @@
namespace boost { namespace python {
struct BOOST_PYTHON_DECL error_already_set {};
struct BOOST_PYTHON_DECL argument_error : error_already_set {};
struct BOOST_PYTHON_DECL error_already_set
{
virtual ~error_already_set();
};
// Handles exceptions caught just before returning to Python code.
// Returns true iff an exception was caught.
@@ -34,7 +36,6 @@ inline void handle_exception()
handle_exception(detail::rethrow);
}
BOOST_PYTHON_DECL void throw_argument_error();
BOOST_PYTHON_DECL void throw_error_already_set();
template <class T>

View File

@@ -81,7 +81,12 @@ class handle
{
}
handle& operator=(handle const& r);
handle& operator=(handle const& r)
{
python::xdecref(m_p);
m_p = python::xincref(r.m_p);
return *this;
}
#if !defined(BOOST_MSVC) || (BOOST_MSVC > 1200)
@@ -132,6 +137,24 @@ class handle
T* m_p;
};
#ifdef BOOST_NO_ARGUMENT_DEPENDENT_LOOKUP
} // namespace python
#endif
template<class T> inline T * get_pointer(python::handle<T> const & p)
{
return p.get();
}
#ifdef BOOST_NO_ARGUMENT_DEPENDENT_LOOKUP
namespace python {
#else
// We don't want get_pointer above to hide the others
using boost::get_pointer;
#endif
typedef handle<PyTypeObject> type_handle;
//
@@ -189,14 +212,6 @@ inline handle<T>::~handle()
python::xdecref(m_p);
}
template <class T>
inline handle<T>& handle<T>::operator=(handle<T> const& r)
{
python::xdecref(m_p);
m_p = python::xincref(r.m_p);
return *this;
}
template <class T>
inline T* handle<T>::operator->() const
{

View File

@@ -7,6 +7,7 @@
# define HAS_BACK_REFERENCE_DWA2002323_HPP
# include <boost/python/detail/prefix.hpp>
# include <boost/mpl/bool.hpp>
namespace boost { namespace python {
@@ -14,8 +15,8 @@ namespace boost { namespace python {
// contains a back-reference to its owning PyObject*
template <class T>
struct has_back_reference
: mpl::false_
{
BOOST_STATIC_CONSTANT(bool, value = false);
};

View File

@@ -15,6 +15,7 @@
#include <boost/python/detail/type_list.hpp>
#include <boost/python/args_fwd.hpp>
#include <boost/python/detail/make_keyword_range_fn.hpp>
#include <boost/python/def_visitor.hpp>
#include <boost/mpl/if.hpp>
#include <boost/mpl/apply_if.hpp>
@@ -110,10 +111,13 @@ namespace detail
#endif
template <int NDefaults>
struct define_class_init_helper;
} // namespace detail
template <class DerivedT>
struct init_base
struct init_base : def_visitor<DerivedT>
{
init_base(char const* doc_, detail::keyword_range const& keywords_)
: m_doc(doc_), m_keywords(keywords_)
@@ -122,7 +126,7 @@ struct init_base
init_base(char const* doc_)
: m_doc(doc_)
{}
DerivedT const& derived() const
{
return *static_cast<DerivedT const*>(this);
@@ -142,6 +146,39 @@ struct init_base
{
return default_call_policies();
}
private:
// visit
//
// Defines a set of n_defaults + 1 constructors for its
// class_<...> argument. Each constructor after the first has
// one less argument to its right. Example:
//
// init<int, optional<char, long, double> >
//
// Defines:
//
// __init__(int, char, long, double)
// __init__(int, char, long)
// __init__(int, char)
// __init__(int)
template <class classT>
void visit(classT& cl) const
{
typedef typename DerivedT::signature signature;
typedef typename DerivedT::n_arguments n_arguments;
typedef typename DerivedT::n_defaults n_defaults;
detail::define_class_init_helper<n_defaults::value>::apply(
cl
, derived().call_policies()
, signature()
, n_arguments()
, derived().doc_string()
, derived().keywords());
}
friend class python::def_visitor_access;
private: // data members
char const* m_doc;
@@ -203,22 +240,22 @@ class init : public init_base<init<BOOST_PYTHON_OVERLOAD_ARGS> >
: base(doc_)
{
}
template <class Keywords>
init(char const* doc_, Keywords const& kw)
: base(doc_, std::make_pair(kw.base(), kw.base() + Keywords::size))
{
typedef typename detail::error::more_keywords_than_init_arguments<
Keywords::size, n_arguments::value
>::too_many_keywords assertion;
}
template <class Keywords>
init(Keywords const& kw, char const* doc_ = 0)
template <std::size_t N>
init(char const* doc_, detail::keywords<N> const& kw)
: base(doc_, kw.range())
{
typedef typename detail::error::more_keywords_than_init_arguments<
Keywords::size, n_arguments::value
N, n_arguments::value
>::too_many_keywords assertion;
}
template <std::size_t N>
init(detail::keywords<N> const& kw, char const* doc_ = 0)
: base(doc_, kw.range())
{
typedef typename detail::error::more_keywords_than_init_arguments<
N, n_arguments::value
>::too_many_keywords assertion;
}
@@ -291,23 +328,14 @@ namespace detail
, detail::keyword_range const& keywords_
)
{
typedef typename ClassT::holder_selector holder_selector_t;
# if !BOOST_WORKAROUND(__MWERKS__, <= 0x2407)
typedef typename holder_selector_t::type selector_t;
# endif
typedef typename ClassT::held_type held_type_t;
typedef typename ClassT::select_holder selector_t;
cl.def(
"__init__",
detail::make_keyword_range_constructor<Signature,NArgs>(
policies
, keywords_
# if BOOST_WORKAROUND(__MWERKS__, <= 0x2407)
// Using runtime type selection works around a CWPro7 bug.
, holder_selector_t::execute((held_type_t*)0).get()
# else
, selector_t::get()
# endif
)
, doc
);
@@ -326,7 +354,8 @@ namespace detail
//
///////////////////////////////////////////////////////////////////////////////
template <int NDefaults>
struct define_class_init_helper {
struct define_class_init_helper
{
template <class ClassT, class CallPoliciesT, class Signature, class NArgs>
static void apply(
@@ -364,50 +393,17 @@ namespace detail
template <class ClassT, class CallPoliciesT, class Signature, class NArgs>
static void apply(
ClassT& cl
, CallPoliciesT const& policies
, Signature const& args
, NArgs
, char const* doc
, detail::keyword_range const& keywords)
, CallPoliciesT const& policies
, Signature const& args
, NArgs
, char const* doc
, detail::keyword_range const& keywords)
{
def_init_aux(cl, args, NArgs(), policies, doc, keywords);
detail::def_init_aux(cl, args, NArgs(), policies, doc, keywords);
}
};
}
///////////////////////////////////////////////////////////////////////////////
//
// define_init
//
// Accepts a class_ and an init-list. Defines a set of constructors for
// the class given the arguments. The init list (see init above) has
// n_defaults (number of default arguments and n_arguments (number of
// actual arguments). This function defines n_defaults + 1 constructors
// for the class. Each constructor after the first has one less argument
// to its right. Example:
//
// init<int, default<char, long, double>
//
// Defines:
//
// __init__(int, char, long, double)
// __init__(int, char, long)
// __init__(int, char)
// __init__(int)
//
///////////////////////////////////////////////////////////////////////////////
template <class ClassT, class InitT>
void
define_init(ClassT& cl, InitT const& i)
{
typedef typename InitT::signature signature;
typedef typename InitT::n_arguments n_arguments;
typedef typename InitT::n_defaults n_defaults;
detail::define_class_init_helper<n_defaults::value>::apply(
cl, i.call_policies(), signature(), n_arguments(), i.doc_string(), i.keywords());
}
}} // namespace boost::python
#undef BOOST_PYTHON_OVERLOAD_TYPES_WITH_DEFAULT

View File

@@ -11,9 +11,13 @@
# include <boost/python/detail/target.hpp>
# include <boost/python/object/iterator.hpp>
# include <boost/python/object_core.hpp>
# include <boost/type_traits/cv_traits.hpp>
# include <boost/type_traits/transform_traits.hpp>
# include <boost/bind.hpp>
# include <boost/bind/protect.hpp>
namespace boost { namespace python {
namespace detail
@@ -21,14 +25,19 @@ namespace detail
// Adds an additional layer of binding to
// objects::make_iterator(...), which allows us to pass member
// function and member data pointers.
template <class NextPolicies, class Target, class Accessor1, class Accessor2>
template <class Target, class Accessor1, class Accessor2, class NextPolicies>
inline object make_iterator(
Accessor1 get_start, Accessor2 get_finish, boost::type<Target>* target = 0, NextPolicies* = 0)
Accessor1 get_start
, Accessor2 get_finish
, NextPolicies next_policies
, Target&(*)()
)
{
return objects::make_iterator_function<NextPolicies,Target>(
return objects::make_iterator_function<Target>(
boost::protect(boost::bind(get_start, _1))
, boost::protect(boost::bind(get_finish, _1))
);
, boost::protect(boost::bind(get_finish, _1))
, next_policies
);
}
// Guts of template class iterators<>, below.
@@ -73,9 +82,11 @@ struct iterators
template <class Accessor1, class Accessor2>
object range(Accessor1 start, Accessor2 finish)
{
return detail::make_iterator<objects::default_iterator_call_policies>(
start, finish
, detail::target(start));
return detail::make_iterator(
start, finish
, objects::default_iterator_call_policies()
, detail::target(start)
);
}
// Create an iterator-building function which uses the given accessors
@@ -83,7 +94,7 @@ object range(Accessor1 start, Accessor2 finish)
template <class NextPolicies, class Accessor1, class Accessor2>
object range(Accessor1 start, Accessor2 finish, NextPolicies* = 0)
{
return detail::make_iterator<NextPolicies>(start, finish, detail::target(start));
return detail::make_iterator(start, finish, NextPolicies(), detail::target(start));
}
// Create an iterator-building function which uses the given accessors
@@ -91,8 +102,8 @@ object range(Accessor1 start, Accessor2 finish, NextPolicies* = 0)
template <class NextPolicies, class Target, class Accessor1, class Accessor2>
object range(Accessor1 start, Accessor2 finish, NextPolicies* = 0, boost::type<Target>* = 0)
{
typedef typename add_reference<Target>::type target;
return detail::make_iterator<NextPolicies, target>(start, finish);
// typedef typename add_reference<Target>::type target;
return detail::make_iterator(start, finish, NextPolicies(), (Target&(*)())0);
}
// A Python callable object which produces an iterator traversing

View File

@@ -38,13 +38,13 @@ class long_ : public detail::long_base
template <class T>
explicit long_(T const& rhs)
: base(object(rhs))
: detail::long_base(object(rhs))
{
}
template <class T, class U>
explicit long_(T const& rhs, U const& base)
: base(object(rhs), object(base))
: detail::long_base(object(rhs), object(base))
{
}

View File

@@ -0,0 +1,279 @@
// Copyright David Abrahams 2001. Permission to copy, use,
// modify, sell and distribute this software is granted provided this
// copyright notice appears in all copies. This software is provided
// "as is" without express or implied warranty, and with no claim as
// to its suitability for any purpose.
#ifndef MAKE_CONSTRUCTOR_DWA20011221_HPP
# define MAKE_CONSTRUCTOR_DWA20011221_HPP
# include <boost/python/detail/prefix.hpp>
# include <boost/python/default_call_policies.hpp>
# include <boost/python/args.hpp>
# include <boost/python/object_fwd.hpp>
# include <boost/python/object/function_object.hpp>
# include <boost/python/object/make_holder.hpp>
# include <boost/python/object/pointer_holder.hpp>
# include <boost/python/converter/context_result_converter.hpp>
# include <boost/python/detail/caller.hpp>
# include <boost/python/detail/none.hpp>
# include <boost/mpl/size.hpp>
# include <boost/mpl/int.hpp>
# include <boost/mpl/push_front.hpp>
# include <boost/mpl/pop_front.hpp>
namespace boost { namespace python {
namespace detail
{
template <class T>
struct install_holder : converter::context_result_converter
{
install_holder(PyObject* args_)
: m_self(PyTuple_GetItem(args_, 0)) {}
PyObject* operator()(T x) const
{
dispatch(x, is_pointer<T>());
return none();
}
private:
template <class U>
void dispatch(U* x, mpl::true_) const
{
std::auto_ptr<U> owner(x);
dispatch(owner, mpl::false_());
}
template <class Ptr>
void dispatch(Ptr x, mpl::false_) const
{
typedef typename pointee<Ptr>::type value_type;
typedef objects::pointer_holder<Ptr,value_type> holder;
typedef objects::instance<holder> instance_t;
void* memory = holder::allocate(this->m_self, offsetof(instance_t, storage), sizeof(holder));
try {
(new (memory) holder(x))->install(this->m_self);
}
catch(...) {
holder::deallocate(this->m_self, memory);
throw;
}
}
PyObject* m_self;
};
struct constructor_result_converter
{
template <class T>
struct apply
{
typedef install_holder<T> type;
};
};
template <class BaseArgs, class Offset>
struct offset_args
{
offset_args(BaseArgs base_) : base(base_) {}
BaseArgs base;
};
template <int N, class BaseArgs, class Offset>
inline PyObject* get(mpl::int_<N>, offset_args<BaseArgs,Offset> const& args_)
{
return get(mpl::int_<(N+Offset::value)>(), args_.base);
}
template <class BaseArgs, class Offset>
inline unsigned arity(offset_args<BaseArgs,Offset> const& args_)
{
return arity(args_.base) - Offset::value;
}
template <class BasePolicy_ = default_call_policies>
struct constructor_policy : BasePolicy_
{
constructor_policy(BasePolicy_ base) : BasePolicy_(base) {}
// If the BasePolicy_ supplied a result converter it would be
// ignored; issue an error if it's not the default.
BOOST_STATIC_ASSERT((
is_same<
typename BasePolicy_::result_converter
, default_result_converter
>::value
));
typedef constructor_result_converter result_converter;
typedef offset_args<typename BasePolicy_::argument_package, mpl::int_<1> > argument_package;
};
template <class InnerSignature>
struct outer_constructor_signature
{
typedef typename mpl::pop_front<InnerSignature>::type inner_args;
typedef typename mpl::push_front<inner_args,object>::type outer_args;
typedef typename mpl::push_front<outer_args,void>::type type;
};
// ETI workaround
template <>
struct outer_constructor_signature<int>
{
typedef int type;
};
//
// These helper functions for make_constructor (below) do the raw work
// of constructing a Python object from some invokable entity. See
// <boost/python/detail/caller.hpp> for more information about how
// the Sig arguments is used.
//
// @group make_constructor_aux {
template <class F, class CallPolicies, class Sig>
object make_constructor_aux(
F f // An object that can be invoked by detail::invoke()
, CallPolicies const& p // CallPolicies to use in the invocation
, Sig const& // An MPL sequence of argument types expected by F
)
{
typedef typename outer_constructor_signature<Sig>::type outer_signature;
typedef constructor_policy<CallPolicies> inner_policy;
return objects::function_object(
objects::py_function(
detail::caller<F,inner_policy,Sig>(f, inner_policy(p))
, outer_signature()
)
);
}
// As above, except that it accepts argument keywords. NumKeywords
// is used only for a compile-time assertion to make sure the user
// doesn't pass more keywords than the function can accept. To
// disable all checking, pass mpl::int_<0> for NumKeywords.
template <class F, class CallPolicies, class Sig, class NumKeywords>
object make_constructor_aux(
F f
, CallPolicies const& p
, Sig const&
, detail::keyword_range const& kw // a [begin,end) pair of iterators over keyword names
, NumKeywords // An MPL integral type wrapper: the size of kw
)
{
enum { arity = mpl::size<Sig>::value - 1 };
typedef typename detail::error::more_keywords_than_function_arguments<
NumKeywords::value, arity
>::too_many_keywords assertion;
typedef typename outer_constructor_signature<Sig>::type outer_signature;
typedef constructor_policy<CallPolicies> inner_policy;
return objects::function_object(
objects::py_function(
detail::caller<F,inner_policy,Sig>(f, inner_policy(p))
, outer_signature()
)
);
}
// }
//
// These dispatch functions are used to discriminate between the
// cases when the 3rd argument is keywords or when it is a
// signature.
//
// @group Helpers for make_constructor when called with 3 arguments. {
//
template <class F, class CallPolicies, class Keywords>
object make_constructor_dispatch(F f, CallPolicies const& policies, Keywords const& kw, mpl::true_)
{
return detail::make_constructor_aux(
f
, policies
, detail::get_signature(f)
, kw.range()
, mpl::int_<Keywords::size>()
);
}
template <class F, class CallPolicies, class Signature>
object make_constructor_dispatch(F f, CallPolicies const& policies, Signature const& sig, mpl::false_)
{
return detail::make_constructor_aux(
f
, policies
, sig
);
}
// }
}
// These overloaded functions wrap a function or member function
// pointer as a Python object, using optional CallPolicies,
// Keywords, and/or Signature. @group {
//
template <class F>
object make_constructor(F f)
{
return detail::make_constructor_aux(
f,default_call_policies(), detail::get_signature(f));
}
template <class F, class CallPolicies>
object make_constructor(F f, CallPolicies const& policies)
{
return detail::make_constructor_aux(
f, policies, detail::get_signature(f));
}
template <class F, class CallPolicies, class KeywordsOrSignature>
object make_constructor(
F f
, CallPolicies const& policies
, KeywordsOrSignature const& keywords_or_signature)
{
typedef typename
detail::is_reference_to_keywords<KeywordsOrSignature&>::type
is_kw;
return detail::make_constructor_dispatch(
f
, policies
, keywords_or_signature
, is_kw()
);
}
template <class F, class CallPolicies, class Keywords, class Signature>
object make_constructor(
F f
, CallPolicies const& policies
, Keywords const& kw
, Signature const& sig
)
{
return detail::make_constructor_aux(
f
, policies
, sig
, kw.range()
, mpl::int_<Keywords::size>()
);
}
// }
}}
#endif // MAKE_CONSTRUCTOR_DWA20011221_HPP

View File

@@ -9,7 +9,7 @@
# include <boost/python/detail/prefix.hpp>
# include <boost/python/default_call_policies.hpp>
# include <boost/python/args_fwd.hpp>
# include <boost/python/args.hpp>
# include <boost/python/detail/caller.hpp>
# include <boost/python/object/function_object.hpp>
@@ -26,29 +26,27 @@ namespace detail
// These helper functions for make_function (below) do the raw work
// of constructing a Python object from some invokable entity. See
// <boost/python/detail/caller.hpp> for more information about how
// the ConverterGenerators and Sig arguments are used.
template <class F, class CallPolicies, class ConverterGenerators, class Sig>
// the Sig arguments is used.
template <class F, class CallPolicies, class Sig>
object make_function_aux(
F f // An object that can be invoked by detail::invoke()
, CallPolicies const& p // CallPolicies to use in the invocation
, ConverterGenerators const& // An MPL iterator over a sequence of arg_from_python generators
, Sig const& // An MPL sequence of argument types expected by F
)
{
return objects::function_object(
detail::caller<F,ConverterGenerators,CallPolicies,Sig>(f, p)
, mpl::size<Sig>::value - 1);
detail::caller<F,CallPolicies,Sig>(f, p)
);
}
// As above, except that it accepts argument keywords. NumKeywords
// is used only for a compile-time assertion to make sure the user
// doesn't pass more keywords than the function can accept. To
// disable all checking, pass mpl::int_<0> for NumKeywords.
template <class F, class CallPolicies, class ConverterGenerators, class Sig, class NumKeywords>
template <class F, class CallPolicies, class Sig, class NumKeywords>
object make_function_aux(
F f
, CallPolicies const& p
, ConverterGenerators const&
, Sig const&
, detail::keyword_range const& kw // a [begin,end) pair of iterators over keyword names
, NumKeywords // An MPL integral type wrapper: the size of kw
@@ -61,43 +59,94 @@ namespace detail
>::too_many_keywords assertion;
return objects::function_object(
detail::caller<F,ConverterGenerators,CallPolicies,Sig>(f, p)
, arity
, kw);
detail::caller<F,CallPolicies,Sig>(f, p)
, kw);
}
}
// make_function --
// Helpers for make_function when called with 3 arguments. These
// dispatch functions are used to discriminate between the cases
// when the 3rd argument is keywords or when it is a signature.
//
// @group {
template <class F, class CallPolicies, class Keywords>
object make_function_dispatch(F f, CallPolicies const& policies, Keywords const& kw, mpl::true_)
{
return detail::make_function_aux(
f
, policies
, detail::get_signature(f)
, kw.range()
, mpl::int_<Keywords::size>()
);
}
template <class F, class CallPolicies, class Signature>
object make_function_dispatch(F f, CallPolicies const& policies, Signature const& sig, mpl::false_)
{
return detail::make_function_aux(
f
, policies
, sig
);
}
// }
}
// These overloaded functions wrap a function or member function
// pointer as a Python object, using optional CallPolicies,
// Keywords, and/or Signature.
//
// These overloaded functions wrap a function or member function
// pointer as a Python object, using optional CallPolicies and
// Keywords.
// @group {
template <class F>
object make_function(F f)
{
return detail::make_function_aux(
f,default_call_policies(),detail::args_from_python(), detail::get_signature(f));
f,default_call_policies(), detail::get_signature(f));
}
template <class F, class CallPolicies>
object make_function(F f, CallPolicies const& policies)
{
return detail::make_function_aux(
f,policies,detail::args_from_python(), detail::get_signature(f));
f, policies, detail::get_signature(f));
}
template <class F, class CallPolicies, class Keywords>
object make_function(F f, CallPolicies const& policies, Keywords const& keywords)
template <class F, class CallPolicies, class KeywordsOrSignature>
object make_function(
F f
, CallPolicies const& policies
, KeywordsOrSignature const& keywords_or_signature)
{
typedef typename
detail::is_reference_to_keywords<KeywordsOrSignature&>::type
is_kw;
return detail::make_function_dispatch(
f
, policies
, keywords_or_signature
, is_kw()
);
}
template <class F, class CallPolicies, class Keywords, class Signature>
object make_function(
F f
, CallPolicies const& policies
, Keywords const& kw
, Signature const& sig
)
{
return detail::make_function_aux(
f
f
, policies
, detail::args_from_python()
, detail::get_signature(f)
, keywords.range()
, sig
, kw.range()
, mpl::int_<Keywords::size>()
);
);
}
// }
}}

View File

@@ -14,11 +14,4 @@
# include <boost/python/object_operators.hpp>
# include <boost/python/converter/arg_to_python.hpp>
namespace boost { namespace python {
class type_; // XXX temporary work-around
class string;
}} // namespace boost::python
#endif // OBJECT_DWA2002612_HPP

View File

@@ -8,7 +8,6 @@
# include <boost/python/detail/prefix.hpp>
# include <boost/utility.hpp>
# include <boost/python/instance_holder.hpp>
# include <boost/python/object_core.hpp>
# include <boost/python/type_id.hpp>
# include <cstddef>
@@ -59,6 +58,8 @@ struct BOOST_PYTHON_DECL class_base : python::api::object
void make_method_static(const char *method_name);
};
BOOST_PYTHON_DECL void copy_class_object(type_info const& src, type_info const& dst);
}}} // namespace boost::python::objects
#endif // CLASS_DWA20011214_HPP

View File

@@ -18,6 +18,8 @@
# include <boost/mpl/for_each.hpp>
# include <boost/detail/workaround.hpp>
namespace boost { namespace python { namespace objects {
//////////////////////////////////////////////////////////////////////
@@ -76,8 +78,9 @@ struct register_base_of
template <class Derived, class Bases>
inline void register_class_from_python(Derived* = 0, Bases* = 0)
{
python::detail::force_instantiate(converter::shared_ptr_from_python<Derived>::registration);
// Static object constructor performs registration
static converter::shared_ptr_from_python<Derived> shared_ptr_registration;
// register all up/downcasts here
register_dynamic_id<Derived>();

View File

@@ -11,6 +11,11 @@
# include <boost/type_traits/add_const.hpp>
# include <boost/type_traits/add_reference.hpp>
# include <boost/ref.hpp>
# if BOOST_WORKAROUND(BOOST_MSVC, == 1200)
# include <boost/type_traits/is_enum.hpp>
# include <boost/mpl/and.hpp>
# include <boost/mpl/not.hpp>
# endif
namespace boost { namespace python { namespace objects {
@@ -34,7 +39,17 @@ struct reference_to_value
template <class T>
struct forward
: mpl::if_<
is_scalar<T>
# if BOOST_WORKAROUND(BOOST_MSVC, == 1200)
// vc6 chokes on unforwarding enums nested in classes
mpl::and_<
is_scalar<T>
, mpl::not_<
is_enum<T>
>
>
# else
is_scalar<T>
# endif
, T
, reference_to_value<T>
>

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