Revision: 326
Author: roman_yakovenko
Date: 2006-07-19 23:50:38 -0700 (Wed, 19 Jul 2006)
ViewCVS: http://svn.sourceforge.net/pygccxml/?rev=326&view=rev
Log Message:
-----------
adding "how to ... ?" to documentation
Modified Paths:
--------------
pyplusplus_dev/docs/documentation/index.rest
pyplusplus_dev/docs/documentation/www_configuration.py
Added Paths:
-----------
pyplusplus_dev/docs/documentation/how_to.rest
Added: pyplusplus_dev/docs/documentation/how_to.rest
===================================================================
--- pyplusplus_dev/docs/documentation/how_to.rest (rev 0)
+++ pyplusplus_dev/docs/documentation/how_to.rest 2006-07-20 06:50:38 UTC (rev 326)
@@ -0,0 +1,124 @@
+============
+How to ... ?
+============
+
+.. contents:: Table of contents
+
+----------------------------------------
+How to add custom exception translation?
+----------------------------------------
+::
+
+ struct my_exception{
+ ...
+ const std::string& error() const;
+ ...
+ }
+
+First of all lets define ``translate`` function:
+
+::
+
+ translate_code = \
+ """
+ void translate(const my_exception &exception){
+ PyErr_SetString( PyExc_RuntimeError, exception.error().c_str() );
+ }
+ """
+
+::
+
+ mb.add_declaration_code( translate_code )
+
+
+Now we should register it:
+
+::
+
+ registration_code = "boost::python::register_exception_translator<my_exception>(&translate);"
+ mb.add_registration_code( registration_code )
+
+Small usage advice.
+-------------------
+
+`pyplusplus`_ allows you to define a query that will return you all exception classes:
+
+::
+
+ mb = module_builder_t( ... )
+ exception_classes = mb.decls( lambda decl: decl.name.endswith( 'exception' ) )
+
+Now you can iterate on ``exception_classes``, generate and register translate
+code for every class.
+
+That's all.
+
+-------------------------------------------------------
+How to expose function, which has hand-written wrapper?
+-------------------------------------------------------
+::
+
+ struct window_t{
+ ...
+ void get_size( int& height, int& widht ) const;
+ ...
+ };
+
+You can not expose ``get_size`` function as is - ``int`` is immutable type in
+Python. So, we need to create a wrapper to the function:
+::
+
+ boost::python::tuple get_size_wrapper( const window_t& win ){
+ int height(0), width( 0 );
+ win.get_size( height, widht );
+ return boost::python::make_tuple( height, width );
+ }
+
+::
+
+ class_<window_t>( ... )
+ .def( "get_size", &get_size_wrapper )
+ ...
+ ;
+
+Now, after you know how this problem is solved. I will show how this solution
+could be integrated with `pyplusplus`_.
+
+
+::
+
+ wrapper_code = \
+ """
+ static boost::python::tuple get_size( const window_t& win ){
+ int height(0), width( 0 );
+ win.get_size( height, widht );
+ return boost::python::make_tuple( height, width );
+ }
+ """
+
+::
+
+ registration_code = 'def( "get_size", &%s::get_size )' % window.wrapper_alias
+
+::
+
+ mb = module_builder_t( ... )
+ window = mb.class_( "window_t" )
+ window.member_function( "get_size" ).exclude()
+ window.add_wrapper_code( wrapper_code )
+ window.add_code( registration_code )
+
+That's all.
+
+.. _`pyplusplus` : ./../pyplusplus.html
+.. _`boost.python`: http://www.boost.org/libs/python/doc/index.html
+.. _`Python`: http://www.python.org
+.. _`GCC-XML`: http://www.gccxml.org
+
+..
+ Local Variables:
+ mode: indented-text
+ indent-tabs-mode: nil
+ sentence-end-double-space: t
+ fill-column: 70
+ End:
Modified: pyplusplus_dev/docs/documentation/index.rest
===================================================================
--- pyplusplus_dev/docs/documentation/index.rest 2006-07-20 06:23:22 UTC (rev 325)
+++ pyplusplus_dev/docs/documentation/index.rest 2006-07-20 06:50:38 UTC (rev 326)
@@ -4,8 +4,13 @@
.. contents:: Table of contents
-* `STL Containers`_
+----
+XXXX
+----
+ ???
+
+
.. _`STL Containers` : ./containers.html
Modified: pyplusplus_dev/docs/documentation/www_configuration.py
===================================================================
--- pyplusplus_dev/docs/documentation/www_configuration.py 2006-07-20 06:23:22 UTC (rev 325)
+++ pyplusplus_dev/docs/documentation/www_configuration.py 2006-07-20 06:50:38 UTC (rev 326)
@@ -1,3 +1,5 @@
-name = 'C++ containers'
-main_html_file = 'containers.html'
-files_to_skip = ['indexing_suite_v2.html']
\ No newline at end of file
+name = 'documentation'
+main_html_file = 'index.html'
+files_to_skip = ['indexing_suite_v2.html']
+names = { 'containers' : 'STL containers'
+ , 'how_to' : 'how to ... ?' }
\ No newline at end of file
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|