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

Compare commits

...

725 Commits

Author SHA1 Message Date
Marshall Clow
f54dfbcc22 Release 1.51.0
[SVN r80098]
2012-08-20 22:07:05 +00:00
Ralf W. Grosse-Kunstleve
46796f3413 merging current boost/python and libs/python from trunk into release branch
[SVN r79096]
2012-06-25 22:09:52 +00:00
Ralf W. Grosse-Kunstleve
0b8b88abc7 merging current boost/python and libs/python from trunk into release branch
[SVN r79011]
2012-06-19 20:01:25 +00:00
Ralf W. Grosse-Kunstleve
76db3311ed merging current boost/python and libs/python from trunk into release branch
[SVN r77125]
2012-02-27 02:49:42 +00:00
Ralf W. Grosse-Kunstleve
7acb544b47 merging current boost/python and libs/python from trunk into release branch
[SVN r76422]
2012-01-11 23:48:18 +00:00
Daniel James
f054b64315 Merge python doc rebuild to release.
[SVN r76359]
2012-01-08 10:07:09 +00:00
Ralf W. Grosse-Kunstleve
9064a063b2 merging current boost/python and libs/python from trunk into release branch
[SVN r75919]
2011-12-12 17:46:33 +00:00
Ralf W. Grosse-Kunstleve
fa24dbb88f merging current boost/python and libs/python from trunk into release branch
[SVN r75414]
2011-11-08 21:27:05 +00:00
Ralf W. Grosse-Kunstleve
49e8699b9f merging current boost/python and libs/python from trunk into release branch
[SVN r74931]
2011-10-12 21:38:53 +00:00
Ralf W. Grosse-Kunstleve
cfa2baf8c9 merging current boost/python and libs/python from trunk into release branch
[SVN r72464]
2011-06-07 04:15:33 +00:00
Ralf W. Grosse-Kunstleve
faf3cd0b78 merging current boost/python and libs/python from trunk into release branch
[SVN r72277]
2011-05-30 05:51:49 +00:00
Ralf W. Grosse-Kunstleve
a5e564be83 merging current boost/python and libs/python from trunk into release branch
[SVN r71226]
2011-04-13 17:34:35 +00:00
Dave Abrahams
dcc3590907 verifying commit privs
[SVN r71150]
2011-04-09 16:55:43 +00:00
Ralf W. Grosse-Kunstleve
74daea3d88 boost/libs/python/doc/PyConDC_2003: removing $Date$ and $Revision$ so they do not create noise on each merge to the release branch
[SVN r71004]
2011-04-05 16:49:31 +00:00
Ralf W. Grosse-Kunstleve
e28f0509d8 merging current boost/python and libs/python from trunk into release branch
[SVN r71002]
2011-04-05 16:31:51 +00:00
Ralf W. Grosse-Kunstleve
0a211a746d merging current boost/python and libs/python from trunk into release branch
[SVN r70448]
2011-03-23 00:14:55 +00:00
Ralf W. Grosse-Kunstleve
ba213663b6 merging current boost/python and libs/python from trunk into release branch
[SVN r67483]
2010-12-28 20:38:29 +00:00
Ralf W. Grosse-Kunstleve
736ba48c2b merging current boost/python and libs/python from trunk into release branch
[SVN r67446]
2010-12-24 17:31:05 +00:00
Eric Niebler
6066ffef9a Merged revisions 66606 via svnmerge from
https://svn.boost.org/svn/boost/trunk

........
  r66606 | rwgk | 2010-11-15 18:17:00 -0500 (Mon, 15 Nov 2010) | 1 line
  
  boost/python/object/make_instance.hpp: adding missing includes
........


[SVN r66614]
2010-11-16 18:30:39 +00:00
Ralf W. Grosse-Kunstleve
f759e9eb0e merging current boost/python and libs/python from trunk into release branch
[SVN r66066]
2010-10-18 04:04:52 +00:00
Douglas Gregor
846c5d9914 Add missing includes
[SVN r65142]
2010-08-31 04:50:56 +00:00
Ralf W. Grosse-Kunstleve
65b3aadc63 merging current boost/python and libs/python from trunk into release branch
[SVN r63937]
2010-07-12 22:29:41 +00:00
Hartmut Kaiser
e13ebcd0e8 Spirit: merging from trunk upto rev. 61489
[SVN r63640]
2010-07-04 22:38:38 +00:00
Marshall Clow
63a3f188b8 Merged changes for #2981, #4166, and #4377 to release branch
[SVN r63523]
2010-07-02 15:37:14 +00:00
Daniel James
34b162738f Merge documentation update.
[SVN r63517]
2010-07-02 08:27:42 +00:00
Daniel James
569b395cdd Merge documentation fixes.
* Use `doc/src/*.css` instead of `doc/html/*.css`.
* Remove wiki and people directories.
* Some documentation fixes.
* Left out `minimal.css` changes and boostbook changes because of clashes.


[SVN r63347]
2010-06-26 12:30:09 +00:00
Douglas Gregor
4b9cb5337d Include all of the headers needed for the BOOST_MPL_ASSERT that is failing for several compilers
[SVN r62015]
2010-05-16 01:27:58 +00:00
Ralf W. Grosse-Kunstleve
86db60255a libs/python/test/Jamfile.v2: disabling calling_conventions tests
[SVN r61034]
2010-04-04 05:23:15 +00:00
Ralf W. Grosse-Kunstleve
37b45d2baf merging current boost/python and libs/python from trunk into release branch
[SVN r61033]
2010-04-04 05:19:57 +00:00
Ralf W. Grosse-Kunstleve
471be524f4 boost.python: merging from trunk to release (gcc 4.4 -std=c++0x compatibility)
[SVN r57837]
2009-11-21 14:41:51 +00:00
Ralf W. Grosse-Kunstleve
e485244886 boost.python: merging from trunk to release (Troy Straszheim's fix for a long-standing bug)
[SVN r57621]
2009-11-13 00:40:01 +00:00
Troy D. Straszheim
b9cd3ff109 merge from trunk very minor fixes for ticket #2582
[SVN r57017]
2009-10-20 15:18:26 +00:00
Troy D. Straszheim
d804f1250e rm cmake from the release branch before it goes out broken. Policy dictates that you never commit to release, you commit to trunk and merge to release.
[SVN r56941]
2009-10-17 01:10:45 +00:00
Ralf W. Grosse-Kunstleve
89100353db boost/python, libs/python: all changes from trunk merged into branches/release
[SVN r56806]
2009-10-13 22:37:59 +00:00
Ralf W. Grosse-Kunstleve
46be73387c boost/python/object_operators.hpp: merging trunk rev. 55708 into release branch
[SVN r55742]
2009-08-23 21:22:52 +00:00
Ralf W. Grosse-Kunstleve
d685a5e8c5 python library: sync with trunk to adopt recent exec.cpp fixes
[SVN r55642]
2009-08-18 01:08:46 +00:00
Ralf W. Grosse-Kunstleve
e80224b1ad boost/python, libs/python: all changes from trunk merged into branches/release (without any manual modifications)
Commands used:
  svn merge https://svn.boost.org/svn/boost/branches/release/boost/python https://svn.boost.org/svn/boost/trunk/boost/python /net/chevy/raid1/rwgk/boost_release/merge_attempt/boost/boost/python

  svn merge https://svn.boost.org/svn/boost/branches/release/libs/python https://svn.boost.org/svn/boost/trunk/libs/python /net/chevy/raid1/rwgk/boost_release/merge_attempt/boost/libs/python

  svn, version 1.6.4 (r38063)
     compiled Aug 17 2009, 13:31:03


[SVN r55629]
2009-08-17 21:01:18 +00:00
Troy D. Straszheim
03fdf5b992 Add basic copyright/license to keep cmake out of the inspection report
[SVN r55095]
2009-07-22 21:51:01 +00:00
Jeremiah Willcock
73b4cd3325 Fixed almost all tab and min/max issues found by inspect tool
[SVN r53142]
2009-05-20 19:41:20 +00:00
Douglas Gregor
f7d31f6ead Fix Boost.Python tests
[SVN r52856]
2009-05-08 20:42:11 +00:00
Douglas Gregor
47bb3f55a7 Add the pyrun.py script used to run Boost.Python tests via CMake
[SVN r52818]
2009-05-07 04:44:23 +00:00
Joel de Guzman
6296bd5bc4 bumped wrong version
[SVN r52656]
2009-04-29 08:16:02 +00:00
John Maddock
217250f078 Merge PDF build changes from Trunk.
[SVN r51417]
2009-02-23 18:39:32 +00:00
Troy D. Straszheim
29152af56c merge of cmake build files from trunk per beman
[SVN r50756]
2009-01-24 18:57:20 +00:00
Daniel James
19846f5d79 Merge quickbook workaround and fix some links.
Merged revisions 48987,49230-49231 via svnmerge from 
https://svn.boost.org/svn/boost/trunk

........
  r48987 | danieljames | 2008-09-28 13:21:39 +0100 (Sun, 28 Sep 2008) | 1 line
  
  Clean up some link errors.
........
  r49230 | danieljames | 2008-10-09 23:13:48 +0100 (Thu, 09 Oct 2008) | 1 line
  
  position_iterator is meant to be a forward iterator, so avoid using operator+ with it.
........
  r49231 | danieljames | 2008-10-09 23:14:14 +0100 (Thu, 09 Oct 2008) | 4 lines
  
  Work around the problems with window newlines in position_iterator. (I'm
  about to fix them, but this will get quickbook working immediately).
  
  Fixes #2155
........


[SVN r49242]
2008-10-10 09:29:21 +00:00
Dave Abrahams
a1924a2a72 Merging all trunk changes in Boost.Python to release. The logs for
these changes follow.  r44807 is a merge from another branch; many of
those changes probably don't apply.

  ------------------------------------------------------------------------
  r43423 | danieljames | 2008-02-27 14:22:01 -0500 (Wed, 27 Feb 2008) | 1 line

  Fix incorrect links to copyright of the form 'http:#www.boost.org
  ------------------------------------------------------------------------
  r43546 | rwgk | 2008-03-08 23:30:13 -0500 (Sat, 08 Mar 2008) | 1 line

  map std::invalid_argument -> Python ValueError
  ------------------------------------------------------------------------
  r43799 | grafik | 2008-03-22 18:53:35 -0400 (Sat, 22 Mar 2008) | 1 line

  Remove svn exec property from files that should not be executable to fix permission problems in archives.
  ------------------------------------------------------------------------
  r43845 | dave | 2008-03-24 14:27:22 -0400 (Mon, 24 Mar 2008) | 1 line

  Work around vc9 bugs
  ------------------------------------------------------------------------
  r43901 | bemandawes | 2008-03-27 22:11:13 -0400 (Thu, 27 Mar 2008) | 1 line

  Remove per email from Dave
  ------------------------------------------------------------------------
  r44041 | rwgk | 2008-04-04 14:57:27 -0400 (Fri, 04 Apr 2008) | 1 line

  bogus VC8 warning C4180 disabled
  ------------------------------------------------------------------------
  r44449 | djowel | 2008-04-15 23:07:06 -0400 (Tue, 15 Apr 2008) | 1 line

  Andreas patch
  ------------------------------------------------------------------------
  r44450 | djowel | 2008-04-15 23:07:11 -0400 (Tue, 15 Apr 2008) | 1 line

  Andreas indexing suite patch
  ------------------------------------------------------------------------
  r44807 | danieljames | 2008-04-27 03:39:49 -0400 (Sun, 27 Apr 2008) | 78 lines

  Merge in documentation fixes.  Apart from the change to optional's documenation
  Jamfile, which I included by mistake.

  Fixes #1659, #1661, #1684, #1685, 1687, #1690, #1801

  I wrote about this at:

  http://lists.boost.org/Archives/boost/2008/04/136405.php

  Merged revisions 44585-44806 via svnmerge from 
  https://svn.boost.org/svn/boost/branches/doc

  ........
    r44585 | danieljames | 2008-04-19 16:25:27 +0100 (Sat, 19 Apr 2008) | 2 lines

    Fix broken link to vacpp in bjam docs. Refs #1512
  ........
    r44586 | danieljames | 2008-04-19 16:27:36 +0100 (Sat, 19 Apr 2008) | 2 lines

    Fix broken link to bcpp in bjam docs. Refs #1513
  ........
    r44587 | danieljames | 2008-04-19 16:33:58 +0100 (Sat, 19 Apr 2008) | 2 lines

    DateTime documentation - Fix a link to the serialization library. Refs #1659
  ........
    r44588 | danieljames | 2008-04-19 16:35:36 +0100 (Sat, 19 Apr 2008) | 2 lines

    Fix some links in interprocess & intrusive. Refs #1661
  ........
    r44589 | danieljames | 2008-04-19 16:37:39 +0100 (Sat, 19 Apr 2008) | 2 lines

    Fix some links in the python docs. Refs #1684.
  ........
    r44590 | danieljames | 2008-04-19 16:38:29 +0100 (Sat, 19 Apr 2008) | 2 lines

    Work around a quickbook bug which is affecting the python docs. Refs #1684.
  ........
    r44591 | danieljames | 2008-04-19 16:39:34 +0100 (Sat, 19 Apr 2008) | 2 lines

    Fix a broken link in the numeric conversion docs. Refs #1685
  ........
    r44592 | danieljames | 2008-04-19 16:40:45 +0100 (Sat, 19 Apr 2008) | 2 lines

    Fix some links in the optional docs. Refs #1687
  ........
    r44593 | danieljames | 2008-04-19 16:42:09 +0100 (Sat, 19 Apr 2008) | 2 lines

    Fix link to the hash documentation from bimap. Refs #1690
  ........
    r44599 | danieljames | 2008-04-19 18:07:33 +0100 (Sat, 19 Apr 2008) | 2 lines

    Fix a typo in the format library. Refs #1801
  ........
    r44600 | danieljames | 2008-04-19 19:20:59 +0100 (Sat, 19 Apr 2008) | 1 line

    Initialise svnmerge.
  ........
    r44641 | danieljames | 2008-04-20 18:59:47 +0100 (Sun, 20 Apr 2008) | 2 lines

    Fix the lincense url in shared container iterator documentation.
  ........
    r44642 | danieljames | 2008-04-20 19:00:00 +0100 (Sun, 20 Apr 2008) | 2 lines

    Fix image link in the mpi documentation.
  ........
    r44643 | danieljames | 2008-04-20 19:00:11 +0100 (Sun, 20 Apr 2008) | 2 lines

    Fix a typo in the spirit docs.
  ........
    r44644 | danieljames | 2008-04-20 19:00:23 +0100 (Sun, 20 Apr 2008) | 2 lines

    Escape the slash so that quickbook doesn't think it the start of an italic section, and mess up the link. Refs #1844
  ........
    r44647 | danieljames | 2008-04-20 19:39:47 +0100 (Sun, 20 Apr 2008) | 2 lines

    Fix another typo in spirit docs.
  ........

  ------------------------------------------------------------------------
  r45283 | danieljames | 2008-05-11 09:49:20 -0400 (Sun, 11 May 2008) | 1 line

  Quote href values - our tools don't support unquoted values.
  ------------------------------------------------------------------------
  r45359 | rwgk | 2008-05-14 15:38:08 -0400 (Wed, 14 May 2008) | 1 line

  braces added to resolve g++ 4.3.0 warning
  ------------------------------------------------------------------------
  r45918 | rwgk | 2008-05-29 15:48:55 -0400 (Thu, 29 May 2008) | 66 lines

  See Python C++-SIG thread: "object.attr(object& attrname) proposal"
  Started 2008-05-25 by hohehohe2@gmail.com.

  Excerpts:

  If char const* is passed to objecjt.attr(), it uses
  PyObject_GetAttrStrng() or PyObject_SetAttrStrng().  If object is
  passed to objecjt.attr(), it takes the object as a Python string
  object and uses PyObject_GetAttr() or PyObject_SetAttr().

  If attr() behaves like this, it can be useful when there are lots
  of objects which you know have the same attribute name. You can save
  time by first making a boost::python::object and passing it to every
  object's attr() inside a loop.

  I just made a bit of modification to boost:python locally and did a
  quick test, like

  test 1:
    for(int i = 0; i < n; ++i)
    {
      omain.attr(attrname) = 444; //attrname is a char const*
    }

  test 2:
    for(int i = 0; i < n; ++i)
    {
      object o = omain.attr(attrname); //attrname is a char const*
    }

  test 3:
    for(int i = 0; i < n; ++i)
    {
      omain.attr(oaaaa) = 444; //oaaaa is boost::python::object that represents a string
    }

  test 4:
    for(int i = 0; i < n; ++i)
    {
      object o = omain.attr(oaaaa); //oaaaa is boost::python::object that represents a string
    }

  and it reasonably reflected the difference between PyObject_*Attr() and PyObject_*AttrString.

  test 1 :2783ms
  test 2 :2357ms
  test 3 :1882ms
  test 4 :1267ms

  test5: PyObject_SetAttrString(po_main, "aaaa", po_num444);
  test6: Py_DECREF(PyObject_GetAttrString(po_main, "aaaa"));
  test7: PyObject_SetAttr(po_main, po_aaaa, po_num444);
  test8: Py_DECREF(PyObject_GetAttr(po_main, po_aaaa));
  (po_ prefixed variables are PyObject*),

  all inside each for loop, and the results were

  test 5 :2410ms
  test 6 :2277ms
  test 7 :1629ms
  test 8 :1094ms

  It's boost 1.35.0, Python 2.5 on linux(gcc4.1.2).
  I also did the same test on windows(vs8) and the tendency was not
  so different.

  ------------------------------------------------------------------------
  r45920 | rwgk | 2008-05-29 16:04:19 -0400 (Thu, 29 May 2008) | 1 line

  Projects using Boost.Python: PolyBoRi (text provided by Michael Brickenstein)
  ------------------------------------------------------------------------
  r46115 | schoepflin | 2008-06-04 11:11:05 -0400 (Wed, 04 Jun 2008) | 1 line

  Added missing ostream header file.
  ------------------------------------------------------------------------
  r46445 | dgregor | 2008-06-17 09:54:46 -0400 (Tue, 17 Jun 2008) | 1 line

  Add mime-type and eol-style properties as needed
  ------------------------------------------------------------------------
  r46721 | dave | 2008-06-26 12:41:34 -0400 (Thu, 26 Jun 2008) | 2 lines

  Compatibility with Apache STDCXX library.  Don't assume eh.h comes along with the other headers automatically.

  ------------------------------------------------------------------------
  r46808 | bemandawes | 2008-06-28 09:45:21 -0400 (Sat, 28 Jun 2008) | 1 line

  With his kind permission, change Jaakko "J<LATIN SMALL LETTER A WITH DIARESIS>rvi" to "Jarvi"
  ------------------------------------------------------------------------
  r46817 | djowel | 2008-06-28 14:24:17 -0400 (Sat, 28 Jun 2008) | 1 line

  added note on removing targets
  ------------------------------------------------------------------------
  r46844 | dave | 2008-06-29 08:26:17 -0400 (Sun, 29 Jun 2008) | 2 lines

  Make valid HTML

  ------------------------------------------------------------------------




[SVN r47459]
2008-07-15 21:05:24 +00:00
Joel de Guzman
c205cd86c6 added note on removing targets
[SVN r46900]
2008-06-30 12:14:28 +00:00
Dave Abrahams
8d86dc199c merged valid HTML from trunk
[SVN r46845]
2008-06-29 12:55:50 +00:00
Beman Dawes
55e9ff14a1 With his kind permission, change Jaakko "Järvi" to "Jarvi"
[SVN r46809]
2008-06-28 13:57:20 +00:00
Daniel James
4fea58f634 Add minor documentation fixes to the release branch.
(I left out the changes to the hash library).

Merged via svnmerge from 
https://svn.boost.org/svn/boost/trunk

................
  r44807 | danieljames | 2008-04-27 08:39:49 +0100 (Sun, 27 Apr 2008) | 78 lines
  
  Merge in documentation fixes.  Apart from the change to optional's documenation
  Jamfile, which I included by mistake.
  
  I wrote about this at:
  
  http://lists.boost.org/Archives/boost/2008/04/136405.php
  
  Merged revisions 44585-44806 via svnmerge from 
  https://svn.boost.org/svn/boost/branches/doc
  
  ........
    r44585 | danieljames | 2008-04-19 16:25:27 +0100 (Sat, 19 Apr 2008) | 2 lines
    
    Fix broken link to vacpp in bjam docs.
  ........
    r44586 | danieljames | 2008-04-19 16:27:36 +0100 (Sat, 19 Apr 2008) | 2 lines
    
    Fix broken link to bcpp in bjam docs.
  ........
    r44587 | danieljames | 2008-04-19 16:33:58 +0100 (Sat, 19 Apr 2008) | 2 lines
    
    DateTime documentation - Fix a link to the serialization library.
  ........
    r44588 | danieljames | 2008-04-19 16:35:36 +0100 (Sat, 19 Apr 2008) | 2 lines
    
    Fix some links in interprocess & intrusive.
  ........
    r44589 | danieljames | 2008-04-19 16:37:39 +0100 (Sat, 19 Apr 2008) | 2 lines
    
    Fix some links in the python docs.
  ........
    r44590 | danieljames | 2008-04-19 16:38:29 +0100 (Sat, 19 Apr 2008) | 2 lines
    
    Work around a quickbook bug which is affecting the python docs.
  ........
    r44591 | danieljames | 2008-04-19 16:39:34 +0100 (Sat, 19 Apr 2008) | 2 lines
    
    Fix a broken link in the numeric conversion docs.
  ........
    r44592 | danieljames | 2008-04-19 16:40:45 +0100 (Sat, 19 Apr 2008) | 2 lines
    
    Fix some links in the optional docs.
  ........
    r44593 | danieljames | 2008-04-19 16:42:09 +0100 (Sat, 19 Apr 2008) | 2 lines
    
    Fix link to the hash documentation from bimap.
  ........
    r44599 | danieljames | 2008-04-19 18:07:33 +0100 (Sat, 19 Apr 2008) | 2 lines
    
    Fix a typo in the format library.
  ........
    r44600 | danieljames | 2008-04-19 19:20:59 +0100 (Sat, 19 Apr 2008) | 1 line
    
    Initialise svnmerge.
  ........
    r44641 | danieljames | 2008-04-20 18:59:47 +0100 (Sun, 20 Apr 2008) | 2 lines
    
    Fix the lincense url in shared container iterator documentation.
  ........
    r44642 | danieljames | 2008-04-20 19:00:00 +0100 (Sun, 20 Apr 2008) | 2 lines
    
    Fix image link in the mpi documentation.
  ........
    r44643 | danieljames | 2008-04-20 19:00:11 +0100 (Sun, 20 Apr 2008) | 2 lines
    
    Fix a typo in the spirit docs.
  ........
    r44644 | danieljames | 2008-04-20 19:00:23 +0100 (Sun, 20 Apr 2008) | 2 lines
    
    Escape the slash so that quickbook doesn't think it the start of an italic section, and mess up the link. Refs #1844
  ........
    r44647 | danieljames | 2008-04-20 19:39:47 +0100 (Sun, 20 Apr 2008) | 2 lines
    
    Fix another typo in spirit docs.
  ........
................
  r45232 | danieljames | 2008-05-08 22:50:19 +0100 (Thu, 08 May 2008) | 1 line
  
  Fix some invalid xml by replacing ampersands with character entities.
................
  r45576 | danieljames | 2008-05-20 16:39:25 +0100 (Tue, 20 May 2008) | 20 lines
  
  Merge some small documentation fixes from the doc branch, and mark some
  previously merged changes as merged.
  
  Merged revisions 44811,45129,45142,45154,45281-45282,45365 via svnmerge from 
  https://svn.boost.org/svn/boost/branches/doc
  
  ........
    r45129 | danieljames | 2008-05-05 12:36:50 +0100 (Mon, 05 May 2008) | 2 lines
    
    Update navbar links in boostbook.
  ........
    r45282 | danieljames | 2008-05-11 14:15:31 +0100 (Sun, 11 May 2008) | 2 lines
    
    Group functions in the hash header - requires Frank's free-function-group fix.
    (not included in release branch).
  ........
    r45365 | danieljames | 2008-05-14 21:39:00 +0100 (Wed, 14 May 2008) | 2 lines
    
    Add boost.root to standalone hash documentation.
    (not included in release branch).
  ........
................


[SVN r45622]
2008-05-21 20:57:05 +00:00
Beman Dawes
694ae13063 Merge from trunk 43901 at Dave's request
[SVN r43902]
2008-03-28 02:16:12 +00:00
Joel de Guzman
5168895803 Added note about --preserve-test-targets
[SVN r43849]
2008-03-24 23:04:36 +00:00
Joel de Guzman
c8bf94663c Added note about --preserve-test-targets
[SVN r43848]
2008-03-24 23:02:57 +00:00
Daniel James
928a9389ce Rebuild a lot of documentation.
[SVN r43650]
2008-03-16 11:38:32 +00:00
Daniel James
7d22435994 Merged revisions 43211,43214-43219,43222-43225,43227-43238,43242,43244-43245,43249-43250,43257-43259,43261,43263,43265,43267-43268,43270-43271,43273,43275-43279,43284-43289,43291,43295,43297-43298,43304-43305,43307,43313,43315,43324,43326-43327,43331,43333,43339-43343,43345,43348,43350,43352-43353,43355-43356,43358,43360,43366-43367,43369-43370,43372-43376,43378-43389,43394,43396-43398,43400-43401,43403-43404,43406-43408,43413-43415,43417-43418,43420,43422-43423 via svnmerge from
https://svn.boost.org/svn/boost/trunk

........
  r43417 | danieljames | 2008-02-26 22:04:55 +0000 (Tue, 26 Feb 2008) | 2 lines
  
  Fix a link to Boost.Bimap.
........
  r43418 | danieljames | 2008-02-26 22:07:25 +0000 (Tue, 26 Feb 2008) | 2 lines
  
  Change another link that's no longer in the repository to link to the website.
........
  r43422 | danieljames | 2008-02-27 18:51:14 +0000 (Wed, 27 Feb 2008) | 1 line
  
  Fix broken copyright urls. Fixes #1573.
........
  r43423 | danieljames | 2008-02-27 19:22:01 +0000 (Wed, 27 Feb 2008) | 1 line
  
  Fix incorrect links to copyright of the form 'http:#www.boost.org
........


[SVN r43425]
2008-02-27 20:00:24 +00:00
Daniel James
96dd880146 Merged revisions 43206,43208-43213 via svnmerge from
https://svn.boost.org/svn/boost/trunk

........
  r43206 | danieljames | 2008-02-10 09:55:03 +0000 (Sun, 10 Feb 2008) | 1 line
  
  Fix some broken links.
........
  r43209 | danieljames | 2008-02-10 14:56:22 +0000 (Sun, 10 Feb 2008) | 1 line
  
  Link to people pages on the website, as they've been removed from the download.
........
  r43210 | danieljames | 2008-02-10 15:02:17 +0000 (Sun, 10 Feb 2008) | 1 line
  
  Point links to the pages that used to be in 'more' to the site.
........
  r43212 | danieljames | 2008-02-10 16:10:16 +0000 (Sun, 10 Feb 2008) | 1 line
  
  Fix links on the home page as well.
........
  r43213 | danieljames | 2008-02-10 16:21:22 +0000 (Sun, 10 Feb 2008) | 1 line
  
  Generated documentation which is no longer generated.
........


[SVN r43214]
2008-02-10 16:39:38 +00:00
Jürgen Hunold
63f8e9f3d7 Merged revisions 41544-41546,41549-41551,41558-41561,41564,41567,41570,41573,41576-41579,41581,41583-41586,41589,41591,41594-41612,41614-41620,41622-41624,41628,41630-41635,41637,41640-41641,41643,41649-41650 via svnmerge from
https://svn.boost.org/svn/boost/trunk

........
  r41544 | jhunold | 2007-12-01 20:27:06 +0100 (Sa, 01 Dez 2007) | 2 lines
  
  Silence compiler by adding cosmetic virtual destructors.
........
  r41549 | jhunold | 2007-12-01 21:24:51 +0100 (Sa, 01 Dez 2007) | 2 lines
  
  Silence compiler by adding cosmetic virtual destructors.
........
  r41550 | jhunold | 2007-12-01 21:26:37 +0100 (Sa, 01 Dez 2007) | 3 lines
  
  Remove unused paramters.
  Add -Wextra to gcc flags to enable more warnings.
........
  r41577 | jhunold | 2007-12-02 12:51:08 +0100 (So, 02 Dez 2007) | 3 lines
  
  Revert revisions 41544 and 41549.
  See http://lists.boost.org/Archives/boost/2007/12/131116.php for details.
........
  r41649 | jhunold | 2007-12-03 19:47:17 +0100 (Mo, 03 Dez 2007) | 2 lines
  
  Silence unused paramter warning in release mode.
........
  r41650 | jhunold | 2007-12-03 19:51:26 +0100 (Mo, 03 Dez 2007) | 2 lines
  
  Add cosmetic virtual detructors to silence compile warnings.
........


[SVN r42094]
2007-12-16 10:12:07 +00:00
Beman Dawes
d9b4ada654 Full merge from trunk at revision 41356 of entire boost-root tree.
[SVN r41370]
2007-11-25 18:38:02 +00:00
Beman Dawes
f5df393360 Full merge from trunk at revision 41356 of entire boost-root tree.
[SVN r41369]
2007-11-25 18:07:19 +00:00
Rene Rivera
bf33b54638 Recreate release branch from fixed 1.34.1 tag.
[SVN r40341]
2007-10-23 06:42:50 +00:00
Douglas Gregor
87451007b9 Move Attic files back into their rightful places
[SVN r40311]
2007-10-23 01:47:48 +00:00
Beman Dawes
2392a6a3e2 Starting point for releases
[SVN r39706]
2007-10-05 14:25:06 +00:00
nobody
6c1e7decfa This commit was manufactured by cvs2svn to create tag
'Version_1_34_1'.

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


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

  Support for the specification of "_d" extension suffix.

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

common.jam:

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

  Fixed some grammar and spelling.

virtual-target.jam:

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

libs/python/build/Jamfile.v2:

  #define BOOST_DEBUG_PYTHON when <python-debugging>on


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


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

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


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


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

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

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


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


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

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


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

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


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


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


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


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


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


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


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


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


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


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


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


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


[SVN r32836]
2006-02-11 22:29:33 +00:00
Dave Abrahams
6347ca8065 vc7 workaround
[SVN r32835]
2006-02-11 22:26:45 +00:00
Dave Abrahams
c39836ddc8 Tests for bool conversions
[SVN r32814]
2006-02-10 17:26:06 +00:00
Dave Abrahams
fb35a82bf1 Tests for bool members
[SVN r32813]
2006-02-10 17:25:25 +00:00
Vladimir Prus
44c5c18f45 Update Jamfile.v2
[SVN r32761]
2006-02-09 09:50:56 +00:00
Vladimir Prus
e0cceeb88c Update.
[SVN r32722]
2006-02-08 08:37:05 +00:00
Vladimir Prus
4a5f6f2e24 Update Jamfile.v2
[SVN r32702]
2006-02-07 11:49:00 +00:00
Dave Abrahams
8b1748fea0 add tuple conversion
[SVN r32473]
2006-01-31 03:26:46 +00:00
Ralf W. Grosse-Kunstleve
82919f0d5c another attempt to fix Code Warrior 9.4 link problem
[SVN r32404]
2006-01-24 17:55:56 +00:00
Ralf W. Grosse-Kunstleve
1f6ded7b4e Boost.Python docstring_options.hpp news
[SVN r32390]
2006-01-24 00:41:25 +00:00
Ralf W. Grosse-Kunstleve
a0d2873156 attempt to fix Code Warrior 9.4 link problem
[SVN r32380]
2006-01-23 19:01:17 +00:00
Ralf W. Grosse-Kunstleve
0519d54229 avoid g++ -Wall -W "unused parameter" warnings
[SVN r32373]
2006-01-22 19:29:32 +00:00
Ralf W. Grosse-Kunstleve
c181874335 initialize all slots of PyTypeObject to avoid g++ -Wall -W warnings
[SVN r32372]
2006-01-22 19:26:50 +00:00
Ralf W. Grosse-Kunstleve
203a42c35f avoid g++ -Wall -W "unused parameter" warnings
[SVN r32371]
2006-01-22 19:21:22 +00:00
Ralf W. Grosse-Kunstleve
8eba0eb25b initialize all slots of PyTypeObject to avoid g++ -Wall -W warnings
[SVN r32370]
2006-01-22 19:21:08 +00:00
Dave Abrahams
152e76220a GCC warning suppression from Jody Hagins
[SVN r32363]
2006-01-20 15:55:55 +00:00
Ralf W. Grosse-Kunstleve
8897cc9ce6 selected_doc() helper function modified to increase readability
[SVN r32339]
2006-01-16 20:54:53 +00:00
Ralf W. Grosse-Kunstleve
335cd02c2d new documentation for docstring_options.hpp
[SVN r32338]
2006-01-16 20:37:23 +00:00
Ralf W. Grosse-Kunstleve
758d92b33e seq.attr("__len__")() replaced by len(seq); obsolete len() example removed
[SVN r32337]
2006-01-16 20:36:42 +00:00
Ralf W. Grosse-Kunstleve
28eef45d28 enum_print() removed; it was not reachable anyway since enum inherits
from Python's built-in int type. However, the appearance of FILE*
raised questions about using extensions compiled with Visual C++ 8
with a Python compiled with Visual C++ 7.1.


[SVN r32301]
2006-01-12 23:25:23 +00:00
Ralf W. Grosse-Kunstleve
d8790a34d3 boost::python::len() moved to object.hpp
[SVN r32299]
2006-01-12 21:33:19 +00:00
Ralf W. Grosse-Kunstleve
3b058185c6 new docstring_options to support customization of __doc__ attributes of Boost.Python functions
[SVN r32298]
2006-01-12 19:28:53 +00:00
Ralf W. Grosse-Kunstleve
2261e7eedc new docstring_options to support customization of __doc__ attributes of Boost.Python functions
[SVN r32297]
2006-01-12 19:15:38 +00:00
Ralf W. Grosse-Kunstleve
19a196493f Runtime detection of broken cxxabi::__cxa_demangle versions; based on code contributed by Ult Mundane
[SVN r32296]
2006-01-12 19:12:27 +00:00
Ralf W. Grosse-Kunstleve
d10b5e8d1a Python 2.2 compatibility
[SVN r32295]
2006-01-12 17:49:48 +00:00
Ralf W. Grosse-Kunstleve
1cacefc226 automatic addition of C++ signatures to doc strings
[SVN r32290]
2006-01-12 00:32:29 +00:00
Ralf W. Grosse-Kunstleve
efcd2833f1 Visual C++ 6 compatibility
[SVN r32288]
2006-01-11 19:58:55 +00:00
Ralf W. Grosse-Kunstleve
2f9323d9e9 resolve gcc warnings (based on patches by Scott Howlett)
[SVN r32284]
2006-01-11 03:31:48 +00:00
Eric Niebler
8b2f4b4ce0 make test work on vc6
[SVN r31960]
2005-12-08 22:15:31 +00:00
Douglas Gregor
ab046dc634 Merged from Version_1_33_1
[SVN r31953]
2005-12-08 04:11:36 +00:00
Dave Abrahams
ef3f9b15f0 vc-8 workaround
[SVN r31943]
2005-12-07 05:00:02 +00:00
Dave Abrahams
68463e2fd2 Fixed missing semicolon
[SVN r31852]
2005-12-01 13:06:57 +00:00
Dave Abrahams
f75eca94e0 Fix typo
[SVN r31831]
2005-11-30 11:57:33 +00:00
Dave Abrahams
a23030b83e use symbol visibility for GCC 4.x
[SVN r31828]
2005-11-29 22:26:48 +00:00
Dave Abrahams
321cf2502a use symbol visibility for GCC 4.x
[SVN r31827]
2005-11-29 22:26:05 +00:00
Dave Abrahams
4996f912b4 Workaround for GCC bug described in http://lists.debian.org/debian-gcc/2003/09/msg00055.html
Thanks to Graham Bennett.


[SVN r31809]
2005-11-28 21:16:12 +00:00
Joel de Guzman
09e24cb17d map bug fix when data type is a shared_ptr and NoProxy is true
[SVN r31787]
2005-11-26 16:23:21 +00:00
Joel de Guzman
ac32d13e10 added more tests
[SVN r31786]
2005-11-26 15:13:20 +00:00
Joel de Guzman
b0496d1207 update: map indexing suite
[SVN r31723]
2005-11-21 15:25:47 +00:00
Joel de Guzman
a076239fc8 std::string and std::complex as no-proxy types.
[SVN r31717]
2005-11-21 04:54:23 +00:00
Dave Abrahams
7cf0f9090f Restore map_indexing_suite test that was mistakenly commented out.
[SVN r31621]
2005-11-10 21:58:20 +00:00
Dave Abrahams
479f068673 Attempt Bronek's change to suppress VC++8.0 complaints about redefined
_DEBUG.


[SVN r31557]
2005-11-04 21:38:29 +00:00
Eric Niebler
9b326f15fa qualify friend declaration to make EDG happy
[SVN r31538]
2005-11-02 22:43:05 +00:00
Ralf W. Grosse-Kunstleve
f094a5b9eb boost/python header must be included first due to a Python requirement
[SVN r31535]
2005-11-01 22:12:53 +00:00
Stefan Seefeld
4367850e5d Add examples.
[SVN r31530]
2005-11-01 15:18:02 +00:00
Dave Abrahams
f44a4d6468 Clarified HeldType
[SVN r31528]
2005-11-01 15:08:30 +00:00
Eric Niebler
5206dd55d2 s/Python sequences/Python iterables/ and other assorted feedback from Dave
[SVN r31517]
2005-10-31 19:46:41 +00:00
Dave Abrahams
988bf849a1 Account for Intel 9.0 picking up vc7.1 bug compatibility.
[SVN r31515]
2005-10-31 19:24:48 +00:00
Eric Niebler
6fee43fc6f tests and docs for stl_input_iterator
[SVN r31514]
2005-10-31 18:50:18 +00:00
Eric Niebler
6ec4387ea1 add stl_input_iterator for wrapping a Python iterator in a STL input iterator
[SVN r31513]
2005-10-31 18:49:54 +00:00
Dave Abrahams
e2f59ef548 More restrictions on the need for libpython.a
[SVN r31494]
2005-10-27 12:21:55 +00:00
Dave Abrahams
92a6fafd20 Note that the libpython.a creation instructions are not needed for Python 2.4.1+
[SVN r31466]
2005-10-25 19:08:24 +00:00
Dave Abrahams
4721f5f9af Fix CYGWIN_PYTHON_DEBUG_ROOT to be consistent with docs
Set *nix PYTHON_ROOT to /usr, to be consistent with real installations.
Use *nix rather than Unix everywhere for generality


[SVN r31463]
2005-10-25 15:47:27 +00:00
Dave Abrahams
3864838da2 Fixed for vc6
[SVN r31398]
2005-10-19 22:02:51 +00:00
Dave Abrahams
8e77df69d5 Update
[SVN r31396]
2005-10-19 18:28:02 +00:00
Dave Abrahams
12770b03e8 Add the ability to easily use new-style polymorphism wrappers with
smart pointer held_type.


[SVN r31392]
2005-10-19 18:17:13 +00:00
Dave Abrahams
c8a692b4b4 Bug fix
[SVN r31385]
2005-10-19 13:17:27 +00:00
Dave Abrahams
2571ebb0c2 Added Stefan's new files.
[SVN r31371]
2005-10-18 12:09:36 +00:00
Dave Abrahams
283dbfb593 Updated news
[SVN r31329]
2005-10-14 19:30:01 +00:00
Dave Abrahams
83f227034f Updated news
[SVN r31328]
2005-10-14 19:25:41 +00:00
Dave Abrahams
c5f514a4e6 Build with Python 2.4 by default; also deduce the default PYTHON_ROOT properly on Windows.
[SVN r31325]
2005-10-14 16:19:14 +00:00
Dave Abrahams
9fb15f631e Make it work when Python is compiled with Unicode disabled.
[SVN r31322]
2005-10-14 15:54:12 +00:00
Dave Abrahams
3d8f4c90ba Make it work when Python is compiled with Unicode disabled.
[SVN r31321]
2005-10-14 15:35:06 +00:00
Dave Abrahams
5597dcb321 Disable ADL from addressof uses :(
[SVN r31319]
2005-10-14 15:05:17 +00:00
Joel de Guzman
ab2912e3c2 minor fix
[SVN r31308]
2005-10-13 12:02:25 +00:00
Joel de Guzman
b705931ff0 tweak: wrong c++ code written in python
[SVN r31307]
2005-10-13 11:58:53 +00:00
Eric Niebler
2974286209 fix bugs in example code
[SVN r31305]
2005-10-12 20:17:28 +00:00
Dave Abrahams
1cec514b39 Martin Wille pointed out some missing header dependencies; fixed.
Also moved boost/python/detail/is_xxx.hpp functionality into
boost/detail/is_xxx.hpp to decouple library dependencies between
python and parameter.


[SVN r31290]
2005-10-11 21:20:06 +00:00
Dave Abrahams
8ecd49cbf0 Use "addressof(x)" instead of "&x" to deal with classes that have a
private operator& !!


[SVN r31279]
2005-10-11 13:19:05 +00:00
Ralf W. Grosse-Kunstleve
67a7669ff4 work around Visual C++ 6 problem
[SVN r31075]
2005-09-22 06:20:25 +00:00
Stefan Seefeld
e80545a7d3 Use BOOST_ASSERT instead of std::runtime_error to indicate errors.
[SVN r30954]
2005-09-13 14:42:03 +00:00
Stefan Seefeld
6afe0d4732 Enhance and clean up tests.
[SVN r30907]
2005-09-11 14:50:37 +00:00
Ralf W. Grosse-Kunstleve
f8280b0e1a David Abrahams, Jul 2005: according to 8.5/9 the __GNUC__ workaround at line 69 of data_members.cpp should be made universal.
[SVN r30893]
2005-09-10 05:53:28 +00:00
John Maddock
aa20ce7d2c Large patch from Ulrich Eckhardt to fix support for EVC++ 4.
[SVN r30670]
2005-08-25 16:27:28 +00:00
Stefan Seefeld
6074a23242 Fix exec test.
[SVN r30669]
2005-08-25 15:03:19 +00:00
Dave Abrahams
9ceac3ff8f Fix bug in example thanks to Roman Yakovenko.
[SVN r30616]
2005-08-21 15:19:51 +00:00
Stefan Seefeld
126a3efb92 Add basic embedding support.
[SVN r30601]
2005-08-17 13:04:42 +00:00
Victor A. Wagner Jr.
9205f507b0 Added - #define _CRT_NOFORCE_MANIFEST if we also have to #undef _DEBUG
this isn't really an elegant solution, perhaps people trying to
          debug python (BOOST_DEBUG_PYTHON defined) will really have to
          use the debug version of the CRT with the latest .NET

          There is also a collision if the user happens to have
          #define _CRT_FORCE_MANIFEST which I didn't address


[SVN r30570]
2005-08-13 16:19:19 +00:00
Ralf W. Grosse-Kunstleve
bff975f08c bug fix: friend class def_visitor_access; -> friend class python::def_visitor_access; This fix enables us to remove an EDG specific workaround.
[SVN r30471]
2005-08-04 20:15:35 +00:00
Dave Abrahams
262bcee750 Fix broken links
[SVN r30401]
2005-08-03 12:25:30 +00:00
Dave Abrahams
a3f12b18b1 Fix broken links
[SVN r30398]
2005-08-03 11:39:39 +00:00
Ralf W. Grosse-Kunstleve
ad635ec2d1 include order according to Python's rules
[SVN r30242]
2005-07-26 01:19:18 +00:00
Dave Abrahams
affd36e857 Fix up problem report issues (tabs, broken links, unlinked)
[SVN r30241]
2005-07-25 21:20:10 +00:00
Dave Abrahams
332a45f333 untabify
[SVN r30239]
2005-07-25 20:57:30 +00:00
Joel de Guzman
6cc48f7e5d adjusting link to libraries.html
[SVN r29999]
2005-07-12 07:53:00 +00:00
Joel de Guzman
5b6192d738 Tutorial bug fix (__init__ gets interpreted as underlined _init_ by quickbook)
[SVN r29970]
2005-07-10 20:06:21 +00:00
Joel de Guzman
980733a96d fixed bug where a vector<T*> is being wrapped by the indexing suite.
[SVN r29930]
2005-07-07 14:00:31 +00:00
Dave Abrahams
331209d8b5 Fix link in news
Improve assertions in indirect_traits_test by making them compile-time
and using MPL assert primitives


[SVN r29782]
2005-06-24 15:42:22 +00:00
Dave Abrahams
9116cf382b Fix reference search URL
[SVN r29635]
2005-06-17 02:55:31 +00:00
Dave Abrahams
8cc2b7a5df Add search box
[SVN r29626]
2005-06-16 17:49:38 +00:00
Joel de Guzman
dab01ad668 Typo fix (objecto)
[SVN r29625]
2005-06-16 17:26:00 +00:00
Ralf W. Grosse-Kunstleve
1fca114f6a work around RedHat 7.3 gcc 2.96 code generation errors: use previously checked in VC6, VC7.0 workaround only for exactly these compilers
[SVN r29267]
2005-05-29 17:05:25 +00:00
Dave Abrahams
70ee460a14 Py_Initialize outside the first test routine
[SVN r29167]
2005-05-24 12:20:03 +00:00
Douglas Gregor
07c95aea4e gcc-3_3-darwin also needs -bind_at_load
[SVN r29102]
2005-05-20 20:12:29 +00:00
Dave Abrahams
a3d8a384fa Workaround for compilers that have trouble with lexical_cast.
[SVN r29033]
2005-05-18 14:11:20 +00:00
Dave Abrahams
432d4782a5 Take typeid(T&) rather than typeid(T). For some some compilers won't
let you get away with typeid(T) when T is an incomplete class
type (that's conforming behavior), but GCC at least will allow
typeid(T&) -- also disallowed by the standard when T is incomplete.
If it turns out that EDGs also barf on typeid(T&), we may have more
work to do.

Some warning suppression for MSVC.


[SVN r29020]
2005-05-18 01:34:35 +00:00
Dave Abrahams
424f5bdf31 Workarounds for vc6 and 7.
[SVN r28973]
2005-05-16 17:34:46 +00:00
Dave Abrahams
13b16f9729 Workarounds for vc6 and 7.
[SVN r28958]
2005-05-16 14:54:12 +00:00
Dave Abrahams
82563df3bf Better support for rvalue from-python conversions of shared_ptr:
always return a pointer that holds the owning python object *unless*
the python object contains a NULL shared_ptr holder of the right type.


[SVN r28947]
2005-05-16 03:31:13 +00:00
Dave Abrahams
adb7b62a62 gcc workarounds
[SVN r28946]
2005-05-16 02:49:14 +00:00
Dave Abrahams
02c0b2b486 Improve MPL idiomatic usage
[SVN r28945]
2005-05-16 02:01:35 +00:00
Dave Abrahams
c876db8cae VC8 beta workaround
[SVN r28944]
2005-05-16 01:57:30 +00:00
Joel de Guzman
3ce88daa8b Tutorial Updates for Building BPL Projects
[SVN r28889]
2005-05-14 02:50:34 +00:00
Dave Abrahams
4cec6c4f2f Added copyright
[SVN r28780]
2005-05-10 11:53:17 +00:00
Brett Calcott
e38bf06257 updated visual studio project build file to include two new files (slice.cpp and wrapper.cpp)
updated email address for maintainer of visual studio files.


[SVN r28732]
2005-05-08 09:55:43 +00:00
Joel de Guzman
0deed1ff9b removing unnecessary file
[SVN r28584]
2005-05-02 15:57:42 +00:00
Joel de Guzman
a05a0ae46b Python now correctly syntax colorized + some minor tweaks
[SVN r28581]
2005-05-02 15:51:26 +00:00
Dave Abrahams
fe3906a7cb Fix broken vc6 compatibility
[SVN r28515]
2005-04-28 14:15:19 +00:00
Bruno da Silva de Oliveira
e5ed3a1c6c Fixed bug where the code for wrappers of member functions were defined outside
the pyste namespace. Reported by Dan Haffey.


[SVN r28479]
2005-04-25 23:49:21 +00:00
Bruno da Silva de Oliveira
2bbff71109 *** empty log message ***
[SVN r28478]
2005-04-25 23:49:04 +00:00
Victor A. Wagner Jr.
c492551111 Deleted - an extraneous \r at the end of lines which causes vc8.0 to mistake the
files for some created on the Mac (apparently a HENIOUS crime which is intolerable
          to those at Microsoft and which must be considered an error)
Changed - the version of python mentioned specifically from 2.3 to 2.4


[SVN r28471]
2005-04-25 10:01:07 +00:00
Vladimir Prus
b217c4ffa8 Replace 'run-pyd' with 'bpl-test' in a couple of places. The former does
not produce the .test files that regression tools want.


[SVN r28213]
2005-04-13 11:42:50 +00:00
Ralf W. Grosse-Kunstleve
96e9d6a872 std_pair jam rules and test
[SVN r27876]
2005-03-30 00:36:02 +00:00
Ralf W. Grosse-Kunstleve
fef288fed2 new std::pair to_python_converter example
[SVN r27875]
2005-03-29 23:02:45 +00:00
Stefan Slapeta
2fdb98079d Intel workaround extended to 9.0
[SVN r27861]
2005-03-29 07:41:34 +00:00
Dave Abrahams
bbabf21abf pydoc note
[SVN r27615]
2005-03-12 03:05:04 +00:00
Dave Abrahams
6d24977dd2 Comments for hacks to make PyDoc work. Eliminate reinterpret_cast.
[SVN r27614]
2005-03-12 02:58:42 +00:00
Dave Abrahams
c2b5925600 Hacks to make PyDoc work, from Nick Rasmussen <nick-at-ilm.com>
[SVN r27613]
2005-03-12 02:49:10 +00:00
Dave Abrahams
91e76a296f Added Civilization IV
[SVN r27599]
2005-03-10 14:53:39 +00:00
Dave Abrahams
e4eee902d4 Add missing #include
[SVN r27598]
2005-03-10 14:40:12 +00:00
Ralf W. Grosse-Kunstleve
db71f17dba typo fixed
[SVN r27577]
2005-03-08 15:17:44 +00:00
Ralf W. Grosse-Kunstleve
b754037949 account for changes in newer versions of Python's doctest module
[SVN r27576]
2005-03-08 14:31:12 +00:00
Stefan Slapeta
7bd76d869b Intel 9 workaround
[SVN r27517]
2005-02-28 12:14:13 +00:00
Rene Rivera
c25967a094 Apply typo fixes from Julio M. Merino Vidal
[SVN r27513]
2005-02-27 17:28:24 +00:00
Ralf W. Grosse-Kunstleve
bcb6370b0e fix for obviously broken class Rational example
[SVN r27457]
2005-02-20 23:05:14 +00:00
Jonathan Brandmeyer
17faf4504c Export the client-provided docstrings for init<optional<> > and
_FUNCTION_OVERLOADS() for only the last overload.


[SVN r27415]
2005-02-18 02:42:42 +00:00
Vladimir Prus
53c335f106 Remove unused references to Boost.Test.
[SVN r27390]
2005-02-15 14:43:25 +00:00
Vladimir Prus
cd8951439e More work on Boost.Python. Most tests now pass on Linux.
[SVN r27387]
2005-02-15 12:10:09 +00:00
Ralf W. Grosse-Kunstleve
0e5e2dc92e includes moved to satisfy the "Python.h first" requirement
[SVN r27386]
2005-02-15 10:41:03 +00:00
Jonathan Brandmeyer
4d50bf0ad9 Concatentation subsequent function docstrings rather than replace the original.
[SVN r27332]
2005-02-11 20:03:13 +00:00
Ralf W. Grosse-Kunstleve
1cfa79554d work around gcc problems (gcc 3.2.2 and higher); thanks to John Maddock for the patch!
[SVN r27142]
2005-02-05 07:36:14 +00:00
Jonathan Brandmeyer
567e620565 Match signatures with their mpl::true variants
[SVN r26829]
2005-01-24 02:37:37 +00:00
Jonathan Brandmeyer
5933fdbf39 Add docstring support for non-static properties.
[SVN r26814]
2005-01-22 21:41:37 +00:00
Dave Abrahams
4c21a29a9f Fix typos
[SVN r26644]
2005-01-08 02:13:13 +00:00
Dave Abrahams
7c21f3b48d Add fusion
[SVN r26628]
2005-01-04 23:50:07 +00:00
Dave Abrahams
6f4167700c tests for raw constructors
[SVN r26493]
2004-12-14 03:33:30 +00:00
Dave Abrahams
efae35bbd8 Add tests for raw constructors
[SVN r26407]
2004-12-03 08:00:11 +00:00
Ralf W. Grosse-Kunstleve
8dbd926d9e __DECCXX_VER test: use BOOST_WORKAROUND, BOOST_TESTED_AT instead of raw '#if defined'
[SVN r26363]
2004-11-29 21:32:14 +00:00
Aleksey Gurtovoy
c6e658cfca merge RC_1_32_0 fixes
[SVN r26333]
2004-11-28 04:44:21 +00:00
Aleksey Gurtovoy
b77dcf4bea merge RC_1_32_0 fixes
[SVN r26330]
2004-11-28 03:54:58 +00:00
Joel de Guzman
1e3cfbca03 fixes for the warnings.
[SVN r26290]
2004-11-25 09:17:04 +00:00
Dave Abrahams
1ed231747b update
[SVN r26254]
2004-11-19 14:17:02 +00:00
Joel de Guzman
a926eaa86d Merged from RC 1.32
[SVN r26224]
2004-11-16 07:29:41 +00:00
Ralf W. Grosse-Kunstleve
acd8ec2c31 adjustment for latest Tru64/cxx release (V6.5-042)
[SVN r26222]
2004-11-15 23:50:57 +00:00
Dave Abrahams
441a9dbea0 Stop reserving rights
[SVN r26089]
2004-11-02 20:07:50 +00:00
Dave Abrahams
63e92c49df Stop reserving rights.
[SVN r26088]
2004-11-02 19:46:47 +00:00
Dave Abrahams
49dd8bcf51 Stop reserving rights.
[SVN r26067]
2004-11-01 21:23:47 +00:00
Dave Abrahams
942f4c4ffd Fix bug in example.
[SVN r26049]
2004-11-01 14:17:00 +00:00
Dave Abrahams
43791f3a71 Remove qualification from member function name in overloads invocation.
[SVN r26047]
2004-11-01 14:15:08 +00:00
Dave Abrahams
321bea59fb tidy
[SVN r26026]
2004-11-01 00:21:27 +00:00
Dave Abrahams
601fd16cba add wrapper<T>
[SVN r26025]
2004-11-01 00:14:18 +00:00
Aleksey Gurtovoy
a9cddc10a9 refactor const_argument test to pass if there is a known workaround
[SVN r25924]
2004-10-29 03:19:27 +00:00
Bruno da Silva de Oliveira
03fc159aec no message
[SVN r25886]
2004-10-27 10:47:03 +00:00
Joel de Guzman
59b596e1ee license
[SVN r25867]
2004-10-26 00:13:19 +00:00
John Maddock
1fe6626edb BSL update based on permissions granted in blanket-permission.txt
[SVN r25863]
2004-10-25 11:58:45 +00:00
Aleksey Gurtovoy
fa8cffb3a2 taking care of const_argument test failures (see http://thread.gmane.org/gmane.comp.python.c++/7221)
[SVN r25848]
2004-10-24 07:28:34 +00:00
Joel de Guzman
11daf8dde8 fixed some links
[SVN r25772]
2004-10-18 11:58:55 +00:00
Joel de Guzman
0d6ac67c04 update to quickibook 1.0
[SVN r25771]
2004-10-18 11:29:52 +00:00
Joel de Guzman
978dc88499 Making space for update to quickbook 1.0
[SVN r25769]
2004-10-18 10:39:05 +00:00
Dave Abrahams
655868d803 Eliminate return from void function.
[SVN r25742]
2004-10-15 16:53:40 +00:00
Bruno da Silva de Oliveira
92ff4ab76f Applied patch by Christian Hudon
[SVN r25636]
2004-10-09 19:49:09 +00:00
Joel de Guzman
48a6db6598 redirect
[SVN r25582]
2004-10-06 23:56:05 +00:00
Dave Abrahams
a97d050016 Fixes from Christoph Ludwig <cludwig-at-cdc.informatik.tu-darmstadt.de>
[SVN r25577]
2004-10-05 20:41:12 +00:00
Dave Abrahams
e888d8aa88 Another fix.
[SVN r25576]
2004-10-05 20:40:28 +00:00
Aleksey Gurtovoy
59ca82128a c++boost.gif -> boost.png replacement
[SVN r25573]
2004-10-05 15:45:52 +00:00
Dave Abrahams
0620462efb Fixes from Christoph Ludwig <cludwig-at-cdc.informatik.tu-darmstadt.de>
[SVN r25571]
2004-10-05 14:35:31 +00:00
Stefan Slapeta
f99f1e187c Intel 8.1 workaround
[SVN r25529]
2004-10-02 19:14:52 +00:00
Dave Abrahams
937a851baa warning suppression for GCC
[SVN r25446]
2004-09-28 11:57:06 +00:00
Jonathan Brandmeyer
8e396f8e91 Add new test.
[SVN r25438]
2004-09-27 20:05:52 +00:00
Dave Abrahams
bd74676685 Work around the stupid VC++/Intel bug that retains argument constness in function signatures.
[SVN r25437]
2004-09-27 14:49:27 +00:00
Jonathan Brandmeyer
70e012bc45 Be more correct about testing for Intel 7.1 on MS Windows.
[SVN r25386]
2004-09-24 02:47:14 +00:00
Aleksey Gurtovoy
3bb3434a8d fix MSVC 6.x ICE in 'vector_indexing_suite.cpp'
[SVN r25343]
2004-09-22 16:54:04 +00:00
Dave Abrahams
2121039a2b Use proper configuration macros.
[SVN r25312]
2004-09-21 14:39:50 +00:00
Dave Abrahams
5bab5a2398 Fix GCC export limiting patch from Niall Douglas s_sourceforge-at-nedprod.com
[SVN r25279]
2004-09-20 13:59:59 +00:00
Dave Abrahams
2ca8be0bb2 vc6 workaround
[SVN r25278]
2004-09-20 13:45:52 +00:00
Dave Abrahams
227448f061 Fix #include
[SVN r25274]
2004-09-20 13:39:37 +00:00
Dave Abrahams
0b026dc5a2 Apply GCC export limiting patch from Niall Douglas s_sourceforge-at-nedprod.com
[SVN r25271]
2004-09-20 12:47:31 +00:00
Dave Abrahams
3ba268ed9c moved indirect_traits to boost/detail
[SVN r25237]
2004-09-20 02:50:29 +00:00
Joel de Guzman
c4b09c7526 move to quickbook (WIP)
[SVN r25137]
2004-09-16 05:51:33 +00:00
Joel de Guzman
164e517a54 move to quickbook (WIP)
[SVN r25136]
2004-09-16 05:47:55 +00:00
Dave Abrahams
fd75e791a7 moved indirect_traits to boost/detail
[SVN r25128]
2004-09-16 01:00:30 +00:00
Dave Abrahams
7eb9f910ba moved indirect_traits to boost/detail
[SVN r25127]
2004-09-16 00:47:59 +00:00
Dave Abrahams
78cd3298aa Move indirect_traits to boost/detail
[SVN r25124]
2004-09-15 19:35:10 +00:00
Dave Abrahams
2f5dfbb728 Move indirect_traits to boost/detail
[SVN r25117]
2004-09-15 15:00:12 +00:00
Dave Abrahams
3750668aad Add IPLT, alphabetized.
[SVN r25025]
2004-09-13 01:25:37 +00:00
Dave Abrahams
dc2acc5bf5 add proper default handling
[SVN r25017]
2004-09-11 14:53:05 +00:00
Douglas Gregor
f7db275bc4 License update
[SVN r24990]
2004-09-09 13:59:01 +00:00
Dave Abrahams
7171a34364 Daniel Holth's PyBool mods (dholth-at-fastmail.fm)
[SVN r24980]
2004-09-08 19:18:57 +00:00
Dave Abrahams
f1260e6869 cw ICE workaround
[SVN r24979]
2004-09-08 18:57:14 +00:00
Jonathan Brandmeyer
0b4f2bafe6 Take a shot at enabling the workaround for ICC 7.1 on Windows.
[SVN r24965]
2004-09-08 02:40:52 +00:00
Ralf W. Grosse-Kunstleve
c5cf576deb _DEBUG/BOOST_DEBUG_PYTHON/DEBUG_UNDEFINED_FROM_WRAP_PYTHON_H must appear before #include <pyconfig.h>
[SVN r24942]
2004-09-06 18:42:41 +00:00
Aleksey Gurtovoy
bfd7f71601 merge new MPL version from 'mplbook' branch
[SVN r24874]
2004-09-02 15:41:37 +00:00
Dave Abrahams
87718f91ab Bug fix from Francois Ostiguy <ostiguy-at-fnal.gov>, more similar ones from Dave.
[SVN r24855]
2004-09-01 20:27:47 +00:00
Ralf W. Grosse-Kunstleve
3918395715 always include <pyconfig.h> first
[SVN r24852]
2004-09-01 15:43:52 +00:00
Dave Abrahams
dec9c6d96e removed as defunct
[SVN r24841]
2004-08-31 22:11:37 +00:00
Jonathan Brandmeyer
0c651a890c Use the non-const prototype for all currently known versions of MSVC.
[SVN r24771]
2004-08-26 21:28:28 +00:00
Dave Abrahams
e00462992c Added default args
[SVN r24757]
2004-08-26 14:07:17 +00:00
Ralf W. Grosse-Kunstleve
951c65e5a1 Compaq C++ V6.5-041 still needs the offsetof workaround
[SVN r24732]
2004-08-25 21:50:52 +00:00
John Maddock
0f19b148f6 Converted files to the BSL.
[SVN r24614]
2004-08-20 11:10:24 +00:00
Joel de Guzman
c750be6fc6 fixed link to doc/quickstart.html
[SVN r24573]
2004-08-18 23:53:26 +00:00
Stefan Slapeta
d1003f08de Intel-win32 workaround
[SVN r24560]
2004-08-18 14:29:00 +00:00
Bruno da Silva de Oliveira
386c45fd4d - added copyright notice
[SVN r24521]
2004-08-17 01:51:29 +00:00
Dave Abrahams
725d203c32 Added missing license/copyright
[SVN r24484]
2004-08-15 12:34:39 +00:00
Dave Abrahams
07a14ce350 Clarify/don't abuse extract<>
[SVN r24436]
2004-08-12 14:27:40 +00:00
Joel de Guzman
77c2c8d77c Copyright and License
[SVN r24395]
2004-08-11 02:21:27 +00:00
Ralf W. Grosse-Kunstleve
9ea7f100cc Add license, copyright.
[SVN r24392]
2004-08-10 17:17:52 +00:00
Ralf W. Grosse-Kunstleve
51487a75e9 exercise keyword argument support
[SVN r24389]
2004-08-10 17:05:24 +00:00
Ralf W. Grosse-Kunstleve
500b8e190d support gcc 2.96 workaround (typedef arg arg_;)
[SVN r24388]
2004-08-10 17:04:14 +00:00
Ralf W. Grosse-Kunstleve
9102c12c6d bug fix: make use of kw in make_constructor_aux
[SVN r24387]
2004-08-10 17:03:23 +00:00
Dave Abrahams
cb45ee8879 Add license, copyright.
[SVN r24386]
2004-08-10 16:14:51 +00:00
Dave Abrahams
ecae47236e Add license, copyright.
[SVN r24380]
2004-08-10 14:59:58 +00:00
Jonathan Brandmeyer
d0ca0886bb Add missing copyright notice using the Boost Software License.
[SVN r24377]
2004-08-10 14:41:06 +00:00
Dave Abrahams
18411f4b5f Optimization bug fix from Stefan Seefeld (sseefeld-at-art.ca)
[SVN r24357]
2004-08-09 17:43:02 +00:00
Dave Abrahams
2c383e7216 Workaround bogus GCC warning.
[SVN r24306]
2004-08-05 16:57:10 +00:00
Dave Abrahams
cac6d3e5ac Made Python testing more verbose by default
Avoid using the Boost.Test library wherever possible.


[SVN r24249]
2004-08-02 19:31:59 +00:00
Dave Abrahams
bd985d67d8 Made Python testing more verbose by default
Avoid using the Boost.Test library wherever possible.


[SVN r24248]
2004-08-02 18:47:50 +00:00
Joel de Guzman
6f0a70fa66 minor updates
[SVN r24135]
2004-07-28 02:36:18 +00:00
Ralf W. Grosse-Kunstleve
cbe6de2a2d fixes to avoid EDG 245 warnings (by Jonathan Brandmeyer)
[SVN r24130]
2004-07-28 01:45:50 +00:00
Ralf W. Grosse-Kunstleve
4885d65ec9 redundant else commented out to avoid EDG 245 warnings
[SVN r24106]
2004-07-27 07:11:10 +00:00
Ralf W. Grosse-Kunstleve
047896ac16 fix for char* -> const char* conversion (g++ diagnostic)
[SVN r24105]
2004-07-27 07:10:16 +00:00
Ralf W. Grosse-Kunstleve
fbe3a563c3 avoid "incomplete type" error (EDG 245 diagnostic)
[SVN r24104]
2004-07-27 07:08:53 +00:00
Ralf W. Grosse-Kunstleve
0c453fda0b MIPSpro 7.3.1.x workaround
[SVN r24103]
2004-07-27 07:08:08 +00:00
Ralf W. Grosse-Kunstleve
a1f74e9c63 guard non-const prototype with BOOST_WORKAROUND(BOOST_MSVC, <= 1300)
[SVN r24102]
2004-07-27 07:06:40 +00:00
Jonathan Brandmeyer
763fa1cf0c Silence warning from EDG 245 (Tru64 cxx 6.5)
[SVN r24092]
2004-07-26 23:29:49 +00:00
Dave Abrahams
c8e8ccfa22 New-style polymorphism
[SVN r24083]
2004-07-26 15:34:36 +00:00
Dave Abrahams
597342bf15 Suppress warnings for intel 8
[SVN r24082]
2004-07-26 15:13:05 +00:00
Dave Abrahams
8338b2fb49 Stop using "not"
[SVN r24081]
2004-07-26 14:27:17 +00:00
Douglas Gregor
fed0b09c4e Converted to Boost Software License, Version 1.0
[SVN r24055]
2004-07-26 00:32:12 +00:00
Rene Rivera
3e76482713 Remove tabs in file.
[SVN r24043]
2004-07-25 17:12:17 +00:00
Ralf W. Grosse-Kunstleve
d6325d902e workaround for MIPSpro 7.3.1.3 name lookup problem
[SVN r23825]
2004-07-20 05:12:33 +00:00
Dave Abrahams
615adc5fe6 Make slice work on vc6
Revamp/simplify class registration


[SVN r23823]
2004-07-20 03:16:49 +00:00
Dave Abrahams
2bdb728e87 A few corrections
[SVN r23735]
2004-07-18 21:54:58 +00:00
Jonathan Brandmeyer
5e82d653a1 Correct the documentation to specify that has_back_reference<> must be a
metafunction rather than a traits class.
Correct typos in the example.


[SVN r23730]
2004-07-18 17:53:28 +00:00
Bruno da Silva de Oliveira
27653b7fbf - Applied a patch by Paul Bridger that solves some problems for wrapper
methods.
- Applied a patch by Baptiste Lepilleur that allows the user to inject
code inside the class definition.
- Applied another patch by Baptiste Lepilleur that inserts two new command-line
options that helps with writing makefiles.


[SVN r23725]
2004-07-18 15:50:10 +00:00
Rene Rivera
af1530953e Move dllexport declaration from methods to slice class as mingw can't handle it. Resolves bug #952335.
[SVN r23464]
2004-07-12 13:07:17 +00:00
Ralf W. Grosse-Kunstleve
87290af774 workaround for broken gcc that ships with SuSE 9.0 and SuSE 9.1
[SVN r23411]
2004-07-09 04:53:39 +00:00
Jonathan Brandmeyer
8469d7727d Add a small set of test cases for slice::get_indicies().
Promote slice::start(), slice::stop(), slice::step, and
slice::get_indicies() to const.
Fix typos in the documentation.


[SVN r23408]
2004-07-08 17:29:51 +00:00
Ralf W. Grosse-Kunstleve
44e9ffc5ca correction as per Niall
[SVN r23386]
2004-07-06 22:44:33 +00:00
Vladimir Prus
2e86d1f9bb Remove debug print
[SVN r23368]
2004-07-06 11:27:54 +00:00
Ralf W. Grosse-Kunstleve
112c999818 obtain correct class name via cl.attr("__name__")
[SVN r23359]
2004-07-06 04:36:50 +00:00
Ralf W. Grosse-Kunstleve
858e5e9720 boost/python/detail/prefix.hpp must be included first to satisfy Python requirements; this fixes compilation errors under Tru64 Unix and IRIX using Python 2.3.4
[SVN r23334]
2004-07-04 07:08:54 +00:00
Jonathan Brandmeyer
f2f7b10d15 Revert last change since it was the documentation that was in error.
[SVN r23326]
2004-07-03 17:19:51 +00:00
Jonathan Brandmeyer
4e3c2f237c Correct the documentation with regard to the default backend for the
numeric::array class.


[SVN r23325]
2004-07-03 17:17:56 +00:00
Jonathan Brandmeyer
c246e918f4 Use Numeric.ArrayType in preference to numarray.NDArray, in accordance
with the documentation.


[SVN r23320]
2004-07-03 03:54:35 +00:00
Eric Niebler
b76f185cb6 move BOOST_USING_STD_MIN and _MAX and BOOST_PREVENT_MACRO_SUBSTITUTION to the config headers, remove boost/minmax.hpp, update coding guidelines
[SVN r23313]
2004-07-02 01:21:32 +00:00
Eric Niebler
9d7097177d remove std_min and std_max, update minmax coding guidelines
[SVN r23162]
2004-06-23 04:49:48 +00:00
Ralf W. Grosse-Kunstleve
c6587596b1 unused variable names removed to avoid warning messages (Giulio Eulisse)
[SVN r23080]
2004-06-11 00:11:11 +00:00
Ralf W. Grosse-Kunstleve
b661aad9ac work around MIPSpro 7.41 problems
[SVN r23079]
2004-06-11 00:07:55 +00:00
Joel de Guzman
ca0a0a4a3d [bug fix] added boost::noncopyable to class_ Base
[SVN r23049]
2004-06-08 01:47:30 +00:00
Bruno da Silva de Oliveira
a9cd67873c - fixes module name if run from another directory where the .pyste file is located
[SVN r22977]
2004-05-30 23:14:10 +00:00
Bruno da Silva de Oliveira
b58812e7f1 Applied a patch by Roman Yakovenko that makes the export of unnamed enums
better.


[SVN r22852]
2004-05-17 22:46:43 +00:00
Joel de Guzman
9e2b4380d5 ADL bug-fix
[SVN r22730]
2004-05-04 10:19:33 +00:00
Joel de Guzman
8ae8430e7c ADL bug-fix
[SVN r22729]
2004-05-04 09:41:01 +00:00
Dave Abrahams
2ee25fda61 Added missing const to prevent spurious static asserts
[SVN r22719]
2004-05-01 17:37:15 +00:00
Ralf W. Grosse-Kunstleve
e766286d92 use BOOST_WORKAROUND
[SVN r22640]
2004-04-15 16:24:03 +00:00
Ralf W. Grosse-Kunstleve
4df59a752a make the test work under 64-bit operating systems
[SVN r22639]
2004-04-15 16:15:41 +00:00
Ralf W. Grosse-Kunstleve
e0bf57ae36 workaround for MIPSpro
[SVN r22638]
2004-04-15 15:16:15 +00:00
Ralf W. Grosse-Kunstleve
5df66bb179 adjusted #ifdef's for Compaq C++ V6.5-040 for Compaq Tru64 UNIX
[SVN r22637]
2004-04-15 14:59:31 +00:00
Ralf W. Grosse-Kunstleve
b5256ef70b adjusted #ifdef's for Compaq C++ V6.5-040 for Compaq Tru64 UNIX
[SVN r22636]
2004-04-15 14:17:09 +00:00
Dave Abrahams
6c8fec96b6 Tweaks prompted by Faheem Mitha
[SVN r22632]
2004-04-13 12:19:15 +00:00
Dave Abrahams
cd139bd4ec Fixes prompted by Faheem Mitha
[SVN r22631]
2004-04-13 12:14:10 +00:00
Dave Abrahams
17b0c819e4 improved comments in-line
[SVN r22628]
2004-04-11 12:07:18 +00:00
Joel de Guzman
79c7d736f0 embedding tutorial updates
[SVN r22618]
2004-04-07 07:33:57 +00:00
Joel de Guzman
b627f93cf1 embedding tutorial updates
[SVN r22616]
2004-04-07 02:26:36 +00:00
Joel de Guzman
7d632ab3dd added test for embedding tutorial
[SVN r22614]
2004-04-07 01:32:53 +00:00
Bruno da Silva de Oliveira
bdf80a683c - removed exporters.importing mechanism, because this was causing a serious bug that was preventing the bases code to be generated
[SVN r22613]
2004-04-06 22:53:38 +00:00
Joel de Guzman
ed7292abd3 added test for embedding tutorial
[SVN r22609]
2004-04-06 11:50:20 +00:00
Joel de Guzman
e92f042677 additional constructor in BaseWrap
[SVN r22604]
2004-04-05 09:34:32 +00:00
Joel de Guzman
53cf9e7422 Typo
[SVN r22603]
2004-04-05 09:21:45 +00:00
Dave Abrahams
954afd78b2 Added Vega Strike
[SVN r22583]
2004-04-02 20:04:22 +00:00
Dave Abrahams
957ad2b4b1 Adjust to make the tutorial work
[SVN r22568]
2004-03-30 23:14:47 +00:00
Jonathan Brandmeyer
7187c6132a Throw an IndexError when given an extended slice;
Clip bounds of slices in a mannar consistant with builtin containers;
Prevent undefined behavior within the STL when given certain kinds of
empty slices.


[SVN r22507]
2004-03-17 03:15:35 +00:00
Dave Abrahams
b3f0d7c756 Fix bad "fix".
[SVN r22495]
2004-03-13 01:47:35 +00:00
Dave Abrahams
0cdfdee18f *** empty log message ***
[SVN r22492]
2004-03-12 22:34:43 +00:00
Ralf W. Grosse-Kunstleve
a283f56d05 define BOOST_PYTHON_TYPE_ID_NAME for Linux Intel C++
[SVN r22491]
2004-03-12 18:43:08 +00:00
Dave Abrahams
e6fd78ce93 Fixes for auto_ptr handling
[SVN r22490]
2004-03-12 15:22:16 +00:00
Dave Abrahams
aeed5f029e Use mpl::next to prepare for the next release of MPL
[SVN r22485]
2004-03-12 13:10:40 +00:00
Bruno da Silva de Oliveira
04484d55de - Fixed bug with exception declarations
[SVN r22459]
2004-03-09 01:01:29 +00:00
Jonathan Brandmeyer
476cba228d Changes to support MSVC 6.0.
[SVN r22430]
2004-03-04 16:42:56 +00:00
Eric Niebler
115f9f0644 remove minmax hack from win32.hpp and fix all places that could be affected by the minmax macros
[SVN r22394]
2004-02-26 18:27:02 +00:00
Daniel Wallin
a9c2a95366 boost logo css class
[SVN r22352]
2004-02-21 18:42:52 +00:00
Bruno da Silva de Oliveira
29f3891a68 - Generates the unique number for UniqueInt using the hash of the filename
[SVN r22329]
2004-02-19 22:26:54 +00:00
Bruno da Silva de Oliveira
7b602ef607 - now warns that AllFromHeader is not working in all cases
[SVN r22316]
2004-02-18 22:32:58 +00:00
Bruno da Silva de Oliveira
15e555c7f1 - Fixed UniqueInt bug across different compilation units.
[SVN r22315]
2004-02-18 22:28:28 +00:00
Bruno da Silva de Oliveira
f4fb49d32f - reverted previous commit
[SVN r22313]
2004-02-18 15:33:34 +00:00
Bruno da Silva de Oliveira
89be2fb736 - no_init is now generated for abstract classes
[SVN r22312]
2004-02-18 15:27:59 +00:00
Ralf W. Grosse-Kunstleve
62f0885852 Requires: n/a removed
[SVN r22257]
2004-02-13 18:20:43 +00:00
Ralf W. Grosse-Kunstleve
355e155e69 gcc 3.4 from gcc.gnu.org still suffers from the old static initialization bug under Mac OS 10: workaround adjusted accordingly
[SVN r22255]
2004-02-13 07:10:59 +00:00
Ralf W. Grosse-Kunstleve
ae1584ff3c class_::enable_pickling() in publicized interface; tested with everything incl. VC6 and 7.0
[SVN r22254]
2004-02-13 05:32:38 +00:00
Jonathan Brandmeyer
4a7686cd33 Check rich slicing of Numeric arrays only if Numeric or numarray is
installed.


[SVN r22252]
2004-02-13 02:07:21 +00:00
Jonathan Brandmeyer
799eeb0cb8 Fix a build error on Tru64. Thanks to Ralf W. Grosse-Kunstleve for this
fix.


[SVN r22250]
2004-02-12 23:09:10 +00:00
Jonathan Brandmeyer
8452e275d0 New implementation, tests, and documentation for a PySliceObject
objectmanager.


[SVN r22192]
2004-02-07 21:38:24 +00:00
Joel de Guzman
53268000e7 small typo
[SVN r22067]
2004-01-30 06:15:32 +00:00
Dave Abrahams
52febfe3fc Improved and alphabetized news format, added Python news, updated
iterator news.

Corrections in the Python documentation


[SVN r22039]
2004-01-29 03:34:23 +00:00
Dave Abrahams
8fcfed495a Fixes for intel-linux
added <default> feature handling for specifying build defaults in requirement sets.


[SVN r22027]
2004-01-28 22:50:18 +00:00
Joel de Guzman
2dfe76b082 small typo
[SVN r22026]
2004-01-28 22:45:35 +00:00
Ralf W. Grosse-Kunstleve
11d8751d29 workaround for gcc 3.4 bug when using precompiled header support
[SVN r21715]
2004-01-14 01:37:54 +00:00
Ralf W. Grosse-Kunstleve
b03c3a29e0 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
53e8982e05 fix typo
[SVN r21571]
2004-01-10 02:53:06 +00:00
Ralf W. Grosse-Kunstleve
4a30841ad8 fix for Tru64 cxx problems incl. workaround for gcc 2.96 problems; patch by David Abrahams; thanks Dave!
[SVN r21558]
2004-01-09 07:25:17 +00:00
Dave Abrahams
234ebadb8d pro9 workarounds; some ADL protection for is_xxx
[SVN r21529]
2004-01-07 14:07:21 +00:00
Dave Abrahams
11ee20fa36 Test full slicing.
[SVN r21497]
2004-01-05 12:34:25 +00:00
Dave Abrahams
440599545f Workaround for gcc-3.4 quirks
[SVN r21493]
2004-01-05 11:46:30 +00:00
Dave Abrahams
44ba088cb4 Fix problem with [:] slices on python::objects
[SVN r21472]
2004-01-04 13:41:00 +00:00
Dave Abrahams
08d3798722 .
[SVN r21449]
2004-01-02 18:34:17 +00:00
Ralf W. Grosse-Kunstleve
56ff8e438e fix use of incomplete type (Tru64 cxx diagnostic)
[SVN r21444]
2004-01-02 08:31:21 +00:00
Dave Abrahams
3590a3589d Fix 2-phase lookup bug
[SVN r21442]
2004-01-01 12:46:04 +00:00
Dave Abrahams
7674c82e1f Fix bug with (arg("x"), "y") construct.
[SVN r21437]
2003-12-31 19:20:31 +00:00
Ralf W. Grosse-Kunstleve
b93b21a7f2 work around Visual C++ 6 internal compiler errors
[SVN r21435]
2003-12-31 17:18:03 +00:00
Ralf W. Grosse-Kunstleve
f53925848c work around g++ (GCC) 3.4.0 20031230 (experimental) internal compiler error
[SVN r21432]
2003-12-31 09:37:31 +00:00
Dave Abrahams
eedc88b56a Bug fixes in property handling
[SVN r21429]
2003-12-31 00:23:52 +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
Bruno da Silva de Oliveira
256e3a467c - Appliced a patch from Giulio Eulisse that allows unnamed enumerations to be
exported with an AllFromHeader construct


[SVN r18657]
2003-06-03 20:58:22 +00:00
Ralf W. Grosse-Kunstleve
4477fe4dd6 Python 2.3 Tru64 cxx compatibility & a little cleanup
[SVN r18652]
2003-06-03 02:58:43 +00:00
745 changed files with 33706 additions and 18419 deletions

Binary file not shown.

View File

@@ -1,84 +0,0 @@
# (C) Copyright David Abrahams 2001. Permission to copy, use, modify, sell and
# distribute this software is granted provided this copyright notice appears
# in all copies. This software is provided "as is" without express or implied
# warranty, and with no claim as to its suitability for any purpose.
#
# Boost.Python library Jamfile
# declare the location of this subproject relative to the root
subproject libs/python/build ;
# bring in the rules for python
SEARCH on <module@>python.jam = $(BOOST_BUILD_PATH) ;
include <module@>python.jam ;
if [ check-python-config ]
{
local bpl-linkflags ;
if $(UNIX) && ( $(OS) = AIX )
{
bpl-linkflags = <linkflags>"-e initlibboost_python" ;
}
# Enabling intrinsics (/0i) or maximize speed (/02) seem to cause
# internal compiler errors with this toolset.
local msvc-stlport-workarounds
= <optimization>off "<cxxflags>-Ogty -O1 -Gs" ;
local sources =
numeric.cpp
list.cpp
long.cpp
dict.cpp
tuple.cpp
str.cpp
aix_init_module.cpp
converter/from_python.cpp
converter/registry.cpp
converter/type_id.cpp
object/enum.cpp
object/class.cpp
object/function.cpp
object/inheritance.cpp
object/life_support.cpp
object/pickle_support.cpp
errors.cpp
module.cpp
converter/builtin_converters.cpp
converter/arg_to_python_base.cpp
object/iterator.cpp
object_protocol.cpp
object_operators.cpp
;
dll boost_python
: ../src/$(sources)
: $(BOOST_PYTHON_V2_PROPERTIES)
<define>BOOST_PYTHON_SOURCE
$(bpl-linkflags)
<msvc-stlport><release>$(msvc-stlport-workarounds)
;
lib boost_python
: # sources
../src/$(sources)
: # requirements
$(BOOST_PYTHON_V2_PROPERTIES)
<define>BOOST_PYTHON_SOURCE
<define>BOOST_STATIC_LIB
$(bpl-linkflags)
<msvc-stlport><release>$(msvc-stlport-workarounds)
;
stage bin-stage : <dll>boost_python <lib>boost_python
: <tag><debug>"_debug"
<tag><debug-python>"_pydebug"
:
debug release
;
}

View File

@@ -1,85 +1,151 @@
# Copyright David Abrahams 2001-2006. Distributed under the Boost
# Software License, Version 1.0. (See accompanying
# file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
import os ;
import indirect ;
import modules ;
import feature ;
# Use a very crude way to sense there python is locatted
import python ;
local PYTHON_PATH ;
if [ GLOB /usr/local/include/python2.2 : * ]
if ! [ python.configured ] && ! ( --without-python in [ modules.peek : ARGV ] )
{
PYTHON_PATH = /usr/local ;
}
else if [ GLOB /usr/include/python2.2 : * ]
{
PYTHON_PATH = /usr ;
# Attempt default configuration of python
import toolset : using ;
using python ;
}
if [ os.name ] in CYGWIN NT
if [ python.configured ] || ( --without-python in [ modules.peek : ARGV ] )
{
lib_condition = <link>shared: ;
defines = USE_DL_IMPORT ;
# Declare a target for the python interpreter library
lib python : : <name>python2.2.dll ;
PYTHON_LIB = python ;
}
else
alias config-warning ;
}
else
{
lib python : : <name>python2.2 ;
PYTHON_LIB = python ;
message config-warning
: "warning: No python installation configured and autoconfiguration"
: "note: failed. See http://www.boost.org/libs/python/doc/building.html"
: "note: for configuration instructions or pass --without-python to"
: "note: suppress this message and silently skip all Boost.Python targets"
;
}
rule find-py3-version
{
local versions = [ feature.values python ] ;
local py3ver ;
for local v in $(versions)
{
if $(v) >= 3.0
{
py3ver = $(v) ;
}
}
return $(py3ver) ;
}
if $(PYTHON_PATH) {
py3-version = [ find-py3-version ] ;
project boost/python
: source-location ../src
: requirements <include>$(PYTHON_PATH)/include/python2.2
$(lib_condition)<library-path>$(PYTHON_PATH)/lib/python2.2/config
<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
: source-location ../src
: requirements
-<tag>@$(BOOST_JAMROOT_MODULE)%$(BOOST_JAMROOT_MODULE).tag
<tag>@$(__name__).tag
;
# We have a bug which causes us to conclude that conditionalized
# properties in this section are not free.
# $(lib_condition)<library-path>$(PYTHON_PATH)/lib/python2.2/config
# <shared>true:<find-library>$(PYTHON_LIB)
<library-path>$(PYTHON_PATH)/lib/python2.2/config
<library>$(PYTHON_LIB)
;
lib boost_python
:
numeric.cpp
list.cpp
long.cpp
dict.cpp
tuple.cpp
str.cpp
aix_init_module.cpp
converter/from_python.cpp
converter/registry.cpp
converter/type_id.cpp
object/enum.cpp
object/class.cpp
object/function.cpp
object/inheritance.cpp
object/life_support.cpp
object/pickle_support.cpp
errors.cpp
module.cpp
converter/builtin_converters.cpp
converter/arg_to_python_base.cpp
object/iterator.cpp
object_protocol.cpp
object_operators.cpp
: <link>static:<define>BOOST_PYTHON_STATIC_LIB
<define>BOOST_PYTHON_SOURCE
: <link>shared
;
rule tag ( name : type ? : property-set )
{
local result = $(name) ;
if $(type) in STATIC_LIB SHARED_LIB IMPORT_LIB
{
if $(name) = boost_python && $(PYTHON_ID)
{
result = $(result)-$(PYTHON_ID) ;
}
}
# forward to the boost tagging rule
return [ indirect.call $(BOOST_JAMROOT_MODULE)%$(BOOST_JAMROOT_MODULE).tag
$(result) : $(type) : $(property-set) ] ;
}
rule cond ( test ? : yes * : no * ) { if $(test) { return $(yes) ; } else { return $(no) ; } }
rule unless ( test ? : yes * : no * ) { if ! $(test) { return $(yes) ; } else { return $(no) ; } }
rule lib_boost_python ( is-py3 ? )
{
lib [ cond $(is-py3) : boost_python3 : boost_python ]
: # sources
numeric.cpp
list.cpp
long.cpp
dict.cpp
tuple.cpp
str.cpp
slice.cpp
converter/from_python.cpp
converter/registry.cpp
converter/type_id.cpp
object/enum.cpp
object/class.cpp
object/function.cpp
object/inheritance.cpp
object/life_support.cpp
object/pickle_support.cpp
errors.cpp
module.cpp
converter/builtin_converters.cpp
converter/arg_to_python_base.cpp
object/iterator.cpp
object/stl_iterator.cpp
object_protocol.cpp
object_operators.cpp
wrapper.cpp
import.cpp
exec.cpp
object/function_doc_signature.cpp
: # requirements
<link>static:<define>BOOST_PYTHON_STATIC_LIB
<define>BOOST_PYTHON_SOURCE
# On Windows, all code using Python has to link to the Python
# import library.
#
# On *nix we never link libboost_python to libpython. When
# extending Python, all Python symbols are provided by the
# Python interpreter executable. When embedding Python, the
# client executable is expected to explicitly link to
# /python//python (the target representing libpython) itself.
#
# python_for_extensions is a target defined by Boost.Build to
# provide the Python include paths, and on Windows, the Python
# import library, as usage requirements.
[ cond [ python.configured ] : <library>/python//python_for_extensions ]
# we prevent building when there is no python available
# as it's not possible anyway, and to cause dependents to
# fail to build
[ unless [ python.configured ] : <build>no ]
<dependency>config-warning
<python-debugging>on:<define>BOOST_DEBUG_PYTHON
[ cond $(is-py3) : <python>$(py3-version) ]
: # default build
<link>shared
: # usage requirements
<link>static:<define>BOOST_PYTHON_STATIC_LIB
<python-debugging>on:<define>BOOST_DEBUG_PYTHON
;
}
lib_boost_python ;
boost-install boost_python ;
if $(py3-version)
{
lib_boost_python yes ;
boost-install boost_python3 ;
}

View File

@@ -1,882 +0,0 @@
# Microsoft Developer Studio Project File - Name="boost_python" - Package Owner=<4>
# Microsoft Developer Studio Generated Build File, Format Version 6.00
# ** DO NOT EDIT **
# TARGTYPE "Win32 (x86) Dynamic-Link Library" 0x0102
CFG=BOOST_PYTHON - WIN32 RELEASE
!MESSAGE This is not a valid makefile. To build this project using NMAKE,
!MESSAGE use the Export Makefile command and run
!MESSAGE
!MESSAGE NMAKE /f "boost_python.mak".
!MESSAGE
!MESSAGE You can specify a configuration when running NMAKE
!MESSAGE by defining the macro CFG on the command line. For example:
!MESSAGE
!MESSAGE NMAKE /f "boost_python.mak" CFG="BOOST_PYTHON - WIN32 RELEASE"
!MESSAGE
!MESSAGE Possible choices for configuration are:
!MESSAGE
!MESSAGE "boost_python - Win32 Release" (based on "Win32 (x86) Dynamic-Link Library")
!MESSAGE "boost_python - Win32 Debug" (based on "Win32 (x86) Dynamic-Link Library")
!MESSAGE
# Begin Project
# PROP AllowPerConfigDependencies 0
# PROP Scc_ProjName ""
# PROP Scc_LocalPath ""
CPP=cl.exe
MTL=midl.exe
RSC=rc.exe
!IF "$(CFG)" == "boost_python - Win32 Release"
# PROP BASE Use_MFC 0
# PROP BASE Use_Debug_Libraries 0
# PROP BASE Output_Dir "Release"
# PROP BASE Intermediate_Dir "Release"
# PROP BASE Target_Dir ""
# PROP Use_MFC 0
# PROP Use_Debug_Libraries 0
# PROP Output_Dir "../bin-stage"
# PROP Intermediate_Dir "release-obj"
# PROP Ignore_Export_Lib 0
# PROP Target_Dir ""
F90=df.exe
# ADD BASE CPP /nologo /MT /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "BPL_EXPORTS" /YX /FD /Zm800 /Zm800 /Zm800 /c
# ADD CPP /nologo /MD /W3 /GR /GX /O2 /I "../../../../" /D "NDEBUG" /D "WIN32" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "BOOST_PYTHON_DYNAMIC_LIB" /D "BOOST_PYTHON_SOURCE" /FD /Zm800 /Zm800 /Zm800 /Zm800 /c
# SUBTRACT CPP /YX
# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32
# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32
# ADD BASE RSC /l 0x1409 /d "NDEBUG"
# ADD RSC /l 0x1409 /d "NDEBUG"
BSC32=bscmake.exe
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo
LINK32=link.exe
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /machine:I386
# ADD LINK32 kernel32.lib user32.lib /nologo /dll /machine:I386
!ELSEIF "$(CFG)" == "boost_python - Win32 Debug"
# PROP BASE Use_MFC 0
# PROP BASE Use_Debug_Libraries 1
# PROP BASE Output_Dir "Debug"
# PROP BASE Intermediate_Dir "Debug"
# PROP BASE Target_Dir ""
# PROP Use_MFC 0
# PROP Use_Debug_Libraries 1
# PROP Output_Dir "../bin-stage"
# PROP Intermediate_Dir "debug-obj"
# PROP Ignore_Export_Lib 0
# PROP Target_Dir ""
F90=df.exe
# ADD BASE CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "BPL_EXPORTS" /YX /FD /Zm800 /Zm800 /Zm800 /GZ /c
# ADD CPP /nologo /MDd /W3 /GR /GX /Zi /Od /I "../../../../" /D "_DEBUG" /D "WIN32" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "BOOST_PYTHON_DYNAMIC_LIB" /D "BOOST_PYTHON_SOURCE" /FD /Zm800 /Zm800 /Zm800 /Zm800 /Zm800 /GZ /c
# ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /win32
# ADD MTL /nologo /D "_DEBUG" /mktyplib203 /win32
# ADD BASE RSC /l 0x1409 /d "_DEBUG"
# ADD RSC /l 0x1409 /d "_DEBUG"
BSC32=bscmake.exe
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo
LINK32=link.exe
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /debug /machine:I386 /pdbtype:sept
# ADD LINK32 kernel32.lib user32.lib /nologo /dll /incremental:no /debug /machine:I386 /out:"../bin-stage/boost_python_debug.dll" /pdbtype:sept
!ENDIF
# Begin Target
# Name "boost_python - Win32 Release"
# Name "boost_python - Win32 Debug"
# Begin Group "Source Files"
# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
# Begin Source File
SOURCE=..\..\src\aix_init_module.cpp
# End Source File
# Begin Source File
SOURCE=..\..\src\converter\arg_to_python_base.cpp
# End Source File
# Begin Source File
SOURCE=..\..\src\converter\builtin_converters.cpp
# End Source File
# Begin Source File
SOURCE=..\..\src\object\class.cpp
# End Source File
# Begin Source File
SOURCE=..\..\src\dict.cpp
# End Source File
# Begin Source File
SOURCE=..\..\src\object\enum.cpp
# End Source File
# Begin Source File
SOURCE=..\..\src\errors.cpp
# End Source File
# Begin Source File
SOURCE=..\..\src\converter\from_python.cpp
# End Source File
# Begin Source File
SOURCE=..\..\src\object\function.cpp
# End Source File
# Begin Source File
SOURCE=..\..\src\object\inheritance.cpp
# End Source File
# Begin Source File
SOURCE=..\..\src\object\iterator.cpp
# End Source File
# Begin Source File
SOURCE=..\..\src\object\life_support.cpp
# End Source File
# Begin Source File
SOURCE=..\..\src\list.cpp
# End Source File
# Begin Source File
SOURCE=..\..\src\long.cpp
# End Source File
# Begin Source File
SOURCE=..\..\src\module.cpp
# End Source File
# Begin Source File
SOURCE=..\..\src\numeric.cpp
# End Source File
# Begin Source File
SOURCE=..\..\src\object_operators.cpp
# End Source File
# Begin Source File
SOURCE=..\..\src\object_protocol.cpp
# End Source File
# Begin Source File
SOURCE=..\..\src\object\pickle_support.cpp
# End Source File
# Begin Source File
SOURCE=..\..\src\converter\registry.cpp
# End Source File
# Begin Source File
SOURCE=..\..\src\str.cpp
# End Source File
# Begin Source File
SOURCE=..\..\src\tuple.cpp
# End Source File
# Begin Source File
SOURCE=..\..\src\converter\type_id.cpp
# End Source File
# End Group
# Begin Group "Header Files"
# PROP Default_Filter "h;hpp;hxx;hm;inl"
# Begin Group "detail"
# PROP Default_Filter ""
# Begin Source File
SOURCE=..\..\..\..\boost\python\detail\aix_init_module.hpp
# End Source File
# Begin Source File
SOURCE=..\..\..\..\boost\python\detail\api_placeholder.hpp
# End Source File
# Begin Source File
SOURCE=..\..\..\..\boost\python\detail\arg_tuple_size.hpp
# End Source File
# Begin Source File
SOURCE=..\..\..\..\boost\python\detail\borrowed_ptr.hpp
# End Source File
# Begin Source File
SOURCE=..\..\..\..\boost\python\detail\call_object.hpp
# End Source File
# Begin Source File
SOURCE=..\..\..\..\boost\python\detail\caller.hpp
# End Source File
# Begin Source File
SOURCE=..\..\..\..\boost\python\detail\char_array.hpp
# End Source File
# Begin Source File
SOURCE=..\..\..\..\boost\python\detail\config.hpp
# End Source File
# Begin Source File
SOURCE=..\..\..\..\boost\python\detail\construct.hpp
# End Source File
# Begin Source File
SOURCE=..\..\..\..\boost\python\detail\convertible.hpp
# End Source File
# Begin Source File
SOURCE=..\..\..\..\boost\python\detail\cv_category.hpp
# End Source File
# Begin Source File
SOURCE=..\..\..\..\boost\python\detail\decorated_type_id.hpp
# End Source File
# Begin Source File
SOURCE=..\..\..\..\boost\python\detail\def_helper.hpp
# End Source File
# Begin Source File
SOURCE=..\..\..\..\boost\python\detail\defaults_def.hpp
# End Source File
# Begin Source File
SOURCE=..\..\..\..\boost\python\detail\defaults_gen.hpp
# End Source File
# Begin Source File
SOURCE=..\..\..\..\boost\python\detail\dependent.hpp
# End Source File
# Begin Source File
SOURCE=..\..\..\..\boost\python\detail\destroy.hpp
# End Source File
# Begin Source File
SOURCE=..\..\..\..\boost\python\detail\exception_handler.hpp
# End Source File
# Begin Source File
SOURCE=..\..\..\..\boost\python\detail\force_instantiate.hpp
# End Source File
# Begin Source File
SOURCE=..\..\..\..\boost\python\detail\if_else.hpp
# End Source File
# Begin Source File
SOURCE=..\..\..\..\boost\python\detail\indirect_traits.hpp
# End Source File
# Begin Source File
SOURCE=..\..\..\..\boost\python\detail\make_keyword_range_fn.hpp
# End Source File
# Begin Source File
SOURCE=..\..\..\..\boost\python\detail\make_tuple.hpp
# End Source File
# Begin Source File
SOURCE=..\..\..\..\boost\python\detail\map_entry.hpp
# End Source File
# Begin Source File
SOURCE=..\..\..\..\boost\python\detail\member_function_cast.hpp
# End Source File
# Begin Source File
SOURCE=..\..\..\..\boost\python\detail\module_base.hpp
# End Source File
# Begin Source File
SOURCE=..\..\..\..\boost\python\detail\module_init.hpp
# End Source File
# Begin Source File
SOURCE=..\..\..\..\boost\python\detail\msvc_typeinfo.hpp
# End Source File
# Begin Source File
SOURCE=..\..\..\..\boost\python\detail\none.hpp
# End Source File
# Begin Source File
SOURCE=..\..\..\..\boost\python\detail\not_specified.hpp
# End Source File
# Begin Source File
SOURCE=..\..\..\..\boost\python\detail\operator_id.hpp
# End Source File
# Begin Source File
SOURCE=..\..\..\..\boost\python\detail\overloads_fwd.hpp
# End Source File
# Begin Source File
SOURCE=..\..\..\..\boost\python\detail\pointee.hpp
# End Source File
# Begin Source File
SOURCE=..\..\..\..\boost\python\detail\preprocessor.hpp
# End Source File
# Begin Source File
SOURCE=..\..\..\..\boost\python\detail\python22_fixed.h
# End Source File
# Begin Source File
SOURCE=..\..\..\..\boost\python\detail\raw_pyobject.hpp
# End Source File
# Begin Source File
SOURCE=..\..\..\..\boost\python\detail\referent_storage.hpp
# End Source File
# Begin Source File
SOURCE=..\..\..\..\boost\python\detail\result.hpp
# End Source File
# Begin Source File
SOURCE=..\..\..\..\boost\python\detail\returning.hpp
# End Source File
# Begin Source File
SOURCE=..\..\..\..\boost\python\detail\scope.hpp
# End Source File
# Begin Source File
SOURCE=..\..\..\..\boost\python\detail\string_literal.hpp
# End Source File
# Begin Source File
SOURCE=..\..\..\..\boost\python\detail\target.hpp
# End Source File
# Begin Source File
SOURCE=..\..\..\..\boost\python\detail\translate_exception.hpp
# End Source File
# Begin Source File
SOURCE=..\..\..\..\boost\python\detail\type_list.hpp
# End Source File
# Begin Source File
SOURCE=..\..\..\..\boost\python\detail\type_list_impl.hpp
# End Source File
# Begin Source File
SOURCE=..\..\..\..\boost\python\detail\type_list_impl_no_pts.hpp
# End Source File
# Begin Source File
SOURCE=..\..\..\..\boost\python\detail\type_list_utils.hpp
# End Source File
# Begin Source File
SOURCE=..\..\..\..\boost\python\detail\unwind_type.hpp
# End Source File
# Begin Source File
SOURCE=..\..\..\..\boost\python\detail\void_ptr.hpp
# End Source File
# Begin Source File
SOURCE=..\..\..\..\boost\python\detail\void_return.hpp
# End Source File
# Begin Source File
SOURCE=..\..\..\..\boost\python\detail\wrap_python.hpp
# End Source File
# End Group
# Begin Group "converter"
# PROP Default_Filter ""
# Begin Source File
SOURCE=..\..\..\..\boost\python\converter\arg_from_python.hpp
# End Source File
# Begin Source File
SOURCE=..\..\..\..\boost\python\converter\arg_to_python.hpp
# End Source File
# Begin Source File
SOURCE=..\..\..\..\boost\python\converter\arg_to_python_base.hpp
# End Source File
# Begin Source File
SOURCE=..\..\..\..\boost\python\converter\builtin_converters.hpp
# End Source File
# Begin Source File
SOURCE=..\..\..\..\boost\python\converter\constructor_function.hpp
# End Source File
# Begin Source File
SOURCE=..\..\..\..\boost\python\converter\convertible_function.hpp
# End Source File
# Begin Source File
SOURCE=..\..\..\..\boost\python\converter\from_python.hpp
# End Source File
# Begin Source File
SOURCE=..\..\..\..\boost\python\converter\implicit.hpp
# End Source File
# Begin Source File
SOURCE=..\..\..\..\boost\python\converter\obj_mgr_arg_from_python.hpp
# End Source File
# Begin Source File
SOURCE=..\..\..\..\boost\python\converter\object_manager.hpp
# End Source File
# Begin Source File
SOURCE=..\..\..\..\boost\python\converter\pointer_type_id.hpp
# End Source File
# Begin Source File
SOURCE=..\..\..\..\boost\python\converter\pyobject_traits.hpp
# End Source File
# Begin Source File
SOURCE=..\..\..\..\boost\python\converter\pyobject_type.hpp
# End Source File
# Begin Source File
SOURCE=..\..\..\..\boost\python\converter\pytype_arg_from_python.hpp
# End Source File
# Begin Source File
SOURCE=..\..\..\..\boost\python\converter\pytype_object_mgr_traits.hpp
# End Source File
# Begin Source File
SOURCE=..\..\..\..\boost\python\converter\registered.hpp
# End Source File
# Begin Source File
SOURCE=..\..\..\..\boost\python\converter\registered_pointee.hpp
# End Source File
# Begin Source File
SOURCE=..\..\..\..\boost\python\converter\registrations.hpp
# End Source File
# Begin Source File
SOURCE=..\..\..\..\boost\python\converter\registry.hpp
# End Source File
# Begin Source File
SOURCE=..\..\..\..\boost\python\converter\return_from_python.hpp
# End Source File
# Begin Source File
SOURCE=..\..\..\..\boost\python\converter\rvalue_from_python_data.hpp
# End Source File
# Begin Source File
SOURCE=..\..\..\..\boost\python\converter\to_python_function_type.hpp
# End Source File
# End Group
# Begin Group "object"
# PROP Default_Filter ""
# Begin Source File
SOURCE=..\..\..\..\boost\python\object\add_to_namespace.hpp
# End Source File
# Begin Source File
SOURCE=..\..\..\..\boost\python\object\class.hpp
# End Source File
# Begin Source File
SOURCE=..\..\..\..\boost\python\object\class_converters.hpp
# End Source File
# Begin Source File
SOURCE=..\..\..\..\boost\python\object\class_detail.hpp
# End Source File
# Begin Source File
SOURCE=..\..\..\..\boost\python\object\class_wrapper.hpp
# End Source File
# Begin Source File
SOURCE=..\..\..\..\boost\python\object\construct.hpp
# End Source File
# Begin Source File
SOURCE=..\..\..\..\boost\python\object\enum_base.hpp
# End Source File
# Begin Source File
SOURCE=..\..\..\..\boost\python\object\find_instance.hpp
# End Source File
# Begin Source File
SOURCE=..\..\..\..\boost\python\object\forward.hpp
# End Source File
# Begin Source File
SOURCE=..\..\..\..\boost\python\object\function.hpp
# End Source File
# Begin Source File
SOURCE=..\..\..\..\boost\python\object\function_handle.hpp
# End Source File
# Begin Source File
SOURCE=..\..\..\..\boost\python\object\function_object.hpp
# End Source File
# Begin Source File
SOURCE=..\..\..\..\boost\python\object\inheritance.hpp
# End Source File
# Begin Source File
SOURCE=..\..\..\..\boost\python\object\instance.hpp
# End Source File
# Begin Source File
SOURCE=..\..\..\..\boost\python\object\iterator.hpp
# End Source File
# Begin Source File
SOURCE=..\..\..\..\boost\python\object\iterator_core.hpp
# End Source File
# Begin Source File
SOURCE=..\..\..\..\boost\python\object\life_support.hpp
# End Source File
# Begin Source File
SOURCE=..\..\..\..\boost\python\object\make_holder.hpp
# End Source File
# Begin Source File
SOURCE=..\..\..\..\boost\python\object\make_instance.hpp
# End Source File
# Begin Source File
SOURCE=..\..\..\..\boost\python\object\pickle_support.hpp
# End Source File
# Begin Source File
SOURCE=..\..\..\..\boost\python\object\pointer_holder.hpp
# End Source File
# Begin Source File
SOURCE=..\..\..\..\boost\python\object\py_function.hpp
# End Source File
# Begin Source File
SOURCE=..\..\..\..\boost\python\object\select_holder.hpp
# End Source File
# Begin Source File
SOURCE=..\..\..\..\boost\python\object\value_holder.hpp
# End Source File
# Begin Source File
SOURCE=..\..\..\..\boost\python\object\value_holder_fwd.hpp
# End Source File
# End Group
# Begin Source File
SOURCE=..\..\..\..\boost\python\arg_from_python.hpp
# End Source File
# Begin Source File
SOURCE=..\..\..\..\boost\python\args.hpp
# End Source File
# Begin Source File
SOURCE=..\..\..\..\boost\python\args_fwd.hpp
# End Source File
# Begin Source File
SOURCE=..\..\..\..\boost\python\back_reference.hpp
# End Source File
# Begin Source File
SOURCE=..\..\..\..\boost\python\base_type_traits.hpp
# End Source File
# Begin Source File
SOURCE=..\..\..\..\boost\python\bases.hpp
# End Source File
# Begin Source File
SOURCE=..\..\..\..\boost\python\borrowed.hpp
# End Source File
# Begin Source File
SOURCE=..\..\..\..\boost\python\call.hpp
# End Source File
# Begin Source File
SOURCE=..\..\..\..\boost\python\call_method.hpp
# End Source File
# Begin Source File
SOURCE=..\..\..\..\boost\python\cast.hpp
# End Source File
# Begin Source File
SOURCE=..\..\..\..\boost\python\class.hpp
# End Source File
# Begin Source File
SOURCE=..\..\..\..\boost\python\class_fwd.hpp
# End Source File
# Begin Source File
SOURCE=..\..\..\..\boost\python\copy_const_reference.hpp
# End Source File
# Begin Source File
SOURCE=..\..\..\..\boost\python\copy_non_const_reference.hpp
# End Source File
# Begin Source File
SOURCE=..\..\..\..\boost\python\data_members.hpp
# End Source File
# Begin Source File
SOURCE=..\..\..\..\boost\python\def.hpp
# End Source File
# Begin Source File
SOURCE=..\..\..\..\boost\python\default_call_policies.hpp
# End Source File
# Begin Source File
SOURCE=..\..\..\..\boost\python\dict.hpp
# End Source File
# Begin Source File
SOURCE=..\..\..\..\boost\python\enum.hpp
# End Source File
# Begin Source File
SOURCE=..\..\..\..\boost\python\errors.hpp
# End Source File
# Begin Source File
SOURCE=..\..\..\..\boost\python\exception_translator.hpp
# End Source File
# Begin Source File
SOURCE=..\..\..\..\boost\python\extract.hpp
# End Source File
# Begin Source File
SOURCE=..\..\..\..\boost\python\handle.hpp
# End Source File
# Begin Source File
SOURCE=..\..\..\..\boost\python\handle_fwd.hpp
# End Source File
# Begin Source File
SOURCE=..\..\..\..\boost\python\has_back_reference.hpp
# End Source File
# Begin Source File
SOURCE=..\..\..\..\boost\python\implicit.hpp
# End Source File
# Begin Source File
SOURCE=..\..\..\..\boost\python\init.hpp
# End Source File
# Begin Source File
SOURCE=..\..\..\..\boost\python\instance_holder.hpp
# End Source File
# Begin Source File
SOURCE=..\..\..\..\boost\python\iterator.hpp
# End Source File
# Begin Source File
SOURCE=..\..\..\..\boost\python\list.hpp
# End Source File
# Begin Source File
SOURCE=..\..\..\..\boost\python\long.hpp
# End Source File
# Begin Source File
SOURCE=..\..\..\..\boost\python\lvalue_from_pytype.hpp
# End Source File
# Begin Source File
SOURCE=..\..\..\..\boost\python\make_function.hpp
# End Source File
# Begin Source File
SOURCE=..\..\..\..\boost\python\manage_new_object.hpp
# End Source File
# Begin Source File
SOURCE=..\..\..\..\boost\python\module.hpp
# End Source File
# Begin Source File
SOURCE=..\..\..\..\boost\python\module_init.hpp
# End Source File
# Begin Source File
SOURCE=..\..\..\..\boost\python\numeric.hpp
# End Source File
# Begin Source File
SOURCE=..\..\..\..\boost\python\object.hpp
# End Source File
# Begin Source File
SOURCE=..\..\..\..\boost\python\object_attributes.hpp
# End Source File
# Begin Source File
SOURCE=..\..\..\..\boost\python\object_call.hpp
# End Source File
# Begin Source File
SOURCE=..\..\..\..\boost\python\object_core.hpp
# End Source File
# Begin Source File
SOURCE=..\..\..\..\boost\python\object_fwd.hpp
# End Source File
# Begin Source File
SOURCE=..\..\..\..\boost\python\object_items.hpp
# End Source File
# Begin Source File
SOURCE=..\..\..\..\boost\python\object_operators.hpp
# End Source File
# Begin Source File
SOURCE=..\..\..\..\boost\python\object_protocol.hpp
# End Source File
# Begin Source File
SOURCE=..\..\..\..\boost\python\object_protocol_core.hpp
# End Source File
# Begin Source File
SOURCE=..\..\..\..\boost\python\object_slices.hpp
# End Source File
# Begin Source File
SOURCE=..\..\..\..\boost\python\operators.hpp
# End Source File
# Begin Source File
SOURCE=..\..\..\..\boost\python\operators2.hpp
# End Source File
# Begin Source File
SOURCE=..\..\..\..\boost\python\other.hpp
# End Source File
# Begin Source File
SOURCE=..\..\..\..\boost\python\overloads.hpp
# End Source File
# Begin Source File
SOURCE=..\..\..\..\boost\python\pointee.hpp
# End Source File
# Begin Source File
SOURCE=..\..\..\..\boost\python\proxy.hpp
# End Source File
# Begin Source File
SOURCE=..\..\..\..\boost\python\ptr.hpp
# End Source File
# Begin Source File
SOURCE=..\..\..\..\boost\python\refcount.hpp
# End Source File
# Begin Source File
SOURCE=..\..\..\..\boost\python\reference_existing_object.hpp
# End Source File
# Begin Source File
SOURCE=..\..\..\..\boost\python\return_internal_reference.hpp
# End Source File
# Begin Source File
SOURCE=..\..\..\..\boost\python\return_value_policy.hpp
# End Source File
# Begin Source File
SOURCE=..\..\..\..\boost\python\scope.hpp
# End Source File
# Begin Source File
SOURCE=..\..\..\..\boost\python\self.hpp
# End Source File
# Begin Source File
SOURCE=..\..\..\..\boost\python\signature.hpp
# End Source File
# Begin Source File
SOURCE=..\..\..\..\boost\python\slice_nil.hpp
# End Source File
# Begin Source File
SOURCE=..\..\..\..\boost\python\str.hpp
# End Source File
# Begin Source File
SOURCE=..\..\..\..\boost\python\tag.hpp
# End Source File
# Begin Source File
SOURCE=..\..\..\..\boost\python\to_python_converter.hpp
# End Source File
# Begin Source File
SOURCE=..\..\..\..\boost\python\to_python_indirect.hpp
# End Source File
# Begin Source File
SOURCE=..\..\..\..\boost\python\to_python_value.hpp
# End Source File
# Begin Source File
SOURCE=..\..\..\..\boost\python\tuple.hpp
# End Source File
# Begin Source File
SOURCE=..\..\..\..\boost\python\type_id.hpp
# End Source File
# Begin Source File
SOURCE=..\..\..\..\boost\python\with_custodian_and_ward.hpp
# End Source File
# End Group
# Begin Group "Resource Files"
# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe"
# End Group
# End Target
# End Project

View File

@@ -1,29 +0,0 @@
Microsoft Developer Studio Workspace File, Format Version 6.00
# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE!
###############################################################################
Project: "boost_python"=".\boost_python.dsp" - Package Owner=<4>
Package=<5>
{{{
}}}
Package=<4>
{{{
}}}
###############################################################################
Global:
Package=<5>
{{{
}}}
Package=<3>
{{{
}}}
###############################################################################

28
class.cpp Normal file
View File

@@ -0,0 +1,28 @@
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
#include <boost/python/module.hpp>
#include <boost/python/def.hpp>
#include <boost/python/object.hpp>
#include <boost/python/class.hpp>
using namespace boost::python;
struct X
{
int x;
X(int n) : x(n) { }
};
int x_function(X& x)
{ return x.x;
}
BOOST_PYTHON_MODULE(class_ext)
{
class_<X>("X", init<int>());
def("x_function", x_function);
}
#include "module_tail.cpp"

23
doc/Jamfile Normal file
View File

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

1147
doc/PyConDC_2003/bpl.html Executable file → Normal file

File diff suppressed because it is too large Load Diff

BIN
doc/PyConDC_2003/bpl.pdf Executable file → Normal file

Binary file not shown.

View File

@@ -1,947 +1,5 @@
+++++++++++++++++++++++++++++++++++++++++++
Building Hybrid Systems with Boost.Python
+++++++++++++++++++++++++++++++++++++++++++
.. Copyright David Abrahams 2006. Distributed under the Boost
.. Software License, Version 1.0. (See accompanying
.. file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
:Author: David Abrahams
:Contact: dave@boost-consulting.com
:organization: `Boost Consulting`_
:date: $Date$
:Author: Ralf W. Grosse-Kunstleve
:copyright: Copyright David Abrahams and Ralf W. Grosse-Kunstleve 2003. All rights reserved
.. contents:: Table of Contents
.. _`Boost Consulting`: http://www.boost-consulting.com
==========
Abstract
==========
Boost.Python is an open source C++ library which provides a concise
IDL-like interface for binding C++ classes and functions to
Python. Leveraging the full power of C++ compile-time introspection
and of recently developed metaprogramming techniques, this is achieved
entirely in pure C++, without introducing a new syntax.
Boost.Python's rich set of features and high-level interface make it
possible to engineer packages from the ground up as hybrid systems,
giving programmers easy and coherent access to both the efficient
compile-time polymorphism of C++ and the extremely convenient run-time
polymorphism of Python.
==============
Introduction
==============
Python and C++ are in many ways as different as two languages could
be: while C++ is usually compiled to machine-code, Python is
interpreted. Python's dynamic type system is often cited as the
foundation of its flexibility, while in C++ static typing is the
cornerstone of its efficiency. C++ has an intricate and difficult
compile-time meta-language, while in Python, practically everything
happens at runtime.
Yet for many programmers, these very differences mean that Python and
C++ complement one another perfectly. Performance bottlenecks in
Python programs can be rewritten in C++ for maximal speed, and
authors of powerful C++ libraries choose Python as a middleware
language for its flexible system integration capabilities.
Furthermore, the surface differences mask some strong similarities:
* 'C'-family control structures (if, while, for...)
* Support for object-orientation, functional programming, and generic
programming (these are both *multi-paradigm* programming languages.)
* Comprehensive operator overloading facilities, recognizing the
importance of syntactic variability for readability and
expressivity.
* High-level concepts such as collections and iterators.
* High-level encapsulation facilities (C++: namespaces, Python: modules)
to support the design of re-usable libraries.
* Exception-handling for effective management of error conditions.
* C++ idioms in common use, such as handle/body classes and
reference-counted smart pointers mirror Python reference semantics.
Given Python's rich 'C' interoperability API, it should in principle
be possible to expose C++ type and function interfaces to Python with
an analogous interface to their C++ counterparts. However, the
facilities provided by Python alone for integration with C++ are
relatively meager. Compared to C++ and Python, 'C' has only very
rudimentary abstraction facilities, and support for exception-handling
is completely missing. 'C' extension module writers are required to
manually manage Python reference counts, which is both annoyingly
tedious and extremely error-prone. Traditional extension modules also
tend to contain a great deal of boilerplate code repetition which
makes them difficult to maintain, especially when wrapping an evolving
API.
These limitations have lead to the development of a variety of wrapping
systems. SWIG_ is probably the most popular package for the
integration of C/C++ and Python. A more recent development is SIP_,
which was specifically designed for interfacing Python with the Qt_
graphical user interface library. Both SWIG and SIP introduce their
own specialized languages for customizing inter-language bindings.
This has certain advantages, but having to deal with three different
languages (Python, C/C++ and the interface language) also introduces
practical and mental difficulties. The CXX_ package demonstrates an
interesting alternative. It shows that at least some parts of
Python's 'C' API can be wrapped and presented through a much more
user-friendly C++ interface. However, unlike SWIG and SIP, CXX does
not include support for wrapping C++ classes as new Python types.
The features and goals of Boost.Python_ overlap significantly with
many of these other systems. That said, Boost.Python attempts to
maximize convenience and flexibility without introducing a separate
wrapping language. Instead, it presents the user with a high-level
C++ interface for wrapping C++ classes and functions, managing much of
the complexity behind-the-scenes with static metaprogramming.
Boost.Python also goes beyond the scope of earlier systems by
providing:
* Support for C++ virtual functions that can be overridden in Python.
* Comprehensive lifetime management facilities for low-level C++
pointers and references.
* Support for organizing extensions as Python packages,
with a central registry for inter-language type conversions.
* A safe and convenient mechanism for tying into Python's powerful
serialization engine (pickle).
* Coherence with the rules for handling C++ lvalues and rvalues that
can only come from a deep understanding of both the Python and C++
type systems.
The key insight that sparked the development of Boost.Python is that
much of the boilerplate code in traditional extension modules could be
eliminated using C++ compile-time introspection. Each argument of a
wrapped C++ function must be extracted from a Python object using a
procedure that depends on the argument type. Similarly the function's
return type determines how the return value will be converted from C++
to Python. Of course argument and return types are part of each
function's type, and this is exactly the source from which
Boost.Python deduces most of the information required.
This approach leads to *user guided wrapping*: as much information is
extracted directly from the source code to be wrapped as is possible
within the framework of pure C++, and some additional information is
supplied explicitly by the user. Mostly the guidance is mechanical
and little real intervention is required. Because the interface
specification is written in the same full-featured language as the
code being exposed, the user has unprecedented power available when
she does need to take control.
.. _Python: http://www.python.org/
.. _SWIG: http://www.swig.org/
.. _SIP: http://www.riverbankcomputing.co.uk/sip/index.php
.. _Qt: http://www.trolltech.com/
.. _CXX: http://cxx.sourceforge.net/
.. _Boost.Python: http://www.boost.org/libs/python/doc
===========================
Boost.Python Design Goals
===========================
The primary goal of Boost.Python is to allow users to expose C++
classes and functions to Python using nothing more than a C++
compiler. In broad strokes, the user experience should be one of
directly manipulating C++ objects from Python.
However, it's also important not to translate all interfaces *too*
literally: the idioms of each language must be respected. For
example, though C++ and Python both have an iterator concept, they are
expressed very differently. Boost.Python has to be able to bridge the
interface gap.
It must be possible to insulate Python users from crashes resulting
from trivial misuses of C++ interfaces, such as accessing
already-deleted objects. By the same token the library should
insulate C++ users from low-level Python 'C' API, replacing
error-prone 'C' interfaces like manual reference-count management and
raw ``PyObject`` pointers with more-robust alternatives.
Support for component-based development is crucial, so that C++ types
exposed in one extension module can be passed to functions exposed in
another without loss of crucial information like C++ inheritance
relationships.
Finally, all wrapping must be *non-intrusive*, without modifying or
even seeing the original C++ source code. Existing C++ libraries have
to be wrappable by third parties who only have access to header files
and binaries.
==========================
Hello Boost.Python World
==========================
And now for a preview of Boost.Python, and how it improves on the raw
facilities offered by Python. Here's a function we might want to
expose::
char const* greet(unsigned x)
{
static char const* const msgs[] = { "hello", "Boost.Python", "world!" };
if (x > 2)
throw std::range_error("greet: index out of range");
return msgs[x];
}
To wrap this function in standard C++ using the Python 'C' API, we'd
need something like this::
extern "C" // all Python interactions use 'C' linkage and calling convention
{
// Wrapper to handle argument/result conversion and checking
PyObject* greet_wrap(PyObject* args, PyObject * keywords)
{
int x;
if (PyArg_ParseTuple(args, "i", &x)) // extract/check arguments
{
char const* result = greet(x); // invoke wrapped function
return PyString_FromString(result); // convert result to Python
}
return 0; // error occurred
}
// Table of wrapped functions to be exposed by the module
static PyMethodDef methods[] = {
{ "greet", greet_wrap, METH_VARARGS, "return one of 3 parts of a greeting" }
, { NULL, NULL, 0, NULL } // sentinel
};
// module initialization function
DL_EXPORT init_hello()
{
(void) Py_InitModule("hello", methods); // add the methods to the module
}
}
Now here's the wrapping code we'd use to expose it with Boost.Python::
#include <boost/python.hpp>
using namespace boost::python;
BOOST_PYTHON_MODULE(hello)
{
def("greet", greet, "return one of 3 parts of a greeting");
}
and here it is in action::
>>> import hello
>>> for x in range(3):
... print hello.greet(x)
...
hello
Boost.Python
world!
Aside from the fact that the 'C' API version is much more verbose,
it's worth noting a few things that it doesn't handle correctly:
* The original function accepts an unsigned integer, and the Python
'C' API only gives us a way of extracting signed integers. The
Boost.Python version will raise a Python exception if we try to pass
a negative number to ``hello.greet``, but the other one will proceed
to do whatever the C++ implementation does when converting an
negative integer to unsigned (usually wrapping to some very large
number), and pass the incorrect translation on to the wrapped
function.
* That brings us to the second problem: if the C++ ``greet()``
function is called with a number greater than 2, it will throw an
exception. Typically, if a C++ exception propagates across the
boundary with code generated by a 'C' compiler, it will cause a
crash. As you can see in the first version, there's no C++
scaffolding there to prevent this from happening. Functions wrapped
by Boost.Python automatically include an exception-handling layer
which protects Python users by translating unhandled C++ exceptions
into a corresponding Python exception.
* A slightly more-subtle limitation is that the argument conversion
used in the Python 'C' API case can only get that integer ``x`` in
*one way*. PyArg_ParseTuple can't convert Python ``long`` objects
(arbitrary-precision integers) which happen to fit in an ``unsigned
int`` but not in a ``signed long``, nor will it ever handle a
wrapped C++ class with a user-defined implicit ``operator unsigned
int()`` conversion. Boost.Python's dynamic type conversion
registry allows users to add arbitrary conversion methods.
==================
Library Overview
==================
This section outlines some of the library's major features. Except as
neccessary to avoid confusion, details of library implementation are
omitted.
------------------
Exposing Classes
------------------
C++ classes and structs are exposed with a similarly-terse interface.
Given::
struct World
{
void set(std::string msg) { this->msg = msg; }
std::string greet() { return msg; }
std::string msg;
};
The following code will expose it in our extension module::
#include <boost/python.hpp>
BOOST_PYTHON_MODULE(hello)
{
class_<World>("World")
.def("greet", &World::greet)
.def("set", &World::set)
;
}
Although this code has a certain pythonic familiarity, people
sometimes find the syntax bit confusing because it doesn't look like
most of the C++ code they're used to. All the same, this is just
standard C++. Because of their flexible syntax and operator
overloading, C++ and Python are great for defining domain-specific
(sub)languages
(DSLs), and that's what we've done in Boost.Python. To break it down::
class_<World>("World")
constructs an unnamed object of type ``class_<World>`` and passes
``"World"`` to its constructor. This creates a new-style Python class
called ``World`` in the extension module, and associates it with the
C++ type ``World`` in the Boost.Python type conversion registry. We
might have also written::
class_<World> w("World");
but that would've been more verbose, since we'd have to name ``w``
again to invoke its ``def()`` member function::
w.def("greet", &World::greet)
There's nothing special about the location of the dot for member
access in the original example: C++ allows any amount of whitespace on
either side of a token, and placing the dot at the beginning of each
line allows us to chain as many successive calls to member functions
as we like with a uniform syntax. The other key fact that allows
chaining is that ``class_<>`` member functions all return a reference
to ``*this``.
So the example is equivalent to::
class_<World> w("World");
w.def("greet", &World::greet);
w.def("set", &World::set);
It's occasionally useful to be able to break down the components of a
Boost.Python class wrapper in this way, but the rest of this article
will stick to the terse syntax.
For completeness, here's the wrapped class in use: ::
>>> import hello
>>> planet = hello.World()
>>> planet.set('howdy')
>>> planet.greet()
'howdy'
Constructors
============
Since our ``World`` class is just a plain ``struct``, it has an
implicit no-argument (nullary) constructor. Boost.Python exposes the
nullary constructor by default, which is why we were able to write: ::
>>> planet = hello.World()
However, well-designed classes in any language may require constructor
arguments in order to establish their invariants. Unlike Python,
where ``__init__`` is just a specially-named method, In C++
constructors cannot be handled like ordinary member functions. In
particular, we can't take their address: ``&World::World`` is an
error. The library provides a different interface for specifying
constructors. Given::
struct World
{
World(std::string msg); // added constructor
...
we can modify our wrapping code as follows::
class_<World>("World", init<std::string>())
...
of course, a C++ class may have additional constructors, and we can
expose those as well by passing more instances of ``init<...>`` to
``def()``::
class_<World>("World", init<std::string>())
.def(init<double, double>())
...
Boost.Python allows wrapped functions, member functions, and
constructors to be overloaded to mirror C++ overloading.
Data Members and Properties
===========================
Any publicly-accessible data members in a C++ class can be easily
exposed as either ``readonly`` or ``readwrite`` attributes::
class_<World>("World", init<std::string>())
.def_readonly("msg", &World::msg)
...
and can be used directly in Python: ::
>>> planet = hello.World('howdy')
>>> planet.msg
'howdy'
This does *not* result in adding attributes to the ``World`` instance
``__dict__``, which can result in substantial memory savings when
wrapping large data structures. In fact, no instance ``__dict__``
will be created at all unless attributes are explicitly added from
Python. Boost.Python owes this capability to the new Python 2.2 type
system, in particular the descriptor interface and ``property`` type.
In C++, publicly-accessible data members are considered a sign of poor
design because they break encapsulation, and style guides usually
dictate the use of "getter" and "setter" functions instead. In
Python, however, ``__getattr__``, ``__setattr__``, and since 2.2,
``property`` mean that attribute access is just one more
well-encapsulated syntactic tool at the programmer's disposal.
Boost.Python bridges this idiomatic gap by making Python ``property``
creation directly available to users. If ``msg`` were private, we
could still expose it as attribute in Python as follows::
class_<World>("World", init<std::string>())
.add_property("msg", &World::greet, &World::set)
...
The example above mirrors the familiar usage of properties in Python
2.2+: ::
>>> class World(object):
... __init__(self, msg):
... self.__msg = msg
... def greet(self):
... return self.__msg
... def set(self, msg):
... self.__msg = msg
... msg = property(greet, set)
Operator Overloading
====================
The ability to write arithmetic operators for user-defined types has
been a major factor in the success of both languages for numerical
computation, and the success of packages like NumPy_ attests to the
power of exposing operators in extension modules. Boost.Python
provides a concise mechanism for wrapping operator overloads. The
example below shows a fragment from a wrapper for the Boost rational
number library::
class_<rational<int> >("rational_int")
.def(init<int, int>()) // constructor, e.g. rational_int(3,4)
.def("numerator", &rational<int>::numerator)
.def("denominator", &rational<int>::denominator)
.def(-self) // __neg__ (unary minus)
.def(self + self) // __add__ (homogeneous)
.def(self * self) // __mul__
.def(self + int()) // __add__ (heterogenous)
.def(int() + self) // __radd__
...
The magic is performed using a simplified application of "expression
templates" [VELD1995]_, a technique originally developed for
optimization of high-performance matrix algebra expressions. The
essence is that instead of performing the computation immediately,
operators are overloaded to construct a type *representing* the
computation. In matrix algebra, dramatic optimizations are often
available when the structure of an entire expression can be taken into
account, rather than evaluating each operation "greedily".
Boost.Python uses the same technique to build an appropriate Python
method object based on expressions involving ``self``.
.. _NumPy: http://www.pfdubois.com/numpy/
Inheritance
===========
C++ inheritance relationships can be represented to Boost.Python by adding
an optional ``bases<...>`` argument to the ``class_<...>`` template
parameter list as follows::
class_<Derived, bases<Base1,Base2> >("Derived")
...
This has two effects:
1. When the ``class_<...>`` is created, Python type objects
corresponding to ``Base1`` and ``Base2`` are looked up in
Boost.Python's registry, and are used as bases for the new Python
``Derived`` type object, so methods exposed for the Python ``Base1``
and ``Base2`` types are automatically members of the ``Derived``
type. Because the registry is global, this works correctly even if
``Derived`` is exposed in a different module from either of its
bases.
2. C++ conversions from ``Derived`` to its bases are added to the
Boost.Python registry. Thus wrapped C++ methods expecting (a
pointer or reference to) an object of either base type can be
called with an object wrapping a ``Derived`` instance. Wrapped
member functions of class ``T`` are treated as though they have an
implicit first argument of ``T&``, so these conversions are
neccessary to allow the base class methods to be called for derived
objects.
Of course it's possible to derive new Python classes from wrapped C++
class instances. Because Boost.Python uses the new-style class
system, that works very much as for the Python built-in types. There
is one significant detail in which it differs: the built-in types
generally establish their invariants in their ``__new__`` function, so
that derived classes do not need to call ``__init__`` on the base
class before invoking its methods : ::
>>> class L(list):
... def __init__(self):
... pass
...
>>> L().reverse()
>>>
Because C++ object construction is a one-step operation, C++ instance
data cannot be constructed until the arguments are available, in the
``__init__`` function: ::
>>> class D(SomeBoostPythonClass):
... def __init__(self):
... pass
...
>>> D().some_boost_python_method()
Traceback (most recent call last):
File "<stdin>", line 1, in ?
TypeError: bad argument type for built-in operation
This happened because Boost.Python couldn't find instance data of type
``SomeBoostPythonClass`` within the ``D`` instance; ``D``'s ``__init__``
function masked construction of the base class. It could be corrected
by either removing ``D``'s ``__init__`` function or having it call
``SomeBoostPythonClass.__init__(...)`` explicitly.
Virtual Functions
=================
Deriving new types in Python from extension classes is not very
interesting unless they can be used polymorphically from C++. In
other words, Python method implementations should appear to override
the implementation of C++ virtual functions when called *through base
class pointers/references from C++*. Since the only way to alter the
behavior of a virtual function is to override it in a derived class,
the user must build a special derived class to dispatch a polymorphic
class' virtual functions::
//
// interface to wrap:
//
class Base
{
public:
virtual int f(std::string x) { return 42; }
virtual ~Base();
};
int calls_f(Base const& b, std::string x) { return b.f(x); }
//
// Wrapping Code
//
// Dispatcher class
struct BaseWrap : Base
{
// Store a pointer to the Python object
BaseWrap(PyObject* self_) : self(self_) {}
PyObject* self;
// Default implementation, for when f is not overridden
int f_default(std::string x) { return this->Base::f(x); }
// Dispatch implementation
int f(std::string x) { return call_method<int>(self, "f", x); }
};
...
def("calls_f", calls_f);
class_<Base, BaseWrap>("Base")
.def("f", &Base::f, &BaseWrap::f_default)
;
Now here's some Python code which demonstrates: ::
>>> class Derived(Base):
... def f(self, s):
... return len(s)
...
>>> calls_f(Base(), 'foo')
42
>>> calls_f(Derived(), 'forty-two')
9
Things to notice about the dispatcher class:
* The key element which allows overriding in Python is the
``call_method`` invocation, which uses the same global type
conversion registry as the C++ function wrapping does to convert its
arguments from C++ to Python and its return type from Python to C++.
* Any constructor signatures you wish to wrap must be replicated with
an initial ``PyObject*`` argument
* The dispatcher must store this argument so that it can be used to
invoke ``call_method``
* The ``f_default`` member function is needed when the function being
exposed is not pure virtual; there's no other way ``Base::f`` can be
called on an object of type ``BaseWrap``, since it overrides ``f``.
Deeper Reflection on the Horizon?
=================================
Admittedly, this formula is tedious to repeat, especially on a project
with many polymorphic classes. That it is neccessary reflects some
limitations in C++'s compile-time introspection capabilities: there's
no way to enumerate the members of a class and find out which are
virtual functions. At least one very promising project has been
started to write a front-end which can generate these dispatchers (and
other wrapping code) automatically from C++ headers.
Pyste_ is being developed by Bruno da Silva de Oliveira. It builds on
GCC_XML_, which generates an XML version of GCC's internal program
representation. Since GCC is a highly-conformant C++ compiler, this
ensures correct handling of the most-sophisticated template code and
full access to the underlying type system. In keeping with the
Boost.Python philosophy, a Pyste interface description is neither
intrusive on the code being wrapped, nor expressed in some unfamiliar
language: instead it is a 100% pure Python script. If Pyste is
successful it will mark a move away from wrapping everything directly
in C++ for many of our users. It will also allow us the choice to
shift some of the metaprogram code from C++ to Python. We expect that
soon, not only our users but the Boost.Python developers themselves
will be "thinking hybrid" about their own code.
.. _`GCC_XML`: http://www.gccxml.org/HTML/Index.html
.. _`Pyste`: http://www.boost.org/libs/python/pyste
---------------
Serialization
---------------
*Serialization* is the process of converting objects in memory to a
form that can be stored on disk or sent over a network connection. The
serialized object (most often a plain string) can be retrieved and
converted back to the original object. A good serialization system will
automatically convert entire object hierarchies. Python's standard
``pickle`` module is just such a system. It leverages the language's strong
runtime introspection facilities for serializing practically arbitrary
user-defined objects. With a few simple and unintrusive provisions this
powerful machinery can be extended to also work for wrapped C++ objects.
Here is an example::
#include <string>
struct World
{
World(std::string a_msg) : msg(a_msg) {}
std::string greet() const { return msg; }
std::string msg;
};
#include <boost/python.hpp>
using namespace boost::python;
struct World_picklers : pickle_suite
{
static tuple
getinitargs(World const& w) { return make_tuple(w.greet()); }
};
BOOST_PYTHON_MODULE(hello)
{
class_<World>("World", init<std::string>())
.def("greet", &World::greet)
.def_pickle(World_picklers())
;
}
Now let's create a ``World`` object and put it to rest on disk::
>>> import hello
>>> import pickle
>>> a_world = hello.World("howdy")
>>> pickle.dump(a_world, open("my_world", "w"))
In a potentially *different script* on a potentially *different
computer* with a potentially *different operating system*::
>>> import pickle
>>> resurrected_world = pickle.load(open("my_world", "r"))
>>> resurrected_world.greet()
'howdy'
Of course the ``cPickle`` module can also be used for faster
processing.
Boost.Python's ``pickle_suite`` fully supports the ``pickle`` protocol
defined in the standard Python documentation. Like a __getinitargs__
function in Python, the pickle_suite's getinitargs() is responsible for
creating the argument tuple that will be use to reconstruct the pickled
object. The other elements of the Python pickling protocol,
__getstate__ and __setstate__ can be optionally provided via C++
getstate and setstate functions. C++'s static type system allows the
library to ensure at compile-time that nonsensical combinations of
functions (e.g. getstate without setstate) are not used.
Enabling serialization of more complex C++ objects requires a little
more work than is shown in the example above. Fortunately the
``object`` interface (see next section) greatly helps in keeping the
code manageable.
------------------
Object interface
------------------
Experienced 'C' language extension module authors will be familiar
with the ubiquitous ``PyObject*``, manual reference-counting, and the
need to remember which API calls return "new" (owned) references or
"borrowed" (raw) references. These constraints are not just
cumbersome but also a major source of errors, especially in the
presence of exceptions.
Boost.Python provides a class ``object`` which automates reference
counting and provides conversion to Python from C++ objects of
arbitrary type. This significantly reduces the learning effort for
prospective extension module writers.
Creating an ``object`` from any other type is extremely simple::
object s("hello, world"); // s manages a Python string
``object`` has templated interactions with all other types, with
automatic to-python conversions. It happens so naturally that it's
easily overlooked::
object ten_Os = 10 * s[4]; // -> "oooooooooo"
In the example above, ``4`` and ``10`` are converted to Python objects
before the indexing and multiplication operations are invoked.
The ``extract<T>`` class template can be used to convert Python objects
to C++ types::
double x = extract<double>(o);
If a conversion in either direction cannot be performed, an
appropriate exception is thrown at runtime.
The ``object`` type is accompanied by a set of derived types
that mirror the Python built-in types such as ``list``, ``dict``,
``tuple``, etc. as much as possible. This enables convenient
manipulation of these high-level types from C++::
dict d;
d["some"] = "thing";
d["lucky_number"] = 13;
list l = d.keys();
This almost looks and works like regular Python code, but it is pure
C++. Of course we can wrap C++ functions which accept or return
``object`` instances.
=================
Thinking hybrid
=================
Because of the practical and mental difficulties of combining
programming languages, it is common to settle a single language at the
outset of any development effort. For many applications, performance
considerations dictate the use of a compiled language for the core
algorithms. Unfortunately, due to the complexity of the static type
system, the price we pay for runtime performance is often a
significant increase in development time. Experience shows that
writing maintainable C++ code usually takes longer and requires *far*
more hard-earned working experience than developing comparable Python
code. Even when developers are comfortable working exclusively in
compiled languages, they often augment their systems by some type of
ad hoc scripting layer for the benefit of their users without ever
availing themselves of the same advantages.
Boost.Python enables us to *think hybrid*. Python can be used for
rapidly prototyping a new application; its ease of use and the large
pool of standard libraries give us a head start on the way to a
working system. If necessary, the working code can be used to
discover rate-limiting hotspots. To maximize performance these can
be reimplemented in C++, together with the Boost.Python bindings
needed to tie them back into the existing higher-level procedure.
Of course, this *top-down* approach is less attractive if it is clear
from the start that many algorithms will eventually have to be
implemented in C++. Fortunately Boost.Python also enables us to
pursue a *bottom-up* approach. We have used this approach very
successfully in the development of a toolbox for scientific
applications. The toolbox started out mainly as a library of C++
classes with Boost.Python bindings, and for a while the growth was
mainly concentrated on the C++ parts. However, as the toolbox is
becoming more complete, more and more newly added functionality can be
implemented in Python.
.. image:: python_cpp_mix.jpg
This figure shows the estimated ratio of newly added C++ and Python
code over time as new algorithms are implemented. We expect this
ratio to level out near 70% Python. Being able to solve new problems
mostly in Python rather than a more difficult statically typed
language is the return on our investment in Boost.Python. The ability
to access all of our code from Python allows a broader group of
developers to use it in the rapid development of new applications.
=====================
Development history
=====================
The first version of Boost.Python was developed in 2000 by Dave
Abrahams at Dragon Systems, where he was privileged to have Tim Peters
as a guide to "The Zen of Python". One of Dave's jobs was to develop
a Python-based natural language processing system. Since it was
eventually going to be targeting embedded hardware, it was always
assumed that the compute-intensive core would be rewritten in C++ to
optimize speed and memory footprint [#proto]_. The project also wanted to
test all of its C++ code using Python test scripts [#test]_. The only
tool we knew of for binding C++ and Python was SWIG_, and at the time
its handling of C++ was weak. It would be false to claim any deep
insight into the possible advantages of Boost.Python's approach at
this point. Dave's interest and expertise in fancy C++ template
tricks had just reached the point where he could do some real damage,
and Boost.Python emerged as it did because it filled a need and
because it seemed like a cool thing to try.
This early version was aimed at many of the same basic goals we've
described in this paper, differing most-noticeably by having a
slightly more cumbersome syntax and by lack of special support for
operator overloading, pickling, and component-based development.
These last three features were quickly added by Ullrich Koethe and
Ralf Grosse-Kunstleve [#feature]_, and other enthusiastic contributors arrived
on the scene to contribute enhancements like support for nested
modules and static member functions.
By early 2001 development had stabilized and few new features were
being added, however a disturbing new fact came to light: Ralf had
begun testing Boost.Python on pre-release versions of a compiler using
the EDG_ front-end, and the mechanism at the core of Boost.Python
responsible for handling conversions between Python and C++ types was
failing to compile. As it turned out, we had been exploiting a very
common bug in the implementation of all the C++ compilers we had
tested. We knew that as C++ compilers rapidly became more
standards-compliant, the library would begin failing on more
platforms. Unfortunately, because the mechanism was so central to the
functioning of the library, fixing the problem looked very difficult.
Fortunately, later that year Lawrence Berkeley and later Lawrence
Livermore National labs contracted with `Boost Consulting`_ for support
and development of Boost.Python, and there was a new opportunity to
address fundamental issues and ensure a future for the library. A
redesign effort began with the low level type conversion architecture,
building in standards-compliance and support for component-based
development (in contrast to version 1 where conversions had to be
explicitly imported and exported across module boundaries). A new
analysis of the relationship between the Python and C++ objects was
done, resulting in more intuitive handling for C++ lvalues and
rvalues.
The emergence of a powerful new type system in Python 2.2 made the
choice of whether to maintain compatibility with Python 1.5.2 easy:
the opportunity to throw away a great deal of elaborate code for
emulating classic Python classes alone was too good to pass up. In
addition, Python iterators and descriptors provided crucial and
elegant tools for representing similar C++ constructs. The
development of the generalized ``object`` interface allowed us to
further shield C++ programmers from the dangers and syntactic burdens
of the Python 'C' API. A great number of other features including C++
exception translation, improved support for overloaded functions, and
most significantly, CallPolicies for handling pointers and
references, were added during this period.
In October 2002, version 2 of Boost.Python was released. Development
since then has concentrated on improved support for C++ runtime
polymorphism and smart pointers. Peter Dimov's ingenious
``boost::shared_ptr`` design in particular has allowed us to give the
hybrid developer a consistent interface for moving objects back and
forth across the language barrier without loss of information. At
first, we were concerned that the sophistication and complexity of the
Boost.Python v2 implementation might discourage contributors, but the
emergence of Pyste_ and several other significant feature
contributions have laid those fears to rest. Daily questions on the
Python C++-sig and a backlog of desired improvements show that the
library is getting used. To us, the future looks bright.
.. _`EDG`: http://www.edg.com
=============
Conclusions
=============
Boost.Python achieves seamless interoperability between two rich and
complimentary language environments. Because it leverages template
metaprogramming to introspect about types and functions, the user
never has to learn a third syntax: the interface definitions are
written in concise and maintainable C++. Also, the wrapping system
doesn't have to parse C++ headers or represent the type system: the
compiler does that work for us.
Computationally intensive tasks play to the strengths of C++ and are
often impossible to implement efficiently in pure Python, while jobs
like serialization that are trivial in Python can be very difficult in
pure C++. Given the luxury of building a hybrid software system from
the ground up, we can approach design with new confidence and power.
===========
Citations
===========
.. [VELD1995] T. Veldhuizen, "Expression Templates," C++ Report,
Vol. 7 No. 5 June 1995, pp. 26-31.
http://osl.iu.edu/~tveldhui/papers/Expression-Templates/exprtmpl.html
===========
Footnotes
===========
.. [#proto] In retrospect, it seems that "thinking hybrid" from the
ground up might have been better for the NLP system: the
natural component boundaries defined by the pure python
prototype turned out to be inappropriate for getting the
desired performance and memory footprint out of the C++ core,
which eventually caused some redesign overhead on the Python
side when the core was moved to C++.
.. [#test] We also have some reservations about driving all C++
testing through a Python interface, unless that's the only way
it will be ultimately used. Any transition across language
boundaries with such different object models can inevitably
mask bugs.
.. [#feature] These features were expressed very differently in v1 of
Boost.Python
This file has been moved to http://www.boost-consulting.com/writing/bpl.txt.

View File

@@ -1,3 +1,7 @@
Copyright David Abrahams 2006. Distributed under the Boost
Software License, Version 1.0. (See accompanying
file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
.. This is a comment. Note how any initial comments are moved by
transforms to after the document title, subtitle, and docinfo.
@@ -23,7 +27,6 @@
Somerville, MA 02143
:Contact: dave@boost-consulting.com
:organization: `Boost Consulting`_
:date: $Date$
:status: This is a "work in progress"
:version: 1
:copyright: Copyright David Abrahams 2002. All rights reserved
@@ -273,7 +276,7 @@ correctly:
==================
This section outlines some of the library's major features. Except as
neccessary to avoid confusion, details of library implementation are
necessary to avoid confusion, details of library implementation are
omitted.
-------------------------------------------
@@ -537,7 +540,7 @@ This has two effects:
called with an object wrapping a ``Derived`` instance. Wrapped
member functions of class ``T`` are treated as though they have an
implicit first argument of ``T&``, so these conversions are
neccessary to allow the base class methods to be called for derived
necessary to allow the base class methods to be called for derived
objects.
Of course it's possible to derive new Python classes from wrapped C++
@@ -650,7 +653,7 @@ Things to notice about the dispatcher class:
called on an object of type ``BaseWrap``, since it overrides ``f``.
Admittedly, this formula is tedious to repeat, especially on a project
with many polymorphic classes; that it is neccessary reflects
with many polymorphic classes; that it is necessary reflects
limitations in C++'s compile-time reflection capabilities. Several
efforts are underway to write front-ends for Boost.Python which can
generate these dispatchers (and other wrapping code) automatically.

View File

@@ -1,10 +1,10 @@
/*
:Author: David Goodger
:Contact: goodger@users.sourceforge.net
:date: $Date$
:version: $Revision$
:copyright: This stylesheet has been placed in the public domain.
boostinspect:nolicense
Default cascading style sheet for the HTML output of Docutils.
*/

0
doc/PyConDC_2003/python_cpp_mix.jpg Executable file → Normal file
View File

Before

Width:  |  Height:  |  Size: 22 KiB

After

Width:  |  Height:  |  Size: 22 KiB

0
doc/PyConDC_2003/python_cpp_mix.png Executable file → Normal file
View File

Before

Width:  |  Height:  |  Size: 6.1 KiB

After

Width:  |  Height:  |  Size: 6.1 KiB

View File

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

File diff suppressed because it is too large Load Diff

680
doc/building.rst Normal file
View File

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

View File

@@ -1,11 +1,14 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<!-- Copyright David Abrahams 2006. Distributed under the Boost -->
<!-- Software License, Version 1.0. (See accompanying -->
<!-- file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -->
<html>
<head>
<meta name="generator" content=
"HTML Tidy for Windows (vers 1st August 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">
<link rel="stylesheet" type="text/css" href="../../../boost.css">
<title>Boost.Python</title>
</head>
@@ -16,7 +19,7 @@
<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>
"C++ Boost" src="../../../boost.png" border="0"></a></h3>
</td>
<td valign="top">
@@ -24,10 +27,60 @@
<h2 align="center">Index</h2>
</td>
<td align="right">
<form method="get" action="http://www.google.com/custom">
<p>
<span id= "search-choice">
Search
<select name="hq" id="hq">
<option label="All Documentation" value=
"site:www.boost.org inurl:www.boost.org/libs/python/doc">
All Documentation
</option>
<option label="Tutorial" value=
"site:www.boost.org inurl:www.boost.org/libs/python/doc/tutorial">
Tutorial
</option>
<option label="Reference" value=
"site:www.boost.org inurl:www.boost.org/libs/python/doc/v2">
Reference
</option>
</select>
<br>
</span>
<span id="search-text">
<input type="text" name="q" id="q" size="31" maxlength="255" alt="Search Text" />
</span>
<br>
<span id= "google">
<a href= "http://www.google.com/search">
<img src="../../../more/google_logo_25wht.gif" alt="Google" border="0" /></a>Powered
</span>
<span id="go">
<input type="image" name="search" src="../../../more/space.gif" alt="Search" id="search-button" />
</span>
<br>
<input type="hidden" name="cof" value= "LW:277;L:http://www.boost.org/boost.png;LH:86;AH:center;GL:0;S:http://www.boost.org;AWFID:9b83d16ce652ed5a;" />
<input type="hidden" name="sa" value= "Google Search" />
<input type="hidden" name= "domains" value= "www.boost.org;mail.python.org" /></p>
</form>
</td>
</tr>
<tr>
</tr>
</table>
<hr>
<h2>Synopsis</h2>
Welcome to version 2 of <b>Boost.Python</b>, a C++ library which enables
seamless interoperability between C++ and the <a href=
@@ -73,6 +126,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
@@ -86,11 +147,17 @@
<dt><a href="v2/faq.html">Frequently Asked Questions (FAQs)</a></dt>
<dt><a href="../pyste/index.html">Pyste (Boost.Python code generator)</a></dt>
<dt><a href="http://www.language-binding.net/pyplusplus/pyplusplus.html">Py++ Boost.Python code generator</a></dt>
<dt><a href="../pyste/index.html">Pyste Boost.Python code generator (no longer maintained)</a></dt>
<dt><a href="internals.html">Internals Documentation</a></dt>
<dt><a href="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/progress_reports.html">LLNL Progress Reports</a></dt>
<dt><a href="v2/acknowledgments.html">Acknowledgments</a></dt>
</dl>
@@ -106,12 +173,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="http://www.boost.org/people/dave_abrahams.htm">Dave
Abrahams</a> 2002-2003.</i></p>
</body>
</html>

186
doc/internals.html Normal 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="../../../boost.png" /></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>

182
doc/internals.rst Normal file
View File

@@ -0,0 +1,182 @@
===================================
Boost.Python_ Internals |(logo)|__
===================================
.. |(logo)| image:: ../../../boost.png
:alt: Boost
:class: boost-logo
__ ../../../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

@@ -1,328 +0,0 @@
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>A New Type Conversion Mechanism for Boost.Python</title>
</head>
<body bgcolor="#FFFFFF" text="#000000">
<p><img border="0" src="../../../c++boost.gif" width="277" height="86"
alt="boost logo"></p>
<h1>A New Type Conversion Mechanism for Boost.Python</h1>
<p>By <a href="../../../people/dave_abrahams.htm">David Abrahams</a>.
<h2>Introduction</h2>
This document describes a redesign of the mechanism for automatically
converting objects between C++ and Python. The current implementation
uses two functions for any type <tt>T</tt>:
<blockquote><pre>
U from_python(PyObject*, type&lt;T&gt;);
void to_python(V);
</pre></blockquote>
where U is convertible to T and T is convertible to V. These functions
are at the heart of C++/Python interoperability in Boost.Python, so
why would we want to change them? There are many reasons:
<h3>Bugs</h3>
<p>Firstly, the current mechanism relies on a common C++ compiler
bug. This is not just embarrassing: as compilers get to be more
conformant, the library stops working. The issue, in detail, is the
use of inline friend functions in templates to generate
conversions. It is a very powerful, and legal technique as long as
it's used correctly:
<blockquote><pre>
template &lt;class Derived&gt;
struct add_some_functions
{
friend <i>return-type</i> some_function1(..., Derived <i>cv-*-&amp;-opt</i>, ...);
friend <i>return-type</i> some_function2(..., Derived <i>cv-*-&amp;-opt</i>, ...);
};
template &lt;class T&gt;
struct some_template : add_some_functions&lt;some_template&lt;T&gt; &gt;
{
};
</pre></blockquote>
The <tt>add_some_functions</tt> template generates free functions
which operate on <tt>Derived</tt>, or on related types. Strictly
speaking the related types are not just cv-qualified <tt>Derived</tt>
values, pointers and/or references. Section 3.4.2 in the standard
describes exactly which types you must use as parameters to these
functions if you want the functions to be found
(there is also a less-technical description in section 11.5.1 of
C++PL3 <a href="#ref_1">[1]</a>). Suffice it to say that
with the current design, the <tt>from_python</tt> and
<tt>to_python</tt> functions are not supposed to be callable under any
conditions!
<h3>Compilation and Linking Time</h3>
The conversion functions generated for each wrapped class using the
above technique are not function templates, but regular functions. The
upshot is that they must <i>all</i> be generated regardless of whether
they are actually used. Generating all of those functions can slow
down module compilation, and resolving the references can slow down
linking.
<h3>Efficiency</h3>
The conversion functions are primarily used in (member) function
wrappers to convert the arguments and return values. Being functions,
converters have no interface which allows us to ask &quot;will the
conversion succeed?&quot; without calling the function. Since the
return value of the function must be the object to be passed as an
argument, Boost.Python currently uses C++ exception-handling to detect
an unsuccessful conversion. It's not a particularly good use of
exception-handling, since the failure is not handled very far from
where it occurred. More importantly, it means that C++ exceptions are
thrown during overload resolution as we seek an overload that matches
the arguments passed. Depending on the implementation, this approach
can result in significant slowdowns.
<p>It is also unclear that the current library generates a minimal
amount of code for any type conversion. Many of the conversion
functions are nontrivial, and partly because of compiler limitations,
they are declared <tt>inline</tt>. Also, we could have done a better
job separating the type-specific conversion code from the code which
is type-independent.
<h3>Cross-module Support</h3>
The current strategy requires every module to contain the definition
of conversions it uses. In general, a new module can never supply
conversion code which is used by another module. Ralf Grosse-Kunstleve
designed a clever system which imports conversions directly from one
library into another using some explicit declarations, but it has some
disadvantages also:
<ol>
<li>The system Ullrich Koethe designed for implicit conversion between
wrapped classes related through inheritance does not currently work if
the classes are defined in separate modules.
<li>The writer of the importing module is required to know the name of
the module supplying the imported conversions.
<li>There can be only one way to extract any given C++ type from a
Python object in a given module.
</ol>
The first item might be addressed by moving Boost.Python into a shared
library, but the other two cannot. Ralf turned the limitation in item
two into a feature: the required module is loaded implicitly when a
conversion it defines is invoked. We will probably want to provide
that functionality anyway, but it's not clear that we should require
the declaration of all such conversions. The final item is a more
serious limitation. If, for example, new numeric types are defined in
separate modules, and these types can all be converted to
<tt>double</tt>s, we have to choose just one conversion method.
<h3>Ease-of-use</h3>
One persistent source of confusion for users of Boost.Python has been
the fact that conversions for a class are not be visible at
compile-time until the declaration of that class has been seen. When
the user tries to expose a (member) function operating on or returning
an instance of the class in question, compilation fails...even though
the user goes on to expose the class in the same translation unit!
<p>
The new system lifts all compile-time checks for the existence of
particular type conversions and replaces them with runtime checks, in
true Pythonic style. While this might seem cavalier, the compile-time
checks are actually not much use in the current system if many classes
are wrapped in separate modules, since the checks are based only on
the user's declaration that the conversions exist.
<h2>The New Design</h2>
<h3>Motivation</h3>
The new design was heavily influenced by a desire to generate as
little code as possible in extension modules. Some of Boost.Python's
clients are enormous projects where link time is proportional to the
amount of object code, and there are many Python extension modules. As
such, we try to keep type-specific conversion code out of modules
other than the one the converters are defined in, and rely as much as
possible on centralized control through a shared library.
<h3>The Basics</h3>
The library contains a <tt>registry</tt> which maps runtime type
identifiers (actually an extension of <tt>std::type_info</tt> which
preserves references and constness) to entries containing type
converters. An <tt>entry</tt> can contain only one converter from C++ to Python
(<tt>wrapper</tt>), but many converters from Python to C++
(<tt>unwrapper</tt>s). <font color="#ff0000">What should happen if
multiple modules try to register wrappers for the same type?</font>. Wrappers
and unwrappers are known as <tt>body</tt> objects, and are accessed
by the user and the library (in its function-wrapping code) through
corresponding <tt>handle</tt> (<tt>wrap&lt;T&gt;</tt> and
<tt>unwrap&lt;T&gt;</tt>) objects. The <tt>handle</tt> objects are
extremely lightweight, and delegate <i>all</i> of their operations to
the corresponding <tt>body</tt>.
<p>
When a <tt>handle</tt> object is constructed, it accesses the
registry to find a corresponding <tt>body</tt> that can convert the
handle's constructor argument. Actually the registry record for any
type
<tt>T</tt>used in a module is looked up only once and stored in a
static <tt>registration&lt;T&gt;</tt> object for efficiency. For
example, if the handle is an <tt>unwrap&lt;Foo&amp;&gt;</tt> object,
the <tt>entry</tt> for <tt>Foo&amp;</tt> is looked up in the
<tt>registry</tt>, and each <tt>unwrapper</tt> it contains is queried
to determine if it can convert the
<tt>PyObject*</tt> with which the <tt>unwrap</tt> was constructed. If
a body object which can perform the conversion is found, a pointer to
it is stored in the handle. A body object may at any point store
additional data in the handle to speed up the conversion process.
<p>
Now that the handle has been constructed, the user can ask it whether
the conversion can be performed. All handles can be tested as though
they were convertible to <tt>bool</tt>; a <tt>true</tt> value
indicates success. If the user forges ahead and tries to do the
conversion without checking when no conversion is possible, an
exception will be thrown as usual. The conversion itself is performed
by the body object.
<h3>Handling complex conversions</h3>
<p>Some conversions may require a dynamic allocation. For example,
when a Python tuple is converted to a <tt>std::vector&lt;double&gt;
const&amp;</tt>, we need some storage into which to construct the
vector so that a reference to it can be formed. Furthermore, multiple
conversions of the same type may need to be &quot;active&quot;
simultaneously, so we can't keep a single copy of the storage
anywhere. We could keep the storage in the <tt>body</tt> object, and
have the body clone itself in case the storage is used, but in that
case the storage in the body which lives in the registry is never
used. If the storage was actually an object of the target type (the
safest way in C++), we'd have to find a way to construct one for the
body in the registry, since it may not have a default constructor.
<p>
The most obvious way out of this quagmire is to allocate the object using a
<i>new-expression</i>, and store a pointer to it in the handle. Since
the <tt>body</tt> object knows everything about the data it needs to
allocate (if any), it is also given responsibility for destroying that
data. When the <tt>handle</tt> is destroyed it asks the <tt>body</tt>
object to tear down any data it may have stored there. In many ways,
you can think of the <tt>body</tt> as a &quot;dynamically-determined
vtable&quot; for the handle.
<h3>Eliminating Redundancy</h3>
If you look at the current Boost.Python code, you'll see that there
are an enormous number of conversion functions generated for each
wrapped class. For a given class <tt>T</tt>, functions are generated
to extract the following types <tt>from_python</tt>:
<blockquote><pre>
T*
T const*
T const* const&amp;
T* const&amp;
T&amp;
T const&amp;
T
std::auto_ptr&lt;T&gt;&amp;
std::auto_ptr&lt;T&gt;
std::auto_ptr&lt;T&gt; const&amp;
boost::shared_ptr&lt;T&gt;&amp;
boost::shared_ptr&lt;T&gt;
boost::shared_ptr&lt;T&gt; const&amp;
</pre></blockquote>
Most of these are implemented in terms of just a few conversions, and
<t>if you're lucky</t>, they will be inlined and cause no extra
overhead. In the new system, however, a significant amount of data
will be associated with each type that needs to be converted. We
certainly don't want to register a separate unwrapper object for all
of the above types.
<p>Fortunately, much of the redundancy can be eliminated. For example,
if we generate an unwrapper for <tt>T&</tt>, we don't need an
unwrapper for <tt>T const&</tt> or <tt>T</tt>. Accordingly, the user's
request to wrap/unwrap a given type is translated at compile-time into
a request which helps to eliminate redundancy. The rules used to
<tt>unwrap</tt> a type are:
<ol>
<li> Treat built-in types specially: when unwrapping a value or
constant reference to one of these, use a value for the target
type. It will bind to a const reference if neccessary, and more
importantly, avoids having to dynamically allocate room for
an lvalue of types which can be cheaply copied.
<li>
Reduce everything else to a reference to an un-cv-qualified type
where possible. Since cv-qualification is lost on Python
anyway, there's no point in trying to convert to a
<tt>const&amp;</tt>. <font color="#ff0000">What about conversions
to values like the tuple-&gt;vector example above? It seems to me
that we don't want to make a <tt>vector&lt;double&gt;&amp;</tt>
(non-const) converter available for that case. We may need to
rethink this slightly.</font>
</ol>
<p>To handle the problem described above in item 2, we modify the
procedure slightly. To unwrap any non-scalar <tt>T</tt>, we seek an
unwrapper for <tt>add_reference&lt;T&gt;::type</tt>. Unwrappers for
<tt>T&nbsp;const&amp;</tt> always return <tt>T&amp;</tt>, and are
registered under both <tt>T&nbsp;&amp;</tt> and
<tt>T&nbsp;const&amp;</tt>.
<p>For compilers not supporting partial specialization, unwrappers for
<tt>T&nbsp;const&amp;</tt> must return <tt>T&nbsp;const&amp;</tt>
(since constness can't be stripped), but a separate unwrapper object
need to be registered for <tt>T&nbsp;&amp;</tt> and
<tt>T&nbsp;const&amp;</tt> anyway, for the same reasons.
<font color="#ff0000">We may want to make it possible to compile as
though partial specialization were unavailable even on compilers where
it is available, in case modules could be compiled by different
compilers with compatible ABIs (e.g. Intel C++ and MSVC6).</font>
<h3>Efficient Argument Conversion</h3>
Since type conversions are primarily used in function wrappers, an
optimization is provided for the case where a group of conversions are
used together. Each <tt>handle</tt> class has a corresponding
&quot;<tt>_more</tt>&quot; class which does the same job, but has a
trivial destructor. Instead of asking each &quot;<tt>_more</tt>&quot;
handle to destroy its own body, it is linked into an endogenous list
managed by the first (ordinary) handle. The <tt>wrap</tt> and
<tt>unwrap</tt> destructors are responsible for traversing that list
and asking each <tt>body</tt> class to tear down its
<tt>handle</tt>. This mechanism is also used to determine if all of
the argument/return-value conversions can succeed with a single
function call in the function wrapping code. <font color="#ff0000">We
might need to handle return values in a separate step for Python
callbacks, since the availablility of a conversion won't be known
until the result object is retrieved.</font>
<br>
<hr>
<h2>References</h2>
<p><a name="ref_1">[1]</a>B. Stroustrup, The C++ Programming Language
Special Edition Addison-Wesley, ISBN 0-201-70073-5.
<hr>
<p>Revised <!--webbot bot="Timestamp" s-type="EDITED" s-format="%d %B %Y" startspan -->
13 November, 2002
<!--webbot bot="Timestamp" endspan i-checksum="31283" --></p>
<p>© Copyright David Abrahams, 2001</p>
</body>
</html>

View File

@@ -1,111 +0,0 @@
This hierarchy contains converter handle classes.
+-------------+
| noncopyable |
+-------------+
^
| A common base class used so that
+--------+--------+ conversions can be linked into a
| conversion_base | chain for efficient argument
+-----------------+ conversion
^
|
+---------+-----------+
| |
+-----------+----+ +------+-------+ only used for
| unwrap_more<T> | | wrap_more<T> | chaining, and don't manage any
+----------------+ +--------------+ resources.
^ ^
| |
+-----+-----+ +-------+-+ These converters are what users
| unwrap<T> | | wrap<T> | actually touch, but they do so
+-----------+ +---------+ through a type generator which
minimizes the number of converters
that must be generated, so they
Each unwrap<T>, unwrap_more<T>, wrap<T>, wrap_more<T> converter holds
a reference to an appropriate converter object
This hierarchy contains converter body classes
Exposes use/release which
are needed in case the converter
+-----------+ in the registry needs to be
| converter | cloned. That occurs when a
+-----------+ unwrap target type is not
^ contained within the Python object.
|
+------------------+-----+
| |
+--------+-------+ Exposes |
| unwrapper_base | convertible() |
+----------------+ |
^ |
| |
+--------+----+ +-----+-----+
| unwrapper<T>| | wrapper<T>|
+-------------+ +-----------+
Exposes T convert(PyObject*) Exposes PyObject* convert(T)
unwrap:
constructed with a PyObject*, whose reference count is
incremented.
find the registry entry for the target type
look in the collection of converters for one which claims to be
able to convert the PyObject to the target type.
stick a pointer to the unwrapper in the unwrap object
when unwrap is queried for convertibility, it checks to see
if it has a pointer to an unwrapper.
on conversion, the unwrapper is asked to allocate an
implementation if the unwrap object isn't already holding
one. The unwrap object "takes ownership" of the unwrapper's
implementation. No memory allocation will actually take place
unless this is a value conversion.
on destruction, the unwrapper is asked to free any implementation
held by the unwrap object. No memory deallocation actually
takes place unless this is a value conversion
on destruction, the reference count on the held PyObject is
decremented.
We need to make sure that by default, you can't instantiate
callback<> for reference and pointer return types: although the
unwrappers may exist, they may convert by-value, which would cause
the referent to be destroyed upon return.
wrap:
find the registry entry for the source type
see if there is a converter. If found, stick a pointer to it in
the wrap object.
when queried for convertibility, it checks to see if it has a
pointer to a converter.
on conversion, a reference to the target PyObject is held by the
converter. Generally, the PyObject will have been created by the
converter, but in certain cases it may be a pre-existing object,
whose reference count will have been incremented.
when a wrap<T> x is used to return from a C++ function,
x.release() is returned so that x no longer holds a reference to
the PyObject when destroyed.
Otherwise, on destruction, any PyObject still held has its
reference-count decremented.
When a converter is created by the user, the appropriate element must
be added to the registry; when it is destroyed, it must be removed
from the registry.

View File

@@ -1,121 +1,371 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<!-- Copyright David Abrahams 2006. Distributed under the Boost -->
<!-- Software License, Version 1.0. (See accompanying -->
<!-- file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -->
<html>
<head>
<meta name="generator" content=
"HTML Tidy for Windows (vers 1st August 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">
<head>
<meta name="generator" content=
"HTML Tidy for Cygwin (vers 1st September 2004), 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>Boost.Python - News/Change Log</title>
</head>
<title>Boost.Python - News/Change Log</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>
<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="../../../boost.png" border="0"></a></h3>
</td>
<td valign="top">
<h1 align="center"><a href="index.html">Boost.Python</a></h1>
<td valign="top">
<h1 align="center"><a href="index.html">Boost.Python</a></h1>
<h2 align="center">News/Change Log</h2>
</td>
</tr>
</table>
<hr>
<h2 align="center">News/Change Log</h2>
</td>
</tr>
</table>
<hr>
<dl class="page-index">
<dt>18 March, 2003
<dl class="page-index">
<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.
<dt>Current SVN</dt>
<dd>
<ul>
<li>Python 3 support:</li>
<ul>
<li>All the current Boost.Python test cases passed. Extension modules using
Boost.Python expected to support Python 3 smoothly.</li>
<li>Introduced <code>object.contains</code> where <code>x.contains(y)</code>
is equivalent to Python code <code>y in x</code>.
Now <code>dict.has_key</code> is just a wrapper of <code>object.contains</code>.
</li>
<li>When building against Python 3, <code>str.decode</code> will be removed.</li>
<li>When building against Python 3, the original signature of <code>list.sort</code>, which is:
<pre>void sort(object_cref cmpfunc);</pre>
will change to:
<pre>void sort(args_proxy const &args, kwds_proxy const &kwds);</pre>
<dt>24 February 2003</dt>
This is because in Python 3 <code>list.sort</code> requires all its arguments be keyword arguments.
So you should call it like this:
<pre>x.sort(*tuple(), **dict(make_tuple(make_tuple("reverse", true))));</pre>
<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>
</li>
<li>According to <a href="http://www.python.org/dev/peps/pep-3123/">PEP 3123</a>,
when building Boost.Python against Python older than 2.6, the following macros will
be defined in Boost.Python header:
<pre>
# define Py_TYPE(o) (((PyObject*)(o))->ob_type)
# define Py_REFCNT(o) (((PyObject*)(o))->ob_refcnt)
# define Py_SIZE(o) (((PyVarObject*)(o))->ob_size)</pre>
So extension writers can use these macro directly, to make code clean and compatible with Python 3.
</li>
</ul>
</ul>
</dd>
<dd>Integrated <code>staticmethod</code> support from <a href=
"mailto:nickm-at-sitius.com">Nikolay Mladenov</a>. Thanks,
Nikolay!</dd>
<dt>1.39.0 Release</dt>
<dt>29 December 2002</dt>
<dd>
<ul>
<li>Pythonic signatures are now automatically appended to the
docstrings.
<dd>Added Visual Studio project file and instructions from Brett
Calcott. Thanks, Brett!</dd>
<li>Use <a href="v2/docstring_options.html"
><code>docstring_options.hpp</code></a> header
control the content of docstrings.
<li>This new feature increases the size of the modules by about 14%.
If this is not acceptable it can be turned off by defining the macro
BOOST_PYTHON_NO_PY_SIGNATURES. Modules compiled with and without the macro
defined are compatible.
</li>
<li> If BOOST_PYTHON_NO_PY_SIGNATURES is undefined, this version defines the
macro BOOST_PYTHON_SUPPORTS_PY_SIGNATURES. This allows writing code that will compile
with older version of Boost.Python (see <a href="v2/pytype_function.html#examples">here</a>).
</li>
<li>By defining BOOST_PYTHON_PY_SIGNATURES_PROPER_INIT_SELF_TYPE, and at a cost
of another 14% size increase, proper pythonic type is generated for the "self"
parameter of the __init__ methods.
</li>
<li> To support this new feature changes were made to the
<a href="v2/to_python_converter.html"><code>to_python_converter.hpp</code></a>,
<a href="v2/default_call_policies.html"><code>default_call_policies</code></a>,
<a href="v2/ResultConverter.html"><code>ResultConverter</code></a>,
<a href="v2/CallPolicies.html"><code>CallPolicies</code></a> and some others.
Efforts were made not to have interface breaking changes.
</li>
<dt>20 December 2002</dt>
</ul>
</dd>
<dd>Added automatic downcasting for pointers, references, and smart
pointers to polymorphic class types upon conversion to python</dd>
<dt>12 May 2007 - 1.34.0 release</dt>
<dt>18 December 2002</dt>
<dd>
<ul>
<li>C++ signatures are now automatically appended to the
docstrings.
<dd>Optimized from_python conversions for wrapped classes by putting
the conversion logic in the shared library instead of registering
separate converters for each class in each extension module</dd>
<li>New <a href="v2/docstring_options.html"
><code>docstring_options.hpp</code></a> header to
control the content of docstrings.
<dt>19 November 2002</dt>
<li>Support for converting <code>void*</code> to/from python,
with <code><a
href="v2/opaque.html">opaque_pointer_converter</a></code>
as the return value policy. Thanks to Niall Douglas for the
initial patch.
</ul>
</dd>
<dd>Removed the need for users to cast base class member function
pointers when used as arguments to <a href=
"v2/class.html#class_-spec-modifiers">add_property</a></dd>
<dt>19 October 2005 - 1.33.1 release</dt>
<dt>13 December 2002</dt>
<dd>
<ul>
<li><code>wrapper&lt;T&gt;</code> can now be used as expected with a
held type of <i>some-smart-pointer</i><code>&lt;T&gt;</code></li>
<dd>Allow exporting of <a href=
"v2/enum.html#enum_-spec"><code>enum_</code></a> values into enclosing
<a href="v2/scope.html#scope-spec"><code>scope</code></a>.<br>
Fixed unsigned integer conversions to deal correctly with numbers that
are out-of-range of <code>signed long</code>.</dd>
<li>The build now assumes Python 2.4 by default, rather than 2.2</li>
<dt>14 November 2002</dt>
<li>Support Python that's built without Unicode support</li>
<dd>Auto-detection of class data members wrapped with <a href=
"v2/data_members.html#make_getter-spec"><code>make_getter</code></a></dd>
<li>Support for wrapping classes with overloaded address-of
(<code>&amp;</code>) operators</li>
</ul>
</dd>
<dt>13 November 2002</dt>
<dt>14 August 2005 - 1.33 release</dt>
<dd>Full Support for <code>std::auto_ptr&lt;&gt;</code> added.</dd>
<dd>
<ul>
<li>Support for docstrings on nonstatic properties.</li>
<dt>October 2002</dt>
<li>We now export the client-provided docstrings for
<code>init&lt;optional&lt;&gt; &gt;</code> and
<i>XXX</i><code>_FUNCTION_OVERLOADS()</code> for only the last
overload.</li>
<dd>Ongoing updates and improvements to tutorial documentation</dd>
<li>Fixed some support for Embedded VC++ 4</li>
<dt>10 October 2002</dt>
<li>Better support for rvalue from-python conversions of shared_ptr:
always return a pointer that holds the owning python object *unless*
the python object contains a NULL shared_ptr holder of the right
type.</li>
<dd>Boost.Python V2 is released!</dd>
</dl>
<hr>
<li>Support for exposing <code>vector&lt;T*&gt;</code> with the
indexing suite.</li>
<p>Revised
<!--webbot bot="Timestamp" S-Type="EDITED" S-Format="%d %B, %Y" startspan -->
18 March, 2003
<!--webbot bot="Timestamp" endspan i-checksum="39359" -->
</p>
<li>Support for GCC-3.3 on MacOS.</li>
<p><i>&copy; Copyright <a href="../../../people/dave_abrahams.htm">Dave
Abrahams</a> 2002-2003. All Rights Reserved.</i></p>
</body>
<li>updated visual studio project build file to include two new files
(slice.cpp and wrapper.cpp)</li>
<li>Added search feature to the index page.</li>
<li>Numerous fixes to the tutorial</li>
<li>Numerous workarounds for MSVC 6 and 7, GCC 2.96, and EDG
2.45</li>
</ul>
</dd>
<dt>11 March 2005</dt>
<dd>
<ul>
<li>Added a hack that will fool PyDoc into working with Boost.Python,
thanks to Nick Rasmussen</li>
</ul>
</dd>
<dt>19 November 2004 - 1.32 release</dt>
<dd>
<ul>
<li>Updated to use the Boost Software License.</li>
<li>A new, <a href=
"tutorial/doc/html/python/exposing.html#python.class_virtual_functions">
better method of wrapping classes with virtual functions</a> has been
implemented.</li>
<li>Support for upcoming GCC symbol export control features have been
folded in, thanks to Niall Douglas.</li>
<li>Improved support for <code>std::auto_ptr</code>-like types.</li>
<li>The Visual C++ bug that makes top-level <i>cv-qualification</i>
of function parameter types part of the function type has been worked
around.</li>
<li>Components used by other libraries have been moved out of
<code>python/detail</code> and into <code>boost/detail</code> to
improve dependency relationships.</li>
<li>Miscellaneous bug fixes and compiler workarounds.</li>
</ul>
</dd>
<dt>8 Sept 2004</dt>
<dd>Support for Python's Bool type, thanks to <a href=
"mailto:dholth-at-fastmail.fm">Daniel Holth</a>.</dd>
<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&szlig;auge</a> has contributed <a href=
"v2/opaque.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>
<dt>19 January 2003</dt>
<dd>Integrated <code>staticmethod</code> support from <a href=
"mailto:nickm-at-sitius.com">Nikolay Mladenov</a>. Thanks, Nikolay!</dd>
<dt>29 December 2002</dt>
<dd>Added Visual Studio project file and instructions from Brett Calcott.
Thanks, Brett!</dd>
<dt>20 December 2002</dt>
<dd>Added automatic downcasting for pointers, references, and smart
pointers to polymorphic class types upon conversion to python</dd>
<dt>18 December 2002</dt>
<dd>Optimized from_python conversions for wrapped classes by putting the
conversion logic in the shared library instead of registering separate
converters for each class in each extension module</dd>
<dt>19 November 2002</dt>
<dd>Removed the need for users to cast base class member function
pointers when used as arguments to <a href=
"v2/class.html#class_-spec-modifiers">add_property</a></dd>
<dt>13 December 2002</dt>
<dd>Allow exporting of <a href=
"v2/enum.html#enum_-spec"><code>enum_</code></a> values into enclosing
<a href="v2/scope.html#scope-spec"><code>scope</code></a>.<br>
Fixed unsigned integer conversions to deal correctly with numbers that
are out-of-range of <code>signed long</code>.</dd>
<dt>14 November 2002</dt>
<dd>Auto-detection of class data members wrapped with <a href=
"v2/data_members.html#make_getter-spec"><code>make_getter</code></a></dd>
<dt>13 November 2002</dt>
<dd>Full Support for <code>std::auto_ptr&lt;&gt;</code> added.</dd>
<dt>October 2002</dt>
<dd>Ongoing updates and improvements to tutorial documentation</dd>
<dt>10 October 2002</dt>
<dd>Boost.Python V2 is released!</dd>
</dl>
<hr>
<p>Revised
<!--webbot bot="Timestamp" S-Type="EDITED" S-Format="%d %B, %Y" startspan -->
19 November 2004
<!--webbot bot="Timestamp" endspan i-checksum="39359" --></p>
<p><i>&copy; Copyright <a href="http://www.boost.org/people/dave_abrahams.htm">Dave
Abrahams</a> 2002-2003.</i></p>
</body>
</html>

View File

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

View File

@@ -1,222 +1,466 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<!-- Copyright David Abrahams 2006. Distributed under the Boost -->
<!-- Software License, Version 1.0. (See accompanying -->
<!-- file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -->
<html>
<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">
<head>
<meta name="generator" content=
"HTML Tidy for Cygwin (vers 1st September 2004), see www.w3.org">
<meta http-equiv="Content-Type" content="text/html">
<link rel="stylesheet" type="text/css" href="boost.css">
<title>Boost.Python - Projects using Boost.Python</title>
</head>
<title>Boost.Python - Projects using Boost.Python</title>
</head>
<body link="#0000ff" vlink="#800080">
<table border="0" cellpadding="7" cellspacing="0" width="100%" summary=
"header">
<tr>
<td valign="top" width="300">
<h3><a href="../../../index.htm"><img height="86" width="277" alt=
"C++ Boost" src="../../../c++boost.gif" border="0"></a></h3>
</td>
<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="../../../boost.png" border="0"></a></h3>
</td>
<td valign="top">
<h1 align="center"><a href="index.html">Boost.Python</a></h1>
<td valign="top">
<h1 align="center"><a href="index.html">Boost.Python</a></h1>
<h2 align="center">Projects using Boost.Python</h2>
</td>
</tr>
</table>
<hr>
<h2 align="center">Projects using Boost.Python</h2>
</td>
</tr>
</table>
<hr>
<h2>Introduction</h2>
<h2>Introduction</h2>
<p>This is a partial list of projects using Boost.Python. If you are
using Boost.Python as your Python/C++ binding solution, we'd be proud to
list your project on this page. Just <a href=
"mailto:c++-sig@python.org">post</a> a short description of your project
and how Boost.Python helps you get the job done, and we'll add it to this
page .</p>
<hr>
<p>This is a partial list of projects using Boost.Python. If you are using
Boost.Python as your Python/C++ binding solution, we'd be proud to list
your project on this page. Just <a href=
"mailto:c++-sig@python.org">post</a> a short description of your project
and how Boost.Python helps you get the job done, and we'll add it to this
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>
<dl class="page-index">
<dt><b><a href="http://www.neuralynx.com">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
<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>
<p><a href="mailto:dnuffer@sco.com">Dan Nuffer</a> writes:</p>
<dl class="page-index">
<dt><b>TSLib</b> - <a href="http://www.fortressinv.com">Fortress
Investment Group LLC</a></dt>
<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>
</dl>
<dd>
Fortress Investment Group has contracted <a href=
"http://www.boost-consulting.com">Boost Consulting</a> to develop core
internal financial analysis tools in C++ and to prepare Python bindings
for them using Boost.Python.
<h3>Financial Analysis</h3>
<p>Tom Barket of Fortress writes:</p>
<dl class="page-index">
<dt><b>TSLib</b> - <a href="http://www.fortressinv.com">Fortress
Investment Group LLC</a></dt>
<blockquote>
We have a large C++ analytical library specialized for research in
finance and economics, built for speed and mission critical
stability. Yet Python offers us the flexibility to test out new ideas
quickly and increase the productivity of our time versus working in
C++. There are several key features which make Python stand out. Its
elegance, stability, and breadth of resources on the web are all
valuable, but the most important is its extensibility, due to its
open source transparency. Boost.Python makes Python extensibility
extremely simple and straightforward, yet preserves a great deal of
power and control.
</blockquote>
</dd>
</dl>
<dd>
Fortress Investment Group has contracted <a href=
"http://www.boost-consulting.com">Boost Consulting</a> to develop
core internal financial analysis tools in C++ and to prepare Python
bindings for them using Boost.Python.
<h3>Educational</h3>
<p>Tom Barket of Fortress writes:</p>
<dl class="page-index">
<dt><a href="http://edu.kde.org/kig"><b>Kig</b></a></dt>
<blockquote>
We have a large C++ analytical library specialized for research in
finance and economics, built for speed and mission critical
stability. Yet Python offers us the flexibility to test out new
ideas quickly and increase the productivity of our time versus
working in C++. There are several key features which make Python
stand out. Its elegance, stability, and breadth of resources on the
web are all valuable, but the most important is its extensibility,
due to its open source transparency. Boost.Python makes Python
extensibility extremely simple and straightforward, yet preserves a
great deal of power and control.
</blockquote>
</dd>
</dl>
<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>
<h3>Graphics</h3>
<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>
<dl class="page-index">
<dt><b><a href=
"http://sourceforge.net/projects/pyosg">OpenSceneGraph Bindings</a></b></dt>
<h3>Enterprise Software</h3>
<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>
<dl class="page-index">
<dt><b><a href="http://openwbem.sourceforge.net">OpenWBEM</a></b></dt>
<dt><a href=
"http://www.procoders.net/pythonmagick"><b>PythonMagick</b></a></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
<dd>PythonMagick binds the <a href=
"http://www.graphicsmagick.org">GraphicsMagick</a> image
manipulation library to Python.<br> &nbsp;</dd>
<p><a href="mailto:dnuffer@sco.com">Dan Nuffer</a> writes:</p>
<dt><b><a href=
"http://www.slac.stanford.edu/grp/ek/hippodraw/index.html">HippoDraw</a></b></dt>
<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>
HippoDraw is a data analysis environment consisting of a canvas upon
which graphs such as histograms, scattter plots, etc, are prsented.
It has a highly interactive GUI interface, but some things you need
to do with scripts. HippoDraw can be run as Python extension module
so that all the manipulation can be done from either Python or the
GUI.
<dt><b><a href="http://www.transversal.com">Metafaq</a></b></dt>
<p>Before the web page came online, <a
href="mailto:Paul_Kunz@SLAC.Stanford.EDU">Paul F. Kunz</a>
wrote:</p>
<dd>
Metafaq, from <a href="http://www.transversal.com">Transversal,
Inc.</a>, is an enterprise level online knowledge base management
system.
<blockquote>
Don't have a web page for the project, but the organization's is <a
href=
"http://www.slac.stanford.edu">http://www.slac.stanford.edu</a>
(the first web server site in America, I installed it).
</blockquote>
Which was just too cool a piece of trivia to omit.<br>
&nbsp;
</dd>
</dl>
<p><a href="mailto:ben.young-at-transversal.com">Ben Young</a>
writes:</p>
<h3>Scientific Computing</h3>
<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>
<dl class="page index">
<dt><a href="http://camfr.sourceforge.net"><b>CAMFR</b></a></dt>
<h3>Games</h3>
<dd>
CAMFR is a photonics and electromagnetics modelling tool. Python is
used for computational steering.
<dl>
<dt><b><a href="http://www.firaxis.com">Civilization IV</a></b></dt>
</dl>
<p><a href="mailto:Peter.Bienstman@rug.ac.be">Peter Bienstman</a>
writes:</p>
<blockquote>
&ldquo;The fourth game in the PC strategy series that has sold over five
million copies, Sid Meier's Civilization IV is a bold step forward for
the franchise, with spectacular new 3D graphics and all-new single and
multiplayer content. Civilization IV will also set a new standard for
user-modification, allowing gamers to create their own add-ons using
Python and XML.
<blockquote>
Thanks for providing such a great tool!
</blockquote>
</dd>
<p>Sid Meier's Civilization IV will be released for PC in late 2005. For
more information please visit <a href=
"http://www.firaxis.com">http://www.firaxis.com</a> or write <a href=
"mailto:kgilmore@firaxis.com">kgilmore@firaxis.com</a>&rdquo;</p>
</blockquote>
<dt><a href="http://cctbx.sourceforge.net"><b>cctbx - Computational
Crystallography Toolbox</b></a></dt>
<p>Boost.Python is used as the interface layer between the C++ game code
and Python. Python is used for many purposes in the game, including map
generation, interface screens, game events, tools, tutorials, etc. Most
high-level game operations have been exposed to Python in order to give
modders the power they need to customize the game.</p>
<dd>
Computational Crystallography is concerned with the derivation of
atomic models of crystal structures, given experimental X-ray
diffraction data. The cctbx is an open-source library of fundamental
algorithms for crystallographic computations. The core algorithms are
implemented in C++ and accessed through higher-level Python
interfaces.
<blockquote>
-Mustafa Thamer, Civ4 Lead Programmer
</blockquote>
<p>The cctbx grew together with Boost.Python and is designed from the
ground up as a hybrid Python/C++ system. With one minor exception,
run-time polymorphism is completely handled by Python. C++
compile-time polymorphism is used to implement performance critical
algorithms. The Python and C++ layers are seamlessly integrated using
Boost.Python.</p>
<dl class="page-index">
<dt><b><a href="http://vegastrike.sourceforge.net">Vega
Strike</a></b></dt>
<p>The SourceForge cctbx project is organized in modules to
facilitate use in non-crystallographic applications. The scitbx
module implements a general purpose array family for scientific
applications and pure C++ ports of FFTPACK and the LBFGS conjugate
gradient minimizer.</p>
</dd>
<dd>
<a href="http://vegastrike.sourceforge.net">Vega Strike</a> is the 3D
Space Simulator that allows you to trade and bounty hunt in a vast
universe. Players face dangers, decisions, piracy, and aliens.
<dt><a href="http://www.llnl.gov/CASC/emsolve"><b>EMSolve</b></a></dt>
<p><a href="http://vegastrike.sourceforge.net">Vega Strike</a> has
decided to base its scripting on python, using boost as the layer
between the class hierarchy in python and the class hierarchy in C++.
The result is a very flexible scripting system that treats units as
native python classes when designing missions or writing AI's.</p>
<dd>EMSolve is a provably stable, charge conserving, and energy
conserving solver for Maxwell's equations.<br>
&nbsp;</dd>
<p>A large economic and planetary simulation is currently being run in
the background in python and the results are returned back into C++ in
the form of various factions' spaceships appearing near worlds that
they are simulated to be near in python if the player is in the general
neighborhood.</p>
</dd>
</dl>
<dt><b><a href="http://cern.ch/gaudi">Gaudi</a></b> and <b><a href=
"http://cern.ch/Gaudi/RootPython/">RootPython</a></b></dt>
<h3>Graphics</h3>
<dd>
Gaudi is a framework for particle physics collision data processing
applications developed in the context of the LHCb and ATLAS
experiments at CERN.
<dl class="page-index">
<dt><b><a href="http://sourceforge.net/projects/pyosg">OpenSceneGraph
Bindings</a></b></dt>
<p><a href="mailto:Pere.Mato@cern.ch">Pere Mato Vila</a> writes:</p>
<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>
<blockquote>
We are using Boost.Python to provide scripting/interactive
capability to our framework. We have a module called "GaudiPython"
implemented using Boost.Python that allows the interaction with any
framework service or algorithm from python. RootPython also uses
Boost.Python to provide a generic "gateway" between the <a href=
"http://root.cern.ch">ROOT</a> framework and python
<dt><b><a href=
"http://www.slac.stanford.edu/grp/ek/hippodraw/index.html">HippoDraw</a></b></dt>
<p>Boost.Python is great. We managed very quickly to interface our
framework to python, which is great language. We are trying to
facilitate to our physicists (end-users) a rapid analysis
application development environment based on python. For that,
Boost.Python plays and essential role.</p>
</blockquote>
</dd>
</dl>
<hr>
<dd>
HippoDraw is a data analysis environment consisting of a canvas upon
which graphs such as histograms, scattter plots, etc, are prsented. It
has a highly interactive GUI interface, but some things you need to do
with scripts. HippoDraw can be run as Python extension module so that
all the manipulation can be done from either Python or the GUI.
<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>
<p>Before the web page came online, <a href=
"mailto:Paul_Kunz@SLAC.Stanford.EDU">Paul F. Kunz</a> wrote:</p>
<p><i>&copy; Copyright <a href="../../../people/dave_abrahams.htm">Dave
Abrahams</a> 2002-2003. All Rights Reserved.</i></p>
</body>
<blockquote>
Don't have a web page for the project, but the organization's is
<a href=
"http://www.slac.stanford.edu">http://www.slac.stanford.edu</a> (the
first web server site in America, I installed it).
</blockquote>Which was just too cool a piece of trivia to omit.<br>
&nbsp;
</dd>
<dt><a href="http://www.iplt.org"><b>IPLT</b></a></dt>
<dd>
<a href="mailto:ansgar.philippsen-at-unibas.ch">Ansgar Philippsen</a>
writes:
<blockquote>
IPLT is an image processing library and toolbox for the structural
biology electron microscopy community. I would call it a
budding/evolving project, since it is currently not in production
stage, but rather under heavy development. Python is used as the main
scripting/interaction level, but also for rapid prototyping, since
the underlying C++ class library is pretty much fully exposed via
boost.python (at least the high-level interface). The combined power
of C++ and Python for this project turned out to be just awesome.
</blockquote><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>
<dt><a href="http://www.vpython.org"><b>VPython</b></a></dt>
<dd>
<a href="mailto:Bruce_Sherwood-at-ncsu.edu">Bruce Sherwood</a> writes:
<blockquote>
VPython is an extension for Python that makes it easy to create
navigable 3D animations, which are generated as a side effect of
computational code. VPython is used in education for various
purposes, including teaching physics and programming, but it has also
been used by research scientists to visualize systems or data in 3D.
</blockquote><br>
&nbsp;
</dd>
</dl>
<h3>Scientific Computing</h3>
<dl class="page index">
<dt><a href="http://camfr.sourceforge.net"><b>CAMFR</b></a></dt>
<dd>
CAMFR is a photonics and electromagnetics modelling tool. Python is
used for computational steering.
<p><a href="mailto:Peter.Bienstman@rug.ac.be">Peter Bienstman</a>
writes:</p>
<blockquote>
Thanks for providing such a great tool!
</blockquote>
</dd>
<dt><a href="http://cctbx.sourceforge.net"><b>cctbx - Computational
Crystallography Toolbox</b></a></dt>
<dd>
Computational Crystallography is concerned with the derivation of
atomic models of crystal structures, given experimental X-ray
diffraction data. The cctbx is an open-source library of fundamental
algorithms for crystallographic computations. The core algorithms are
implemented in C++ and accessed through higher-level Python interfaces.
<p>The cctbx grew together with Boost.Python and is designed from the
ground up as a hybrid Python/C++ system. With one minor exception,
run-time polymorphism is completely handled by Python. C++ compile-time
polymorphism is used to implement performance critical algorithms. The
Python and C++ layers are seamlessly integrated using Boost.Python.</p>
<p>The SourceForge cctbx project is organized in modules to facilitate
use in non-crystallographic applications. The scitbx module implements
a general purpose array family for scientific applications and pure C++
ports of FFTPACK and the L-BFGS quasi-Newton minimizer.</p>
</dd>
<dt><a href="http://www.llnl.gov/CASC/emsolve"><b>EMSolve</b></a></dt>
<dd>EMSolve is a provably stable, charge conserving, and energy
conserving solver for Maxwell's equations.<br>
&nbsp;</dd>
<dt><b><a href="http://cern.ch/gaudi">Gaudi</a></b> and <b><a href=
"http://cern.ch/Gaudi/RootPython/">RootPython</a></b></dt>
<dd>
Gaudi is a framework for particle physics collision data processing
applications developed in the context of the LHCb and ATLAS experiments
at CERN.
<p><a href="mailto:Pere.Mato@cern.ch">Pere Mato Vila</a> writes:</p>
<blockquote>
We are using Boost.Python to provide scripting/interactive capability
to our framework. We have a module called "GaudiPython" implemented
using Boost.Python that allows the interaction with any framework
service or algorithm from python. RootPython also uses Boost.Python
to provide a generic "gateway" between the <a href=
"http://root.cern.ch">ROOT</a> framework and python
<p>Boost.Python is great. We managed very quickly to interface our
framework to python, which is great language. We are trying to
facilitate to our physicists (end-users) a rapid analysis application
development environment based on python. For that, 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/index.php?pg=dev_projetos">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/index.php?pg=dev_projetos">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://polybori.sourceforge.net/">PolyBoRi</a></b></dt>
<dd>
<p><a href="mailto:brickenstein@mfo.de"
>Michael Brickenstein</a> writes:</p>
<blockquote>
<p>The core of PolyBoRi is a C++ library, which provides
high-level data types for Boolean polynomials and monomials,
exponent vectors, as well as for the underlying polynomial
rings and subsets of the powerset of the Boolean variables. As
a unique approach, binary decision diagrams are used as
internal storage type for polynomial structures. On top of
this C++-library we provide a Python interface. This allows
parsing of complex polynomial systems, as well as sophisticated
and extendable strategies for Gr&ouml;bner basis computation.
Boost.Python has helped us to create this interface in a
very clean way.</p>
</blockquote>
</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>Systems Libraries</h3>
<dl>
<dt><a href="http://itamarst.org/software"><b>Fusion</b></a></dt>
<dd>
<p>Fusion is a library that supports implementing protocols in C++ for
use with Twisted, allowing control over memory allocation strategies,
fast method calls internally, etc.. Fusion supports TCP, UDP and
multicast, and is implemented using the Boost.Python python
bindings.</p>
<p>Fusion is licensed under the MIT license, and available for download
from <a href=
"http://itamarst.org/software">http://itamarst.org/software</a>.</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, 2008</p>
<p><i>&copy; Copyright <a href="http://www.boost.org/people/dave_abrahams.htm">Dave
Abrahams</a> 2002-2008.</i></p>
</body>
</html>

View File

@@ -1,9 +1,12 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<!-- Copyright David Abrahams 2006. Distributed under the Boost -->
<!-- Software License, Version 1.0. (See accompanying -->
<!-- file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -->
<html>
<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">
@@ -16,7 +19,7 @@
<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>
"C++ Boost" src="../../../boost.png" border="0"></a></h3>
</td>
<td valign="top">
@@ -31,7 +34,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 +46,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 +58,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>
<p><i>&copy; Copyright <a href="http://www.boost.org/people/dave_abrahams.htm">Dave
Abrahams</a> 2003.</i></p>
</body>
</html>

View File

@@ -0,0 +1,18 @@
# Copyright Joel de Guzman 2006. Distributed under the Boost
# Software License, Version 1.0. (See accompanying
# file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
project boost/libs/python/doc/tutorial/doc ;
import boostbook : boostbook ;
using quickbook ;
path-constant images : html ;
boostbook tutorial
:
tutorial.qbk
:
<xsl:param>boost.root=../../../../../..
<format>pdf:<xsl:param>img.src.path=$(images)/
<format>pdf:<xsl:param>boost.url.prefix=http://www.boost.org/doc/libs/release/libs/python/doc/tutorial/doc/html
;

View File

@@ -1,112 +0,0 @@
<html>
<head>
<!-- Generated by the Spirit (http://spirit.sf.net) QuickDoc -->
<title>Auto-Overloading</title>
<link rel="stylesheet" href="theme/style.css" type="text/css">
<link rel="prev" href="default_arguments.html">
<link rel="next" href="object_interface.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>Auto-Overloading</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="default_arguments.html"><img src="theme/l_arr.gif" border="0"></a></td>
<td width="20"><a href="object_interface.html"><img src="theme/r_arr.gif" border="0"></a></td>
</tr>
</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>
can also be used for overloaded functions and member functions with a
common sequence of initial arguments. Here is an example:</p>
<code><pre>
<span class=keyword>void </span><span class=identifier>foo</span><span class=special>()
{
/*...*/
}
</span><span class=keyword>void </span><span class=identifier>foo</span><span class=special>(</span><span class=keyword>bool </span><span class=identifier>a</span><span class=special>)
{
/*...*/
}
</span><span class=keyword>void </span><span class=identifier>foo</span><span class=special>(</span><span class=keyword>bool </span><span class=identifier>a</span><span class=special>, </span><span class=keyword>int </span><span class=identifier>b</span><span class=special>)
{
/*...*/
}
</span><span class=keyword>void </span><span class=identifier>foo</span><span class=special>(</span><span class=keyword>bool </span><span class=identifier>a</span><span class=special>, </span><span class=keyword>int </span><span class=identifier>b</span><span class=special>, </span><span class=keyword>char </span><span class=identifier>c</span><span class=special>)
{
/*...*/
}
</span></pre></code>
<p>
Like in the previous section, we can generate thin wrappers for these
overloaded functions in one-shot:</p>
<code><pre>
<span class=identifier>BOOST_PYTHON_FUNCTION_OVERLOADS</span><span class=special>(</span><span class=identifier>foo_overloads</span><span class=special>, </span><span class=identifier>foo</span><span class=special>, </span><span class=number>0</span><span class=special>, </span><span class=number>3</span><span class=special>)
</span></pre></code>
<p>
Then...</p>
<code><pre>
<span class=special>.</span><span class=identifier>def</span><span class=special>(</span><span class=string>&quot;foo&quot;</span><span class=special>, </span><span class=identifier>foo</span><span class=special>, </span><span class=identifier>foo_overloads</span><span class=special>());
</span></pre></code>
<p>
Notice though that we have a situation now where we have a minimum of zero
(0) arguments and a maximum of 3 arguments.</p>
<a name="manual_wrapping"></a><h2>Manual Wrapping</h2><p>
It is important to emphasize however that <b>the overloaded functions must
have a common sequence of initial arguments</b>. Otherwise, our scheme above
will not work. If this is not the case, we have to wrap our functions
<a href="overloading.html">
manually</a>.</p>
<p>
Actually, we can mix and match manual wrapping of overloaded functions and
automatic wrapping through <tt>BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS</tt> and
its sister, <tt>BOOST_PYTHON_FUNCTION_OVERLOADS</tt>. Following up on our example
presented in the section <a href="overloading.html">
on overloading</a>, since the
first 4 overload functins have a common sequence of initial arguments, we
can use <tt>BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS</tt> to automatically wrap the
first three of the <tt>def</tt>s and manually wrap just the last. Here's
how we'll do this:</p>
<code><pre>
<span class=identifier>BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS</span><span class=special>(</span><span class=identifier>xf_overloads</span><span class=special>, </span><span class=identifier>f</span><span class=special>, </span><span class=number>1</span><span class=special>, </span><span class=number>4</span><span class=special>)
</span></pre></code>
<p>
Create a member function pointers as above for both X::f overloads:</p>
<code><pre>
<span class=keyword>bool </span><span class=special>(</span><span class=identifier>X</span><span class=special>::*</span><span class=identifier>fx1</span><span class=special>)(</span><span class=keyword>int</span><span class=special>, </span><span class=keyword>double</span><span class=special>, </span><span class=keyword>char</span><span class=special>) = &amp;</span><span class=identifier>X</span><span class=special>::</span><span class=identifier>f</span><span class=special>;
</span><span class=keyword>int </span><span class=special>(</span><span class=identifier>X</span><span class=special>::*</span><span class=identifier>fx2</span><span class=special>)(</span><span class=keyword>int</span><span class=special>, </span><span class=keyword>int</span><span class=special>, </span><span class=keyword>int</span><span class=special>) = &amp;</span><span class=identifier>X</span><span class=special>::</span><span class=identifier>f</span><span class=special>;
</span></pre></code>
<p>
Then...</p>
<code><pre>
<span class=special>.</span><span class=identifier>def</span><span class=special>(</span><span class=string>&quot;f&quot;</span><span class=special>, </span><span class=identifier>fx1</span><span class=special>, </span><span class=identifier>xf_overloads</span><span class=special>());
.</span><span class=identifier>def</span><span class=special>(</span><span class=string>&quot;f&quot;</span><span class=special>, </span><span class=identifier>fx2</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="default_arguments.html"><img src="theme/l_arr.gif" border="0"></a></td>
<td width="20"><a href="object_interface.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

@@ -1,77 +0,0 @@
<html>
<head>
<!-- Generated by the Spirit (http://spirit.sf.net) QuickDoc -->
<title>Basic Interface</title>
<link rel="stylesheet" href="theme/style.css" type="text/css">
<link rel="prev" href="object_interface.html">
<link rel="next" href="derived_object_types.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>Basic Interface</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="object_interface.html"><img src="theme/l_arr.gif" border="0"></a></td>
<td width="20"><a href="derived_object_types.html"><img src="theme/r_arr.gif" border="0"></a></td>
</tr>
</table>
<p>
Class <tt>object</tt> wraps <tt>PyObject*</tt>. All the intricacies of dealing with
<tt>PyObject</tt>s such as managing reference counting are handled by the
<tt>object</tt> class. C++ object interoperability is seamless. Boost.Python C++
<tt>object</tt>s can in fact be explicitly constructed from any C++ object.</p>
<p>
To illustrate, this Python code snippet:</p>
<code><pre>
<span class=identifier>def </span><span class=identifier>f</span><span class=special>(</span><span class=identifier>x</span><span class=special>, </span><span class=identifier>y</span><span class=special>):
</span><span class=keyword>if </span><span class=special>(</span><span class=identifier>y </span><span class=special>== </span><span class=literal>'foo'</span><span class=special>):
</span><span class=identifier>x</span><span class=special>[</span><span class=number>3</span><span class=special>:</span><span class=number>7</span><span class=special>] = </span><span class=literal>'bar'
</span><span class=keyword>else</span><span class=special>:
</span><span class=identifier>x</span><span class=special>.</span><span class=identifier>items </span><span class=special>+= </span><span class=identifier>y</span><span class=special>(</span><span class=number>3</span><span class=special>, </span><span class=identifier>x</span><span class=special>)
</span><span class=keyword>return </span><span class=identifier>x
</span><span class=identifier>def </span><span class=identifier>getfunc</span><span class=special>():
</span><span class=keyword>return </span><span class=identifier>f</span><span class=special>;
</span></pre></code>
<p>
Can be rewritten in C++ using Boost.Python facilities this way:</p>
<code><pre>
<span class=identifier>object </span><span class=identifier>f</span><span class=special>(</span><span class=identifier>object </span><span class=identifier>x</span><span class=special>, </span><span class=identifier>object </span><span class=identifier>y</span><span class=special>) {
</span><span class=keyword>if </span><span class=special>(</span><span class=identifier>y </span><span class=special>== </span><span class=string>&quot;foo&quot;</span><span class=special>)
</span><span class=identifier>x</span><span class=special>.</span><span class=identifier>slice</span><span class=special>(</span><span class=number>3</span><span class=special>,</span><span class=number>7</span><span class=special>) = </span><span class=string>&quot;bar&quot;</span><span class=special>;
</span><span class=keyword>else
</span><span class=identifier>x</span><span class=special>.</span><span class=identifier>attr</span><span class=special>(</span><span class=string>&quot;items&quot;</span><span class=special>) += </span><span class=identifier>y</span><span class=special>(</span><span class=number>3</span><span class=special>, </span><span class=identifier>x</span><span class=special>);
</span><span class=keyword>return </span><span class=identifier>x</span><span class=special>;
}
</span><span class=identifier>object </span><span class=identifier>getfunc</span><span class=special>() {
</span><span class=keyword>return </span><span class=identifier>object</span><span class=special>(</span><span class=identifier>f</span><span class=special>);
}
</span></pre></code>
<p>
Apart from cosmetic differences due to the fact that we are writing the
code in C++, the look and feel should be immediately apparent to the Python
coder.</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="object_interface.html"><img src="theme/l_arr.gif" border="0"></a></td>
<td width="20"><a href="derived_object_types.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

@@ -1,191 +0,0 @@
<html>
<head>
<!-- Generated by the Spirit (http://spirit.sf.net) QuickDoc -->
<title>Building Hello World</title>
<link rel="stylesheet" href="theme/style.css" type="text/css">
<link rel="prev" href="quickstart.html">
<link rel="next" href="exposing_classes.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>Building Hello World</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="quickstart.html"><img src="theme/l_arr.gif" border="0"></a></td>
<td width="20"><a href="exposing_classes.html"><img src="theme/r_arr.gif" border="0"></a></td>
</tr>
</table>
<a name="from_start_to_finish"></a><h2>From Start To Finish</h2><p>
Now the first thing you'd want to do is to build the Hello World module and
try it for yourself in Python. In this section, we shall outline the steps
necessary to achieve that. We shall use the build tool that comes bundled
with every boost distribution: <b>bjam</b>.</p>
<table width="80%" border="0" align="center">
<tr>
<td class="note_box">
<img src="theme/lens.gif"></img> <b>Building without bjam</b><br><br>
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>.
</td>
</tr>
</table>
<p>
We shall skip over the details. Our objective will be to simply create the
hello world module and run it in Python. For a complete reference to
building Boost.Python, check out: <a href="../../building.html">
building.html</a>.
After this brief <i>bjam</i> tutorial, we should have built two DLLs:</p>
<ul><li>boost_python.dll</li><li>hello.pyd</li></ul><p>
if you are on Windows, and</p>
<ul><li>libboost_python.so</li><li>hello.so</li></ul><p>
if you are on Unix.</p>
<p>
The tutorial example can be found in the directory:
<tt>libs/python/example/tutorial</tt>. There, you can find:</p>
<ul><li>hello.cpp</li><li>Jamfile</li></ul><p>
The <tt>hello.cpp</tt> file is our C++ hello world example. The <tt>Jamfile</tt> is a
minimalist <i>bjam</i> script that builds the DLLs for us.</p>
<p>
Before anything else, you should have the bjam executable in your boost
directory or somewhere in your path such that <tt>bjam</tt> can be executed in
the command line. Pre-built Boost.Jam executables are available for most
platforms. For example, a pre-built Microsoft Windows bjam executable can
be downloaded <a href="http://boost.sourceforge.net/jam-executables/bin.ntx86/bjam.zip">
here</a>.
The complete list of bjam pre-built
executables can be found <a href="../../../../../tools/build/index.html#Jam">
here</a>.</p>
<a name="lets_jam_"></a><h2>Lets Jam!</h2><p>
<img src="theme/jam.png"></img></p>
<p>
Here is our minimalist Jamfile:</p>
<code><pre>
subproject libs/python/example/tutorial ;
SEARCH on python.jam = $(BOOST_BUILD_PATH) ;
include python.jam ;
extension hello # Declare a Python extension called hello
: hello.cpp # source
&lt;dll&gt;../../build/boost_python # dependencies
;
</pre></code><p>
First, we need to specify our location in the boost project hierarchy.
It so happens that the tutorial example is located in <tt>/libs/python/example/tutorial</tt>.
Thus:</p>
<code><pre>
subproject libs/python/example/tutorial ;
</pre></code><p>
Then we will include the definitions needed by Python modules:</p>
<code><pre>
SEARCH on python.jam = $(BOOST_BUILD_PATH) ;
include python.jam ;
</pre></code><p>
Finally we declare our <tt>hello</tt> extension:</p>
<code><pre>
extension hello # Declare a Python extension called hello
: hello.cpp # source
&lt;dll&gt;../../build/boost_python # dependencies
;
</pre></code><a name="running_bjam"></a><h2>Running bjam</h2><p>
<i>bjam</i> is run using your operating system's command line interpreter.</p>
<blockquote><p>Start it up.</p></blockquote><p>
Make sure that the environment is set so that we can invoke the C++
compiler. With MSVC, that would mean running the <tt>Vcvars32.bat</tt> batch
file. For instance:</p>
<code><pre>
<span class=identifier>C</span><span class=special>:\</span><span class=identifier>Program </span><span class=identifier>Files</span><span class=special>\</span><span class=identifier>Microsoft </span><span class=identifier>Visual </span><span class=identifier>Studio</span><span class=special>\</span><span class=identifier>VC98</span><span class=special>\</span><span class=identifier>bin</span><span class=special>\</span><span class=identifier>Vcvars32</span><span class=special>.</span><span class=identifier>bat
</span></pre></code>
<p>
Some environment variables will have to be setup for proper building of our
Python modules. Example:</p>
<code><pre>
<span class=identifier>set </span><span class=identifier>PYTHON_ROOT</span><span class=special>=</span><span class=identifier>c</span><span class=special>:/</span><span class=identifier>dev</span><span class=special>/</span><span class=identifier>tools</span><span class=special>/</span><span class=identifier>python
</span><span class=identifier>set </span><span class=identifier>PYTHON_VERSION</span><span class=special>=</span><span class=number>2.2
</span></pre></code>
<p>
The above assumes that the Python installation is in <tt>c:/dev/tools/python</tt>
and that we are using Python version 2.2. You'll have to tweak this path
appropriately. <img src="theme/note.gif"></img> Be sure not to include a third number, e.g. <b>not</b> &quot;2.2.1&quot;,
even if that's the version you have.</p>
<p>
Now we are ready... Be sure to <tt>cd</tt> to <tt>libs/python/example/tutorial</tt>
where the tutorial <tt>&quot;hello.cpp&quot;</tt> and the <tt>&quot;Jamfile&quot;</tt> is situated.</p>
<p>
Finally:</p>
<code><pre>
<span class=identifier>bjam </span><span class=special>-</span><span class=identifier>sTOOLS</span><span class=special>=</span><span class=identifier>msvc
</span></pre></code>
<p>
We are again assuming that we are using Microsoft Visual C++ version 6. If
not, then you will have to specify the appropriate tool. See
<a href="../../../../../tools/build/index.html">
Building Boost Libraries</a> for
further details.</p>
<p>
It should be building now:</p>
<code><pre>
cd C:\dev\boost\libs\python\example\tutorial
bjam -sTOOLS=msvc
...patience...
...found 1703 targets...
...updating 40 targets...
</pre></code><p>
And so on... Finally:</p>
<code><pre>
vc-C++ ..\..\..\..\libs\python\example\tutorial\bin\hello.pyd\msvc\debug\
runtime-link-dynamic\hello.obj
hello.cpp
vc-Link ..\..\..\..\libs\python\example\tutorial\bin\hello.pyd\msvc\debug\
runtime-link-dynamic\hello.pyd ..\..\..\..\libs\python\example\tutorial\bin\
hello.pyd\msvc\debug\runtime-link-dynamic\hello.lib
Creating library ..\..\..\..\libs\python\example\tutorial\bin\hello.pyd\
msvc\debug\runtime-link-dynamic\hello.lib and object ..\..\..\..\libs\python\
example\tutorial\bin\hello.pyd\msvc\debug\runtime-link-dynamic\hello.exp
...updated 40 targets...
</pre></code><p>
If all is well, you should now have:</p>
<ul><li>boost_python.dll</li><li>hello.pyd</li></ul><p>
if you are on Windows, and</p>
<ul><li>libboost_python.so</li><li>hello.so</li></ul><p>
if you are on Unix.</p>
<p>
<tt>boost_python.dll</tt> can be found somewhere in <tt>libs\python\build\bin</tt>
while <tt>hello.pyd</tt> can be found somewhere in
<tt>libs\python\example\tutorial\bin</tt>. After a successful build, you can just
link in these DLLs with the Python interpreter. In Windows for example, you
can simply put these libraries inside the directory where the Python
executable is.</p>
<p>
You may now fire up Python and run our hello module:</p>
<code><pre>
<span class=special>&gt;&gt;&gt; </span><span class=identifier>import </span><span class=identifier>hello
</span><span class=special>&gt;&gt;&gt; </span><span class=identifier>print </span><span class=identifier>hello</span><span class=special>.</span><span class=identifier>greet</span><span class=special>()
</span><span class=identifier>hello</span><span class=special>, </span><span class=identifier>world
</span></pre></code>
<blockquote><p><b>There you go... Have fun!</b></p></blockquote><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="quickstart.html"><img src="theme/l_arr.gif" border="0"></a></td>
<td width="20"><a href="exposing_classes.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

@@ -1,169 +0,0 @@
<html>
<head>
<!-- Generated by the Spirit (http://spirit.sf.net) QuickDoc -->
<title>Call Policies</title>
<link rel="stylesheet" href="theme/style.css" type="text/css">
<link rel="prev" href="functions.html">
<link rel="next" href="overloading.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>Call Policies</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="functions.html"><img src="theme/l_arr.gif" border="0"></a></td>
<td width="20"><a href="overloading.html"><img src="theme/r_arr.gif" border="0"></a></td>
</tr>
</table>
<p>
In C++, we often deal with arguments and return types such as pointers
and references. Such primitive types are rather, ummmm, low level and
they really don't tell us much. At the very least, we don't know the
owner of the pointer or the referenced object. No wonder languages
such as Java and Python never deal with such low level entities. In
C++, it's usually considered a good practice to use smart pointers
which exactly describe ownership semantics. Still, even good C++
interfaces use raw references and pointers sometimes, so Boost.Python
must deal with them. To do this, it may need your help. Consider the
following C++ function:</p>
<code><pre>
<span class=identifier>X</span><span class=special>&amp; </span><span class=identifier>f</span><span class=special>(</span><span class=identifier>Y</span><span class=special>&amp; </span><span class=identifier>y</span><span class=special>, </span><span class=identifier>Z</span><span class=special>* </span><span class=identifier>z</span><span class=special>);
</span></pre></code>
<p>
How should the library wrap this function? A naive approach builds a
Python X object around result reference. This strategy might or might
not work out. Here's an example where it didn't</p>
<code><pre>
<span class=special>&gt;&gt;&gt; </span><span class=identifier>x </span><span class=special>= </span><span class=identifier>f</span><span class=special>(</span><span class=identifier>y</span><span class=special>, </span><span class=identifier>z</span><span class=special>) </span>##<span class=identifier>x </span><span class=identifier>refers </span><span class=identifier>to </span><span class=identifier>some </span><span class=identifier>C</span><span class=special>++ </span><span class=identifier>X
</span><span class=special>&gt;&gt;&gt; </span><span class=identifier>del </span><span class=identifier>y
</span><span class=special>&gt;&gt;&gt; </span><span class=identifier>x</span><span class=special>.</span><span class=identifier>some_method</span><span class=special>() </span>##<span class=identifier>CRASH</span><span class=special>!
</span></pre></code>
<p>
What's the problem?</p>
<p>
Well, what if f() was implemented as shown below:</p>
<code><pre>
<span class=identifier>X</span><span class=special>&amp; </span><span class=identifier>f</span><span class=special>(</span><span class=identifier>Y</span><span class=special>&amp; </span><span class=identifier>y</span><span class=special>, </span><span class=identifier>Z</span><span class=special>* </span><span class=identifier>z</span><span class=special>)
{
</span><span class=identifier>y</span><span class=special>.</span><span class=identifier>z </span><span class=special>= </span><span class=identifier>z</span><span class=special>;
</span><span class=keyword>return </span><span class=identifier>y</span><span class=special>.</span><span class=identifier>x</span><span class=special>;
}
</span></pre></code>
<p>
The problem is that the lifetime of result X&amp; is tied to the lifetime
of y, because the f() returns a reference to a member of the y
object. This idiom is is not uncommon and perfectly acceptable in the
context of C++. However, Python users should not be able to crash the
system just by using our C++ interface. In this case deleting y will
invalidate the reference to X. We have a dangling reference.</p>
<p>
Here's what's happening:</p>
<ol><li><tt>f</tt> is called passing in a reference to <tt>y</tt> and a pointer to <tt>z</tt></li><li>A reference to <tt>y.x</tt> is returned</li><li><tt>y</tt> is deleted. <tt>x</tt> is a dangling reference</li><li><tt>x.some_method()</tt> is called</li><li><b>BOOM!</b></li></ol><p>
We could copy result into a new object:</p>
<code><pre>
<span class=special>&gt;&gt;&gt; </span><span class=identifier>f</span><span class=special>(</span><span class=identifier>y</span><span class=special>, </span><span class=identifier>z</span><span class=special>).</span><span class=identifier>set</span><span class=special>(</span><span class=number>42</span><span class=special>) </span>##<span class=identifier>Result </span><span class=identifier>disappears
</span><span class=special>&gt;&gt;&gt; </span><span class=identifier>y</span><span class=special>.</span><span class=identifier>x</span><span class=special>.</span><span class=identifier>get</span><span class=special>() </span>##<span class=identifier>No </span><span class=identifier>crash</span><span class=special>, </span><span class=identifier>but </span><span class=identifier>still </span><span class=identifier>bad
</span><span class=number>3.14
</span></pre></code>
<p>
This is not really our intent of our C++ interface. We've broken our
promise that the Python interface should reflect the C++ interface as
closely as possible.</p>
<p>
Our problems do not end there. Suppose Y is implemented as follows:</p>
<code><pre>
<span class=keyword>struct </span><span class=identifier>Y
</span><span class=special>{
</span><span class=identifier>X </span><span class=identifier>x</span><span class=special>; </span><span class=identifier>Z</span><span class=special>* </span><span class=identifier>z</span><span class=special>;
</span><span class=keyword>int </span><span class=identifier>z_value</span><span class=special>() { </span><span class=keyword>return </span><span class=identifier>z</span><span class=special>-&gt;</span><span class=identifier>value</span><span class=special>(); }
};
</span></pre></code>
<p>
Notice that the data member <tt>z</tt> is held by class Y using a raw
pointer. Now we have a potential dangling pointer problem inside Y:</p>
<code><pre>
<span class=special>&gt;&gt;&gt; </span><span class=identifier>x </span><span class=special>= </span><span class=identifier>f</span><span class=special>(</span><span class=identifier>y</span><span class=special>, </span><span class=identifier>z</span><span class=special>) </span>##<span class=identifier>y </span><span class=identifier>refers </span><span class=identifier>to </span><span class=identifier>z
</span><span class=special>&gt;&gt;&gt; </span><span class=identifier>del </span><span class=identifier>z </span>##<span class=identifier>Kill </span><span class=identifier>the </span><span class=identifier>z </span><span class=identifier>object
</span><span class=special>&gt;&gt;&gt; </span><span class=identifier>y</span><span class=special>.</span><span class=identifier>z_value</span><span class=special>() </span>##<span class=identifier>CRASH</span><span class=special>!
</span></pre></code>
<p>
For reference, here's the implementation of <tt>f</tt> again:</p>
<code><pre>
<span class=identifier>X</span><span class=special>&amp; </span><span class=identifier>f</span><span class=special>(</span><span class=identifier>Y</span><span class=special>&amp; </span><span class=identifier>y</span><span class=special>, </span><span class=identifier>Z</span><span class=special>* </span><span class=identifier>z</span><span class=special>)
{
</span><span class=identifier>y</span><span class=special>.</span><span class=identifier>z </span><span class=special>= </span><span class=identifier>z</span><span class=special>;
</span><span class=keyword>return </span><span class=identifier>y</span><span class=special>.</span><span class=identifier>x</span><span class=special>;
}
</span></pre></code>
<p>
Here's what's happening:</p>
<ol><li><tt>f</tt> is called passing in a reference to <tt>y</tt> and a pointer to <tt>z</tt></li><li>A pointer to <tt>z</tt> is held by <tt>y</tt></li><li>A reference to <tt>y.x</tt> is returned</li><li><tt>z</tt> is deleted. <tt>y.z</tt> is a dangling pointer</li><li><tt>y.z_value()</tt> is called</li><li><tt>z-&gt;value()</tt> is called</li><li><b>BOOM!</b></li></ol><a name="call_policies"></a><h2>Call Policies</h2><p>
Call Policies may be used in situations such as the example detailed above.
In our example, <tt>return_internal_reference</tt> and <tt>with_custodian_and_ward</tt>
are our friends:</p>
<code><pre>
<span class=identifier>def</span><span class=special>(</span><span class=string>&quot;f&quot;</span><span class=special>, </span><span class=identifier>f</span><span class=special>,
</span><span class=identifier>return_internal_reference</span><span class=special>&lt;</span><span class=number>1</span><span class=special>,
</span><span class=identifier>with_custodian_and_ward</span><span class=special>&lt;</span><span class=number>1</span><span class=special>, </span><span class=number>2</span><span class=special>&gt; &gt;());
</span></pre></code>
<p>
What are the <tt>1</tt> and <tt>2</tt> parameters, you ask?</p>
<code><pre>
<span class=identifier>return_internal_reference</span><span class=special>&lt;</span><span class=number>1
</span></pre></code>
<p>
Informs Boost.Python that the first argument, in our case <tt>Y&amp; y</tt>, is the
owner of the returned reference: <tt>X&amp;</tt>. The &quot;<tt>1</tt>&quot; simply specifies the
first argument. In short: &quot;return an internal reference <tt>X&amp;</tt> owned by the
1st argument <tt>Y&amp; y</tt>&quot;.</p>
<code><pre>
<span class=identifier>with_custodian_and_ward</span><span class=special>&lt;</span><span class=number>1</span><span class=special>, </span><span class=number>2</span><span class=special>&gt;
</span></pre></code>
<p>
Informs Boost.Python that the lifetime of the argument indicated by ward
(i.e. the 2nd argument: <tt>Z* z</tt>) is dependent on the lifetime of the
argument indicated by custodian (i.e. the 1st argument: <tt>Y&amp; y</tt>).</p>
<p>
It is also important to note that we have defined two policies above. Two
or more policies can be composed by chaining. Here's the general syntax:</p>
<code><pre>
<span class=identifier>policy1</span><span class=special>&lt;</span><span class=identifier>args</span><span class=special>...,
</span><span class=identifier>policy2</span><span class=special>&lt;</span><span class=identifier>args</span><span class=special>...,
</span><span class=identifier>policy3</span><span class=special>&lt;</span><span class=identifier>args</span><span class=special>...&gt; &gt; &gt;
</span></pre></code>
<p>
Here is the list of predefined call policies. A complete reference detailing
these can be found <a href="../../v2/reference.html#models_of_call_policies">
here</a>.</p>
<ul><li><b>with_custodian_and_ward</b><br> Ties lifetimes of the arguments</li><li><b>with_custodian_and_ward_postcall</b><br> Ties lifetimes of the arguments and results</li><li><b>return_internal_reference</b><br> Ties lifetime of one argument to that of result</li><li><b>return_value_policy&lt;T&gt; with T one of:</b><br></li><li><b>reference_existing_object</b><br>naïve (dangerous) approach</li><li><b>copy_const_reference</b><br>Boost.Python v1 approach</li><li><b>copy_non_const_reference</b><br></li><li><b>manage_new_object</b><br> Adopt a pointer and hold the instance</li></ul><table width="80%" border="0" align="center">
<tr>
<td class="note_box">
<img src="theme/smiley.gif"></img> <b>Remember the Zen, Luke:</b><br><br>
&quot;Explicit is better than implicit&quot;<br>
&quot;In the face of ambiguity, refuse the temptation to guess&quot;<br> </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="functions.html"><img src="theme/l_arr.gif" border="0"></a></td>
<td width="20"><a href="overloading.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

@@ -1,78 +0,0 @@
<html>
<head>
<!-- Generated by the Spirit (http://spirit.sf.net) QuickDoc -->
<title>Class Data Members</title>
<link rel="stylesheet" href="theme/style.css" type="text/css">
<link rel="prev" href="constructors.html">
<link rel="next" href="class_properties.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>Class Data Members</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="constructors.html"><img src="theme/l_arr.gif" border="0"></a></td>
<td width="20"><a href="class_properties.html"><img src="theme/r_arr.gif" border="0"></a></td>
</tr>
</table>
<p>
Data members may also be exposed to Python so that they can be
accessed as attributes of the corresponding Python class. Each data
member that we wish to be exposed may be regarded as <b>read-only</b> or
<b>read-write</b>. Consider this class <tt>Var</tt>:</p>
<code><pre>
<span class=keyword>struct </span><span class=identifier>Var
</span><span class=special>{
</span><span class=identifier>Var</span><span class=special>(</span><span class=identifier>std</span><span class=special>::</span><span class=identifier>string </span><span class=identifier>name</span><span class=special>) : </span><span class=identifier>name</span><span class=special>(</span><span class=identifier>name</span><span class=special>), </span><span class=identifier>value</span><span class=special>() {}
</span><span class=identifier>std</span><span class=special>::</span><span class=identifier>string </span><span class=keyword>const </span><span class=identifier>name</span><span class=special>;
</span><span class=keyword>float </span><span class=identifier>value</span><span class=special>;
};
</span></pre></code>
<p>
Our C++ <tt>Var</tt> class and its data members can be exposed to Python:</p>
<code><pre>
<span class=identifier>class_</span><span class=special>&lt;</span><span class=identifier>Var</span><span class=special>&gt;(</span><span class=string>&quot;Var&quot;</span><span class=special>, </span><span class=identifier>init</span><span class=special>&lt;</span><span class=identifier>std</span><span class=special>::</span><span class=identifier>string</span><span class=special>&gt;())
.</span><span class=identifier>def_readonly</span><span class=special>(</span><span class=string>&quot;name&quot;</span><span class=special>, &amp;</span><span class=identifier>Var</span><span class=special>::</span><span class=identifier>name</span><span class=special>)
.</span><span class=identifier>def_readwrite</span><span class=special>(</span><span class=string>&quot;value&quot;</span><span class=special>, &amp;</span><span class=identifier>Var</span><span class=special>::</span><span class=identifier>value</span><span class=special>);
</span></pre></code>
<p>
Then, in Python, assuming we have placed our Var class inside the namespace
hello as we did before:</p>
<code><pre>
<span class=special>&gt;&gt;&gt; </span><span class=identifier>x </span><span class=special>= </span><span class=identifier>hello</span><span class=special>.</span><span class=identifier>Var</span><span class=special>(</span><span class=literal>'pi'</span><span class=special>)
&gt;&gt;&gt; </span><span class=identifier>x</span><span class=special>.</span><span class=identifier>value </span><span class=special>= </span><span class=number>3.14
</span><span class=special>&gt;&gt;&gt; </span><span class=identifier>print </span><span class=identifier>x</span><span class=special>.</span><span class=identifier>name</span><span class=special>, </span><span class=literal>'is around'</span><span class=special>, </span><span class=identifier>x</span><span class=special>.</span><span class=identifier>value
</span><span class=identifier>pi </span><span class=identifier>is </span><span class=identifier>around </span><span class=number>3.14
</span></pre></code>
<p>
Note that <tt>name</tt> is exposed as <b>read-only</b> while <tt>value</tt> is exposed
as <b>read-write</b>.</p>
<code><pre>
&gt;&gt;&gt; x.name = 'e' # can't change name
Traceback (most recent call last):
File &quot;&lt;stdin&gt;&quot;, line 1, in ?
AttributeError: can't set attribute
</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="constructors.html"><img src="theme/l_arr.gif" border="0"></a></td>
<td width="20"><a href="class_properties.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

@@ -1,109 +0,0 @@
<html>
<head>
<!-- Generated by the Spirit (http://spirit.sf.net) QuickDoc -->
<title>Class Operators/Special Functions</title>
<link rel="stylesheet" href="theme/style.css" type="text/css">
<link rel="prev" href="virtual_functions_with_default_implementations.html">
<link rel="next" href="functions.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>Class Operators/Special Functions</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="virtual_functions_with_default_implementations.html"><img src="theme/l_arr.gif" border="0"></a></td>
<td width="20"><a href="functions.html"><img src="theme/r_arr.gif" border="0"></a></td>
</tr>
</table>
<a name="python_operators"></a><h2>Python Operators</h2><p>
C is well known for the abundance of operators. C++ extends this to the
extremes by allowing operator overloading. Boost.Python takes advantage of
this and makes it easy to wrap C++ operator-powered classes.</p>
<p>
Consider a file position class <tt>FilePos</tt> and a set of operators that take
on FilePos instances:</p>
<code><pre>
<span class=keyword>class </span><span class=identifier>FilePos </span><span class=special>{ /*...*/ };
</span><span class=identifier>FilePos </span><span class=keyword>operator</span><span class=special>+(</span><span class=identifier>FilePos</span><span class=special>, </span><span class=keyword>int</span><span class=special>);
</span><span class=identifier>FilePos </span><span class=keyword>operator</span><span class=special>+(</span><span class=keyword>int</span><span class=special>, </span><span class=identifier>FilePos</span><span class=special>);
</span><span class=keyword>int </span><span class=keyword>operator</span><span class=special>-(</span><span class=identifier>FilePos</span><span class=special>, </span><span class=identifier>FilePos</span><span class=special>);
</span><span class=identifier>FilePos </span><span class=keyword>operator</span><span class=special>-(</span><span class=identifier>FilePos</span><span class=special>, </span><span class=keyword>int</span><span class=special>);
</span><span class=identifier>FilePos</span><span class=special>&amp; </span><span class=keyword>operator</span><span class=special>+=(</span><span class=identifier>FilePos</span><span class=special>&amp;, </span><span class=keyword>int</span><span class=special>);
</span><span class=identifier>FilePos</span><span class=special>&amp; </span><span class=keyword>operator</span><span class=special>-=(</span><span class=identifier>FilePos</span><span class=special>&amp;, </span><span class=keyword>int</span><span class=special>);
</span><span class=keyword>bool </span><span class=keyword>operator</span><span class=special>&lt;(</span><span class=identifier>FilePos</span><span class=special>, </span><span class=identifier>FilePos</span><span class=special>);
</span></pre></code>
<p>
The class and the various operators can be mapped to Python rather easily
and intuitively:</p>
<code><pre>
<span class=identifier>class_</span><span class=special>&lt;</span><span class=identifier>FilePos</span><span class=special>&gt;(</span><span class=string>&quot;FilePos&quot;</span><span class=special>)
.</span><span class=identifier>def</span><span class=special>(</span><span class=identifier>self </span><span class=special>+ </span><span class=keyword>int</span><span class=special>()) // </span><span class=identifier>__add__
</span><span class=special>.</span><span class=identifier>def</span><span class=special>(</span><span class=keyword>int</span><span class=special>() + </span><span class=identifier>self</span><span class=special>) // </span><span class=identifier>__radd__
</span><span class=special>.</span><span class=identifier>def</span><span class=special>(</span><span class=identifier>self </span><span class=special>- </span><span class=identifier>self</span><span class=special>) // </span><span class=identifier>__sub__
</span><span class=special>.</span><span class=identifier>def</span><span class=special>(</span><span class=identifier>self </span><span class=special>- </span><span class=keyword>int</span><span class=special>()) // </span><span class=identifier>__sub__
</span><span class=special>.</span><span class=identifier>def</span><span class=special>(</span><span class=identifier>self </span><span class=special>+= </span><span class=keyword>int</span><span class=special>()) // </span><span class=identifier>__iadd__
</span><span class=special>.</span><span class=identifier>def</span><span class=special>(</span><span class=identifier>self </span><span class=special>-= </span><span class=identifier>other</span><span class=special>&lt;</span><span class=keyword>int</span><span class=special>&gt;())
.</span><span class=identifier>def</span><span class=special>(</span><span class=identifier>self </span><span class=special>&lt; </span><span class=identifier>self</span><span class=special>); // </span><span class=identifier>__lt__
</span></pre></code>
<p>
The code snippet above is very clear and needs almost no explanation at
all. It is virtually the same as the operators' signatures. Just take
note that <tt>self</tt> refers to FilePos object. Also, not every class <tt>T</tt> that
you might need to interact with in an operator expression is (cheaply)
default-constructible. You can use <tt>other&lt;T&gt;()</tt> in place of an actual
<tt>T</tt> instance when writing &quot;self expressions&quot;.</p>
<a name="special_methods"></a><h2>Special Methods</h2><p>
Python has a few more <i>Special Methods</i>. Boost.Python supports all of the
standard special method names supported by real Python class instances. A
similar set of intuitive interfaces can also be used to wrap C++ functions
that correspond to these Python <i>special functions</i>. Example:</p>
<code><pre>
<span class=keyword>class </span><span class=identifier>Rational
</span><span class=special>{ </span><span class=keyword>operator </span><span class=keyword>double</span><span class=special>() </span><span class=keyword>const</span><span class=special>; };
</span><span class=identifier>Rational </span><span class=identifier>pow</span><span class=special>(</span><span class=identifier>Rational</span><span class=special>, </span><span class=identifier>Rational</span><span class=special>);
</span><span class=identifier>Rational </span><span class=identifier>abs</span><span class=special>(</span><span class=identifier>Rational</span><span class=special>);
</span><span class=identifier>ostream</span><span class=special>&amp; </span><span class=keyword>operator</span><span class=special>&lt;&lt;(</span><span class=identifier>ostream</span><span class=special>&amp;,</span><span class=identifier>Rational</span><span class=special>);
</span><span class=identifier>class_</span><span class=special>&lt;</span><span class=identifier>Rational</span><span class=special>&gt;()
.</span><span class=identifier>def</span><span class=special>(</span><span class=identifier>float_</span><span class=special>(</span><span class=identifier>self</span><span class=special>)) // </span><span class=identifier>__float__
</span><span class=special>.</span><span class=identifier>def</span><span class=special>(</span><span class=identifier>pow</span><span class=special>(</span><span class=identifier>self</span><span class=special>, </span><span class=identifier>other</span><span class=special>&lt;</span><span class=identifier>Rational</span><span class=special>&gt;)) // </span><span class=identifier>__pow__
</span><span class=special>.</span><span class=identifier>def</span><span class=special>(</span><span class=identifier>abs</span><span class=special>(</span><span class=identifier>self</span><span class=special>)) // </span><span class=identifier>__abs__
</span><span class=special>.</span><span class=identifier>def</span><span class=special>(</span><span class=identifier>str</span><span class=special>(</span><span class=identifier>self</span><span class=special>)) // </span><span class=identifier>__str__
</span><span class=special>;
</span></pre></code>
<p>
Need we say more?</p>
<table width="80%" border="0" align="center">
<tr>
<td class="note_box">
<img src="theme/lens.gif"></img> What is the business of <tt>operator&lt;&lt;</tt> <tt>.def(str(self))</tt>?
Well, the method <tt>str</tt> requires the <tt>operator&lt;&lt;</tt> to do its work (i.e.
<tt>operator&lt;&lt;</tt> is used by the method defined by def(str(self)). </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="virtual_functions_with_default_implementations.html"><img src="theme/l_arr.gif" border="0"></a></td>
<td width="20"><a href="functions.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

@@ -1,81 +0,0 @@
<html>
<head>
<!-- Generated by the Spirit (http://spirit.sf.net) QuickDoc -->
<title>Class Properties</title>
<link rel="stylesheet" href="theme/style.css" type="text/css">
<link rel="prev" href="class_data_members.html">
<link rel="next" href="inheritance.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>Class Properties</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="class_data_members.html"><img src="theme/l_arr.gif" border="0"></a></td>
<td width="20"><a href="inheritance.html"><img src="theme/r_arr.gif" border="0"></a></td>
</tr>
</table>
<p>
In C++, classes with public data members are usually frowned
upon. Well designed classes that take advantage of encapsulation hide
the class' data members. The only way to access the class' data is
through access (getter/setter) functions. Access functions expose class
properties. Here's an example:</p>
<code><pre>
<span class=keyword>struct </span><span class=identifier>Num
</span><span class=special>{
</span><span class=identifier>Num</span><span class=special>();
</span><span class=keyword>float </span><span class=identifier>get</span><span class=special>() </span><span class=keyword>const</span><span class=special>;
</span><span class=keyword>void </span><span class=identifier>set</span><span class=special>(</span><span class=keyword>float </span><span class=identifier>value</span><span class=special>);
...
};
</span></pre></code>
<p>
However, in Python attribute access is fine; it doesn't neccessarily break
encapsulation to let users handle attributes directly, because the
attributes can just be a different syntax for a method call. Wrapping our
<tt>Num</tt> class using Boost.Python:</p>
<code><pre>
<span class=identifier>class_</span><span class=special>&lt;</span><span class=identifier>Num</span><span class=special>&gt;(</span><span class=string>&quot;Num&quot;</span><span class=special>)
.</span><span class=identifier>add_property</span><span class=special>(</span><span class=string>&quot;rovalue&quot;</span><span class=special>, &amp;</span><span class=identifier>Num</span><span class=special>::</span><span class=identifier>get</span><span class=special>)
.</span><span class=identifier>add_property</span><span class=special>(</span><span class=string>&quot;value&quot;</span><span class=special>, &amp;</span><span class=identifier>Num</span><span class=special>::</span><span class=identifier>get</span><span class=special>, &amp;</span><span class=identifier>Num</span><span class=special>::</span><span class=identifier>set</span><span class=special>);
</span></pre></code>
<p>
And at last, in Python:</p>
<code><pre>
<span class=special>&gt;&gt;&gt; </span><span class=identifier>x </span><span class=special>= </span><span class=identifier>Num</span><span class=special>()
&gt;&gt;&gt; </span><span class=identifier>x</span><span class=special>.</span><span class=identifier>value </span><span class=special>= </span><span class=number>3.14
</span><span class=special>&gt;&gt;&gt; </span><span class=identifier>x</span><span class=special>.</span><span class=identifier>value</span><span class=special>, </span><span class=identifier>x</span><span class=special>.</span><span class=identifier>rovalue
</span><span class=special>(</span><span class=number>3.14</span><span class=special>, </span><span class=number>3.14</span><span class=special>)
&gt;&gt;&gt; </span><span class=identifier>x</span><span class=special>.</span><span class=identifier>rovalue </span><span class=special>= </span><span class=number>2.17 </span>##<span class=identifier>error</span><span class=special>!
</span></pre></code>
<p>
Take note that the class property <tt>rovalue</tt> is exposed as <b>read-only</b>
since the <tt>rovalue</tt> setter member function is not passed in:</p>
<code><pre>
<span class=special>.</span><span class=identifier>add_property</span><span class=special>(</span><span class=string>&quot;rovalue&quot;</span><span class=special>, &amp;</span><span class=identifier>Num</span><span class=special>::</span><span class=identifier>get</span><span class=special>)
</span></pre></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="class_data_members.html"><img src="theme/l_arr.gif" border="0"></a></td>
<td width="20"><a href="inheritance.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

@@ -1,129 +0,0 @@
<html>
<head>
<!-- Generated by the Spirit (http://spirit.sf.net) QuickDoc -->
<title>Class Virtual Functions</title>
<link rel="stylesheet" href="theme/style.css" type="text/css">
<link rel="prev" href="inheritance.html">
<link rel="next" href="deriving_a_python_class.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>Class Virtual Functions</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="inheritance.html"><img src="theme/l_arr.gif" border="0"></a></td>
<td width="20"><a href="deriving_a_python_class.html"><img src="theme/r_arr.gif" border="0"></a></td>
</tr>
</table>
<p>
In this section, we shall learn how to make functions behave
polymorphically through virtual functions. Continuing our example, let us
add a virtual function to our <tt>Base</tt> class:</p>
<code><pre>
<span class=keyword>struct </span><span class=identifier>Base
</span><span class=special>{
</span><span class=keyword>virtual </span><span class=keyword>int </span><span class=identifier>f</span><span class=special>() = </span><span class=number>0</span><span class=special>;
};
</span></pre></code>
<p>
Since <tt>f</tt> is a pure virtual function, <tt>Base</tt> is now an abstract
class. Given an instance of our class, the free function <tt>call_f</tt>
calls some implementation of this virtual function in a concrete
derived class:</p>
<code><pre>
<span class=keyword>int </span><span class=identifier>call_f</span><span class=special>(</span><span class=identifier>Base</span><span class=special>&amp; </span><span class=identifier>b</span><span class=special>) { </span><span class=keyword>return </span><span class=identifier>b</span><span class=special>.</span><span class=identifier>f</span><span class=special>(); }
</span></pre></code>
<p>
To allow this function to be implemented in a Python derived class, we
need to create a class wrapper:</p>
<code><pre>
<span class=keyword>struct </span><span class=identifier>BaseWrap </span><span class=special>: </span><span class=identifier>Base
</span><span class=special>{
</span><span class=identifier>BaseWrap</span><span class=special>(</span><span class=identifier>PyObject</span><span class=special>* </span><span class=identifier>self_</span><span class=special>)
: </span><span class=identifier>self</span><span class=special>(</span><span class=identifier>self_</span><span class=special>) {}
</span><span class=keyword>int </span><span class=identifier>f</span><span class=special>() { </span><span class=keyword>return </span><span class=identifier>call_method</span><span class=special>&lt;</span><span class=keyword>int</span><span class=special>&gt;(</span><span class=identifier>self</span><span class=special>, </span><span class=string>&quot;f&quot;</span><span class=special>); }
</span><span class=identifier>PyObject</span><span class=special>* </span><span class=identifier>self</span><span class=special>;
};
</span></pre></code>
<table width="80%" border="0" align="center">
<tr>
<td class="note_box">
<img src="theme/lens.gif"></img> <b>member function and methods</b><br><br> Python, like
many object oriented languages uses the term <b>methods</b>. Methods
correspond roughly to C++'s <b>member functions</b> </td>
</tr>
</table>
<p>
Our class wrapper <tt>BaseWrap</tt> is derived from <tt>Base</tt>. Its overridden
virtual member function <tt>f</tt> in effect calls the corresponding method
of the Python object <tt>self</tt>, which is a pointer back to the Python
<tt>Base</tt> object holding our <tt>BaseWrap</tt> instance.</p>
<table width="80%" border="0" align="center">
<tr>
<td class="note_box">
<img src="theme/note.gif"></img> <b>Why do we need BaseWrap?</b><br><br>
<i>You may ask</i>, &quot;Why do we need the <tt>BaseWrap</tt> derived class? This could
have been designed so that everything gets done right inside of
Base.&quot;<br><br>
One of the goals of Boost.Python is to be minimally intrusive on an
existing C++ design. In principle, it should be possible to expose the
interface for a 3rd party library without changing it. To unintrusively
hook into the virtual functions so that a Python override may be called, we
must use a derived class.<br><br>
Note however that you don't need to do this to get methods overridden
in Python to behave virtually when called <i>from</i> <b>Python</b>. The only
time you need to do the <tt>BaseWrap</tt> dance is when you have a virtual
function that's going to be overridden in Python and called
polymorphically <i>from</i> <b>C++</b>. </td>
</tr>
</table>
<p>
Wrapping <tt>Base</tt> and the free function <tt>call_f</tt>:</p>
<code><pre>
<span class=identifier>class_</span><span class=special>&lt;</span><span class=identifier>Base</span><span class=special>, </span><span class=identifier>BaseWrap</span><span class=special>, </span><span class=identifier>boost</span><span class=special>::</span><span class=identifier>noncopyable</span><span class=special>&gt;(</span><span class=string>&quot;Base&quot;</span><span class=special>, </span><span class=identifier>no_init</span><span class=special>)
;
</span><span class=identifier>def</span><span class=special>(</span><span class=string>&quot;call_f&quot;</span><span class=special>, </span><span class=identifier>call_f</span><span class=special>);
</span></pre></code>
<p>
Notice that we parameterized the <tt>class_</tt> template with <tt>BaseWrap</tt> as the
second parameter. What is <tt>noncopyable</tt>? Without it, the library will try
to create code for converting Base return values of wrapped functions to
Python. To do that, it needs Base's copy constructor... which isn't
available, since Base is an abstract class.</p>
<p>
In Python, let us try to instantiate our <tt>Base</tt> class:</p>
<code><pre>
<span class=special>&gt;&gt;&gt; </span><span class=identifier>base </span><span class=special>= </span><span class=identifier>Base</span><span class=special>()
</span><span class=identifier>RuntimeError</span><span class=special>: </span><span class=identifier>This </span><span class=keyword>class </span><span class=identifier>cannot </span><span class=identifier>be </span><span class=identifier>instantiated </span><span class=identifier>from </span><span class=identifier>Python
</span></pre></code>
<p>
Why is it an error? <tt>Base</tt> is an abstract class. As such it is advisable
to define the Python wrapper with <tt>no_init</tt> as we have done above. Doing
so will disallow abstract base classes such as <tt>Base</tt> to be instantiated.</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="inheritance.html"><img src="theme/l_arr.gif" border="0"></a></td>
<td width="20"><a href="deriving_a_python_class.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

@@ -1,102 +0,0 @@
<html>
<head>
<!-- Generated by the Spirit (http://spirit.sf.net) QuickDoc -->
<title>Constructors</title>
<link rel="stylesheet" href="theme/style.css" type="text/css">
<link rel="prev" href="exposing_classes.html">
<link rel="next" href="class_data_members.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>Constructors</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="exposing_classes.html"><img src="theme/l_arr.gif" border="0"></a></td>
<td width="20"><a href="class_data_members.html"><img src="theme/r_arr.gif" border="0"></a></td>
</tr>
</table>
<p>
Our previous example didn't have any explicit constructors.
Since <tt>World</tt> is declared as a plain struct, it has an implicit default
constructor. Boost.Python exposes the default constructor by default,
which is why we were able to write</p>
<code><pre>
<span class=special>&gt;&gt;&gt; </span><span class=identifier>planet </span><span class=special>= </span><span class=identifier>hello</span><span class=special>.</span><span class=identifier>World</span><span class=special>()
</span></pre></code>
<p>
We may wish to wrap a class with a non-default constructor. Let us
build on our previous example:</p>
<code><pre>
<span class=keyword>struct </span><span class=identifier>World
</span><span class=special>{
</span><span class=identifier>World</span><span class=special>(</span><span class=identifier>std</span><span class=special>::</span><span class=identifier>string </span><span class=identifier>msg</span><span class=special>): </span><span class=identifier>msg</span><span class=special>(</span><span class=identifier>msg</span><span class=special>) {} // </span><span class=identifier>added </span><span class=identifier>constructor
</span><span class=keyword>void </span><span class=identifier>set</span><span class=special>(</span><span class=identifier>std</span><span class=special>::</span><span class=identifier>string </span><span class=identifier>msg</span><span class=special>) { </span><span class=keyword>this</span><span class=special>-&gt;</span><span class=identifier>msg </span><span class=special>= </span><span class=identifier>msg</span><span class=special>; }
</span><span class=identifier>std</span><span class=special>::</span><span class=identifier>string </span><span class=identifier>greet</span><span class=special>() { </span><span class=keyword>return </span><span class=identifier>msg</span><span class=special>; }
</span><span class=identifier>std</span><span class=special>::</span><span class=identifier>string </span><span class=identifier>msg</span><span class=special>;
};
</span></pre></code>
<p>
This time <tt>World</tt> has no default constructor; our previous
wrapping code would fail to compile when the library tried to expose
it. We have to tell <tt>class_&lt;World&gt;</tt> about the constructor we want to
expose instead.</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=keyword>using </span><span class=keyword>namespace </span><span class=identifier>boost</span><span class=special>::</span><span class=identifier>python</span><span class=special>;
</span><span class=identifier>BOOST_PYTHON_MODULE</span><span class=special>(</span><span class=identifier>hello</span><span class=special>)
{
</span><span class=identifier>class_</span><span class=special>&lt;</span><span class=identifier>World</span><span class=special>&gt;(</span><span class=string>&quot;World&quot;</span><span class=special>, </span><span class=identifier>init</span><span class=special>&lt;</span><span class=identifier>std</span><span class=special>::</span><span class=identifier>string</span><span class=special>&gt;())
.</span><span class=identifier>def</span><span class=special>(</span><span class=string>&quot;greet&quot;</span><span class=special>, &amp;</span><span class=identifier>World</span><span class=special>::</span><span class=identifier>greet</span><span class=special>)
.</span><span class=identifier>def</span><span class=special>(</span><span class=string>&quot;set&quot;</span><span class=special>, &amp;</span><span class=identifier>World</span><span class=special>::</span><span class=identifier>set</span><span class=special>)
;
}
</span></pre></code>
<p>
<tt>init&lt;std::string&gt;()</tt> exposes the constructor taking in a
<tt>std::string</tt> (in Python, constructors are spelled
&quot;<tt>&quot;__init__&quot;</tt>&quot;).</p>
<p>
We can expose additional constructors by passing more <tt>init&lt;...&gt;</tt>s to
the <tt>def()</tt> member function. Say for example we have another World
constructor taking in two doubles:</p>
<code><pre>
<span class=identifier>class_</span><span class=special>&lt;</span><span class=identifier>World</span><span class=special>&gt;(</span><span class=string>&quot;World&quot;</span><span class=special>, </span><span class=identifier>init</span><span class=special>&lt;</span><span class=identifier>std</span><span class=special>::</span><span class=identifier>string</span><span class=special>&gt;())
.</span><span class=identifier>def</span><span class=special>(</span><span class=identifier>init</span><span class=special>&lt;</span><span class=keyword>double</span><span class=special>, </span><span class=keyword>double</span><span class=special>&gt;())
.</span><span class=identifier>def</span><span class=special>(</span><span class=string>&quot;greet&quot;</span><span class=special>, &amp;</span><span class=identifier>World</span><span class=special>::</span><span class=identifier>greet</span><span class=special>)
.</span><span class=identifier>def</span><span class=special>(</span><span class=string>&quot;set&quot;</span><span class=special>, &amp;</span><span class=identifier>World</span><span class=special>::</span><span class=identifier>set</span><span class=special>)
;
</span></pre></code>
<p>
On the other hand, if we do not wish to expose any constructors at
all, we may use <tt>no_init</tt> instead:</p>
<code><pre>
<span class=identifier>class_</span><span class=special>&lt;</span><span class=identifier>Abstract</span><span class=special>&gt;(</span><span class=string>&quot;Abstract&quot;</span><span class=special>, </span><span class=identifier>no_init</span><span class=special>)
</span></pre></code>
<p>
This actually adds an <tt>__init__</tt> method which always raises a
Python RuntimeError exception.</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="exposing_classes.html"><img src="theme/l_arr.gif" border="0"></a></td>
<td width="20"><a href="class_data_members.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

@@ -1,158 +0,0 @@
<html>
<head>
<!-- Generated by the Spirit (http://spirit.sf.net) QuickDoc -->
<title>Default Arguments</title>
<link rel="stylesheet" href="theme/style.css" type="text/css">
<link rel="prev" href="overloading.html">
<link rel="next" href="auto_overloading.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>Default Arguments</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="overloading.html"><img src="theme/l_arr.gif" border="0"></a></td>
<td width="20"><a href="auto_overloading.html"><img src="theme/r_arr.gif" border="0"></a></td>
</tr>
</table>
<p>
Boost.Python wraps (member) function pointers. Unfortunately, C++ function
pointers carry no default argument info. Take a function <tt>f</tt> with default
arguments:</p>
<code><pre>
<span class=keyword>int </span><span class=identifier>f</span><span class=special>(</span><span class=keyword>int</span><span class=special>, </span><span class=keyword>double </span><span class=special>= </span><span class=number>3.14</span><span class=special>, </span><span class=keyword>char </span><span class=keyword>const</span><span class=special>* = </span><span class=string>&quot;hello&quot;</span><span class=special>);
</span></pre></code>
<p>
But the type of a pointer to the function <tt>f</tt> has no information
about its default arguments:</p>
<code><pre>
<span class=keyword>int</span><span class=special>(*</span><span class=identifier>g</span><span class=special>)(</span><span class=keyword>int</span><span class=special>,</span><span class=keyword>double</span><span class=special>,</span><span class=keyword>char </span><span class=keyword>const</span><span class=special>*) = </span><span class=identifier>f</span><span class=special>; // </span><span class=identifier>defaults </span><span class=identifier>lost</span><span class=special>!
</span></pre></code>
<p>
When we pass this function pointer to the <tt>def</tt> function, there is no way
to retrieve the default arguments:</p>
<code><pre>
<span class=identifier>def</span><span class=special>(</span><span class=string>&quot;f&quot;</span><span class=special>, </span><span class=identifier>f</span><span class=special>); // </span><span class=identifier>defaults </span><span class=identifier>lost</span><span class=special>!
</span></pre></code>
<p>
Because of this, when wrapping C++ code, we had to resort to manual
wrapping as outlined in the <a href="overloading.html">
previous section</a>, or
writing thin wrappers:</p>
<code><pre>
<span class=comment>// write &quot;thin wrappers&quot;
</span><span class=keyword>int </span><span class=identifier>f1</span><span class=special>(</span><span class=keyword>int </span><span class=identifier>x</span><span class=special>) { </span><span class=identifier>f</span><span class=special>(</span><span class=identifier>x</span><span class=special>); }
</span><span class=keyword>int </span><span class=identifier>f2</span><span class=special>(</span><span class=keyword>int </span><span class=identifier>x</span><span class=special>, </span><span class=keyword>double </span><span class=identifier>y</span><span class=special>) { </span><span class=identifier>f</span><span class=special>(</span><span class=identifier>x</span><span class=special>,</span><span class=identifier>y</span><span class=special>); }
/*...*/
// </span><span class=identifier>in </span><span class=identifier>module </span><span class=identifier>init
</span><span class=identifier>def</span><span class=special>(</span><span class=string>&quot;f&quot;</span><span class=special>, </span><span class=identifier>f</span><span class=special>); // </span><span class=identifier>all </span><span class=identifier>arguments
</span><span class=identifier>def</span><span class=special>(</span><span class=string>&quot;f&quot;</span><span class=special>, </span><span class=identifier>f2</span><span class=special>); // </span><span class=identifier>two </span><span class=identifier>arguments
</span><span class=identifier>def</span><span class=special>(</span><span class=string>&quot;f&quot;</span><span class=special>, </span><span class=identifier>f1</span><span class=special>); // </span><span class=identifier>one </span><span class=identifier>argument
</span></pre></code>
<p>
When you want to wrap functions (or member functions) that either:</p>
<ul><li>have default arguments, or</li><li>are overloaded with a common sequence of initial arguments</li></ul><a name="boost_python_function_overloads"></a><h2>BOOST_PYTHON_FUNCTION_OVERLOADS</h2><p>
Boost.Python now has a way to make it easier. For instance, given a function:</p>
<code><pre>
<span class=keyword>int </span><span class=identifier>foo</span><span class=special>(</span><span class=keyword>int </span><span class=identifier>a</span><span class=special>, </span><span class=keyword>char </span><span class=identifier>b </span><span class=special>= </span><span class=number>1</span><span class=special>, </span><span class=keyword>unsigned </span><span class=identifier>c </span><span class=special>= </span><span class=number>2</span><span class=special>, </span><span class=keyword>double </span><span class=identifier>d </span><span class=special>= </span><span class=number>3</span><span class=special>)
{
/*...*/
}
</span></pre></code>
<p>
The macro invocation:</p>
<code><pre>
<span class=identifier>BOOST_PYTHON_FUNCTION_OVERLOADS</span><span class=special>(</span><span class=identifier>foo_overloads</span><span class=special>, </span><span class=identifier>foo</span><span class=special>, </span><span class=number>1</span><span class=special>, </span><span class=number>4</span><span class=special>)
</span></pre></code>
<p>
will automatically create the thin wrappers for us. This macro will create
a class <tt>foo_overloads</tt> that can be passed on to <tt>def(...)</tt>. The third
and fourth macro argument are the minimum arguments and maximum arguments,
respectively. In our <tt>foo</tt> function the minimum number of arguments is 1
and the maximum number of arguments is 4. The <tt>def(...)</tt> function will
automatically add all the foo variants for us:</p>
<code><pre>
<span class=identifier>def</span><span class=special>(</span><span class=string>&quot;foo&quot;</span><span class=special>, </span><span class=identifier>foo</span><span class=special>, </span><span class=identifier>foo_overloads</span><span class=special>());
</span></pre></code>
<a name="boost_python_member_function_overloads"></a><h2>BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS</h2><p>
Objects here, objects there, objects here there everywhere. More frequently
than anything else, we need to expose member functions of our classes to
Python. Then again, we have the same inconveniences as before when default
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
the thin wrappers for wrapping member functions. Let's have an example:</p>
<code><pre>
<span class=keyword>struct </span><span class=identifier>george
</span><span class=special>{
</span><span class=keyword>void
</span><span class=identifier>wack_em</span><span class=special>(</span><span class=keyword>int </span><span class=identifier>a</span><span class=special>, </span><span class=keyword>int </span><span class=identifier>b </span><span class=special>= </span><span class=number>0</span><span class=special>, </span><span class=keyword>char </span><span class=identifier>c </span><span class=special>= </span><span class=literal>'x'</span><span class=special>)
{
/*...*/
}
};
</span></pre></code>
<p>
The macro invocation:</p>
<code><pre>
<span class=identifier>BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS</span><span class=special>(</span><span class=identifier>george_overloads</span><span class=special>, </span><span class=identifier>wack_em</span><span class=special>, </span><span class=number>1</span><span class=special>, </span><span class=number>3</span><span class=special>)
</span></pre></code>
<p>
will generate a set of thin wrappers for george's <tt>wack_em</tt> member function
accepting a minimum of 1 and a maximum of 3 arguments (i.e. the third and
fourth macro argument). The thin wrappers are all enclosed in a class named
<tt>george_overloads</tt> that can then be used as an argument to <tt>def(...)</tt>:</p>
<code><pre>
<span class=special>.</span><span class=identifier>def</span><span class=special>(</span><span class=string>&quot;wack_em&quot;</span><span class=special>, &amp;</span><span class=identifier>george</span><span class=special>::</span><span class=identifier>wack_em</span><span class=special>, </span><span class=identifier>george_overloads</span><span class=special>());
</span></pre></code>
<p>
See the <a href="../../v2/overloads.html#BOOST_PYTHON_FUNCTION_OVERLOADS-spec">
overloads reference</a>
for details.</p>
<a name="init_and_optional"></a><h2>init and optional</h2><p>
A similar facility is provided for class constructors, again, with
default arguments or a sequence of overloads. Remember <tt>init&lt;...&gt;</tt>? For example,
given a class X with a constructor:</p>
<code><pre>
<span class=keyword>struct </span><span class=identifier>X
</span><span class=special>{
</span><span class=identifier>X</span><span class=special>(</span><span class=keyword>int </span><span class=identifier>a</span><span class=special>, </span><span class=keyword>char </span><span class=identifier>b </span><span class=special>= </span><span class=literal>'D'</span><span class=special>, </span><span class=identifier>std</span><span class=special>::</span><span class=identifier>string </span><span class=identifier>c </span><span class=special>= </span><span class=string>&quot;constructor&quot;</span><span class=special>, </span><span class=keyword>double </span><span class=identifier>d </span><span class=special>= </span><span class=number>0.0</span><span class=special>);
/*...*/
}
</span></pre></code>
<p>
You can easily add this constructor to Boost.Python in one shot:</p>
<code><pre>
<span class=special>.</span><span class=identifier>def</span><span class=special>(</span><span class=identifier>init</span><span class=special>&lt;</span><span class=keyword>int</span><span class=special>, </span><span class=identifier>optional</span><span class=special>&lt;</span><span class=keyword>char</span><span class=special>, </span><span class=identifier>std</span><span class=special>::</span><span class=identifier>string</span><span class=special>, </span><span class=keyword>double</span><span class=special>&gt; &gt;())
</span></pre></code>
<p>
Notice the use of <tt>init&lt;...&gt;</tt> and <tt>optional&lt;...&gt;</tt> to signify the default
(optional arguments).</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="overloading.html"><img src="theme/l_arr.gif" border="0"></a></td>
<td width="20"><a href="auto_overloading.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

@@ -1,117 +0,0 @@
<html>
<head>
<!-- Generated by the Spirit (http://spirit.sf.net) QuickDoc -->
<title>Derived Object types</title>
<link rel="stylesheet" href="theme/style.css" type="text/css">
<link rel="prev" href="basic_interface.html">
<link rel="next" href="extracting_c___objects.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>Derived Object types</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="basic_interface.html"><img src="theme/l_arr.gif" border="0"></a></td>
<td width="20"><a href="extracting_c___objects.html"><img src="theme/r_arr.gif" border="0"></a></td>
</tr>
</table>
<p>
Boost.Python comes with a set of derived <tt>object</tt> types corresponding to
that of Python's:</p>
<ul><li>list</li><li>dict</li><li>tuple</li><li>str</li><li>long_</li><li>enum</li></ul><p>
These derived <tt>object</tt> types act like real Python types. For instance:</p>
<code><pre>
<span class=identifier>str</span><span class=special>(</span><span class=number>1</span><span class=special>) ==&gt; </span><span class=string>&quot;1&quot;
</span></pre></code>
<p>
Wherever appropriate, a particular derived <tt>object</tt> has corresponding
Python type's methods. For instance, <tt>dict</tt> has a <tt>keys()</tt> method:</p>
<code><pre>
<span class=identifier>d</span><span class=special>.</span><span class=identifier>keys</span><span class=special>()
</span></pre></code>
<p>
<tt>make_tuple</tt> is provided for declaring <i>tuple literals</i>. Example:</p>
<code><pre>
<span class=identifier>make_tuple</span><span class=special>(</span><span class=number>123</span><span class=special>, </span><span class=literal>'D'</span><span class=special>, </span><span class=string>&quot;Hello, World&quot;</span><span class=special>, </span><span class=number>0.0</span><span class=special>);
</span></pre></code>
<p>
In C++, when Boost.Python <tt>object</tt>s are used as arguments to functions,
subtype matching is required. For example, when a function <tt>f</tt>, as
declared below, is wrapped, it will only accept instances of Python's
<tt>str</tt> type and subtypes.</p>
<code><pre>
<span class=keyword>void </span><span class=identifier>f</span><span class=special>(</span><span class=identifier>str </span><span class=identifier>name</span><span class=special>)
{
</span><span class=identifier>object </span><span class=identifier>n2 </span><span class=special>= </span><span class=identifier>name</span><span class=special>.</span><span class=identifier>attr</span><span class=special>(</span><span class=string>&quot;upper&quot;</span><span class=special>)(); // </span><span class=identifier>NAME </span><span class=special>= </span><span class=identifier>name</span><span class=special>.</span><span class=identifier>upper</span><span class=special>()
</span><span class=identifier>str </span><span class=identifier>NAME </span><span class=special>= </span><span class=identifier>name</span><span class=special>.</span><span class=identifier>upper</span><span class=special>(); // </span><span class=identifier>better
</span><span class=identifier>object </span><span class=identifier>msg </span><span class=special>= </span><span class=string>&quot;%s is bigger than %s&quot; </span><span class=special>% </span><span class=identifier>make_tuple</span><span class=special>(</span><span class=identifier>NAME</span><span class=special>,</span><span class=identifier>name</span><span class=special>);
}
</span></pre></code>
<p>
In finer detail:</p>
<code><pre>
<span class=identifier>str </span><span class=identifier>NAME </span><span class=special>= </span><span class=identifier>name</span><span class=special>.</span><span class=identifier>upper</span><span class=special>();
</span></pre></code>
<p>
Illustrates that we provide versions of the str type's methods as C++
member functions.</p>
<code><pre>
<span class=identifier>object </span><span class=identifier>msg </span><span class=special>= </span><span class=string>&quot;%s is bigger than %s&quot; </span><span class=special>% </span><span class=identifier>make_tuple</span><span class=special>(</span><span class=identifier>NAME</span><span class=special>,</span><span class=identifier>name</span><span class=special>);
</span></pre></code>
<p>
Demonstrates that you can write the C++ equivalent of <tt>&quot;format&quot; % x,y,z</tt>
in Python, which is useful since there's no easy way to do that in std C++.</p>
<p>
<img src="theme/alert.gif"></img> <b>Beware</b> the common pitfall of forgetting that the constructors
of most of Python's mutable types make copies, just as in Python.</p>
<p>
Python:</p>
<code><pre>
<span class=special>&gt;&gt;&gt; </span><span class=identifier>d </span><span class=special>= </span><span class=identifier>dict</span><span class=special>(</span><span class=identifier>x</span><span class=special>.</span><span class=identifier>__dict__</span><span class=special>) </span>##<span class=identifier>copies </span><span class=identifier>x</span><span class=special>.</span><span class=identifier>__dict__
</span><span class=special>&gt;&gt;&gt; </span><span class=identifier>d</span><span class=special>[</span><span class=literal>'whatever'</span><span class=special>] </span>##<span class=identifier>modifies </span><span class=identifier>the </span><span class=identifier>copy
</span></pre></code>
<p>
C++:</p>
<code><pre>
<span class=identifier>dict </span><span class=identifier>d</span><span class=special>(</span><span class=identifier>x</span><span class=special>.</span><span class=identifier>attr</span><span class=special>(</span><span class=string>&quot;__dict__&quot;</span><span class=special>)); </span>##<span class=identifier>copies </span><span class=identifier>x</span><span class=special>.</span><span class=identifier>__dict__
</span><span class=identifier>d</span><span class=special>[</span><span class=literal>'whatever'</span><span class=special>] = </span><span class=number>3</span><span class=special>; </span>##<span class=identifier>modifies </span><span class=identifier>the </span><span class=identifier>copy
</span></pre></code>
<a name="class__lt_t_gt__as_objects"></a><h2>class_&lt;T&gt; as objects</h2><p>
Due to the dynamic nature of Boost.Python objects, any <tt>class_&lt;T&gt;</tt> may
also be one of these types! The following code snippet wraps the class
(type) object.</p>
<p>
We can use this to create wrapped instances. Example:</p>
<code><pre>
<span class=identifier>object </span><span class=identifier>vec345 </span><span class=special>= (
</span><span class=identifier>class_</span><span class=special>&lt;</span><span class=identifier>Vec2</span><span class=special>&gt;(</span><span class=string>&quot;Vec2&quot;</span><span class=special>, </span><span class=identifier>init</span><span class=special>&lt;</span><span class=keyword>double</span><span class=special>, </span><span class=keyword>double</span><span class=special>&gt;())
.</span><span class=identifier>def_readonly</span><span class=special>(</span><span class=string>&quot;length&quot;</span><span class=special>, &amp;</span><span class=identifier>Point</span><span class=special>::</span><span class=identifier>length</span><span class=special>)
.</span><span class=identifier>def_readonly</span><span class=special>(</span><span class=string>&quot;angle&quot;</span><span class=special>, &amp;</span><span class=identifier>Point</span><span class=special>::</span><span class=identifier>angle</span><span class=special>)
)(</span><span class=number>3.0</span><span class=special>, </span><span class=number>4.0</span><span class=special>);
</span><span class=identifier>assert</span><span class=special>(</span><span class=identifier>vec345</span><span class=special>.</span><span class=identifier>attr</span><span class=special>(</span><span class=string>&quot;length&quot;</span><span class=special>) == </span><span class=number>5.0</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="basic_interface.html"><img src="theme/l_arr.gif" border="0"></a></td>
<td width="20"><a href="extracting_c___objects.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

@@ -1,83 +0,0 @@
<html>
<head>
<!-- Generated by the Spirit (http://spirit.sf.net) QuickDoc -->
<title>Deriving a Python Class</title>
<link rel="stylesheet" href="theme/style.css" type="text/css">
<link rel="prev" href="class_virtual_functions.html">
<link rel="next" href="virtual_functions_with_default_implementations.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>Deriving a Python Class</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="class_virtual_functions.html"><img src="theme/l_arr.gif" border="0"></a></td>
<td width="20"><a href="virtual_functions_with_default_implementations.html"><img src="theme/r_arr.gif" border="0"></a></td>
</tr>
</table>
<p>
Continuing, we can derive from our base class Base in Python and override
the virtual function in Python. Before we can do that, we have to set up
our <tt>class_</tt> wrapper as:</p>
<code><pre>
<span class=identifier>class_</span><span class=special>&lt;</span><span class=identifier>Base</span><span class=special>, </span><span class=identifier>BaseWrap</span><span class=special>, </span><span class=identifier>boost</span><span class=special>::</span><span class=identifier>noncopyable</span><span class=special>&gt;(</span><span class=string>&quot;Base&quot;</span><span class=special>)
;
</span></pre></code>
<p>
Otherwise, we have to suppress the Base class' <tt>no_init</tt> by adding an
<tt>__init__()</tt> method to all our derived classes. <tt>no_init</tt> actually adds
an <tt>__init__</tt> method that raises a Python RuntimeError exception.</p>
<code><pre>
<span class=special>&gt;&gt;&gt; </span><span class=keyword>class </span><span class=identifier>Derived</span><span class=special>(</span><span class=identifier>Base</span><span class=special>):
... </span><span class=identifier>def </span><span class=identifier>f</span><span class=special>(</span><span class=identifier>self</span><span class=special>):
... </span><span class=keyword>return </span><span class=number>42
</span><span class=special>...
</span></pre></code>
<p>
Cool eh? A Python class deriving from a C++ class!</p>
<p>
Let's now make an instance of our Python class <tt>Derived</tt>:</p>
<code><pre>
<span class=special>&gt;&gt;&gt; </span><span class=identifier>derived </span><span class=special>= </span><span class=identifier>Derived</span><span class=special>()
</span></pre></code>
<p>
Calling <tt>derived.f()</tt>:</p>
<code><pre>
<span class=special>&gt;&gt;&gt; </span><span class=identifier>derived</span><span class=special>.</span><span class=identifier>f</span><span class=special>()
</span><span class=number>42
</span></pre></code>
<p>
Will yield the expected result. Finally, calling calling the free function
<tt>call_f</tt> with <tt>derived</tt> as argument:</p>
<code><pre>
<span class=special>&gt;&gt;&gt; </span><span class=identifier>call_f</span><span class=special>(</span><span class=identifier>derived</span><span class=special>)
</span><span class=number>42
</span></pre></code>
<p>
Will also yield the expected result.</p>
<p>
Here's what's happening:</p>
<ol><li><tt>call_f(derived)</tt> is called in Python</li><li>This corresponds to <tt>def(&quot;call_f&quot;, call_f);</tt>. Boost.Python dispatches this call.</li><li><tt>int call_f(Base&amp; b) { return b.f(); }</tt> accepts the call.</li><li>The overridden virtual function <tt>f</tt> of <tt>BaseWrap</tt> is called.</li><li><tt>call_method&lt;int&gt;(self, &quot;f&quot;);</tt> dispatches the call back to Python.</li><li><tt>def f(self): return 42</tt> is finally called.</li></ol><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="class_virtual_functions.html"><img src="theme/l_arr.gif" border="0"></a></td>
<td width="20"><a href="virtual_functions_with_default_implementations.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

@@ -1,97 +0,0 @@
<html>
<head>
<!-- Generated by the Spirit (http://spirit.sf.net) QuickDoc -->
<title>Embedding</title>
<link rel="stylesheet" href="theme/style.css" type="text/css">
<link rel="prev" href="enums.html">
<link rel="next" href="using_the_interpreter.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>Embedding</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="enums.html"><img src="theme/l_arr.gif" border="0"></a></td>
<td width="20"><a href="using_the_interpreter.html"><img src="theme/r_arr.gif" border="0"></a></td>
</tr>
</table>
<p>
By now you should know how to use Boost.Python to call your C++ code from
Python. However, sometimes you may need to do the reverse: call Python code
from the C++-side. This requires you to <i>embed</i> the Python interpreter
into your C++ program.</p>
<p>
Currently, Boost.Python does not directly support everything you'll need
when embedding. Therefore you'll need to use the
<a href="http://www.python.org/doc/current/api/api.html">
Python/C API</a> to fill in
the gaps. However, Boost.Python already makes embedding a lot easier and,
in a future version, it may become unnecessary to touch the Python/C API at
all. So stay tuned... <img src="theme/smiley.gif"></img></p>
<a name="building_embedded_programs"></a><h2>Building embedded programs</h2><p>
To be able to use embedding in your programs, they have to be linked to
both Boost.Python's and Python's static link library.</p>
<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>
<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
your major Python version number.</p>
<p>
Additionally, Python's <tt>/include</tt> subdirectory has to be added to your
include path.</p>
<p>
In a Jamfile, all the above boils down to:</p>
<code><pre>
projectroot c:\projects\embedded_program ; # location of the program
# bring in the rules for python
SEARCH on python.jam = $(BOOST_BUILD_PATH) ;
include python.jam ;
exe embedded_program # name of the executable
: #sources
embedded_program.cpp
: # requirements
&lt;find-library&gt;boost_python &lt;library-path&gt;c:\boost\libs\python
$(PYTHON_PROPERTIES)
&lt;library-path&gt;$(PYTHON_LIB_PATH)
&lt;find-library&gt;$(PYTHON_EMBEDDED_LIBRARY) ;
</pre></code><a name="getting_started"></a><h2>Getting started</h2><p>
Being able to build is nice, but there is nothing to build yet. Embedding
the Python interpreter into one of your C++ programs requires these 4
steps:</p>
<ol><li>#include <tt>&lt;boost/python.hpp&gt;</tt><br><br></li><li>Call <a href="http://www.python.org/doc/current/api/initialization.html#l2h-652">
Py_Initialize</a>() to start the interpreter and create the <tt>__main__</tt> module.<br><br></li><li>Call other Python C API routines to use the interpreter.<br><br></li><li>Call <a href="http://www.python.org/doc/current/api/initialization.html#l2h-656">
Py_Finalize</a>() to stop the interpreter and release its resources.</li></ol><p>
(Of course, there can be other C++ code between all of these steps.)</p>
<blockquote><p><i><b>Now that we can embed the interpreter in our programs, lets see how to put it to use...</b></i></p></blockquote><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="enums.html"><img src="theme/l_arr.gif" border="0"></a></td>
<td width="20"><a href="using_the_interpreter.html"><img src="theme/r_arr.gif" border="0"></a></td>
</tr>
</table>
<br>
<hr size="1"><p class="copyright">Copyright &copy; 2002-2003 Dirk Gerrits<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

@@ -1,95 +0,0 @@
<html>
<head>
<!-- Generated by the Spirit (http://spirit.sf.net) QuickDoc -->
<title>Enums</title>
<link rel="stylesheet" href="theme/style.css" type="text/css">
<link rel="prev" href="extracting_c___objects.html">
<link rel="next" href="embedding.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>Enums</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="extracting_c___objects.html"><img src="theme/l_arr.gif" border="0"></a></td>
<td width="20"><a href="embedding.html"><img src="theme/r_arr.gif" border="0"></a></td>
</tr>
</table>
<p>
Boost.Python has a nifty facility to capture and wrap C++ enums. While
Python has no <tt>enum</tt> type, we'll often want to expose our C++ enums to
Python as an <tt>int</tt>. Boost.Python's enum facility makes this easy while
taking care of the proper conversions from Python's dynamic typing to C++'s
strong static typing (in C++, ints cannot be implicitly converted to
enums). To illustrate, given a C++ enum:</p>
<code><pre>
<span class=keyword>enum </span><span class=identifier>choice </span><span class=special>{ </span><span class=identifier>red</span><span class=special>, </span><span class=identifier>blue </span><span class=special>};
</span></pre></code>
<p>
the construct:</p>
<code><pre>
<span class=identifier>enum_</span><span class=special>&lt;</span><span class=identifier>choice</span><span class=special>&gt;(</span><span class=string>&quot;choice&quot;</span><span class=special>)
.</span><span class=identifier>value</span><span class=special>(</span><span class=string>&quot;red&quot;</span><span class=special>, </span><span class=identifier>red</span><span class=special>)
.</span><span class=identifier>value</span><span class=special>(</span><span class=string>&quot;blue&quot;</span><span class=special>, </span><span class=identifier>blue</span><span class=special>)
;
</span></pre></code>
<p>
can be used to expose to Python. The new enum type is created in the
current <tt>scope()</tt>, which is usually the current module. The snippet above
creates a Python class derived from Python's <tt>int</tt> type which is
associated with the C++ type passed as its first parameter.</p>
<table width="80%" border="0" align="center">
<tr>
<td class="note_box">
<img src="theme/lens.gif"></img> <b>what is a scope?</b><br><br> The scope is a class that has an
associated global Python object which controls the Python namespace in
which new extension classes and wrapped functions will be defined as
attributes. Details can be found <a href="../../v2/scope.html">
here</a>. </td>
</tr>
</table>
<p>
You can access those values in Python as</p>
<code><pre>
<span class=special>&gt;&gt;&gt; </span><span class=identifier>my_module</span><span class=special>.</span><span class=identifier>choice</span><span class=special>.</span><span class=identifier>red
</span><span class=identifier>my_module</span><span class=special>.</span><span class=identifier>choice</span><span class=special>.</span><span class=identifier>red
</span></pre></code>
<p>
where my_module is the module where the enum is declared. You can also
create a new scope around a class:</p>
<code><pre>
<span class=identifier>scope </span><span class=identifier>in_X </span><span class=special>= </span><span class=identifier>class_</span><span class=special>&lt;</span><span class=identifier>X</span><span class=special>&gt;(</span><span class=string>&quot;X&quot;</span><span class=special>)
.</span><span class=identifier>def</span><span class=special>( ... )
.</span><span class=identifier>def</span><span class=special>( ... )
;
// </span><span class=identifier>Expose </span><span class=identifier>X</span><span class=special>::</span><span class=identifier>nested </span><span class=identifier>as </span><span class=identifier>X</span><span class=special>.</span><span class=identifier>nested
</span><span class=identifier>enum_</span><span class=special>&lt;</span><span class=identifier>X</span><span class=special>::</span><span class=identifier>nested</span><span class=special>&gt;(</span><span class=string>&quot;nested&quot;</span><span class=special>)
.</span><span class=identifier>value</span><span class=special>(</span><span class=string>&quot;red&quot;</span><span class=special>, </span><span class=identifier>red</span><span class=special>)
.</span><span class=identifier>value</span><span class=special>(</span><span class=string>&quot;blue&quot;</span><span class=special>, </span><span class=identifier>blue</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="extracting_c___objects.html"><img src="theme/l_arr.gif" border="0"></a></td>
<td width="20"><a href="embedding.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

@@ -1,60 +0,0 @@
<html>
<head>
<!-- Generated by the Spirit (http://spirit.sf.net) QuickDoc -->
<title>Exception Translation</title>
<link rel="stylesheet" href="theme/style.css" type="text/css">
<link rel="prev" href="iterators.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>Exception Translation</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="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>
</tr>
</table>
<p>
All C++ exceptions must be caught at the boundary with Python code. This
boundary is the point where C++ meets Python. Boost.Python provides a
default exception handler that translates selected standard exceptions,
then gives up:</p>
<code><pre>
<span class=identifier>raise </span><span class=identifier>RuntimeError</span><span class=special>, </span><span class=literal>'unidentifiable C++ Exception'
</span></pre></code>
<p>
Users may provide custom translation. Here's an example:</p>
<code><pre>
<span class=keyword>struct </span><span class=identifier>PodBayDoorException</span><span class=special>;
</span><span class=keyword>void </span><span class=identifier>translator</span><span class=special>(</span><span class=identifier>PodBayDoorException </span><span class=keyword>const</span><span class=special>&amp; </span><span class=identifier>x</span><span class=special>) {
</span><span class=identifier>PyErr_SetString</span><span class=special>(</span><span class=identifier>PyExc_UserWarning</span><span class=special>, </span><span class=string>&quot;I'm sorry Dave...&quot;</span><span class=special>);
}
</span><span class=identifier>BOOST_PYTHON_MODULE</span><span class=special>(</span><span class=identifier>kubrick</span><span class=special>) {
</span><span class=identifier>register_exception_translator</span><span class=special>&lt;
</span><span class=identifier>PodBayDoorException</span><span class=special>&gt;(</span><span class=identifier>translator</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="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>
</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

@@ -1,79 +0,0 @@
<html>
<head>
<!-- Generated by the Spirit (http://spirit.sf.net) QuickDoc -->
<title>Exposing Classes</title>
<link rel="stylesheet" href="theme/style.css" type="text/css">
<link rel="prev" href="building_hello_world.html">
<link rel="next" href="constructors.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>Exposing Classes</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="building_hello_world.html"><img src="theme/l_arr.gif" border="0"></a></td>
<td width="20"><a href="constructors.html"><img src="theme/r_arr.gif" border="0"></a></td>
</tr>
</table>
<p>
Now let's expose a C++ class to Python.</p>
<p>
Consider a C++ class/struct that we want to expose to Python:</p>
<code><pre>
<span class=keyword>struct </span><span class=identifier>World
</span><span class=special>{
</span><span class=keyword>void </span><span class=identifier>set</span><span class=special>(</span><span class=identifier>std</span><span class=special>::</span><span class=identifier>string </span><span class=identifier>msg</span><span class=special>) { </span><span class=keyword>this</span><span class=special>-&gt;</span><span class=identifier>msg </span><span class=special>= </span><span class=identifier>msg</span><span class=special>; }
</span><span class=identifier>std</span><span class=special>::</span><span class=identifier>string </span><span class=identifier>greet</span><span class=special>() { </span><span class=keyword>return </span><span class=identifier>msg</span><span class=special>; }
</span><span class=identifier>std</span><span class=special>::</span><span class=identifier>string </span><span class=identifier>msg</span><span class=special>;
};
</span></pre></code>
<p>
We can expose this to Python by writing a corresponding Boost.Python
C++ Wrapper:</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=keyword>using </span><span class=keyword>namespace </span><span class=identifier>boost</span><span class=special>::</span><span class=identifier>python</span><span class=special>;
</span><span class=identifier>BOOST_PYTHON_MODULE</span><span class=special>(</span><span class=identifier>hello</span><span class=special>)
{
</span><span class=identifier>class_</span><span class=special>&lt;</span><span class=identifier>World</span><span class=special>&gt;(</span><span class=string>&quot;World&quot;</span><span class=special>)
.</span><span class=identifier>def</span><span class=special>(</span><span class=string>&quot;greet&quot;</span><span class=special>, &amp;</span><span class=identifier>World</span><span class=special>::</span><span class=identifier>greet</span><span class=special>)
.</span><span class=identifier>def</span><span class=special>(</span><span class=string>&quot;set&quot;</span><span class=special>, &amp;</span><span class=identifier>World</span><span class=special>::</span><span class=identifier>set</span><span class=special>)
;
}
</span></pre></code>
<p>
Here, we wrote a C++ class wrapper that exposes the member functions
<tt>greet</tt> and <tt>set</tt>. Now, after building our module as a shared library, we
may use our class <tt>World</tt> in Python. Here's a sample Python session:</p>
<code><pre>
<span class=special>&gt;&gt;&gt; </span><span class=identifier>import </span><span class=identifier>hello
</span><span class=special>&gt;&gt;&gt; </span><span class=identifier>planet </span><span class=special>= </span><span class=identifier>hello</span><span class=special>.</span><span class=identifier>World</span><span class=special>()
&gt;&gt;&gt; </span><span class=identifier>planet</span><span class=special>.</span><span class=identifier>set</span><span class=special>(</span><span class=literal>'howdy'</span><span class=special>)
&gt;&gt;&gt; </span><span class=identifier>planet</span><span class=special>.</span><span class=identifier>greet</span><span class=special>()
</span><span class=literal>'howdy'
</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="building_hello_world.html"><img src="theme/l_arr.gif" border="0"></a></td>
<td width="20"><a href="constructors.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

@@ -1,79 +0,0 @@
<html>
<head>
<!-- Generated by the Spirit (http://spirit.sf.net) QuickDoc -->
<title>Extracting C++ objects</title>
<link rel="stylesheet" href="theme/style.css" type="text/css">
<link rel="prev" href="derived_object_types.html">
<link rel="next" href="enums.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>Extracting C++ objects</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="derived_object_types.html"><img src="theme/l_arr.gif" border="0"></a></td>
<td width="20"><a href="enums.html"><img src="theme/r_arr.gif" border="0"></a></td>
</tr>
</table>
<p>
At some point, we will need to get C++ values out of object instances. This
can be achieved with the <tt>extract&lt;T&gt;</tt> function. Consider the following:</p>
<code><pre>
<span class=keyword>double </span><span class=identifier>x </span><span class=special>= </span><span class=identifier>o</span><span class=special>.</span><span class=identifier>attr</span><span class=special>(</span><span class=string>&quot;length&quot;</span><span class=special>); // </span><span class=identifier>compile </span><span class=identifier>error
</span></pre></code>
<p>
In the code above, we got a compiler error because Boost.Python
<tt>object</tt> can't be implicitly converted to <tt>double</tt>s. Instead, what
we wanted to do above can be achieved by writing:</p>
<code><pre>
<span class=keyword>double </span><span class=identifier>l </span><span class=special>= </span><span class=identifier>extract</span><span class=special>&lt;</span><span class=keyword>double</span><span class=special>&gt;(</span><span class=identifier>o</span><span class=special>.</span><span class=identifier>attr</span><span class=special>(</span><span class=string>&quot;length&quot;</span><span class=special>));
</span><span class=identifier>Vec2</span><span class=special>&amp; </span><span class=identifier>v </span><span class=special>= </span><span class=identifier>extract</span><span class=special>&lt;</span><span class=identifier>Vec2</span><span class=special>&amp;&gt;(</span><span class=identifier>o</span><span class=special>);
</span><span class=identifier>assert</span><span class=special>(</span><span class=identifier>l </span><span class=special>== </span><span class=identifier>v</span><span class=special>.</span><span class=identifier>length</span><span class=special>());
</span></pre></code>
<p>
The first line attempts to extract the &quot;length&quot; attribute of the
Boost.Python <tt>object</tt> <tt>o</tt>. The second line attempts to <i>extract</i> the
<tt>Vec2</tt> object from held by the Boost.Python <tt>object</tt> <tt>o</tt>.</p>
<p>
Take note that we said &quot;attempt to&quot; above. What if the Boost.Python
<tt>object</tt> <tt>o</tt> does not really hold a <tt>Vec2</tt> type? This is certainly
a possibility considering the dynamic nature of Python <tt>object</tt>s. To
be on the safe side, if the C++ type can't be extracted, an
appropriate exception is thrown. To avoid an exception, we need to
test for extractibility:</p>
<code><pre>
<span class=identifier>extract</span><span class=special>&lt;</span><span class=identifier>Vec2</span><span class=special>&amp;&gt; </span><span class=identifier>x</span><span class=special>(</span><span class=identifier>o</span><span class=special>);
</span><span class=keyword>if </span><span class=special>(</span><span class=identifier>x</span><span class=special>.</span><span class=identifier>check</span><span class=special>()) {
</span><span class=identifier>Vec2</span><span class=special>&amp; </span><span class=identifier>v </span><span class=special>= </span><span class=identifier>x</span><span class=special>(); ...
</span></pre></code>
<p>
<img src="theme/bulb.gif"></img> The astute reader might have noticed that the <tt>extract&lt;T&gt;</tt>
facility in fact solves the mutable copying problem:</p>
<code><pre>
<span class=identifier>dict </span><span class=identifier>d </span><span class=special>= </span><span class=identifier>extract</span><span class=special>&lt;</span><span class=identifier>dict</span><span class=special>&gt;(</span><span class=identifier>x</span><span class=special>.</span><span class=identifier>attr</span><span class=special>(</span><span class=string>&quot;__dict__&quot;</span><span class=special>));
</span><span class=identifier>d</span><span class=special>[</span><span class=literal>'whatever'</span><span class=special>] = </span><span class=number>3</span><span class=special>; </span>##<span class=identifier>modifies </span><span class=identifier>x</span><span class=special>.</span><span class=identifier>__dict__ </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="derived_object_types.html"><img src="theme/l_arr.gif" border="0"></a></td>
<td width="20"><a href="enums.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

@@ -1,73 +0,0 @@
<html>
<head>
<!-- Generated by the Spirit (http://spirit.sf.net) QuickDoc -->
<title>Functions</title>
<link rel="stylesheet" href="theme/style.css" type="text/css">
<link rel="prev" href="class_operators_special_functions.html">
<link rel="next" href="call_policies.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>Functions</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="class_operators_special_functions.html"><img src="theme/l_arr.gif" border="0"></a></td>
<td width="20"><a href="call_policies.html"><img src="theme/r_arr.gif" border="0"></a></td>
</tr>
</table>
<p>
In this chapter, we'll look at Boost.Python powered functions in closer
detail. We shall see some facilities to make exposing C++ functions to
Python safe from potential pifalls such as dangling pointers and
references. We shall also see facilities that will make it even easier for
us to expose C++ functions that take advantage of C++ features such as
overloading and default arguments.</p>
<blockquote><p><i>Read on...</i></p></blockquote><p>
But before you do, you might want to fire up Python 2.2 or later and type
<tt>&gt;&gt;&gt; import this</tt>.</p>
<code><pre>
&gt;&gt;&gt; import this
The Zen of Python, by Tim Peters
Beautiful is better than ugly.
Explicit is better than implicit.
Simple is better than complex.
Complex is better than complicated.
Flat is better than nested.
Sparse is better than dense.
Readability counts.
Special cases aren't special enough to break the rules.
Although practicality beats purity.
Errors should never pass silently.
Unless explicitly silenced.
In the face of ambiguity, refuse the temptation to guess.
There should be one-- and preferably only one --obvious way to do it
Although that way may not be obvious at first unless you're Dutch.
Now is better than never.
Although never is often better than *right* now.
If the implementation is hard to explain, it's a bad idea.
If the implementation is easy to explain, it may be a good idea.
Namespaces are one honking great idea -- let's do more of those!
</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="class_operators_special_functions.html"><img src="theme/l_arr.gif" border="0"></a></td>
<td width="20"><a href="call_policies.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>

Binary file not shown.

After

Width:  |  Height:  |  Size: 603 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 358 B

View File

Before

Width:  |  Height:  |  Size: 3.8 KiB

After

Width:  |  Height:  |  Size: 3.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 336 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 658 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 334 B

View File

Before

Width:  |  Height:  |  Size: 14 KiB

After

Width:  |  Height:  |  Size: 14 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 867 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 640 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 370 B

View File

@@ -0,0 +1,142 @@
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
<title>Chapter&#160;1.&#160;python 2.0</title>
<link rel="stylesheet" href="../../../../../../doc/src/boostbook.css" type="text/css">
<meta name="generator" content="DocBook XSL Stylesheets V1.76.1">
<link rel="home" href="index.html" title="Chapter&#160;1.&#160;python 2.0">
<link rel="next" href="python/hello.html" title="Building Hello World">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<table cellpadding="2" width="100%"><tr>
<td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../../../../boost.png"></td>
<td align="center"><a href="../../../../../../index.html">Home</a></td>
<td align="center"><a href="../../../../../../libs/libraries.htm">Libraries</a></td>
<td align="center"><a href="http://www.boost.org/users/people.html">People</a></td>
<td align="center"><a href="http://www.boost.org/users/faq.html">FAQ</a></td>
<td align="center"><a href="../../../../../../more/index.htm">More</a></td>
</tr></table>
<hr>
<div class="spirit-nav"><a accesskey="n" href="python/hello.html"><img src="../../../../../../doc/src/images/next.png" alt="Next"></a></div>
<div class="chapter">
<div class="titlepage"><div>
<div><h2 class="title">
<a name="python"></a>Chapter&#160;1.&#160;python 2.0</h2></div>
<div><div class="author"><h3 class="author">
<span class="firstname">Joel</span> <span class="surname">de Guzman</span>
</h3></div></div>
<div><div class="author"><h3 class="author">
<span class="firstname">David</span> <span class="surname">Abrahams</span>
</h3></div></div>
<div><p class="copyright">Copyright &#169; 2002-2005 Joel
de Guzman, David Abrahams</p></div>
<div><div class="legalnotice">
<a name="python.legal"></a><p>
Distributed under the Boost Software License, Version 1.0. (See accompanying
file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">
http://www.boost.org/LICENSE_1_0.txt </a>)
</p>
</div></div>
</div></div>
<div class="toc">
<p><b>Table of Contents</b></p>
<dl>
<dt><span class="section"><a href="index.html#python.quickstart">QuickStart</a></span></dt>
<dt><span class="section"><a href="python/hello.html">Building Hello World</a></span></dt>
<dt><span class="section"><a href="python/exposing.html">Exposing Classes</a></span></dt>
<dd><dl>
<dt><span class="section"><a href="python/exposing.html#python.constructors">Constructors</a></span></dt>
<dt><span class="section"><a href="python/exposing.html#python.class_data_members">Class Data Members</a></span></dt>
<dt><span class="section"><a href="python/exposing.html#python.class_properties">Class Properties</a></span></dt>
<dt><span class="section"><a href="python/exposing.html#python.inheritance">Inheritance</a></span></dt>
<dt><span class="section"><a href="python/exposing.html#python.class_virtual_functions">Class Virtual Functions</a></span></dt>
<dt><span class="section"><a href="python/exposing.html#python.virtual_functions_with_default_implementations">Virtual Functions with Default Implementations</a></span></dt>
<dt><span class="section"><a href="python/exposing.html#python.class_operators_special_functions">Class Operators/Special Functions</a></span></dt>
</dl></dd>
<dt><span class="section"><a href="python/functions.html">Functions</a></span></dt>
<dd><dl>
<dt><span class="section"><a href="python/functions.html#python.call_policies">Call Policies</a></span></dt>
<dt><span class="section"><a href="python/functions.html#python.overloading">Overloading</a></span></dt>
<dt><span class="section"><a href="python/functions.html#python.default_arguments">Default Arguments</a></span></dt>
<dt><span class="section"><a href="python/functions.html#python.auto_overloading">Auto-Overloading</a></span></dt>
</dl></dd>
<dt><span class="section"><a href="python/object.html">Object Interface</a></span></dt>
<dd><dl>
<dt><span class="section"><a href="python/object.html#python.basic_interface">Basic Interface</a></span></dt>
<dt><span class="section"><a href="python/object.html#python.derived_object_types">Derived Object types</a></span></dt>
<dt><span class="section"><a href="python/object.html#python.extracting_c___objects">Extracting C++ objects</a></span></dt>
<dt><span class="section"><a href="python/object.html#python.enums">Enums</a></span></dt>
<dt><span class="section"><a href="python/object.html#python.creating_python_object">Creating <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">python</span><span class="special">::</span><span class="identifier">object</span></code> from <code class="computeroutput"><span class="identifier">PyObject</span><span class="special">*</span></code></a></span></dt>
</dl></dd>
<dt><span class="section"><a href="python/embedding.html">Embedding</a></span></dt>
<dd><dl><dt><span class="section"><a href="python/embedding.html#python.using_the_interpreter">Using the interpreter</a></span></dt></dl></dd>
<dt><span class="section"><a href="python/iterators.html">Iterators</a></span></dt>
<dt><span class="section"><a href="python/exception.html">Exception Translation</a></span></dt>
<dt><span class="section"><a href="python/techniques.html">General Techniques</a></span></dt>
<dd><dl>
<dt><span class="section"><a href="python/techniques.html#python.creating_packages">Creating Packages</a></span></dt>
<dt><span class="section"><a href="python/techniques.html#python.extending_wrapped_objects_in_python">Extending Wrapped Objects in Python</a></span></dt>
<dt><span class="section"><a href="python/techniques.html#python.reducing_compiling_time">Reducing Compiling Time</a></span></dt>
</dl></dd>
</dl>
</div>
<div class="section">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="python.quickstart"></a>QuickStart</h2></div></div></div>
<p>
The Boost Python Library is a framework for interfacing Python and C++. It
allows you to quickly and seamlessly expose C++ classes functions and objects
to Python, and vice-versa, using no special tools -- just your C++ compiler.
It is designed to wrap C++ interfaces non-intrusively, so that you should not
have to change the C++ code at all in order to wrap it, making Boost.Python
ideal for exposing 3rd-party libraries to Python. The library's use of advanced
metaprogramming techniques simplifies its syntax for users, so that wrapping
code takes on the look of a kind of declarative interface definition language
(IDL).
</p>
<h3>
<a name="quickstart.hello_world"></a>
Hello World
</h3>
<p>
Following C/C++ tradition, let's start with the "hello, world". A
C++ Function:
</p>
<pre class="programlisting"><span class="keyword">char</span> <span class="keyword">const</span><span class="special">*</span> <span class="identifier">greet</span><span class="special">()</span>
<span class="special">{</span>
<span class="keyword">return</span> <span class="string">"hello, world"</span><span class="special">;</span>
<span class="special">}</span>
</pre>
<p>
can be exposed to Python by writing a Boost.Python wrapper:
</p>
<pre class="programlisting"><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="identifier">BOOST_PYTHON_MODULE</span><span class="special">(</span><span class="identifier">hello_ext</span><span class="special">)</span>
<span class="special">{</span>
<span class="keyword">using</span> <span class="keyword">namespace</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">python</span><span class="special">;</span>
<span class="identifier">def</span><span class="special">(</span><span class="string">"greet"</span><span class="special">,</span> <span class="identifier">greet</span><span class="special">);</span>
<span class="special">}</span>
</pre>
<p>
That's it. We're done. We can now build this as a shared library. The resulting
DLL is now visible to Python. Here's a sample Python session:
</p>
<pre class="programlisting"><span class="special">&gt;&gt;&gt;</span> <span class="keyword">import</span> <span class="identifier">hello_ext</span>
<span class="special">&gt;&gt;&gt;</span> <span class="keyword">print</span> <span class="identifier">hello_ext</span><span class="special">.</span><span class="identifier">greet</span><span class="special">()</span>
<span class="identifier">hello</span><span class="special">,</span> <span class="identifier">world</span>
</pre>
<div class="blockquote"><blockquote class="blockquote"><p>
<span class="emphasis"><em><span class="bold"><strong>Next stop... Building your Hello World module
from start to finish...</strong></span></em></span>
</p></blockquote></div>
</div>
</div>
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
<td align="left"><p><small>Last revised: December 26, 2011 at 21:58:39 GMT</small></p></td>
<td align="right"><div class="copyright-footer"></div></td>
</tr></table>
<hr>
<div class="spirit-nav"><a accesskey="n" href="python/hello.html"><img src="../../../../../../doc/src/images/next.png" alt="Next"></a></div>
</body>
</html>

View File

@@ -0,0 +1,269 @@
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
<title>Embedding</title>
<link rel="stylesheet" href="../../../../../../../doc/src/boostbook.css" type="text/css">
<meta name="generator" content="DocBook XSL Stylesheets V1.76.1">
<link rel="home" href="../index.html" title="Chapter&#160;1.&#160;python 2.0">
<link rel="up" href="../index.html" title="Chapter&#160;1.&#160;python 2.0">
<link rel="prev" href="object.html" title="Object Interface">
<link rel="next" href="iterators.html" title="Iterators">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<table cellpadding="2" width="100%"><tr>
<td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../../../../../boost.png"></td>
<td align="center"><a href="../../../../../../../index.html">Home</a></td>
<td align="center"><a href="../../../../../../../libs/libraries.htm">Libraries</a></td>
<td align="center"><a href="http://www.boost.org/users/people.html">People</a></td>
<td align="center"><a href="http://www.boost.org/users/faq.html">FAQ</a></td>
<td align="center"><a href="../../../../../../../more/index.htm">More</a></td>
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="object.html"><img src="../../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../index.html"><img src="../../../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="iterators.html"><img src="../../../../../../../doc/src/images/next.png" alt="Next"></a>
</div>
<div class="section">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="python.embedding"></a>Embedding</h2></div></div></div>
<div class="toc"><dl><dt><span class="section"><a href="embedding.html#python.using_the_interpreter">Using the interpreter</a></span></dt></dl></div>
<p>
By now you should know how to use Boost.Python to call your C++ code from Python.
However, sometimes you may need to do the reverse: call Python code from the
C++-side. This requires you to <span class="emphasis"><em>embed</em></span> the Python interpreter
into your C++ program.
</p>
<p>
Currently, Boost.Python does not directly support everything you'll need when
embedding. Therefore you'll need to use the <a href="http://www.python.org/doc/current/api/api.html" target="_top">Python/C
API</a> to fill in the gaps. However, Boost.Python already makes embedding
a lot easier and, in a future version, it may become unnecessary to touch the
Python/C API at all. So stay tuned... <span class="inlinemediaobject"><img src="../images/smiley.png" alt="smiley"></span>
</p>
<h3>
<a name="embedding.building_embedded_programs"></a>
Building embedded programs
</h3>
<p>
To be able to embed python into your programs, you have to link to both Boost.Python's
as well as Python's own runtime library.
</p>
<p>
Boost.Python's library comes in two variants. Both are located in Boost's
<code class="literal">/libs/python/build/bin-stage</code> subdirectory. On Windows, the
variants are called <code class="literal">boost_python.lib</code> (for release builds)
and <code class="literal">boost_python_debug.lib</code> (for debugging). If you can't
find the libraries, you probably haven't built Boost.Python yet. See <a href="../../../../building.html" target="_top">Building and Testing</a> on how to do this.
</p>
<p>
Python's library can be found in the <code class="literal">/libs</code> subdirectory
of your Python directory. On Windows it is called pythonXY.lib where X.Y is
your major Python version number.
</p>
<p>
Additionally, Python's <code class="literal">/include</code> subdirectory has to be added
to your include path.
</p>
<p>
In a Jamfile, all the above boils down to:
</p>
<pre class="programlisting">projectroot c:\projects\embedded_program ; # location of the program
# bring in the rules for python
SEARCH on python.jam = $(BOOST_BUILD_PATH) ;
include python.jam ;
exe embedded_program # name of the executable
: #sources
embedded_program.cpp
: # requirements
&lt;find-library&gt;boost_python &lt;library-path&gt;c:\boost\libs\python
$(PYTHON_PROPERTIES)
&lt;library-path&gt;$(PYTHON_LIB_PATH)
&lt;find-library&gt;$(PYTHON_EMBEDDED_LIBRARY) ;
</pre>
<h3>
<a name="embedding.getting_started"></a>
Getting started
</h3>
<p>
Being able to build is nice, but there is nothing to build yet. Embedding the
Python interpreter into one of your C++ programs requires these 4 steps:
</p>
<div class="orderedlist"><ol class="orderedlist" type="1">
<li class="listitem">
#include <code class="literal">&lt;boost/python.hpp&gt;</code>
</li>
<li class="listitem">
Call <a href="http://www.python.org/doc/current/api/initialization.html#l2h-652" target="_top">Py_Initialize</a>()
to start the interpreter and create the <code class="literal">__main__</code> module.
</li>
<li class="listitem">
Call other Python C API routines to use the interpreter.
</li>
</ol></div>
<div class="note"><table border="0" summary="Note">
<tr>
<td rowspan="2" align="center" valign="top" width="25"><img alt="[Note]" src="../../../../../../../doc/src/images/note.png"></td>
<th align="left">Note</th>
</tr>
<tr><td align="left" valign="top"><p>
<span class="bold"><strong>Note that at this time you must not call <a href="http://www.python.org/doc/current/api/initialization.html#l2h-656" target="_top">Py_Finalize</a>()
to stop the interpreter. This may be fixed in a future version of boost.python.</strong></span>
</p></td></tr>
</table></div>
<p>
(Of course, there can be other C++ code between all of these steps.)
</p>
<div class="blockquote"><blockquote class="blockquote"><p>
<span class="emphasis"><em><span class="bold"><strong>Now that we can embed the interpreter in
our programs, lets see how to put it to use...</strong></span></em></span>
</p></blockquote></div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="python.using_the_interpreter"></a>Using the interpreter</h3></div></div></div>
<p>
As you probably already know, objects in Python are reference-counted. Naturally,
the <code class="literal">PyObject</code>s of the Python C API are also reference-counted.
There is a difference however. While the reference-counting is fully automatic
in Python, the Python C API requires you to do it <a href="http://www.python.org/doc/current/c-api/refcounting.html" target="_top">by
hand</a>. This is messy and especially hard to get right in the presence
of C++ exceptions. Fortunately Boost.Python provides the <a href="../../../../v2/handle.html" target="_top">handle</a>
and <a href="../../../../v2/object.html" target="_top">object</a> class templates to
automate the process.
</p>
<h3>
<a name="using_the_interpreter.running_python_code"></a>
Running Python code
</h3>
<p>
Boost.python provides three related functions to run Python code from C++.
</p>
<pre class="programlisting"><span class="identifier">object</span> <span class="identifier">eval</span><span class="special">(</span><span class="identifier">str</span> <span class="identifier">expression</span><span class="special">,</span> <span class="identifier">object</span> <span class="identifier">globals</span> <span class="special">=</span> <span class="identifier">object</span><span class="special">(),</span> <span class="identifier">object</span> <span class="identifier">locals</span> <span class="special">=</span> <span class="identifier">object</span><span class="special">())</span>
<span class="identifier">object</span> <span class="identifier">exec</span><span class="special">(</span><span class="identifier">str</span> <span class="identifier">code</span><span class="special">,</span> <span class="identifier">object</span> <span class="identifier">globals</span> <span class="special">=</span> <span class="identifier">object</span><span class="special">(),</span> <span class="identifier">object</span> <span class="identifier">locals</span> <span class="special">=</span> <span class="identifier">object</span><span class="special">())</span>
<span class="identifier">object</span> <span class="identifier">exec_file</span><span class="special">(</span><span class="identifier">str</span> <span class="identifier">filename</span><span class="special">,</span> <span class="identifier">object</span> <span class="identifier">globals</span> <span class="special">=</span> <span class="identifier">object</span><span class="special">(),</span> <span class="identifier">object</span> <span class="identifier">locals</span> <span class="special">=</span> <span class="identifier">object</span><span class="special">())</span>
</pre>
<p>
eval evaluates the given expression and returns the resulting value. exec
executes the given code (typically a set of statements) returning the result,
and exec_file executes the code contained in the given file.
</p>
<p>
The <code class="literal">globals</code> and <code class="literal">locals</code> parameters are
Python dictionaries containing the globals and locals of the context in which
to run the code. For most intents and purposes you can use the namespace
dictionary of the <code class="literal">__main__</code> module for both parameters.
</p>
<p>
Boost.python provides a function to import a module:
</p>
<pre class="programlisting"><span class="identifier">object</span> <span class="identifier">import</span><span class="special">(</span><span class="identifier">str</span> <span class="identifier">name</span><span class="special">)</span>
</pre>
<p>
import imports a python module (potentially loading it into the running process
first), and returns it.
</p>
<p>
Let's import the <code class="literal">__main__</code> module and run some Python code
in its namespace:
</p>
<pre class="programlisting"><span class="identifier">object</span> <span class="identifier">main_module</span> <span class="special">=</span> <span class="identifier">import</span><span class="special">(</span><span class="string">"__main__"</span><span class="special">);</span>
<span class="identifier">object</span> <span class="identifier">main_namespace</span> <span class="special">=</span> <span class="identifier">main_module</span><span class="special">.</span><span class="identifier">attr</span><span class="special">(</span><span class="string">"__dict__"</span><span class="special">);</span>
<span class="identifier">object</span> <span class="identifier">ignored</span> <span class="special">=</span> <span class="identifier">exec</span><span class="special">(</span><span class="string">"hello = file('hello.txt', 'w')\n"</span>
<span class="string">"hello.write('Hello world!')\n"</span>
<span class="string">"hello.close()"</span><span class="special">,</span>
<span class="identifier">main_namespace</span><span class="special">);</span>
</pre>
<p>
This should create a file called 'hello.txt' in the current directory containing
a phrase that is well-known in programming circles.
</p>
<h3>
<a name="using_the_interpreter.manipulating_python_objects"></a>
Manipulating Python objects
</h3>
<p>
Often we'd like to have a class to manipulate Python objects. But we have
already seen such a class above, and in the <a href="object.html" target="_top">previous
section</a>: the aptly named <code class="literal">object</code> class and its
derivatives. We've already seen that they can be constructed from a <code class="literal">handle</code>.
The following examples should further illustrate this fact:
</p>
<pre class="programlisting"><span class="identifier">object</span> <span class="identifier">main_module</span> <span class="special">=</span> <span class="identifier">import</span><span class="special">(</span><span class="string">"__main__"</span><span class="special">);</span>
<span class="identifier">object</span> <span class="identifier">main_namespace</span> <span class="special">=</span> <span class="identifier">main_module</span><span class="special">.</span><span class="identifier">attr</span><span class="special">(</span><span class="string">"__dict__"</span><span class="special">);</span>
<span class="identifier">object</span> <span class="identifier">ignored</span> <span class="special">=</span> <span class="identifier">exec</span><span class="special">(</span><span class="string">"result = 5 ** 2"</span><span class="special">,</span> <span class="identifier">main_namespace</span><span class="special">);</span>
<span class="keyword">int</span> <span class="identifier">five_squared</span> <span class="special">=</span> <span class="identifier">extract</span><span class="special">&lt;</span><span class="keyword">int</span><span class="special">&gt;(</span><span class="identifier">main_namespace</span><span class="special">[</span><span class="string">"result"</span><span class="special">]);</span>
</pre>
<p>
Here we create a dictionary object for the <code class="literal">__main__</code> module's
namespace. Then we assign 5 squared to the result variable and read this
variable from the dictionary. Another way to achieve the same result is to
use eval instead, which returns the result directly:
</p>
<pre class="programlisting"><span class="identifier">object</span> <span class="identifier">result</span> <span class="special">=</span> <span class="identifier">eval</span><span class="special">(</span><span class="string">"5 ** 2"</span><span class="special">);</span>
<span class="keyword">int</span> <span class="identifier">five_squared</span> <span class="special">=</span> <span class="identifier">extract</span><span class="special">&lt;</span><span class="keyword">int</span><span class="special">&gt;(</span><span class="identifier">result</span><span class="special">);</span>
</pre>
<h3>
<a name="using_the_interpreter.exception_handling"></a>
Exception handling
</h3>
<p>
If an exception occurs in the evaluation of the python expression, <a href="../../../../v2/errors.html#error_already_set-spec" target="_top">error_already_set</a>
is thrown:
</p>
<pre class="programlisting"><span class="keyword">try</span>
<span class="special">{</span>
<span class="identifier">object</span> <span class="identifier">result</span> <span class="special">=</span> <span class="identifier">eval</span><span class="special">(</span><span class="string">"5/0"</span><span class="special">);</span>
<span class="comment">// execution will never get here:</span>
<span class="keyword">int</span> <span class="identifier">five_divided_by_zero</span> <span class="special">=</span> <span class="identifier">extract</span><span class="special">&lt;</span><span class="keyword">int</span><span class="special">&gt;(</span><span class="identifier">result</span><span class="special">);</span>
<span class="special">}</span>
<span class="keyword">catch</span><span class="special">(</span><span class="identifier">error_already_set</span> <span class="keyword">const</span> <span class="special">&amp;)</span>
<span class="special">{</span>
<span class="comment">// handle the exception in some way</span>
<span class="special">}</span>
</pre>
<p>
The <code class="literal">error_already_set</code> exception class doesn't carry any
information in itself. To find out more about the Python exception that occurred,
you need to use the <a href="http://www.python.org/doc/api/exceptionHandling.html" target="_top">exception
handling functions</a> of the Python C API in your catch-statement. This
can be as simple as calling <a href="http://www.python.org/doc/api/exceptionHandling.html#l2h-70" target="_top">PyErr_Print()</a>
to print the exception's traceback to the console, or comparing the type
of the exception with those of the <a href="http://www.python.org/doc/api/standardExceptions.html" target="_top">standard
exceptions</a>:
</p>
<pre class="programlisting"><span class="keyword">catch</span><span class="special">(</span><span class="identifier">error_already_set</span> <span class="keyword">const</span> <span class="special">&amp;)</span>
<span class="special">{</span>
<span class="keyword">if</span> <span class="special">(</span><span class="identifier">PyErr_ExceptionMatches</span><span class="special">(</span><span class="identifier">PyExc_ZeroDivisionError</span><span class="special">))</span>
<span class="special">{</span>
<span class="comment">// handle ZeroDivisionError specially</span>
<span class="special">}</span>
<span class="keyword">else</span>
<span class="special">{</span>
<span class="comment">// print all other errors to stderr</span>
<span class="identifier">PyErr_Print</span><span class="special">();</span>
<span class="special">}</span>
<span class="special">}</span>
</pre>
<p>
(To retrieve even more information from the exception you can use some of
the other exception handling functions listed <a href="http://www.python.org/doc/api/exceptionHandling.html" target="_top">here</a>.)
</p>
</div>
</div>
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
<td align="left"></td>
<td align="right"><div class="copyright-footer">Copyright &#169; 2002-2005 Joel
de Guzman, David Abrahams<p>
Distributed under the Boost Software License, Version 1.0. (See accompanying
file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">
http://www.boost.org/LICENSE_1_0.txt </a>)
</p>
</div></td>
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="object.html"><img src="../../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../index.html"><img src="../../../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="iterators.html"><img src="../../../../../../../doc/src/images/next.png" alt="Next"></a>
</div>
</body>
</html>

View File

@@ -0,0 +1,63 @@
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
<title>Exception Translation</title>
<link rel="stylesheet" href="../../../../../../../doc/src/boostbook.css" type="text/css">
<meta name="generator" content="DocBook XSL Stylesheets V1.76.1">
<link rel="home" href="../index.html" title="Chapter&#160;1.&#160;python 2.0">
<link rel="up" href="../index.html" title="Chapter&#160;1.&#160;python 2.0">
<link rel="prev" href="iterators.html" title="Iterators">
<link rel="next" href="techniques.html" title="General Techniques">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<table cellpadding="2" width="100%"><tr>
<td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../../../../../boost.png"></td>
<td align="center"><a href="../../../../../../../index.html">Home</a></td>
<td align="center"><a href="../../../../../../../libs/libraries.htm">Libraries</a></td>
<td align="center"><a href="http://www.boost.org/users/people.html">People</a></td>
<td align="center"><a href="http://www.boost.org/users/faq.html">FAQ</a></td>
<td align="center"><a href="../../../../../../../more/index.htm">More</a></td>
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="iterators.html"><img src="../../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../index.html"><img src="../../../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="techniques.html"><img src="../../../../../../../doc/src/images/next.png" alt="Next"></a>
</div>
<div class="section">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="python.exception"></a>Exception Translation</h2></div></div></div>
<p>
All C++ exceptions must be caught at the boundary with Python code. This boundary
is the point where C++ meets Python. Boost.Python provides a default exception
handler that translates selected standard exceptions, then gives up:
</p>
<pre class="programlisting"><span class="keyword">raise</span> <span class="identifier">RuntimeError</span><span class="special">,</span> <span class="string">'unidentifiable C++ Exception'</span>
</pre>
<p>
Users may provide custom translation. Here's an example:
</p>
<pre class="programlisting"><span class="identifier">struct</span> <span class="identifier">PodBayDoorException</span><span class="special">;</span>
<span class="identifier">void</span> <span class="identifier">translator</span><span class="special">(</span><span class="identifier">PodBayDoorException</span> <span class="identifier">const</span><span class="special">&amp;</span> <span class="identifier">x</span><span class="special">)</span> <span class="special">{</span>
<span class="identifier">PyErr_SetString</span><span class="special">(</span><span class="identifier">PyExc_UserWarning</span><span class="special">,</span> <span class="string">"I'm sorry Dave..."</span><span class="special">);</span>
<span class="special">}</span>
<span class="identifier">BOOST_PYTHON_MODULE</span><span class="special">(</span><span class="identifier">kubrick</span><span class="special">)</span> <span class="special">{</span>
<span class="identifier">register_exception_translator</span><span class="special">&lt;</span>
<span class="identifier">PodBayDoorException</span><span class="special">&gt;(</span><span class="identifier">translator</span><span class="special">);</span>
<span class="special">...</span>
</pre>
</div>
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
<td align="left"></td>
<td align="right"><div class="copyright-footer">Copyright &#169; 2002-2005 Joel
de Guzman, David Abrahams<p>
Distributed under the Boost Software License, Version 1.0. (See accompanying
file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">
http://www.boost.org/LICENSE_1_0.txt </a>)
</p>
</div></td>
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="iterators.html"><img src="../../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../index.html"><img src="../../../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="techniques.html"><img src="../../../../../../../doc/src/images/next.png" alt="Next"></a>
</div>
</body>
</html>

View File

@@ -0,0 +1,591 @@
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
<title>Exposing Classes</title>
<link rel="stylesheet" href="../../../../../../../doc/src/boostbook.css" type="text/css">
<meta name="generator" content="DocBook XSL Stylesheets V1.76.1">
<link rel="home" href="../index.html" title="Chapter&#160;1.&#160;python 2.0">
<link rel="up" href="../index.html" title="Chapter&#160;1.&#160;python 2.0">
<link rel="prev" href="hello.html" title="Building Hello World">
<link rel="next" href="functions.html" title="Functions">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<table cellpadding="2" width="100%"><tr>
<td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../../../../../boost.png"></td>
<td align="center"><a href="../../../../../../../index.html">Home</a></td>
<td align="center"><a href="../../../../../../../libs/libraries.htm">Libraries</a></td>
<td align="center"><a href="http://www.boost.org/users/people.html">People</a></td>
<td align="center"><a href="http://www.boost.org/users/faq.html">FAQ</a></td>
<td align="center"><a href="../../../../../../../more/index.htm">More</a></td>
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="hello.html"><img src="../../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../index.html"><img src="../../../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="functions.html"><img src="../../../../../../../doc/src/images/next.png" alt="Next"></a>
</div>
<div class="section">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="python.exposing"></a>Exposing Classes</h2></div></div></div>
<div class="toc"><dl>
<dt><span class="section"><a href="exposing.html#python.constructors">Constructors</a></span></dt>
<dt><span class="section"><a href="exposing.html#python.class_data_members">Class Data Members</a></span></dt>
<dt><span class="section"><a href="exposing.html#python.class_properties">Class Properties</a></span></dt>
<dt><span class="section"><a href="exposing.html#python.inheritance">Inheritance</a></span></dt>
<dt><span class="section"><a href="exposing.html#python.class_virtual_functions">Class Virtual Functions</a></span></dt>
<dt><span class="section"><a href="exposing.html#python.virtual_functions_with_default_implementations">Virtual Functions with Default Implementations</a></span></dt>
<dt><span class="section"><a href="exposing.html#python.class_operators_special_functions">Class Operators/Special Functions</a></span></dt>
</dl></div>
<p>
Now let's expose a C++ class to Python.
</p>
<p>
Consider a C++ class/struct that we want to expose to Python:
</p>
<pre class="programlisting"><span class="keyword">struct</span> <span class="identifier">World</span>
<span class="special">{</span>
<span class="keyword">void</span> <span class="identifier">set</span><span class="special">(</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">string</span> <span class="identifier">msg</span><span class="special">)</span> <span class="special">{</span> <span class="keyword">this</span><span class="special">-&gt;</span><span class="identifier">msg</span> <span class="special">=</span> <span class="identifier">msg</span><span class="special">;</span> <span class="special">}</span>
<span class="identifier">std</span><span class="special">::</span><span class="identifier">string</span> <span class="identifier">greet</span><span class="special">()</span> <span class="special">{</span> <span class="keyword">return</span> <span class="identifier">msg</span><span class="special">;</span> <span class="special">}</span>
<span class="identifier">std</span><span class="special">::</span><span class="identifier">string</span> <span class="identifier">msg</span><span class="special">;</span>
<span class="special">};</span>
</pre>
<p>
We can expose this to Python by writing a corresponding Boost.Python C++ Wrapper:
</p>
<pre class="programlisting"><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">using</span> <span class="keyword">namespace</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">python</span><span class="special">;</span>
<span class="identifier">BOOST_PYTHON_MODULE</span><span class="special">(</span><span class="identifier">hello</span><span class="special">)</span>
<span class="special">{</span>
<span class="identifier">class_</span><span class="special">&lt;</span><span class="identifier">World</span><span class="special">&gt;(</span><span class="string">"World"</span><span class="special">)</span>
<span class="special">.</span><span class="identifier">def</span><span class="special">(</span><span class="string">"greet"</span><span class="special">,</span> <span class="special">&amp;</span><span class="identifier">World</span><span class="special">::</span><span class="identifier">greet</span><span class="special">)</span>
<span class="special">.</span><span class="identifier">def</span><span class="special">(</span><span class="string">"set"</span><span class="special">,</span> <span class="special">&amp;</span><span class="identifier">World</span><span class="special">::</span><span class="identifier">set</span><span class="special">)</span>
<span class="special">;</span>
<span class="special">}</span>
</pre>
<p>
Here, we wrote a C++ class wrapper that exposes the member functions <code class="literal">greet</code>
and <code class="literal">set</code>. Now, after building our module as a shared library,
we may use our class <code class="literal">World</code> in Python. Here's a sample Python
session:
</p>
<pre class="programlisting"><span class="special">&gt;&gt;&gt;</span> <span class="keyword">import</span> <span class="identifier">hello</span>
<span class="special">&gt;&gt;&gt;</span> <span class="identifier">planet</span> <span class="special">=</span> <span class="identifier">hello</span><span class="special">.</span><span class="identifier">World</span><span class="special">()</span>
<span class="special">&gt;&gt;&gt;</span> <span class="identifier">planet</span><span class="special">.</span><span class="identifier">set</span><span class="special">(</span><span class="string">'howdy'</span><span class="special">)</span>
<span class="special">&gt;&gt;&gt;</span> <span class="identifier">planet</span><span class="special">.</span><span class="identifier">greet</span><span class="special">()</span>
<span class="string">'howdy'</span>
</pre>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="python.constructors"></a>Constructors</h3></div></div></div>
<p>
Our previous example didn't have any explicit constructors. Since <code class="literal">World</code>
is declared as a plain struct, it has an implicit default constructor. Boost.Python
exposes the default constructor by default, which is why we were able to
write
</p>
<pre class="programlisting"><span class="special">&gt;&gt;&gt;</span> <span class="identifier">planet</span> <span class="special">=</span> <span class="identifier">hello</span><span class="special">.</span><span class="identifier">World</span><span class="special">()</span>
</pre>
<p>
We may wish to wrap a class with a non-default constructor. Let us build
on our previous example:
</p>
<pre class="programlisting"><span class="keyword">struct</span> <span class="identifier">World</span>
<span class="special">{</span>
<span class="identifier">World</span><span class="special">(</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">string</span> <span class="identifier">msg</span><span class="special">):</span> <span class="identifier">msg</span><span class="special">(</span><span class="identifier">msg</span><span class="special">)</span> <span class="special">{}</span> <span class="comment">// added constructor</span>
<span class="keyword">void</span> <span class="identifier">set</span><span class="special">(</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">string</span> <span class="identifier">msg</span><span class="special">)</span> <span class="special">{</span> <span class="keyword">this</span><span class="special">-&gt;</span><span class="identifier">msg</span> <span class="special">=</span> <span class="identifier">msg</span><span class="special">;</span> <span class="special">}</span>
<span class="identifier">std</span><span class="special">::</span><span class="identifier">string</span> <span class="identifier">greet</span><span class="special">()</span> <span class="special">{</span> <span class="keyword">return</span> <span class="identifier">msg</span><span class="special">;</span> <span class="special">}</span>
<span class="identifier">std</span><span class="special">::</span><span class="identifier">string</span> <span class="identifier">msg</span><span class="special">;</span>
<span class="special">};</span>
</pre>
<p>
This time <code class="literal">World</code> has no default constructor; our previous
wrapping code would fail to compile when the library tried to expose it.
We have to tell <code class="literal">class_&lt;World&gt;</code> about the constructor
we want to expose instead.
</p>
<pre class="programlisting"><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">using</span> <span class="keyword">namespace</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">python</span><span class="special">;</span>
<span class="identifier">BOOST_PYTHON_MODULE</span><span class="special">(</span><span class="identifier">hello</span><span class="special">)</span>
<span class="special">{</span>
<span class="identifier">class_</span><span class="special">&lt;</span><span class="identifier">World</span><span class="special">&gt;(</span><span class="string">"World"</span><span class="special">,</span> <span class="identifier">init</span><span class="special">&lt;</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">string</span><span class="special">&gt;())</span>
<span class="special">.</span><span class="identifier">def</span><span class="special">(</span><span class="string">"greet"</span><span class="special">,</span> <span class="special">&amp;</span><span class="identifier">World</span><span class="special">::</span><span class="identifier">greet</span><span class="special">)</span>
<span class="special">.</span><span class="identifier">def</span><span class="special">(</span><span class="string">"set"</span><span class="special">,</span> <span class="special">&amp;</span><span class="identifier">World</span><span class="special">::</span><span class="identifier">set</span><span class="special">)</span>
<span class="special">;</span>
<span class="special">}</span>
</pre>
<p>
<code class="literal">init&lt;std::string&gt;()</code> exposes the constructor taking
in a <code class="literal">std::string</code> (in Python, constructors are spelled
"<code class="literal">"__init__"</code>").
</p>
<p>
We can expose additional constructors by passing more <code class="literal">init&lt;...&gt;</code>s
to the <code class="literal">def()</code> member function. Say for example we have
another World constructor taking in two doubles:
</p>
<pre class="programlisting"><span class="identifier">class_</span><span class="special">&lt;</span><span class="identifier">World</span><span class="special">&gt;(</span><span class="string">"World"</span><span class="special">,</span> <span class="identifier">init</span><span class="special">&lt;</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">string</span><span class="special">&gt;())</span>
<span class="special">.</span><span class="identifier">def</span><span class="special">(</span><span class="identifier">init</span><span class="special">&lt;</span><span class="keyword">double</span><span class="special">,</span> <span class="keyword">double</span><span class="special">&gt;())</span>
<span class="special">.</span><span class="identifier">def</span><span class="special">(</span><span class="string">"greet"</span><span class="special">,</span> <span class="special">&amp;</span><span class="identifier">World</span><span class="special">::</span><span class="identifier">greet</span><span class="special">)</span>
<span class="special">.</span><span class="identifier">def</span><span class="special">(</span><span class="string">"set"</span><span class="special">,</span> <span class="special">&amp;</span><span class="identifier">World</span><span class="special">::</span><span class="identifier">set</span><span class="special">)</span>
<span class="special">;</span>
</pre>
<p>
On the other hand, if we do not wish to expose any constructors at all, we
may use <code class="literal">no_init</code> instead:
</p>
<pre class="programlisting"><span class="identifier">class_</span><span class="special">&lt;</span><span class="identifier">Abstract</span><span class="special">&gt;(</span><span class="string">"Abstract"</span><span class="special">,</span> <span class="identifier">no_init</span><span class="special">)</span>
</pre>
<p>
This actually adds an <code class="literal">__init__</code> method which always raises
a Python RuntimeError exception.
</p>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="python.class_data_members"></a>Class Data Members</h3></div></div></div>
<p>
Data members may also be exposed to Python so that they can be accessed as
attributes of the corresponding Python class. Each data member that we wish
to be exposed may be regarded as <span class="bold"><strong>read-only</strong></span>
or <span class="bold"><strong>read-write</strong></span>. Consider this class <code class="literal">Var</code>:
</p>
<pre class="programlisting"><span class="keyword">struct</span> <span class="identifier">Var</span>
<span class="special">{</span>
<span class="identifier">Var</span><span class="special">(</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">string</span> <span class="identifier">name</span><span class="special">)</span> <span class="special">:</span> <span class="identifier">name</span><span class="special">(</span><span class="identifier">name</span><span class="special">),</span> <span class="identifier">value</span><span class="special">()</span> <span class="special">{}</span>
<span class="identifier">std</span><span class="special">::</span><span class="identifier">string</span> <span class="keyword">const</span> <span class="identifier">name</span><span class="special">;</span>
<span class="keyword">float</span> <span class="identifier">value</span><span class="special">;</span>
<span class="special">};</span>
</pre>
<p>
Our C++ <code class="literal">Var</code> class and its data members can be exposed
to Python:
</p>
<pre class="programlisting"><span class="identifier">class_</span><span class="special">&lt;</span><span class="identifier">Var</span><span class="special">&gt;(</span><span class="string">"Var"</span><span class="special">,</span> <span class="identifier">init</span><span class="special">&lt;</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">string</span><span class="special">&gt;())</span>
<span class="special">.</span><span class="identifier">def_readonly</span><span class="special">(</span><span class="string">"name"</span><span class="special">,</span> <span class="special">&amp;</span><span class="identifier">Var</span><span class="special">::</span><span class="identifier">name</span><span class="special">)</span>
<span class="special">.</span><span class="identifier">def_readwrite</span><span class="special">(</span><span class="string">"value"</span><span class="special">,</span> <span class="special">&amp;</span><span class="identifier">Var</span><span class="special">::</span><span class="identifier">value</span><span class="special">);</span>
</pre>
<p>
Then, in Python, assuming we have placed our Var class inside the namespace
hello as we did before:
</p>
<pre class="programlisting"><span class="special">&gt;&gt;&gt;</span> <span class="identifier">x</span> <span class="special">=</span> <span class="identifier">hello</span><span class="special">.</span><span class="identifier">Var</span><span class="special">(</span><span class="string">'pi'</span><span class="special">)</span>
<span class="special">&gt;&gt;&gt;</span> <span class="identifier">x</span><span class="special">.</span><span class="identifier">value</span> <span class="special">=</span> <span class="number">3.14</span>
<span class="special">&gt;&gt;&gt;</span> <span class="keyword">print</span> <span class="identifier">x</span><span class="special">.</span><span class="identifier">name</span><span class="special">,</span> <span class="string">'is around'</span><span class="special">,</span> <span class="identifier">x</span><span class="special">.</span><span class="identifier">value</span>
<span class="identifier">pi</span> <span class="keyword">is</span> <span class="identifier">around</span> <span class="number">3.14</span>
</pre>
<p>
Note that <code class="literal">name</code> is exposed as <span class="bold"><strong>read-only</strong></span>
while <code class="literal">value</code> is exposed as <span class="bold"><strong>read-write</strong></span>.
</p>
<pre class="programlisting"><span class="special">&gt;&gt;&gt;</span> <span class="identifier">x</span><span class="special">.</span><span class="identifier">name</span> <span class="special">=</span> <span class="string">'e'</span> <span class="comment"># can't change name</span>
<span class="identifier">Traceback</span> <span class="special">(</span><span class="identifier">most</span> <span class="identifier">recent</span> <span class="identifier">call</span> <span class="identifier">last</span><span class="special">):</span>
<span class="identifier">File</span> <span class="string">"&lt;stdin&gt;"</span><span class="special">,</span> <span class="identifier">line</span> <span class="number">1</span><span class="special">,</span> <span class="keyword">in</span> <span class="error">?</span>
<span class="identifier">AttributeError</span><span class="special">:</span> <span class="identifier">can</span><span class="error">'</span><span class="identifier">t</span> <span class="identifier">set</span> <span class="identifier">attribute</span>
</pre>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="python.class_properties"></a>Class Properties</h3></div></div></div>
<p>
In C++, classes with public data members are usually frowned upon. Well designed
classes that take advantage of encapsulation hide the class' data members.
The only way to access the class' data is through access (getter/setter)
functions. Access functions expose class properties. Here's an example:
</p>
<pre class="programlisting"><span class="keyword">struct</span> <span class="identifier">Num</span>
<span class="special">{</span>
<span class="identifier">Num</span><span class="special">();</span>
<span class="keyword">float</span> <span class="identifier">get</span><span class="special">()</span> <span class="keyword">const</span><span class="special">;</span>
<span class="keyword">void</span> <span class="identifier">set</span><span class="special">(</span><span class="keyword">float</span> <span class="identifier">value</span><span class="special">);</span>
<span class="special">...</span>
<span class="special">};</span>
</pre>
<p>
However, in Python attribute access is fine; it doesn't neccessarily break
encapsulation to let users handle attributes directly, because the attributes
can just be a different syntax for a method call. Wrapping our <code class="literal">Num</code>
class using Boost.Python:
</p>
<pre class="programlisting"><span class="identifier">class_</span><span class="special">&lt;</span><span class="identifier">Num</span><span class="special">&gt;(</span><span class="string">"Num"</span><span class="special">)</span>
<span class="special">.</span><span class="identifier">add_property</span><span class="special">(</span><span class="string">"rovalue"</span><span class="special">,</span> <span class="special">&amp;</span><span class="identifier">Num</span><span class="special">::</span><span class="identifier">get</span><span class="special">)</span>
<span class="special">.</span><span class="identifier">add_property</span><span class="special">(</span><span class="string">"value"</span><span class="special">,</span> <span class="special">&amp;</span><span class="identifier">Num</span><span class="special">::</span><span class="identifier">get</span><span class="special">,</span> <span class="special">&amp;</span><span class="identifier">Num</span><span class="special">::</span><span class="identifier">set</span><span class="special">);</span>
</pre>
<p>
And at last, in Python:
</p>
<pre class="programlisting"><span class="special">&gt;&gt;&gt;</span> <span class="identifier">x</span> <span class="special">=</span> <span class="identifier">Num</span><span class="special">()</span>
<span class="special">&gt;&gt;&gt;</span> <span class="identifier">x</span><span class="special">.</span><span class="identifier">value</span> <span class="special">=</span> <span class="number">3.14</span>
<span class="special">&gt;&gt;&gt;</span> <span class="identifier">x</span><span class="special">.</span><span class="identifier">value</span><span class="special">,</span> <span class="identifier">x</span><span class="special">.</span><span class="identifier">rovalue</span>
<span class="special">(</span><span class="number">3.14</span><span class="special">,</span> <span class="number">3.14</span><span class="special">)</span>
<span class="special">&gt;&gt;&gt;</span> <span class="identifier">x</span><span class="special">.</span><span class="identifier">rovalue</span> <span class="special">=</span> <span class="number">2.17</span> <span class="comment"># error!</span>
</pre>
<p>
Take note that the class property <code class="literal">rovalue</code> is exposed as
<span class="bold"><strong>read-only</strong></span> since the <code class="literal">rovalue</code>
setter member function is not passed in:
</p>
<pre class="programlisting"><span class="special">.</span><span class="identifier">add_property</span><span class="special">(</span><span class="string">"rovalue"</span><span class="special">,</span> <span class="special">&amp;</span><span class="identifier">Num</span><span class="special">::</span><span class="identifier">get</span><span class="special">)</span>
</pre>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="python.inheritance"></a>Inheritance</h3></div></div></div>
<p>
In the previous examples, we dealt with classes that are not polymorphic.
This is not often the case. Much of the time, we will be wrapping polymorphic
classes and class hierarchies related by inheritance. We will often have
to write Boost.Python wrappers for classes that are derived from abstract
base classes.
</p>
<p>
Consider this trivial inheritance structure:
</p>
<pre class="programlisting"><span class="keyword">struct</span> <span class="identifier">Base</span> <span class="special">{</span> <span class="keyword">virtual</span> <span class="special">~</span><span class="identifier">Base</span><span class="special">();</span> <span class="special">};</span>
<span class="keyword">struct</span> <span class="identifier">Derived</span> <span class="special">:</span> <span class="identifier">Base</span> <span class="special">{};</span>
</pre>
<p>
And a set of C++ functions operating on <code class="literal">Base</code> and <code class="literal">Derived</code>
object instances:
</p>
<pre class="programlisting"><span class="keyword">void</span> <span class="identifier">b</span><span class="special">(</span><span class="identifier">Base</span><span class="special">*);</span>
<span class="keyword">void</span> <span class="identifier">d</span><span class="special">(</span><span class="identifier">Derived</span><span class="special">*);</span>
<span class="identifier">Base</span><span class="special">*</span> <span class="identifier">factory</span><span class="special">()</span> <span class="special">{</span> <span class="keyword">return</span> <span class="keyword">new</span> <span class="identifier">Derived</span><span class="special">;</span> <span class="special">}</span>
</pre>
<p>
We've seen how we can wrap the base class <code class="literal">Base</code>:
</p>
<pre class="programlisting"><span class="identifier">class_</span><span class="special">&lt;</span><span class="identifier">Base</span><span class="special">&gt;(</span><span class="string">"Base"</span><span class="special">)</span>
<span class="comment">/*...*/</span>
<span class="special">;</span>
</pre>
<p>
Now we can inform Boost.Python of the inheritance relationship between <code class="literal">Derived</code>
and its base class <code class="literal">Base</code>. Thus:
</p>
<pre class="programlisting"><span class="identifier">class_</span><span class="special">&lt;</span><span class="identifier">Derived</span><span class="special">,</span> <span class="identifier">bases</span><span class="special">&lt;</span><span class="identifier">Base</span><span class="special">&gt;</span> <span class="special">&gt;(</span><span class="string">"Derived"</span><span class="special">)</span>
<span class="comment">/*...*/</span>
<span class="special">;</span>
</pre>
<p>
Doing so, we get some things for free:
</p>
<div class="orderedlist"><ol class="orderedlist" type="1">
<li class="listitem">
Derived automatically inherits all of Base's Python methods (wrapped
C++ member functions)
</li>
<li class="listitem">
<span class="bold"><strong>If</strong></span> Base is polymorphic, <code class="literal">Derived</code>
objects which have been passed to Python via a pointer or reference to
<code class="literal">Base</code> can be passed where a pointer or reference to
<code class="literal">Derived</code> is expected.
</li>
</ol></div>
<p>
Now, we will expose the C++ free functions <code class="literal">b</code> and <code class="literal">d</code>
and <code class="literal">factory</code>:
</p>
<pre class="programlisting"><span class="identifier">def</span><span class="special">(</span><span class="string">"b"</span><span class="special">,</span> <span class="identifier">b</span><span class="special">);</span>
<span class="identifier">def</span><span class="special">(</span><span class="string">"d"</span><span class="special">,</span> <span class="identifier">d</span><span class="special">);</span>
<span class="identifier">def</span><span class="special">(</span><span class="string">"factory"</span><span class="special">,</span> <span class="identifier">factory</span><span class="special">);</span>
</pre>
<p>
Note that free function <code class="literal">factory</code> is being used to generate
new instances of class <code class="literal">Derived</code>. In such cases, we use
<code class="literal">return_value_policy&lt;manage_new_object&gt;</code> to instruct
Python to adopt the pointer to <code class="literal">Base</code> and hold the instance
in a new Python <code class="literal">Base</code> object until the the Python object
is destroyed. We will see more of Boost.Python <a class="link" href="functions.html#python.call_policies" title="Call Policies">call
policies</a> later.
</p>
<pre class="programlisting"><span class="comment">// Tell Python to take ownership of factory's result</span>
<span class="identifier">def</span><span class="special">(</span><span class="string">"factory"</span><span class="special">,</span> <span class="identifier">factory</span><span class="special">,</span>
<span class="identifier">return_value_policy</span><span class="special">&lt;</span><span class="identifier">manage_new_object</span><span class="special">&gt;());</span>
</pre>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="python.class_virtual_functions"></a>Class Virtual Functions</h3></div></div></div>
<p>
In this section, we will learn how to make functions behave polymorphically
through virtual functions. Continuing our example, let us add a virtual function
to our <code class="literal">Base</code> class:
</p>
<pre class="programlisting"><span class="keyword">struct</span> <span class="identifier">Base</span>
<span class="special">{</span>
<span class="keyword">virtual</span> <span class="special">~</span><span class="identifier">Base</span><span class="special">()</span> <span class="special">{}</span>
<span class="keyword">virtual</span> <span class="keyword">int</span> <span class="identifier">f</span><span class="special">()</span> <span class="special">=</span> <span class="number">0</span><span class="special">;</span>
<span class="special">};</span>
</pre>
<p>
One of the goals of Boost.Python is to be minimally intrusive on an existing
C++ design. In principle, it should be possible to expose the interface for
a 3rd party library without changing it. It is not ideal to add anything
to our class <code class="computeroutput"><span class="identifier">Base</span></code>. Yet, when
you have a virtual function that's going to be overridden in Python and called
polymorphically <span class="bold"><strong>from C++</strong></span>, we'll need to
add some scaffoldings to make things work properly. What we'll do is write
a class wrapper that derives from <code class="computeroutput"><span class="identifier">Base</span></code>
that will unintrusively hook into the virtual functions so that a Python
override may be called:
</p>
<pre class="programlisting"><span class="keyword">struct</span> <span class="identifier">BaseWrap</span> <span class="special">:</span> <span class="identifier">Base</span><span class="special">,</span> <span class="identifier">wrapper</span><span class="special">&lt;</span><span class="identifier">Base</span><span class="special">&gt;</span>
<span class="special">{</span>
<span class="keyword">int</span> <span class="identifier">f</span><span class="special">()</span>
<span class="special">{</span>
<span class="keyword">return</span> <span class="keyword">this</span><span class="special">-&gt;</span><span class="identifier">get_override</span><span class="special">(</span><span class="string">"f"</span><span class="special">)();</span>
<span class="special">}</span>
<span class="special">};</span>
</pre>
<p>
Notice too that in addition to inheriting from <code class="computeroutput"><span class="identifier">Base</span></code>,
we also multiply- inherited <code class="computeroutput"><span class="identifier">wrapper</span><span class="special">&lt;</span><span class="identifier">Base</span><span class="special">&gt;</span></code> (See <a href="../../../../v2/wrapper.html" target="_top">Wrapper</a>).
The <code class="computeroutput"><span class="identifier">wrapper</span></code> template makes
the job of wrapping classes that are meant to overridden in Python, easier.
</p>
<div class="sidebar">
<div class="titlepage"></div>
<p>
<span class="inlinemediaobject"><img src="../images/alert.png" alt="alert"></span> <span class="bold"><strong>MSVC6/7 Workaround</strong></span>
</p>
<p>
If you are using Microsoft Visual C++ 6 or 7, you have to write <code class="computeroutput"><span class="identifier">f</span></code> as:
</p>
<p>
<code class="computeroutput"><span class="keyword">return</span> <span class="identifier">call</span><span class="special">&lt;</span><span class="keyword">int</span><span class="special">&gt;(</span><span class="keyword">this</span><span class="special">-&gt;</span><span class="identifier">get_override</span><span class="special">(</span><span class="string">"f"</span><span class="special">).</span><span class="identifier">ptr</span><span class="special">());</span></code>.
</p>
</div>
<p>
BaseWrap's overridden virtual member function <code class="computeroutput"><span class="identifier">f</span></code>
in effect calls the corresponding method of the Python object through <code class="computeroutput"><span class="identifier">get_override</span></code>.
</p>
<p>
Finally, exposing <code class="computeroutput"><span class="identifier">Base</span></code>:
</p>
<pre class="programlisting"><span class="identifier">class_</span><span class="special">&lt;</span><span class="identifier">BaseWrap</span><span class="special">,</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">noncopyable</span><span class="special">&gt;(</span><span class="string">"Base"</span><span class="special">)</span>
<span class="special">.</span><span class="identifier">def</span><span class="special">(</span><span class="string">"f"</span><span class="special">,</span> <span class="identifier">pure_virtual</span><span class="special">(&amp;</span><span class="identifier">Base</span><span class="special">::</span><span class="identifier">f</span><span class="special">))</span>
<span class="special">;</span>
</pre>
<p>
<code class="computeroutput"><span class="identifier">pure_virtual</span></code> signals Boost.Python
that the function <code class="computeroutput"><span class="identifier">f</span></code> is a
pure virtual function.
</p>
<div class="note"><table border="0" summary="Note">
<tr>
<td rowspan="2" align="center" valign="top" width="25"><img alt="[Note]" src="../../../../../../../doc/src/images/note.png"></td>
<th align="left">Note</th>
</tr>
<tr><td align="left" valign="top">
<p>
<span class="bold"><strong>member function and methods</strong></span>
</p>
<p>
Python, like many object oriented languages uses the term <span class="bold"><strong>methods</strong></span>.
Methods correspond roughly to C++'s <span class="bold"><strong>member functions</strong></span>
</p>
</td></tr>
</table></div>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="python.virtual_functions_with_default_implementations"></a>Virtual Functions with Default Implementations</h3></div></div></div>
<p>
We've seen in the previous section how classes with pure virtual functions
are wrapped using Boost.Python's <a href="../../../../v2/wrapper.html" target="_top">class
wrapper</a> facilities. If we wish to wrap <span class="bold"><strong>non</strong></span>-pure-virtual
functions instead, the mechanism is a bit different.
</p>
<p>
Recall that in the <a class="link" href="exposing.html#python.class_virtual_functions" title="Class Virtual Functions">previous
section</a>, we wrapped a class with a pure virtual function that we then
implemented in C++, or Python classes derived from it. Our base class:
</p>
<pre class="programlisting"><span class="keyword">struct</span> <span class="identifier">Base</span>
<span class="special">{</span>
<span class="keyword">virtual</span> <span class="keyword">int</span> <span class="identifier">f</span><span class="special">()</span> <span class="special">=</span> <span class="number">0</span><span class="special">;</span>
<span class="special">};</span>
</pre>
<p>
had a pure virtual function <code class="literal">f</code>. If, however, its member
function <code class="literal">f</code> was not declared as pure virtual:
</p>
<pre class="programlisting"><span class="keyword">struct</span> <span class="identifier">Base</span>
<span class="special">{</span>
<span class="keyword">virtual</span> <span class="special">~</span><span class="identifier">Base</span><span class="special">()</span> <span class="special">{}</span>
<span class="keyword">virtual</span> <span class="keyword">int</span> <span class="identifier">f</span><span class="special">()</span> <span class="special">{</span> <span class="keyword">return</span> <span class="number">0</span><span class="special">;</span> <span class="special">}</span>
<span class="special">};</span>
</pre>
<p>
We wrap it this way:
</p>
<pre class="programlisting"><span class="keyword">struct</span> <span class="identifier">BaseWrap</span> <span class="special">:</span> <span class="identifier">Base</span><span class="special">,</span> <span class="identifier">wrapper</span><span class="special">&lt;</span><span class="identifier">Base</span><span class="special">&gt;</span>
<span class="special">{</span>
<span class="keyword">int</span> <span class="identifier">f</span><span class="special">()</span>
<span class="special">{</span>
<span class="keyword">if</span> <span class="special">(</span><span class="identifier">override</span> <span class="identifier">f</span> <span class="special">=</span> <span class="keyword">this</span><span class="special">-&gt;</span><span class="identifier">get_override</span><span class="special">(</span><span class="string">"f"</span><span class="special">))</span>
<span class="keyword">return</span> <span class="identifier">f</span><span class="special">();</span> <span class="comment">// *note*</span>
<span class="keyword">return</span> <span class="identifier">Base</span><span class="special">::</span><span class="identifier">f</span><span class="special">();</span>
<span class="special">}</span>
<span class="keyword">int</span> <span class="identifier">default_f</span><span class="special">()</span> <span class="special">{</span> <span class="keyword">return</span> <span class="keyword">this</span><span class="special">-&gt;</span><span class="identifier">Base</span><span class="special">::</span><span class="identifier">f</span><span class="special">();</span> <span class="special">}</span>
<span class="special">};</span>
</pre>
<p>
Notice how we implemented <code class="computeroutput"><span class="identifier">BaseWrap</span><span class="special">::</span><span class="identifier">f</span></code>. Now,
we have to check if there is an override for <code class="computeroutput"><span class="identifier">f</span></code>.
If none, then we call <code class="computeroutput"><span class="identifier">Base</span><span class="special">::</span><span class="identifier">f</span><span class="special">()</span></code>.
</p>
<div class="sidebar">
<div class="titlepage"></div>
<p>
<span class="inlinemediaobject"><img src="../images/alert.png" alt="alert"></span> <span class="bold"><strong>MSVC6/7 Workaround</strong></span>
</p>
<p>
If you are using Microsoft Visual C++ 6 or 7, you have to rewrite the line
with the <code class="computeroutput"><span class="special">*</span><span class="identifier">note</span><span class="special">*</span></code> as:
</p>
<p>
<code class="computeroutput"><span class="keyword">return</span> <span class="identifier">call</span><span class="special">&lt;</span><span class="keyword">char</span> <span class="keyword">const</span><span class="special">*&gt;(</span><span class="identifier">f</span><span class="special">.</span><span class="identifier">ptr</span><span class="special">());</span></code>.
</p>
</div>
<p>
Finally, exposing:
</p>
<pre class="programlisting"><span class="identifier">class_</span><span class="special">&lt;</span><span class="identifier">BaseWrap</span><span class="special">,</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">noncopyable</span><span class="special">&gt;(</span><span class="string">"Base"</span><span class="special">)</span>
<span class="special">.</span><span class="identifier">def</span><span class="special">(</span><span class="string">"f"</span><span class="special">,</span> <span class="special">&amp;</span><span class="identifier">Base</span><span class="special">::</span><span class="identifier">f</span><span class="special">,</span> <span class="special">&amp;</span><span class="identifier">BaseWrap</span><span class="special">::</span><span class="identifier">default_f</span><span class="special">)</span>
<span class="special">;</span>
</pre>
<p>
Take note that we expose both <code class="computeroutput"><span class="special">&amp;</span><span class="identifier">Base</span><span class="special">::</span><span class="identifier">f</span></code> and <code class="computeroutput"><span class="special">&amp;</span><span class="identifier">BaseWrap</span><span class="special">::</span><span class="identifier">default_f</span></code>. Boost.Python needs to keep track
of 1) the dispatch function <code class="literal">f</code> and 2) the forwarding function
to its default implementation <code class="literal">default_f</code>. There's a special
<code class="literal">def</code> function for this purpose.
</p>
<p>
In Python, the results would be as expected:
</p>
<pre class="programlisting"><span class="special">&gt;&gt;&gt;</span> <span class="identifier">base</span> <span class="special">=</span> <span class="identifier">Base</span><span class="special">()</span>
<span class="special">&gt;&gt;&gt;</span> <span class="keyword">class</span> <span class="identifier">Derived</span><span class="special">(</span><span class="identifier">Base</span><span class="special">):</span>
<span class="special">...</span> <span class="keyword">def</span> <span class="identifier">f</span><span class="special">(</span><span class="identifier">self</span><span class="special">):</span>
<span class="special">...</span> <span class="keyword">return</span> <span class="number">42</span>
<span class="special">...</span>
<span class="special">&gt;&gt;&gt;</span> <span class="identifier">derived</span> <span class="special">=</span> <span class="identifier">Derived</span><span class="special">()</span>
</pre>
<p>
Calling <code class="literal">base.f()</code>:
</p>
<pre class="programlisting"><span class="special">&gt;&gt;&gt;</span> <span class="identifier">base</span><span class="special">.</span><span class="identifier">f</span><span class="special">()</span>
<span class="number">0</span>
</pre>
<p>
Calling <code class="literal">derived.f()</code>:
</p>
<pre class="programlisting"><span class="special">&gt;&gt;&gt;</span> <span class="identifier">derived</span><span class="special">.</span><span class="identifier">f</span><span class="special">()</span>
<span class="number">42</span>
</pre>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="python.class_operators_special_functions"></a>Class Operators/Special Functions</h3></div></div></div>
<h3>
<a name="class_operators_special_functions.python_operators"></a>
Python Operators
</h3>
<p>
C is well known for the abundance of operators. C++ extends this to the extremes
by allowing operator overloading. Boost.Python takes advantage of this and
makes it easy to wrap C++ operator-powered classes.
</p>
<p>
Consider a file position class <code class="literal">FilePos</code> and a set of operators
that take on FilePos instances:
</p>
<pre class="programlisting"><span class="keyword">class</span> <span class="identifier">FilePos</span> <span class="special">{</span> <span class="comment">/*...*/</span> <span class="special">};</span>
<span class="identifier">FilePos</span> <span class="keyword">operator</span><span class="special">+(</span><span class="identifier">FilePos</span><span class="special">,</span> <span class="keyword">int</span><span class="special">);</span>
<span class="identifier">FilePos</span> <span class="keyword">operator</span><span class="special">+(</span><span class="keyword">int</span><span class="special">,</span> <span class="identifier">FilePos</span><span class="special">);</span>
<span class="keyword">int</span> <span class="keyword">operator</span><span class="special">-(</span><span class="identifier">FilePos</span><span class="special">,</span> <span class="identifier">FilePos</span><span class="special">);</span>
<span class="identifier">FilePos</span> <span class="keyword">operator</span><span class="special">-(</span><span class="identifier">FilePos</span><span class="special">,</span> <span class="keyword">int</span><span class="special">);</span>
<span class="identifier">FilePos</span><span class="special">&amp;</span> <span class="keyword">operator</span><span class="special">+=(</span><span class="identifier">FilePos</span><span class="special">&amp;,</span> <span class="keyword">int</span><span class="special">);</span>
<span class="identifier">FilePos</span><span class="special">&amp;</span> <span class="keyword">operator</span><span class="special">-=(</span><span class="identifier">FilePos</span><span class="special">&amp;,</span> <span class="keyword">int</span><span class="special">);</span>
<span class="keyword">bool</span> <span class="keyword">operator</span><span class="special">&lt;(</span><span class="identifier">FilePos</span><span class="special">,</span> <span class="identifier">FilePos</span><span class="special">);</span>
</pre>
<p>
The class and the various operators can be mapped to Python rather easily
and intuitively:
</p>
<pre class="programlisting"><span class="identifier">class_</span><span class="special">&lt;</span><span class="identifier">FilePos</span><span class="special">&gt;(</span><span class="string">"FilePos"</span><span class="special">)</span>
<span class="special">.</span><span class="identifier">def</span><span class="special">(</span><span class="identifier">self</span> <span class="special">+</span> <span class="keyword">int</span><span class="special">())</span> <span class="comment">// __add__</span>
<span class="special">.</span><span class="identifier">def</span><span class="special">(</span><span class="keyword">int</span><span class="special">()</span> <span class="special">+</span> <span class="identifier">self</span><span class="special">)</span> <span class="comment">// __radd__</span>
<span class="special">.</span><span class="identifier">def</span><span class="special">(</span><span class="identifier">self</span> <span class="special">-</span> <span class="identifier">self</span><span class="special">)</span> <span class="comment">// __sub__</span>
<span class="special">.</span><span class="identifier">def</span><span class="special">(</span><span class="identifier">self</span> <span class="special">-</span> <span class="keyword">int</span><span class="special">())</span> <span class="comment">// __sub__</span>
<span class="special">.</span><span class="identifier">def</span><span class="special">(</span><span class="identifier">self</span> <span class="special">+=</span> <span class="keyword">int</span><span class="special">())</span> <span class="comment">// __iadd__</span>
<span class="special">.</span><span class="identifier">def</span><span class="special">(</span><span class="identifier">self</span> <span class="special">-=</span> <span class="identifier">other</span><span class="special">&lt;</span><span class="keyword">int</span><span class="special">&gt;())</span>
<span class="special">.</span><span class="identifier">def</span><span class="special">(</span><span class="identifier">self</span> <span class="special">&lt;</span> <span class="identifier">self</span><span class="special">);</span> <span class="comment">// __lt__</span>
</pre>
<p>
The code snippet above is very clear and needs almost no explanation at all.
It is virtually the same as the operators' signatures. Just take note that
<code class="literal">self</code> refers to FilePos object. Also, not every class
<code class="literal">T</code> that you might need to interact with in an operator
expression is (cheaply) default-constructible. You can use <code class="literal">other&lt;T&gt;()</code>
in place of an actual <code class="literal">T</code> instance when writing "self
expressions".
</p>
<h3>
<a name="class_operators_special_functions.special_methods"></a>
Special Methods
</h3>
<p>
Python has a few more <span class="emphasis"><em>Special Methods</em></span>. Boost.Python
supports all of the standard special method names supported by real Python
class instances. A similar set of intuitive interfaces can also be used to
wrap C++ functions that correspond to these Python <span class="emphasis"><em>special functions</em></span>.
Example:
</p>
<pre class="programlisting"><span class="keyword">class</span> <span class="identifier">Rational</span>
<span class="special">{</span> <span class="keyword">public</span><span class="special">:</span> <span class="keyword">operator</span> <span class="keyword">double</span><span class="special">()</span> <span class="keyword">const</span><span class="special">;</span> <span class="special">};</span>
<span class="identifier">Rational</span> <span class="identifier">pow</span><span class="special">(</span><span class="identifier">Rational</span><span class="special">,</span> <span class="identifier">Rational</span><span class="special">);</span>
<span class="identifier">Rational</span> <span class="identifier">abs</span><span class="special">(</span><span class="identifier">Rational</span><span class="special">);</span>
<span class="identifier">ostream</span><span class="special">&amp;</span> <span class="keyword">operator</span><span class="special">&lt;&lt;(</span><span class="identifier">ostream</span><span class="special">&amp;,</span><span class="identifier">Rational</span><span class="special">);</span>
<span class="identifier">class_</span><span class="special">&lt;</span><span class="identifier">Rational</span><span class="special">&gt;(</span><span class="string">"Rational"</span><span class="special">)</span>
<span class="special">.</span><span class="identifier">def</span><span class="special">(</span><span class="identifier">float_</span><span class="special">(</span><span class="identifier">self</span><span class="special">))</span> <span class="comment">// __float__</span>
<span class="special">.</span><span class="identifier">def</span><span class="special">(</span><span class="identifier">pow</span><span class="special">(</span><span class="identifier">self</span><span class="special">,</span> <span class="identifier">other</span><span class="special">&lt;</span><span class="identifier">Rational</span><span class="special">&gt;))</span> <span class="comment">// __pow__</span>
<span class="special">.</span><span class="identifier">def</span><span class="special">(</span><span class="identifier">abs</span><span class="special">(</span><span class="identifier">self</span><span class="special">))</span> <span class="comment">// __abs__</span>
<span class="special">.</span><span class="identifier">def</span><span class="special">(</span><span class="identifier">str</span><span class="special">(</span><span class="identifier">self</span><span class="special">))</span> <span class="comment">// __str__</span>
<span class="special">;</span>
</pre>
<p>
Need we say more?
</p>
<div class="note"><table border="0" summary="Note">
<tr>
<td rowspan="2" align="center" valign="top" width="25"><img alt="[Note]" src="../../../../../../../doc/src/images/note.png"></td>
<th align="left">Note</th>
</tr>
<tr><td align="left" valign="top"><p>
What is the business of <code class="computeroutput"><span class="keyword">operator</span><span class="special">&lt;&lt;</span></code>? Well, the method <code class="computeroutput"><span class="identifier">str</span></code> requires the <code class="computeroutput"><span class="keyword">operator</span><span class="special">&lt;&lt;</span></code> to do its work (i.e. <code class="computeroutput"><span class="keyword">operator</span><span class="special">&lt;&lt;</span></code>
is used by the method defined by <code class="computeroutput"><span class="identifier">def</span><span class="special">(</span><span class="identifier">str</span><span class="special">(</span><span class="identifier">self</span><span class="special">))</span></code>.
</p></td></tr>
</table></div>
</div>
</div>
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
<td align="left"></td>
<td align="right"><div class="copyright-footer">Copyright &#169; 2002-2005 Joel
de Guzman, David Abrahams<p>
Distributed under the Boost Software License, Version 1.0. (See accompanying
file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">
http://www.boost.org/LICENSE_1_0.txt </a>)
</p>
</div></td>
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="hello.html"><img src="../../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../index.html"><img src="../../../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="functions.html"><img src="../../../../../../../doc/src/images/next.png" alt="Next"></a>
</div>
</body>
</html>

View File

@@ -0,0 +1,586 @@
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
<title>Functions</title>
<link rel="stylesheet" href="../../../../../../../doc/src/boostbook.css" type="text/css">
<meta name="generator" content="DocBook XSL Stylesheets V1.76.1">
<link rel="home" href="../index.html" title="Chapter&#160;1.&#160;python 2.0">
<link rel="up" href="../index.html" title="Chapter&#160;1.&#160;python 2.0">
<link rel="prev" href="exposing.html" title="Exposing Classes">
<link rel="next" href="object.html" title="Object Interface">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<table cellpadding="2" width="100%"><tr>
<td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../../../../../boost.png"></td>
<td align="center"><a href="../../../../../../../index.html">Home</a></td>
<td align="center"><a href="../../../../../../../libs/libraries.htm">Libraries</a></td>
<td align="center"><a href="http://www.boost.org/users/people.html">People</a></td>
<td align="center"><a href="http://www.boost.org/users/faq.html">FAQ</a></td>
<td align="center"><a href="../../../../../../../more/index.htm">More</a></td>
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="exposing.html"><img src="../../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../index.html"><img src="../../../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="object.html"><img src="../../../../../../../doc/src/images/next.png" alt="Next"></a>
</div>
<div class="section">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="python.functions"></a>Functions</h2></div></div></div>
<div class="toc"><dl>
<dt><span class="section"><a href="functions.html#python.call_policies">Call Policies</a></span></dt>
<dt><span class="section"><a href="functions.html#python.overloading">Overloading</a></span></dt>
<dt><span class="section"><a href="functions.html#python.default_arguments">Default Arguments</a></span></dt>
<dt><span class="section"><a href="functions.html#python.auto_overloading">Auto-Overloading</a></span></dt>
</dl></div>
<p>
In this chapter, we'll look at Boost.Python powered functions in closer detail.
We will see some facilities to make exposing C++ functions to Python safe from
potential pifalls such as dangling pointers and references. We will also see
facilities that will make it even easier for us to expose C++ functions that
take advantage of C++ features such as overloading and default arguments.
</p>
<div class="blockquote"><blockquote class="blockquote"><p>
<span class="emphasis"><em>Read on...</em></span>
</p></blockquote></div>
<p>
But before you do, you might want to fire up Python 2.2 or later and type
<code class="literal">&gt;&gt;&gt; import this</code>.
</p>
<pre class="programlisting">&gt;&gt;&gt; import this
The Zen of Python, by Tim Peters
Beautiful is better than ugly.
Explicit is better than implicit.
Simple is better than complex.
Complex is better than complicated.
Flat is better than nested.
Sparse is better than dense.
Readability counts.
Special cases aren't special enough to break the rules.
Although practicality beats purity.
Errors should never pass silently.
Unless explicitly silenced.
In the face of ambiguity, refuse the temptation to guess.
There should be one-- and preferably only one --obvious way to do it
Although that way may not be obvious at first unless you're Dutch.
Now is better than never.
Although never is often better than <span class="bold"><strong>right</strong></span> now.
If the implementation is hard to explain, it's a bad idea.
If the implementation is easy to explain, it may be a good idea.
Namespaces are one honking great idea -- let's do more of those!
</pre>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="python.call_policies"></a>Call Policies</h3></div></div></div>
<p>
In C++, we often deal with arguments and return types such as pointers and
references. Such primitive types are rather, ummmm, low level and they really
don't tell us much. At the very least, we don't know the owner of the pointer
or the referenced object. No wonder languages such as Java and Python never
deal with such low level entities. In C++, it's usually considered a good
practice to use smart pointers which exactly describe ownership semantics.
Still, even good C++ interfaces use raw references and pointers sometimes,
so Boost.Python must deal with them. To do this, it may need your help. Consider
the following C++ function:
</p>
<pre class="programlisting"><span class="identifier">X</span><span class="special">&amp;</span> <span class="identifier">f</span><span class="special">(</span><span class="identifier">Y</span><span class="special">&amp;</span> <span class="identifier">y</span><span class="special">,</span> <span class="identifier">Z</span><span class="special">*</span> <span class="identifier">z</span><span class="special">);</span>
</pre>
<p>
How should the library wrap this function? A naive approach builds a Python
X object around result reference. This strategy might or might not work out.
Here's an example where it didn't
</p>
<pre class="programlisting"><span class="special">&gt;&gt;&gt;</span> <span class="identifier">x</span> <span class="special">=</span> <span class="identifier">f</span><span class="special">(</span><span class="identifier">y</span><span class="special">,</span> <span class="identifier">z</span><span class="special">)</span> <span class="preprocessor"># x</span> <span class="identifier">refers</span> <span class="identifier">to</span> <span class="identifier">some</span> <span class="identifier">C</span><span class="special">++</span> <span class="identifier">X</span>
<span class="special">&gt;&gt;&gt;</span> <span class="identifier">del</span> <span class="identifier">y</span>
<span class="special">&gt;&gt;&gt;</span> <span class="identifier">x</span><span class="special">.</span><span class="identifier">some_method</span><span class="special">()</span> <span class="preprocessor"># CRASH</span><span class="special">!</span>
</pre>
<p>
What's the problem?
</p>
<p>
Well, what if f() was implemented as shown below:
</p>
<pre class="programlisting"><span class="identifier">X</span><span class="special">&amp;</span> <span class="identifier">f</span><span class="special">(</span><span class="identifier">Y</span><span class="special">&amp;</span> <span class="identifier">y</span><span class="special">,</span> <span class="identifier">Z</span><span class="special">*</span> <span class="identifier">z</span><span class="special">)</span>
<span class="special">{</span>
<span class="identifier">y</span><span class="special">.</span><span class="identifier">z</span> <span class="special">=</span> <span class="identifier">z</span><span class="special">;</span>
<span class="keyword">return</span> <span class="identifier">y</span><span class="special">.</span><span class="identifier">x</span><span class="special">;</span>
<span class="special">}</span>
</pre>
<p>
The problem is that the lifetime of result X&amp; is tied to the lifetime
of y, because the f() returns a reference to a member of the y object. This
idiom is is not uncommon and perfectly acceptable in the context of C++.
However, Python users should not be able to crash the system just by using
our C++ interface. In this case deleting y will invalidate the reference
to X. We have a dangling reference.
</p>
<p>
Here's what's happening:
</p>
<div class="orderedlist"><ol class="orderedlist" type="1">
<li class="listitem">
<code class="literal">f</code> is called passing in a reference to <code class="literal">y</code>
and a pointer to <code class="literal">z</code>
</li>
<li class="listitem">
A reference to <code class="literal">y.x</code> is returned
</li>
<li class="listitem">
<code class="literal">y</code> is deleted. <code class="literal">x</code> is a dangling reference
</li>
<li class="listitem">
<code class="literal">x.some_method()</code> is called
</li>
<li class="listitem">
<span class="bold"><strong>BOOM!</strong></span>
</li>
</ol></div>
<p>
We could copy result into a new object:
</p>
<pre class="programlisting"><span class="special">&gt;&gt;&gt;</span> <span class="identifier">f</span><span class="special">(</span><span class="identifier">y</span><span class="special">,</span> <span class="identifier">z</span><span class="special">).</span><span class="identifier">set</span><span class="special">(</span><span class="number">42</span><span class="special">)</span> <span class="comment"># Result disappears</span>
<span class="special">&gt;&gt;&gt;</span> <span class="identifier">y</span><span class="special">.</span><span class="identifier">x</span><span class="special">.</span><span class="identifier">get</span><span class="special">()</span> <span class="comment"># No crash, but still bad</span>
<span class="number">3.14</span>
</pre>
<p>
This is not really our intent of our C++ interface. We've broken our promise
that the Python interface should reflect the C++ interface as closely as
possible.
</p>
<p>
Our problems do not end there. Suppose Y is implemented as follows:
</p>
<pre class="programlisting"><span class="keyword">struct</span> <span class="identifier">Y</span>
<span class="special">{</span>
<span class="identifier">X</span> <span class="identifier">x</span><span class="special">;</span> <span class="identifier">Z</span><span class="special">*</span> <span class="identifier">z</span><span class="special">;</span>
<span class="keyword">int</span> <span class="identifier">z_value</span><span class="special">()</span> <span class="special">{</span> <span class="keyword">return</span> <span class="identifier">z</span><span class="special">-&gt;</span><span class="identifier">value</span><span class="special">();</span> <span class="special">}</span>
<span class="special">};</span>
</pre>
<p>
Notice that the data member <code class="literal">z</code> is held by class Y using
a raw pointer. Now we have a potential dangling pointer problem inside Y:
</p>
<pre class="programlisting"><span class="special">&gt;&gt;&gt;</span> <span class="identifier">x</span> <span class="special">=</span> <span class="identifier">f</span><span class="special">(</span><span class="identifier">y</span><span class="special">,</span> <span class="identifier">z</span><span class="special">)</span> <span class="preprocessor"># y</span> <span class="identifier">refers</span> <span class="identifier">to</span> <span class="identifier">z</span>
<span class="special">&gt;&gt;&gt;</span> <span class="identifier">del</span> <span class="identifier">z</span> <span class="preprocessor"># Kill</span> <span class="identifier">the</span> <span class="identifier">z</span> <span class="identifier">object</span>
<span class="special">&gt;&gt;&gt;</span> <span class="identifier">y</span><span class="special">.</span><span class="identifier">z_value</span><span class="special">()</span> <span class="preprocessor"># CRASH</span><span class="special">!</span>
</pre>
<p>
For reference, here's the implementation of <code class="literal">f</code> again:
</p>
<pre class="programlisting"><span class="identifier">X</span><span class="special">&amp;</span> <span class="identifier">f</span><span class="special">(</span><span class="identifier">Y</span><span class="special">&amp;</span> <span class="identifier">y</span><span class="special">,</span> <span class="identifier">Z</span><span class="special">*</span> <span class="identifier">z</span><span class="special">)</span>
<span class="special">{</span>
<span class="identifier">y</span><span class="special">.</span><span class="identifier">z</span> <span class="special">=</span> <span class="identifier">z</span><span class="special">;</span>
<span class="keyword">return</span> <span class="identifier">y</span><span class="special">.</span><span class="identifier">x</span><span class="special">;</span>
<span class="special">}</span>
</pre>
<p>
Here's what's happening:
</p>
<div class="orderedlist"><ol class="orderedlist" type="1">
<li class="listitem">
<code class="literal">f</code> is called passing in a reference to <code class="literal">y</code>
and a pointer to <code class="literal">z</code>
</li>
<li class="listitem">
A pointer to <code class="literal">z</code> is held by <code class="literal">y</code>
</li>
<li class="listitem">
A reference to <code class="literal">y.x</code> is returned
</li>
<li class="listitem">
<code class="literal">z</code> is deleted. <code class="literal">y.z</code> is a dangling
pointer
</li>
<li class="listitem">
<code class="literal">y.z_value()</code> is called
</li>
<li class="listitem">
<code class="literal">z-&gt;value()</code> is called
</li>
<li class="listitem">
<span class="bold"><strong>BOOM!</strong></span>
</li>
</ol></div>
<h3>
<a name="call_policies.call_policies"></a>
Call Policies
</h3>
<p>
Call Policies may be used in situations such as the example detailed above.
In our example, <code class="literal">return_internal_reference</code> and <code class="literal">with_custodian_and_ward</code>
are our friends:
</p>
<pre class="programlisting"><span class="identifier">def</span><span class="special">(</span><span class="string">"f"</span><span class="special">,</span> <span class="identifier">f</span><span class="special">,</span>
<span class="identifier">return_internal_reference</span><span class="special">&lt;</span><span class="number">1</span><span class="special">,</span>
<span class="identifier">with_custodian_and_ward</span><span class="special">&lt;</span><span class="number">1</span><span class="special">,</span> <span class="number">2</span><span class="special">&gt;</span> <span class="special">&gt;());</span>
</pre>
<p>
What are the <code class="literal">1</code> and <code class="literal">2</code> parameters, you
ask?
</p>
<pre class="programlisting"><span class="identifier">return_internal_reference</span><span class="special">&lt;</span><span class="number">1</span>
</pre>
<p>
Informs Boost.Python that the first argument, in our case <code class="literal">Y&amp;
y</code>, is the owner of the returned reference: <code class="literal">X&amp;</code>.
The "<code class="literal">1</code>" simply specifies the first argument.
In short: "return an internal reference <code class="literal">X&amp;</code> owned
by the 1st argument <code class="literal">Y&amp; y</code>".
</p>
<pre class="programlisting"><span class="identifier">with_custodian_and_ward</span><span class="special">&lt;</span><span class="number">1</span><span class="special">,</span> <span class="number">2</span><span class="special">&gt;</span>
</pre>
<p>
Informs Boost.Python that the lifetime of the argument indicated by ward
(i.e. the 2nd argument: <code class="literal">Z* z</code>) is dependent on the lifetime
of the argument indicated by custodian (i.e. the 1st argument: <code class="literal">Y&amp;
y</code>).
</p>
<p>
It is also important to note that we have defined two policies above. Two
or more policies can be composed by chaining. Here's the general syntax:
</p>
<pre class="programlisting"><span class="identifier">policy1</span><span class="special">&lt;</span><span class="identifier">args</span><span class="special">...,</span>
<span class="identifier">policy2</span><span class="special">&lt;</span><span class="identifier">args</span><span class="special">...,</span>
<span class="identifier">policy3</span><span class="special">&lt;</span><span class="identifier">args</span><span class="special">...&gt;</span> <span class="special">&gt;</span> <span class="special">&gt;</span>
</pre>
<p>
Here is the list of predefined call policies. A complete reference detailing
these can be found <a href="../../../../v2/reference.html#models_of_call_policies" target="_top">here</a>.
</p>
<div class="itemizedlist"><ul class="itemizedlist" type="disc">
<li class="listitem">
<span class="bold"><strong>with_custodian_and_ward</strong></span>: Ties lifetimes
of the arguments
</li>
<li class="listitem">
<span class="bold"><strong>with_custodian_and_ward_postcall</strong></span>: Ties
lifetimes of the arguments and results
</li>
<li class="listitem">
<span class="bold"><strong>return_internal_reference</strong></span>: Ties lifetime
of one argument to that of result
</li>
<li class="listitem">
<span class="bold"><strong>return_value_policy&lt;T&gt; with T one of:</strong></span>
<div class="itemizedlist"><ul class="itemizedlist" type="circle">
<li class="listitem">
<span class="bold"><strong>reference_existing_object</strong></span>: naive
(dangerous) approach
</li>
<li class="listitem">
<span class="bold"><strong>copy_const_reference</strong></span>: Boost.Python
v1 approach
</li>
<li class="listitem">
<span class="bold"><strong>copy_non_const_reference</strong></span>:
</li>
<li class="listitem">
<span class="bold"><strong>manage_new_object</strong></span>: Adopt a pointer
and hold the instance
</li>
</ul></div>
</li>
</ul></div>
<div class="sidebar">
<div class="titlepage"></div>
<p>
<span class="inlinemediaobject"><img src="../images/smiley.png" alt="smiley"></span> <span class="bold"><strong>Remember the Zen, Luke:</strong></span>
</p>
<p>
"Explicit is better than implicit"
</p>
<p>
"In the face of ambiguity, refuse the temptation to guess"
</p>
</div>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="python.overloading"></a>Overloading</h3></div></div></div>
<p>
The following illustrates a scheme for manually wrapping an overloaded member
functions. Of course, the same technique can be applied to wrapping overloaded
non-member functions.
</p>
<p>
We have here our C++ class:
</p>
<pre class="programlisting"><span class="keyword">struct</span> <span class="identifier">X</span>
<span class="special">{</span>
<span class="keyword">bool</span> <span class="identifier">f</span><span class="special">(</span><span class="keyword">int</span> <span class="identifier">a</span><span class="special">)</span>
<span class="special">{</span>
<span class="keyword">return</span> <span class="keyword">true</span><span class="special">;</span>
<span class="special">}</span>
<span class="keyword">bool</span> <span class="identifier">f</span><span class="special">(</span><span class="keyword">int</span> <span class="identifier">a</span><span class="special">,</span> <span class="keyword">double</span> <span class="identifier">b</span><span class="special">)</span>
<span class="special">{</span>
<span class="keyword">return</span> <span class="keyword">true</span><span class="special">;</span>
<span class="special">}</span>
<span class="keyword">bool</span> <span class="identifier">f</span><span class="special">(</span><span class="keyword">int</span> <span class="identifier">a</span><span class="special">,</span> <span class="keyword">double</span> <span class="identifier">b</span><span class="special">,</span> <span class="keyword">char</span> <span class="identifier">c</span><span class="special">)</span>
<span class="special">{</span>
<span class="keyword">return</span> <span class="keyword">true</span><span class="special">;</span>
<span class="special">}</span>
<span class="keyword">int</span> <span class="identifier">f</span><span class="special">(</span><span class="keyword">int</span> <span class="identifier">a</span><span class="special">,</span> <span class="keyword">int</span> <span class="identifier">b</span><span class="special">,</span> <span class="keyword">int</span> <span class="identifier">c</span><span class="special">)</span>
<span class="special">{</span>
<span class="keyword">return</span> <span class="identifier">a</span> <span class="special">+</span> <span class="identifier">b</span> <span class="special">+</span> <span class="identifier">c</span><span class="special">;</span>
<span class="special">};</span>
<span class="special">};</span>
</pre>
<p>
Class X has 4 overloaded functions. We will start by introducing some member
function pointer variables:
</p>
<pre class="programlisting"><span class="keyword">bool</span> <span class="special">(</span><span class="identifier">X</span><span class="special">::*</span><span class="identifier">fx1</span><span class="special">)(</span><span class="keyword">int</span><span class="special">)</span> <span class="special">=</span> <span class="special">&amp;</span><span class="identifier">X</span><span class="special">::</span><span class="identifier">f</span><span class="special">;</span>
<span class="keyword">bool</span> <span class="special">(</span><span class="identifier">X</span><span class="special">::*</span><span class="identifier">fx2</span><span class="special">)(</span><span class="keyword">int</span><span class="special">,</span> <span class="keyword">double</span><span class="special">)</span> <span class="special">=</span> <span class="special">&amp;</span><span class="identifier">X</span><span class="special">::</span><span class="identifier">f</span><span class="special">;</span>
<span class="keyword">bool</span> <span class="special">(</span><span class="identifier">X</span><span class="special">::*</span><span class="identifier">fx3</span><span class="special">)(</span><span class="keyword">int</span><span class="special">,</span> <span class="keyword">double</span><span class="special">,</span> <span class="keyword">char</span><span class="special">)=</span> <span class="special">&amp;</span><span class="identifier">X</span><span class="special">::</span><span class="identifier">f</span><span class="special">;</span>
<span class="keyword">int</span> <span class="special">(</span><span class="identifier">X</span><span class="special">::*</span><span class="identifier">fx4</span><span class="special">)(</span><span class="keyword">int</span><span class="special">,</span> <span class="keyword">int</span><span class="special">,</span> <span class="keyword">int</span><span class="special">)</span> <span class="special">=</span> <span class="special">&amp;</span><span class="identifier">X</span><span class="special">::</span><span class="identifier">f</span><span class="special">;</span>
</pre>
<p>
With these in hand, we can proceed to define and wrap this for Python:
</p>
<pre class="programlisting"><span class="special">.</span><span class="identifier">def</span><span class="special">(</span><span class="string">"f"</span><span class="special">,</span> <span class="identifier">fx1</span><span class="special">)</span>
<span class="special">.</span><span class="identifier">def</span><span class="special">(</span><span class="string">"f"</span><span class="special">,</span> <span class="identifier">fx2</span><span class="special">)</span>
<span class="special">.</span><span class="identifier">def</span><span class="special">(</span><span class="string">"f"</span><span class="special">,</span> <span class="identifier">fx3</span><span class="special">)</span>
<span class="special">.</span><span class="identifier">def</span><span class="special">(</span><span class="string">"f"</span><span class="special">,</span> <span class="identifier">fx4</span><span class="special">)</span>
</pre>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="python.default_arguments"></a>Default Arguments</h3></div></div></div>
<p>
Boost.Python wraps (member) function pointers. Unfortunately, C++ function
pointers carry no default argument info. Take a function <code class="literal">f</code>
with default arguments:
</p>
<pre class="programlisting"><span class="keyword">int</span> <span class="identifier">f</span><span class="special">(</span><span class="keyword">int</span><span class="special">,</span> <span class="keyword">double</span> <span class="special">=</span> <span class="number">3.14</span><span class="special">,</span> <span class="keyword">char</span> <span class="keyword">const</span><span class="special">*</span> <span class="special">=</span> <span class="string">"hello"</span><span class="special">);</span>
</pre>
<p>
But the type of a pointer to the function <code class="literal">f</code> has no information
about its default arguments:
</p>
<pre class="programlisting"><span class="keyword">int</span><span class="special">(*</span><span class="identifier">g</span><span class="special">)(</span><span class="keyword">int</span><span class="special">,</span><span class="keyword">double</span><span class="special">,</span><span class="keyword">char</span> <span class="keyword">const</span><span class="special">*)</span> <span class="special">=</span> <span class="identifier">f</span><span class="special">;</span> <span class="comment">// defaults lost!</span>
</pre>
<p>
When we pass this function pointer to the <code class="literal">def</code> function,
there is no way to retrieve the default arguments:
</p>
<pre class="programlisting"><span class="identifier">def</span><span class="special">(</span><span class="string">"f"</span><span class="special">,</span> <span class="identifier">f</span><span class="special">);</span> <span class="comment">// defaults lost!</span>
</pre>
<p>
Because of this, when wrapping C++ code, we had to resort to manual wrapping
as outlined in the <a class="link" href="functions.html#python.overloading" title="Overloading">previous section</a>,
or writing thin wrappers:
</p>
<pre class="programlisting"><span class="comment">// write "thin wrappers"</span>
<span class="keyword">int</span> <span class="identifier">f1</span><span class="special">(</span><span class="keyword">int</span> <span class="identifier">x</span><span class="special">)</span> <span class="special">{</span> <span class="keyword">return</span> <span class="identifier">f</span><span class="special">(</span><span class="identifier">x</span><span class="special">);</span> <span class="special">}</span>
<span class="keyword">int</span> <span class="identifier">f2</span><span class="special">(</span><span class="keyword">int</span> <span class="identifier">x</span><span class="special">,</span> <span class="keyword">double</span> <span class="identifier">y</span><span class="special">)</span> <span class="special">{</span> <span class="keyword">return</span> <span class="identifier">f</span><span class="special">(</span><span class="identifier">x</span><span class="special">,</span><span class="identifier">y</span><span class="special">);</span> <span class="special">}</span>
<span class="comment">/*...*/</span>
<span class="comment">// in module init</span>
<span class="identifier">def</span><span class="special">(</span><span class="string">"f"</span><span class="special">,</span> <span class="identifier">f</span><span class="special">);</span> <span class="comment">// all arguments</span>
<span class="identifier">def</span><span class="special">(</span><span class="string">"f"</span><span class="special">,</span> <span class="identifier">f2</span><span class="special">);</span> <span class="comment">// two arguments</span>
<span class="identifier">def</span><span class="special">(</span><span class="string">"f"</span><span class="special">,</span> <span class="identifier">f1</span><span class="special">);</span> <span class="comment">// one argument</span>
</pre>
<p>
When you want to wrap functions (or member functions) that either:
</p>
<div class="itemizedlist"><ul class="itemizedlist" type="disc">
<li class="listitem">
have default arguments, or
</li>
<li class="listitem">
are overloaded with a common sequence of initial arguments
</li>
</ul></div>
<h3>
<a name="default_arguments.boost_python_function_overloads"></a>
BOOST_PYTHON_FUNCTION_OVERLOADS
</h3>
<p>
Boost.Python now has a way to make it easier. For instance, given a function:
</p>
<pre class="programlisting"><span class="keyword">int</span> <span class="identifier">foo</span><span class="special">(</span><span class="keyword">int</span> <span class="identifier">a</span><span class="special">,</span> <span class="keyword">char</span> <span class="identifier">b</span> <span class="special">=</span> <span class="number">1</span><span class="special">,</span> <span class="keyword">unsigned</span> <span class="identifier">c</span> <span class="special">=</span> <span class="number">2</span><span class="special">,</span> <span class="keyword">double</span> <span class="identifier">d</span> <span class="special">=</span> <span class="number">3</span><span class="special">)</span>
<span class="special">{</span>
<span class="comment">/*...*/</span>
<span class="special">}</span>
</pre>
<p>
The macro invocation:
</p>
<pre class="programlisting"><span class="identifier">BOOST_PYTHON_FUNCTION_OVERLOADS</span><span class="special">(</span><span class="identifier">foo_overloads</span><span class="special">,</span> <span class="identifier">foo</span><span class="special">,</span> <span class="number">1</span><span class="special">,</span> <span class="number">4</span><span class="special">)</span>
</pre>
<p>
will automatically create the thin wrappers for us. This macro will create
a class <code class="literal">foo_overloads</code> that can be passed on to <code class="literal">def(...)</code>.
The third and fourth macro argument are the minimum arguments and maximum
arguments, respectively. In our <code class="literal">foo</code> function the minimum
number of arguments is 1 and the maximum number of arguments is 4. The <code class="literal">def(...)</code>
function will automatically add all the foo variants for us:
</p>
<pre class="programlisting"><span class="identifier">def</span><span class="special">(</span><span class="string">"foo"</span><span class="special">,</span> <span class="identifier">foo</span><span class="special">,</span> <span class="identifier">foo_overloads</span><span class="special">());</span>
</pre>
<h3>
<a name="default_arguments.boost_python_member_function_overloads"></a>
BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS
</h3>
<p>
Objects here, objects there, objects here there everywhere. More frequently
than anything else, we need to expose member functions of our classes to
Python. Then again, we have the same inconveniences as before when default
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 <code class="literal">BOOST_PYTHON_FUNCTION_OVERLOADS</code>, <code class="literal">BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS</code>
may be used to automatically create the thin wrappers for wrapping member
functions. Let's have an example:
</p>
<pre class="programlisting"><span class="keyword">struct</span> <span class="identifier">george</span>
<span class="special">{</span>
<span class="keyword">void</span>
<span class="identifier">wack_em</span><span class="special">(</span><span class="keyword">int</span> <span class="identifier">a</span><span class="special">,</span> <span class="keyword">int</span> <span class="identifier">b</span> <span class="special">=</span> <span class="number">0</span><span class="special">,</span> <span class="keyword">char</span> <span class="identifier">c</span> <span class="special">=</span> <span class="char">'x'</span><span class="special">)</span>
<span class="special">{</span>
<span class="comment">/*...*/</span>
<span class="special">}</span>
<span class="special">};</span>
</pre>
<p>
The macro invocation:
</p>
<pre class="programlisting"><span class="identifier">BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS</span><span class="special">(</span><span class="identifier">george_overloads</span><span class="special">,</span> <span class="identifier">wack_em</span><span class="special">,</span> <span class="number">1</span><span class="special">,</span> <span class="number">3</span><span class="special">)</span>
</pre>
<p>
will generate a set of thin wrappers for george's <code class="literal">wack_em</code>
member function accepting a minimum of 1 and a maximum of 3 arguments (i.e.
the third and fourth macro argument). The thin wrappers are all enclosed
in a class named <code class="literal">george_overloads</code> that can then be used
as an argument to <code class="literal">def(...)</code>:
</p>
<pre class="programlisting"><span class="special">.</span><span class="identifier">def</span><span class="special">(</span><span class="string">"wack_em"</span><span class="special">,</span> <span class="special">&amp;</span><span class="identifier">george</span><span class="special">::</span><span class="identifier">wack_em</span><span class="special">,</span> <span class="identifier">george_overloads</span><span class="special">());</span>
</pre>
<p>
See the <a href="../../../../v2/overloads.html#BOOST_PYTHON_FUNCTION_OVERLOADS-spec" target="_top">overloads
reference</a> for details.
</p>
<h3>
<a name="default_arguments.init_and_optional"></a>
init and optional
</h3>
<p>
A similar facility is provided for class constructors, again, with default
arguments or a sequence of overloads. Remember <code class="literal">init&lt;...&gt;</code>?
For example, given a class X with a constructor:
</p>
<pre class="programlisting"><span class="keyword">struct</span> <span class="identifier">X</span>
<span class="special">{</span>
<span class="identifier">X</span><span class="special">(</span><span class="keyword">int</span> <span class="identifier">a</span><span class="special">,</span> <span class="keyword">char</span> <span class="identifier">b</span> <span class="special">=</span> <span class="char">'D'</span><span class="special">,</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">string</span> <span class="identifier">c</span> <span class="special">=</span> <span class="string">"constructor"</span><span class="special">,</span> <span class="keyword">double</span> <span class="identifier">d</span> <span class="special">=</span> <span class="number">0.0</span><span class="special">);</span>
<span class="comment">/*...*/</span>
<span class="special">}</span>
</pre>
<p>
You can easily add this constructor to Boost.Python in one shot:
</p>
<pre class="programlisting"><span class="special">.</span><span class="identifier">def</span><span class="special">(</span><span class="identifier">init</span><span class="special">&lt;</span><span class="keyword">int</span><span class="special">,</span> <span class="identifier">optional</span><span class="special">&lt;</span><span class="keyword">char</span><span class="special">,</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">string</span><span class="special">,</span> <span class="keyword">double</span><span class="special">&gt;</span> <span class="special">&gt;())</span>
</pre>
<p>
Notice the use of <code class="literal">init&lt;...&gt;</code> and <code class="literal">optional&lt;...&gt;</code>
to signify the default (optional arguments).
</p>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="python.auto_overloading"></a>Auto-Overloading</h3></div></div></div>
<p>
It was mentioned in passing in the previous section that <code class="literal">BOOST_PYTHON_FUNCTION_OVERLOADS</code>
and <code class="literal">BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS</code> can also be
used for overloaded functions and member functions with a common sequence
of initial arguments. Here is an example:
</p>
<pre class="programlisting"><span class="keyword">void</span> <span class="identifier">foo</span><span class="special">()</span>
<span class="special">{</span>
<span class="comment">/*...*/</span>
<span class="special">}</span>
<span class="keyword">void</span> <span class="identifier">foo</span><span class="special">(</span><span class="keyword">bool</span> <span class="identifier">a</span><span class="special">)</span>
<span class="special">{</span>
<span class="comment">/*...*/</span>
<span class="special">}</span>
<span class="keyword">void</span> <span class="identifier">foo</span><span class="special">(</span><span class="keyword">bool</span> <span class="identifier">a</span><span class="special">,</span> <span class="keyword">int</span> <span class="identifier">b</span><span class="special">)</span>
<span class="special">{</span>
<span class="comment">/*...*/</span>
<span class="special">}</span>
<span class="keyword">void</span> <span class="identifier">foo</span><span class="special">(</span><span class="keyword">bool</span> <span class="identifier">a</span><span class="special">,</span> <span class="keyword">int</span> <span class="identifier">b</span><span class="special">,</span> <span class="keyword">char</span> <span class="identifier">c</span><span class="special">)</span>
<span class="special">{</span>
<span class="comment">/*...*/</span>
<span class="special">}</span>
</pre>
<p>
Like in the previous section, we can generate thin wrappers for these overloaded
functions in one-shot:
</p>
<pre class="programlisting"><span class="identifier">BOOST_PYTHON_FUNCTION_OVERLOADS</span><span class="special">(</span><span class="identifier">foo_overloads</span><span class="special">,</span> <span class="identifier">foo</span><span class="special">,</span> <span class="number">0</span><span class="special">,</span> <span class="number">3</span><span class="special">)</span>
</pre>
<p>
Then...
</p>
<pre class="programlisting"><span class="special">.</span><span class="identifier">def</span><span class="special">(</span><span class="string">"foo"</span><span class="special">,</span> <span class="special">(</span><span class="keyword">void</span><span class="special">(*)(</span><span class="keyword">bool</span><span class="special">,</span> <span class="keyword">int</span><span class="special">,</span> <span class="keyword">char</span><span class="special">))</span><span class="number">0</span><span class="special">,</span> <span class="identifier">foo_overloads</span><span class="special">());</span>
</pre>
<p>
Notice though that we have a situation now where we have a minimum of zero
(0) arguments and a maximum of 3 arguments.
</p>
<h3>
<a name="auto_overloading.manual_wrapping"></a>
Manual Wrapping
</h3>
<p>
It is important to emphasize however that <span class="bold"><strong>the overloaded
functions must have a common sequence of initial arguments</strong></span>. Otherwise,
our scheme above will not work. If this is not the case, we have to wrap
our functions <a class="link" href="functions.html#python.overloading" title="Overloading">manually</a>.
</p>
<p>
Actually, we can mix and match manual wrapping of overloaded functions and
automatic wrapping through <code class="literal">BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS</code>
and its sister, <code class="literal">BOOST_PYTHON_FUNCTION_OVERLOADS</code>. Following
up on our example presented in the section <a class="link" href="functions.html#python.overloading" title="Overloading">on
overloading</a>, since the first 4 overload functins have a common sequence
of initial arguments, we can use <code class="literal">BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS</code>
to automatically wrap the first three of the <code class="literal">def</code>s and
manually wrap just the last. Here's how we'll do this:
</p>
<pre class="programlisting"><span class="identifier">BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS</span><span class="special">(</span><span class="identifier">xf_overloads</span><span class="special">,</span> <span class="identifier">f</span><span class="special">,</span> <span class="number">1</span><span class="special">,</span> <span class="number">4</span><span class="special">)</span>
</pre>
<p>
Create a member function pointers as above for both X::f overloads:
</p>
<pre class="programlisting"><span class="keyword">bool</span> <span class="special">(</span><span class="identifier">X</span><span class="special">::*</span><span class="identifier">fx1</span><span class="special">)(</span><span class="keyword">int</span><span class="special">,</span> <span class="keyword">double</span><span class="special">,</span> <span class="keyword">char</span><span class="special">)</span> <span class="special">=</span> <span class="special">&amp;</span><span class="identifier">X</span><span class="special">::</span><span class="identifier">f</span><span class="special">;</span>
<span class="keyword">int</span> <span class="special">(</span><span class="identifier">X</span><span class="special">::*</span><span class="identifier">fx2</span><span class="special">)(</span><span class="keyword">int</span><span class="special">,</span> <span class="keyword">int</span><span class="special">,</span> <span class="keyword">int</span><span class="special">)</span> <span class="special">=</span> <span class="special">&amp;</span><span class="identifier">X</span><span class="special">::</span><span class="identifier">f</span><span class="special">;</span>
</pre>
<p>
Then...
</p>
<pre class="programlisting"><span class="special">.</span><span class="identifier">def</span><span class="special">(</span><span class="string">"f"</span><span class="special">,</span> <span class="identifier">fx1</span><span class="special">,</span> <span class="identifier">xf_overloads</span><span class="special">());</span>
<span class="special">.</span><span class="identifier">def</span><span class="special">(</span><span class="string">"f"</span><span class="special">,</span> <span class="identifier">fx2</span><span class="special">)</span>
</pre>
</div>
</div>
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
<td align="left"></td>
<td align="right"><div class="copyright-footer">Copyright &#169; 2002-2005 Joel
de Guzman, David Abrahams<p>
Distributed under the Boost Software License, Version 1.0. (See accompanying
file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">
http://www.boost.org/LICENSE_1_0.txt </a>)
</p>
</div></td>
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="exposing.html"><img src="../../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../index.html"><img src="../../../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="object.html"><img src="../../../../../../../doc/src/images/next.png" alt="Next"></a>
</div>
</body>
</html>

View File

@@ -0,0 +1,195 @@
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
<title>Building Hello World</title>
<link rel="stylesheet" href="../../../../../../../doc/src/boostbook.css" type="text/css">
<meta name="generator" content="DocBook XSL Stylesheets V1.76.1">
<link rel="home" href="../index.html" title="Chapter&#160;1.&#160;python 2.0">
<link rel="up" href="../index.html" title="Chapter&#160;1.&#160;python 2.0">
<link rel="prev" href="../index.html" title="Chapter&#160;1.&#160;python 2.0">
<link rel="next" href="exposing.html" title="Exposing Classes">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<table cellpadding="2" width="100%"><tr>
<td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../../../../../boost.png"></td>
<td align="center"><a href="../../../../../../../index.html">Home</a></td>
<td align="center"><a href="../../../../../../../libs/libraries.htm">Libraries</a></td>
<td align="center"><a href="http://www.boost.org/users/people.html">People</a></td>
<td align="center"><a href="http://www.boost.org/users/faq.html">FAQ</a></td>
<td align="center"><a href="../../../../../../../more/index.htm">More</a></td>
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="../index.html"><img src="../../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../index.html"><img src="../../../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="exposing.html"><img src="../../../../../../../doc/src/images/next.png" alt="Next"></a>
</div>
<div class="section">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="python.hello"></a>Building Hello World</h2></div></div></div>
<h3>
<a name="hello.from_start_to_finish"></a>
From Start To Finish
</h3>
<p>
Now the first thing you'd want to do is to build the Hello World module and
try it for yourself in Python. In this section, we will outline the steps necessary
to achieve that. We will use the build tool that comes bundled with every boost
distribution: <span class="bold"><strong>bjam</strong></span>.
</p>
<div class="note"><table border="0" summary="Note">
<tr>
<td rowspan="2" align="center" valign="top" width="25"><img alt="[Note]" src="../../../../../../../doc/src/images/note.png"></td>
<th align="left">Note</th>
</tr>
<tr><td align="left" valign="top">
<p>
<span class="bold"><strong>Building without bjam</strong></span>
</p>
<p>
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 <code class="literal">bjam</code>.
</p>
<p>
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.
</p>
</td></tr>
</table></div>
<p>
We will skip over the details. Our objective will be to simply create the hello
world module and run it in Python. For a complete reference to building Boost.Python,
check out: <a href="../../../../building.html" target="_top">building.html</a>. After
this brief <span class="emphasis"><em>bjam</em></span> tutorial, we should have built the DLLs
and run a python program using the extension.
</p>
<p>
The tutorial example can be found in the directory: <code class="literal">libs/python/example/tutorial</code>.
There, you can find:
</p>
<div class="itemizedlist"><ul class="itemizedlist" type="disc">
<li class="listitem">
hello.cpp
</li>
<li class="listitem">
hello.py
</li>
<li class="listitem">
Jamroot
</li>
</ul></div>
<p>
The <code class="literal">hello.cpp</code> file is our C++ hello world example. The
<code class="literal">Jamroot</code> is a minimalist <span class="emphasis"><em>bjam</em></span> script
that builds the DLLs for us. Finally, <code class="literal">hello.py</code> is our Python
program that uses the extension in <code class="literal">hello.cpp</code>.
</p>
<p>
Before anything else, you should have the bjam executable in your boost directory
or somewhere in your path such that <code class="literal">bjam</code> can be executed
in the command line. Pre-built Boost.Jam executables are available for most
platforms. The complete list of Bjam executables can be found <a href="http://sourceforge.net/project/showfiles.php?group_id=7586" target="_top">here</a>.
</p>
<h3>
<a name="hello.let_s_jam_"></a>
Let's Jam!
</h3>
<p>
<span class="inlinemediaobject"><img src="../images/jam.png" alt="jam"></span>
</p>
<p>
<a href="../../../../../example/tutorial/Jamroot" target="_top">Here</a> is our minimalist
Jamroot file. Simply copy the file and tweak <code class="literal">use-project boost</code>
to where your boost root directory is and your OK.
</p>
<p>
The comments contained in the Jamrules file above should be sufficient to get
you going.
</p>
<h3>
<a name="hello.running_bjam"></a>
Running bjam
</h3>
<p>
<span class="emphasis"><em>bjam</em></span> is run using your operating system's command line
interpreter.
</p>
<div class="blockquote"><blockquote class="blockquote"><p>
Start it up.
</p></blockquote></div>
<p>
A file called user-config.jam in your home directory is used to configure your
tools. In Windows, your home directory can be found by typing:
</p>
<pre class="programlisting">ECHO %HOMEDRIVE%%HOMEPATH%
</pre>
<p>
into a command prompt window. Your file should at least have the rules for
your compiler and your python installation. A specific example of this on Windows
would be:
</p>
<pre class="programlisting"># MSVC configuration
using msvc : 8.0 ;
# Python configuration
using python : 2.4 : C:<span class="emphasis"><em>dev/tools/Python</em></span> ;
</pre>
<p>
The first rule tells Bjam to use the MSVC 8.0 compiler and associated tools.
The second rule provides information on Python, its version and where it is
located. The above assumes that the Python installation is in <code class="literal">C:<span class="emphasis"><em>dev/tools\/Python</em></span></code>.
If you have one fairly "standard" python installation for your platform,
you might not need to do this.
</p>
<p>
Now we are ready... Be sure to <code class="literal">cd</code> to <code class="literal">libs/python/example/tutorial</code>
where the tutorial <code class="literal">"hello.cpp"</code> and the <code class="literal">"Jamroot"</code>
is situated.
</p>
<p>
Finally:
</p>
<pre class="programlisting"><span class="identifier">bjam</span>
</pre>
<p>
It should be building now:
</p>
<pre class="programlisting">cd C:\dev\boost\libs\python\example\tutorial
bjam
...patience...
...found 1101 targets...
...updating 35 targets...
</pre>
<p>
And so on... Finally:
</p>
<pre class="programlisting">Creating library <span class="emphasis"><em>path-to-boost_python.dll</em></span>
Creating library /path-to-hello_ext.exp/
**passed** ... hello.test
...updated 35 targets...
</pre>
<p>
Or something similar. If all is well, you should now have built the DLLs and
run the Python program.
</p>
<div class="blockquote"><blockquote class="blockquote"><p>
<span class="bold"><strong>There you go... Have fun!</strong></span>
</p></blockquote></div>
</div>
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
<td align="left"></td>
<td align="right"><div class="copyright-footer">Copyright &#169; 2002-2005 Joel
de Guzman, David Abrahams<p>
Distributed under the Boost Software License, Version 1.0. (See accompanying
file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">
http://www.boost.org/LICENSE_1_0.txt </a>)
</p>
</div></td>
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="../index.html"><img src="../../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../index.html"><img src="../../../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="exposing.html"><img src="../../../../../../../doc/src/images/next.png" alt="Next"></a>
</div>
</body>
</html>

View File

@@ -0,0 +1,187 @@
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
<title>Iterators</title>
<link rel="stylesheet" href="../../../../../../../doc/src/boostbook.css" type="text/css">
<meta name="generator" content="DocBook XSL Stylesheets V1.76.1">
<link rel="home" href="../index.html" title="Chapter&#160;1.&#160;python 2.0">
<link rel="up" href="../index.html" title="Chapter&#160;1.&#160;python 2.0">
<link rel="prev" href="embedding.html" title="Embedding">
<link rel="next" href="exception.html" title="Exception Translation">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<table cellpadding="2" width="100%"><tr>
<td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../../../../../boost.png"></td>
<td align="center"><a href="../../../../../../../index.html">Home</a></td>
<td align="center"><a href="../../../../../../../libs/libraries.htm">Libraries</a></td>
<td align="center"><a href="http://www.boost.org/users/people.html">People</a></td>
<td align="center"><a href="http://www.boost.org/users/faq.html">FAQ</a></td>
<td align="center"><a href="../../../../../../../more/index.htm">More</a></td>
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="embedding.html"><img src="../../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../index.html"><img src="../../../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="exception.html"><img src="../../../../../../../doc/src/images/next.png" alt="Next"></a>
</div>
<div class="section">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="python.iterators"></a>Iterators</h2></div></div></div>
<p>
In C++, and STL in particular, we see iterators everywhere. Python also has
iterators, but these are two very different beasts.
</p>
<p>
<span class="bold"><strong>C++ iterators:</strong></span>
</p>
<div class="itemizedlist"><ul class="itemizedlist" type="disc">
<li class="listitem">
C++ has 5 type categories (random-access, bidirectional, forward, input,
output)
</li>
<li class="listitem">
There are 2 Operation categories: reposition, access
</li>
<li class="listitem">
A pair of iterators is needed to represent a (first/last) range.
</li>
</ul></div>
<p>
<span class="bold"><strong>Python Iterators:</strong></span>
</p>
<div class="itemizedlist"><ul class="itemizedlist" type="disc">
<li class="listitem">
1 category (forward)
</li>
<li class="listitem">
1 operation category (next())
</li>
<li class="listitem">
Raises StopIteration exception at end
</li>
</ul></div>
<p>
The typical Python iteration protocol: <code class="literal"><span class="bold"><strong>for y
in x...</strong></span></code> is as follows:
</p>
<pre class="programlisting"><span class="identifier">iter</span> <span class="special">=</span> <span class="identifier">x</span><span class="special">.</span><span class="identifier">__iter__</span><span class="special">()</span> <span class="comment"># get iterator</span>
<span class="keyword">try</span><span class="special">:</span>
<span class="keyword">while</span> <span class="number">1</span><span class="special">:</span>
<span class="identifier">y</span> <span class="special">=</span> <span class="identifier">iter</span><span class="special">.</span><span class="identifier">next</span><span class="special">()</span> <span class="comment"># get each item</span>
<span class="special">...</span> <span class="comment"># process y</span>
<span class="keyword">except</span> <span class="identifier">StopIteration</span><span class="special">:</span> <span class="keyword">pass</span> <span class="comment"># iterator exhausted</span>
</pre>
<p>
Boost.Python provides some mechanisms to make C++ iterators play along nicely
as Python iterators. What we need to do is to produce appropriate <code class="computeroutput"><span class="identifier">__iter__</span></code> function from C++ iterators that
is compatible with the Python iteration protocol. For example:
</p>
<pre class="programlisting"><span class="identifier">object</span> <span class="identifier">get_iterator</span> <span class="special">=</span> <span class="identifier">iterator</span><span class="special">&lt;</span><span class="identifier">vector</span><span class="special">&lt;</span><span class="keyword">int</span><span class="special">&gt;</span> <span class="special">&gt;();</span>
<span class="identifier">object</span> <span class="identifier">iter</span> <span class="special">=</span> <span class="identifier">get_iterator</span><span class="special">(</span><span class="identifier">v</span><span class="special">);</span>
<span class="identifier">object</span> <span class="identifier">first</span> <span class="special">=</span> <span class="identifier">iter</span><span class="special">.</span><span class="identifier">next</span><span class="special">();</span>
</pre>
<p>
Or for use in class_&lt;&gt;:
</p>
<pre class="programlisting"><span class="special">.</span><span class="identifier">def</span><span class="special">(</span><span class="string">"__iter__"</span><span class="special">,</span> <span class="identifier">iterator</span><span class="special">&lt;</span><span class="identifier">vector</span><span class="special">&lt;</span><span class="keyword">int</span><span class="special">&gt;</span> <span class="special">&gt;())</span>
</pre>
<p>
<span class="bold"><strong>range</strong></span>
</p>
<p>
We can create a Python savvy iterator using the range function:
</p>
<div class="itemizedlist"><ul class="itemizedlist" type="disc">
<li class="listitem">
range(start, finish)
</li>
<li class="listitem">
range&lt;Policies,Target&gt;(start, finish)
</li>
</ul></div>
<p>
Here, start/finish may be one of:
</p>
<div class="itemizedlist"><ul class="itemizedlist" type="disc">
<li class="listitem">
member data pointers
</li>
<li class="listitem">
member function pointers
</li>
<li class="listitem">
adaptable function object (use Target parameter)
</li>
</ul></div>
<p>
<span class="bold"><strong>iterator</strong></span>
</p>
<div class="itemizedlist"><ul class="itemizedlist" type="disc"><li class="listitem">
iterator&lt;T, Policies&gt;()
</li></ul></div>
<p>
Given a container <code class="literal">T</code>, iterator is a shortcut that simply
calls <code class="literal">range</code> with &amp;T::begin, &amp;T::end.
</p>
<p>
Let's put this into action... Here's an example from some hypothetical bogon
Particle accelerator code:
</p>
<pre class="programlisting"><span class="identifier">f</span> <span class="special">=</span> <span class="identifier">Field</span><span class="special">()</span>
<span class="keyword">for</span> <span class="identifier">x</span> <span class="keyword">in</span> <span class="identifier">f</span><span class="special">.</span><span class="identifier">pions</span><span class="special">:</span>
<span class="identifier">smash</span><span class="special">(</span><span class="identifier">x</span><span class="special">)</span>
<span class="keyword">for</span> <span class="identifier">y</span> <span class="keyword">in</span> <span class="identifier">f</span><span class="special">.</span><span class="identifier">bogons</span><span class="special">:</span>
<span class="identifier">count</span><span class="special">(</span><span class="identifier">y</span><span class="special">)</span>
</pre>
<p>
Now, our C++ Wrapper:
</p>
<pre class="programlisting"><span class="identifier">class_</span><span class="special">&lt;</span><span class="identifier">F</span><span class="special">&gt;(</span><span class="string">"Field"</span><span class="special">)</span>
<span class="special">.</span><span class="identifier">property</span><span class="special">(</span><span class="string">"pions"</span><span class="special">,</span> <span class="identifier">range</span><span class="special">(&amp;</span><span class="identifier">F</span><span class="special">::</span><span class="identifier">p_begin</span><span class="special">,</span> <span class="special">&amp;</span><span class="identifier">F</span><span class="special">::</span><span class="identifier">p_end</span><span class="special">))</span>
<span class="special">.</span><span class="identifier">property</span><span class="special">(</span><span class="string">"bogons"</span><span class="special">,</span> <span class="identifier">range</span><span class="special">(&amp;</span><span class="identifier">F</span><span class="special">::</span><span class="identifier">b_begin</span><span class="special">,</span> <span class="special">&amp;</span><span class="identifier">F</span><span class="special">::</span><span class="identifier">b_end</span><span class="special">));</span>
</pre>
<p>
<span class="bold"><strong>stl_input_iterator</strong></span>
</p>
<p>
So far, we have seen how to expose C++ iterators and ranges to Python. Sometimes
we wish to go the other way, though: we'd like to pass a Python sequence to
an STL algorithm or use it to initialize an STL container. We need to make
a Python iterator look like an STL iterator. For that, we use <code class="computeroutput"><span class="identifier">stl_input_iterator</span><span class="special">&lt;&gt;</span></code>.
Consider how we might implement a function that exposes <code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">list</span><span class="special">&lt;</span><span class="keyword">int</span><span class="special">&gt;::</span><span class="identifier">assign</span><span class="special">()</span></code> to Python:
</p>
<pre class="programlisting"><span class="keyword">template</span><span class="special">&lt;</span><span class="keyword">typename</span> <span class="identifier">T</span><span class="special">&gt;</span>
<span class="keyword">void</span> <span class="identifier">list_assign</span><span class="special">(</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">list</span><span class="special">&lt;</span><span class="identifier">T</span><span class="special">&gt;&amp;</span> <span class="identifier">l</span><span class="special">,</span> <span class="identifier">object</span> <span class="identifier">o</span><span class="special">)</span> <span class="special">{</span>
<span class="comment">// Turn a Python sequence into an STL input range</span>
<span class="identifier">stl_input_iterator</span><span class="special">&lt;</span><span class="identifier">T</span><span class="special">&gt;</span> <span class="identifier">begin</span><span class="special">(</span><span class="identifier">o</span><span class="special">),</span> <span class="identifier">end</span><span class="special">;</span>
<span class="identifier">l</span><span class="special">.</span><span class="identifier">assign</span><span class="special">(</span><span class="identifier">begin</span><span class="special">,</span> <span class="identifier">end</span><span class="special">);</span>
<span class="special">}</span>
<span class="comment">// Part of the wrapper for list&lt;int&gt;</span>
<span class="identifier">class_</span><span class="special">&lt;</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">list</span><span class="special">&lt;</span><span class="keyword">int</span><span class="special">&gt;</span> <span class="special">&gt;(</span><span class="string">"list_int"</span><span class="special">)</span>
<span class="special">.</span><span class="identifier">def</span><span class="special">(</span><span class="string">"assign"</span><span class="special">,</span> <span class="special">&amp;</span><span class="identifier">list_assign</span><span class="special">&lt;</span><span class="keyword">int</span><span class="special">&gt;)</span>
<span class="comment">// ...</span>
<span class="special">;</span>
</pre>
<p>
Now in Python, we can assign any integer sequence to <code class="computeroutput"><span class="identifier">list_int</span></code>
objects:
</p>
<pre class="programlisting"><span class="identifier">x</span> <span class="special">=</span> <span class="identifier">list_int</span><span class="special">();</span>
<span class="identifier">x</span><span class="special">.</span><span class="identifier">assign</span><span class="special">([</span><span class="number">1</span><span class="special">,</span><span class="number">2</span><span class="special">,</span><span class="number">3</span><span class="special">,</span><span class="number">4</span><span class="special">,</span><span class="number">5</span><span class="special">])</span>
</pre>
</div>
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
<td align="left"></td>
<td align="right"><div class="copyright-footer">Copyright &#169; 2002-2005 Joel
de Guzman, David Abrahams<p>
Distributed under the Boost Software License, Version 1.0. (See accompanying
file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">
http://www.boost.org/LICENSE_1_0.txt </a>)
</p>
</div></td>
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="embedding.html"><img src="../../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../index.html"><img src="../../../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="exception.html"><img src="../../../../../../../doc/src/images/next.png" alt="Next"></a>
</div>
</body>
</html>

View File

@@ -0,0 +1,360 @@
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
<title>Object Interface</title>
<link rel="stylesheet" href="../../../../../../../doc/src/boostbook.css" type="text/css">
<meta name="generator" content="DocBook XSL Stylesheets V1.76.1">
<link rel="home" href="../index.html" title="Chapter&#160;1.&#160;python 2.0">
<link rel="up" href="../index.html" title="Chapter&#160;1.&#160;python 2.0">
<link rel="prev" href="functions.html" title="Functions">
<link rel="next" href="embedding.html" title="Embedding">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<table cellpadding="2" width="100%"><tr>
<td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../../../../../boost.png"></td>
<td align="center"><a href="../../../../../../../index.html">Home</a></td>
<td align="center"><a href="../../../../../../../libs/libraries.htm">Libraries</a></td>
<td align="center"><a href="http://www.boost.org/users/people.html">People</a></td>
<td align="center"><a href="http://www.boost.org/users/faq.html">FAQ</a></td>
<td align="center"><a href="../../../../../../../more/index.htm">More</a></td>
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="functions.html"><img src="../../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../index.html"><img src="../../../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="embedding.html"><img src="../../../../../../../doc/src/images/next.png" alt="Next"></a>
</div>
<div class="section">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="python.object"></a>Object Interface</h2></div></div></div>
<div class="toc"><dl>
<dt><span class="section"><a href="object.html#python.basic_interface">Basic Interface</a></span></dt>
<dt><span class="section"><a href="object.html#python.derived_object_types">Derived Object types</a></span></dt>
<dt><span class="section"><a href="object.html#python.extracting_c___objects">Extracting C++ objects</a></span></dt>
<dt><span class="section"><a href="object.html#python.enums">Enums</a></span></dt>
<dt><span class="section"><a href="object.html#python.creating_python_object">Creating <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">python</span><span class="special">::</span><span class="identifier">object</span></code> from <code class="computeroutput"><span class="identifier">PyObject</span><span class="special">*</span></code></a></span></dt>
</dl></div>
<p>
Python is dynamically typed, unlike C++ which is statically typed. Python variables
may hold an integer, a float, list, dict, tuple, str, long etc., among other
things. In the viewpoint of Boost.Python and C++, these Pythonic variables
are just instances of class <code class="literal">object</code>. We will see in this
chapter how to deal with Python objects.
</p>
<p>
As mentioned, one of the goals of Boost.Python is to provide a bidirectional
mapping between C++ and Python while maintaining the Python feel. Boost.Python
C++ <code class="literal">object</code>s are as close as possible to Python. This should
minimize the learning curve significantly.
</p>
<p>
<span class="inlinemediaobject"><img src="../images/python.png" alt="python"></span>
</p>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="python.basic_interface"></a>Basic Interface</h3></div></div></div>
<p>
Class <code class="literal">object</code> wraps <code class="literal">PyObject*</code>. All the
intricacies of dealing with <code class="literal">PyObject</code>s such as managing
reference counting are handled by the <code class="literal">object</code> class. C++
object interoperability is seamless. Boost.Python C++ <code class="literal">object</code>s
can in fact be explicitly constructed from any C++ object.
</p>
<p>
To illustrate, this Python code snippet:
</p>
<pre class="programlisting"><span class="keyword">def</span> <span class="identifier">f</span><span class="special">(</span><span class="identifier">x</span><span class="special">,</span> <span class="identifier">y</span><span class="special">):</span>
<span class="keyword">if</span> <span class="special">(</span><span class="identifier">y</span> <span class="special">==</span> <span class="string">'foo'</span><span class="special">):</span>
<span class="identifier">x</span><span class="special">[</span><span class="number">3</span><span class="special">:</span><span class="number">7</span><span class="special">]</span> <span class="special">=</span> <span class="string">'bar'</span>
<span class="keyword">else</span><span class="special">:</span>
<span class="identifier">x</span><span class="special">.</span><span class="identifier">items</span> <span class="special">+=</span> <span class="identifier">y</span><span class="special">(</span><span class="number">3</span><span class="special">,</span> <span class="identifier">x</span><span class="special">)</span>
<span class="keyword">return</span> <span class="identifier">x</span>
<span class="keyword">def</span> <span class="identifier">getfunc</span><span class="special">():</span>
<span class="keyword">return</span> <span class="identifier">f</span><span class="special">;</span>
</pre>
<p>
Can be rewritten in C++ using Boost.Python facilities this way:
</p>
<pre class="programlisting"><span class="identifier">object</span> <span class="identifier">f</span><span class="special">(</span><span class="identifier">object</span> <span class="identifier">x</span><span class="special">,</span> <span class="identifier">object</span> <span class="identifier">y</span><span class="special">)</span> <span class="special">{</span>
<span class="keyword">if</span> <span class="special">(</span><span class="identifier">y</span> <span class="special">==</span> <span class="string">"foo"</span><span class="special">)</span>
<span class="identifier">x</span><span class="special">.</span><span class="identifier">slice</span><span class="special">(</span><span class="number">3</span><span class="special">,</span><span class="number">7</span><span class="special">)</span> <span class="special">=</span> <span class="string">"bar"</span><span class="special">;</span>
<span class="keyword">else</span>
<span class="identifier">x</span><span class="special">.</span><span class="identifier">attr</span><span class="special">(</span><span class="string">"items"</span><span class="special">)</span> <span class="special">+=</span> <span class="identifier">y</span><span class="special">(</span><span class="number">3</span><span class="special">,</span> <span class="identifier">x</span><span class="special">);</span>
<span class="keyword">return</span> <span class="identifier">x</span><span class="special">;</span>
<span class="special">}</span>
<span class="identifier">object</span> <span class="identifier">getfunc</span><span class="special">()</span> <span class="special">{</span>
<span class="keyword">return</span> <span class="identifier">object</span><span class="special">(</span><span class="identifier">f</span><span class="special">);</span>
<span class="special">}</span>
</pre>
<p>
Apart from cosmetic differences due to the fact that we are writing the code
in C++, the look and feel should be immediately apparent to the Python coder.
</p>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="python.derived_object_types"></a>Derived Object types</h3></div></div></div>
<p>
Boost.Python comes with a set of derived <code class="literal">object</code> types
corresponding to that of Python's:
</p>
<div class="itemizedlist"><ul class="itemizedlist" type="disc">
<li class="listitem">
list
</li>
<li class="listitem">
dict
</li>
<li class="listitem">
tuple
</li>
<li class="listitem">
str
</li>
<li class="listitem">
long_
</li>
<li class="listitem">
enum
</li>
</ul></div>
<p>
These derived <code class="literal">object</code> types act like real Python types.
For instance:
</p>
<pre class="programlisting"><span class="identifier">str</span><span class="special">(</span><span class="number">1</span><span class="special">)</span> <span class="special">==&gt;</span> <span class="string">"1"</span>
</pre>
<p>
Wherever appropriate, a particular derived <code class="literal">object</code> has
corresponding Python type's methods. For instance, <code class="literal">dict</code>
has a <code class="literal">keys()</code> method:
</p>
<pre class="programlisting"><span class="identifier">d</span><span class="special">.</span><span class="identifier">keys</span><span class="special">()</span>
</pre>
<p>
<code class="literal">make_tuple</code> is provided for declaring <span class="emphasis"><em>tuple literals</em></span>.
Example:
</p>
<pre class="programlisting"><span class="identifier">make_tuple</span><span class="special">(</span><span class="number">123</span><span class="special">,</span> <span class="char">'D'</span><span class="special">,</span> <span class="string">"Hello, World"</span><span class="special">,</span> <span class="number">0.0</span><span class="special">);</span>
</pre>
<p>
In C++, when Boost.Python <code class="literal">object</code>s are used as arguments
to functions, subtype matching is required. For example, when a function
<code class="literal">f</code>, as declared below, is wrapped, it will only accept
instances of Python's <code class="literal">str</code> type and subtypes.
</p>
<pre class="programlisting"><span class="keyword">void</span> <span class="identifier">f</span><span class="special">(</span><span class="identifier">str</span> <span class="identifier">name</span><span class="special">)</span>
<span class="special">{</span>
<span class="identifier">object</span> <span class="identifier">n2</span> <span class="special">=</span> <span class="identifier">name</span><span class="special">.</span><span class="identifier">attr</span><span class="special">(</span><span class="string">"upper"</span><span class="special">)();</span> <span class="comment">// NAME = name.upper()</span>
<span class="identifier">str</span> <span class="identifier">NAME</span> <span class="special">=</span> <span class="identifier">name</span><span class="special">.</span><span class="identifier">upper</span><span class="special">();</span> <span class="comment">// better</span>
<span class="identifier">object</span> <span class="identifier">msg</span> <span class="special">=</span> <span class="string">"%s is bigger than %s"</span> <span class="special">%</span> <span class="identifier">make_tuple</span><span class="special">(</span><span class="identifier">NAME</span><span class="special">,</span><span class="identifier">name</span><span class="special">);</span>
<span class="special">}</span>
</pre>
<p>
In finer detail:
</p>
<pre class="programlisting"><span class="identifier">str</span> <span class="identifier">NAME</span> <span class="special">=</span> <span class="identifier">name</span><span class="special">.</span><span class="identifier">upper</span><span class="special">();</span>
</pre>
<p>
Illustrates that we provide versions of the str type's methods as C++ member
functions.
</p>
<pre class="programlisting"><span class="identifier">object</span> <span class="identifier">msg</span> <span class="special">=</span> <span class="string">"%s is bigger than %s"</span> <span class="special">%</span> <span class="identifier">make_tuple</span><span class="special">(</span><span class="identifier">NAME</span><span class="special">,</span><span class="identifier">name</span><span class="special">);</span>
</pre>
<p>
Demonstrates that you can write the C++ equivalent of <code class="literal">"format"
% x,y,z</code> in Python, which is useful since there's no easy way to
do that in std C++.
</p>
<div class="sidebar">
<div class="titlepage"></div>
<p>
<span class="inlinemediaobject"><img src="../images/alert.png" alt="alert"></span> <span class="bold"><strong>Beware</strong></span> the common pitfall
of forgetting that the constructors of most of Python's mutable types make
copies, just as in Python.
</p>
</div>
<p>
Python:
</p>
<pre class="programlisting"><span class="special">&gt;&gt;&gt;</span> <span class="identifier">d</span> <span class="special">=</span> <span class="identifier">dict</span><span class="special">(</span><span class="identifier">x</span><span class="special">.</span><span class="identifier">__dict__</span><span class="special">)</span> <span class="comment"># copies x.__dict__</span>
<span class="special">&gt;&gt;&gt;</span> <span class="identifier">d</span><span class="special">[</span><span class="string">'whatever'</span><span class="special">]</span> <span class="special">=</span> <span class="number">3</span> <span class="comment"># modifies the copy</span>
</pre>
<p>
C++:
</p>
<pre class="programlisting"><span class="identifier">dict</span> <span class="identifier">d</span><span class="special">(</span><span class="identifier">x</span><span class="special">.</span><span class="identifier">attr</span><span class="special">(</span><span class="string">"__dict__"</span><span class="special">));</span> <span class="comment">// copies x.__dict__</span>
<span class="identifier">d</span><span class="special">[</span><span class="char">'whatever'</span><span class="special">]</span> <span class="special">=</span> <span class="number">3</span><span class="special">;</span> <span class="comment">// modifies the copy</span>
</pre>
<h3>
<a name="derived_object_types.class__lt_t_gt__as_objects"></a>
class_&lt;T&gt; as objects
</h3>
<p>
Due to the dynamic nature of Boost.Python objects, any <code class="literal">class_&lt;T&gt;</code>
may also be one of these types! The following code snippet wraps the class
(type) object.
</p>
<p>
We can use this to create wrapped instances. Example:
</p>
<pre class="programlisting"><span class="identifier">object</span> <span class="identifier">vec345</span> <span class="special">=</span> <span class="special">(</span>
<span class="identifier">class_</span><span class="special">&lt;</span><span class="identifier">Vec2</span><span class="special">&gt;(</span><span class="string">"Vec2"</span><span class="special">,</span> <span class="identifier">init</span><span class="special">&lt;</span><span class="keyword">double</span><span class="special">,</span> <span class="keyword">double</span><span class="special">&gt;())</span>
<span class="special">.</span><span class="identifier">def_readonly</span><span class="special">(</span><span class="string">"length"</span><span class="special">,</span> <span class="special">&amp;</span><span class="identifier">Point</span><span class="special">::</span><span class="identifier">length</span><span class="special">)</span>
<span class="special">.</span><span class="identifier">def_readonly</span><span class="special">(</span><span class="string">"angle"</span><span class="special">,</span> <span class="special">&amp;</span><span class="identifier">Point</span><span class="special">::</span><span class="identifier">angle</span><span class="special">)</span>
<span class="special">)(</span><span class="number">3.0</span><span class="special">,</span> <span class="number">4.0</span><span class="special">);</span>
<span class="identifier">assert</span><span class="special">(</span><span class="identifier">vec345</span><span class="special">.</span><span class="identifier">attr</span><span class="special">(</span><span class="string">"length"</span><span class="special">)</span> <span class="special">==</span> <span class="number">5.0</span><span class="special">);</span>
</pre>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="python.extracting_c___objects"></a>Extracting C++ objects</h3></div></div></div>
<p>
At some point, we will need to get C++ values out of object instances. This
can be achieved with the <code class="literal">extract&lt;T&gt;</code> function. Consider
the following:
</p>
<pre class="programlisting"><span class="keyword">double</span> <span class="identifier">x</span> <span class="special">=</span> <span class="identifier">o</span><span class="special">.</span><span class="identifier">attr</span><span class="special">(</span><span class="string">"length"</span><span class="special">);</span> <span class="comment">// compile error</span>
</pre>
<p>
In the code above, we got a compiler error because Boost.Python <code class="literal">object</code>
can't be implicitly converted to <code class="literal">double</code>s. Instead, what
we wanted to do above can be achieved by writing:
</p>
<pre class="programlisting"><span class="keyword">double</span> <span class="identifier">l</span> <span class="special">=</span> <span class="identifier">extract</span><span class="special">&lt;</span><span class="keyword">double</span><span class="special">&gt;(</span><span class="identifier">o</span><span class="special">.</span><span class="identifier">attr</span><span class="special">(</span><span class="string">"length"</span><span class="special">));</span>
<span class="identifier">Vec2</span><span class="special">&amp;</span> <span class="identifier">v</span> <span class="special">=</span> <span class="identifier">extract</span><span class="special">&lt;</span><span class="identifier">Vec2</span><span class="special">&amp;&gt;(</span><span class="identifier">o</span><span class="special">);</span>
<span class="identifier">assert</span><span class="special">(</span><span class="identifier">l</span> <span class="special">==</span> <span class="identifier">v</span><span class="special">.</span><span class="identifier">length</span><span class="special">());</span>
</pre>
<p>
The first line attempts to extract the "length" attribute of the
Boost.Python <code class="literal">object</code>. The second line attempts to <span class="emphasis"><em>extract</em></span>
the <code class="literal">Vec2</code> object from held by the Boost.Python <code class="literal">object</code>.
</p>
<p>
Take note that we said "attempt to" above. What if the Boost.Python
<code class="literal">object</code> does not really hold a <code class="literal">Vec2</code>
type? This is certainly a possibility considering the dynamic nature of Python
<code class="literal">object</code>s. To be on the safe side, if the C++ type can't
be extracted, an appropriate exception is thrown. To avoid an exception,
we need to test for extractibility:
</p>
<pre class="programlisting"><span class="identifier">extract</span><span class="special">&lt;</span><span class="identifier">Vec2</span><span class="special">&amp;&gt;</span> <span class="identifier">x</span><span class="special">(</span><span class="identifier">o</span><span class="special">);</span>
<span class="keyword">if</span> <span class="special">(</span><span class="identifier">x</span><span class="special">.</span><span class="identifier">check</span><span class="special">())</span> <span class="special">{</span>
<span class="identifier">Vec2</span><span class="special">&amp;</span> <span class="identifier">v</span> <span class="special">=</span> <span class="identifier">x</span><span class="special">();</span> <span class="special">...</span>
</pre>
<p>
<span class="inlinemediaobject"><img src="../images/tip.png" alt="tip"></span> The astute reader might have noticed that the <code class="literal">extract&lt;T&gt;</code>
facility in fact solves the mutable copying problem:
</p>
<pre class="programlisting"><span class="identifier">dict</span> <span class="identifier">d</span> <span class="special">=</span> <span class="identifier">extract</span><span class="special">&lt;</span><span class="identifier">dict</span><span class="special">&gt;(</span><span class="identifier">x</span><span class="special">.</span><span class="identifier">attr</span><span class="special">(</span><span class="string">"__dict__"</span><span class="special">));</span>
<span class="identifier">d</span><span class="special">[</span><span class="string">"whatever"</span><span class="special">]</span> <span class="special">=</span> <span class="number">3</span><span class="special">;</span> <span class="comment">// modifies x.__dict__ !</span>
</pre>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="python.enums"></a>Enums</h3></div></div></div>
<p>
Boost.Python has a nifty facility to capture and wrap C++ enums. While Python
has no <code class="literal">enum</code> type, we'll often want to expose our C++ enums
to Python as an <code class="literal">int</code>. Boost.Python's enum facility makes
this easy while taking care of the proper conversions from Python's dynamic
typing to C++'s strong static typing (in C++, ints cannot be implicitly converted
to enums). To illustrate, given a C++ enum:
</p>
<pre class="programlisting"><span class="keyword">enum</span> <span class="identifier">choice</span> <span class="special">{</span> <span class="identifier">red</span><span class="special">,</span> <span class="identifier">blue</span> <span class="special">};</span>
</pre>
<p>
the construct:
</p>
<pre class="programlisting"><span class="identifier">enum_</span><span class="special">&lt;</span><span class="identifier">choice</span><span class="special">&gt;(</span><span class="string">"choice"</span><span class="special">)</span>
<span class="special">.</span><span class="identifier">value</span><span class="special">(</span><span class="string">"red"</span><span class="special">,</span> <span class="identifier">red</span><span class="special">)</span>
<span class="special">.</span><span class="identifier">value</span><span class="special">(</span><span class="string">"blue"</span><span class="special">,</span> <span class="identifier">blue</span><span class="special">)</span>
<span class="special">;</span>
</pre>
<p>
can be used to expose to Python. The new enum type is created in the current
<code class="literal">scope()</code>, which is usually the current module. The snippet
above creates a Python class derived from Python's <code class="literal">int</code>
type which is associated with the C++ type passed as its first parameter.
</p>
<div class="note"><table border="0" summary="Note">
<tr>
<td rowspan="2" align="center" valign="top" width="25"><img alt="[Note]" src="../../../../../../../doc/src/images/note.png"></td>
<th align="left">Note</th>
</tr>
<tr><td align="left" valign="top">
<p>
<span class="bold"><strong>what is a scope?</strong></span>
</p>
<p>
The scope is a class that has an associated global Python object which
controls the Python namespace in which new extension classes and wrapped
functions will be defined as attributes. Details can be found <a href="../../../../v2/scope.html" target="_top">here</a>.
</p>
</td></tr>
</table></div>
<p>
You can access those values in Python as
</p>
<pre class="programlisting"><span class="special">&gt;&gt;&gt;</span> <span class="identifier">my_module</span><span class="special">.</span><span class="identifier">choice</span><span class="special">.</span><span class="identifier">red</span>
<span class="identifier">my_module</span><span class="special">.</span><span class="identifier">choice</span><span class="special">.</span><span class="identifier">red</span>
</pre>
<p>
where my_module is the module where the enum is declared. You can also create
a new scope around a class:
</p>
<pre class="programlisting"><span class="identifier">scope</span> <span class="identifier">in_X</span> <span class="special">=</span> <span class="identifier">class_</span><span class="special">&lt;</span><span class="identifier">X</span><span class="special">&gt;(</span><span class="string">"X"</span><span class="special">)</span>
<span class="special">.</span><span class="identifier">def</span><span class="special">(</span> <span class="special">...</span> <span class="special">)</span>
<span class="special">.</span><span class="identifier">def</span><span class="special">(</span> <span class="special">...</span> <span class="special">)</span>
<span class="special">;</span>
<span class="comment">// Expose X::nested as X.nested</span>
<span class="identifier">enum_</span><span class="special">&lt;</span><span class="identifier">X</span><span class="special">::</span><span class="identifier">nested</span><span class="special">&gt;(</span><span class="string">"nested"</span><span class="special">)</span>
<span class="special">.</span><span class="identifier">value</span><span class="special">(</span><span class="string">"red"</span><span class="special">,</span> <span class="identifier">red</span><span class="special">)</span>
<span class="special">.</span><span class="identifier">value</span><span class="special">(</span><span class="string">"blue"</span><span class="special">,</span> <span class="identifier">blue</span><span class="special">)</span>
<span class="special">;</span>
</pre>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="python.creating_python_object"></a>Creating <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">python</span><span class="special">::</span><span class="identifier">object</span></code> from <code class="computeroutput"><span class="identifier">PyObject</span><span class="special">*</span></code>
</h3></div></div></div>
<p>
When you want a <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">python</span><span class="special">::</span><span class="identifier">object</span></code> to manage a pointer to <code class="computeroutput"><span class="identifier">PyObject</span><span class="special">*</span></code>
pyobj one does:
</p>
<pre class="programlisting"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">python</span><span class="special">::</span><span class="identifier">object</span> <span class="identifier">o</span><span class="special">(</span><span class="identifier">boost</span><span class="special">::</span><span class="identifier">python</span><span class="special">::</span><span class="identifier">handle</span><span class="special">&lt;&gt;(</span><span class="identifier">pyobj</span><span class="special">));</span>
</pre>
<p>
In this case, the <code class="computeroutput"><span class="identifier">o</span></code> object,
manages the <code class="computeroutput"><span class="identifier">pyobj</span></code>, it won&#8217;t
increase the reference count on construction.
</p>
<p>
Otherwise, to use a borrowed reference:
</p>
<pre class="programlisting"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">python</span><span class="special">::</span><span class="identifier">object</span> <span class="identifier">o</span><span class="special">(</span><span class="identifier">boost</span><span class="special">::</span><span class="identifier">python</span><span class="special">::</span><span class="identifier">handle</span><span class="special">&lt;&gt;(</span><span class="identifier">boost</span><span class="special">::</span><span class="identifier">python</span><span class="special">::</span><span class="identifier">borrowed</span><span class="special">(</span><span class="identifier">pyobj</span><span class="special">)));</span>
</pre>
<p>
In this case, <code class="computeroutput"><span class="identifier">Py_INCREF</span></code> is
called, so <code class="computeroutput"><span class="identifier">pyobj</span></code> is not destructed
when object o goes out of scope.
</p>
</div>
</div>
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
<td align="left"></td>
<td align="right"><div class="copyright-footer">Copyright &#169; 2002-2005 Joel
de Guzman, David Abrahams<p>
Distributed under the Boost Software License, Version 1.0. (See accompanying
file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">
http://www.boost.org/LICENSE_1_0.txt </a>)
</p>
</div></td>
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="functions.html"><img src="../../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../index.html"><img src="../../../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="embedding.html"><img src="../../../../../../../doc/src/images/next.png" alt="Next"></a>
</div>
</body>
</html>

View File

@@ -0,0 +1,440 @@
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
<title>General Techniques</title>
<link rel="stylesheet" href="../../../../../../../doc/src/boostbook.css" type="text/css">
<meta name="generator" content="DocBook XSL Stylesheets V1.76.1">
<link rel="home" href="../index.html" title="Chapter&#160;1.&#160;python 2.0">
<link rel="up" href="../index.html" title="Chapter&#160;1.&#160;python 2.0">
<link rel="prev" href="exception.html" title="Exception Translation">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<table cellpadding="2" width="100%"><tr>
<td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../../../../../boost.png"></td>
<td align="center"><a href="../../../../../../../index.html">Home</a></td>
<td align="center"><a href="../../../../../../../libs/libraries.htm">Libraries</a></td>
<td align="center"><a href="http://www.boost.org/users/people.html">People</a></td>
<td align="center"><a href="http://www.boost.org/users/faq.html">FAQ</a></td>
<td align="center"><a href="../../../../../../../more/index.htm">More</a></td>
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="exception.html"><img src="../../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../index.html"><img src="../../../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../../../../../doc/src/images/home.png" alt="Home"></a>
</div>
<div class="section">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="python.techniques"></a>General Techniques</h2></div></div></div>
<div class="toc"><dl>
<dt><span class="section"><a href="techniques.html#python.creating_packages">Creating Packages</a></span></dt>
<dt><span class="section"><a href="techniques.html#python.extending_wrapped_objects_in_python">Extending Wrapped Objects in Python</a></span></dt>
<dt><span class="section"><a href="techniques.html#python.reducing_compiling_time">Reducing Compiling Time</a></span></dt>
</dl></div>
<p>
Here are presented some useful techniques that you can use while wrapping code
with Boost.Python.
</p>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="python.creating_packages"></a>Creating Packages</h3></div></div></div>
<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" target="_top">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)
<code class="literal">sounds</code>. Our library already has a neat C++ namespace hierarchy,
like so:
</p>
<pre class="programlisting"><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>
<p>
We would like to present this same hierarchy to the Python user, allowing
him to write code like this:
</p>
<pre class="programlisting"><span class="keyword">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="comment"># echo is a C++ function</span>
</pre>
<p>
The first step is to write the wrapping code. We have to export each module
separately with Boost.Python, like this:
</p>
<pre class="programlisting"><span class="special">/*</span> <span class="identifier">file</span> <span class="identifier">core</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">core</span><span class="special">)</span>
<span class="special">{</span>
<span class="special">/*</span> <span class="identifier">export</span> <span class="identifier">everything</span> <span class="keyword">in</span> <span class="identifier">the</span> <span class="identifier">sounds</span><span class="special">::</span><span class="identifier">core</span> <span class="identifier">namespace</span> <span class="special">*/</span>
<span class="special">...</span>
<span class="special">}</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="special">{</span>
<span class="special">/*</span> <span class="identifier">export</span> <span class="identifier">everything</span> <span class="keyword">in</span> <span class="identifier">the</span> <span class="identifier">sounds</span><span class="special">::</span><span class="identifier">io</span> <span class="identifier">namespace</span> <span class="special">*/</span>
<span class="special">...</span>
<span class="special">}</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="special">{</span>
<span class="special">/*</span> <span class="identifier">export</span> <span class="identifier">everything</span> <span class="keyword">in</span> <span class="identifier">the</span> <span class="identifier">sounds</span><span class="special">::</span><span class="identifier">filters</span> <span class="identifier">namespace</span> <span class="special">*/</span>
<span class="special">...</span>
<span class="special">}</span>
</pre>
<p>
Compiling these files will generate the following Python extensions: <code class="literal">core.pyd</code>,
<code class="literal">io.pyd</code> and <code class="literal">filters.pyd</code>.
</p>
<div class="note"><table border="0" summary="Note">
<tr>
<td rowspan="2" align="center" valign="top" width="25"><img alt="[Note]" src="../../../../../../../doc/src/images/note.png"></td>
<th align="left">Note</th>
</tr>
<tr><td align="left" valign="top"><p>
The extension <code class="literal">.pyd</code> is used for python extension modules,
which are just shared libraries. Using the default for your system, like
<code class="literal">.so</code> for Unix and <code class="literal">.dll</code> for Windows,
works just as well.
</p></td></tr>
</table></div>
<p>
Now, we create this directory structure for our Python package:
</p>
<pre class="programlisting">sounds/
__init__.py
core.pyd
filters.pyd
io.pyd
</pre>
<p>
The file <code class="literal">__init__.py</code> is what tells Python that the directory
<code class="literal">sounds/</code> is actually a Python package. It can be a empty
file, but can also perform some magic, that will be shown later.
</p>
<p>
Now our package is ready. All the user has to do is put <code class="literal">sounds</code>
into his <a href="http://www.python.org/doc/current/tut/node8.html#SECTION008110000000000000000" target="_top">PYTHONPATH</a>
and fire up the interpreter:
</p>
<pre class="programlisting"><span class="special">&gt;&gt;&gt;</span> <span class="keyword">import</span> <span class="identifier">sounds</span><span class="special">.</span><span class="identifier">io</span>
<span class="special">&gt;&gt;&gt;</span> <span class="keyword">import</span> <span class="identifier">sounds</span><span class="special">.</span><span class="identifier">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="string">'file.mp3'</span><span class="special">)</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>
<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 <span class="emphasis"><em>pure</em></span> 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>
<pre class="programlisting"><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="special">{</span>
<span class="special">...</span>
<span class="comment">/* export everything in the sounds::core namespace */</span>
<span class="special">}</span>
</pre>
<p>
Note that we added an underscore to the module name. The filename will have
to be changed to <code class="literal">_core.pyd</code> as well, and we do the same
to the other extension modules. Now, we change our package hierarchy like
so:
</p>
<pre class="programlisting">sounds/
__init__.py
core/
__init__.py
<span class="underline">core.pyd
filters/
\</span>_init__.py
<span class="underline">filters.pyd
io/
\</span>_init__.py
_io.pyd
</pre>
<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>
<pre class="programlisting"><span class="special">&gt;&gt;&gt;</span> <span class="keyword">import</span> <span class="identifier">sounds</span><span class="special">.</span><span class="identifier">core</span><span class="special">.</span><span class="identifier">_core</span>
<span class="special">&gt;&gt;&gt;</span> <span class="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>
<p>
which is not what we want. But here enters the <code class="literal">__init__.py</code>
magic: everything that is brought to the <code class="literal">__init__.py</code> namespace
can be accessed directly by the user. So, all we have to do is bring the
entire namespace from <code class="literal">_core.pyd</code> to <code class="literal">core/__init__.py</code>.
So add this line of code to <code class="literal">sounds/core/__init__.py</code>:
</p>
<pre class="programlisting"><span class="keyword">from</span> <span class="identifier">_core</span> <span class="keyword">import</span> <span class="special">*</span>
</pre>
<p>
We do the same for the other packages. Now the user accesses the functions
and classes in the extension modules like before:
</p>
<pre class="programlisting"><span class="special">&gt;&gt;&gt;</span> <span class="keyword">import</span> <span class="identifier">sounds</span><span class="special">.</span><span class="identifier">filters</span>
<span class="special">&gt;&gt;&gt;</span> <span class="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>
<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 <span class="emphasis"><em>pure</em></span>
Python function, <code class="literal">echo_noise</code>, to the <code class="literal">filters</code>
package. This function applies both the <code class="literal">echo</code> and <code class="literal">noise</code>
filters in sequence in the given <code class="literal">sound</code> object. We create
a file named <code class="literal">sounds/filters/echo_noise.py</code> and code our
function:
</p>
<pre class="programlisting"><span class="keyword">import</span> <span class="identifier">_filters</span>
<span class="keyword">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>
<p>
Next, we add this line to <code class="literal">sounds/filters/__init__.py</code>:
</p>
<pre class="programlisting"><span class="keyword">from</span> <span class="identifier">echo_noise</span> <span class="keyword">import</span> <span class="identifier">echo_noise</span>
</pre>
<p>
And that's it. The user now accesses this function like any other function
from the <code class="literal">filters</code> package:
</p>
<pre class="programlisting"><span class="special">&gt;&gt;&gt;</span> <span class="keyword">import</span> <span class="identifier">sounds</span><span class="special">.</span><span class="identifier">filters</span>
<span class="special">&gt;&gt;&gt;</span> <span class="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>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="python.extending_wrapped_objects_in_python"></a>Extending Wrapped Objects in Python</h3></div></div></div>
<p>
Thanks to Python's flexibility, you can easily add new methods to a class,
even after it was already created:
</p>
<pre class="programlisting"><span class="special">&gt;&gt;&gt;</span> <span class="keyword">class</span> <span class="identifier">C</span><span class="special">(</span><span class="identifier">object</span><span class="special">):</span> <span class="keyword">pass</span>
<span class="special">&gt;&gt;&gt;</span>
<span class="special">&gt;&gt;&gt;</span> <span class="comment"># a regular function</span>
<span class="special">&gt;&gt;&gt;</span> <span class="keyword">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="string">'A C instance!'</span>
<span class="special">&gt;&gt;&gt;</span>
<span class="special">&gt;&gt;&gt;</span> <span class="comment"># now we turn it in a member 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;</span>
<span class="special">&gt;&gt;&gt;</span> <span class="identifier">c</span> <span class="special">=</span> <span class="identifier">C</span><span class="special">()</span>
<span class="special">&gt;&gt;&gt;</span> <span class="keyword">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">!</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>
<p>
Yes, Python rox. <span class="inlinemediaobject"><img src="../images/smiley.png" alt="smiley"></span>
</p>
<p>
We can do the same with classes that were wrapped with Boost.Python. Suppose
we have a class <code class="literal">point</code> in C++:
</p>
<pre class="programlisting"><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="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">"point"</span><span class="special">)...;</span>
<span class="special">}</span>
</pre>
<p>
If we are using the technique from the previous session, <a class="link" href="techniques.html#python.creating_packages" title="Creating Packages">Creating
Packages</a>, we can code directly into <code class="literal">geom/__init__.py</code>:
</p>
<pre class="programlisting"><span class="keyword">from</span> <span class="identifier">_geom</span> <span class="keyword">import</span> <span class="special">*</span>
<span class="comment"># a regular function</span>
<span class="keyword">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="comment"># now we turn it into a member function</span>
<span class="identifier">point</span><span class="special">.</span><span class="identifier">__str__</span> <span class="special">=</span> <span class="identifier">point_str</span>
</pre>
<p>
<span class="bold"><strong>All</strong></span> point instances created from C++ will
also have this member function! This technique has several advantages:
</p>
<div class="itemizedlist"><ul class="itemizedlist" type="disc">
<li class="listitem">
Cut down compile times to zero for these additional functions
</li>
<li class="listitem">
Reduce the memory footprint to virtually zero
</li>
<li class="listitem">
Minimize the need to recompile
</li>
<li class="listitem">
Rapid prototyping (you can move the code to C++ if required without changing
the interface)
</li>
</ul></div>
<p>
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.
</p>
<pre class="programlisting"><span class="comment"># The one Boost.Python uses for all wrapped classes.</span>
<span class="comment"># You can use here any class exported by Boost instead of "point"</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="keyword">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="keyword">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="keyword">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="keyword">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="comment"># inject some methods in the point 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="keyword">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="string">'Point(x=%s, y=%s)'</span> <span class="special">%</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="keyword">def</span> <span class="identifier">foo</span><span class="special">(</span><span class="identifier">self</span><span class="special">):</span>
<span class="keyword">print</span> <span class="string">'foo!'</span>
</pre>
<p>
Now let's see how it got:
</p>
<pre class="programlisting"><span class="special">&gt;&gt;&gt;</span> <span class="keyword">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">)</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>
<p>
Another useful idea is to replace constructors with factory functions:
</p>
<pre class="programlisting"><span class="identifier">_point</span> <span class="special">=</span> <span class="identifier">point</span>
<span class="keyword">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>
<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>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="python.reducing_compiling_time"></a>Reducing Compiling Time</h3></div></div></div>
<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>
<pre class="programlisting"><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="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">"point"</span><span class="special">)...;</span>
<span class="special">}</span>
<span class="comment">/* file triangle.cpp */</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="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">"triangle"</span><span class="special">)...;</span>
<span class="special">}</span>
</pre>
<p>
Now you create a file <code class="literal">main.cpp</code>, which contains the <code class="literal">BOOST_PYTHON_MODULE</code>
macro, and call the various export functions inside it.
</p>
<pre class="programlisting"><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="special">{</span>
<span class="identifier">export_point</span><span class="special">();</span>
<span class="identifier">export_triangle</span><span class="special">();</span>
<span class="special">}</span>
</pre>
<p>
Compiling and linking together all this files produces the same result as
the usual approach:
</p>
<pre class="programlisting"><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="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">"point"</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">"triangle"</span><span class="special">)...;</span>
<span class="special">}</span>
</pre>
<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>
<div class="note"><table border="0" summary="Note">
<tr>
<td rowspan="2" align="center" valign="top" width="25"><img alt="[Note]" src="../../../../../../../doc/src/images/note.png"></td>
<th align="left">Note</th>
</tr>
<tr><td align="left" valign="top"><p>
If you're exporting your classes with <a href="../../../../../pyste/index.html" target="_top">Pyste</a>,
take a look at the <code class="literal">--multiple</code> option, that generates
the wrappers in various files as demonstrated here.
</p></td></tr>
</table></div>
<div class="note"><table border="0" summary="Note">
<tr>
<td rowspan="2" align="center" valign="top" width="25"><img alt="[Note]" src="../../../../../../../doc/src/images/note.png"></td>
<th align="left">Note</th>
</tr>
<tr><td align="left" valign="top"><p>
This method is useful too if you are getting the error message <span class="emphasis"><em>"fatal
error C1204:Compiler limit:internal structure overflow"</em></span>
when compiling a large source file, as explained in the <a href="../../../../v2/faq.html#c1204" target="_top">FAQ</a>.
</p></td></tr>
</table></div>
</div>
</div>
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
<td align="left"></td>
<td align="right"><div class="copyright-footer">Copyright &#169; 2002-2005 Joel
de Guzman, David Abrahams<p>
Distributed under the Boost Software License, Version 1.0. (See accompanying
file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">
http://www.boost.org/LICENSE_1_0.txt </a>)
</p>
</div></td>
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="exception.html"><img src="../../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../index.html"><img src="../../../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../../../../../doc/src/images/home.png" alt="Home"></a>
</div>
</body>
</html>

View File

@@ -1,98 +0,0 @@
<html>
<head>
<!-- Generated by the Spirit (http://spirit.sf.net) QuickDoc -->
<title>Inheritance</title>
<link rel="stylesheet" href="theme/style.css" type="text/css">
<link rel="prev" href="class_properties.html">
<link rel="next" href="class_virtual_functions.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>Inheritance</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="class_properties.html"><img src="theme/l_arr.gif" border="0"></a></td>
<td width="20"><a href="class_virtual_functions.html"><img src="theme/r_arr.gif" border="0"></a></td>
</tr>
</table>
<p>
In the previous examples, we dealt with classes that are not polymorphic.
This is not often the case. Much of the time, we will be wrapping
polymorphic classes and class hierarchies related by inheritance. We will
often have to write Boost.Python wrappers for classes that are derived from
abstract base classes.</p>
<p>
Consider this trivial inheritance structure:</p>
<code><pre>
<span class=keyword>struct </span><span class=identifier>Base </span><span class=special>{ </span><span class=keyword>virtual </span><span class=special>~</span><span class=identifier>Base</span><span class=special>(); };
</span><span class=keyword>struct </span><span class=identifier>Derived </span><span class=special>: </span><span class=identifier>Base </span><span class=special>{};
</span></pre></code>
<p>
And a set of C++ functions operating on <tt>Base</tt> and <tt>Derived</tt> object
instances:</p>
<code><pre>
<span class=keyword>void </span><span class=identifier>b</span><span class=special>(</span><span class=identifier>Base</span><span class=special>*);
</span><span class=keyword>void </span><span class=identifier>d</span><span class=special>(</span><span class=identifier>Derived</span><span class=special>*);
</span><span class=identifier>Base</span><span class=special>* </span><span class=identifier>factory</span><span class=special>() { </span><span class=keyword>return </span><span class=keyword>new </span><span class=identifier>Derived</span><span class=special>; }
</span></pre></code>
<p>
We've seen how we can wrap the base class <tt>Base</tt>:</p>
<code><pre>
<span class=identifier>class_</span><span class=special>&lt;</span><span class=identifier>Base</span><span class=special>&gt;(</span><span class=string>&quot;Base&quot;</span><span class=special>)
/*...*/
;
</span></pre></code>
<p>
Now we can inform Boost.Python of the inheritance relationship between
<tt>Derived</tt> and its base class <tt>Base</tt>. Thus:</p>
<code><pre>
<span class=identifier>class_</span><span class=special>&lt;</span><span class=identifier>Derived</span><span class=special>, </span><span class=identifier>bases</span><span class=special>&lt;</span><span class=identifier>Base</span><span class=special>&gt; &gt;(</span><span class=string>&quot;Derived&quot;</span><span class=special>)
/*...*/
;
</span></pre></code>
<p>
Doing so, we get some things for free:</p>
<ol><li>Derived automatically inherits all of Base's Python methods (wrapped C++ member functions)</li><li><b>If</b> Base is polymorphic, <tt>Derived</tt> objects which have been passed to Python via a pointer or reference to <tt>Base</tt> can be passed where a pointer or reference to <tt>Derived</tt> is expected.</li></ol><p>
Now, we shall expose the C++ free functions <tt>b</tt> and <tt>d</tt> and <tt>factory</tt>:</p>
<code><pre>
<span class=identifier>def</span><span class=special>(</span><span class=string>&quot;b&quot;</span><span class=special>, </span><span class=identifier>b</span><span class=special>);
</span><span class=identifier>def</span><span class=special>(</span><span class=string>&quot;d&quot;</span><span class=special>, </span><span class=identifier>d</span><span class=special>);
</span><span class=identifier>def</span><span class=special>(</span><span class=string>&quot;factory&quot;</span><span class=special>, </span><span class=identifier>factory</span><span class=special>);
</span></pre></code>
<p>
Note that free function <tt>factory</tt> is being used to generate new
instances of class <tt>Derived</tt>. In such cases, we use
<tt>return_value_policy&lt;manage_new_object&gt;</tt> to instruct Python to adopt
the pointer to <tt>Base</tt> and hold the instance in a new Python <tt>Base</tt>
object until the the Python object is destroyed. We shall see more of
Boost.Python <a href="call_policies.html">
call policies</a> later.</p>
<code><pre>
<span class=comment>// Tell Python to take ownership of factory's result
</span><span class=identifier>def</span><span class=special>(</span><span class=string>&quot;factory&quot;</span><span class=special>, </span><span class=identifier>factory</span><span class=special>,
</span><span class=identifier>return_value_policy</span><span class=special>&lt;</span><span class=identifier>manage_new_object</span><span class=special>&gt;());
</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="class_properties.html"><img src="theme/l_arr.gif" border="0"></a></td>
<td width="20"><a href="class_virtual_functions.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

@@ -1,101 +0,0 @@
<html>
<head>
<!-- Generated by the Spirit (http://spirit.sf.net) QuickDoc -->
<title>Iterators</title>
<link rel="stylesheet" href="theme/style.css" type="text/css">
<link rel="prev" href="using_the_interpreter.html">
<link rel="next" href="exception_translation.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>Iterators</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="using_the_interpreter.html"><img src="theme/l_arr.gif" border="0"></a></td>
<td width="20"><a href="exception_translation.html"><img src="theme/r_arr.gif" border="0"></a></td>
</tr>
</table>
<p>
In C++, and STL in particular, we see iterators everywhere. Python also has
iterators, but these are two very different beasts.</p>
<p>
<b>C++ iterators:</b></p>
<ul><li>C++ has 5 type categories (random-access, bidirectional, forward, input, output)</li><li>There are 2 Operation categories: reposition, access</li><li>A pair of iterators is needed to represent a (first/last) range.</li></ul><p>
<b>Python Iterators:</b></p>
<ul><li>1 category (forward)</li><li>1 operation category (next())</li><li>Raises StopIteration exception at end</li></ul><p>
The typical Python iteration protocol: <tt><b>for y in x...</b></tt> is as follows:</p>
<code><pre>
<span class=identifier>iter </span><span class=special>= </span><span class=identifier>x</span><span class=special>.</span><span class=identifier>__iter__</span><span class=special>() </span>##<span class=identifier>get </span><span class=identifier>iterator
</span><span class=keyword>try</span><span class=special>:
</span><span class=keyword>while </span><span class=number>1</span><span class=special>:
</span><span class=identifier>y </span><span class=special>= </span><span class=identifier>iter</span><span class=special>.</span><span class=identifier>next</span><span class=special>() </span>##<span class=identifier>get </span><span class=identifier>each </span><span class=identifier>item
</span><span class=special>... </span>##<span class=identifier>process </span><span class=identifier>y
</span><span class=identifier>except </span><span class=identifier>StopIteration</span><span class=special>: </span><span class=identifier>pass </span>##<span class=identifier>iterator </span><span class=identifier>exhausted
</span></pre></code>
<p>
Boost.Python provides some mechanisms to make C++ iterators play along
nicely as Python iterators. What we need to do is to produce
appropriate __iter__ function from C++ iterators that is compatible
with the Python iteration protocol. For example:</p>
<code><pre>
<span class=identifier>object </span><span class=identifier>get_iterator </span><span class=special>= </span><span class=identifier>iterator</span><span class=special>&lt;</span><span class=identifier>vector</span><span class=special>&lt;</span><span class=keyword>int</span><span class=special>&gt; &gt;();
</span><span class=identifier>object </span><span class=identifier>iter </span><span class=special>= </span><span class=identifier>get_iterator</span><span class=special>(</span><span class=identifier>v</span><span class=special>);
</span><span class=identifier>object </span><span class=identifier>first </span><span class=special>= </span><span class=identifier>iter</span><span class=special>.</span><span class=identifier>next</span><span class=special>();
</span></pre></code>
<p>
Or for use in class_&lt;&gt;:</p>
<code><pre>
<span class=special>.</span><span class=identifier>def</span><span class=special>(</span><span class=string>&quot;__iter__&quot;</span><span class=special>, </span><span class=identifier>iterator</span><span class=special>&lt;</span><span class=identifier>vector</span><span class=special>&lt;</span><span class=keyword>int</span><span class=special>&gt; &gt;())
</span></pre></code>
<p>
<b>range</b></p>
<p>
We can create a Python savvy iterator using the range function:</p>
<ul><li>range(start, finish)</li><li>range&lt;Policies,Target&gt;(start, finish)</li></ul><p>
Here, start/finish may be one of:</p>
<ul><li>member data pointers</li><li>member function pointers</li><li>adaptable function object (use Target parameter)</li></ul><p>
<b>iterator</b></p>
<ul><li>iterator&lt;T, Policies&gt;()</li></ul><p>
Given a container <tt>T</tt>, iterator is a shortcut that simply calls <tt>range</tt>
with &amp;T::begin, &amp;T::end.</p>
<p>
Let's put this into action... Here's an example from some hypothetical
bogon Particle accelerator code:</p>
<code><pre>
<span class=identifier>f </span><span class=special>= </span><span class=identifier>Field</span><span class=special>()
</span><span class=keyword>for </span><span class=identifier>x </span><span class=identifier>in </span><span class=identifier>f</span><span class=special>.</span><span class=identifier>pions</span><span class=special>:
</span><span class=identifier>smash</span><span class=special>(</span><span class=identifier>x</span><span class=special>)
</span><span class=keyword>for </span><span class=identifier>y </span><span class=identifier>in </span><span class=identifier>f</span><span class=special>.</span><span class=identifier>bogons</span><span class=special>:
</span><span class=identifier>count</span><span class=special>(</span><span class=identifier>y</span><span class=special>)
</span></pre></code>
<p>
Now, our C++ Wrapper:</p>
<code><pre>
<span class=identifier>class_</span><span class=special>&lt;</span><span class=identifier>F</span><span class=special>&gt;(</span><span class=string>&quot;Field&quot;</span><span class=special>)
.</span><span class=identifier>property</span><span class=special>(</span><span class=string>&quot;pions&quot;</span><span class=special>, </span><span class=identifier>range</span><span class=special>(&amp;</span><span class=identifier>F</span><span class=special>::</span><span class=identifier>p_begin</span><span class=special>, &amp;</span><span class=identifier>F</span><span class=special>::</span><span class=identifier>p_end</span><span class=special>))
.</span><span class=identifier>property</span><span class=special>(</span><span class=string>&quot;bogons&quot;</span><span class=special>, </span><span class=identifier>range</span><span class=special>(&amp;</span><span class=identifier>F</span><span class=special>::</span><span class=identifier>b_begin</span><span class=special>, &amp;</span><span class=identifier>F</span><span class=special>::</span><span class=identifier>b_end</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="using_the_interpreter.html"><img src="theme/l_arr.gif" border="0"></a></td>
<td width="20"><a href="exception_translation.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

@@ -1,54 +0,0 @@
<html>
<head>
<!-- Generated by the Spirit (http://spirit.sf.net) QuickDoc -->
<title>Object Interface</title>
<link rel="stylesheet" href="theme/style.css" type="text/css">
<link rel="prev" href="auto_overloading.html">
<link rel="next" href="basic_interface.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>Object Interface</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="auto_overloading.html"><img src="theme/l_arr.gif" border="0"></a></td>
<td width="20"><a href="basic_interface.html"><img src="theme/r_arr.gif" border="0"></a></td>
</tr>
</table>
<p>
Python is dynamically typed, unlike C++ which is statically typed. Python
variables may hold an integer, a float, list, dict, tuple, str, long etc.,
among other things. In the viewpoint of Boost.Python and C++, these
Pythonic variables are just instances of class <tt>object</tt>. We shall see in
this chapter how to deal with Python objects.</p>
<p>
As mentioned, one of the goals of Boost.Python is to provide a
bidirectional mapping between C++ and Python while maintaining the Python
feel. Boost.Python C++ <tt>object</tt>s are as close as possible to Python. This
should minimize the learning curve significantly.</p>
<p>
<img src="theme/python.png"></img></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="auto_overloading.html"><img src="theme/l_arr.gif" border="0"></a></td>
<td width="20"><a href="basic_interface.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

@@ -1,88 +0,0 @@
<html>
<head>
<!-- Generated by the Spirit (http://spirit.sf.net) QuickDoc -->
<title>Overloading</title>
<link rel="stylesheet" href="theme/style.css" type="text/css">
<link rel="prev" href="call_policies.html">
<link rel="next" href="default_arguments.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>Overloading</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="call_policies.html"><img src="theme/l_arr.gif" border="0"></a></td>
<td width="20"><a href="default_arguments.html"><img src="theme/r_arr.gif" border="0"></a></td>
</tr>
</table>
<p>
The following illustrates a scheme for manually wrapping an overloaded
member functions. Of course, the same technique can be applied to wrapping
overloaded non-member functions.</p>
<p>
We have here our C++ class:</p>
<code><pre>
<span class=keyword>struct </span><span class=identifier>X
</span><span class=special>{
</span><span class=keyword>bool </span><span class=identifier>f</span><span class=special>(</span><span class=keyword>int </span><span class=identifier>a</span><span class=special>)
{
</span><span class=keyword>return </span><span class=keyword>true</span><span class=special>;
}
</span><span class=keyword>bool </span><span class=identifier>f</span><span class=special>(</span><span class=keyword>int </span><span class=identifier>a</span><span class=special>, </span><span class=keyword>double </span><span class=identifier>b</span><span class=special>)
{
</span><span class=keyword>return </span><span class=keyword>true</span><span class=special>;
}
</span><span class=keyword>bool </span><span class=identifier>f</span><span class=special>(</span><span class=keyword>int </span><span class=identifier>a</span><span class=special>, </span><span class=keyword>double </span><span class=identifier>b</span><span class=special>, </span><span class=keyword>char </span><span class=identifier>c</span><span class=special>)
{
</span><span class=keyword>return </span><span class=keyword>true</span><span class=special>;
}
</span><span class=keyword>int </span><span class=identifier>f</span><span class=special>(</span><span class=keyword>int </span><span class=identifier>a</span><span class=special>, </span><span class=keyword>int </span><span class=identifier>b</span><span class=special>, </span><span class=keyword>int </span><span class=identifier>c</span><span class=special>)
{
</span><span class=keyword>return </span><span class=identifier>a </span><span class=special>+ </span><span class=identifier>b </span><span class=special>+ </span><span class=identifier>c</span><span class=special>;
};
};
</span></pre></code>
<p>
Class X has 4 overloaded functions. We shall start by introducing some
member function pointer variables:</p>
<code><pre>
<span class=keyword>bool </span><span class=special>(</span><span class=identifier>X</span><span class=special>::*</span><span class=identifier>fx1</span><span class=special>)(</span><span class=keyword>int</span><span class=special>) = &amp;</span><span class=identifier>X</span><span class=special>::</span><span class=identifier>f</span><span class=special>;
</span><span class=keyword>bool </span><span class=special>(</span><span class=identifier>X</span><span class=special>::*</span><span class=identifier>fx2</span><span class=special>)(</span><span class=keyword>int</span><span class=special>, </span><span class=keyword>double</span><span class=special>) = &amp;</span><span class=identifier>X</span><span class=special>::</span><span class=identifier>f</span><span class=special>;
</span><span class=keyword>bool </span><span class=special>(</span><span class=identifier>X</span><span class=special>::*</span><span class=identifier>fx3</span><span class=special>)(</span><span class=keyword>int</span><span class=special>, </span><span class=keyword>double</span><span class=special>, </span><span class=keyword>char</span><span class=special>)= &amp;</span><span class=identifier>X</span><span class=special>::</span><span class=identifier>f</span><span class=special>;
</span><span class=keyword>int </span><span class=special>(</span><span class=identifier>X</span><span class=special>::*</span><span class=identifier>fx4</span><span class=special>)(</span><span class=keyword>int</span><span class=special>, </span><span class=keyword>int</span><span class=special>, </span><span class=keyword>int</span><span class=special>) = &amp;</span><span class=identifier>X</span><span class=special>::</span><span class=identifier>f</span><span class=special>;
</span></pre></code>
<p>
With these in hand, we can proceed to define and wrap this for Python:</p>
<code><pre>
<span class=special>.</span><span class=identifier>def</span><span class=special>(</span><span class=string>&quot;f&quot;</span><span class=special>, </span><span class=identifier>fx1</span><span class=special>)
.</span><span class=identifier>def</span><span class=special>(</span><span class=string>&quot;f&quot;</span><span class=special>, </span><span class=identifier>fx2</span><span class=special>)
.</span><span class=identifier>def</span><span class=special>(</span><span class=string>&quot;f&quot;</span><span class=special>, </span><span class=identifier>fx3</span><span class=special>)
.</span><span class=identifier>def</span><span class=special>(</span><span class=string>&quot;f&quot;</span><span class=special>, </span><span class=identifier>fx4</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="call_policies.html"><img src="theme/l_arr.gif" border="0"></a></td>
<td width="20"><a href="default_arguments.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

@@ -1,79 +0,0 @@
<html>
<head>
<!-- Generated by the Spirit (http://spirit.sf.net) QuickDoc -->
<title>QuickStart</title>
<link rel="stylesheet" href="theme/style.css" type="text/css">
<link rel="next" href="building_hello_world.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>QuickStart</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"><img src="theme/l_arr_disabled.gif" border="0"></td>
<td width="20"><a href="building_hello_world.html"><img src="theme/r_arr.gif" border="0"></a></td>
</tr>
</table>
<p>
The Boost Python Library is a framework for interfacing Python and
C++. It allows you to quickly and seamlessly expose C++ classes
functions and objects to Python, and vice-versa, using no special
tools -- just your C++ compiler. It is designed to wrap C++ interfaces
non-intrusively, so that you should not have to change the C++ code at
all in order to wrap it, making Boost.Python ideal for exposing
3rd-party libraries to Python. The library's use of advanced
metaprogramming techniques simplifies its syntax for users, so that
wrapping code takes on the look of a kind of declarative interface
definition language (IDL).</p>
<a name="hello_world"></a><h2>Hello World</h2><p>
Following C/C++ tradition, let's start with the &quot;hello, world&quot;. A C++
Function:</p>
<code><pre>
<span class=keyword>char </span><span class=keyword>const</span><span class=special>* </span><span class=identifier>greet</span><span class=special>()
{
</span><span class=keyword>return </span><span class=string>&quot;hello, world&quot;</span><span class=special>;
}
</span></pre></code>
<p>
can be exposed to Python by writing a Boost.Python wrapper:</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=keyword>using </span><span class=keyword>namespace </span><span class=identifier>boost</span><span class=special>::</span><span class=identifier>python</span><span class=special>;
</span><span class=identifier>BOOST_PYTHON_MODULE</span><span class=special>(</span><span class=identifier>hello</span><span class=special>)
{
</span><span class=identifier>def</span><span class=special>(</span><span class=string>&quot;greet&quot;</span><span class=special>, </span><span class=identifier>greet</span><span class=special>);
}
</span></pre></code>
<p>
That's it. We're done. We can now build this as a shared library. The
resulting DLL is now visible to Python. Here's a sample Python session:</p>
<code><pre>
<span class=special>&gt;&gt;&gt; </span><span class=identifier>import </span><span class=identifier>hello
</span><span class=special>&gt;&gt;&gt; </span><span class=identifier>print </span><span class=identifier>hello</span><span class=special>.</span><span class=identifier>greet</span><span class=special>()
</span><span class=identifier>hello</span><span class=special>, </span><span class=identifier>world
</span></pre></code>
<blockquote><p><i><b>Next stop... Building your Hello World module from start to finish...</b></i></p></blockquote><table border="0">
<tr>
<td width="30"><a href="../index.html"><img src="theme/u_arr.gif" border="0"></a></td>
<td width="30"><img src="theme/l_arr_disabled.gif" border="0"></td>
<td width="20"><a href="building_hello_world.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>

Binary file not shown.

Before

Width:  |  Height:  |  Size: 577 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 70 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.3 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.5 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 944 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 152 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 8.6 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 147 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 91 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 897 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 151 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 147 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 91 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 879 B

View File

@@ -1,170 +0,0 @@
body
{
background-image: url(bkd.gif);
background-color: #FFFFFF;
margin: 1em 2em 1em 2em;
}
h1 { font-family: Verdana, Arial, Helvetica, sans-serif; font-weight: bold; text-align: left; }
h2 { font: 140% sans-serif; font-weight: bold; text-align: left; }
h3 { font: 120% sans-serif; font-weight: bold; text-align: left; }
h4 { font: bold 100% sans-serif; font-weight: bold; text-align: left; }
h5 { font: italic 100% sans-serif; font-weight: bold; text-align: left; }
h6 { font: small-caps 100% sans-serif; font-weight: bold; text-align: left; }
pre
{
border-top: gray 1pt solid;
border-right: gray 1pt solid;
border-left: gray 1pt solid;
border-bottom: gray 1pt solid;
padding-top: 2pt;
padding-right: 2pt;
padding-left: 2pt;
padding-bottom: 2pt;
display: block;
font-family: "courier new", courier, mono;
background-color: #eeeeee; font-size: small
}
code
{
font-family: "Courier New", Courier, mono;
font-size: small
}
tt
{
display: inline;
font-family: "Courier New", Courier, mono;
color: #000099;
font-size: small
}
p
{
text-align: justify;
font-family: Georgia, "Times New Roman", Times, serif
}
ul
{
list-style-image: url(bullet.gif);
font-family: Georgia, "Times New Roman", Times, serif
}
ol
{
font-family: Georgia, "Times New Roman", Times, serif
}
a
{
font-weight: bold;
color: #003366;
text-decoration: none;
}
a:hover { color: #8080FF; }
.literal { color: #666666; font-style: italic}
.keyword { color: #000099}
.identifier {}
.comment { font-style: italic; color: #990000}
.special { color: #800040}
.preprocessor { color: #FF0000}
.string { font-style: italic; color: #666666}
.copyright { color: #666666; font-size: small}
.white_bkd { background-color: #FFFFFF}
.dk_grey_bkd { background-color: #999999}
.quotes { color: #666666; font-style: italic; font-weight: bold}
.note_box
{
display: block;
border-top: gray 1pt solid;
border-right: gray 1pt solid;
border-left: gray 1pt solid;
border-bottom: gray 1pt solid;
padding-right: 12pt;
padding-left: 12pt;
padding-bottom: 12pt;
padding-top: 12pt;
font-family: Arial, Helvetica, sans-serif;
background-color: #E2E9EF;
font-size: small; text-align: justify
}
.table_title
{
background-color: #648CCA;
font-family: Verdana, Arial, Helvetica, sans-serif; color: #FFFFFF;
font-weight: bold
; padding-top: 4px; padding-right: 4px; padding-bottom: 4px; padding-left: 4px
}
.table_cells
{
background-color: #E2E9EF;
font-family: Geneva, Arial, Helvetica, san-serif;
font-size: small
; padding-top: 4px; padding-right: 4px; padding-bottom: 4px; padding-left: 4px
}
.toc
{
DISPLAY: block;
background-color: #E2E9EF
font-family: Arial, Helvetica, sans-serif;
border-top: gray 1pt solid;
border-left: gray 1pt solid;
border-bottom: gray 1pt solid;
border-right: gray 1pt solid;
padding-top: 24pt;
padding-right: 24pt;
padding-left: 24pt;
padding-bottom: 24pt;
}
.toc_title
{
background-color: #648CCA;
padding-top: 4px;
padding-right: 4px;
padding-bottom: 4px;
padding-left: 4px;
font-family: Geneva, Arial, Helvetica, san-serif;
color: #FFFFFF;
font-weight: bold
}
.toc_cells
{
background-color: #E2E9EF;
padding-top: 4px;
padding-right: 4px;
padding-bottom: 4px;
padding-left: 4px;
font-family: Geneva, Arial, Helvetica, san-serif;
font-size: small
}
div.logo
{
float: right;
}
.toc_cells_L0 { background-color: #E2E9EF; padding-top: 4px; padding-right: 4px; padding-bottom: 4px; padding-left: 4px; font-family: Geneva, Arial, Helvetica, san-serif; font-size: small }
.toc_cells_L1 { background-color: #E2E9EF; padding-top: 4px; padding-right: 4px; padding-bottom: 4px; padding-left: 44px; font-family: Geneva, Arial, Helvetica, san-serif; font-size: small }
.toc_cells_L2 { background-color: #E2E9EF; padding-top: 4px; padding-right: 4px; padding-bottom: 4px; padding-left: 88px; font-family: Geneva, Arial, Helvetica, san-serif; font-size: small }
.toc_cells_L3 { background-color: #E2E9EF; padding-top: 4px; padding-right: 4px; padding-bottom: 4px; padding-left: 122px; font-family: Geneva, Arial, Helvetica, san-serif; font-size: small }
.toc_cells_L4 { background-color: #E2E9EF; padding-top: 4px; padding-right: 4px; padding-bottom: 4px; padding-left: 166px; font-family: Geneva, Arial, Helvetica, san-serif; font-size: small }

Binary file not shown.

Before

Width:  |  Height:  |  Size: 170 B

View File

@@ -1,238 +0,0 @@
<html>
<head>
<!-- Generated by the Spirit (http://spirit.sf.net) QuickDoc -->
<title>Using the interpreter</title>
<link rel="stylesheet" href="theme/style.css" type="text/css">
<link rel="prev" href="embedding.html">
<link rel="next" href="iterators.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>Using the interpreter</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="embedding.html"><img src="theme/l_arr.gif" border="0"></a></td>
<td width="20"><a href="iterators.html"><img src="theme/r_arr.gif" border="0"></a></td>
</tr>
</table>
<p>
As you probably already know, objects in Python are reference-counted.
Naturally, the <tt>PyObject</tt>s of the Python/C API are also reference-counted.
There is a difference however. While the reference-counting is fully
automatic in Python, the Python/C API requires you to do it
<a href="http://www.python.org/doc/current/api/refcounts.html">
by hand</a>. This is
messy and especially hard to get right in the presence of C++ exceptions.
Fortunately Boost.Python provides the <a href="../../v2/handle.html">
handle</a> class
template to automate the process.</p>
<a name="reference_counting_handles"></a><h2>Reference-counting handles</h2><p>
There are two ways in which a function in the Python/C API can return a
<tt>PyObject*</tt>: as a <i>borrowed reference</i> or as a <i>new reference</i>. Which of
these a function uses, is listed in that function's documentation. The two
require slightely different approaches to reference-counting but both can
be 'handled' by Boost.Python.</p>
<p>
For a function returning a <i>borrowed reference</i> we'll have to tell the
<tt>handle</tt> that the <tt>PyObject*</tt> is borrowed with the aptly named
<a href="../../v2/handle.html#borrowed-spec">
borrowed</a> function. Two functions
returning borrowed references are <a href="http://www.python.org/doc/current/api/importing.html#l2h-125">
PyImport_AddModule</a> and <a href="http://www.python.org/doc/current/api/moduleObjects.html#l2h-594">
PyModule_GetDict</a>.
The former returns a reference to an already imported module, the latter
retrieves a module's namespace dictionary. Let's use them to retrieve the
namespace of the <tt>__main__</tt> module:</p>
<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>handle</span><span class=special>&lt;&gt; </span><span class=identifier>main_namespace</span><span class=special>(</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></pre></code>
<p>
Because the Python/C API doesn't know anything about <tt>handle</tt>s, we used
the <a href="../../v2/handle.html#handle-spec-observers">
get</a> member function to
retrieve the <tt>PyObject*</tt> from which the <tt>handle</tt> was constructed.</p>
<p>
For a function returning a <i>new reference</i> we can just create a <tt>handle</tt>
out of the raw <tt>PyObject*</tt> without wrapping it in a call to borrowed. One
such function that returns a new reference is <a href="http://www.python.org/doc/current/api/veryhigh.html#l2h-55">
PyRun_String</a> which we'll
discuss in the next section.</p>
<table width="80%" border="0" align="center">
<tr>
<td class="note_box">
<img src="theme/lens.gif"></img> <b>Handle is a class <i>template</i>, so why haven't we been using any template parameters?</b><br>
<br>
<tt>handle</tt> has a single template parameter specifying the type of the managed object. This type is <tt>PyObject</tt> 99% of the time, so the parameter was defaulted to <tt>PyObject</tt> for convenience. Therefore we can use the shorthand <tt>handle&lt;&gt;</tt> instead of the longer, but equivalent, <tt>handle&lt;PyObject&gt;</tt>.
</td>
</tr>
</table>
<a name="running_python_code"></a><h2>Running Python code</h2><p>
To run Python code from C++ there is a family of functions in the API
starting with the PyRun prefix. You can find the full list of these
functions <a href="http://www.python.org/doc/current/api/veryhigh.html">
here</a>. They
all work similarly so we will look at only one of them, namely:</p>
<code><pre>
<span class=identifier>PyObject</span><span class=special>* </span><span class=identifier>PyRun_String</span><span class=special>(</span><span class=keyword>char </span><span class=special>*</span><span class=identifier>str</span><span class=special>, </span><span class=keyword>int </span><span class=identifier>start</span><span class=special>, </span><span class=identifier>PyObject </span><span class=special>*</span><span class=identifier>globals</span><span class=special>, </span><span class=identifier>PyObject </span><span class=special>*</span><span class=identifier>locals</span><span class=special>)
</span></pre></code>
<p>
<a href="http://www.python.org/doc/current/api/veryhigh.html#l2h-55">
PyRun_String</a> takes the code to execute as a null-terminated (C-style)
string in its <tt>str</tt> parameter. The function returns a new reference to a
Python object. Which object is returned depends on the <tt>start</tt> paramater.</p>
<p>
The <tt>start</tt> parameter is the start symbol from the Python grammar to use
for interpreting the code. The possible values are:</p>
<table width="90%" border="0" align="center"> <tr>
<td class="table_title" colspan="6">
Start symbols </td>
</tr>
<tr><tr><td class="table_cells"><a href="http://www.python.org/doc/current/api/veryhigh.html#l2h-58">
Py_eval_input</a></td><td class="table_cells">for interpreting isolated expressions</td></tr><td class="table_cells"><a href="http://www.python.org/doc/current/api/veryhigh.html#l2h-59">
Py_file_input</a></td><td class="table_cells">for interpreting sequences of statements</td></tr><td class="table_cells"><a href="http://www.python.org/doc/current/api/veryhigh.html#l2h-60">
Py_single_input</a></td><td class="table_cells">for interpreting a single statement</td></tr></table>
<p>
When using <a href="http://www.python.org/doc/current/api/veryhigh.html#l2h-58">
Py_eval_input</a>, the input string must contain a single expression
and its result is returned. When using <a href="http://www.python.org/doc/current/api/veryhigh.html#l2h-59">
Py_file_input</a>, the string can
contain an abitrary number of statements and None is returned.
<a href="http://www.python.org/doc/current/api/veryhigh.html#l2h-60">
Py_single_input</a> works in the same way as <a href="http://www.python.org/doc/current/api/veryhigh.html#l2h-59">
Py_file_input</a> but only accepts a
single statement.</p>
<p>
Lastly, the <tt>globals</tt> and <tt>locals</tt> parameters are Python dictionaries
containing the globals and locals of the context in which to run the code.
For most intents and purposes you can use the namespace dictionary of the
<tt>__main__</tt> module for both parameters.</p>
<p>
We have already seen how to get the <tt>__main__</tt> module's namespace so let's
run some Python code in it:</p>
<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>handle</span><span class=special>&lt;&gt; </span><span class=identifier>main_namespace</span><span class=special>(</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;hello = file('hello.txt', 'w')\n&quot;
</span><span class=string>&quot;hello.write('Hello world!')\n&quot;
</span><span class=string>&quot;hello.close()&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>get</span><span class=special>(), </span><span class=identifier>main_namespace</span><span class=special>.</span><span class=identifier>get</span><span class=special>()) );
</span></pre></code>
<p>
This should create a file called 'hello.txt' in the current directory
containing a phrase that is well-known in programming circles.</p>
<p>
<img src="theme/note.gif"></img> <b>Note</b> that we wrap the return value of <a href="http://www.python.org/doc/current/api/veryhigh.html#l2h-55">
PyRun_String</a> in a
(nameless) <tt>handle</tt> even though we are not interested in it. If we didn't
do this, the the returned object would be kept alive unnecessarily. Unless
you want to be a Dr. Frankenstein, always wrap <tt>PyObject*</tt>s in <tt>handle</tt>s.</p>
<a name="beyond_handles"></a><h2>Beyond handles</h2><p>
It's nice that <tt>handle</tt> manages the reference counting details for us, but
other than that it doesn't do much. Often we'd like to have a more useful
class to manipulate Python objects. But we have already seen such a class
in the <a href="object_interface.html">
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>
<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>
<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
the dictionary. Another way to achieve the same result is to let
<a href="http://www.python.org/doc/current/api/veryhigh.html#l2h-55">
PyRun_String</a> return the result directly with <a href="http://www.python.org/doc/current/api/veryhigh.html#l2h-58">
Py_eval_input</a>:</p>
<code><pre>
<span class=identifier>object </span><span class=identifier>result</span><span class=special>(</span><span class=identifier>handle</span><span class=special>&lt;&gt;( </span><span class=identifier>PyRun_String</span><span class=special>(</span><span class=string>&quot;5 ** 2&quot;</span><span class=special>, </span><span class=identifier>Py_eval_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>result</span><span class=special>);
</span></pre></code>
<p>
<img src="theme/note.gif"></img> <b>Note</b> that <tt>object</tt>'s member function to return the wrapped
<tt>PyObject*</tt> is called <tt>ptr</tt> instead of <tt>get</tt>. This makes sense if you
take into account the different functions that <tt>object</tt> and <tt>handle</tt>
perform.</p>
<a name="exception_handling"></a><h2>Exception handling</h2><p>
If an exception occurs in the execution of some Python code, the <a href="http://www.python.org/doc/current/api/veryhigh.html#l2h-55">
PyRun_String</a> function returns a null pointer. Constructing a <tt>handle</tt> out of this null pointer throws <a href="../../v2/errors.html#error_already_set-spec">
error_already_set</a>, so basically, the Python exception is automatically translated into a C++ exception when using <tt>handle</tt>:</p>
<code><pre>
<span class=keyword>try
</span><span class=special>{
</span><span class=identifier>object </span><span class=identifier>result</span><span class=special>(</span><span class=identifier>handle</span><span class=special>&lt;&gt;( </span><span class=identifier>PyRun_String</span><span class=special>(</span><span class=string>&quot;5/0&quot;</span><span class=special>, </span><span class=identifier>Py_eval_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=identifier>execution </span><span class=identifier>will </span><span class=identifier>never </span><span class=identifier>get </span><span class=identifier>here</span><span class=special>:
</span><span class=keyword>int </span><span class=identifier>five_divided_by_zero </span><span class=special>= </span><span class=identifier>extract</span><span class=special>&lt;</span><span class=keyword>int</span><span class=special>&gt;(</span><span class=identifier>result</span><span class=special>);
}
</span><span class=keyword>catch</span><span class=special>(</span><span class=identifier>error_already_set</span><span class=special>)
{
// </span><span class=identifier>handle </span><span class=identifier>the </span><span class=identifier>exception </span><span class=identifier>in </span><span class=identifier>some </span><span class=identifier>way
</span><span class=special>}
</span></pre></code>
<p>
The <tt>error_already_set</tt> exception class doesn't carry any information in itself. To find out more about the Python exception that occurred, you need to use the <a href="http://www.python.org/doc/api/exceptionHandling.html">
exception handling functions</a> of the Python/C API in your catch-statement. This can be as simple as calling <a href="http://www.python.org/doc/api/exceptionHandling.html#l2h-70">
PyErr_Print()</a> to print the exception's traceback to the console, or comparing the type of the exception with those of the <a href="http://www.python.org/doc/api/standardExceptions.html">
standard exceptions</a>:</p>
<code><pre>
<span class=keyword>catch</span><span class=special>(</span><span class=identifier>error_already_set</span><span class=special>)
{
</span><span class=keyword>if </span><span class=special>(</span><span class=identifier>PyErr_ExceptionMatches</span><span class=special>(</span><span class=identifier>PyExc_ZeroDivisionError</span><span class=special>))
{
// </span><span class=identifier>handle </span><span class=identifier>ZeroDivisionError </span><span class=identifier>specially
</span><span class=special>}
</span><span class=keyword>else
</span><span class=special>{
// </span><span class=identifier>print </span><span class=identifier>all </span><span class=identifier>other </span><span class=identifier>errors </span><span class=identifier>to </span><span class=identifier>stderr
</span><span class=identifier>PyErr_Print</span><span class=special>();
}
}
</span></pre></code>
<p>
(To retrieve even more information from the exception you can use some of the other exception handling functions listed <a href="http://www.python.org/doc/api/exceptionHandling.html">
here</a>.)</p>
<p>
If you'd rather not have <tt>handle</tt> throw a C++ exception when it is constructed, you can use the <a href="../../v2/handle.html#allow_null-spec">
allow_null</a> function in the same way you'd use borrowed:</p>
<code><pre>
<span class=identifier>handle</span><span class=special>&lt;&gt; </span><span class=identifier>result</span><span class=special>(</span><span class=identifier>allow_null</span><span class=special>( </span><span class=identifier>PyRun_String</span><span class=special>(</span><span class=string>&quot;5/0&quot;</span><span class=special>, </span><span class=identifier>Py_eval_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>if </span><span class=special>(!</span><span class=identifier>result</span><span class=special>)
// </span><span class=identifier>Python </span><span class=identifier>exception </span><span class=identifier>occurred
</span><span class=keyword>else
</span><span class=comment>// everything went okay, it's safe to use the result
</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="embedding.html"><img src="theme/l_arr.gif" border="0"></a></td>
<td width="20"><a href="iterators.html"><img src="theme/r_arr.gif" border="0"></a></td>
</tr>
</table>
<br>
<hr size="1"><p class="copyright">Copyright &copy; 2002-2003 Dirk Gerrits<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

@@ -1,122 +0,0 @@
<html>
<head>
<!-- Generated by the Spirit (http://spirit.sf.net) QuickDoc -->
<title>Virtual Functions with Default Implementations</title>
<link rel="stylesheet" href="theme/style.css" type="text/css">
<link rel="prev" href="deriving_a_python_class.html">
<link rel="next" href="class_operators_special_functions.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>Virtual Functions with Default Implementations</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="deriving_a_python_class.html"><img src="theme/l_arr.gif" border="0"></a></td>
<td width="20"><a href="class_operators_special_functions.html"><img src="theme/r_arr.gif" border="0"></a></td>
</tr>
</table>
<p>
Recall that in the <a href="class_virtual_functions.html">
previous section</a>, we
wrapped a class with a pure virtual function that we then implemented in
C++ or Python classes derived from it. Our base class:</p>
<code><pre>
<span class=keyword>struct </span><span class=identifier>Base
</span><span class=special>{
</span><span class=keyword>virtual </span><span class=keyword>int </span><span class=identifier>f</span><span class=special>() = </span><span class=number>0</span><span class=special>;
};
</span></pre></code>
<p>
had a pure virtual function <tt>f</tt>. If, however, its member function <tt>f</tt> was
not declared as pure virtual:</p>
<code><pre>
<span class=keyword>struct </span><span class=identifier>Base
</span><span class=special>{
</span><span class=keyword>virtual </span><span class=keyword>int </span><span class=identifier>f</span><span class=special>() { </span><span class=keyword>return </span><span class=number>0</span><span class=special>; }
};
</span></pre></code>
<p>
and instead had a default implementation that returns <tt>0</tt>, as shown above,
we need to add a forwarding function that calls the <tt>Base</tt> default virtual
function <tt>f</tt> implementation:</p>
<code><pre>
<span class=keyword>struct </span><span class=identifier>BaseWrap </span><span class=special>: </span><span class=identifier>Base
</span><span class=special>{
</span><span class=identifier>BaseWrap</span><span class=special>(</span><span class=identifier>PyObject</span><span class=special>* </span><span class=identifier>self_</span><span class=special>)
: </span><span class=identifier>self</span><span class=special>(</span><span class=identifier>self_</span><span class=special>) {}
</span><span class=keyword>int </span><span class=identifier>f</span><span class=special>() { </span><span class=keyword>return </span><span class=identifier>call_method</span><span class=special>&lt;</span><span class=keyword>int</span><span class=special>&gt;(</span><span class=identifier>self</span><span class=special>, </span><span class=string>&quot;f&quot;</span><span class=special>); }
</span><span class=keyword>int </span><span class=identifier>default_f</span><span class=special>() { </span><span class=keyword>return </span><span class=identifier>Base</span><span class=special>::</span><span class=identifier>f</span><span class=special>(); } // &lt;&lt;=== ***</span><span class=identifier>ADDED</span><span class=special>***
</span><span class=identifier>PyObject</span><span class=special>* </span><span class=identifier>self</span><span class=special>;
};
</span></pre></code>
<p>
Then, Boost.Python needs to keep track of 1) the dispatch function <tt>f</tt> and
2) the forwarding function to its default implementation <tt>default_f</tt>.
There's a special <tt>def</tt> function for this purpose. Here's how it is
applied to our example above:</p>
<code><pre>
<span class=identifier>class_</span><span class=special>&lt;</span><span class=identifier>Base</span><span class=special>, </span><span class=identifier>BaseWrap</span><span class=special>&gt;(</span><span class=string>&quot;Base&quot;</span><span class=special>)
.</span><span class=identifier>def</span><span class=special>(</span><span class=string>&quot;f&quot;</span><span class=special>, &amp;</span><span class=identifier>Base</span><span class=special>::</span><span class=identifier>f</span><span class=special>, &amp;</span><span class=identifier>BaseWrap</span><span class=special>::</span><span class=identifier>default_f</span><span class=special>)
</span></pre></code>
<p>
Note that we are allowing <tt>Base</tt> objects to be instantiated this time,
unlike before where we specifically defined the <tt>class_&lt;Base&gt;</tt> with
<tt>no_init</tt>.</p>
<p>
In Python, the results would be as expected:</p>
<code><pre>
<span class=special>&gt;&gt;&gt; </span><span class=identifier>base </span><span class=special>= </span><span class=identifier>Base</span><span class=special>()
&gt;&gt;&gt; </span><span class=keyword>class </span><span class=identifier>Derived</span><span class=special>(</span><span class=identifier>Base</span><span class=special>):
... </span><span class=identifier>def </span><span class=identifier>f</span><span class=special>(</span><span class=identifier>self</span><span class=special>):
... </span><span class=keyword>return </span><span class=number>42
</span><span class=special>...
&gt;&gt;&gt; </span><span class=identifier>derived </span><span class=special>= </span><span class=identifier>Derived</span><span class=special>()
</span></pre></code>
<p>
Calling <tt>base.f()</tt>:</p>
<code><pre>
<span class=special>&gt;&gt;&gt; </span><span class=identifier>base</span><span class=special>.</span><span class=identifier>f</span><span class=special>()
</span><span class=number>0
</span></pre></code>
<p>
Calling <tt>derived.f()</tt>:</p>
<code><pre>
<span class=special>&gt;&gt;&gt; </span><span class=identifier>derived</span><span class=special>.</span><span class=identifier>f</span><span class=special>()
</span><span class=number>42
</span></pre></code>
<p>
Calling <tt>call_f</tt>, passing in a <tt>base</tt> object:</p>
<code><pre>
<span class=special>&gt;&gt;&gt; </span><span class=identifier>call_f</span><span class=special>(</span><span class=identifier>base</span><span class=special>)
</span><span class=number>0
</span></pre></code>
<p>
Calling <tt>call_f</tt>, passing in a <tt>derived</tt> object:</p>
<code><pre>
<span class=special>&gt;&gt;&gt; </span><span class=identifier>call_f</span><span class=special>(</span><span class=identifier>derived</span><span class=special>)
</span><span class=number>42
</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="deriving_a_python_class.html"><img src="theme/l_arr.gif" border="0"></a></td>
<td width="20"><a href="class_operators_special_functions.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

@@ -1,156 +1,18 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<!-- Copyright David Abrahams 2006. Distributed under the Boost -->
<!-- Software License, Version 1.0. (See accompanying -->
<!-- file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -->
<html>
<head>
<!-- Generated by the Spirit (http://spirit.sf.net) QuickDoc -->
<title>Boost Python Tutorial</title>
<link rel="stylesheet" href="doc/theme/style.css" type="text/css">
<link rel="next" href="quickstart.html">
</head>
<body>
<table width="100%" height="48" border="0" cellspacing="2">
<tr>
<td><img src="doc/theme/c%2B%2Bboost.gif">
</td>
<td width="85%">
<font size="6" face="Verdana, Arial, Helvetica, sans-serif"><b>Boost Python Tutorial</b></font>
</td>
</tr>
</table>
<br>
<table width="80%" border="0" align="center">
<tr>
<td class="toc_title">Table of contents</td>
</tr>
<tr>
<td class="toc_cells_L0">
<a href="doc/quickstart.html">QuickStart</a>
</td>
</tr>
<tr>
<td class="toc_cells_L0">
<a href="doc/building_hello_world.html">Building Hello World</a>
</td>
</tr>
<tr>
<td class="toc_cells_L0">
<a href="doc/exposing_classes.html">Exposing Classes</a>
</td>
</tr>
<tr>
<td class="toc_cells_L1">
<a href="doc/constructors.html">Constructors</a>
</td>
</tr>
<tr>
<td class="toc_cells_L1">
<a href="doc/class_data_members.html">Class Data Members</a>
</td>
</tr>
<tr>
<td class="toc_cells_L1">
<a href="doc/class_properties.html">Class Properties</a>
</td>
</tr>
<tr>
<td class="toc_cells_L1">
<a href="doc/inheritance.html">Inheritance</a>
</td>
</tr>
<tr>
<td class="toc_cells_L1">
<a href="doc/class_virtual_functions.html">Class Virtual Functions</a>
</td>
</tr>
<tr>
<td class="toc_cells_L1">
<a href="doc/deriving_a_python_class.html">Deriving a Python Class</a>
</td>
</tr>
<tr>
<td class="toc_cells_L1">
<a href="doc/virtual_functions_with_default_implementations.html">Virtual Functions with Default Implementations</a>
</td>
</tr>
<tr>
<td class="toc_cells_L1">
<a href="doc/class_operators_special_functions.html">Class Operators/Special Functions</a>
</td>
</tr>
<tr>
<td class="toc_cells_L0">
<a href="doc/functions.html">Functions</a>
</td>
</tr>
<tr>
<td class="toc_cells_L1">
<a href="doc/call_policies.html">Call Policies</a>
</td>
</tr>
<tr>
<td class="toc_cells_L1">
<a href="doc/overloading.html">Overloading</a>
</td>
</tr>
<tr>
<td class="toc_cells_L1">
<a href="doc/default_arguments.html">Default Arguments</a>
</td>
</tr>
<tr>
<td class="toc_cells_L1">
<a href="doc/auto_overloading.html">Auto-Overloading</a>
</td>
</tr>
<tr>
<td class="toc_cells_L0">
<a href="doc/object_interface.html">Object Interface</a>
</td>
</tr>
<tr>
<td class="toc_cells_L1">
<a href="doc/basic_interface.html">Basic Interface</a>
</td>
</tr>
<tr>
<td class="toc_cells_L1">
<a href="doc/derived_object_types.html">Derived Object types</a>
</td>
</tr>
<tr>
<td class="toc_cells_L1">
<a href="doc/extracting_c___objects.html">Extracting C++ objects</a>
</td>
</tr>
<tr>
<td class="toc_cells_L1">
<a href="doc/enums.html">Enums</a>
</td>
</tr>
<tr>
<td class="toc_cells_L0">
<a href="doc/embedding.html">Embedding</a>
</td>
</tr>
<tr>
<td class="toc_cells_L1">
<a href="doc/using_the_interpreter.html">Using the interpreter</a>
</td>
</tr>
<tr>
<td class="toc_cells_L0">
<a href="doc/iterators.html">Iterators</a>
</td>
</tr>
<tr>
<td class="toc_cells_L0">
<a href="doc/exception_translation.html">Exception Translation</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>
<head>
<meta http-equiv="refresh" content="0; URL=doc/html/index.html">
</head>
<body>
Automatic redirection failed, click this
<a href="doc/html/index.html">link</a> &nbsp;<hr>
<p>© Copyright Beman Dawes, 2001</p>
<p>Distributed under the Boost Software License, Version 1.0. (See
accompanying file <a href="../../../../LICENSE_1_0.txt">
LICENSE_1_0.txt</a> or copy at
<a href="http://www.boost.org/LICENSE_1_0.txt">www.boost.org/LICENSE_1_0.txt</a>)</p>
</body>
</html>

View File

@@ -1,3 +1,6 @@
<!-- Copyright David Abrahams 2006. Distributed under the Boost -->
<!-- Software License, Version 1.0. (See accompanying -->
<!-- file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -->
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
@@ -10,7 +13,7 @@
<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>
"C++ Boost" src="../../../../boost.png" border="0"></a></h3>
</td>
<td valign="top">
<h1 align="center"><a href="../index.html">Boost.Python</a></h1>
@@ -45,7 +48,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
@@ -157,7 +160,7 @@ documentation).
13 November, 2002
<!--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="http://www.boost.org/people/dave_abrahams.htm">Dave Abrahams</a>
2002. </i></p>
</body>
</html>

View File

@@ -1,11 +1,14 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<!-- Copyright David Abrahams 2006. Distributed under the Boost -->
<!-- Software License, Version 1.0. (See accompanying -->
<!-- file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -->
<html>
<head>
<meta name="generator" content=
"HTML Tidy for Windows (vers 1st August 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>
<link rel="stylesheet" type="text/css" href="../../../../boost.css">
<title>Boost.Python - CallPolicies Concept</title>
</head>
@@ -16,7 +19,7 @@
<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>
alt="C++ Boost" src="../../../../boost.png" border="0"></a></h3>
</td>
<td valign="top">
@@ -57,6 +60,7 @@
<li><code>postcall</code> - Python argument tuple and result management
after the wrapped object is invoked</li>
<li><code>extract_return_type</code> - metafunction for extracting the return type from a given signature type sequence</li>
</ol>
<h2><a name="composition"></a>CallPolicies Composition</h2>
@@ -113,7 +117,7 @@
"ResultConverter.html#ResultConverterGenerator-concept">ResultConverterGenerator</a>.</td>
<td>An MPL unary <a href=
"../../../mpl/doc/paper/html/usage.html#metafunctions.classes">Metafunction
"../../../mpl/doc/refmanual/metafunction-class.html">Metafunction
Class</a> used produce the "preliminary" result object.</td>
</tr>
@@ -129,7 +133,16 @@
reference count must be decremented; if another existing object is
returned, its reference count must be incremented.</td>
</tr>
</table>
<tr>
<td valign="top"><code>P::extract_return_type</code></td>
<td>A model of <a href=
"../../../mpl/doc/refmanual/metafunction.html">Metafunction</a>.</td>
<td>An MPL unary <a href=
"../../../mpl/doc/refmanual/metafunction.html">Metafunction</a> used extract the return type from a given signature. By default it is derived from mpl::front.</td>
</tr>
</table>
Models of CallPolicies are required to be <a href=
"../../../utility/CopyConstructible.html">CopyConstructible</a>.
<hr>
@@ -141,8 +154,7 @@
</p>
<p><i>&copy; Copyright <a href=
"../../../../people/dave_abrahams.htm">Dave Abrahams</a> 2002. All Rights
Reserved.</i></p>
"http://www.boost.org/people/dave_abrahams.htm">Dave Abrahams</a> 2002.</i></p>
<p>Permission to copy, use, modify, sell and distribute this software is
granted provided this copyright notice appears in all copies. This

View File

@@ -1,7 +1,10 @@
<!-- Copyright David Abrahams 2006. Distributed under the Boost -->
<!-- Software License, Version 1.0. (See accompanying -->
<!-- file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -->
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link rel="stylesheet" type="text/css" href=../../../../boost.css>
<link rel="stylesheet" type="text/css" href="../../../../boost.css">
<title>Boost.Python - Dereferenceable Concept</title>
</head>
<body link="#0000ff" vlink="#800080">
@@ -9,7 +12,7 @@
"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>
<h3><a href="../../../../index.htm"><img height="86" width="277" alt="C++ Boost" src="../../../../boost.png" border="0"></a></h3>
</td>
<td valign="top">
<h1 align="center"><a href="../index.html">Boost.Python</a></h1>
@@ -28,50 +31,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>
<p><i>&copy; Copyright <a href="http://www.boost.org/people/dave_abrahams.htm">Dave
Abrahams</a> 2002-2003. </i>
<p>Permission to copy, use, modify, sell
and distribute this software is granted provided this copyright notice appears

11
doc/v2/Extractor.html Executable file → Normal file
View File

@@ -1,7 +1,10 @@
<!-- Copyright David Abrahams 2006. Distributed under the Boost -->
<!-- Software License, Version 1.0. (See accompanying -->
<!-- file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -->
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link rel="stylesheet" type="text/css" href=../../../../boost.css>
<link rel="stylesheet" type="text/css" href="../../../../boost.css">
<title>Boost.Python - Extractor Concept</title>
</head>
<body link="#0000ff" vlink="#800080">
@@ -9,7 +12,7 @@
"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>
<h3><a href="../../../../index.htm"><img height="86" width="277" alt="C++ Boost" src="../../../../boost.png" border="0"></a></h3>
</td>
<td valign="top">
<h1 align="center"><a href="../index.html">Boost.Python</a></h1>
@@ -82,8 +85,8 @@ are layout-compatible with PyObject.
13 November, 2002
<!--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><i>&copy; Copyright <a href="http://www.boost.org/people/dave_abrahams.htm">Dave
Abrahams</a> 2002. </i>
<p>Permission to copy, use, modify, sell
and distribute this software is granted provided this copyright notice appears

11
doc/v2/HolderGenerator.html Executable file → Normal file
View File

@@ -1,7 +1,10 @@
<!-- Copyright David Abrahams 2006. Distributed under the Boost -->
<!-- Software License, Version 1.0. (See accompanying -->
<!-- file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -->
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link rel="stylesheet" type="text/css" href=../../../../boost.css>
<link rel="stylesheet" type="text/css" href="../../../../boost.css">
<title>Boost.Python - Holder Concept</title>
</head>
<body link="#0000ff" vlink="#800080">
@@ -9,7 +12,7 @@
"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>
<h3><a href="../../../../index.htm"><img height="86" width="277" alt="C++ Boost" src="../../../../boost.png" border="0"></a></h3>
</td>
<td valign="top">
<h1 align="center"><a href="../index.html">Boost.Python</a></h1>
@@ -60,8 +63,8 @@ type.
13 November, 2002
<!--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><i>&copy; Copyright <a href="http://www.boost.org/people/dave_abrahams.htm">Dave
Abrahams</a> 2002. </i>
<p>Permission to copy, use, modify, sell
and distribute this software is granted provided this copyright notice appears

View File

@@ -1,3 +1,6 @@
<!-- Copyright David Abrahams 2006. Distributed under the Boost -->
<!-- Software License, Version 1.0. (See accompanying -->
<!-- file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -->
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
@@ -10,7 +13,7 @@
<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>
"C++ Boost" src="../../../../boost.png" border="0"></a></h3>
</td>
<td valign="top">
<h1 align="center"><a href="../index.html">Boost.Python</a></h1>
@@ -220,7 +223,7 @@ you'll just have to wait till next month (hopefully the beginning).
13 November, 2002
<!--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="http://www.boost.org/people/dave_abrahams.htm">Dave Abrahams</a>
2002. </i></p>
</body>
</html>

View File

@@ -1,3 +1,6 @@
<!-- Copyright David Abrahams 2006. Distributed under the Boost -->
<!-- Software License, Version 1.0. (See accompanying -->
<!-- file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -->
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
@@ -10,7 +13,7 @@
<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>
"C++ Boost" src="../../../../boost.png" border="0"></a></h3>
</td>
<td valign="top">
<h1 align="center"><a href="../index.html">Boost.Python</a></h1>
@@ -228,7 +231,7 @@ worth doing anything about it.
13 November, 2002
<!--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="http://www.boost.org/people/dave_abrahams.htm">Dave Abrahams</a>
2002. </i></p>
</body>
</html>

View File

@@ -1,3 +1,6 @@
<!-- Copyright David Abrahams 2006. Distributed under the Boost -->
<!-- Software License, Version 1.0. (See accompanying -->
<!-- file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -->
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
@@ -10,7 +13,7 @@
<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>
"C++ Boost" src="../../../../boost.png" border="0"></a></h3>
</td>
<td valign="top">
<h1 align="center"><a href="../index.html">Boost.Python</a></h1>
@@ -54,7 +57,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 +73,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 +87,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 +157,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 +214,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>
@@ -303,7 +305,7 @@ to these issues will probably have to be formalized before long.
13 November, 2002
<!--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="http://www.boost.org/people/dave_abrahams.htm">Dave Abrahams</a>
2002. </i></p>
</body>
</html>

View File

@@ -1,5 +1,8 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<!-- Copyright David Abrahams 2006. Distributed under the Boost -->
<!-- Software License, Version 1.0. (See accompanying -->
<!-- file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -->
<html>
<head>
<meta name="generator" content=
@@ -16,7 +19,7 @@
<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>
alt="C++ Boost" src="../../../../boost.png" border="0"></a></h3>
</td>
<td valign="top">
@@ -144,13 +147,7 @@ instances of the associated Python type will be considered a match.
</p>
<p><i>&copy; Copyright <a href=
"../../../../people/dave_abrahams.htm">Dave Abrahams</a> 2002. All Rights
Reserved.</i></p>
<p>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.</p>
"http://www.boost.org/people/dave_abrahams.htm">Dave Abrahams</a> 2002.</i></p>
</body>
</html>

View File

@@ -1,7 +1,12 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<!-- Copyright David Abrahams 2006. Distributed under the Boost -->
<!-- Software License, Version 1.0. (See accompanying -->
<!-- file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -->
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link rel="stylesheet" type="text/css" href=../../../../boost.css>
<link rel="stylesheet" type="text/css" href="../../../../boost.css">
<title>Boost.Python - ResultConverter Concept</title>
</head>
<body link="#0000ff" vlink="#800080">
@@ -9,7 +14,7 @@
"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>
<h3><a href="../../../../index.htm"><img height="86" width="277" alt="C++ Boost" src="../../../../boost.png" border="0"></a></h3>
</td>
<td valign="top">
<h1 align="center"><a href="../index.html">Boost.Python</a></h1>
@@ -21,10 +26,12 @@
<dl class="page-index">
<dt><a href="#introduction">Introduction</a></dt>
<dt><a href="#concept-requirements">Concept Requirements</a></dt>
<dl class="page-index">
<dt><a href="#ResultConverter-concept">ResultConverter Concept</a></dt>
<dt><a href="#ResultConverterGenerator-concept">ResultConverterGenerator Concept</a></dt>
</dl>
<dd>
<dl class="page-index">
<dt><a href="#ResultConverter-concept">ResultConverter Concept</a></dt>
<dt><a href="#ResultConverterGenerator-concept">ResultConverterGenerator Concept</a></dt>
</dl>
</dd>
</dl>
<h2><a name="introduction"></a>Introduction</h2>
@@ -76,6 +83,13 @@ denotes an object of type <code><b>R</b></code>.
href="http://www.python.org/doc/current/api/exceptionHandling.html#l2h-71">PyErr_Occurred</a>
should return non-zero.</td>
</tr>
<tr>
<td valign="top"><code>c.get_pytype()</code></td>
<td><code>PyTypeObject const*</code></td>
<td>A pointer to a Python Type object corresponding to result of the conversion,
or <code>0</code>. Used for documentation generation. If <code>0</code> is returned
the generated type in the documentation will be <b>object</b> .</td>
</tr>
</table>
<h3><a name="ResultConverterGenerator-concept"></a>ResultConverterGenerator Concept</h3>
@@ -99,8 +113,8 @@ C++ function return type.
09 May, 2002 <!--Luann's birthday! -->
<!--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><i>&copy; Copyright <a href="http://www.boost.org/people/dave_abrahams.htm">Dave
Abrahams</a> 2002. </i>
<p>Permission to copy, use, modify, sell
and distribute this software is granted provided this copyright notice appears

View File

@@ -1,5 +1,8 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<!-- Copyright David Abrahams 2006. Distributed under the Boost -->
<!-- Software License, Version 1.0. (See accompanying -->
<!-- file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -->
<html>
<head>
<meta name="generator" content=
@@ -16,7 +19,7 @@
<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>
alt="C++ Boost" src="../../../../boost.png" border="0"></a></h3>
</td>
<td valign="top">
@@ -28,7 +31,7 @@
</table>
<hr>
<p><a href="../../../../people/dave_abrahams.htm">Dave Abrahams</a> is
<p><a href="http://www.boost.org/people/dave_abrahams.htm">Dave Abrahams</a> is
the architect, designer, and implementor of <b>Boost.Python</b>.</p>
<p><a href="mailto:brett.calcott@paradise.net.nz">Brett Calcott</a>
@@ -44,7 +47,7 @@
argument support</a> and wrote the excellent <a href=
"../tutorial/index.html">tutorial documentation</a>.</p>
<p><a href="../../../../people/ralf_w_grosse_kunstleve.htm">Ralf W.
<p><a href="http://www.boost.org/people/ralf_w_grosse_kunstleve.htm">Ralf W.
Grosse-Kunstleve</a> implemented the <a href="pickle.html">pickle
support</a>, and has enthusiastically supported the library since its
birth, contributing to design decisions and providing invaluable
@@ -56,15 +59,15 @@
C++ and Python for solving the problems of large-scale software
construction.</p>
<p><a href="../../../../people/aleksey_gurtovoy.htm">Aleksey Gurtovoy</a>
<p><a href="http://www.boost.org/people/aleksey_gurtovoy.htm">Aleksey Gurtovoy</a>
wrote an incredible C++ <a href="http://www.mywikinet.com/mpl">Template
Metaprogramming Library</a> which allows Boost.Python to perform much of
its compile-time magic. In addition, Aleksey very generously contributed
his time and deep knowledge of the quirks of various buggy compilers to
help us get around problems at crucial moments.</p>
<p><a href="../../../../people/paul_mensonides.htm">Paul Mensonides</a>,
building on the work <a href="../../../../people/vesa_karvonen.htm">Vesa
<p><a href="http://www.boost.org/people/paul_mensonides.htm">Paul Mensonides</a>,
building on the work <a href="http://www.boost.org/people/vesa_karvonen.htm">Vesa
Karvonen</a>, wrote a similarly amazing <a href=
"../../../preprocessor/doc/index.html">Preprocessor Metaprogramming
Library</a>, and generously contributed the time and expertise to get it
@@ -72,7 +75,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.
@@ -126,8 +129,7 @@
</p>
<p><i>&copy; Copyright <a href=
"../../../../people/dave_abrahams.htm">Dave Abrahams</a> 2002. All Rights
Reserved.</i></p>
"http://www.boost.org/people/dave_abrahams.htm">Dave Abrahams</a> 2002.</i></p>
</body>
</html>

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