From 8a94c597a050e05940c95822fcc353e3af6c461b Mon Sep 17 00:00:00 2001 From: Joel de Guzman Date: Wed, 9 Oct 2002 14:31:39 +0000 Subject: [PATCH] More tweaks (tutorial) [SVN r15826] --- doc/tutorial/doc/building_hello_world.html | 19 ++++-- doc/tutorial/doc/call_policies.html | 2 +- doc/tutorial/doc/class_data_members.html | 7 +-- doc/tutorial/doc/class_virtual_functions.html | 7 ++- doc/tutorial/doc/constructors.html | 2 +- doc/tutorial/doc/derived_object_types.html | 27 +++++---- doc/tutorial/doc/quickstart.txt | 54 ++++++++++++------ doc/tutorial/doc/theme/jam.png | Bin 0 -> 3884 bytes 8 files changed, 76 insertions(+), 42 deletions(-) create mode 100644 doc/tutorial/doc/theme/jam.png diff --git a/doc/tutorial/doc/building_hello_world.html b/doc/tutorial/doc/building_hello_world.html index 68094b60..8595ea56 100644 --- a/doc/tutorial/doc/building_hello_world.html +++ b/doc/tutorial/doc/building_hello_world.html @@ -36,22 +36,26 @@ building Boost.Python, check out: building.html. After this brief bjam tutorial, we should have built two DLLs:

-This assumes of course that we are running on Windows.

+if you are on Windows, and

+

+if you are on Unix.

The tutorial example can be found in the directory: -/libs/python/example/tutorial. There, you can find:

+libs/python/example/tutorial. There, you can find:

The hello.cpp file is our C++ hello world example. The Jamfile is a minimalist bjam script that builds the DLLs for us.

Before anything else, you should have the bjam executable in your boost -directory. Pre-built Boost.Jam executables are available for some +directory. Pre-built Boost.Jam executables are available for most platforms. For example, a pre-built Microsoft Windows bjam executable can be downloaded here. The complete list of bjam pre-built executables can be found here.

Lets Jam!

+

+

Here is our minimalist Jamfile:

     subproject libs/python/example/tutorial ;
@@ -99,8 +103,9 @@ Python modules. Example:

The above assumes that the Python installation is in c:/dev/tools/python -and that we are using Python version 2.2. Be sure not to include a third -number, e.g. not "2.2.1", even if that's the version you have.

+and that we are using Python version 2.2. You'll have to tweak this path +appropriately. Be sure not to include a third number, e.g. not "2.2.1", +even if that's the version you have.

Now we are ready... Be sure to cd to libs/python/example/tutorial where the tutorial "hello.cpp" and the "Jamfile" is situated.

@@ -139,6 +144,10 @@ And so on... Finally:

If all is well, you should now have:

+if you are on Windows, and

+

+if you are on Unix.

+

boost_python.dll can be found somewhere in libs\python\build\bin while hello.pyd can be found somewhere in libs\python\example\tutorial\bin. After a successful build, you can just diff --git a/doc/tutorial/doc/call_policies.html b/doc/tutorial/doc/call_policies.html index f0decf84..194097df 100644 --- a/doc/tutorial/doc/call_policies.html +++ b/doc/tutorial/doc/call_policies.html @@ -142,7 +142,7 @@ or more policies can be composed by chaining. Here's the general syntax:

Here is the list of predefined call policies. A complete reference detailing -these can be found +these can be found here.

diff --git a/doc/tutorial/doc/class_data_members.html b/doc/tutorial/doc/class_data_members.html index 4718880c..39847ba8 100644 --- a/doc/tutorial/doc/class_data_members.html +++ b/doc/tutorial/doc/class_data_members.html @@ -56,12 +56,11 @@ Then, in Python:

Note that name is exposed as read-only while value is exposed as read-write.

-    >>> x.name = 'e' #can't change name
+    >>> x.name = 'e' # can't change name
     Traceback (most recent call last):
       File "<stdin>", line 1, in ?
-    AttributeError: can't set attribute
-
-
+ AttributeError: can't set attribute +
diff --git a/doc/tutorial/doc/class_virtual_functions.html b/doc/tutorial/doc/class_virtual_functions.html index dea828c4..72c3fe3d 100644 --- a/doc/tutorial/doc/class_virtual_functions.html +++ b/doc/tutorial/doc/class_virtual_functions.html @@ -92,15 +92,16 @@ polymorphically fromC++.

Wrapping Base and the free function call_f:

-    class_<Base, BaseWrap, noncopyable>("Base", no_init)
+    class_<Base, BaseWrap, boost::noncopyable>("Base", no_init)
         ;
     def("call_f", call_f);
 

Notice that we parameterized the class_ template with BaseWrap as the second parameter. What is noncopyable? Without it, the library will try -to instantiate a copy constructor for returning Base objects from -functions.

+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.

In Python, let us try to instantiate our Base class:

diff --git a/doc/tutorial/doc/constructors.html b/doc/tutorial/doc/constructors.html
index 621387f5..79237526 100644
--- a/doc/tutorial/doc/constructors.html
+++ b/doc/tutorial/doc/constructors.html
@@ -64,7 +64,7 @@ expose instead.

init<std::string>() exposes the constructor taking in a std::string (in Python, constructors are spelled -"__init__(...)").

+""__init__"").

We can expose additional constructors by passing more init<...>s to the def() member function. Say for example we have another World diff --git a/doc/tutorial/doc/derived_object_types.html b/doc/tutorial/doc/derived_object_types.html index 4d08db05..303774f7 100644 --- a/doc/tutorial/doc/derived_object_types.html +++ b/doc/tutorial/doc/derived_object_types.html @@ -70,18 +70,21 @@ member functions.

Demonstrates that you can write the C++ equivalent of "format" % x,y,z in Python, which is useful since there's no easy way to do that in std C++.

-
- - - -
- Beware the common pitfall of -forgetting that the constructors of most of Python's mutable types -make copies, just as in Python.

- - dict d(x.attr("__dict__")); # makes a copy of x's dict
- d['whatever'] = 3; # modifies a copy of x.__dict__ (not the original)
-
+

+ Beware the common pitfall of forgetting that the constructors +of most of Python's mutable types make copies, just as in Python.

+

+Python:

+
+    >>> d = dict(x.__dict__)     #copies x.__dict__
+    >>> d['whatever']            #modifies the copy
+
+

+C++:

+
+    dict d(x.attr("__dict__"));  #copies x.__dict__
+    d['whatever'] = 3;           #modifies the copy
+

class_<T> as objects

Due to the dynamic nature of Boost.Python objects, any class_<T> may also be one of these types! The following code snippet wraps the class diff --git a/doc/tutorial/doc/quickstart.txt b/doc/tutorial/doc/quickstart.txt index ecf3b87d..a8176ec1 100644 --- a/doc/tutorial/doc/quickstart.txt +++ b/doc/tutorial/doc/quickstart.txt @@ -65,10 +65,15 @@ After this brief ['bjam] tutorial, we should have built two DLLs: * boost_python.dll * hello.pyd -This assumes of course that we are running on Windows. +if you are on Windows, and + +* libboost_python.so +* hello.so + +if you are on Unix. The tutorial example can be found in the directory: -[^/libs/python/example/tutorial]. There, you can find: +[^libs/python/example/tutorial]. There, you can find: * hello.cpp * Jamfile @@ -77,12 +82,13 @@ The [^hello.cpp] file is our C++ hello world example. The [^Jamfile] is a minimalist ['bjam] script that builds the DLLs for us. Before anything else, you should have the bjam executable in your boost -directory. Pre-built Boost.Jam executables are available for some +directory. Pre-built Boost.Jam executables are available for most platforms. For example, a pre-built Microsoft Windows bjam executable can be downloaded [@http://boost.sourceforge.net/jam-executables/bin.ntx86/bjam.zip here]. The complete list of bjam pre-built executables can be found [@../../../../../tools/build/index.html#Jam here]. [h2 Lets Jam!] +[$theme/jam.png] Here is our minimalist Jamfile: @@ -141,8 +147,9 @@ Python modules. Example: set PYTHON_VERSION=2.2 The above assumes that the Python installation is in [^c:/dev/tools/python] -and that we are using Python version 2.2. Be sure not to include a third -number, e.g. [*not] "2.2.1", even if that's the version you have. +and that we are using Python version 2.2. You'll have to tweak this path +appropriately. __note__ Be sure not to include a third number, e.g. [*not] "2.2.1", +even if that's the version you have. Now we are ready... Be sure to [^cd] to [^libs/python/example/tutorial] where the tutorial [^"hello.cpp"] and the [^"Jamfile"] is situated. @@ -186,6 +193,13 @@ If all is well, you should now have: * boost_python.dll * hello.pyd +if you are on Windows, and + +* libboost_python.so +* hello.so + +if you are on Unix. + [^boost_python.dll] can be found somewhere in [^libs\python\build\bin] while [^hello.pyd] can be found somewhere in [^libs\python\example\tutorial\bin]. After a successful build, you can just @@ -276,7 +290,7 @@ expose instead. [^init()] exposes the constructor taking in a [^std::string] (in Python, constructors are spelled -"[^__init__(...)]"). +"[^"__init__"]"). We can expose additional constructors by passing more [^init<...>]s to the [^def()] member function. Say for example we have another World @@ -326,10 +340,12 @@ Then, in Python: Note that [^name] is exposed as [*read-only] while [^value] is exposed as [*read-write]. +[pre >>> x.name = 'e' # can't change name Traceback (most recent call last): File "", line 1, in ? AttributeError: can't set attribute +] [page:1 Class Properties] @@ -482,14 +498,15 @@ polymorphically ['from] [*C++].] Wrapping [^Base] and the free function [^call_f]: - class_("Base", no_init) + class_("Base", no_init) ; def("call_f", call_f); Notice that we parameterized the [^class_] template with [^BaseWrap] as the second parameter. What is [^noncopyable]? Without it, the library will try -to instantiate a copy constructor for returning Base objects from -functions. +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. In Python, let us try to instantiate our [^Base] class: @@ -820,7 +837,7 @@ or more policies can be composed by chaining. Here's the general syntax: policy3 > > Here is the list of predefined call policies. A complete reference detailing -these can be found [@../../v2/CallPolicies.html here]. +these can be found [@../../v2/reference.html#models_of_call_policies here]. * [*with_custodian_and_ward][br] Ties lifetimes of the arguments * [*with_custodian_and_ward_postcall][br] Ties lifetimes of the arguments and results @@ -1007,13 +1024,18 @@ member functions. Demonstrates that you can write the C++ equivalent of [^"format" % x,y,z] in Python, which is useful since there's no easy way to do that in std C++. -[blurb __alert__ Beware the common pitfall of -forgetting that the constructors of most of Python's mutable types -make copies, just as in Python.[br][br] +__alert__ [*Beware] the common pitfall of forgetting that the constructors +of most of Python's mutable types make copies, just as in Python. - [^dict d(x.attr("__dict__")); # makes a copy of x's dict[br] - '''d['whatever']''' = 3; # modifies a copy of x.__dict__ (not the original)[br]] -] +Python: + + >>> d = dict(x.__dict__) # copies x.__dict__ + >>> d['whatever'] # modifies the copy + +C++: + + dict d(x.attr("__dict__")); # copies x.__dict__ + d['whatever'] = 3; # modifies the copy [h2 class_ as objects] diff --git a/doc/tutorial/doc/theme/jam.png b/doc/tutorial/doc/theme/jam.png new file mode 100644 index 0000000000000000000000000000000000000000..224ed7914bb5a31a407511093500aa1fe9d9e571 GIT binary patch literal 3884 zcmeAS@N?(olHy`uVBq!ia0y~yV5nzcU~uJNV_;xNjW#hE=bLrwBlWk7u9BNWG%WIzG^?ia{Jx0?d2cu65lo_tIq4R{ZpB|^Gj6) zSQHbUotHf@zxm;v$tNPW%s1Luc2<|6?FW0^VrZqF7Q%Y`1Ew|lr=xYj$EHQEz3mDMmMpd z>ejiX)97pynn`5kW z|CRi$_`uF-U0Tl!|N5S1TOOPDXU~o+TYOinI`YoqQ_`=^1)VOOpVS2UPMZHtf92(U zF(~lpmyJ~=b>FwfdM6w>w@64vPjkD9T!BlS8{-PeFW+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