[C++-sig] Py++ module for code with protected operator=

2010-03-19 Thread Maciej Sitarz

Hi all,

I want to create python module for class that has protected operator=.
That class placed in std::vector and code generated by Py++ uses that 
operator.


Simple example...
*
The c++ code:

#include 

class JobPropertyWrapper {
protected:
JobPropertyWrapper& operator=( const 
JobPropertyWrapper& aProp ) throw () { return *this; }

};

class classA {
public:
void fun( const std::vector& v) { }
};

int main() {
classA c;
c.fun( std::vector() );
return 1;
}

**
Py++ script:

mb = module_builder.module_builder_t( ... )
mb.class_( 'JobPropertyWrapper' ).noncopyable = True
mb.build_code_creator( module_name='test' )

**
The compile error(part of it):

test.h:6: error: 'JobPropertyWrapper& 
JobPropertyWrapper::operator=(const JobPropertyWrapper&)' is protected
/usr/include/boost/python/suite/indexing/vector_indexing_suite.hpp:91: 
error: within this context
test.h: In member function 'void std::vector<_Tp, 
_Alloc>::_M_insert_aux(__gnu_cxx::__normal_iteratorstd::_Vector_base<_Tp, _Alloc>::_Tp_alloc_type::pointer, 
std::vector<_Tp, _Alloc> >, const _Tp&) [with _Tp = JobPropertyWrapper, 
_Alloc = std::allocator]':



As you can see i tried to inform py++ that the class is 'noncopyable' 
but that didn't do the trick.


I attached the generated code.
There's also some problem with operator== not existing, which I also 
didn't know how to fix.


Thanks in advance
--
Maciek Sitarz

--
Maciek Sitarz
// This file has been generated by Py++.

#include "boost/python.hpp"

#include "boost/python/suite/indexing/vector_indexing_suite.hpp"

#include "test.h"

namespace bp = boost::python;

BOOST_PYTHON_MODULE(test){
{ //::std::vector< JobPropertyWrapper >
typedef bp::class_< std::vector< JobPropertyWrapper > > vector_less__JobPropertyWrapper__greater__exposer_t;
vector_less__JobPropertyWrapper__greater__exposer_t vector_less__JobPropertyWrapper__greater__exposer = vector_less__JobPropertyWrapper__greater__exposer_t( "vector_less__JobPropertyWrapper__greater_" );
bp::scope vector_less__JobPropertyWrapper__greater__scope( vector_less__JobPropertyWrapper__greater__exposer );
//WARNING: the next line of code will not compile, because "::JobPropertyWrapper" does not have operator== !
vector_less__JobPropertyWrapper__greater__exposer.def( bp::vector_indexing_suite< ::std::vector< JobPropertyWrapper > >() );
}

bp::class_< JobPropertyWrapper, boost::noncopyable >( "JobPropertyWrapper" );

bp::class_< classA >( "classA" )
.def( 
"fun"
, (void ( ::classA::* )( ::std::vector< JobPropertyWrapper > const & ) )( &::classA::fun )
, ( bp::arg("v") ) );

{ //::main

typedef int ( *main_function_type )(  );

bp::def( 
"main"
, main_function_type( &::main ) );

}
}
___
Cplusplus-sig mailing list
[email protected]
http://mail.python.org/mailman/listinfo/cplusplus-sig

[C++-sig] docstring for property?

2010-03-19 Thread Gennadiy Rozental
How do I provide doc string to the property like this:
...

   .add_property( "goo", make_function(...) )

While we are at it, how do I provide docstring and arg names to the operators:

...
   .def( self < self )


Gennadiy

___
Cplusplus-sig mailing list
[email protected]
http://mail.python.org/mailman/listinfo/cplusplus-sig


[C++-sig] boost.pyton scope bug?

2010-03-19 Thread Gennadiy Rozental
I am doing something like this in export part of mymodule:

scope S = class_("X", no_init );

class_( "Y",... )
...
;

In Python I do see mymodule.X.Y, but mymodule.X.Y.__name__ is 'mymodule.Y'

Gennadiy

___
Cplusplus-sig mailing list
[email protected]
http://mail.python.org/mailman/listinfo/cplusplus-sig


Re: [C++-sig] boost.pyton scope bug?

2010-03-19 Thread Jim Bosch
On Fri, 2010-03-19 at 19:55 +, Gennadiy Rozental wrote:
> I am doing something like this in export part of mymodule:
> 
> scope S = class_("X", no_init );
> 
> class_( "Y",... )
> ...
> ;
> 
> In Python I do see mymodule.X.Y, but mymodule.X.Y.__name__ is 'mymodule.Y'
> 

Hmm.  In the same situation, I simply get mymodule.X.Y.__name__ ==
'Y' (and mymodule.X.__name__ == 'X') - no module prefixes at all.  That
matches the pure-python inner class result, at least on my system.

I do get mymodule.X.__module__ == 'mymodule' and mymodule.X.Y.__module__
== 'mymodule', but that's also correct as far as mirroring the
pure-python inner class result.

(This is Python 2.6.4; it may have changed in 3.0, but I certainly hope
it doesn't depend on anything else).

Note that you can change the __module__ attribute; I often import my
wrapped names into different submodules in a package and adjust their
__module__ accordingly to make a Python interface that mirrors the C++
namespaces better - but all that has to be done in Python; boost python
can't do it for you (maybe Py++ could?)

Jim Bosch


___
Cplusplus-sig mailing list
[email protected]
http://mail.python.org/mailman/listinfo/cplusplus-sig


Re: [C++-sig] boost.pyton scope bug?

2010-03-19 Thread Gennadiy Rozental
Jim Bosch  gmail.com> writes:

> 
> On Fri, 2010-03-19 at 19:55 +, Gennadiy Rozental wrote:
> > I am doing something like this in export part of mymodule:
> > 
> > scope S = class_("X", no_init );
> > 
> > class_( "Y",... )
> > ...
> > ;
> > 
> > In Python I do see mymodule.X.Y, but mymodule.X.Y.__name__ is 'mymodule.Y'
> > 
> 
> Hmm.  In the same situation, I simply get mymodule.X.Y.__name__ ==
> 'Y' (and mymodule.X.__name__ == 'X') - no module prefixes at all.  That
> matches the pure-python inner class result, at least on my system.

You right. I got it wrong when reported the error. The problem, is that when I
print mymodule.X.Y I am getting  which is wrong IMO
 
> I do get mymodule.X.__module__ == 'mymodule' and mymodule.X.Y.__module__
> == 'mymodule', but that's also correct as far as mirroring the
> pure-python inner class result.

Well I hoped to mimic some kind of subnamespace with scope. Thus the module
should be mymodule.X or the name should be X.Y

> Note that you can change the __module__ attribute; I often import my
> wrapped names into different submodules in a package and adjust their
> __module__ accordingly to make a Python interface that mirrors the C++
> namespaces better - but all that has to be done in Python; boost python
> can't do it for you (maybe Py++ could?)

Can you show an example?

I am currently tweaking this Python as well (post loading) like this:

mymodule.X.Y.__name__ = 'X.Y'

It's still not completely satisfactory, since help(mymodule.X) does not do the
right job, but at least it does not show Y as 'mymodule.Y'

Gennadiy

___
Cplusplus-sig mailing list
[email protected]
http://mail.python.org/mailman/listinfo/cplusplus-sig


[C++-sig] how to avoid documenting private methods

2010-03-19 Thread Gennadiy Rozental
I've got exported class A and I'd like to avoid reporting private methods when
users type help (mymodule.A). Is there anything like __all__ for modules? naming
these methods starting with _ does not help either.

Please advise,

Gennadiy

___
Cplusplus-sig mailing list
[email protected]
http://mail.python.org/mailman/listinfo/cplusplus-sig