pygccxml-commit Mailing List for C++ Python language bindings (Page 43)
Brought to you by:
mbaas,
roman_yakovenko
You can subscribe to this list here.
2006 |
Jan
|
Feb
|
Mar
(190) |
Apr
(166) |
May
(170) |
Jun
(75) |
Jul
(105) |
Aug
(131) |
Sep
(99) |
Oct
(84) |
Nov
(67) |
Dec
(54) |
---|---|---|---|---|---|---|---|---|---|---|---|---|
2007 |
Jan
(66) |
Feb
(49) |
Mar
(25) |
Apr
(62) |
May
(21) |
Jun
(34) |
Jul
(9) |
Aug
(21) |
Sep
(5) |
Oct
|
Nov
(63) |
Dec
(34) |
2008 |
Jan
(10) |
Feb
(42) |
Mar
(26) |
Apr
(25) |
May
(6) |
Jun
(40) |
Jul
(18) |
Aug
(29) |
Sep
(6) |
Oct
(32) |
Nov
(14) |
Dec
(56) |
2009 |
Jan
(127) |
Feb
(52) |
Mar
(2) |
Apr
(10) |
May
(29) |
Jun
(3) |
Jul
|
Aug
(16) |
Sep
(4) |
Oct
(11) |
Nov
(8) |
Dec
(14) |
2010 |
Jan
(31) |
Feb
(1) |
Mar
(7) |
Apr
(9) |
May
(1) |
Jun
|
Jul
(2) |
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
2011 |
Jan
|
Feb
(8) |
Mar
(4) |
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
2014 |
Jan
|
Feb
|
Mar
(1) |
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
From: <rom...@us...> - 2006-12-21 05:44:30
|
Revision: 808 http://svn.sourceforge.net/pygccxml/?rev=808&view=rev Author: roman_yakovenko Date: 2006-12-20 21:44:30 -0800 (Wed, 20 Dec 2006) Log Message: ----------- ++version Modified Paths: -------------- pygccxml_dev/setup.py pyplusplus_dev/setup.py Modified: pygccxml_dev/setup.py =================================================================== --- pygccxml_dev/setup.py 2006-12-21 05:43:08 UTC (rev 807) +++ pygccxml_dev/setup.py 2006-12-21 05:44:30 UTC (rev 808) @@ -52,7 +52,7 @@ setup( name = "pygccxml", - version = "0.8.3", + version = "0.8.5", description = "GCC-XML generated file reader", author = "Roman Yakovenko", author_email = "rom...@gm...", Modified: pyplusplus_dev/setup.py =================================================================== --- pyplusplus_dev/setup.py 2006-12-21 05:43:08 UTC (rev 807) +++ pyplusplus_dev/setup.py 2006-12-21 05:44:30 UTC (rev 808) @@ -90,7 +90,7 @@ setup( name = "Py++", - version = "0.8.3", + version = "0.8.5", description="Py++ is a framework of components for creating C++ code generator for Boost.Python library", author="Roman Yakovenko", author_email="rom...@gm...", This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <rom...@us...> - 2006-12-21 05:43:07
|
Revision: 807 http://svn.sourceforge.net/pygccxml/?rev=807&view=rev Author: roman_yakovenko Date: 2006-12-20 21:43:08 -0800 (Wed, 20 Dec 2006) Log Message: ----------- adding new warning and making epydoc to be happy Modified Paths: -------------- pyplusplus_dev/pyplusplus/decl_wrappers/calldef_wrapper.py pyplusplus_dev/pyplusplus/messages/warnings_.py Modified: pyplusplus_dev/pyplusplus/decl_wrappers/calldef_wrapper.py =================================================================== --- pyplusplus_dev/pyplusplus/decl_wrappers/calldef_wrapper.py 2006-12-20 08:47:22 UTC (rev 806) +++ pyplusplus_dev/pyplusplus/decl_wrappers/calldef_wrapper.py 2006-12-21 05:43:08 UTC (rev 807) @@ -164,6 +164,9 @@ if self.transformations: #if user defined transformation, than I think it took care of the problems + ft = self.transformations[0] + if ft.alias == ft.unique_name: + msgs.append( messages.W1044 % ft.alias ) return msgs if suspicious_type( self.return_type ) and None is self.call_policies: Modified: pyplusplus_dev/pyplusplus/messages/warnings_.py =================================================================== --- pyplusplus_dev/pyplusplus/messages/warnings_.py 2006-12-20 08:47:22 UTC (rev 806) +++ pyplusplus_dev/pyplusplus/messages/warnings_.py 2006-12-21 05:43:08 UTC (rev 807) @@ -126,9 +126,20 @@ W1043 = 'Py++ created an ugly alias ("%s") for template instantiated class.' +W1044 = 'Py++ created an ugly alias ("%s") for function wrapper.' + warnings = globals() for identifier, explanation in warnings.items(): + if len( identifier ) != 5: + continue + if identifier[0] != 'W': + continue + try: + int( identifier[1:] ) + except: + continue + globals()[ identifier ] = 'warning %s: %s' % ( identifier, explanation ) del warnings This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <rom...@us...> - 2006-12-20 08:47:23
|
Revision: 806 http://svn.sourceforge.net/pygccxml/?rev=806&view=rev Author: roman_yakovenko Date: 2006-12-20 00:47:22 -0800 (Wed, 20 Dec 2006) Log Message: ----------- adding announcements Modified Paths: -------------- pygccxml_dev/docs/definition.rest pygccxml_dev/docs/history/history.rest pyplusplus_dev/docs/history/history.rest Added Paths: ----------- pygccxml_dev/announcement.txt pyplusplus_dev/announcement.txt Added: pygccxml_dev/announcement.txt =================================================================== --- pygccxml_dev/announcement.txt (rev 0) +++ pygccxml_dev/announcement.txt 2006-12-20 08:47:22 UTC (rev 806) @@ -0,0 +1,69 @@ +Hello! + +I'm pleased to announce the 0.8.5 release of pygccxml. + +What is pygccxml? +================= + +"...The purpose of the GCC-XML extension is to generate an XML description of a +C++ program from GCC's internal representation. " + +-- Introduction to GCC-XML + +The purpose of pygccxml is to read a generated file and provide a simple +framework to navigate C++ declarations, using Python classes. + +Where is pygccxml? +================== + +Site: http://language-binding.net/pygccxml/pygccxml.html + +Download: http://language-binding.net/pygccxml/download.html + +What's new? +=========== + +Features +-------- + +* Added new functionality: "I depend on them". Every declaration can report + types and declarations it depends on. This functionality helps code generators. + For example, Py++, the Boost.Python code generator, uses it to verify that all + relevant declarations were exposed. + +* Declarations, read from GCC-XML generated file, could be saved in cache. + +Small features +-------------- +* New type traits have been added: + + * is_bool + +* Small improvement to algorithm, which extracts value_type + ( mapped_type ) from "std" containers. + +* Few aliases to long method name were introduced: + + ============================= ========================== + Name Alias + ============================= ========================== + scopedef_t.variable scopedef_t.var + scopedef_t.variables scopedef_t.vars + scopedef_t.member_function scopedef_t.mem_fun + scopedef_t.member_functions scopedef_t.mem_funs + scopedef_t.free_function scopedef_t.free_fun + scopedef_t.free_functions scopedef_t.free_funs + ============================= ========================== + +Bug fixes +--------- + +* "signed char" and "char" are two different types. This bug was fixed and + now pygccxml treats them right. Many thanks to Gaetan Lehmann for reporting + the bug. + +* Fixing bug related to array size and cache. + + +For a more complete list, please see the news: +http://language-binding.net/pygccxml/history/history.html Modified: pygccxml_dev/docs/definition.rest =================================================================== --- pygccxml_dev/docs/definition.rest 2006-12-20 06:56:58 UTC (rev 805) +++ pygccxml_dev/docs/definition.rest 2006-12-20 08:47:22 UTC (rev 806) @@ -1,10 +1,8 @@ -"...The purpose of the `GCC-XML`_ extension is to generate an XML description -of a C++ program from GCC's internal representation. Since XML is easy to parse, -other development tools will be able to work with C++ programs without the -burden of a complicated C++ parser..." - --- Introduction to `GCC-XML`_ - +The purpose of the `GCC-XML`_ extension is to generate an XML description of a +C++ program from GCC's internal representation. + + -- Introduction to `GCC-XML`_ + The purpose of `pygccxml`_ is to read a generated file and provide a simple framework to navigate C++ declarations, using Python classes. Modified: pygccxml_dev/docs/history/history.rest =================================================================== --- pygccxml_dev/docs/history/history.rest 2006-12-20 06:56:58 UTC (rev 805) +++ pygccxml_dev/docs/history/history.rest 2006-12-20 08:47:22 UTC (rev 806) @@ -23,7 +23,7 @@ Version 0.8.5 ------------- -1. Adding new functionality: "I depend on them". Every declarations can report +1. Added new functionality: "I depend on them". Every declaration can report types and declarations it depends on. 2. ``signed char`` and ``char`` are two different types. This bug was fixed and Added: pyplusplus_dev/announcement.txt =================================================================== --- pyplusplus_dev/announcement.txt (rev 0) +++ pyplusplus_dev/announcement.txt 2006-12-20 08:47:22 UTC (rev 806) @@ -0,0 +1,55 @@ +Hello! + +I'm pleased to announce the 0.8.5 release of Py++. + +What is Py++? +============= + +Py++ is an object-oriented framework for creating a code generator for +Boost.Python library. + +Where is Py++? +============== + +Site: http://language-binding.net/pyplusplus/pyplusplus.html + +Download: http://language-binding.net/pyplusplus/download.html + +What's new? +=========== + +Features +-------- + +* Added "Function Transformation" feature: + http://language-binding.net/pyplusplus/documentation/functions/transformation/transformation.html + +* Added new functionality, which allows you to control messages and warnings: + http://language-binding.net/pyplusplus/documentation/feedback.html#how-to-disable-warning-s + +* Adding new algorithm, which controls the registration order of the functions. + http://language-binding.net/pyplusplus/documentation/functions/registration_order.html + +* Added new "Py++" defined `return_pointee_value`_ call policy: + http://language-binding.net/pyplusplus/documentation/functions/call_policies.html#py-defined-call-policies + +* Opaque types are fully supported: + http://language-binding.net/pyplusplus/documentation/functions/call_policies.html#special-case + + +Small features +-------------- + +* It is possible to configure "Py++" to generate faster ( compilation time ) + code for indexing suite version 2. See API documentation. + +* The algorithm, which finds all class properties was improved. Now it provides + a better way to control properties creation. A property that would hide another + exposed declaration will not be registered\\created. + +* Work around for "custom smart pointer as member variable" Boost.Python bug + was introduced. + + +For a more complete list, please see the news: +http://language-binding.net/pyplusplus/history/history.html Modified: pyplusplus_dev/docs/history/history.rest =================================================================== --- pyplusplus_dev/docs/history/history.rest 2006-12-20 06:56:58 UTC (rev 805) +++ pyplusplus_dev/docs/history/history.rest 2006-12-20 08:47:22 UTC (rev 806) @@ -36,7 +36,7 @@ Version 0.8.5 ------------- -1. `Function transformation`_ feature goes live. +1. Added `Function Transformation`_ feature. .. _`Function transformation` : ../documentation/functions/transformation/transformation.html @@ -45,7 +45,7 @@ .. _`how to disable warnings?` : ../documentation/feedback.html#how-to-disable-warning-s -3. Adding new algorithm, which controls the registration order of the functions. +3. Added new algorithm, which controls the registration order of the functions. See `registration order document`_ .. _`registration order document` : ../documentation/functions/registration_order.html @@ -171,7 +171,7 @@ 5. Member variables, that are pointers exported correctly. -6. Adding experimental support for ``vector_indexing_suite``. +6. Added experimental support for ``vector_indexing_suite``. 7. Bug fixes. This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <rom...@us...> - 2006-12-20 06:56:59
|
Revision: 805 http://svn.sourceforge.net/pygccxml/?rev=805&view=rev Author: roman_yakovenko Date: 2006-12-19 22:56:58 -0800 (Tue, 19 Dec 2006) Log Message: ----------- improving named_tuple functionality Modified Paths: -------------- pyplusplus_dev/pyplusplus/code_repository/convenience.py pyplusplus_dev/pyplusplus/code_repository/named_tuple.py pyplusplus_dev/pyplusplus/file_writers/writer.py pyplusplus_dev/pyplusplus/function_transformers/controllers.py pyplusplus_dev/pyplusplus/function_transformers/templates.py pyplusplus_dev/pyplusplus/function_transformers/transformer.py pyplusplus_dev/pyplusplus/module_creator/creator.py pyplusplus_dev/unittests/data/function_transformations_to_be_exported.hpp pyplusplus_dev/unittests/function_transformations_tester.py pyplusplus_dev/unittests/temp/named_tuple.py Modified: pyplusplus_dev/pyplusplus/code_repository/convenience.py =================================================================== --- pyplusplus_dev/pyplusplus/code_repository/convenience.py 2006-12-18 08:36:12 UTC (rev 804) +++ pyplusplus_dev/pyplusplus/code_repository/convenience.py 2006-12-20 06:56:58 UTC (rev 805) @@ -137,19 +137,32 @@ inline boost::python::object get_out_argument( boost::python::object result, const char* arg_name ){ - if( PySequence_Check( result.ptr() ) ){ - return boost::python::getattr( result, arg_name ); + if( !PySequence_Check( result.ptr() ) ){ + return result; } + boost::python::object cls = boost::python::getattr( result, "__class__" ); + boost::python::object cls_name = boost::python::getattr( cls, "__name__" ); + std::string name = boost::python::extract< std::string >( cls_name ); + if( "named_tuple" == name ){ + return boost::python::getattr( result, arg_name ); + } else{ return result; } + } inline boost::python::object get_out_argument( boost::python::object result, index_type index ){ - if( PySequence_Check( result.ptr() ) ){ - return result[ index ]; + if( !PySequence_Check( result.ptr() ) ){ + return result; } + boost::python::object cls = boost::python::getattr( result, "__class__" ); + boost::python::object cls_name = boost::python::getattr( cls, "__name__" ); + std::string name = boost::python::extract< std::string >( cls_name ); + if( "named_tuple" == name ){ + return result[ index ]; + } else{ return result; } Modified: pyplusplus_dev/pyplusplus/code_repository/named_tuple.py =================================================================== --- pyplusplus_dev/pyplusplus/code_repository/named_tuple.py 2006-12-18 08:36:12 UTC (rev 804) +++ pyplusplus_dev/pyplusplus/code_repository/named_tuple.py 2006-12-20 06:56:58 UTC (rev 805) @@ -12,31 +12,18 @@ # http://www.boost.org/LICENSE_1_0.txt) class named_tuple(tuple): - \"\"\"Creates tuple, which allows access to stored values by name and by index. + \"\"\"Creates tuple, which allows access to stored values by name and\\or by index. - named_tuple could be constructed exactly in the same way as Python dict. + Construction example: named_tuple( ('a',0), ('b',1) ) + 'a' and 'b' are names, while 0 and 1 are values \"\"\" - def __new__(cls, seq=None, **keywd): - if seq: - if isinstance( seq, dict ): - return tuple.__new__( cls, seq.values() ) - else: - return tuple.__new__( cls, [ val for name, val in seq] ) - else: - return tuple.__new__( cls, keywd.values() ) + def __new__(cls, *args): + return tuple.__new__( cls, [ val for name, val in args] ) - def __init__(self, seq=None, **keywd): - "named_tuple could be constructed exactly in the same way as Python dict." + def __init__(self, *args): tuple.__init__( self ) - if seq: - if isinstance( seq, dict ): - name2value = dict( seq.iteritems() ) - else: - name2value = dict( seq ) - else: - name2value = dict( keywd ) - self.__dict__[ '__name2value' ] = name2value + self.__dict__[ '__name2value' ] = dict( args ) def __getattr__(self, name): try: @@ -56,7 +43,7 @@ return super( named_tuple, self ).__getitem__( key ) if __name__ == '__main__': - nt = named_tuple( a=0, b=1) + nt = named_tuple( ('a',0), ('b',1) ) assert nt.a == 0 and nt.b == 1 a,b = nt assert a == 0 and b == 1 Modified: pyplusplus_dev/pyplusplus/file_writers/writer.py =================================================================== --- pyplusplus_dev/pyplusplus/file_writers/writer.py 2006-12-18 08:36:12 UTC (rev 804) +++ pyplusplus_dev/pyplusplus/file_writers/writer.py 2006-12-20 06:56:58 UTC (rev 805) @@ -50,12 +50,7 @@ for cr in code_repository.all: if self.__extmodule.is_system_header( cr.file_name ): self.write_file( os.path.join( dir, cr.file_name ), cr.code ) - #temporal patch: always write named_tuple.py file - f = file( os.path.join( dir, code_repository.named_tuple.file_name ), 'w+b' ) - f.write( code_repository.named_tuple.code ) - f.close() - @staticmethod def write_file( fpath, content ): """Write a source file. @@ -73,7 +68,10 @@ writer_t.logger.debug( 'write code to file "%s" - started' % fpath ) start_time = time.clock() fcontent_new = [] - fcontent_new.append( '// This file has been generated by Py++.' ) + if os.path.splitext( fpath )[1] == '.py': + fcontent_new.append( '# This file has been generated by Py++.' ) + else: + fcontent_new.append( '// This file has been generated by Py++.' ) fcontent_new.append( os.linesep * 2 ) fcontent_new.append( content ) fcontent_new.append( os.linesep ) #keep gcc happy Modified: pyplusplus_dev/pyplusplus/function_transformers/controllers.py =================================================================== --- pyplusplus_dev/pyplusplus/function_transformers/controllers.py 2006-12-18 08:36:12 UTC (rev 804) +++ pyplusplus_dev/pyplusplus/function_transformers/controllers.py 2006-12-20 06:56:58 UTC (rev 805) @@ -1,3 +1,16 @@ +# Copyright 2006 Roman Yakovenko. +# 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) + +"""defines controller classes which help to define the function transformation + +The idea behind implementation of "Function Transformation" functionality is simple: +Py++ defines few templates. Transformers are just editors for the templates. +In most cases, transformers don't directly edit the template, but use controller +classes for this purpose. Controller classes provide an abstraction of the templates. +""" + import string import templates from pygccxml import declarations @@ -3,5 +16,14 @@ class variable_t( object ): + """defines C++ variable""" def __init__( self, type, name, initialize_expr='' ): + """ + @param type: type of the variable + @type type: instance of L{pygccxml.declarations.type_t} + + @param name: name( str ) of the variable + + @param initialize_expr: an expression that initialize the variable + """ self.__name = name self.__type = type @@ -10,14 +32,17 @@ @property def name( self ): + "variable name" return self.__name @property def type( self ): + "variable type" return self.__type @property def initialize_expr( self ): + "inirialize expression" return self.__initialize_expr def declare_var_string( self ): @@ -27,6 +52,14 @@ , initialize_expr=self.initialize_expr ) class variables_manager_t( object ): + """function wrapper variables manager + + Almost every time we define new transformer, we need to define variables. + It is important to keep the variable names unique. This class will ensure this. + Every time you declare new variable, it will return the unique variable name. + The name will be built from the original variable name and some index, which + will make the variable to be unique. + """ def __init__( self ): object.__init__( self ) self.__variables = [] #variables @@ -34,14 +67,32 @@ @property def variables( self ): + "list of all declared variables" return self.__variables def declare_variable( self, type, name, initialize_expr='' ): + """declare variable + + @param type: type of the variable + @type type: instance of L{pygccxml.declarations.type_t} + + @param name: name( str ) of the variable + + @param initialize_expr: an expression that initialize the variable + + @return: the unique variable name + """ unique_name = self.__create_unique_var_name( name ) self.__variables.append( variable_t( type, unique_name, initialize_expr ) ) return unique_name def register_name( self, name ): + """register predefined variable name + + There are use cases, where it is convenience to define variables within + a template. In such cases, the only thing that should be done is registering + a unique name of the variable. + """ return self.__create_unique_var_name( name ) def __create_unique_var_name( self, name ): @@ -61,6 +112,8 @@ return vm class controller_base_t( object ): + """base class for all controller classes""" + def __init__( self, function ): self.__function = function @@ -69,10 +122,11 @@ return self.__function def apply( self, transformations ): + """asks all transformations to configure the controller""" raise NotImplementedError() class sealed_fun_controller_t( controller_base_t ): - #base class for free and member function controllers + """base class for free and member function controllers""" def __init__( self, function ): controller_base_t.__init__( self, function ) self.__vars_manager = create_variables_manager( function ) @@ -104,7 +158,7 @@ @property def wrapper_args( self ): - return self.__wrapper_args + return filter( None, self.__wrapper_args ) def find_wrapper_arg( self, name ): for arg in self.wrapper_args: @@ -116,7 +170,7 @@ arg = self.find_wrapper_arg( name ) if not arg: raise LookupError( "Unable to remove '%s' argument - not found!" % name ) - del self.wrapper_args[ self.wrapper_args.index(arg) ] + self.__wrapper_args[ self.__wrapper_args.index(arg) ] = None @property def arg_expressions( self ): Modified: pyplusplus_dev/pyplusplus/function_transformers/templates.py =================================================================== --- pyplusplus_dev/pyplusplus/function_transformers/templates.py 2006-12-18 08:36:12 UTC (rev 804) +++ pyplusplus_dev/pyplusplus/function_transformers/templates.py 2006-12-20 06:56:58 UTC (rev 805) @@ -5,11 +5,12 @@ # Matthias Baas is an initial author of the templates. +"""defines few templates, which will be used to create a function-wrapper +definition.""" + import os from string import Template -#TODO: pre_call, post_call terminology should be changed. Use prefix and suffix -#instead: http://boost.org/libs/smart_ptr/sp_techniques.html#wrapper class sealed_fun: body = Template( os.linesep.join([ Modified: pyplusplus_dev/pyplusplus/function_transformers/transformer.py =================================================================== --- pyplusplus_dev/pyplusplus/function_transformers/transformer.py 2006-12-18 08:36:12 UTC (rev 804) +++ pyplusplus_dev/pyplusplus/function_transformers/transformer.py 2006-12-20 06:56:58 UTC (rev 805) @@ -2,8 +2,6 @@ # 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) -# -# Initial author: Matthias Baas """This module contains the class L{transformer_t}. """ @@ -12,23 +10,15 @@ from pygccxml import declarations, parser return_ = -1 +#return_ is a spacial const, which represent an index of return type class transformer_t: + """Base class for a function transformer.""" + USE_1_BASED_INDEXING = False - - """Base class for a function transformer. - - This class specifies the interface that a user written transformer - has to implement. It doesn't contain any actual functionality so - a user doesn't have to derive from this class. Methods that are not - implemented are treated as if they would do nothing and return None. - - @author: Matthias Baas - """ - + def __init__(self, function): - """Constructor. - """ + """@param function: reference to function declaration""" self.__function = function @property @@ -41,6 +31,10 @@ return [] def get_argument( self, reference ): + """returns reference to the desired argument + + @param reference: name( str ) or index( int ) of the argument + """ if isinstance( reference, str ): found = filter( lambda arg: arg.name == reference, self.function.arguments ) if len( found ) == 1: @@ -53,6 +47,10 @@ return self.function.arguments[ reference ] def get_type( self, reference ): + """returns type of the desired argument or return type of the function + + @param reference: name( str ) or index( int ) of the argument + """ global return_ if isinstance( reference, int ) and reference == return_: return self.function.return_type @@ -60,9 +58,26 @@ return self.get_argument( reference ).type def configure_mem_fun( self, controller ): + """Transformers should overridde the method, in order to define custom + transformation for non-virtual member function. + + @param controller: instance of L{mem_fun_controller_t} class + """ pass def configure_free_fun( self, controller ): + """Transformers should overridde the method, in order to define custom + transformation for free function. + + @param controller: instance of L{free_fun_controller_t} class + """ pass - \ No newline at end of file + def configure_virtual_mem_fun( self, controller ): + """Transformers should overridde the method, in order to define custom + transformation for virtual member function. + + @param controller: instance of L{virtual_mem_fun_controller_t} class + """ + pass + Modified: pyplusplus_dev/pyplusplus/module_creator/creator.py =================================================================== --- pyplusplus_dev/pyplusplus/module_creator/creator.py 2006-12-18 08:36:12 UTC (rev 804) +++ pyplusplus_dev/pyplusplus/module_creator/creator.py 2006-12-20 06:56:58 UTC (rev 805) @@ -428,7 +428,10 @@ # Check if it is a header from the code repository if header in code_repository.headers: self.__extmodule.add_system_header( header ) - + + if not self.__extmodule.is_system_header( code_repository.named_tuple.file_name ): + self.__extmodule.add_system_header( code_repository.named_tuple.file_name ) + if self.curr_decl.has_static: #static_method should be created only once. found = filter( lambda creator: isinstance( creator, code_creators.static_method_t ) Modified: pyplusplus_dev/unittests/data/function_transformations_to_be_exported.hpp =================================================================== --- pyplusplus_dev/unittests/data/function_transformations_to_be_exported.hpp 2006-12-18 08:36:12 UTC (rev 804) +++ pyplusplus_dev/unittests/data/function_transformations_to_be_exported.hpp 2006-12-20 06:56:58 UTC (rev 805) @@ -184,6 +184,13 @@ }; struct bug_render_target_t{ + + static float get_static_statistics( bug_render_target_t& inst ){ + float x,y; + inst.get_statistics( x, y ); + return x+y; + } + virtual void get_statistics( float& x, float& y ) const{ x = 1.1;; y = 1.2; Modified: pyplusplus_dev/unittests/function_transformations_tester.py =================================================================== --- pyplusplus_dev/unittests/function_transformations_tester.py 2006-12-18 08:36:12 UTC (rev 804) +++ pyplusplus_dev/unittests/function_transformations_tester.py 2006-12-20 06:56:58 UTC (rev 805) @@ -8,7 +8,6 @@ import math import unittest import fundamental_tester_base -from named_tuple import named_tuple from pyplusplus import function_transformers as ft from pyplusplus.module_builder import call_policies @@ -140,15 +139,16 @@ return self.m_height+1 def fixed_output_array(self): + from named_tuple import named_tuple # Produce a correct return value if self.fixed_output_array_mode==0: - return named_tuple( v=(2,5,7) ) + return named_tuple( ('v', (2,5,7)) ) # Produce the wrong type elif self.fixed_output_array_mode==1: return 5 # Produce a sequence with the wrong number of items elif self.fixed_output_array_mode==2: - return named_tuple( v=(2,5) ) + return named_tuple( ('v', (2,5)) ) pyimg1 = py_image1_t(3,7) @@ -202,6 +202,18 @@ cls = module.no_virtual_members_t() self.assertEqual(cls.member(), (True, 17)) + class py_bug_render_target_t( module.bug_render_target_t ): + def __init__( self ): + module.bug_render_target_t.__init__( self ) + + def get_statistics( self ): + from named_tuple import named_tuple + return named_tuple( ( 'x', 2.0 ), ( 'y', 3.0 ) ) + tmp = py_bug_render_target_t() + + tmp.get_statistics() + self.failUnless( 2.0 + 3.0 == module.bug_render_target_t.get_static_statistics( tmp ) ) + def create_suite(): suite = unittest.TestSuite() suite.addTest( unittest.makeSuite(tester_t)) Modified: pyplusplus_dev/unittests/temp/named_tuple.py =================================================================== --- pyplusplus_dev/unittests/temp/named_tuple.py 2006-12-18 08:36:12 UTC (rev 804) +++ pyplusplus_dev/unittests/temp/named_tuple.py 2006-12-20 06:56:58 UTC (rev 805) @@ -1,3 +1,5 @@ +# This file has been generated by Py++. + # Copyright 2004 Roman Yakovenko. # Distributed under the Boost Software License, Version 1.0. (See # accompanying file LICENSE_1_0.txt or copy at @@ -4,31 +6,18 @@ # http://www.boost.org/LICENSE_1_0.txt) class named_tuple(tuple): - """Creates tuple, which allows access to stored values by name and by index. + """Creates tuple, which allows access to stored values by name and\or by index. - named_tuple could be constructed exactly in the same way as Python dict. + Construction example: named_tuple( ('a',0), ('b',1) ) + 'a' and 'b' are names, while 0 and 1 are values """ - def __new__(cls, seq=None, **keywd): - if seq: - if isinstance( seq, dict ): - return tuple.__new__( cls, seq.values() ) - else: - return tuple.__new__( cls, [ val for name, val in seq] ) - else: - return tuple.__new__( cls, keywd.values() ) + def __new__(cls, *args): + return tuple.__new__( cls, [ val for name, val in args] ) - def __init__(self, seq=None, **keywd): - "named_tuple could be constructed exactly in the same way as Python dict." + def __init__(self, *args): tuple.__init__( self ) - if seq: - if isinstance( seq, dict ): - name2value = dict( seq.iteritems() ) - else: - name2value = dict( seq ) - else: - name2value = dict( keywd ) - self.__dict__[ '__name2value' ] = name2value + self.__dict__[ '__name2value' ] = dict( args ) def __getattr__(self, name): try: @@ -48,9 +37,10 @@ return super( named_tuple, self ).__getitem__( key ) if __name__ == '__main__': - nt = named_tuple( a=0, b=1) + nt = named_tuple( ('a',0), ('b',1) ) assert nt.a == 0 and nt.b == 1 a,b = nt assert a == 0 and b == 1 assert nt[ "a" ] == 0 and nt[ "b" ] == 1 + This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <rom...@us...> - 2006-12-18 08:36:14
|
Revision: 804 http://svn.sourceforge.net/pygccxml/?rev=804&view=rev Author: roman_yakovenko Date: 2006-12-18 00:36:12 -0800 (Mon, 18 Dec 2006) Log Message: ----------- fixing "const" bug Modified Paths: -------------- pyplusplus_dev/pyplusplus/code_creators/calldef_transformed.py pyplusplus_dev/pyplusplus/function_transformers/templates.py pyplusplus_dev/unittests/data/function_transformations_to_be_exported.hpp Modified: pyplusplus_dev/pyplusplus/code_creators/calldef_transformed.py =================================================================== --- pyplusplus_dev/pyplusplus/code_creators/calldef_transformed.py 2006-12-17 19:57:49 UTC (rev 803) +++ pyplusplus_dev/pyplusplus/code_creators/calldef_transformed.py 2006-12-18 08:36:12 UTC (rev 804) @@ -333,7 +333,10 @@ tmpl_values['wrapper_class'] = self.parent.wrapper_alias tmpl_values['wrapped_class'] = declarations.full_name( self.declaration.parent ) tmpl_values['wrapped_inst'] = cntrl.inst_arg.name - + tmpl_values['wrapped_inst_constness'] = '' + if declarations.is_const( declarations.remove_reference( cntrl.inst_arg.type ) ): + tmpl_values['wrapped_inst_constness'] = 'const' + decl_vars = cntrl.variables[:] if not declarations.is_void( self.declaration.return_type ): decl_vars.append( cntrl.result_variable ) Modified: pyplusplus_dev/pyplusplus/function_transformers/templates.py =================================================================== --- pyplusplus_dev/pyplusplus/function_transformers/templates.py 2006-12-17 19:57:49 UTC (rev 803) +++ pyplusplus_dev/pyplusplus/function_transformers/templates.py 2006-12-18 08:36:12 UTC (rev 804) @@ -43,7 +43,7 @@ 'static $return_type $unique_function_name( $arg_declarations ){' , ' $declare_variables' , ' $pre_call' - , ' if( dynamic_cast< $wrapper_class* >( boost::addressof( $wrapped_inst ) ) ){' + , ' if( dynamic_cast< $wrapper_class $wrapped_inst_constness* >( boost::addressof( $wrapped_inst ) ) ){' , ' $save_result$wrapped_inst.$wrapped_class::$function_name($arg_expressions);' , ' }' , ' else{' Modified: pyplusplus_dev/unittests/data/function_transformations_to_be_exported.hpp =================================================================== --- pyplusplus_dev/unittests/data/function_transformations_to_be_exported.hpp 2006-12-17 19:57:49 UTC (rev 803) +++ pyplusplus_dev/unittests/data/function_transformations_to_be_exported.hpp 2006-12-18 08:36:12 UTC (rev 804) @@ -184,7 +184,7 @@ }; struct bug_render_target_t{ - virtual void get_statistics( float& x, float& y ){ + virtual void get_statistics( float& x, float& y ) const{ x = 1.1;; y = 1.2; } @@ -197,6 +197,7 @@ frame_stats_t fs; fs.x = 1.1; fs.y = 1.2; + return fs; } }; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <rom...@us...> - 2006-12-17 19:57:49
|
Revision: 803 http://svn.sourceforge.net/pygccxml/?rev=803&view=rev Author: roman_yakovenko Date: 2006-12-17 11:57:49 -0800 (Sun, 17 Dec 2006) Log Message: ----------- updating docs and adding new compile time test case Modified Paths: -------------- pyplusplus_dev/docs/history/history.rest pyplusplus_dev/docs/quotes.rest pyplusplus_dev/unittests/data/function_transformations_to_be_exported.hpp pyplusplus_dev/unittests/function_transformations_tester.py Modified: pyplusplus_dev/docs/history/history.rest =================================================================== --- pyplusplus_dev/docs/history/history.rest 2006-12-15 20:11:48 UTC (rev 802) +++ pyplusplus_dev/docs/history/history.rest 2006-12-17 19:57:49 UTC (rev 803) @@ -17,6 +17,7 @@ * Lakin Wecker * Georgiy Dernovoy * Gottfried Ganssauge +* Andy Miller ------------ Project name Modified: pyplusplus_dev/docs/quotes.rest =================================================================== --- pyplusplus_dev/docs/quotes.rest 2006-12-15 20:11:48 UTC (rev 802) +++ pyplusplus_dev/docs/quotes.rest 2006-12-17 19:57:49 UTC (rev 803) @@ -35,6 +35,13 @@ Lakin Wecker, the author of `Python-OGRE`_ project +"... Py++ allows the wrappers to be "automagically" created, which means it's much +easier to keep things up to date (the maintainence on the Py++ based wrapper is +tiny compared to any other system I've used). It also allows us to wrap other +libraries fairly easily. " + + Andy Miller, a developer of `Python-OGRE`_ project + ------------------ Who is using Py++? ------------------ Modified: pyplusplus_dev/unittests/data/function_transformations_to_be_exported.hpp =================================================================== --- pyplusplus_dev/unittests/data/function_transformations_to_be_exported.hpp 2006-12-15 20:11:48 UTC (rev 802) +++ pyplusplus_dev/unittests/data/function_transformations_to_be_exported.hpp 2006-12-17 19:57:49 UTC (rev 803) @@ -183,6 +183,23 @@ ~ft_private_destructor_t(){} }; +struct bug_render_target_t{ + virtual void get_statistics( float& x, float& y ){ + x = 1.1;; + y = 1.2; + } + + struct frame_stats_t{ + float x, y; + }; + + virtual frame_stats_t get_statistics(){ + frame_stats_t fs; + fs.x = 1.1; + fs.y = 1.2; + } +}; + } #endif//__function_transformations_to_be_exported_hpp__ Modified: pyplusplus_dev/unittests/function_transformations_tester.py =================================================================== --- pyplusplus_dev/unittests/function_transformations_tester.py 2006-12-15 20:11:48 UTC (rev 802) +++ pyplusplus_dev/unittests/function_transformations_tester.py 2006-12-17 19:57:49 UTC (rev 803) @@ -68,6 +68,9 @@ mb.decls(lambda decl: decl.name.startswith("_")).exclude() + cls = mb.class_("bug_render_target_t") + cls.mem_fun("get_statistics", arg_types=['float &']*2).add_transformation( ft.output(0), ft.output(1) ) + def run_tests(self, module): """Run the actual unit tests. """ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <rom...@us...> - 2006-12-15 20:11:49
|
Revision: 802 http://svn.sourceforge.net/pygccxml/?rev=802&view=rev Author: roman_yakovenko Date: 2006-12-15 12:11:48 -0800 (Fri, 15 Dec 2006) Log Message: ----------- updating docs Modified Paths: -------------- pygccxml_dev/docs/history/history.rest pyplusplus_dev/docs/history/history.rest Modified: pygccxml_dev/docs/history/history.rest =================================================================== --- pygccxml_dev/docs/history/history.rest 2006-12-14 18:41:53 UTC (rev 801) +++ pygccxml_dev/docs/history/history.rest 2006-12-15 20:11:48 UTC (rev 802) @@ -10,50 +10,50 @@ Thanks to all the people that have contributed patches, bug reports and suggestions: - * My wife - Yulia - * John Pallister - * Matthias Baas - * Allen Bierbaum - * Georgiy Dernovoy - * Darren Garnier - * Gottfried Ganssauge - * Gaetan Lehmann - +* My wife - Yulia +* John Pallister +* Matthias Baas +* Allen Bierbaum +* Georgiy Dernovoy +* Darren Garnier +* Gottfried Ganssauge +* Gaetan Lehmann + ------------- Version 0.8.5 ------------- -1. ``signed char`` and ``char`` are two different types. This bug was fixed and - now `pygccxml`_ treats them right. Many thanks to Gaetan Lehmann for reporting +1. Adding new functionality: "I depend on them". Every declarations can report + types and declarations it depends on. + +2. ``signed char`` and ``char`` are two different types. This bug was fixed and + now `pygccxml`_ treats them right. Many thanks to Gaetan Lehmann for reporting the bug. -2. Declarations, read from GCC-XML generated file, could be saved in cache. +3. Declarations, read from GCC-XML generated file, could be saved in cache. -3. New type traits have been added: - +4. New type traits have been added: + * ``is_bool`` - -4. Small improvment to algorithm, which extracts ``value_type``( ``mapped_type`` ) - from STD containers. - -5. Few aliases to long method name were introduced: +5. Small improvement to algorithm, which extracts ``value_type`` + ( ``mapped_type`` ) from "std" containers. + +6. Few aliases to long method name were introduced: + ================================= ========================== - name alias + Name Alias ================================= ========================== - ``scopedef_t.variable`` ``scopedef_t.var`` - ``scopedef_t.variables`` ``scopedef_t.vars`` - ``scopedef_t.member_function`` ``scopedef_t.mem_fun`` - ``scopedef_t.member_functions`` ``scopedef_t.mem_funs`` - ``scopedef_t.free_function`` ``scopedef_t.free_fun`` - ``scopedef_t.free_functions`` ``scopedef_t.free_funs`` + ``scopedef_t.variable`` ``scopedef_t.var`` + ``scopedef_t.variables`` ``scopedef_t.vars`` + ``scopedef_t.member_function`` ``scopedef_t.mem_fun`` + ``scopedef_t.member_functions`` ``scopedef_t.mem_funs`` + ``scopedef_t.free_function`` ``scopedef_t.free_fun`` + ``scopedef_t.free_functions`` ``scopedef_t.free_funs`` ================================= ========================== -6. Fixing bug related to array size and cache. +7. Fixing bug related to array size and cache. -7. Adding new functionality: "I depend on them". Every declarations could be asked - to report - ------------- Version 0.8.2 ------------- Modified: pyplusplus_dev/docs/history/history.rest =================================================================== --- pyplusplus_dev/docs/history/history.rest 2006-12-14 18:41:53 UTC (rev 801) +++ pyplusplus_dev/docs/history/history.rest 2006-12-15 20:11:48 UTC (rev 802) @@ -10,13 +10,13 @@ Thanks to all the people that have contributed patches, bug reports and suggestions: - * My wife - Yulia - * John Pallister - * Matthias Baas - * Allen Bierbaum - * Lakin Wecker - * Georgiy Dernovoy - * Gottfried Ganssauge +* My wife - Yulia +* John Pallister +* Matthias Baas +* Allen Bierbaum +* Lakin Wecker +* Georgiy Dernovoy +* Gottfried Ganssauge ------------ Project name @@ -31,7 +31,45 @@ 3. Users always changed the name of the projects. I saw at least 6 different names. +------------- +Version 0.8.5 +------------- +1. `Function transformation`_ feature goes live. + +.. _`Function transformation` : ../documentation/functions/transformation/transformation.html + +2. "Py++" introduces new functionality, which allows you to control messages and + warnings: `how to disable warnings?`_ . + +.. _`how to disable warnings?` : ../documentation/feedback.html#how-to-disable-warning-s + +3. Adding new algorithm, which controls the registration order of the functions. + See `registration order document`_ + +.. _`registration order document` : ../documentation/functions/registration_order.html + +4. New "Py++" defined `return_pointee_value`_ call policy was introduced. + +.. _`return_pointee_value` : ../documentation/functions/call_policies.html#py-defined-call-policies + +5. Support for opaque types was added. Read more about this feature `here`__. + +.. __ : ../documentation/functions/call_policies.html#special-case + +6. It is possible to configure "Py++" to generate faster ( compilation time ) + code for indexing suite version 2. See API documentation. + +7. The algorithm, which finds all class properties was improved. It provides + user with a better way to control properties creation. A property that would + hide another exposed declaration will not be registered\\created. + +8. Work around for "custom smart pointer as member variable" Boost.Python bug + was introduced. + +9. Bugs fixes and documentation improvement. + + ------------- Version 0.8.2 ------------- This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <rom...@us...> - 2006-12-14 18:41:55
|
Revision: 801 http://svn.sourceforge.net/pygccxml/?rev=801&view=rev Author: roman_yakovenko Date: 2006-12-14 10:41:53 -0800 (Thu, 14 Dec 2006) Log Message: ----------- adding new test cases Modified Paths: -------------- pyplusplus_dev/unittests/data/free_functions_to_be_exported.hpp pyplusplus_dev/unittests/data/member_functions_to_be_exported.hpp pyplusplus_dev/unittests/free_functions_tester.py pyplusplus_dev/unittests/member_functions_tester.py Modified: pyplusplus_dev/unittests/data/free_functions_to_be_exported.hpp =================================================================== --- pyplusplus_dev/unittests/data/free_functions_to_be_exported.hpp 2006-12-14 12:58:00 UTC (rev 800) +++ pyplusplus_dev/unittests/data/free_functions_to_be_exported.hpp 2006-12-14 18:41:53 UTC (rev 801) @@ -12,7 +12,7 @@ return 1; } -inline int plus(int a, int b=21){ +inline int plus(int a, const int b=21){ return a+b; } Modified: pyplusplus_dev/unittests/data/member_functions_to_be_exported.hpp =================================================================== --- pyplusplus_dev/unittests/data/member_functions_to_be_exported.hpp 2006-12-14 12:58:00 UTC (rev 800) +++ pyplusplus_dev/unittests/data/member_functions_to_be_exported.hpp 2006-12-14 18:41:53 UTC (rev 801) @@ -176,6 +176,11 @@ mem_fun_environment_t env; int i = env.get_value<int>(""); } + +struct mem_fun_constness_t{ + static int do_smth( int, const int ){ return 0; } + void do_smth_mem( int, const int ){} +}; } #endif//__member_functions_to_be_exported_hpp__ Modified: pyplusplus_dev/unittests/free_functions_tester.py =================================================================== --- pyplusplus_dev/unittests/free_functions_tester.py 2006-12-14 12:58:00 UTC (rev 800) +++ pyplusplus_dev/unittests/free_functions_tester.py 2006-12-14 18:41:53 UTC (rev 801) @@ -19,6 +19,7 @@ def customize(self, mb ): mb.calldef( 'one' ).alias = 'ONE' + mb.calldef('plus' ).create_with_signature = True def run_tests(self, module): self.failUnless( module.ONE() == 1 ) Modified: pyplusplus_dev/unittests/member_functions_tester.py =================================================================== --- pyplusplus_dev/unittests/member_functions_tester.py 2006-12-14 12:58:00 UTC (rev 800) +++ pyplusplus_dev/unittests/member_functions_tester.py 2006-12-14 18:41:53 UTC (rev 801) @@ -43,6 +43,8 @@ mb.run_query_optimizer() + mb.class_('mem_fun_constness_t' ).always_expose_using_scope = True + def create_py_immutable_by_ref( self, module ): class py_immutable_by_ref( module.immutable_by_ref_t ): def __init__( self ): This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <rom...@us...> - 2006-12-14 12:58:00
|
Revision: 800 http://svn.sourceforge.net/pygccxml/?rev=800&view=rev Author: roman_yakovenko Date: 2006-12-14 04:58:00 -0800 (Thu, 14 Dec 2006) Log Message: ----------- updating history Modified Paths: -------------- pygccxml_dev/docs/history/history.rest Modified: pygccxml_dev/docs/history/history.rest =================================================================== --- pygccxml_dev/docs/history/history.rest 2006-12-14 08:21:53 UTC (rev 799) +++ pygccxml_dev/docs/history/history.rest 2006-12-14 12:58:00 UTC (rev 800) @@ -20,13 +20,40 @@ * Gaetan Lehmann ------------- -Version 0.8.* +Version 0.8.5 ------------- 1. ``signed char`` and ``char`` are two different types. This bug was fixed and now `pygccxml`_ treats them right. Many thanks to Gaetan Lehmann for reporting the bug. +2. Declarations, read from GCC-XML generated file, could be saved in cache. + +3. New type traits have been added: + + * ``is_bool`` + +4. Small improvment to algorithm, which extracts ``value_type``( ``mapped_type`` ) + from STD containers. + +5. Few aliases to long method name were introduced: + + ================================= ========================== + name alias + ================================= ========================== + ``scopedef_t.variable`` ``scopedef_t.var`` + ``scopedef_t.variables`` ``scopedef_t.vars`` + ``scopedef_t.member_function`` ``scopedef_t.mem_fun`` + ``scopedef_t.member_functions`` ``scopedef_t.mem_funs`` + ``scopedef_t.free_function`` ``scopedef_t.free_fun`` + ``scopedef_t.free_functions`` ``scopedef_t.free_funs`` + ================================= ========================== + +6. Fixing bug related to array size and cache. + +7. Adding new functionality: "I depend on them". Every declarations could be asked + to report + ------------- Version 0.8.2 ------------- This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <rom...@us...> - 2006-12-14 08:21:54
|
Revision: 799 http://svn.sourceforge.net/pygccxml/?rev=799&view=rev Author: roman_yakovenko Date: 2006-12-14 00:21:53 -0800 (Thu, 14 Dec 2006) Log Message: ----------- a group of small improvements to the projects, mainly improving error messages Modified Paths: -------------- pygccxml_dev/pygccxml/declarations/calldef.py pyplusplus_dev/pyplusplus/decl_wrappers/decl_wrapper.py pyplusplus_dev/pyplusplus/decl_wrappers/properties.py pyplusplus_dev/pyplusplus/file_writers/multiple_files.py pyplusplus_dev/pyplusplus/messages/warnings_.py pyplusplus_dev/pyplusplus/module_creator/dependencies_manager.py pyplusplus_dev/pyplusplus/module_creator/types_database.py Modified: pygccxml_dev/pygccxml/declarations/calldef.py =================================================================== --- pygccxml_dev/pygccxml/declarations/calldef.py 2006-12-14 07:04:27 UTC (rev 798) +++ pygccxml_dev/pygccxml/declarations/calldef.py 2006-12-14 08:21:53 UTC (rev 799) @@ -431,6 +431,20 @@ def __init__( self, *args, **keywords ): member_calldef_t.__init__( self, *args, **keywords ) + def __str__(self): + # Get the full name of the calldef... + name = algorithm.full_name(self) + if name[:2]=="::": + name = name[2:] + # Add the arguments... + args = map(lambda a: str(a), self.arguments) + res = "%s(%s)"%(name, ", ".join(args)) + # Append the declaration class + cls = 'constructor' + if self.is_copy_constructor: + cls = 'copy ' + cls + return "%s [%s]"%(res, cls) + def _get_is_copy_constructor(self): args = self.arguments if 1 != len( args ): Modified: pyplusplus_dev/pyplusplus/decl_wrappers/decl_wrapper.py =================================================================== --- pyplusplus_dev/pyplusplus/decl_wrappers/decl_wrapper.py 2006-12-14 07:04:27 UTC (rev 798) +++ pyplusplus_dev/pyplusplus/decl_wrappers/decl_wrapper.py 2006-12-14 08:21:53 UTC (rev 799) @@ -128,7 +128,13 @@ msgs = [] if not self.exportable: msgs.append( self.why_not_exportable() ) - msgs.extend( self._readme_impl() ) + + if declarations.templates.is_instantiation( self.name ) \ + and self.alias == self._generate_valid_name(): + msgs.append( messages.W1043 % self.alias ) + + msgs.extend( self._readme_impl() ) + return messages.filter_disabled_msgs( msgs, self.__msgs_to_ignore ) @property Modified: pyplusplus_dev/pyplusplus/decl_wrappers/properties.py =================================================================== --- pyplusplus_dev/pyplusplus/decl_wrappers/properties.py 2006-12-14 07:04:27 UTC (rev 798) +++ pyplusplus_dev/pyplusplus/decl_wrappers/properties.py 2006-12-14 08:21:53 UTC (rev 799) @@ -6,6 +6,8 @@ "defines property_t helper class" import algorithm +from pyplusplus import messages +from pyplusplus import _logging_ from pygccxml import declarations class property_t( object ): @@ -248,6 +250,12 @@ self.getters, self.setters = recognizer.class_accessors( cls ) self.inherited_getters, self.inherited_setters = recognizer.inherited_accessors( cls ) + def __report_illegal_property( self, property_ ): + logger = _logging_.loggers.declarations + if not messages.filter_disabled_msgs([messages.W1041], property_.fget.parent.disabled_messaged ): + return #user disabled property warning + logger.warn( "%s;%s" % ( property_.fget.parent, messages.W1041 % property_ ) ) + def __is_legal_property( self, property_ ): """property is legal if it does not hide other declarations""" def is_relevant( decl ): @@ -281,11 +289,14 @@ if fset in used_setters: continue property_ = self.recognizer.create_property( fget, fset ) - if property_ and self.__is_legal_property( property_ ): - used_getters.add( fget ) - used_setters.add( fset ) - properties.append( property_ ) - break + if property_: + if self.__is_legal_property( property_ ): + used_getters.add( fget ) + used_setters.add( fset ) + properties.append( property_ ) + break + else: + self.__report_illegal_property( property_ ) return properties def __call__( self ): @@ -306,10 +317,13 @@ if fget in used_getters: continue property_ = self.recognizer.create_read_only_property( fget ) - if property_ and self.__is_legal_property( property_ ): - used_getters.add( fget ) - properties.append( property_ ) - + if property_: + if self.__is_legal_property( property_ ): + used_getters.add( fget ) + properties.append( property_ ) + else: + self.__report_illegal_property( property_ ) + if self.exclude_accessors: map( lambda accessor: accessor.exclude(), used_getters ) map( lambda accessor: accessor.exclude(), used_setters ) Modified: pyplusplus_dev/pyplusplus/file_writers/multiple_files.py =================================================================== --- pyplusplus_dev/pyplusplus/file_writers/multiple_files.py 2006-12-14 07:04:27 UTC (rev 798) +++ pyplusplus_dev/pyplusplus/file_writers/multiple_files.py 2006-12-14 08:21:53 UTC (rev 799) @@ -7,6 +7,8 @@ import os import writer +from pyplusplus import messages +from pyplusplus import _logging_ from pygccxml import declarations from pyplusplus import decl_wrappers from pyplusplus import code_creators @@ -133,13 +135,10 @@ value_class = class_traits.get_declaration( element_type ) return self.create_value_traits_header_name( value_class ) except RuntimeError, error: - msg = "%s;%s" \ - % ( str(code_creator.declaration) - , "Py++ can not find out container value_type( mapped_type )." - "The container class is template instantiation declaration and not definition." - "This container class will be exported, but there is a posiblity, that generated code will not compile." - "The solution to the problem is to create a variable of the class." ) - self.logger.warn( msg ) + decls_logger = _logging_.loggers.declarations + if not messages.filter_disabled_msgs([messages.W1042], code_creator.declaration.disabled_messaged ): + return #user disabled property warning + decls_logger.warn( "%s;%s" % ( code_creator.declaration, messages.W1042 ) ) def create_include_code( self, creators, head_headers=None, tail_headers=None ): answer = [] Modified: pyplusplus_dev/pyplusplus/messages/warnings_.py =================================================================== --- pyplusplus_dev/pyplusplus/messages/warnings_.py 2006-12-14 07:04:27 UTC (rev 798) +++ pyplusplus_dev/pyplusplus/messages/warnings_.py 2006-12-14 08:21:53 UTC (rev 799) @@ -3,11 +3,11 @@ # accompanying file LICENSE_1_0.txt or copy at # http://www.boost.org/LICENSE_1_0.txt) -"""This package defines all user messages( warnings + errors ), which will be +"""This package defines all user messages (warnings + errors), which will be reported to user. """ -W1000 = 'Py++, by default, does not expose internal compilers declarations.'\ +W1000 = 'Py++, by default, does not expose internal compilers declarations. '\ 'Names of those declarations usually start with "__".' W1001 = 'Py++, by default, does not expose internal declarations. ' \ @@ -15,7 +15,7 @@ W1002 = 'Py++, by default, does not expose compiler generated declarations.' -W1003 = 'Virtual functions that returns const reference can not be overriden from Python. ' \ +W1003 = 'Virtual functions that returns const reference cannot be overridden from Python. ' \ 'Reason: boost::python::override::operator()(...) saves the result of the marshaling ' \ '(from Python to C++) on the stack. Thus operator() returns reference ' \ 'to a temporary variable. Consider to use "Function Transformation" functionality ' \ @@ -25,7 +25,7 @@ 'pointer to function. ' \ ' See http://www.boost.org/libs/python/doc/v2/faq.html#funcptr for more information.' -W1005 = 'Py++ can not expose function that takes as argument/returns instance of non public class. ' \ +W1005 = 'Py++ cannot expose function that takes as argument/returns instance of non-public class. ' \ 'Generated code will not compile.' W1006 = 'Py++ need your help to expose function that takes as argument/returns C++ arrays. ' \ @@ -36,9 +36,9 @@ 'For more information see: http://www.boost.org/libs/python/doc/v2/configuration.html' W1008 = 'The function returns non-const reference to "Python immutable" type. ' \ - 'The value can not be modified from Python. ' + 'The value cannot be modified from Python. ' -W1009 = 'The function takes as argument (name=%s, pos=%d ) non-const reference ' \ +W1009 = 'The function takes as argument (name=%s, pos=%d) non-const reference ' \ 'to Python immutable type - function could not be called from Python. ' \ 'Take a look on "Function Transformation" functionality and define the transformation.' @@ -98,7 +98,7 @@ W1033 = "Py++ can not expose unnamed variables" -W1034 = "Py++ can not expose alignement bit." +W1034 = "Py++ can not expose alignment bit." W1035 = "Py++ can not expose static pointer member variables. This could be changed in future." @@ -111,11 +111,21 @@ W1039 = "Py++ doesn't expose private or protected member variables." -W1040 = 'The declaration is unexposed, but there are other declarations, which refer to it.' \ - 'This could cause "no to_python converter found" run time error.' \ +W1040 = 'The declaration is unexposed, but there are other declarations, which refer to it. ' \ + 'This could cause "no to_python converter found" run time error. ' \ 'Declarations: %s' +W1041 = 'Property "%s" could not be created. There is another exposed declaration with the same name( alias )." ' \ + 'The property will make it inaccessible.' +W1042 = 'Py++ can not find out container value_type( mapped_type ). ' \ + 'The container class is template instantiation declaration and not definition. ' \ + 'This container class will be exported, but there is a possibility, that ' \ + 'generated code will not compile or will lack some functionality. ' \ + 'The solution to the problem is to create a variable of the class.' + +W1043 = 'Py++ created an ugly alias ("%s") for template instantiated class.' + warnings = globals() for identifier, explanation in warnings.items(): Modified: pyplusplus_dev/pyplusplus/module_creator/dependencies_manager.py =================================================================== --- pyplusplus_dev/pyplusplus/module_creator/dependencies_manager.py 2006-12-14 07:04:27 UTC (rev 798) +++ pyplusplus_dev/pyplusplus/module_creator/dependencies_manager.py 2006-12-14 08:21:53 UTC (rev 799) @@ -20,29 +20,13 @@ self.__exported_decls.append( decl ) def __is_std_decl( self, decl ): - if not decl.parent: + #Every class under std should be exported by Boost.Python and\\or Py++ + #Also this is not the case right now, I prefer to hide the warnings + dpath = declarations.declaration_path( decl ) + if len( dpath ) < 3: return False - - if not isinstance( decl.parent, declarations.namespace_t ): + if dpath[1] != 'std': return False - - if 'std' != decl.parent.name: - return False - - ns_std = decl.parent - if not ns_std.parent: - return False - - if not isinstance( ns_std.parent, declarations.namespace_t ): - return False - - if '::' != ns_std.parent.name: - return False - - global_ns = ns_std.parent - if global_ns.parent: - return False - if decl.name.startswith( 'pair<' ): #special case return False Modified: pyplusplus_dev/pyplusplus/module_creator/types_database.py =================================================================== --- pyplusplus_dev/pyplusplus/module_creator/types_database.py 2006-12-14 07:04:27 UTC (rev 798) +++ pyplusplus_dev/pyplusplus/module_creator/types_database.py 2006-12-14 08:21:53 UTC (rev 799) @@ -3,6 +3,7 @@ # accompanying file LICENSE_1_0.txt or copy at # http://www.boost.org/LICENSE_1_0.txt) +from pyplusplus import messages from pygccxml import declarations from pyplusplus import code_creators from pyplusplus import _logging_ @@ -73,14 +74,10 @@ #check extraction of element type from container container_cls.indexing_suite.element_type except RuntimeError: - msg = "%s;%s" \ - % ( str(container_cls) - , "Py++ can not find out container value_type( mapped_type )." - "The container class is template instantiation declaration and not definition." - "This container class will be exported, but there is a posiblity, that generated code will not compile." - "The solution to the problem is to create a variable of the class." ) - _logging_.loggers.declarations.warn( msg ) - + decls_logger = _logging_.loggers.declarations + if not messages.filter_disabled_msgs([messages.W1042], container_cls.disabled_messaged ): + return #user disabled property warning + decls_logger.warn( "%s;%s" % ( container_cls, messages.W1042 ) ) self.__containers.add( container_cls ) return True @@ -182,4 +179,4 @@ def _get_used_containers( self ): return self.__containers used_containers = property( _get_used_containers) - \ No newline at end of file + This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <rom...@us...> - 2006-12-14 07:04:26
|
Revision: 798 http://svn.sourceforge.net/pygccxml/?rev=798&view=rev Author: roman_yakovenko Date: 2006-12-13 23:04:27 -0800 (Wed, 13 Dec 2006) Log Message: ----------- improving the algorithm, which guesses container element type Modified Paths: -------------- pygccxml_dev/pygccxml/declarations/__init__.py pygccxml_dev/pygccxml/declarations/class_declaration.py pygccxml_dev/pygccxml/declarations/type_traits.py Modified: pygccxml_dev/pygccxml/declarations/__init__.py =================================================================== --- pygccxml_dev/pygccxml/declarations/__init__.py 2006-12-13 22:12:02 UTC (rev 797) +++ pygccxml_dev/pygccxml/declarations/__init__.py 2006-12-14 07:04:27 UTC (rev 798) @@ -18,9 +18,8 @@ from class_declaration import ACCESS_TYPES from class_declaration import hierarchy_info_t from class_declaration import class_declaration_t +from class_declaration import class_types -class_types = ( class_t, class_declaration_t ) - from typedef import typedef_t from cpptypes import type_t Modified: pygccxml_dev/pygccxml/declarations/class_declaration.py =================================================================== --- pygccxml_dev/pygccxml/declarations/class_declaration.py 2006-12-13 22:12:02 UTC (rev 797) +++ pygccxml_dev/pygccxml/declarations/class_declaration.py 2006-12-14 07:04:27 UTC (rev 798) @@ -356,3 +356,5 @@ , ACCESS_TYPES.ALL ) return answer + +class_types = ( class_t, class_declaration_t ) Modified: pygccxml_dev/pygccxml/declarations/type_traits.py =================================================================== --- pygccxml_dev/pygccxml/declarations/type_traits.py 2006-12-13 22:12:02 UTC (rev 797) +++ pygccxml_dev/pygccxml/declarations/type_traits.py 2006-12-14 07:04:27 UTC (rev 798) @@ -898,9 +898,9 @@ found = global_ns.decls( name=value_type_str , function=lambda decl: not isinstance( decl, calldef.calldef_t ) , allow_empty=True ) - if not found: - if cpptypes.FUNDAMENTAL_TYPES.has_key( value_type_str ): - return cpptypes.FUNDAMENTAL_TYPES[value_type_str] + if not found: + if cpptypes.FUNDAMENTAL_TYPES.has_key( value_type_str[2:] ): #remove leading :: + return cpptypes.FUNDAMENTAL_TYPES[value_type_str[2:]] elif is_std_string( value_type_str ): string_ = global_ns.typedef( '::std::string' ) return remove_declarated( string_ ) @@ -908,7 +908,24 @@ string_ = global_ns.typedef( '::std::wstring' ) return remove_declarated( string_ ) else: - return None + value_type_str = value_type_str[2:]#removing leading :: + has_const = value_type_str.startswith( 'const ' ) + if has_const: + value_type_str = value_type_str[ len('const '): ] + has_pointer = value_type_str.endswith( '*' ) + if has_pointer: + value_type_str = value_type_str[:-1] + found = impl_details.find_value_type( global_ns, value_type_str ) + if not found: + return None + else: + if isinstance( found, class_declaration.class_types ): + found = cpptypes.declarated_t( found ) + if has_const: + found = cpptypes.const_t( found ) + if has_pointer: + found = cpptypes.pointer_t( found ) + return found if len( found ) == 1: return found[0] else: This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <rom...@us...> - 2006-12-13 22:12:03
|
Revision: 797 http://svn.sourceforge.net/pygccxml/?rev=797&view=rev Author: roman_yakovenko Date: 2006-12-13 14:12:02 -0800 (Wed, 13 Dec 2006) Log Message: ----------- fixing spelling errors Modified Paths: -------------- pyplusplus_dev/docs/bpl_lessons_learned/lessons_learned.rest pyplusplus_dev/docs/documentation/architecture.rest pyplusplus_dev/docs/documentation/best_practices.rest pyplusplus_dev/docs/documentation/containers.rest pyplusplus_dev/docs/documentation/feedback.rest pyplusplus_dev/docs/documentation/functions/call_policies.rest pyplusplus_dev/docs/documentation/functions/default_args.rest pyplusplus_dev/docs/documentation/functions/overloading.rest pyplusplus_dev/docs/documentation/functions/registration_order.rest pyplusplus_dev/docs/documentation/functions/transformation/built_in/built_in.rest pyplusplus_dev/docs/documentation/functions/transformation/built_in/inout.rest pyplusplus_dev/docs/documentation/functions/transformation/built_in/input.rest pyplusplus_dev/docs/documentation/functions/transformation/built_in/input_static_array.rest pyplusplus_dev/docs/documentation/functions/transformation/built_in/output.rest pyplusplus_dev/docs/documentation/functions/transformation/built_in/output_static_array.rest pyplusplus_dev/docs/documentation/functions/transformation/custom/custom.rest pyplusplus_dev/docs/documentation/functions/transformation/name_mangling.rest pyplusplus_dev/docs/documentation/how_to.rest pyplusplus_dev/docs/documentation/index.rest pyplusplus_dev/docs/documentation/inserting_code.rest pyplusplus_dev/docs/documentation/properties.rest pyplusplus_dev/docs/documentation/tutorials/module_builder/module_builder.rest pyplusplus_dev/docs/download.rest pyplusplus_dev/docs/examples/easybmp/easybmp.rest pyplusplus_dev/docs/history/history.rest pyplusplus_dev/docs/links.rest pyplusplus_dev/docs/peps/dsl_challenge.rest pyplusplus_dev/docs/peps/peps_index.rest pyplusplus_dev/docs/pyplusplus.rest pyplusplus_dev/docs/quotes.rest Modified: pyplusplus_dev/docs/bpl_lessons_learned/lessons_learned.rest =================================================================== --- pyplusplus_dev/docs/bpl_lessons_learned/lessons_learned.rest 2006-12-13 08:16:21 UTC (rev 796) +++ pyplusplus_dev/docs/bpl_lessons_learned/lessons_learned.rest 2006-12-13 22:12:02 UTC (rev 797) @@ -25,7 +25,7 @@ .. include:: ./shared_ptr/definition.rest .. _`boost::shared_ptr< const T>` : ./shared_ptr/shared_ptr.html - + .. _`Py++` : ./../pyplusplus.html .. _`pygccxml` : http://www.language-binding.net/pygccxml/pygccxml.html .. _`SourceForge`: http://sourceforge.net/index.php Modified: pyplusplus_dev/docs/documentation/architecture.rest =================================================================== --- pyplusplus_dev/docs/documentation/architecture.rest 2006-12-13 08:16:21 UTC (rev 796) +++ pyplusplus_dev/docs/documentation/architecture.rest 2006-12-13 22:12:02 UTC (rev 797) @@ -8,7 +8,7 @@ Introduction ------------ -This document will describe an architecture behind `Py++`_. +This document will describe an architecture behind `Py++`_. --------------------------- Py++ & pygccxml integration @@ -17,18 +17,18 @@ C++ --- -C++ is very powerful programming language. The power brings complexity. It is -not an easy task to parse C++ source files and to create in memory representation -of declarations tree. The declarations tree is worth nothing, if a user is not -able to explorer it, to run queries against it or to find out traits of a +C++ is very powerful programming language. The power brings complexity. It is +not an easy task to parse C++ source files and to create in memory representation +of declarations tree. The declarations tree is worth nothing, if a user is not +able to explorer it, to run queries against it or to find out traits of a declaration or a type. -On the earlier stage of the development, I realized, that all this functionality -does not belong to code generator and should be implemented out side of it. -`pygccxml`_ project was born. `pygccxml`_ made the code generator to be smaller +On the earlier stage of the development, I realized, that all this functionality +does not belong to code generator and should be implemented out side of it. +`pygccxml`_ project was born. `pygccxml`_ made the code generator to be smaller and C++ parser independent. It provides next services: -* definition of classes, that describe C++ declaration and types, and their +* definition of classes, that describe C++ declaration and types, and their analyzers ( type traits ) * C++ source files parsing and caching functionality @@ -45,7 +45,7 @@ * indexing suite parameters * generate warnings/hints - + * ... @@ -57,8 +57,8 @@ Parsing integration ~~~~~~~~~~~~~~~~~~~ -`Py++`_ provides it's own "API" to configure `pygccxml`_ parsing services. The -"API" I am talking about, is arguments to ``module_builder.__init__`` method. +`Py++`_ provides it's own "API" to configure `pygccxml`_ parsing services. The +"API" I am talking about, is arguments to ``module_builder.__init__`` method. We think, that exposing those services via `Py++`_ simplifies its usage. @@ -78,11 +78,11 @@ * query engine API -The user should be familiar with these parts and relevant API. In my opinion, -wrapping or hiding the API will not provide an additional value. The interface +The user should be familiar with these parts and relevant API. In my opinion, +wrapping or hiding the API will not provide an additional value. The interface of all those services is pretty simple and well polished. -Before I explain how these services are integrated, take a look on next source +Before I explain how these services are integrated, take a look on next source code: .. code-block:: Python @@ -100,43 +100,43 @@ my_class.rename("MyClass") -What you see here, is a common pattern, that will appear in all projects, that +What you see here, is a common pattern, that will appear in all projects, that use `Py++`_: * find the declaration(s) * give the instruction(s) to the code generator engine -What is the point of this example? From the user point of view it is perfectly -good, it makes a lot of sense to configure the code generation engine, using -the declarations tree. How does `Py++`_ add missing functionality to -``pygccxml.declarations`` classes? There were few possible solutions to the +What is the point of this example? From the user point of view it is perfectly +good, it makes a lot of sense to configure the code generation engine, using +the declarations tree. How does `Py++`_ add missing functionality to +``pygccxml.declarations`` classes? There were few possible solutions to the problem. The next one was implemented: 1. ``pygccxml.parser`` package interface was extended. Instead of creating - a concrete instance of declaration classes, ``pygccxml.parser`` package uses + a concrete instance of declaration classes, ``pygccxml.parser`` package uses a factory. - + 2. ``pyplusplus.decl_wrappers`` package defines classes, which derive from ``pygccxml.declarations`` classes and defines the factory. -The implemented solution is not the simplest one, but it provides an additional +The implemented solution is not the simplest one, but it provides an additional value to the project: -* the code generation engine configuration and declarations tree are tightly +* the code generation engine configuration and declarations tree are tightly coupled * the functionality provided by ``pygccxml.declarations`` and ``pygccxml.parser`` packages is available for ``pyplusplus.decl_wrappers`` classes -* classes defined in ``pyplusplus.decl_wrappers`` package implement next +* classes defined in ``pyplusplus.decl_wrappers`` package implement next functionality: - - * setting reasonable defaults for the code generation engine( call policies, + + * setting reasonable defaults for the code generation engine( call policies, indexing suite, ... ) - + * provides user with additional information( warnings and hints ) - + * as a bonus, `pygccxml`_ remained to be stand-alone project ---------------------- @@ -160,7 +160,7 @@ ``Code creators`` ----------------- -Do you know how many ways exist to export member function? If you will try to +Do you know how many ways exist to export member function? If you will try to answer the question, consider next function characteristics and their mix: * virtuality( non virtual, virtual or pure virtual ) @@ -171,59 +171,59 @@ * overloads -As you see, there are a lot of use cases. How do ``code creators`` solve the problem? +As you see, there are a lot of use cases. How do ``code creators`` solve the problem? Definition ~~~~~~~~~~ ``Code creator`` is an in-memory fragment of a C++ code. -Also, ``code creator`` can represent an arbitrary C++ code, in practice it -represents logically complete block. +Also, ``code creator`` can represent an arbitrary C++ code, in practice it +represents logically complete block. Example of ``code creators``: * ``code_creators.enum_t`` generates registration code for an enumeration - -* ``code_creators.mem_fun_pv_t`` generates registration code for public, pure + +* ``code_creators.mem_fun_pv_t`` generates registration code for public, pure virtual function - -* ``code_creators.mem_fun_pv_wrapper_t`` generates declaration code for public, + +* ``code_creators.mem_fun_pv_wrapper_t`` generates declaration code for public, pure virtual function - + * ``code_creators.include_t`` generates include directives -* ``code_creators.custom_text_t`` adds some custom( read user ) text\\code to +* ``code_creators.custom_text_t`` adds some custom( read user ) text\\code to the generated code -There are primary two groups of ``code creators``: declaration based and others. +There are primary two groups of ``code creators``: declaration based and others. Declaration based ``code creator`` keeps reference to the declaration ( ``pyplusplus.decl_wrapper.*`` class instance ). During code generation process, -it reads its settings( the code generation engine instructions ) from the -declaration. Declaration based ``code creators`` also divided into two groups. -The first group creates registration code, where the second one creates +it reads its settings( the code generation engine instructions ) from the +declaration. Declaration based ``code creators`` also divided into two groups. +The first group creates registration code, where the second one creates wrapper\\helper declaration code. I will reuse `this example`__, from `Boost.Python`_ tutorials. .. __ : http://boost.org/libs/python/doc/tutorial/doc/html/python/exposing.html#python.virtual_functions_with_default_implementations -1. ``BaseWrap::f``, ``BaseWrap::default_f`` - declaration code is created by +1. ``BaseWrap::f``, ``BaseWrap::default_f`` - declaration code is created by ``code_creators.mem_fun_v_wrapper_t`` 2. ``f`` registration code is created by ``code_creators.mem_fun_v_t``. This - code creator also keeps reference to the relevant instance of + code creator also keeps reference to the relevant instance of ``code_creators.mem_fun_v_wrapper_t`` class. -Composite ``code creator`` is a creator, which contains other creators. Composite -``code creator`` embeds the code, created by internal ``code creators``, within +Composite ``code creator`` is a creator, which contains other creators. Composite +``code creator`` embeds the code, created by internal ``code creators``, within the code it creates. For example: * ``code_creators.class_t``: - First of all it creates class registration code ( ``class_<...>`` ), after - this it appends to it code generated by internal creators. + First of all it creates class registration code ( ``class_<...>`` ), after + this it appends to it code generated by internal creators. * ``code_creators.module_body_t``: @@ -242,7 +242,7 @@ ``Code creators tree`` ~~~~~~~~~~~~~~~~~~~~~~ -``code_creators.module_t`` class is a top level ``code creator``. Take a look on +``code_creators.module_t`` class is a top level ``code creator``. Take a look on next possible "snapshot" of the ``code creators tree``: :: @@ -262,7 +262,7 @@ <free_function_t ...> <...> -You can think about ``code creators tree`` as some kind of `AST`_. +You can think about ``code creators tree`` as some kind of `AST`_. .. _`AST`: http://en.wikipedia.org/wiki/Abstract_syntax_tree @@ -270,7 +270,7 @@ ----------------------------------- ``pyplusplus.module_creator`` package is responsible for the tree construction. -``pyplusplus.module_creator.creator_t`` is the main class of the package. It +``pyplusplus.module_creator.creator_t`` is the main class of the package. It creates the tree in few steps: 1. It builds set of exposed declarations. @@ -279,7 +279,7 @@ 3. It creates ``code creators`` and put them into the right place within the tree. 4. If a declaration describes C++ class, it applies these steps to it. -Another responsibility of ``creator_t`` class, is to analyze declarations and +Another responsibility of ``creator_t`` class, is to analyze declarations and their dependency graphs. As a result, this class can: * find out a class ``HeldType`` @@ -288,15 +288,15 @@ * find out STD containers, which should be exported -* warn user, if some declaration is not exported and it used somewhere in +* warn user, if some declaration is not exported and it used somewhere in exported declarations ( **not implemented** ) ``File writers`` ---------------- -``File writers`` classes are responsible for writing ``code creators tree`` into -the files. `Py++`_ implements next strategies of writing ``code creators tree`` +``File writers`` classes are responsible for writing ``code creators tree`` into +the files. `Py++`_ implements next strategies of writing ``code creators tree`` into files: * single file @@ -307,7 +307,7 @@ * multiple files, with huge classes are written into multiple files - provides a solution for `compiler limit`_ problem. - + .. _`compiler limit` : http://www.boost.org/libs/python/doc/v2/faq.html#c1204 The more sophisticated approach, the better understanding of ``code creators`` Modified: pyplusplus_dev/docs/documentation/best_practices.rest =================================================================== --- pyplusplus_dev/docs/documentation/best_practices.rest 2006-12-13 08:16:21 UTC (rev 796) +++ pyplusplus_dev/docs/documentation/best_practices.rest 2006-12-13 22:12:02 UTC (rev 797) @@ -115,7 +115,7 @@ for those declarations that are actually used within your library). In the ``pygccxml`` package you can set the value for the ``-fxml-start`` - option using the ``start_with_declarations`` attribute of the + option using the ``start_with_declarations`` attribute of the ``pygccxml.parser.config_t`` object that you are passing to the parser. Modified: pyplusplus_dev/docs/documentation/containers.rest =================================================================== --- pyplusplus_dev/docs/documentation/containers.rest 2006-12-13 08:16:21 UTC (rev 796) +++ pyplusplus_dev/docs/documentation/containers.rest 2006-12-13 22:12:02 UTC (rev 797) @@ -25,7 +25,7 @@ * multiset * hash_multiset -It is not a trivial task to expose C++ container to Python. Boost.Python has +It is not a trivial task to expose C++ container to Python. Boost.Python has a functionality that will help you to expose some of STL containers to `Python`_. This functionality called - "indexing suite". If you want, you can read more about indexing suite `here`__. @@ -33,15 +33,15 @@ .. __ : http://boost.org/libs/python/doc/v2/indexing.html Boost.Python, out of the box, supports only ``vector``, ``map`` and ``hash_map`` -containers. In October 2003, Raoul Gough implemented support for the rest of -containers. Well, actually he did much more - he implemented new framework. -This framework provides support for almost all C++ containers and also an easy -way to add support for custom ones. You'd better read his `post`_ to +containers. In October 2003, Raoul Gough implemented support for the rest of +containers. Well, actually he did much more - he implemented new framework. +This framework provides support for almost all C++ containers and also an easy +way to add support for custom ones. You'd better read his `post`_ to `Boost.Python`_ mailing list or `documentation`_ for the new indexing suite. Now, I am sure you have next question: if this suite is so good, why it is not -in the main branch? The short answer is that this suite has some problems on +in the main branch? The short answer is that this suite has some problems on MSVC 6.0 compiler and there are few users, that still use that compiler. The long answer is here: @@ -57,10 +57,10 @@ Py++ and indexing suites ------------------------ -`Py++`_ implements support for both indexing suites. More over, you can +`Py++`_ implements support for both indexing suites. More over, you can freely mix indexing suites. For example you can expose ``std::vector<int>`` using `Boost.Python`_ built-in indexing suite and ``std::map< int, std::string>`` using -Raoul Gough's indexing suite. +Raoul Gough's indexing suite. ----------------- How does it work? @@ -69,7 +69,7 @@ In both cases, `Py++`_ provides almost "hands free" solution. `Py++`_ keeps track of all exported functions and variables, and if it sees that there is a usage of stl container, it exports the container. In both cases, `Py++`_ -analyzes the container ``value_type`` ( or in case of mapping container +analyzes the container ``value_type`` ( or in case of mapping container ``mapped_type`` ), in order to set reasonable defaults, when it generates the code. ------------------- @@ -84,16 +84,16 @@ mb = module_builder_t( ..., indexing_suite_version=2 ) -Every declared class has ``indexing_suite`` property. If the class is an +Every declared class has ``indexing_suite`` property. If the class is an instantiation of STL container, this property contains reference to an instance -of ``indexing_suite1_t`` or ``indexing_suite2_t`` class. +of ``indexing_suite1_t`` or ``indexing_suite2_t`` class. -How does `Py++`_ know, that a class represents STL container instantiation? -Well, it uses ``pygccxml.declarations.container_traits`` to find out this. -``pygccxml.declarations.container_traits`` class, provides all functionality +How does `Py++`_ know, that a class represents STL container instantiation? +Well, it uses ``pygccxml.declarations.container_traits`` to find out this. +``pygccxml.declarations.container_traits`` class, provides all functionality needed to identify container and to find out its ``value_type`` -( ``mapped_type`` ). +( ``mapped_type`` ). Built-in indexing suite API @@ -105,13 +105,13 @@ * ``no_proxy`` - a boolean, if ``value_type`` is one of the next types * fundamental type - + * enumeration * std::string or std::wstring * boost::shared_ptr<?> - + then, ``no_proxy`` will be set to ``True``, otherwise to ``False``. * ``derived_policies`` - a string, that will be added as is to generated code @@ -128,28 +128,28 @@ .. code-block:: C++ struct item{ - ... + ... private: bool operator==( const item& ) const; bool operator<( const item& ) const; }; - + struct my_data{ std::vector<item> items; std::map< std::string, item > name2item_mapping; }; -`Py++`_ declarations tree will contains ``item``, ``my_data``, -``vector<item>`` and ``map<string,item>`` class declarations. +`Py++`_ declarations tree will contains ``item``, ``my_data``, +``vector<item>`` and ``map<string,item>`` class declarations. -If ``value_type`` does not support "equal" or "less than" functionality, sort +If ``value_type`` does not support "equal" or "less than" functionality, sort and search functionality could not be exported. -`Py++`_ class declaration has two properties: ``equality_comparable`` and -``less_than_comparable``. The value of those properties is calculated on first -invocation. If `Py++`_ can find ``operator==``, that works on ``value_type``, -then, ``equality_comparable`` property value will be set to ``True``, otherwise +`Py++`_ class declaration has two properties: ``equality_comparable`` and +``less_than_comparable``. The value of those properties is calculated on first +invocation. If `Py++`_ can find ``operator==``, that works on ``value_type``, +then, ``equality_comparable`` property value will be set to ``True``, otherwise to ``False``. Same process is applied on ``less_than_comparable`` property. In our case, `Py++`_ will set both properties to ``False``, thus sort and @@ -159,36 +159,36 @@ * ``container_class`` - read only property, returns reference to container class declaration - + * ``container_traits`` - read only property, returns reference to the relevant - container traits class. Container traits classes are defined in + container traits class. Container traits classes are defined in ``pygccxml.declarations`` package. - + * ``element_type`` - is a reference to container ``value_type`` or ``mapped_type``. -* ``call_policies`` - read/write property, in near future I will add code to - `Py++`_ that will analize container ``value_type`` and will decide about +* ``call_policies`` - read/write property, in near future I will add code to + `Py++`_ that will analyze container ``value_type`` and will decide about default call policies. Just an example: for non-copy constructable classes - ``call_policies`` should be set to ``return_internal_reference``. - -* ``[disable|enable]_method`` - new indexing suite, allows to configure + ``call_policies`` should be set to ``return_internal_reference``. + +* ``[disable|enable]_method`` - new indexing suite, allows to configure functionality exported to Python, using simple bitwise operations on predefined flags. `Py++`_ allows you to specify what methods you want to disable or enable. ``indexing_suite2_t.METHODS`` contains names of all supported methods. - + * ``[disable|enable]_methods_group`` - almost same as above, but allows you - to specify what group of methods you want to disable or enable. + to specify what group of methods you want to disable or enable. ``indexing_suite2_t.METHOD_GROUPS`` contains names of all supported groups. Small tips/hints ---------------- 1. If you set ``equality_comparable`` or ``less_than_comparable`` to ``False``. - The indexing suite will disable relevant functionality. You don't have + The indexing suite will disable relevant functionality. You don't have explicitly to disable method or mothods group. -2. The documentation of new indexing suite contains few small mistakes. - I hope, I will have time to fix them. Any way, `Py++`_ generates +2. The documentation of new indexing suite contains few small mistakes. + I hope, I will have time to fix them. Any way, `Py++`_ generates correct code. Modified: pyplusplus_dev/docs/documentation/feedback.rest =================================================================== --- pyplusplus_dev/docs/documentation/feedback.rest 2006-12-13 08:16:21 UTC (rev 796) +++ pyplusplus_dev/docs/documentation/feedback.rest 2006-12-13 22:12:02 UTC (rev 797) @@ -19,8 +19,8 @@ Those goals all have something in common. In order to achieve them, `Py++`_ must -give useful feedback to the user. Because `Py++`_ understands the -declarations it exports, it can scan declarations for potential problems, report +give useful feedback to the user. Because `Py++`_ understands the +declarations it exports, it can scan declarations for potential problems, report them and in some cases provide hints about how to resolve the problem. Few examples: * @@ -42,11 +42,11 @@ struct window{ ... - void get_size( int& heght, int& widht ) const; + void get_size( int& height, int& width ) const; }; Member function ``get_size`` can be exposed to Python, but it will not be callable because [FILL IN HERE]. - + * In order to expose free/member function that takes more than 10 arguments user should define ``BOOST_PYTHON_MAX_ARITY`` macro. @@ -56,12 +56,12 @@ struct X{ ... }; - + void do_smth( X x ); - + If you expose ``do_smth`` function and don't expose struct ``X``, `Py++`_ will tell you that struct ``X`` is used in exported declaration, but was not - exposed. + exposed. For these problems and many other `Py++`_ gives a nice explanation and sometimes a link to the relevant information on the Internet. @@ -78,7 +78,7 @@ important messages to ``stdout``. More over it prints them only for declarations that are going to be exported. -`Py++`_ uses the python `logging`_ package to write all user messages. By +`Py++`_ uses the python `logging`_ package to write all user messages. By default, messages with ``DEBUG`` level will be skipped, all other messages will be reported. @@ -99,7 +99,7 @@ * warning unique identifier: "W1020" -* short explanation of the problem: "Py++ will generate class wrapper - hand +* short explanation of the problem: "Py++ will generate class wrapper - hand written code should be added to the wrapper class" --------------- @@ -109,20 +109,20 @@ How to disable warning(s)? -------------------------- -Every warning has unique identifier. In the example I gave it was ``W1020``. +Every warning has unique identifier. In the example I gave it was ``W1020``. .. code-block:: Python from pyplusplus import messages from pyplusplus import module_builder - + mb = module_builder.module_builder_t( ... ) xyz = mb.class_( XYZ ) xyz.disable_warnings( messages.W1020 ) It is also possible to disable warnings for all declarations. ``pyplusplus.messages`` package defines ``DISABLE_MESSAGES`` variable. This variable( ``list`` ) keeps -all warnings, which should not be reported. Use ``messages.disable`` function to +all warnings, which should not be reported. Use ``messages.disable`` function to edit it: .. code-block:: Python @@ -134,7 +134,7 @@ ----------- If you are here, it probably means that you are not pleased with default configuration -and want to change it, right? +and want to change it, right? 1. If you simply want to change the logging message level: @@ -149,38 +149,38 @@ 2. But what if you want to disable some messages and leave others? This is also possible. - `Py++`_ and `pygccxml`_ do not use a single logger. Almost every internal + `Py++`_ and `pygccxml`_ do not use a single logger. Almost every internal package has its own logger. So you can enable one logger and disable another one. - + The `pygccxml`_ package defines all loggers in the ``pygccxml.utils`` package. - + The `Py++`_ package defines all loggers in the ``pyplusplus._logging_`` package. - - Both packages define a ``loggers`` class. Those classes keep references to + + Both packages define a ``loggers`` class. Those classes keep references to different loggers. The ``loggers`` classes look very similar to the next class: .. code-block:: Python import logging #standard Python package - + def _create_logger_( name ): logger = logging.getLogger(name) ... return logger - + class loggers: file_writer = _create_logger_( 'pyplusplus.file_writer' ) declarations = _create_logger_( 'pyplusplus.declarations' ) - module_builder = _create_logger_( 'pyplusplus.module_builder' ) + module_builder = _create_logger_( 'pyplusplus.module_builder' ) root = logging.getLogger( 'pyplusplus' ) all = [ root, file_writer, module_builder, declarations ] You can use these references in the ``logging`` package to complete your task of adjusting individual loggers. - - One more thing, `Py++`_ automatically splits long message, where line + + One more thing, `Py++`_ automatically splits long message, where line length defaults to 70 characters. Thus it is very convenient to read them on your screen. - If you want to use different tools to monitor those messages, consider to use + If you want to use different tools to monitor those messages, consider to use standard `Formatter`_ class, instead of ``multi_line_formatter_t`` one. @@ -191,17 +191,17 @@ * ``why_not_exportable( self )`` - This method explains why a declaration could not be exported. The return value + This method explains why a declaration could not be exported. The return value is a string or ``None``. ``None`` is returned if the declaration is exportable. - Property ``exportable`` will be set to ``True`` if declaration is exportable, - and to ``False`` otherwise. + Property ``exportable`` will be set to ``True`` if declaration is exportable, + and to ``False`` otherwise. * ``readme( self )`` This method gives you access to all tips/hints/warnings `Py++`_ has about - the declaration. This methods returns a list of strings. If the declaration is - not exportable, than first message within the list is an explanation, why it + the declaration. This methods returns a list of strings. If the declaration is + not exportable, than first message within the list is an explanation, why it is not exportable. Modified: pyplusplus_dev/docs/documentation/functions/call_policies.rest =================================================================== --- pyplusplus_dev/docs/documentation/functions/call_policies.rest 2006-12-13 08:16:21 UTC (rev 796) +++ pyplusplus_dev/docs/documentation/functions/call_policies.rest 2006-12-13 22:12:02 UTC (rev 797) @@ -18,7 +18,7 @@ Syntax ------ -The call policies in `Py++`_ are named exactly as in `Boost.Python`_, only the +The call policies in `Py++`_ are named exactly as in `Boost.Python`_, only the syntax is slightly different. For instance, this call policy: .. code-block:: C++ @@ -37,7 +37,7 @@ Usage example ------------- -Every "callable" object in `Py++`_ has ``call_policies`` property. +Every "callable" object in `Py++`_ has ``call_policies`` property. C++ code: @@ -45,9 +45,9 @@ struct data{...}; const data& do_smth( const data& d, int x ); - + void return_second_arg( int x, int y ); - + typedef struct opaque_ *opaque_pointer; opaque_pointer get_opaque(); @@ -57,15 +57,15 @@ from pyplusplus import module_builder from pyplusplus.module_builder import call_policies - + mb = module_builder.module_builder_t( ... ) mb.free_function( 'return_second_arg' ).call_policies = call_policies.return_arg( 2 ) #---------------------------------------^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - + mb.member_function( 'do_smth' ).call_policies = call_policies.return_self() #-------------------------------^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - - mb.calldef( 'get_opaque' ).call_policies + + mb.calldef( 'get_opaque' ).call_policies = call_policies.return_value_policy( call_policies.return_opaque_pointer ) -------- @@ -78,41 +78,41 @@ * ``default_call_policies``: * `Python`_ immutable type returned by value: C++ fundamental types, ``std::string``, enumerations - + * user-defined type ( class ) returned by value - + * return type is ``const char*`` * ``return_value_policy`` - + * ``return_opaque_pointer`` - - * return type is ``void*`` - + + * return type is ``void*`` + * return type is ``const void*`` - + * return type is ``T*`` and ``T`` is a user defined opaque type - - ``class_t`` and ``class_declaration_t`` classes have ``opaque`` property. - You have to set it to ``True``, if you want `Py++`_ to create this call - policy automaticly for all functions, that use ``T*`` as return type. - + + ``class_t`` and ``class_declaration_t`` classes have ``opaque`` property. + You have to set it to ``True``, if you want `Py++`_ to create this call + policy automatically for all functions, that use ``T*`` as return type. + * ``copy_const_reference`` * return type is ``const T&`` - + * for member ``operator[]`` that returns const reference to immutable type - + * ``return_by_value`` * return type is ``const wchar_t*`` - + * ``copy_non_const_reference`` - + * return type is ``T&``, for member ``operator[]`` that returns reference to immutable type - + * ``return_internal_reference`` - + * return type is ``T&``, for member ``operator[]`` --------------------- @@ -124,13 +124,13 @@ * `Py++`_ prints a warning message -* `Py++`_ generates code with - +* `Py++`_ generates code with + .. code-block:: C++ - + /* undefined call policies */ - - comment, in place of call policy. If `Py++`_ was wrong and function doesn't + + comment, in place of call policy. If `Py++`_ was wrong and function doesn't need call policy the generate code will compile fine, otherwise you will get a compilation error. @@ -142,13 +142,13 @@ Before you read this paragraph consider to read `Boost.Python`_ `return_opaque_pointer documentation`_. ``return_value_policy( return_opaque_pointer )`` is a special policy for `Boost.Python`_. -In this case, it requieres from you to define specialization for the -``boost::python::type_id`` function on the type pointed to by returned pointer. -`Py++`_ will generate the required code. +In this case, it requires from you to define specialization for the +``boost::python::type_id`` function on the type pointed to by returned pointer. +`Py++`_ will generate the required code. Actually you should define ``boost::python::type_id`` specialization also in case -a function takes the opaque type as an argument. `Py++`_ can do it for you, all +a function takes the opaque type as an argument. `Py++`_ can do it for you, all you need is to say to mark a declaration as opaque. Example: @@ -157,13 +157,13 @@ struct identity_impl_t{}; typedef identity_impl_t* identity; - + struct world_t{ - + world_t( identity id ); - + identity get_id() const; - + ... }; @@ -175,7 +175,7 @@ mb.class_( 'identity_impl_t' ).opaque = True -.. _`return_opaque_pointer documentation` : http://boost.org/libs/python/doc/v2/return_opaque_pointer.html +.. _`return_opaque_pointer documentation` : http://boost.org/libs/python/doc/v2/return_opaque_pointer.html -------------------------- Py++ defined call policies @@ -184,7 +184,7 @@ return_pointee_value -------------------- -Class ``return_pointee_value`` is a model of `ResultConverterGenerator`_ which +Class ``return_pointee_value`` is a model of `ResultConverterGenerator`_ which can be used to wrap C++ functions returning any pointer, such that the pointee of return value is copied into a new Python object. @@ -197,11 +197,11 @@ static float value = 0.5; return &value; } - + float* get_null_value(){ return (float*)( 0 ); } - + namespace bpl = boost::python; BOOST_PYTHON_MODULE(my_module){ def( "get_value" @@ -217,7 +217,7 @@ from pyplusplus import module_builder from pyplusplus.module_builder import call_policies - + mb = module_builder.module_builder_t( ... ) mb.free_function( return_type='float *' ).call_policies \ = call_policies.return_value_policy( call_policies.return_pointee_value ) @@ -227,7 +227,7 @@ .. code-block:: Python import my_module - + assert 0.5 == my_module.get_value() assert None is my_module.get_null_value() Modified: pyplusplus_dev/docs/documentation/functions/default_args.rest =================================================================== --- pyplusplus_dev/docs/documentation/functions/default_args.rest 2006-12-13 08:16:21 UTC (rev 796) +++ pyplusplus_dev/docs/documentation/functions/default_args.rest 2006-12-13 22:12:02 UTC (rev 797) @@ -8,7 +8,7 @@ Introduction ------------ -There is more than one way to export function with default arguments. Before we +There is more than one way to export function with default arguments. Before we proceed, please take a look on next class: .. code-block:: C++ @@ -18,7 +18,7 @@ bool f(int a=12) { return true; - } + } }; ------------------- @@ -30,16 +30,16 @@ .. code-block:: C++ namespace bp = boost::python; - + BOOST_PYTHON_MODULE(pyplusplus){ - bp::class_< X >( "X" ) - .def( + bp::class_< X >( "X" ) + .def( "f" , &::X::f - , ( bp::arg("a")=(int)(12) ) ); + , ( bp::arg("a")=(int)(12) ) ); } -The additional value of the approach is keyword arguments. You will be able to +The additional value of the approach is keyword arguments. You will be able to call function ``f`` like this: .. code-block:: Python @@ -58,7 +58,7 @@ .. code-block:: Python import module_builder - + mb = module_builder.module_builder_t( ... ) x = mb.class_( "X" ) x.member_function( "f" ).use_overload_macro = True @@ -75,36 +75,36 @@ struct S1; struct S2; - + struct S1{ void do_smth( S2* s2=0 ); }; - + struct S2{ void do_smth( S1 s1=S1() ); }; - + BOOST_PYTHON_MODULE( ... ){ using namespace boost::python; - + class_< S2 >( "S2" ) .def( "do_smth", &S2::do_smth, ( arg("s1")=S1() ) ); - + class_< S1 >( "S1" ) .def( "do_smth", &S1::do_smth, ( arg("s2")=object() ) ); - + } -The good news is that it is very easy to identify the problem: the module could -not be loaded. The main reason is that expression ``arg("s1")=S1()`` requires -``S1`` struct to be registered. `GCC-XML`_ reports default arguments as strings. -`Py++`_ doesn't have enough information to generate code with the right class +The good news is that it is very easy to identify the problem: the module could +not be loaded. The main reason is that expression ``arg("s1")=S1()`` requires +``S1`` struct to be registered. `GCC-XML`_ reports default arguments as strings. +`Py++`_ doesn't have enough information to generate code with the right class registration order. In this case you have to instruct `Py++`_ to use macros: .. code-block:: Python - import module_builde - + import module_builder + mb = module_builder.module_builder_t( ... ) s2 = mb.class_( "S2" ) s2.member_function( "do_smth" ).use_overload_macro = True @@ -126,11 +126,11 @@ struct S1; struct S2; - + struct S1{ S1( S2* s2=0 ); }; - + struct S2{ S2( S1 s1=S1() ); }; Modified: pyplusplus_dev/docs/documentation/functions/overloading.rest =================================================================== --- pyplusplus_dev/docs/documentation/functions/overloading.rest 2006-12-13 08:16:21 UTC (rev 796) +++ pyplusplus_dev/docs/documentation/functions/overloading.rest 2006-12-13 22:12:02 UTC (rev 797) @@ -21,12 +21,12 @@ { return true; } - + bool f(int a, double b) { return true; } - + bool f(int a, double b, char c) { return true; @@ -49,18 +49,18 @@ .. code-block:: C++ namespace bp = boost::python; - + BOOST_PYTHON_MODULE(pyplusplus){ - bp::class_< X >( "X" ) - .def( + bp::class_< X >( "X" ) + .def( "f" , (bool ( ::X::* )( int ) )( &::X::f ) - , ( bp::arg("a") ) ) - .def( + , ( bp::arg("a") ) ) + .def( "f" , (bool ( ::X::* )( int,double ) )( &::X::f ) - , ( bp::arg("a"), bp::arg("b") ) ) - .def( + , ( bp::arg("a"), bp::arg("b") ) ) + .def( "f" , (bool ( ::X::* )( int,double,char ) )( &::X::f ) , ( bp::arg("a"), bp::arg("b"), bp::arg("c") ) ); @@ -85,45 +85,45 @@ .. code-block:: C++ struct Y{ - + void do_smth( int ); - + template< class T> void do_smth( T t ); - + }; If you didn't instantiate( use ) ``do_smth`` member function, than `GCC-XML`_ -will not report it. As a result, `Py++`_ will not be aware of the fact that +will not report it. As a result, `Py++`_ will not be aware of the fact that ``do_smth`` is an overloaded function. To make the long story short, the generated -code will not compile. You have to instruct `Py++`_ to generate code, which +code will not compile. You have to instruct `Py++`_ to generate code, which contains function type: .. code-block:: Python from pyplusplus import module_builder - + mb = module_builder.module_builder_t( ... ) y = mb.class_( 'Y' ) y.member_function( 'do_smth' ).create_with_signature = True #------------------------------^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Every `Py++`_ class, which describes C++ function\\operator has ``create_with_signature`` -property. You have to set it to ``True``. Default value of the property is +property. You have to set it to ``True``. Default value of the property is computed. If the exported function is overloaded, then its value is ``True`` otherwise it will be ``False``. Do nothing approach weakness ---------------------------- -Code modification - the weakness of the "do nothing" approach. We live in the -dynamic world. You can create bindings for a project, but a month letter, the -project developers will add a new function to the exported class. Lets assume -that the new function will introduce overloading. If ``create_with_signature`` -has ``False`` as a value, than the previously generated code will not compile -and you will have to run code generator one more time. +Code modification - the weakness of the "do nothing" approach. We live in the +dynamic world. You can create bindings for a project, but a month letter, the +project developers will add a new function to the exported class. Lets assume +that the new function will introduce overloading. If ``create_with_signature`` +has ``False`` as a value, than the previously generated code will not compile +and you will have to run code generator one more time. -Consider to explicitly set ``create_with_signature`` to ``True``. It will save +Consider to explicitly set ``create_with_signature`` to ``True``. It will save your and your users time in future. .. code-block:: Python @@ -136,7 +136,7 @@ Overloading using macros ------------------------ -`Boost.Python`_ provides two macros, which help you to deal with overloaded +`Boost.Python`_ provides two macros, which help you to deal with overloaded functions: * ``BOOST_PYTHON_FUNCTION_OVERLOADS`` @@ -152,12 +152,12 @@ .. code-block:: Python import module_builder - + mb = module_builder.module_builder_t( ... ) x = mb.class_( "X" ) x.member_functions( "f" ).use_overload_macro = True #-------------------------^^^^^^^^^^^^^^^^^^^^^^^^^ - + Member and free functions declaration classes have ``use_overload_macro`` property. The default value of the property is ``False``. Modified: pyplusplus_dev/docs/documentation/functions/registration_order.rest =================================================================== --- pyplusplus_dev/docs/documentation/functions/registration_order.rest 2006-12-13 08:16:21 UTC (rev 796) +++ pyplusplus_dev/docs/documentation/functions/registration_order.rest 2006-12-13 22:12:02 UTC (rev 797) @@ -8,10 +8,10 @@ Introduction ------------ -"... I would very much like to pass bools from Python to C++ and have them -accepted as bools. However I cannot seem to do this. ..." +"... I would very much like to pass booleans from Python to C++ and have them +accepted as boils. However I cannot seem to do this. ..." -"... My class has 2 "append" functions. The first one, has single argument with +"... My class has 2 "append" functions. The first one, has single argument with type "const char*", the second one also has single argument with type "char". It seems, that I am not able to call the first function. ..." @@ -26,30 +26,30 @@ struct tester_t{ tester_t() {} - + const char* append(const char*) { return "append(const char *)"; } - + const char* append(const char) { return "append(const char)"; } - + const char* do_smth( bool ) { return "do_smth( bool )"; } - + const char* do_smth( int ) { return "do_smth( int )"; } }; -`Py++`_ generates code, that register functions in the order they apper in the +`Py++`_ generates code, that register functions in the order they appear in the source code: .. code-block:: C++ namespace bp = boost::python; - + BOOST_PYTHON_MODULE(my_module){ - bp::class_< tester_t >( "tester_t" ) - .def( bp::init< >() ) + bp::class_< tester_t >( "tester_t" ) + .def( bp::init< >() ) .def( "append" , (char const * ( ::tester_t::* )( char const * ) )( &::tester_t::append ) ) .def( "append" @@ -73,7 +73,7 @@ print tester.do_smth( True ) print tester.do_smth( 10 ) print tester.append( "Hello world!" ) - + ? The output is: @@ -84,8 +84,8 @@ append(const char) -Unexpected, right? The registration order of exposed overloaded functions is -important. `Boost.Python`_ tries overloads in reverse order of definition. +Unexpected, right? The registration order of exposed overloaded functions is +important. `Boost.Python`_ tries overloads in reverse order of definition. If I understand right, `Boost.Python`_ tries to match in reverse order the overloaded functions, if it can convert `Python`_ arguments to C++ ones, it does @@ -94,7 +94,7 @@ Now, when you understand the behaviour, it should be pretty simple to provide a correct functionality: -1. You can change alias of the function, by mangling the type of the argument +1. You can change alias of the function, by mangling the type of the argument into it: .. code-block:: Python @@ -105,38 +105,38 @@ 2. You can reorder the declarations within the source file. -3. You can ask `Py++`_ to generate code, which takes into account the order of +3. You can ask `Py++`_ to generate code, which takes into account the order of declarations: - + .. code-block:: Python - + from pyplusplus.module_creator import sort_algorithms - + sort_algorithms.USE_CALLDEF_ORGANIZER = True # The functionality is available from version 0.8.3 - + 4. The last and the perfect solution. `Py++`_ will let you know, when your code - has such problem. The functionality is available from version 0.8.3. After - this you can change the aliases of the functions. The third step is to create + has such problem. The functionality is available from version 0.8.3. After + this you can change the aliases of the functions. The third step is to create small "dispatch" function in Python: - + .. code-block:: Python - + import my_module - + def tester_t_do_smth( self, value ): if isinstance( value, bool ): self.do_smth_bool( value ): else: self.do_smth_int( value ) - + tester_t.do_smth = tester_t_do_smth - The tehnique showen here described pretty good in `Boost.Python`_ + The technique shown here described pretty good in `Boost.Python`_ `Extending Wrapped Objects in Python tutorials`_ . May be in future, `Py++`_ will generate this code for you. Anyway, if you have - a lot of use cases like this consider to generate `Python`_ code and not to + a lot of use cases like this consider to generate `Python`_ code and not to write it manually. .. _`Extending Wrapped Objects in Python tutorials` : http://boost.org/libs/python/doc/tutorial/doc/html/python/techniques.html#python.extending_wrapped_objects_in_python Modified: pyplusplus_dev/docs/documentation/functions/transformation/built_in/built_in.rest =================================================================== --- pyplusplus_dev/docs/documentation/functions/transformation/built_in/built_in.rest 2006-12-13 08:16:21 UTC (rev 796) +++ pyplusplus_dev/docs/documentation/functions/transformation/built_in/built_in.rest 2006-12-13 22:12:02 UTC (rev 797) @@ -20,11 +20,11 @@ * ``output_static_array`` -The set doesn't cover all common use cases, but it will grow with every new -version of `Py++`_. If you created your own transformer consider to contribute +The set doesn't cover all common use cases, but it will grow with every new +version of `Py++`_. If you created your own transformer consider to contribute it to the project. -I suggest you to start reading `output`_ transformer. It is pretty simple and +I suggest you to start reading `output`_ transformer. It is pretty simple and well explained. .. _`output` : ./output.html @@ -32,10 +32,10 @@ All built-in transformers could be applied on any function, except constructors and pure virtual functions. The support for them be added in future releases. -You don't have to warry about call policies. You can set the call policy and +You don't have to worry about call policies. You can set the call policy and `Py++`_ will generate the correct code. -You don't have to warry about the number of arguments, transformers or return +You don't have to worry about the number of arguments, transformers or return value. `Py++`_ handles pretty well such use cases. Modified: pyplusplus_dev/docs/documentation/functions/transformation/built_in/inout.rest =================================================================== --- pyplusplus_dev/docs/documentation/functions/transformation/built_in/inout.rest 2006-12-13 08:16:21 UTC (rev 796) +++ pyplusplus_dev/docs/documentation/functions/transformation/built_in/inout.rest 2006-12-13 22:12:02 UTC (rev 797) @@ -9,8 +9,8 @@ ---------- ``inout`` transformer is a combination of `input`_ and `output`_ transformers. -It removes a "reference" type from the function argument and then adds the -"returned", by the original function, value to the return statement of the +It removes a "reference" type from the function argument and then adds the +"returned", by the original function, value to the return statement of the function-wrapper. ``inout`` transformer takes as argument name or index of the original function @@ -27,20 +27,20 @@ .. code-block:: C++ #include <string> - + inline void hello_world( std::string& hw ){ hw = "hello world!"; } Lets say that you need to expose ``hello_world`` function. As you know -``std::string`` is mapped to `Python`_ string, which is immutable type, so you +``std::string`` is mapped to `Python`_ string, which is immutable type, so you have to create small wrapper for the function. Next `Py++`_ code does it for you: .. code-block:: Python from pyplusplus import module_builder from pyplusplus import function_transformers as FT - + mb = module_builder.module_builder_t( ... ) hw = mb.mem_fun( 'hello_world' ) hw.add_transformation( FT.inout(0) ) @@ -50,11 +50,11 @@ .. code-block:: C++ namespace bp = boost::python; - + static boost::python::object hello_world_a3478182294a057b61508c30b1361318( ::std::string hw ){ ::hello_world(hw); return bp::object( hw ); - } + } BOOST_PYTHON_MODULE(...){ ... Modified: pyplusplus_dev/docs/documentation/functions/transformation/built_in/input.rest =================================================================== --- pyplusplus_dev/docs/documentation/functions/transformation/built_in/input.rest 2006-12-13 08:16:21 UTC (rev 796) +++ pyplusplus_dev/docs/documentation/functions/transformation/built_in/input.rest 2006-12-13 22:12:02 UTC (rev 797) @@ -21,20 +21,20 @@ .. code-block:: C++ #include <string> - + inline void hello_world( std::string& hw ){ hw = "hello world!"; } Lets say that you need to expose ``hello_world`` function. As you know -``std::string`` is mapped to `Python`_ string, which is immutable type, so you +``std::string`` is mapped to `Python`_ string, which is immutable type, so you have to create small wrapper for the function. Next `Py++`_ code does it for you: .. code-block:: Python from pyplusplus import module_builder from pyplusplus import function_transformers as FT - + mb = module_builder.module_builder_t( ... ) hw = mb.mem_fun( 'hello_world' ) hw.add_transformation( FT.input(0) ) @@ -44,7 +44,7 @@ .. code-block:: C++ namespace bp = boost::python; - + static void hello_world_a3478182294a057b61508c30b1361318( ::std::string hw ){ ::hello_world(hw); } Modified: pyplusplus_dev/docs/documentation/functions/transformation/built_in/input_static_array.rest =================================================================== --- pyplusplus_dev/docs/documentation/functions/transformation/built_in/input_static_array.rest 2006-12-13 08:16:21 UTC (rev 796) +++ pyplusplus_dev/docs/documentation/functions/transformation/built_in/input_static_array.rest 2006-12-13 22:12:02 UTC (rev 797) @@ -8,12 +8,12 @@ Definition ---------- -"input_static_array" transformer works on native static arrays. It handles the -translation between `Python`_ object, passed as argument that represent a sequence, +"input_static_array" transformer works on native static arrays. It handles the +translation between `Python`_ object, passed as argument that represent a sequence, and the array. Size of array should be predefined. -"input_static_array" transformer takes as first argument name or index of the -original function argument. The argument should have "array" or "pointer" type. +"input_static_array" transformer takes as first argument name or index of the +original function argument. The argument should have "array" or "pointer" type. The second argument should an integer value, that represents array size. ------- @@ -23,13 +23,13 @@ .. code-block:: C++ struct vector3{ - + void init( int values[3] ){ x = values[0]; y = values[1]; z = values[2]; } - + int x,y,z; }; @@ -40,7 +40,7 @@ from pyplusplus import module_builder from pyplusplus import function_transformers as FT - + mb = module_builder.module_builder_t( ... ) v3 = mb.class_( 'vector3' ) v3.mem_fun( 'init' ).add_transformation( FT.input_static_array( 0, 3 ) ) @@ -50,24 +50,24 @@ .. code-block:: C++ #include "__convenience.pypp.hpp" //Py++ header file, which contains few convenience function - + namespace bp = boost::python; - + static void init_418e52f4a347efa6b7e123b96f32a73c( ::ft::vector3 & inst, boost::python::object values ){ int native_values[3]; pyplus_conv::ensure_uniform_sequence< int >( values, 3 ); pyplus_conv::copy_sequence( values, pyplus_conv::array_inserter( native_values, 3 ) ); inst.init(native_values); } - + BOOST_PYTHON_MODULE(...){ ... - bp::class_< ft::vector3 >( "vector3", "documentation" ) + bp::class_< ft::vector3 >( "vector3", "documentation" ) .def( "init" , &init_418e52f4a347efa6b7e123b96f32a73c , ( bp::arg("inst"), bp::arg("values") ) ) - .def_readwrite( "x", &ft::vector3::x ) - .def_readwrite( "y", &ft::vector3::y ) + .def_readwrite( "x", &ft::vector3::x ) + .def_readwrite( "y", &ft::vector3::y ) .def_readwrite( "z", &ft::vector3::z ); } Modified: pyplusplus_dev/docs/documentation/functions/transformation/built_in/output.rest =================================================================== --- pyplusplus_dev/docs/documentation/functions/transformation/built_in/output.rest 2006-12-13 08:16:21 UTC (rev 796) +++ pyplusplus_dev/docs/documentation/functions/transformation/built_in/output.rest 2006-12-13 22:12:02 UTC (rev 797) @@ -9,7 +9,7 @@ ---------- "output" transformer removes an argument from the function definition and adds -the "returned", by the original function, value to the return statement of the +the "returned", by the original function, value to the return statement of the function-wrapper. "output" transformer takes as argument name or index of the original function @@ -23,20 +23,20 @@ .. code-block:: C++ #include <string> - + inline void hello_world( std::string& hw ){ hw = "hello world!"; } Lets say that you need to expose ``hello_world`` function. As you know -``std::string`` is mapped to `Python`_ string, which is immutable type, so you +``std::string`` is mapped to `Python`_ string, which is immutable type, so you have to create small wrapper for the function. Next `Py++`_ code does it for you: .. code-block:: Python from pyplusplus import module_builder from pyplusplus import function_transformers as FT - + mb = module_builder.module_builder_t( ... ) hw = mb.mem_fun( 'hello_world' ) hw.add_transformation( FT.output(0) ) @@ -46,13 +46,13 @@ .. code-block:: C++ namespace bp = boost::python; - + static boost::python::object hello_world_a3478182294a057b61508c30b1361318( ){ std::string hw2; ::hello_world(hw2); return bp::object( hw2 ); } - + BOOST_PYTHON_MODULE(...){ ... bp::def( "hello_world", &hello_world_a3478182294a057b61508c30b1361318 ); Modified: pyplusplus_dev/docs/documentation/functions/transformation/built_in/output_static_array.rest =================================================================== --- pyplusplus_dev/docs/documentation/functions/transformation/built_in/output_static_array.rest 2006-12-13 08:16:21 UTC (rev 796) +++ pyplusplus_dev/docs/documentation/functions/transformation/built_in/output_static_array.rest 2006-12-13 22:12:02 UTC (rev 797) @@ -8,11 +8,11 @@ Definition ---------- -"output_static_array" transformer works on native static arrays. It handles the +"output_static_array" transformer works on native static arrays. It handles the translation between array and `Python`_ list object. Size of array should be predefined. -"output_static_array" transformer takes as first argument name or index of the -original function argument. The argument should have "array" or "pointer" type. +"output_static_array" transformer takes as first argument name or index of the +original function argument. The argument should have "array" or "pointer" type. The second argument should an integer value, that represents array size. ------- @@ -22,13 +22,13 @@ .. code-block:: C++ struct vector3{ - + void get_values( int values[3] ){ values[0] = x; values[1] = y; values[2] = z; - } - + } + int x,y,z; }; @@ -39,7 +39,7 @@ from pyplusplus import module_builder from pyplusplus import function_transformers as FT - + mb = module_builder.module_builder_t( ... ) v3 = mb.class_( 'vector3' ) v3.mem_fun( 'get_values' ).add_transformation( FT.output_static_array( 0, 3 ) ) @@ -49,9 +49,9 @@ .. code-block:: C++ #include "__convenience.pypp.hpp" //Py++ header file, which contains few convenience function - + namespace bp = boost::python; - + static boost::python::object get_values_22786c66e5973b70f714e7662e2aecd2( ::ft::vector3 & inst ){ int native_values[3]; boost::python::list py_values; @@ -59,15 +59,15 @@ pyplus_conv::copy_container( native_values, native_values + 3, pyplus_conv::list_inserter( py_values ) ); return bp::object( py_values ); } - + ... [truncated message content] |
From: <rom...@us...> - 2006-12-13 08:16:23
|
Revision: 796 http://svn.sourceforge.net/pygccxml/?rev=796&view=rev Author: roman_yakovenko Date: 2006-12-13 00:16:21 -0800 (Wed, 13 Dec 2006) Log Message: ----------- small refactoring to allow better control over generated properties Modified Paths: -------------- pyplusplus_dev/pyplusplus/decl_wrappers/properties.py Modified: pyplusplus_dev/pyplusplus/decl_wrappers/properties.py =================================================================== --- pyplusplus_dev/pyplusplus/decl_wrappers/properties.py 2006-12-11 08:19:39 UTC (rev 795) +++ pyplusplus_dev/pyplusplus/decl_wrappers/properties.py 2006-12-13 08:16:21 UTC (rev 796) @@ -9,6 +9,10 @@ from pygccxml import declarations class property_t( object ): + """This class describes a "property". + + It keeps + """ def __init__( self, name, fget, fset=None, doc='', is_static=False ): self._name = name self._fget = fget @@ -42,7 +46,7 @@ if self.fset: desc.append( ', ' ) desc.append( 'fset=%s' % declarations.full_name( self.fset ) ) - return "property [%s]"% ''.join( desc ) + return 'property "%s"[%s]' % ( self.name, ''.join( desc ) ) class property_recognizer_i(object): @@ -55,6 +59,73 @@ def create_read_only_property( sefl, fget ): raise NotImplementedError() + def is_accessor( self, mem_fun ): + if mem_fun.ignore: + return False + if mem_fun.access_type != 'public': + return False + if mem_fun.has_static: + return False #TODO: should be supported + if mem_fun.virtuality == declarations.VIRTUALITY_TYPES.PURE_VIRTUAL: + return False + return True + + def is_getter( self, mem_fun ): + if mem_fun.arguments: + return False + if declarations.is_void( mem_fun.return_type ): + return False + if not mem_fun.has_const: + return False + if mem_fun.overloads: + return False + return True + + def is_setter( self, mem_fun ): + if len( mem_fun.arguments ) != 1: + return False + if not declarations.is_void( mem_fun.return_type ): + return False + if mem_fun.has_const: + return False + if mem_fun.overloads: + return False + return True + + def __get_accessors( self, mem_funs ): + getters = [] + setters = [] + for mem_fun in mem_funs: + if not self.is_accessor( mem_fun ): + continue + elif self.is_getter( mem_fun ): + getters.append( mem_fun ) + elif self.is_setter( mem_fun ): + setters.append( mem_fun ) + else: + continue + return ( getters, setters ) + + def class_accessors( self, cls ): + return self.__get_accessors( cls.mem_funs( recursive=False, allow_empty=True ) ) + + def base_classes( self, cls ): + base_clss = [] + for hierarchy_info in cls.recursive_bases: + if hierarchy_info.related_class.ignore: #don't scan excluded classes + continue + if 'public' != hierarchy_info.access_type: #don't scan non public hierarchy + continue + base_clss.append( hierarchy_info.related_class ) + return base_clss + + def inherited_accessors( self, cls ): + mem_funs = [] + map( lambda base_cls: mem_funs.extend( base_cls.mem_funs( recursive=False, allow_empty=True ) ) + , self.base_classes( cls ) ) + return self.__get_accessors( mem_funs ) + + class name_based_recognizer_t( property_recognizer_i ): def __init__( self ): property_recognizer_i.__init__( self ) @@ -174,59 +245,33 @@ recognizer = name_based_recognizer_t() self.recognizer = recognizer self.exclude_accessors = exclude_accessors - self.getters, self.setters \ - = self.__get_accessors( cls.member_functions( recursive=False, allow_empty=True ) ) + self.getters, self.setters = recognizer.class_accessors( cls ) + self.inherited_getters, self.inherited_setters = recognizer.inherited_accessors( cls ) - inherted_mem_funs = [] - for hierarchy_info in cls.recursive_bases: - if hierarchy_info.related_class.ignore: #don't scan excluded classes - continue - if 'public' != hierarchy_info.access_type: #don't scan non public hierarchy - continue - base_cls = hierarchy_info.related_class - inherted_mem_funs.extend( base_cls.member_functions( recursive=False, allow_empty=True ) ) + def __is_legal_property( self, property_ ): + """property is legal if it does not hide other declarations""" + def is_relevant( decl ): + irrelevant_classes = ( declarations.constructor_t + , declarations.destructor_t + , declarations.typedef_t ) + + if isinstance( decl, irrelevant_classes ): + return False + if decl.ignore: + return False + if decl.alias != property_.name: + return False + if self.exclude_accessors \ + and ( decl is property_.fget or decl is property_.fset ): + return False + return True - self.inherited_getters, self.inherited_setters \ - = self.__get_accessors( inherted_mem_funs ) + relevant_decls = [] + relevant_classes = [self.cls] + self.recognizer.base_classes( self.cls ) + for cls in relevant_classes: + relevant_decls.extend( cls.decls( is_relevant, recursive=False, allow_empty=True ) ) + return not bool( relevant_decls ) - def __is_getter( self, mem_fun ): - if mem_fun.arguments: - return False - if declarations.is_void( mem_fun.return_type ): - return False - if not mem_fun.has_const: - return False - return True - - def __is_setter( self, mem_fun ): - if len( mem_fun.arguments ) != 1: - return False - if not declarations.is_void( mem_fun.return_type ): - return False - if mem_fun.has_const: - return False - return True - - def __get_accessors( self, mem_funs ): - getters = [] - setters = [] - for mem_fun in mem_funs: - if mem_fun.ignore: - continue - elif mem_fun.access_type != 'public': - continue - elif mem_fun.has_static: - continue #TODO: should be supported - elif mem_fun.virtuality == declarations.VIRTUALITY_TYPES.PURE_VIRTUAL: - continue - elif self.__is_getter( mem_fun ): - getters.append( mem_fun ) - elif self.__is_setter( mem_fun ): - setters.append( mem_fun ) - else: - continue - return ( getters, setters ) - def find_properties( self, getters, setters, used_getters, used_setters ): properties = [] for fget in getters: @@ -236,13 +281,13 @@ if fset in used_setters: continue property_ = self.recognizer.create_property( fget, fset ) - if property_: + if property_ and self.__is_legal_property( property_ ): used_getters.add( fget ) used_setters.add( fset ) properties.append( property_ ) break return properties - + def __call__( self ): used_getters = set() used_setters = set() @@ -261,7 +306,7 @@ if fget in used_getters: continue property_ = self.recognizer.create_read_only_property( fget ) - if property_: + if property_ and self.__is_legal_property( property_ ): used_getters.add( fget ) properties.append( property_ ) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <rom...@us...> - 2006-12-11 08:19:39
|
Revision: 795 http://svn.sourceforge.net/pygccxml/?rev=795&view=rev Author: roman_yakovenko Date: 2006-12-11 00:19:39 -0800 (Mon, 11 Dec 2006) Log Message: ----------- updating documentation Modified Paths: -------------- pyplusplus_dev/docs/documentation/functions/transformation/built_in/built_in.rest Added Paths: ----------- pyplusplus_dev/docs/documentation/functions/transformation/built_in/input_static_array.rest pyplusplus_dev/docs/documentation/functions/transformation/built_in/output_static_array.rest Modified: pyplusplus_dev/docs/documentation/functions/transformation/built_in/built_in.rest =================================================================== --- pyplusplus_dev/docs/documentation/functions/transformation/built_in/built_in.rest 2006-12-11 07:07:41 UTC (rev 794) +++ pyplusplus_dev/docs/documentation/functions/transformation/built_in/built_in.rest 2006-12-11 08:19:39 UTC (rev 795) @@ -29,8 +29,8 @@ .. _`output` : ./output.html -All built-in transformers could be applied on any function, except constructors. -The support for constructors will be added in future releases. +All built-in transformers could be applied on any function, except constructors +and pure virtual functions. The support for them be added in future releases. You don't have to warry about call policies. You can set the call policy and `Py++`_ will generate the correct code. Added: pyplusplus_dev/docs/documentation/functions/transformation/built_in/input_static_array.rest =================================================================== --- pyplusplus_dev/docs/documentation/functions/transformation/built_in/input_static_array.rest (rev 0) +++ pyplusplus_dev/docs/documentation/functions/transformation/built_in/input_static_array.rest 2006-12-11 08:19:39 UTC (rev 795) @@ -0,0 +1,85 @@ +================================== +``input_static_array`` transformer +================================== + +.. contents:: Table of contents + +---------- +Definition +---------- + +"input_static_array" transformer works on native static arrays. It handles the +translation between `Python`_ object, passed as argument that represent a sequence, +and the array. Size of array should be predefined. + +"input_static_array" transformer takes as first argument name or index of the +original function argument. The argument should have "array" or "pointer" type. +The second argument should an integer value, that represents array size. + +------- +Example +------- + +.. code-block:: C++ + + struct vector3{ + + void init( int values[3] ){ + x = values[0]; + y = values[1]; + z = values[2]; + } + + int x,y,z; + }; + +In order to expose ``init`` member function we need to create small wrapper: +Next `Py++`_ code does it for you: + + .. code-block:: Python + + from pyplusplus import module_builder + from pyplusplus import function_transformers as FT + + mb = module_builder.module_builder_t( ... ) + v3 = mb.class_( 'vector3' ) + v3.mem_fun( 'init' ).add_transformation( FT.input_static_array( 0, 3 ) ) + +What you see below is the relevant pieces of generated code: + + .. code-block:: C++ + + #include "__convenience.pypp.hpp" //Py++ header file, which contains few convenience function + + namespace bp = boost::python; + + static void init_418e52f4a347efa6b7e123b96f32a73c( ::ft::vector3 & inst, boost::python::object values ){ + int native_values[3]; + pyplus_conv::ensure_uniform_sequence< int >( values, 3 ); + pyplus_conv::copy_sequence( values, pyplus_conv::array_inserter( native_values, 3 ) ); + inst.init(native_values); + } + + BOOST_PYTHON_MODULE(...){ + ... + bp::class_< ft::vector3 >( "vector3", "documentation" ) + .def( "init" + , &init_418e52f4a347efa6b7e123b96f32a73c + , ( bp::arg("inst"), bp::arg("values") ) ) + .def_readwrite( "x", &ft::vector3::x ) + .def_readwrite( "y", &ft::vector3::y ) + .def_readwrite( "z", &ft::vector3::z ); + } + +.. _`Py++` : ./../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: Added: pyplusplus_dev/docs/documentation/functions/transformation/built_in/output_static_array.rest =================================================================== --- pyplusplus_dev/docs/documentation/functions/transformation/built_in/output_static_array.rest (rev 0) +++ pyplusplus_dev/docs/documentation/functions/transformation/built_in/output_static_array.rest 2006-12-11 08:19:39 UTC (rev 795) @@ -0,0 +1,85 @@ +=================================== +``output_static_array`` transformer +=================================== + +.. contents:: Table of contents + +---------- +Definition +---------- + +"output_static_array" transformer works on native static arrays. It handles the +translation between array and `Python`_ list object. Size of array should be predefined. + +"output_static_array" transformer takes as first argument name or index of the +original function argument. The argument should have "array" or "pointer" type. +The second argument should an integer value, that represents array size. + +------- +Example +------- + +.. code-block:: C++ + + struct vector3{ + + void get_values( int values[3] ){ + values[0] = x; + values[1] = y; + values[2] = z; + } + + int x,y,z; + }; + +In order to expose ``get_values`` member function we need to create small wrapper: +Next `Py++`_ code does it for you: + + .. code-block:: Python + + from pyplusplus import module_builder + from pyplusplus import function_transformers as FT + + mb = module_builder.module_builder_t( ... ) + v3 = mb.class_( 'vector3' ) + v3.mem_fun( 'get_values' ).add_transformation( FT.output_static_array( 0, 3 ) ) + +What you see below is the relevant pieces of generated code: + + .. code-block:: C++ + + #include "__convenience.pypp.hpp" //Py++ header file, which contains few convenience function + + namespace bp = boost::python; + + static boost::python::object get_values_22786c66e5973b70f714e7662e2aecd2( ::ft::vector3 & inst ){ + int native_values[3]; + boost::python::list py_values; + inst.get_values(native_values); + pyplus_conv::copy_container( native_values, native_values + 3, pyplus_conv::list_inserter( py_values ) ); + return bp::object( py_values ); + } + + BOOST_PYTHON_MODULE(...){ + ... + bp::class_< ft::vector3 >( "vector3", "documentation" ) + .def( "get_values" + , &get_values_22786c66e5973b70f714e7662e2aecd2 + , ( bp::arg("inst") ) ) + .def_readwrite( "x", &ft::vector3::x ) + .def_readwrite( "y", &ft::vector3::y ) + .def_readwrite( "z", &ft::vector3::z ); + } + +.. _`Py++` : ./../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: This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <rom...@us...> - 2006-12-11 07:07:44
|
Revision: 794 http://svn.sourceforge.net/pygccxml/?rev=794&view=rev Author: roman_yakovenko Date: 2006-12-10 23:07:41 -0800 (Sun, 10 Dec 2006) Log Message: ----------- updating documentation Modified Paths: -------------- pyplusplus_dev/docs/documentation/functions/transformation/built_in/built_in.rest pyplusplus_dev/docs/documentation/functions/transformation/name_mangling.rest pyplusplus_dev/docs/documentation/functions/transformation/terminology.rest pyplusplus_dev/docs/peps/peps_index.rest pyplusplus_dev/docs/pyplusplus.rest Added Paths: ----------- pyplusplus_dev/docs/documentation/functions/transformation/custom/ pyplusplus_dev/docs/documentation/functions/transformation/custom/custom.rest pyplusplus_dev/docs/documentation/functions/transformation/custom/www_configuration.py Removed Paths: ------------- pyplusplus_dev/docs/peps/function_transformation.rest Modified: pyplusplus_dev/docs/documentation/functions/transformation/built_in/built_in.rest =================================================================== --- pyplusplus_dev/docs/documentation/functions/transformation/built_in/built_in.rest 2006-12-10 20:42:12 UTC (rev 793) +++ pyplusplus_dev/docs/documentation/functions/transformation/built_in/built_in.rest 2006-12-11 07:07:41 UTC (rev 794) @@ -16,24 +16,29 @@ * ``inout`` -* ``input_array`` +* ``input_static_array`` -* ``output_array`` +* ``output_static_array`` The set doesn't cover all common use cases, but it will grow with every new version of `Py++`_. If you created your own transformer consider to contribute it to the project. -I suggest you to start reading ``output`` transformer. It is pretty simple and +I suggest you to start reading `output`_ transformer. It is pretty simple and well explained. +.. _`output` : ./output.html + All built-in transformers could be applied on any function, except constructors. The support for constructors will be added in future releases. You don't have to warry about call policies. You can set the call policy and -`Py++`_ will generate correct code. +`Py++`_ will generate the correct code. +You don't have to warry about the number of arguments, transformers or return +value. `Py++`_ handles pretty well such use cases. + .. _`Py++` : ./../pyplusplus.html .. _`Boost.Python`: http://www.boost.org/libs/python/doc/index.html .. _`Python`: http://www.python.org Added: pyplusplus_dev/docs/documentation/functions/transformation/custom/custom.rest =================================================================== --- pyplusplus_dev/docs/documentation/functions/transformation/custom/custom.rest (rev 0) +++ pyplusplus_dev/docs/documentation/functions/transformation/custom/custom.rest 2006-12-11 07:07:41 UTC (rev 794) @@ -0,0 +1,40 @@ +========================= +User defined transformers +========================= + +.. contents:: Table of contents + +---- +KISS +---- + +KISS - Keep It Simple Stupid! + +The main goal of the feature: to provide relatively simple way to implement +custom transformers. More over, all `built-in transformers`_ implemented as is +they were custom transformers. + +----------- +How to ...? +----------- + +Unfortunatelly I don't have enough time to write a complete documentation :-(. +Meanwhile fill free to `contact me`_. You also can take a look on `built-in transformers`_ +implementation. + +.. _`contact me` : ../../../../links.html#id5 +.. _`built-in transformers` : ../built_in/built_in.html + + +.. _`Py++` : ./../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: Added: pyplusplus_dev/docs/documentation/functions/transformation/custom/www_configuration.py =================================================================== --- pyplusplus_dev/docs/documentation/functions/transformation/custom/www_configuration.py (rev 0) +++ pyplusplus_dev/docs/documentation/functions/transformation/custom/www_configuration.py 2006-12-11 07:07:41 UTC (rev 794) @@ -0,0 +1,4 @@ +name = 'custom transformers' +#main_html_file = 'index.html' + +names = { } Modified: pyplusplus_dev/docs/documentation/functions/transformation/name_mangling.rest =================================================================== --- pyplusplus_dev/docs/documentation/functions/transformation/name_mangling.rest 2006-12-10 20:42:12 UTC (rev 793) +++ pyplusplus_dev/docs/documentation/functions/transformation/name_mangling.rest 2006-12-11 07:07:41 UTC (rev 794) @@ -59,7 +59,9 @@ function The good news - they will not be changed between different runs of the code -generator. If you are exposing an overloaded function, than `Py++`_ uses the ugly +generator. + +If you are exposing an overloaded function, in that case `Py++`_ uses the ugly function-wrapper name as an alias. It is up to you to change the alias: .. code-block:: Python Modified: pyplusplus_dev/docs/documentation/functions/transformation/terminology.rest =================================================================== --- pyplusplus_dev/docs/documentation/functions/transformation/terminology.rest 2006-12-10 20:42:12 UTC (rev 793) +++ pyplusplus_dev/docs/documentation/functions/transformation/terminology.rest 2006-12-11 07:07:41 UTC (rev 794) @@ -4,7 +4,7 @@ .. contents:: Table of contents -* Function transformation +**Function transformation** `Py++`_ sub-system\\framework, which allows you to create function wrappers and to keep smile. @@ -12,21 +12,21 @@ The operation of changing one function into another in accordance with some rules. Especially: a change of return type and\\or arguments and their mapping to the original ones. - -* Function wrapper ( or just wrapper ) +**Function wrapper** ( or just wrapper ) + C++ function, which calls some other function. -* Immutable type +**Immutable type** An instance of this type could not be modified after construction -* Transformer +**Transformer** An object that applies predefined set of rules on a function, during function-wrapper construction process. -* Function alias ( or just alias ) +**Function alias** ( or just alias ) Name under which `Python`_ users see the exposed function Deleted: pyplusplus_dev/docs/peps/function_transformation.rest =================================================================== --- pyplusplus_dev/docs/peps/function_transformation.rest 2006-12-10 20:42:12 UTC (rev 793) +++ pyplusplus_dev/docs/peps/function_transformation.rest 2006-12-11 07:07:41 UTC (rev 794) @@ -1,333 +0,0 @@ -======================== -Function transformation -======================== - -.. contents:: Table of contents - -------------------- -What is useful for? -------------------- - -https://realityforge.vrsource.org/view/PyppApi/CodeInserter gives a nice introduction -and the problem description. Please read it. - ------------ -Terminology ------------ - -Lets say that we have a function ``f``: - -:: - - f = R f( A0 a0, ..., AN an ) - -``R`` and ``A*`` represent an arbitrary C++ types. What we want is to create -another function ``ft`` (transformed): - -:: - - ft = RT ft( AT0 at0, ..., ATM atm ) - -such that will do an additional work before and after ``f`` call. - -Definitions ------------ - -*Transformation* - process that defines how to create transformed function from the -original one. - -For example - ``make function argument to be return value``: -:: - - f = void get_last_error( int& error ); - -:: - - ft = int get_last_error(); - -The definition of ``ft`` could look like: - -.. code-block:: C++ - - int get_last_error_transformed(){ - int error(0); - get_last_error( error ); - return error; - } - -I modified ``f`` signature and added some code before and after ``f`` call. - -*Function transformation* - group of transformations that should be applied at once -on a function. - -For example a function could have two immutable arguments, passed by reference. -Function transformation aggregates two transformations. - -A user will be able to define few function transformations for a single function. - ------------------------ -Design & implementation ------------------------ - -In the previous paragraph I introduced two new concepts: "transformation" and -"function transformation". These concepts should be presented in the solution. - - -Transformation --------------- - -Transformation class has two responsibilities: - -1. to modify function signature: - - * remove argument - * change argument type - * join arguments - * change return type - -2. to implement the transformation - -It is important to distinct between the responsibilities. Function signature -defines "interface" for a lot of services provided by `Py++`_. While the second -one is "implementation details" and should be "hidden" from the rest of the world. - -In an ideal world we would have 2 classes, one class - one responsibility. -In `Py++`_ it means that we would have ``transformation_t`` class: - -.. code-block:: Python - - class transformation_t( object ): - def __init__( self ): - pass - -.. code-block:: Python - - def check( self, function ): - "checks whether the transformation could be applied on the function or not" - raise NotImplementedError() - -.. code-block:: Python - - def signature_changes( self, function ): - "returns a list of changes that should be done on function signature" - raise NotImplementedError() - -The class logically belongs to the ``decl_wrappers`` package. The ``transformer_t`` -is the second class, which logically belongs to ``code_creators`` package: - -.. code-block:: Python - - class transformer_t( ast_visitor_t ): - def __init__( self, function, transformation ): - function is a reference to the declaration we want to apply transformation on - transformation is an instance of "concrete" transformation - -.. code-block:: Python - - def apply( self, function_body_as_tree ): - "integrates transformation code to function body" - raise NotImplementedError() - -What is ``ast_visitor_t`` and ``function_body_as_tree``. In an ideal world -concrete instance of ``transformer_t`` class would work with some kind of AST -( Abstract Syntax Tree ). Thus transformer would travel on the tree and modify it. - -Get the job done! ------------------ - -The previously described solution will not work in our, `Py++`_ developers and -users, world. There are mainly two reasons: - -1. AST approach is tooooooo complex. We don't have time to develop an AST for - representing, even limited subset of C++ expressions. Users will not have - time to learn how to use it. - -2. Class separation approach will not work too. In order to introduce new - transformation, user will have to understand the whole design of the `Py++`_ - package. - -Matthias Baas provided a "real world" solution for both problems. At first I did -not understand it, but now I appreciate it very much. It does not meant that I -agree with the his implementation. As for me he did not stress enough the -concepts within the code and more over he mixed them in different classes. - -I am going to propose another solution, which will be based on existing code. -Small re-factoring is needed. I don't expect changes in the user code. - -Proposed class: - -.. code-block:: Python - - class transformer_t( object ): - "base class for all transformation classes" - def __init__( self ): - pass - -.. code-block:: Python - - def check( self, function ): - "checks whether the transformation could be applied on the function or not" - raise NotImplementedError() - -.. code-block:: Python - - def signature_changes( self, function ): - "returns a list of changes that should be done on function signature" - raise NotImplementedError() - -.. code-block:: Python - - def apply( self, sm ): #sm is an instance of the substitution manager - "integrates transformation code into function transformation body" - raise NotImplementedError() - -Comments: - -1. ``substituion_manager_t`` class allows us to achieve same result as with AST. - he way it does it is pretty simple to explain and understand - string - substitution. - -2. ``transformer_t`` class allows user to introduce new transformations, without - understanding the whole `Py++`_ package. - -Function trasformation -~~~~~~~~~~~~~~~~~~~~~~ - -What is responcibility of the ``function_transformation_t`` class? - -1. To keep reference to transformations defined by the user. - -2. To apply every transformation on the function body. For this purpose this - class will keep instance of ``substituion_manager_t`` class. - -3. To provide interface for ``mem_fun_v_transformed_t`` and - ``mem_fun_v_transformed_wrapper_t`` code creators classes. - -4. [Nice to have]To check, whether the transformation defined by user is - applicable or not. - -Somewhere we should put "function transformation" factory. This factory will -create or give a hint to the user what transformation could\\should be applied -on the function. - -------------------------------------- -output_arg transformation example -------------------------------------- - -.. code-block:: Python - - class output_arg_t( transformer_t ): - def __init__( self, ordinal ): - self.ordinal = ordinal - -.. code-block:: Python - - def check( self, decl ): - if len( decl.arguments ) <= self.ordinal: - return user message - type_ = decl.arguments[self.ordinal].type - if not reference to immutable type: - raise user message - -.. code-block:: Python - - def signature_changes( self, decl ): - assert not self.check( decl ) - return [ remove_arg( self.ordinal ) - , add_var_to_return_value( decl.arguments[ self.ordinal ].name ] - -.. code-block:: Python - - def apply( self, sm ): - if sm is wrapper around C++ function: - sm. add declaration of variable type = decl.arguments[ self.ordinal ].type - and name = decl.arguments[ self.ordinal ].type and initial value - sm. add variable to return expression. - else: #sm is a wrapper around Python function - sm. extract value from the tuple and assign it to the argument - -.. code-block:: Python - - def output_arg( ordinal ): - return output_arg_t( ordinal ) - ------------------ -Problems to solve ------------------ - -I don't have any solution to the next problems. - -Call policies -------------- - -I am going to change a little an example, from `Boost.Python`_ tutorials: -http://www.boost.org/libs/python/doc/tutorial/doc/html/python/functions.html#python.call_policies - -.. code-block:: C++ - - //C++ code - struct Y - { - X x; Z* z; - int z_value() { return z->value(); } - }; - -.. code-block:: C++ - - X& f(Y& y, Z* z, int& error) - { - y.z = z; - return y.x; - } - -.. code-block:: C++ - - //Boost.Python code - def("f", f, return_internal_reference<1, with_custodian_and_ward<1, 2> >() ); - -What is the difference? Function ``f`` now takes 3rd argument - ``int&``. This -function could not be called from `Python`_. (Hint: numbers are immutable -objects in `Python`_ ). So in order to expose function ``f`` to `Python`_, -an user need to create a wrapper. And now he has a problem: how to wrap the function? - -I see only one solution user have to change signature of function ``f``. -Now some speculations: - -1. May be it is possible with `Boost.Python`_ library to set call policies on the - part of the return value? - - .. code-block:: C++ - - boost::tuple f_wrapper( Y& y, Z* z ){ - int error(0); - X& x = f( y, z, error ); - return boost::tuple<X&, int>( x, error ); - } - - def("f", f_wrapper, smart call policies that will work only on first element within the tuple ); - -2. May be it is possible to create Boost.Python ``object`` with life-time management - hint? - - .. code-block:: C++ - - boost::python::tuple f_wrapper( Y& y, Z* z ){ - int error(0); - X& x = f( y, z, error ); - boost::python::object x_obj( x, x is internal reference of y ); - return boost::python::make_tuple( x_obj, error ); - } - -.. _`Py++` : ./../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/peps/peps_index.rest =================================================================== --- pyplusplus_dev/docs/peps/peps_index.rest 2006-12-10 20:42:12 UTC (rev 793) +++ pyplusplus_dev/docs/peps/peps_index.rest 2006-12-11 07:07:41 UTC (rev 794) @@ -42,15 +42,6 @@ The coding itself should take something like 4 - 5 hours, including unit test. ---------------------- -Call wrapper policies ---------------------- - -Not all functions could be exposed to Python as is. This `document`__ will -explain how `Py++`_ will help users to create wrappers around those functions. - -.. __ : ./function_transformation.html - ------------------------------------------ Domain Specific Language ( DSL ) challenge ------------------------------------------ Modified: pyplusplus_dev/docs/pyplusplus.rest =================================================================== --- pyplusplus_dev/docs/pyplusplus.rest 2006-12-10 20:42:12 UTC (rev 793) +++ pyplusplus_dev/docs/pyplusplus.rest 2006-12-11 07:07:41 UTC (rev 794) @@ -127,9 +127,11 @@ ------------- * `Py++`_ support almost all features found in `Boost.Python`_ library + * `Py++`_ generates code, which will help you to understand compiler generated error messages + * `Py++`_ has few modes of writing code into files: @@ -148,13 +150,13 @@ * Your license is written at the top of every file * `Py++`_ will check the "completeness" of the bindings. It will check for you - that exposed declarations don't have references to unexposed ones. + that the exposed declarations don't have references to unexposed ones. * `Py++`_ provides enough functionality to extract source code documentation and write it as Python documentation string -* `Py++`_ provides simple and powerful framework to create wraper for functions, - which could not be exposed as is to `Python`_. +* `Py++`_ provides simple and powerful framework to create a wrapper for + functions, which could not be exposed as is to `Python`_. * ... This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <rom...@us...> - 2006-12-10 20:42:12
|
Revision: 793 http://svn.sourceforge.net/pygccxml/?rev=793&view=rev Author: roman_yakovenko Date: 2006-12-10 12:42:12 -0800 (Sun, 10 Dec 2006) Log Message: ----------- fixing small bug in FT functionality Modified Paths: -------------- pyplusplus_dev/pyplusplus/code_creators/calldef_transformed.py Modified: pyplusplus_dev/pyplusplus/code_creators/calldef_transformed.py =================================================================== --- pyplusplus_dev/pyplusplus/code_creators/calldef_transformed.py 2006-12-10 20:41:30 UTC (rev 792) +++ pyplusplus_dev/pyplusplus/code_creators/calldef_transformed.py 2006-12-10 20:42:12 UTC (rev 793) @@ -145,7 +145,7 @@ def function_type(self): return declarations.free_function_type_t( return_type=self.controller.wrapper_return_type - , arguments_types=self.controller.wrapper_args ) + , arguments_types=[ arg.type for arg in self.controller.wrapper_args ] ) def wrapper_name( self ): return self.ft.unique_name This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <rom...@us...> - 2006-12-10 20:41:33
|
Revision: 792 http://svn.sourceforge.net/pygccxml/?rev=792&view=rev Author: roman_yakovenko Date: 2006-12-10 12:41:30 -0800 (Sun, 10 Dec 2006) Log Message: ----------- adding documentation for built-in transformers Modified Paths: -------------- pyplusplus_dev/docs/documentation/functions/transformation/built_in/built_in.rest pyplusplus_dev/docs/documentation/functions/transformation/built_in/output.rest pyplusplus_dev/docs/documentation/functions/transformation/terminology.rest pyplusplus_dev/docs/documentation/functions/transformation/www_configuration.py Added Paths: ----------- pyplusplus_dev/docs/documentation/functions/transformation/built_in/inout.rest pyplusplus_dev/docs/documentation/functions/transformation/built_in/input.rest pyplusplus_dev/docs/documentation/functions/transformation/name_mangling.rest Modified: pyplusplus_dev/docs/documentation/functions/transformation/built_in/built_in.rest =================================================================== --- pyplusplus_dev/docs/documentation/functions/transformation/built_in/built_in.rest 2006-12-10 18:42:00 UTC (rev 791) +++ pyplusplus_dev/docs/documentation/functions/transformation/built_in/built_in.rest 2006-12-10 20:41:30 UTC (rev 792) @@ -20,13 +20,20 @@ * ``output_array`` -This set doesn't cover all common use cases, but it will grow with every new +The set doesn't cover all common use cases, but it will grow with every new version of `Py++`_. If you created your own transformer consider to contribute it to the project. I suggest you to start reading ``output`` transformer. It is pretty simple and well explained. +All built-in transformers could be applied on any function, except constructors. +The support for constructors will be added in future releases. + +You don't have to warry about call policies. You can set the call policy and +`Py++`_ will generate correct code. + + .. _`Py++` : ./../pyplusplus.html .. _`Boost.Python`: http://www.boost.org/libs/python/doc/index.html .. _`Python`: http://www.python.org Added: pyplusplus_dev/docs/documentation/functions/transformation/built_in/inout.rest =================================================================== --- pyplusplus_dev/docs/documentation/functions/transformation/built_in/inout.rest (rev 0) +++ pyplusplus_dev/docs/documentation/functions/transformation/built_in/inout.rest 2006-12-10 20:41:30 UTC (rev 792) @@ -0,0 +1,75 @@ +====================== +``inout`` transformer +====================== + +.. contents:: Table of contents + +---------- +Definition +---------- + +``inout`` transformer is a combination of `input`_ and `output`_ transformers. +It removes a "reference" type from the function argument and then adds the +"returned", by the original function, value to the return statement of the +function-wrapper. + +``inout`` transformer takes as argument name or index of the original function +argument. The argument should have "reference" type. Support for "pointer" type +will be added pretty soon. + +.. _`input` : input.html +.. _`output` : output.html + +------- +Example +------- + +.. code-block:: C++ + + #include <string> + + inline void hello_world( std::string& hw ){ + hw = "hello world!"; + } + +Lets say that you need to expose ``hello_world`` function. As you know +``std::string`` is mapped to `Python`_ string, which is immutable type, so you +have to create small wrapper for the function. Next `Py++`_ code does it for you: + + .. code-block:: Python + + from pyplusplus import module_builder + from pyplusplus import function_transformers as FT + + mb = module_builder.module_builder_t( ... ) + hw = mb.mem_fun( 'hello_world' ) + hw.add_transformation( FT.inout(0) ) + +What you see below is the relevant pieces of generated code: + + .. code-block:: C++ + + namespace bp = boost::python; + + static boost::python::object hello_world_a3478182294a057b61508c30b1361318( ::std::string hw ){ + ::hello_world(hw); + return bp::object( hw ); + } + + BOOST_PYTHON_MODULE(...){ + ... + bp::def( "hello_world", &hello_world_a3478182294a057b61508c30b1361318 ); + } + +.. _`Py++` : ./../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: Added: pyplusplus_dev/docs/documentation/functions/transformation/built_in/input.rest =================================================================== --- pyplusplus_dev/docs/documentation/functions/transformation/built_in/input.rest (rev 0) +++ pyplusplus_dev/docs/documentation/functions/transformation/built_in/input.rest 2006-12-10 20:41:30 UTC (rev 792) @@ -0,0 +1,68 @@ +====================== +``input`` transformer +====================== + +.. contents:: Table of contents + +---------- +Definition +---------- + +"input" transformer removes a "reference" type from the function argument. + +"input" transformer takes as argument name or index of the original function +argument. The argument should have "reference" type. Support for "pointer" type +will be added pretty soon. + +------- +Example +------- + +.. code-block:: C++ + + #include <string> + + inline void hello_world( std::string& hw ){ + hw = "hello world!"; + } + +Lets say that you need to expose ``hello_world`` function. As you know +``std::string`` is mapped to `Python`_ string, which is immutable type, so you +have to create small wrapper for the function. Next `Py++`_ code does it for you: + + .. code-block:: Python + + from pyplusplus import module_builder + from pyplusplus import function_transformers as FT + + mb = module_builder.module_builder_t( ... ) + hw = mb.mem_fun( 'hello_world' ) + hw.add_transformation( FT.input(0) ) + +What you see below is the relevant pieces of generated code: + + .. code-block:: C++ + + namespace bp = boost::python; + + static void hello_world_a3478182294a057b61508c30b1361318( ::std::string hw ){ + ::hello_world(hw); + } + + BOOST_PYTHON_MODULE(...){ + ... + bp::def( "hello_world", &hello_world_a3478182294a057b61508c30b1361318 ); + } + +.. _`Py++` : ./../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/functions/transformation/built_in/output.rest =================================================================== --- pyplusplus_dev/docs/documentation/functions/transformation/built_in/output.rest 2006-12-10 18:42:00 UTC (rev 791) +++ pyplusplus_dev/docs/documentation/functions/transformation/built_in/output.rest 2006-12-10 20:41:30 UTC (rev 792) @@ -8,11 +8,11 @@ Definition ---------- -``output`` transformer removes an argument from the function definition and adds +"output" transformer removes an argument from the function definition and adds the "returned", by the original function, value to the return statement of the function-wrapper. -``output`` transformer takes as argument name or index of the original function +"output" transformer takes as argument name or index of the original function argument. The argument should have "reference" type. Support for "pointer" type will be added pretty soon. @@ -58,38 +58,7 @@ bp::def( "hello_world", &hello_world_a3478182294a057b61508c30b1361318 ); } -Explanation ------------ -I feel like I need to explain why the function wrapper for ``hello_world`` function -has such strange name - ``hello_world_a3478182294a057b61508c30b1361318``. The -short answer is function overloading. Consider next code that you need to export: - - .. code-block:: C++ - - void get_distance( long& ); - void get_distance( double& ); - -In order to expose ``get_distance`` functions you have to create 2 function -wrappers and give them distinguish names. You also have to register them under -different aliases, otherwise your users will not be able to call the functions. -`Py++`_ does it for you. The generated wrapper names are unique in the whole -project. They will not be changed between different runs of the code generator. -The aliases `Py++`_ gives to the functions are ugly. You have to provide your -own aliases: - - .. code-block:: Python - - from pyplusplus import module_builder - from pyplusplus import function_transformers as FT - - mb = module_builder.module_builder_t( ... ) - get_distance_int = mb.mem_fun( 'get_distance', arg_types=[ 'int &'] ) - get_distance_int.add_transformation( FT.output(0), alias="get_distance_as_int" ) - -The main reason for the behaviour is that even if you forget to give an alias -to a function, your users will still be able to call the function. - .. _`Py++` : ./../pyplusplus.html .. _`Boost.Python`: http://www.boost.org/libs/python/doc/index.html .. _`Python`: http://www.python.org Added: pyplusplus_dev/docs/documentation/functions/transformation/name_mangling.rest =================================================================== --- pyplusplus_dev/docs/documentation/functions/transformation/name_mangling.rest (rev 0) +++ pyplusplus_dev/docs/documentation/functions/transformation/name_mangling.rest 2006-12-10 20:41:30 UTC (rev 792) @@ -0,0 +1,91 @@ +============= +Name mangling +============= + +.. contents:: Table of contents + +---------- +Definition +---------- + +Wikipedia has a nice `explantion`_ what name mangling is. + +.. _`explantion` : http://en.wikipedia.org/wiki/Name_mangling + +---- +Why? +---- + +I am sure you want to ask why and where `Py++`_ uses name mangling? `Py++`_ uses +name mangling to create function-wrappers for overloaded and\\or free functions. +Consider next use case: + + .. code-block:: C++ + + void get_distance( long& ); + void get_distance( double& ); + +In order to expose ``get_distance`` functions you have to create 2 function +wrappers: + + .. code-block:: C++ + + long get_distance_as_long(){...} + double get_distance_as_double(){...} + +You have to give them distinguish names - C++ does not allow overloading, base +on return type only. You also have to exposes them under different aliases, +otherwise they will not be callable from `Python`_: + + .. code-block:: C++ + + namespace bp = boost::python; + BOOST_PYTHON_MODULE(...){ + bp::def( "get_distance_as_long", &get_distance_as_long ); + bp::def( "get_distance_as_double", &get_distance_as_double ); + } + +------------ +The solution +------------ + +`Py++`_ implements a solution to the problem. The generated wrapper names are +unique in the whole project. However, they are pretty ugly: + +* ``get_distance_610ef0e8a293a62001a25cd3dc59b769`` for ``get_distance( long& )`` + function + +* ``get_distance_702c7b971ac4e91b12f260ac85b36d84`` for ``get_distance( double& )`` + function + +The good news - they will not be changed between different runs of the code +generator. If you are exposing an overloaded function, than `Py++`_ uses the ugly +function-wrapper name as an alias. It is up to you to change the alias: + + .. code-block:: Python + + from pyplusplus import module_builder + from pyplusplus import function_transformers as FT + + mb = module_builder.module_builder_t( ... ) + get_distance_as_long = mb.mem_fun( 'get_distance', arg_types=['long &'] ) + get_distance_as_long.add_transformation( FT.output(0), alias="get_distance_as_long" ) + +There are two main reasons for such implementation\\behaviour: + +1. The generated code will always compile and be correct. +2. If you forgot to give an alias to a function, your users will still be able + to call the function. So no need to rush and create new release. + +.. _`Py++` : ./../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/functions/transformation/terminology.rest =================================================================== --- pyplusplus_dev/docs/documentation/functions/transformation/terminology.rest 2006-12-10 18:42:00 UTC (rev 791) +++ pyplusplus_dev/docs/documentation/functions/transformation/terminology.rest 2006-12-10 20:41:30 UTC (rev 792) @@ -13,7 +13,7 @@ rules. Especially: a change of return type and\\or arguments and their mapping to the original ones. -* Function wrapper +* Function wrapper ( or just wrapper ) C++ function, which calls some other function. @@ -26,7 +26,11 @@ An object that applies predefined set of rules on a function, during function-wrapper construction process. +* Function alias ( or just alias ) + Name under which `Python`_ users see the exposed function + + .. _`Py++` : ./../pyplusplus.html .. _`Boost.Python`: http://www.boost.org/libs/python/doc/index.html .. _`Python`: http://www.python.org Modified: pyplusplus_dev/docs/documentation/functions/transformation/www_configuration.py =================================================================== --- pyplusplus_dev/docs/documentation/functions/transformation/www_configuration.py 2006-12-10 18:42:00 UTC (rev 791) +++ pyplusplus_dev/docs/documentation/functions/transformation/www_configuration.py 2006-12-10 20:41:30 UTC (rev 792) @@ -2,4 +2,5 @@ #main_html_file = 'index.html' names = { 'built_in_transformers' : 'built-in transformers' + , 'name_mangling' : 'name mangling' } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <rom...@us...> - 2006-12-10 18:42:04
|
Revision: 791 http://svn.sourceforge.net/pygccxml/?rev=791&view=rev Author: roman_yakovenko Date: 2006-12-10 10:42:00 -0800 (Sun, 10 Dec 2006) Log Message: ----------- updating environment on linux Modified Paths: -------------- pyplusplus_dev/environment.py Modified: pyplusplus_dev/environment.py =================================================================== --- pyplusplus_dev/environment.py 2006-12-10 07:16:59 UTC (rev 790) +++ pyplusplus_dev/environment.py 2006-12-10 18:42:00 UTC (rev 791) @@ -34,7 +34,7 @@ gccxml.executable = r'd:/dev/gccxml_cvs/gccxml-bin/bin/release/gccxml.exe' else: scons.suffix = '.so' - boost.libs = [ '/home/roman/boost_cvs/bin' ] + boost.libs = [ '/home/roman/boost_cvs/libs/python/build/bin-stage' ] boost.include = '/home/roman/boost_cvs' python.include = '/usr/include/python2.4' gccxml.executable = '/home/roman/gccxml-build/bin/gccxml' This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <rom...@us...> - 2006-12-10 07:16:58
|
Revision: 790 http://svn.sourceforge.net/pygccxml/?rev=790&view=rev Author: roman_yakovenko Date: 2006-12-09 23:16:59 -0800 (Sat, 09 Dec 2006) Log Message: ----------- updating environment to use new( to me ) boost directory layout Modified Paths: -------------- pyplusplus_dev/environment.py pyplusplus_dev/unittests/autoconfig.py Modified: pyplusplus_dev/environment.py =================================================================== --- pyplusplus_dev/environment.py 2006-12-10 07:15:29 UTC (rev 789) +++ pyplusplus_dev/environment.py 2006-12-10 07:16:59 UTC (rev 790) @@ -27,14 +27,14 @@ if sys.platform == 'win32': scons.suffix = '.pyd' scons.ccflags = ['/MD', '/EHsc', '/GR', '/Zc:wchar_t', '/Zc:forScope' ] - boost.libs = 'd:/dev/boost_cvs/bin' + boost.libs = [ 'd:/dev/boost_cvs/libs/python/build/bin-stage' ] boost.include = 'd:/dev/boost_cvs' python.libs = 'e:/python25/libs' python.include = 'e:/python25/include' gccxml.executable = r'd:/dev/gccxml_cvs/gccxml-bin/bin/release/gccxml.exe' else: scons.suffix = '.so' - boost.libs = '/home/roman/boost_cvs/bin' + boost.libs = [ '/home/roman/boost_cvs/bin' ] boost.include = '/home/roman/boost_cvs' python.include = '/usr/include/python2.4' gccxml.executable = '/home/roman/gccxml-build/bin/gccxml' Modified: pyplusplus_dev/unittests/autoconfig.py =================================================================== --- pyplusplus_dev/unittests/autoconfig.py 2006-12-10 07:15:29 UTC (rev 789) +++ pyplusplus_dev/unittests/autoconfig.py 2006-12-10 07:16:59 UTC (rev 790) @@ -20,7 +20,7 @@ class scons_config: libs = ['boost_python'] - libpath = [ boost.libs, python.libs ] + libpath = [ python.libs ] + boost.libs cpppath = [ boost.include, python.include ] include_dirs = cpppath + [data_directory] This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <rom...@us...> - 2006-12-10 07:15:29
|
Revision: 789 http://svn.sourceforge.net/pygccxml/?rev=789&view=rev Author: roman_yakovenko Date: 2006-12-09 23:15:29 -0800 (Sat, 09 Dec 2006) Log Message: ----------- adding "static" to array [in|out] transformers Modified Paths: -------------- pyplusplus_dev/pyplusplus/function_transformers/__init__.py pyplusplus_dev/pyplusplus/function_transformers/transformers.py pyplusplus_dev/unittests/function_transformations_tester.py Modified: pyplusplus_dev/pyplusplus/function_transformers/__init__.py =================================================================== --- pyplusplus_dev/pyplusplus/function_transformers/__init__.py 2006-12-10 06:27:20 UTC (rev 788) +++ pyplusplus_dev/pyplusplus/function_transformers/__init__.py 2006-12-10 07:15:29 UTC (rev 789) @@ -35,12 +35,12 @@ return transformers.inout_t( function, *args, **keywd ) return creator -def input_array( *args, **keywd ): +def input_static_array( *args, **keywd ): def creator( function ): - return transformers.input_array_t( function, *args, **keywd ) + return transformers.input_static_array_t( function, *args, **keywd ) return creator -def output_array( *args, **keywd ): +def output_static_array( *args, **keywd ): def creator( function ): - return transformers.output_array_t( function, *args, **keywd ) + return transformers.output_static_array_t( function, *args, **keywd ) return creator Modified: pyplusplus_dev/pyplusplus/function_transformers/transformers.py =================================================================== --- pyplusplus_dev/pyplusplus/function_transformers/transformers.py 2006-12-10 06:27:20 UTC (rev 788) +++ pyplusplus_dev/pyplusplus/function_transformers/transformers.py 2006-12-10 07:15:29 UTC (rev 789) @@ -210,7 +210,7 @@ _arr2seq = string.Template( 'pyplus_conv::copy_container( $native_array, $native_array + $array_size, pyplus_conv::list_inserter( $pylist ) );' ) -class input_array_t(transformer.transformer_t): +class input_static_array_t(transformer.transformer_t): """Handles an input array with fixed size. void setVec3(double* v) -> setVec3(object v) @@ -286,8 +286,8 @@ self.__configure_v_mem_fun_default( controller.default_controller ) -# output_array_t -class output_array_t(transformer.transformer_t): +# s - static +class output_static_array_t(transformer.transformer_t): """Handles an output array of a fixed size. void getVec3(double* v) -> v = getVec3() Modified: pyplusplus_dev/unittests/function_transformations_tester.py =================================================================== --- pyplusplus_dev/unittests/function_transformations_tester.py 2006-12-10 06:27:20 UTC (rev 788) +++ pyplusplus_dev/unittests/function_transformations_tester.py 2006-12-10 07:15:29 UTC (rev 789) @@ -43,8 +43,8 @@ point3d = mb.class_( 'point3d_t' ) point3d.add_wrapper_code( '' ) - point3d.mem_fun( 'initialize' ).add_transformation( ft.input_array(0, size=3) ) - point3d.mem_fun( 'position' ).add_transformation( ft.output_array(0, size=3) ) + point3d.mem_fun( 'initialize' ).add_transformation( ft.input_static_array(0, size=3) ) + point3d.mem_fun( 'position' ).add_transformation( ft.output_static_array(0, size=3) ) point3d.mem_fun( 'distance' ).add_transformation( ft.output(1) ) image = mb.class_( "image_t" ) @@ -54,8 +54,8 @@ image.member_function( "get_one_value" ).add_transformation( ft.output(0) ) image.member_function( "get_size2" ).add_transformation( ft.output(0), ft.output(1) ) image.member_function( "input_arg" ).add_transformation( ft.input(0) ) - image.member_function( "fixed_input_array" ).add_transformation( ft.input_array(0,3) ) - image.member_function( "fixed_output_array" ).add_transformation( ft.output_array(0,3) ) + image.member_function( "fixed_input_array" ).add_transformation( ft.input_static_array(0,3) ) + image.member_function( "fixed_output_array" ).add_transformation( ft.output_static_array(0,3) ) mb.free_function("get_cpp_instance").call_policies \ = call_policies.return_value_policy(call_policies.reference_existing_object) mb.variable( "cpp_instance" ).exclude() This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <rom...@us...> - 2006-12-10 06:27:22
|
Revision: 788 http://svn.sourceforge.net/pygccxml/?rev=788&view=rev Author: roman_yakovenko Date: 2006-12-09 22:27:20 -0800 (Sat, 09 Dec 2006) Log Message: ----------- adding smart ptr work around for member variables Modified Paths: -------------- pyplusplus_dev/pyplusplus/code_creators/member_variable.py pyplusplus_dev/pyplusplus/decl_wrappers/variable_wrapper.py pyplusplus_dev/unittests/data/smart_pointers_to_be_exported.hpp pyplusplus_dev/unittests/smart_pointers_tester.py Modified: pyplusplus_dev/pyplusplus/code_creators/member_variable.py =================================================================== --- pyplusplus_dev/pyplusplus/code_creators/member_variable.py 2006-12-08 19:47:42 UTC (rev 787) +++ pyplusplus_dev/pyplusplus/code_creators/member_variable.py 2006-12-10 06:27:20 UTC (rev 788) @@ -95,7 +95,7 @@ tmpl = '%(access)s( "%(alias)s", &%(name)s%(doc)s )' access = 'def_readwrite' - if self.is_read_only(): + if self.declaration.is_read_only: access = 'def_readonly' doc = '' if self.documentation: @@ -103,38 +103,56 @@ result = tmpl % { 'access' : access , 'alias' : self.alias - , 'name' : algorithm.create_identifier( self, self.declaration.decl_string ) + , 'name' : self.decl_identifier , 'doc' : doc } return result - def is_read_only( self ): - type_ = declarations.remove_alias( self.declaration.type ) - if declarations.is_pointer( type_ ): - type_ = declarations.remove_pointer( type_ ) - return isinstance( type_, declarations.const_t ) + def _generate_for_smart_ptr( self ): + doc = '' + add_property = '' + make_getter = algorithm.create_identifier( self, '::boost::python::make_getter') + make_setter = algorithm.create_identifier( self, '::boost::python::make_setter') + if self.declaration.type_qualifiers.has_static: + add_property = 'add_static_property' + else: + if self.documentation: + doc = self.documentation + add_property = 'add_property' + add_property_args = [ '"%s"' % self.alias ] + getter_code = declarations.call_invocation.join( + make_getter + , [ '&' + self.decl_identifier + , self.declaration.getter_call_policies.create( self ) ] + , os.linesep + self.indent( self.PARAM_SEPARATOR, 6) ) + + add_property_args.append( getter_code ) + if not self.declaration.is_read_only: + setter_code = '' + setter_args = [ '&' + self.decl_identifier ] + if self.declaration.setter_call_policies \ + and not self.declaration.setter_call_policies.is_default(): + setter_args.append( self.declaration.setter_call_policies.create( self ) ) + setter_code = declarations.call_invocation.join( + make_setter + , setter_args + , os.linesep + self.indent( self.PARAM_SEPARATOR, 6) ) + add_property_args.append( setter_code) + if doc: + add_property_args.append( doc ) + return declarations.call_invocation.join( + add_property + , add_property_args + , os.linesep + self.indent( self.PARAM_SEPARATOR, 4 ) ) - if declarations.is_reference( type_ ): - type_ = declarations.remove_reference( type_ ) - - if isinstance( type_, declarations.const_t ): - return True - - if isinstance( type_, declarations.declarated_t ) \ - and isinstance( type_.declaration, declarations.class_t ) \ - and not declarations.has_public_assign( type_.declaration ): - return True - return False - - def _generate_variable( self ): + def _create_impl( self ): if declarations.is_pointer( self.declaration.type ): return self._generate_for_pointer() + elif self.declaration.apply_smart_ptr_wa: + return self._generate_for_smart_ptr() else: return self._generate_for_none_pointer() - def _create_impl(self): - return self._generate_variable() - class member_variable_wrapper_t( code_creator.code_creator_t , declaration_based.declaration_based_t ): """ Modified: pyplusplus_dev/pyplusplus/decl_wrappers/variable_wrapper.py =================================================================== --- pyplusplus_dev/pyplusplus/decl_wrappers/variable_wrapper.py 2006-12-08 19:47:42 UTC (rev 787) +++ pyplusplus_dev/pyplusplus/decl_wrappers/variable_wrapper.py 2006-12-10 06:27:20 UTC (rev 788) @@ -6,9 +6,10 @@ """defines class that configure global and member variable exposing""" import decl_wrapper +import python_traits +import call_policies from pyplusplus import messages from pygccxml import declarations -from pyplusplus.decl_wrappers import python_traits class variable_t(decl_wrapper.decl_wrapper_t, declarations.variable_t): """defines a set of properties, that will instruct Py++ how to expose the variable""" @@ -17,6 +18,8 @@ decl_wrapper.decl_wrapper_t.__init__( self ) self._getter_call_policies = None self._setter_call_policies = None + self._apply_smart_ptr_wa = False + self._is_read_only = None __call_policies_doc__ = \ """There are usecase, when exporting member variable forces Py++ to @@ -29,6 +32,14 @@ """ def get_getter_call_policies( self ): + if None is self._getter_call_policies: + if self.apply_smart_ptr_wa: + value_policy = '' + if self.is_read_only: + value_policy = call_policies.copy_const_reference + else: + value_policy = call_policies.copy_non_const_reference + self._getter_call_policies = call_policies.return_value_policy( value_policy ) return self._getter_call_policies def set_getter_call_policies( self, call_policies ): self._getter_call_policies = call_policies @@ -36,12 +47,55 @@ , doc=__call_policies_doc__ ) def get_setter_call_policies( self ): + if None is self._getter_call_policies: + if self.apply_smart_ptr_wa: + self._setter_call_policies = call_policies.default_call_policies() return self._setter_call_policies def set_setter_call_policies( self, call_policies ): self._setter_call_policies = call_policies setter_call_policies = property( get_setter_call_policies, set_setter_call_policies , doc=__call_policies_doc__ ) + def get_apply_smart_ptr_wa( self ): + return self._apply_smart_ptr_wa + def set_apply_smart_ptr_wa( self, value): + self._apply_smart_ptr_wa = value + apply_smart_ptr_wa = property( get_apply_smart_ptr_wa, set_apply_smart_ptr_wa + , doc="" ) + + + def __find_out_is_read_only(self): + type_ = declarations.remove_alias( self.type ) + + if isinstance( type_, declarations.const_t ): + return True + + if declarations.is_pointer( type_ ): + type_ = declarations.remove_pointer( type_ ) + + if declarations.is_reference( type_ ): + type_ = declarations.remove_reference( type_ ) + + if isinstance( type_, declarations.const_t ): + return True + + if self.apply_smart_ptr_wa: + return False #all smart pointers has assign operator + + if isinstance( type_, declarations.declarated_t ) \ + and isinstance( type_.declaration, declarations.class_t ) \ + and not declarations.has_public_assign( type_.declaration ): + return True + return False + + def get_is_read_only( self ): + if None is self._is_read_only: + self._is_read_only = self.__find_out_is_read_only() + return self._is_read_only + def set_is_read_only( self, v ): + self._is_read_only = v + is_read_only = property( get_is_read_only, set_is_read_only ) + def _exportable_impl( self ): if not self.name: return messages.W1033 Modified: pyplusplus_dev/unittests/data/smart_pointers_to_be_exported.hpp =================================================================== --- pyplusplus_dev/unittests/data/smart_pointers_to_be_exported.hpp 2006-12-08 19:47:42 UTC (rev 787) +++ pyplusplus_dev/unittests/data/smart_pointers_to_be_exported.hpp 2006-12-10 06:27:20 UTC (rev 788) @@ -1,56 +1,56 @@ -// Copyright 2004 Roman Yakovenko. -// 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) - -#ifndef __smart_pointers_to_be_exported_hpp__ -#define __smart_pointers_to_be_exported_hpp__ -#include <memory> -#include "boost/shared_ptr.hpp" - -namespace smart_pointers{ - -struct base{ - base() : base_value(19) {} - int base_value; +// Copyright 2004 Roman Yakovenko. +// 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) + +#ifndef __smart_pointers_to_be_exported_hpp__ +#define __smart_pointers_to_be_exported_hpp__ +#include <memory> +#include "boost/shared_ptr.hpp" + +namespace smart_pointers{ + +struct base{ + base() : base_value(19) {} + int base_value; virtual int get_base_value(){ return base_value; } - virtual int get_some_value() = 0; -}; - -struct data : base{ - data() : value(11){} - int value; + virtual int get_some_value() = 0; +}; + +struct data : base{ + data() : value(11){} + int value; virtual int get_value(){ return value; } - virtual int get_some_value(){ return 23; } -}; - -typedef std::auto_ptr< base > base_a_ptr; -typedef boost::shared_ptr< base > base_s_ptr; - -typedef std::auto_ptr< data > data_a_ptr; -typedef boost::shared_ptr< data > data_s_ptr; - -data_a_ptr create_auto(); -data_s_ptr create_shared(); - -int ref_auto( data_a_ptr& a ); -int ref_shared( data_s_ptr& a ); - -int val_auto( data_a_ptr a ); -int val_shared( data_s_ptr a ); - -int const_ref_auto( const data_a_ptr& a ); -int const_ref_shared( const data_s_ptr& a ); - -int ref_auto_base_value( base_a_ptr& a ); -int ref_shared_base_value( base_s_ptr& a ); - -int val_auto_base_value( base_a_ptr a ); -int val_shared_base_value( base_s_ptr a ); - -int const_ref_auto_base_value( const base_a_ptr& a ); -int const_ref_shared_base_value( const base_s_ptr& a ); + virtual int get_some_value(){ return 23; } +}; +typedef std::auto_ptr< base > base_a_ptr; +typedef boost::shared_ptr< base > base_s_ptr; + +typedef std::auto_ptr< data > data_a_ptr; +typedef boost::shared_ptr< data > data_s_ptr; + +data_a_ptr create_auto(); +data_s_ptr create_shared(); + +int ref_auto( data_a_ptr& a ); +int ref_shared( data_s_ptr& a ); + +int val_auto( data_a_ptr a ); +int val_shared( data_s_ptr a ); + +int const_ref_auto( const data_a_ptr& a ); +int const_ref_shared( const data_s_ptr& a ); + +int ref_auto_base_value( base_a_ptr& a ); +int ref_shared_base_value( base_s_ptr& a ); + +int val_auto_base_value( base_a_ptr a ); +int val_shared_base_value( base_s_ptr a ); + +int const_ref_auto_base_value( const base_a_ptr& a ); +int const_ref_shared_base_value( const base_s_ptr& a ); + int ref_auto_some_value( base_a_ptr& a ); int ref_shared_some_value( base_s_ptr& a ); @@ -60,7 +60,24 @@ int const_ref_auto_some_value( const base_a_ptr& a ); int const_ref_shared_some_value( const base_s_ptr& a ); - -} - -#endif//__smart_pointers_to_be_exported_hpp__ +struct shared_data_buffer_t{ + shared_data_buffer_t() + : size( 0 ) + {} + int size; +}; + +struct shared_data_buffer_holder_t{ + typedef boost::shared_ptr<shared_data_buffer_t> holder_impl_t; + shared_data_buffer_holder_t() + : buffer( new shared_data_buffer_t() ) + , const_buffer( new shared_data_buffer_t() ) + {} + + holder_impl_t buffer; + const holder_impl_t const_buffer; +}; + +} + +#endif//__smart_pointers_to_be_exported_hpp__ Modified: pyplusplus_dev/unittests/smart_pointers_tester.py =================================================================== --- pyplusplus_dev/unittests/smart_pointers_tester.py 2006-12-08 19:47:42 UTC (rev 787) +++ pyplusplus_dev/unittests/smart_pointers_tester.py 2006-12-10 06:27:20 UTC (rev 788) @@ -23,6 +23,8 @@ base = mb.class_( 'base' ) shared_ptrs = mb.decls( lambda decl: decl.name.startswith( 'shared_ptr<' ) ) shared_ptrs.disable_warnings( messages.W1040 ) + mb.variable( 'buffer' ).apply_smart_ptr_wa = True + mb.variable( 'const_buffer' ).apply_smart_ptr_wa = True def create_py_derived( self, module ): class py_derived_t( module.base ): @@ -82,6 +84,16 @@ self.failUnless( 23 == module.const_ref_auto_some_value(da) ) self.failUnless( 28 == module.const_ref_shared_some_value(py_derived) ) + holder1 = module.shared_data_buffer_holder_t() + self.failUnless( holder1.buffer.size == 0 ) + + holder2 = module.shared_data_buffer_holder_t() + holder2.buffer.size = 2 + + holder1.buffer = holder2.buffer + self.failUnless( holder1.buffer.size == 2 ) + holder1.buffer.size = 3 + self.failUnless( holder2.buffer.size == 3 ) def create_suite(): suite = unittest.TestSuite() This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <rom...@us...> - 2006-12-08 19:47:43
|
Revision: 787 http://svn.sourceforge.net/pygccxml/?rev=787&view=rev Author: roman_yakovenko Date: 2006-12-08 11:47:42 -0800 (Fri, 08 Dec 2006) Log Message: ----------- adding new link Modified Paths: -------------- pyplusplus_dev/docs/download.rest Modified: pyplusplus_dev/docs/download.rest =================================================================== --- pyplusplus_dev/docs/download.rest 2006-12-08 19:46:21 UTC (rev 786) +++ pyplusplus_dev/docs/download.rest 2006-12-08 19:47:42 UTC (rev 787) @@ -45,6 +45,9 @@ You can find it `here`_. Take a look on new `getting started guide`_ for Boost libraries. +Another very valuable link related to Boost is http://engineering.meta-comm.com/boost.aspx . +You will find hourly snapshots of the source code and the documentation for all +Boost libraries. .. _`getting started guide` : http://boost.cvs.sourceforge.net/*checkout*/boost/boost/more/getting_started.html .. _`here` : http://www.boost-consulting.com/download.html This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <rom...@us...> - 2006-12-08 19:46:28
|
Revision: 786 http://svn.sourceforge.net/pygccxml/?rev=786&view=rev Author: roman_yakovenko Date: 2006-12-08 11:46:21 -0800 (Fri, 08 Dec 2006) Log Message: ----------- adding work around for smart pointers as member variables Modified Paths: -------------- pyplusplus_dev/docs/bpl_lessons_learned/smart_ptrs/bindings.cpp pyplusplus_dev/docs/bpl_lessons_learned/smart_ptrs/classes.hpp pyplusplus_dev/docs/bpl_lessons_learned/smart_ptrs/test.py Modified: pyplusplus_dev/docs/bpl_lessons_learned/smart_ptrs/bindings.cpp =================================================================== --- pyplusplus_dev/docs/bpl_lessons_learned/smart_ptrs/bindings.cpp 2006-12-07 10:39:03 UTC (rev 785) +++ pyplusplus_dev/docs/bpl_lessons_learned/smart_ptrs/bindings.cpp 2006-12-08 19:46:21 UTC (rev 786) @@ -3,30 +3,30 @@ namespace bp = boost::python; -namespace boost{ namespace python{ +// "get_pointer" function returns pointer to the object managed by smart pointer +// class instance - //We need to tell Boost.Python how to work with your smart pointer. - //Short explanation: - // "get_pointer" extracts the pointer to the object it manages. - // "pointee" extracts the type of the object, smart pointer manages. +template<class T> +inline T * get_pointer(smart_ptr_t<T> const& p){ + return p.get(); +} + +inline derived_t * get_pointer(derived_ptr_t const& p){ + return p.get(); +} - //You can read more about this functionality in the reference manual: - //http://boost.org/libs/python/doc/v2/pointee.html . +namespace boost{ namespace python{ - template<class T> - inline T * get_pointer(smart_ptr_t<T> const& p){ - return p.get(); - } + // "pointee" class tells Boost.Python the type of the object managed by smart + // pointer class. + // You can read more about "pointee" class here: + // http://boost.org/libs/python/doc/v2/pointee.html template <class T> struct pointee< smart_ptr_t<T> >{ typedef T type; }; - inline derived_t * get_pointer(derived_ptr_t const& p){ - return p.get(); - } - template<> struct pointee< derived_ptr_t >{ typedef derived_t type; @@ -34,6 +34,9 @@ } } +// "get_pointer" and "pointee" are needed, in order to allow Boost.Python to +// work with user defined smart pointer + struct base_wrapper_t : base_i, bp::wrapper< base_i > { base_wrapper_t() @@ -76,33 +79,33 @@ BOOST_PYTHON_MODULE( custom_sptr ){ bp::class_< base_wrapper_t, boost::noncopyable, smart_ptr_t< base_wrapper_t > >( "base_i" ) - //----------------------------------------------^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - //HeldType of the abstract class, which is managed by custom smart pointer - //should be smart_ptr_t< base_wrapper_t >. + // ---------------------------------------------^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + // HeldType of the abstract class, which is managed by custom smart pointer + // should be smart_ptr_t< base_wrapper_t >. .def( "get_value", bp::pure_virtual( &base_i::get_value ) ); - //Register implicit conversion between smart pointers. Boost.Python library - //can not discover relationship between classes. You have to tell about the - //relationship to it. This will allow Boost.Python to treat right, the - //functions, which expect to get as argument smart_ptr_t< base_i > class - //instance, when smart_ptr_t< derived from base_i > class instance is passed. + // Register implicit conversion between smart pointers. Boost.Python library + // can not discover relationship between classes. You have to tell about the + // relationship to it. This will allow Boost.Python to treat right, the + // functions, which expect to get as argument smart_ptr_t< base_i > class + // instance, when smart_ptr_t< derived from base_i > class instance is passed. // - //For more information about implicitly_convertible see the documentation: - //http://boost.org/libs/python/doc/v2/implicit.html . + // For more information about implicitly_convertible see the documentation: + // http://boost.org/libs/python/doc/v2/implicit.html . bp::implicitly_convertible< smart_ptr_t< base_wrapper_t >, smart_ptr_t< base_i > >(); - //The register_ptr_to_python functionality is explaned very well in the - //documentation: - //http://boost.org/libs/python/doc/v2/register_ptr_to_python.html . + // The register_ptr_to_python functionality is explaned very well in the + // documentation: + // http://boost.org/libs/python/doc/v2/register_ptr_to_python.html . bp::register_ptr_to_python< smart_ptr_t< base_i > >(); bp::class_< derived_wrapper_t, bp::bases< base_i >, smart_ptr_t<derived_wrapper_t> >( "derived_t" ) - //--------------------------------------------------^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - //Pay attention on the class HeldType. It will allow us to create new classes - //in Python, which derive from the derived_t class. + // -------------------------------------------------^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + // Pay attention on the class HeldType. It will allow us to create new classes + // in Python, which derive from the derived_t class. .def( "get_value", &derived_t::get_value, &derived_wrapper_t::default_get_value ); - //Now register all existing conversion: + // Now register all existing conversion: bp::implicitly_convertible< smart_ptr_t< derived_wrapper_t >, smart_ptr_t< derived_t > >(); bp::implicitly_convertible< smart_ptr_t< derived_t >, smart_ptr_t< base_i > >(); bp::implicitly_convertible< derived_ptr_t, smart_ptr_t< derived_t > >(); @@ -113,4 +116,23 @@ bp::def( "val_get_value", &::val_get_value ); bp::def( "create_derived", &::create_derived ); bp::def( "create_base", &::create_base ); + + // Work around for the public member variable, where type of the variable + // is smart pointer problem + bp::class_< shared_data::buffer_t >( "buffer_t" ) + .def_readwrite( "size", &shared_data::buffer_t::size ); + + bp::register_ptr_to_python< smart_ptr_t< shared_data::buffer_t > >(); + + bp::class_< shared_data::buffer_holder_t >( "buffer_holder_t" ) + .def( "get_data", &shared_data::buffer_holder_t::get_data ) + .def_readwrite( "data_naive", &shared_data::buffer_holder_t::data ) + // If you will try to access "data_naive" you will get + // TypeError: No Python class registered for C++ class smart_ptr_t<shared_data::buffer_t> + // Next lines of code contain work around + .add_property( "data" + , bp::make_getter( &shared_data::buffer_holder_t::data + , bp::return_value_policy<bp::copy_non_const_reference>() ) + , bp::make_setter( &shared_data::buffer_holder_t::data ) ); + } Modified: pyplusplus_dev/docs/bpl_lessons_learned/smart_ptrs/classes.hpp =================================================================== --- pyplusplus_dev/docs/bpl_lessons_learned/smart_ptrs/classes.hpp 2006-12-07 10:39:03 UTC (rev 785) +++ pyplusplus_dev/docs/bpl_lessons_learned/smart_ptrs/classes.hpp 2006-12-08 19:46:21 UTC (rev 786) @@ -13,9 +13,10 @@ derived_t(){} virtual int get_value() const{ return 0xD; } }; - -//Small convenience class. Actually it is defined here, because this is a pattern -//Ogre project uses. + +// Some smart pointer classes does not have reach interface as boost ones. +// In order to provide same level of convenience, users are forced to create +// classes, which derive from smart pointer class. struct derived_ptr_t : public smart_ptr_t< derived_t >{ derived_ptr_t() @@ -56,8 +57,8 @@ } }; -//Few functions that will be used to test custom smart pointer functionality -//from Python. +// Few functions that will be used to test custom smart pointer functionality +// from Python. derived_ptr_t create_derived(){ return derived_ptr_t( new derived_t() ); } @@ -67,16 +68,16 @@ } -//Next function could be exposed, but it could not be called from Python, when -//the argument is the instance of a derived class. +// Next function could be exposed, but it could not be called from Python, when +// the argument is the instance of a derived class. // -//This is the explanation David Abrahams gave: -// Naturally; there is no instance of smart_ptr_t<base_i> anywhere in the -// Python object for the reference to bind to. The rules are the same as in C++: +// This is the explanation David Abrahams gave: +// Naturally; there is no instance of smart_ptr_t<base_i> anywhere in the +// Python object for the reference to bind to. The rules are the same as in C++: // -// int f(smart_ptr_t<base>& x); -// smart_ptr_t<derived> y; -// int z = f(y); // fails to compile +// int f(smart_ptr_t<base>& x); +// smart_ptr_t<derived> y; +// int z = f(y); // fails to compile inline int ref_get_value( smart_ptr_t< base_i >& a ){ @@ -93,5 +94,30 @@ return a->get_value(); } +namespace shared_data{ + +// Boost.Python has small problem with user defined smart pointers and public +// member variables, exposed using def_readonly, def_readwrite functionality +// Read carefully "make_getter" documentation. +// http://boost.org/libs/python/doc/v2/data_members.html#make_getter-spec +// bindings.cpp contains solution to the problem. + +struct buffer_t{ + buffer_t() : size(0) {} + int size; +}; + +struct buffer_holder_t{ + buffer_holder_t() + : data( new buffer_t() ) + {} + + smart_ptr_t< buffer_t > get_data(){ return data; } + + smart_ptr_t< buffer_t > data; +}; + +} + #endif//classes_11_11_2006 Modified: pyplusplus_dev/docs/bpl_lessons_learned/smart_ptrs/test.py =================================================================== --- pyplusplus_dev/docs/bpl_lessons_learned/smart_ptrs/test.py 2006-12-07 10:39:03 UTC (rev 785) +++ pyplusplus_dev/docs/bpl_lessons_learned/smart_ptrs/test.py 2006-12-08 19:46:21 UTC (rev 786) @@ -59,6 +59,16 @@ self.__test_val( inst, val ) self.__test_const_ref( inst, val ) + def test_mem_var_access( self ): + holder = custom_sptr.buffer_holder_t() + self.failUnless( holder.get_data().size == 0 ) + self.failUnless( holder.data.size == 0 ) + try: + self.failUnless( holder.data_naive.size == 0 ) + self.fail("TypeError exception was not raised.") + except TypeError: + pass + def create_suite(): suite = unittest.TestSuite() suite.addTest( unittest.makeSuite(tester_t)) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <rom...@us...> - 2006-12-07 10:39:04
|
Revision: 785 http://svn.sourceforge.net/pygccxml/?rev=785&view=rev Author: roman_yakovenko Date: 2006-12-07 02:39:03 -0800 (Thu, 07 Dec 2006) Log Message: ----------- adding output transformer documentation Modified Paths: -------------- pyplusplus_dev/docs/documentation/functions/transformation/transformation.rest pyplusplus_dev/docs/documentation/functions/transformation/www_configuration.py Added Paths: ----------- pyplusplus_dev/docs/documentation/functions/transformation/built_in/ pyplusplus_dev/docs/documentation/functions/transformation/built_in/built_in.rest pyplusplus_dev/docs/documentation/functions/transformation/built_in/output.rest pyplusplus_dev/docs/documentation/functions/transformation/built_in/www_configuration.py pyplusplus_dev/docs/documentation/functions/transformation/terminology.rest Added: pyplusplus_dev/docs/documentation/functions/transformation/built_in/built_in.rest =================================================================== --- pyplusplus_dev/docs/documentation/functions/transformation/built_in/built_in.rest (rev 0) +++ pyplusplus_dev/docs/documentation/functions/transformation/built_in/built_in.rest 2006-12-07 10:39:03 UTC (rev 785) @@ -0,0 +1,41 @@ +===================== +Built-in transformers +===================== + +.. contents:: Table of contents + +------------ +Introduction +------------ + +`Py++`_ comes with few predefined transformers: + +* ``output`` + +* ``input`` + +* ``inout`` + +* ``input_array`` + +* ``output_array`` + +This set doesn't cover all common use cases, but it will grow with every new +version of `Py++`_. If you created your own transformer consider to contribute +it to the project. + +I suggest you to start reading ``output`` transformer. It is pretty simple and +well explained. + +.. _`Py++` : ./../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: Added: pyplusplus_dev/docs/documentation/functions/transformation/built_in/output.rest =================================================================== --- pyplusplus_dev/docs/documentation/functions/transformation/built_in/output.rest (rev 0) +++ pyplusplus_dev/docs/documentation/functions/transformation/built_in/output.rest 2006-12-07 10:39:03 UTC (rev 785) @@ -0,0 +1,104 @@ +====================== +``output`` transformer +====================== + +.. contents:: Table of contents + +---------- +Definition +---------- + +``output`` transformer removes an argument from the function definition and adds +the "returned", by the original function, value to the return statement of the +function-wrapper. + +``output`` transformer takes as argument name or index of the original function +argument. The argument should have "reference" type. Support for "pointer" type +will be added pretty soon. + +------- +Example +------- + +.. code-block:: C++ + + #include <string> + + inline void hello_world( std::string& hw ){ + hw = "hello world!"; + } + +Lets say that you need to expose ``hello_world`` function. As you know +``std::string`` is mapped to `Python`_ string, which is immutable type, so you +have to create small wrapper for the function. Next `Py++`_ code does it for you: + + .. code-block:: Python + + from pyplusplus import module_builder + from pyplusplus import function_transformers as FT + + mb = module_builder.module_builder_t( ... ) + hw = mb.mem_fun( 'hello_world' ) + hw.add_transformation( FT.output(0) ) + +What you see below is the relevant pieces of generated code: + + .. code-block:: C++ + + namespace bp = boost::python; + + static boost::python::object hello_world_a3478182294a057b61508c30b1361318( ){ + std::string hw2; + ::hello_world(hw2); + return bp::object( hw2 ); + } + + BOOST_PYTHON_MODULE(...){ + ... + bp::def( "hello_world", &hello_world_a3478182294a057b61508c30b1361318 ); + } + +Explanation +----------- + +I feel like I need to explain why the function wrapper for ``hello_world`` function +has such strange name - ``hello_world_a3478182294a057b61508c30b1361318``. The +short answer is function overloading. Consider next code that you need to export: + + .. code-block:: C++ + + void get_distance( long& ); + void get_distance( double& ); + +In order to expose ``get_distance`` functions you have to create 2 function +wrappers and give them distinguish names. You also have to register them under +different aliases, otherwise your users will not be able to call the functions. +`Py++`_ does it for you. The generated wrapper names are unique in the whole +project. They will not be changed between different runs of the code generator. +The aliases `Py++`_ gives to the functions are ugly. You have to provide your +own aliases: + + .. code-block:: Python + + from pyplusplus import module_builder + from pyplusplus import function_transformers as FT + + mb = module_builder.module_builder_t( ... ) + get_distance_int = mb.mem_fun( 'get_distance', arg_types=[ 'int &'] ) + get_distance_int.add_transformation( FT.output(0), alias="get_distance_as_int" ) + +The main reason for the behaviour is that even if you forget to give an alias +to a function, your users will still be able to call the function. + +.. _`Py++` : ./../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: Added: pyplusplus_dev/docs/documentation/functions/transformation/built_in/www_configuration.py =================================================================== --- pyplusplus_dev/docs/documentation/functions/transformation/built_in/www_configuration.py (rev 0) +++ pyplusplus_dev/docs/documentation/functions/transformation/built_in/www_configuration.py 2006-12-07 10:39:03 UTC (rev 785) @@ -0,0 +1,4 @@ +name = 'built-in transformers' +#main_html_file = 'index.html' + +names = { } Added: pyplusplus_dev/docs/documentation/functions/transformation/terminology.rest =================================================================== --- pyplusplus_dev/docs/documentation/functions/transformation/terminology.rest (rev 0) +++ pyplusplus_dev/docs/documentation/functions/transformation/terminology.rest 2006-12-07 10:39:03 UTC (rev 785) @@ -0,0 +1,41 @@ +=========== +Terminology +=========== + +.. contents:: Table of contents + +* Function transformation + + `Py++`_ sub-system\\framework, which allows you to create function wrappers + and to keep smile. + + The operation of changing one function into another in accordance with some + rules. Especially: a change of return type and\\or arguments and their mapping + to the original ones. + +* Function wrapper + + C++ function, which calls some other function. + +* Immutable type + + An instance of this type could not be modified after construction + +* Transformer + + An object that applies predefined set of rules on a function, during + function-wrapper construction process. + + +.. _`Py++` : ./../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/functions/transformation/transformation.rest =================================================================== --- pyplusplus_dev/docs/documentation/functions/transformation/transformation.rest 2006-12-06 14:58:17 UTC (rev 784) +++ pyplusplus_dev/docs/documentation/functions/transformation/transformation.rest 2006-12-07 10:39:03 UTC (rev 785) @@ -8,12 +8,12 @@ Introduction ------------ -During the development of Python bindings for some C++ library, it might get +During the development of `Python`_ bindings for some C++ library, it might get necessary to write custom wrapper code for a particular function in order to make that function usable from `Python`_. An often mentioned example that demonstrates the problem is the ``get_size()`` -method of a fictitious image class: +member function of a fictitious image class: .. code-block:: C++ @@ -68,25 +68,16 @@ #Next line has same effect get_size.add_transformation( FT.output('width'), FT.output('height') ) -`Py++`_ will generate very similar code you just saw. +`Py++`_ will generate a code, very similar to one found in +``boost::python::tuple get_size( const image_t& img )`` function. ------------ -Terminology ------------ +--------- +Thanks to +--------- -* Immutable type +Thanks goes to Matthias Baas for his efforts and hard work. He did a research, +implemented the initial working version and wrote a lot of documentation. - An instance of this type could not be modified after construction - -* Function wrapper - - C++ function that call the original one - -* Function transformation - - `Py++`_ sub system\\framework, which will allow you to create function wrappers - and to keep smile. - .. _`Py++` : ./../pyplusplus.html .. _`Boost.Python`: http://www.boost.org/libs/python/doc/index.html .. _`Python`: http://www.python.org Modified: pyplusplus_dev/docs/documentation/functions/transformation/www_configuration.py =================================================================== --- pyplusplus_dev/docs/documentation/functions/transformation/www_configuration.py 2006-12-06 14:58:17 UTC (rev 784) +++ pyplusplus_dev/docs/documentation/functions/transformation/www_configuration.py 2006-12-07 10:39:03 UTC (rev 785) @@ -1,5 +1,5 @@ name = 'function transformation' #main_html_file = 'index.html' -names = { +names = { 'built_in_transformers' : 'built-in transformers' } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <rom...@us...> - 2006-12-06 14:58:18
|
Revision: 784 http://svn.sourceforge.net/pygccxml/?rev=784&view=rev Author: roman_yakovenko Date: 2006-12-06 06:58:17 -0800 (Wed, 06 Dec 2006) Log Message: ----------- adding FT documentation Added Paths: ----------- pyplusplus_dev/docs/documentation/functions/transformation/ pyplusplus_dev/docs/documentation/functions/transformation/transformation.rest pyplusplus_dev/docs/documentation/functions/transformation/www_configuration.py Added: pyplusplus_dev/docs/documentation/functions/transformation/transformation.rest =================================================================== --- pyplusplus_dev/docs/documentation/functions/transformation/transformation.rest (rev 0) +++ pyplusplus_dev/docs/documentation/functions/transformation/transformation.rest 2006-12-06 14:58:17 UTC (rev 784) @@ -0,0 +1,101 @@ +======================= +Function transformation +======================= + +.. contents:: Table of contents + +------------ +Introduction +------------ + +During the development of Python bindings for some C++ library, it might get +necessary to write custom wrapper code for a particular function in order to +make that function usable from `Python`_. + +An often mentioned example that demonstrates the problem is the ``get_size()`` +method of a fictitious image class: + +.. code-block:: C++ + + void get_size(int& width, int& height); + +This member function cannot be exposed with standard `Boost.Python`_ mechanisms. +The main reasons for this is that ``int`` is immutable type in `Python`_. +An instance of immutable type could not be changed after construction. The only +way to expose this function to `Python`_ is to create small wrapper, which will +return a tuple. In `Python`_, the above function would instead be invoked like this: + +.. code-block:: Python + + width, height = img.get_size() + +and the wrapper could look like this: + +.. code-block:: C++ + + boost::python::tuple get_size( const image_t& img ){ + int width; + int height; + img.get_size( width, height ); + return boost::python::make_tuple( width, height ); + } + +As you can see this function is simply invokes the original ``get_size()`` member +function and return the output values as a tuple. + +Unfortunately, C++ source code cannot describe the semantics of an argument so +there is no way for a code generator tool such as `Py++`_ to know whether an +argument that has a reference type is actually an output argument, an input +argument or an input/output argument. That's why the user will always have to +"enhance" the C++ code and tell the code generator tool about the missing +information. + +Note: C++ fundamental types, enumerations and string are all mapped to `Python`_ +immutable types. + +Instead of forcing you to write the entire wrapper function, `Py++`_ allows you +to provide the semantics of an argument(s) and then it will take care of +producing the correct code: + +.. code-block:: Python + + from pyplusplus import module_builder + from pyplusplus import function_transformers as FT + + mb = module_builder.module_builder_t( ... ) + get_size = mb.mem_fun( 'image_t::get_size' ) + get_size.add_transformation( FT.output(0), FT.output(1) ) + #Next line has same effect + get_size.add_transformation( FT.output('width'), FT.output('height') ) + +`Py++`_ will generate very similar code you just saw. + +----------- +Terminology +----------- + +* Immutable type + + An instance of this type could not be modified after construction + +* Function wrapper + + C++ function that call the original one + +* Function transformation + + `Py++`_ sub system\\framework, which will allow you to create function wrappers + and to keep smile. + +.. _`Py++` : ./../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: Added: pyplusplus_dev/docs/documentation/functions/transformation/www_configuration.py =================================================================== --- pyplusplus_dev/docs/documentation/functions/transformation/www_configuration.py (rev 0) +++ pyplusplus_dev/docs/documentation/functions/transformation/www_configuration.py 2006-12-06 14:58:17 UTC (rev 784) @@ -0,0 +1,5 @@ +name = 'function transformation' +#main_html_file = 'index.html' + +names = { +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |