[C++-sig] code generation of two scenarios

Balasubramanyam, Shivakumar sbalasub at qualcomm.com
Wed Jul 19 20:41:37 CEST 2006


Hi,

I have the code generated for two scenarios below and I do not
understand the difference in behavior for *test* function,

In this first case, I would need to write the hand-wrapper code for
test(immutable &int) function.

The differences in code are that, the sample 2 code has an array
instantiation, which would generate the py++ array wrapper.

Where as the second sample has this built-in, which would return me a
tuple of (int,int)

Any reasons why?

************************************************************************
*********************************************
#include <stdio.h>
class A
{
        public:
		static int test(unsigned int & num)  ;
};

// This file has been generated by pyplusplus.
#include "boost/python.hpp"
#include
"/local/mnt/workspace/software/pyplusplus-0.8.0/tests/csw/test2/A.h"
namespace bp = boost::python;

BOOST_PYTHON_MODULE(test2){
    bp::class_< A >( "A" )    
        .def( 
            "test"
            , &::A::test
            , ( bp::arg("num") )
            , bp::default_call_policies() )    
        .staticmethod( "test" );
}
************************************************************************
*********************************************
************************************************************************
*********************************************
#include <stdio.h>

const unsigned int COUNT = 100;
class A
{
        public:
		static int test(unsigned int & num)  ;
                static unsigned int _indexArray[COUNT]; 
};

// This file has been generated by pyplusplus.

#include "boost/python.hpp"
#include "__array_1.pypp.hpp"
#include
"/local/mnt/workspace/software/pyplusplus-0.8.0/tests/csw/test2/A.h"

namespace bp = boost::python;
struct A_wrapper : A, bp::wrapper< A > {
    A_wrapper(A const & arg )
    : A( arg )
      , bp::wrapper< A >(){
        // copy constructor
    }
    A_wrapper()
    : A()
      , bp::wrapper< A >(){
        // null constructor
    }
    pyplusplus::containers::static_sized::array_1_t< unsigned int, 100 >
    pyplusplus__indexArray_wrapper(){
        return pyplusplus::containers::static_sized::array_1_t< unsigned
int, 100 >( _indexArray );
    }
};

BOOST_PYTHON_MODULE(test2){
    { //::A
        typedef bp::class_< A_wrapper > A_exposer_t;
        A_exposer_t A_exposer = A_exposer_t( "A" );
        bp::scope A_scope( A_exposer );
        { //::A::test
            typedef int ( *function_ptr_t )( unsigned int & );
            A_exposer.def( 
                "test"
                , function_ptr_t( &::A::test )
                , ( bp::arg("num") )
                , bp::default_call_policies() );
        }
        pyplusplus::containers::static_sized::register_array_1< unsigned
int, 100, bp::default_call_policies >( "__array_1_unsigned_int_100" );
        A_exposer.add_static_property( "_indexArray"
            , bp::make_function(
(pyplusplus::containers::static_sized::array_1_t< unsigned int, 100 > (
A_wrapper::* )(  ) )(&A_wrapper::pyplusplus__indexArray_wrapper) ) );;
        A_exposer.staticmethod( "test" );
    }
    bp::scope().attr("COUNT") = COUNT;
}
************************************************************************
*********************************************





-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/cplusplus-sig/attachments/20060719/c320dc8c/attachment.htm>


More information about the Cplusplus-sig mailing list