Revision: 943
http://svn.sourceforge.net/pygccxml/?rev=943&view=rev
Author: roman_yakovenko
Date: 2007-03-04 12:38:31 -0800 (Sun, 04 Mar 2007)
Log Message:
-----------
updating documentation
Modified Paths:
--------------
pyplusplus_dev/docs/documentation/multi_module_development.rest
Modified: pyplusplus_dev/docs/documentation/multi_module_development.rest
===================================================================
--- pyplusplus_dev/docs/documentation/multi_module_development.rest 2007-03-01 14:19:19 UTC (rev 942)
+++ pyplusplus_dev/docs/documentation/multi_module_development.rest 2007-03-04 20:38:31 UTC (rev 943)
@@ -8,75 +8,132 @@
Introduction
------------
-It is a common practices to construct final program or just a library\\package
-from few different dependent\\independent packages\\libraries. Many time these
-libraries reuse classes\\functions defined in another one. I think this is a must
-requirement from a code generator to be able to expose these libraries to `Python`_ ,
+It is a common practices to construct final program or a package from few
+different dependent or independent C++ libraries. Many time these libraries
+reuse classes\\functions defined in some other library. I think this is a must
+requirement from a code generator to be able to expose these libraries to `Python`_ ,
without "re-exposing" the class\\functions definition twise.
+This functionality is new in version "0.8.6".
-Please take a look on `Creating Packages`_ example, in `Boost.Python`_ tutorials.
-The example introduces slightly different use case, but it is good enough for us.
+---------------------
+Use case introduction
+---------------------
-Lets assume ``sounds::core`` namespace defines interface (base class) for all
-filter classes. ``sounds::filters`` namespace defines few "filter" classes.
+Lets say that you have to expose few libraries, which deal with image processing:
-The question now is how to expose the classes to Python, while preserving their
-logical location using `Py++`_?
+* ``core`` library - defines base class for all image classes - ``image_i``
-.. _`Creating Packages` : http://boost.org/libs/python/doc/tutorial/doc/html/python/techniques.html#python.creating_packages
+* ``png`` library - defines class ``png_image_t``, which derives from
+ ``core::image_i`` and implements functionality for "png" image format.
--------------------
-``already_exposed``
--------------------
+The code:
-`Py++`_ declaration
-
.. code-block:: C++
- //file sounds/core/filter_interface.h
+ namespace core{
+ class image_i{
+ ...
+ virtual void load() = 0;
+ };
+ } //core
- namespace sounds{ namespace core{
-
- struct filter_i{
+ namespace png{
+ class png_image_t : public core::image_i{
...
- virtual void apply() = 0;
+ virtual void load();
};
- } } //sounds::core
+ }
-.. code-block:: C++
+The desired goal is to expose every class in its own package.
- //file sounds/filters/ogg.h
-
- #include "sounds/core/filter_interface.h"
-
- namespace sounds{ namespace ogg{
-
- struct noise_cleaner_t : public core::filter_i{
- ...
- };
-
- } } //sound::ogg
+-------------------
+``already_exposed``
+-------------------
+Every `Py++`_ declaration has ``already_exposed`` property. This property says
+to `Py++`_ that the declaration is already exposed in another module:
+
.. code-block:: Python
#generate_code.py script
mb_core = module_builder_t( ... )
- mb_core.class_( 'filter_i' ).include()
-
- mb_filters = module_builder_t( ... )
- mb_filters.class_( '::sounds::core::filter_i' ).already_exposed = True
-
- #----------------------------------------------^^^^^^^^^^^^^^^^^^^^^^^
- #This will tell to Py++ that "filter_i" class is already exposed
-
-`Py++`_ will generate right code for both modules:
+ mb_core.class_( 'image_i' ).include()
+ mb_core.build_code_creator( 'core' )
+ mb.write_module( 'core.cpp' )
+ mb_png = module_builder_t( ... )
+ mb_png.class_( '::core::image_i' ).already_exposed = True
+ mb_png.class_( '::png::png_image_t' ).include()
+ mb_core.build_code_creator( 'png' )
+ mb.write_module( 'png.cpp' )
+`Py++`_ will generate code very similar to the next one:
+.. code-block:: C++
+ //file core.cpp
+ namespace bp = boost::python;
+
+ struct image_i_wrapper : core::image_i, bp::wrapper< core::image_i > {
+ image_i_wrapper()
+ : core::image_i(), bp::wrapper< core::image_i >()
+ {}
+
+ virtual void load( ){
+ bp::override func_load = this->get_override( "load" );
+ func_load( );
+ }
+ ...
+ };
+
+ BOOST_PYTHON_MODULE(core){
+ bp::class_< image_i_wrapper, boost::noncopyable >( "image_i" )
+ ...
+ .def( "load", bp::pure_virtual( &::core::image_i::load ) );
+ }
+
+.. code-block:: C++
+
+ //file png.cpp
+ struct png_image_t_wrapper : png::png_image_t, bp::wrapper< png::png_image_t > {
+
+ png_image_t_wrapper()
+ : png::png_image_t(), bp::wrapper< png::png_image_t >()
+ {}
+
+ virtual void load( ) {
+ if( bp::override func_load = this->get_override( "load" ) )
+ func_load( );
+ else
+ this->png::png_image_t::load( );
+ }
+
+ void default_load( ) {
+ png::png_image_t::load( );
+ }
+ };
+
+ BOOST_PYTHON_MODULE(pyplusplus){
+ bp::class_< png_image_t_wrapper, bp::bases< core::image_i > >( "png_image_t" )
+ //-------------------------------^^^^^^^^^^^^^^^^^^^^^^^^^^
+ ...
+ .def( "load", &::png::png_image_t::load, &png_image_t_wrapper::default_load );
+ }
+
+As you can see "png.cpp" file doesn't contains code, which exposes ``core::image_i``
+class.
+
+------
+Caveat
+------
+
+You should import module "core", before "png". `Boost.Python`_ requires definition
+of any base class to be exposed\\registered before a derive one.
+
+
.. _`Py++` : ./../pyplusplus.html
.. _`Boost.Python`: http://www.boost.org/libs/python/doc/index.html
.. _`Python`: http://www.python.org
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|