Revision: 351
Author: roman_yakovenko
Date: 2006-07-26 07:24:17 -0700 (Wed, 26 Jul 2006)
ViewCVS: http://svn.sourceforge.net/pygccxml/?rev=351&view=rev
Log Message:
-----------
adding documentation, that will describe how to add custom code to generated one
Modified Paths:
--------------
pyplusplus_dev/docs/documentation/www_configuration.py
Added Paths:
-----------
pyplusplus_dev/docs/documentation/inserting_code.rest
Added: pyplusplus_dev/docs/documentation/inserting_code.rest
===================================================================
--- pyplusplus_dev/docs/documentation/inserting_code.rest (rev 0)
+++ pyplusplus_dev/docs/documentation/inserting_code.rest 2006-07-26 14:24:17 UTC (rev 351)
@@ -0,0 +1,109 @@
+=============
+Inerting code
+=============
+
+.. contents:: Table of contents
+
+------------
+Introduction
+------------
+
+`pyplusplus`_ is not a magician! Sometimes there is a need to modify or add code
+to generated file(s). This document will describe how you can insert your code
+to almost any place.
+
+-----------
+Source code
+-----------
+
+I am going to introduce C++ class ``world_t``. I will use it for all explanations.
+
+::
+
+ struct world_t {
+ void set(std::string msg) { this->msg = msg; }
+ std::string greet() { return msg; }
+
+ std::string msg;
+ };
+
+If run `pyplusplus`_ on this code it will generate next `boost.python`_ code:
+
+::
+
+ bp::class_< world_t, boost::noncopyable >( "world_t" )
+ .def(
+ "greet"
+ , &::world_t::greet
+ , bp::default_call_policies() )
+ .def(
+ "set"
+ , &::world_t::set
+ , ( bp::arg("msg") )
+ , bp::default_call_policies() )
+ .def_readwrite( "msg", &world_t::msg );
+
+It is possible, that `pyplusplus`_ will generate code, that expose class
+``world_t``, that will look different. The second form is more verbose, but it
+provides solution for few problems.
+
+::
+
+ { //::world_t
+ typedef bp::class_< world_t, boost::noncopyable > world_t_exposer_t;
+ world_t_exposer_t world_t_exposer = world_t_exposer_t( "world_t" );
+ bp::scope world_t_scope( world_t_exposer );
+ { //::world_t::greet
+
+ typedef ::std::string ( ::world_t::*function_ptr_t )( ) ;
+
+ world_t_exposer.def(
+ "greet"
+ , function_ptr_t( &::world_t::greet )
+ , bp::default_call_policies() );
+
+ }
+ { //::world_t::set
+
+ typedef void ( ::world_t::*function_ptr_t )( ::std::string ) ;
+
+ world_t_exposer.def(
+ "set"
+ , function_ptr_t( &::world_t::set )
+ , ( bp::arg("msg") )
+ , bp::default_call_policies() );
+
+ }
+ world_t_exposer.def_readwrite( "msg", &world_t::msg );
+ }
+
+
+--------------------
+Insert code to class
+--------------------
+
+``class_t`` declaration defines ``add_code( self, code, works_on_instance=True )``
+method.
+
+::
+
+ mb = module_builder_t( ... )
+ my_class = mb.class_( 'my_class' )
+ my_class.add_code( C++ code )
+
+
+
+
+.. _`pyplusplus` : ./../pyplusplus.html
+.. _`pygccxml` : ./../../pygccxml/pygccxml.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/www_configuration.py
===================================================================
--- pyplusplus_dev/docs/documentation/www_configuration.py 2006-07-26 13:08:20 UTC (rev 350)
+++ pyplusplus_dev/docs/documentation/www_configuration.py 2006-07-26 14:24:17 UTC (rev 351)
@@ -3,5 +3,6 @@
files_to_skip = ['indexing_suite_v2.html']
names = { 'containers' : 'STL containers'
, 'how_to' : 'how to ... ?'
- , 'doc_string' : 'documentation string'
+ , 'doc_string' : 'documentation string'
+ , 'inserting_code' : 'inserting code'
}
\ No newline at end of file
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|