[C++-sig] Returning a simple char *
Hello,
I thought I was trying to do something simple.
While wrapping a 3rd party library, I have a c++ class with two member
function returning pointers like this:
class videoInput
{
public:
static char * getDeviceName(int deviceID);
};
and a module like this:
#include "boost//python.hpp"
#include "videoInput.h"
using namespace boost::python;
BOOST_PYTHON_MODULE(pyVideoInput)
{
class_("videoInput")
.def("getDeviceName",
&videoInput::getDeviceName,
return_value_policy())
.staticmethod("getDeviceName")
;
}
Following the guide here
(http://wiki.python.org/moin/boost.python/PointersAndSmartPointers) I
thought this was the right way but I get errors:
pyVideoInput.cpp
C:\boost_1_41_0\boost/python/object/make_instance.hpp(24) : error C2027:
use of undefined type 'boost::STATIC_ASSERTION_FAILURE
'
with
[
x=false
]
C:\boost_1_41_0\boost/python/to_python_indirect.hpp(95) : see
reference to function template instantiation 'PyObject *boos
t::python::objects::make_instance_impl::execute(Arg
&)' being compiled
with
[
T=char,
Holder=holder_t,
Derived=boost::python::objects::make_ptr_instance,
Arg=smart_pointer
]
..
pyVideoInput.cpp(16) : see reference to function template
instantiation 'boost::python::class_ &boost::python::class_>::def*)(int),boost::python::return_value_policy>(const
char *,A1,const A2 &)' being comp
iled
with
[
W=videoInput,
ResultConverterGenerator=boost::python::manage_new_object,
A1=char *(__cdecl *)(int),
A2=boost::python::return_value_policy
]
//
It seems to be attempting to use a smart_ptr?
Can anyone help explain this to me? Many thanks
Simon
___
Cplusplus-sig mailing list
[email protected]
http://mail.python.org/mailman/listinfo/cplusplus-sig
[C++-sig] Member function bp::optional? Or workaround?
I have a few default parameters in a couple of my member functions, and
these functions do not conform to the format required
forBOOST_PYTHON_MEMBER_FUNCTION_OVERLOAD..
I was wondering how to go about creating those thin wrappers for these
functions.
For example, my class would be something like
struct Foo
{
int bar( const Y* = NULL );
int bar( const X&, const Y* = NULL );
};
___
Cplusplus-sig mailing list
[email protected]
http://mail.python.org/mailman/listinfo/cplusplus-sig
Re: [C++-sig] Member function bp::optional? Or workaround?
On Dienstag 12 Januar 2010, Charles Solar wrote: > I have a few default parameters in a couple of my member functions, and > these functions do not conform to the format required > forBOOST_PYTHON_MEMBER_FUNCTION_OVERLOAD.. I never use BOOST_PYTHON_MEMBER_FUNCTION_OVERLOAD anyway. You may freely .def'ine multiple overloads yourself. (Or maybe you want to try pyplusplus, if you have many such functions.) -- Ciao, / /.o. /--/ ..o / / ANS ooo signature.asc Description: This is a digitally signed message part. ___ Cplusplus-sig mailing list [email protected] http://mail.python.org/mailman/listinfo/cplusplus-sig
Re: [C++-sig] Member function bp::optional? Or workaround?
Well I want to define the overloads myself anyway, I just do not know how to properly setup the small wrapper that will work. In the doc it tells you how to make flat function wrappers, but nothing on member function wrappers. I am unsure how I am supposed to handle the this pointer, for example. So idealy what I would like to know is what the macro does so I can manually write out the wrappers myself. And I have tried using Py++, it does not handle the default argument, it just puts the call in there and python still requires the param to be there. On Tue, Jan 12, 2010 at 1:21 PM, Hans Meine wrote: > On Dienstag 12 Januar 2010, Charles Solar wrote: > > I have a few default parameters in a couple of my member functions, and > > these functions do not conform to the format required > > forBOOST_PYTHON_MEMBER_FUNCTION_OVERLOAD.. > > I never use BOOST_PYTHON_MEMBER_FUNCTION_OVERLOAD anyway. You may > freely .def'ine multiple overloads yourself. (Or maybe you want to try > pyplusplus, if you have many such functions.) > > -- > Ciao, / /.o. > /--/ ..o >/ / ANS ooo > > ___ > Cplusplus-sig mailing list > [email protected] > http://mail.python.org/mailman/listinfo/cplusplus-sig > ___ Cplusplus-sig mailing list [email protected] http://mail.python.org/mailman/listinfo/cplusplus-sig
Re: [C++-sig] [boost.python] How can I wrap operator==?
On Mon, Jan 11, 2010 at 6:05 AM, blp330 wrote: > > Hi, > > I want to wrap operator== for my object, Py++ generates that: > > Document_exposer.def( bp::self != bp::self); > Document_exposer.def( bp::self == bp::self ); > > But I want to do something more, so I try to wrap it with: > > Document_exposer.def( > bp::self != bp::self > , &Document__NotEqualWrap ); > Document_exposer.def( > bp::self == bp::self > , &Document__EqualWrap ); > > It can't be compiled... > > How can I do? It is not clear what you are asking for. If the "Document" class has special function for comparison, than may be you can define few global operators ( == and != ). -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ ___ Cplusplus-sig mailing list [email protected] http://mail.python.org/mailman/listinfo/cplusplus-sig
Re: [C++-sig] Member function bp::optional? Or workaround?
Charles Solar wrote:
Well I want to define the overloads myself anyway, I just do not know
how to properly setup the small wrapper that will work. In the doc it
tells you how to make flat function wrappers, but nothing on member
function wrappers. I am unsure how I am supposed to handle the this
pointer, for example.
So idealy what I would like to know is what the macro does so I can
manually write out the wrappers myself.
And I have tried using Py++, it does not handle the default argument, it
just puts the call in there and python still requires the param to be there.
Personally I hate that overload-wrapping macro thing. Here's one way to
do it:
struct T
{
void bar(int i) { cout << "bar(" << i << ")\n"; }
void bar() { cout << "bar\n"; }
};
//
// use 'self' for 'this' for the sake of pythonicism
//
void bar_int (T* self, int i) { self->bar(i); }
void bar_void(T* self){ self->bar(); }
BOOST_PYTHON_MODULE(foop)
{
class_("T")
.def("bar", bar_int)
.def("bar", bar_void)
;
}
-t
___
Cplusplus-sig mailing list
[email protected]
http://mail.python.org/mailman/listinfo/cplusplus-sig
Re: [C++-sig] Member function bp::optional? Or workaround?
Looks perfect, thanks much.
On Tue, Jan 12, 2010 at 2:01 PM, troy d. straszheim wrote:
> Charles Solar wrote:
>
>> Well I want to define the overloads myself anyway, I just do not know how
>> to properly setup the small wrapper that will work. In the doc it tells you
>> how to make flat function wrappers, but nothing on member function wrappers.
>> I am unsure how I am supposed to handle the this pointer, for example.
>> So idealy what I would like to know is what the macro does so I can
>> manually write out the wrappers myself.
>>
>> And I have tried using Py++, it does not handle the default argument, it
>> just puts the call in there and python still requires the param to be there.
>>
>>
> Personally I hate that overload-wrapping macro thing. Here's one way to do
> it:
>
> struct T
> {
> void bar(int i) { cout << "bar(" << i << ")\n"; }
> void bar() { cout << "bar\n"; }
> };
>
> //
> // use 'self' for 'this' for the sake of pythonicism
> //
> void bar_int (T* self, int i) { self->bar(i); }
> void bar_void(T* self){ self->bar(); }
>
> BOOST_PYTHON_MODULE(foop)
> {
> class_("T")
>.def("bar", bar_int)
>.def("bar", bar_void)
>;
> }
>
> -t
>
>
> ___
> Cplusplus-sig mailing list
> [email protected]
> http://mail.python.org/mailman/listinfo/cplusplus-sig
>
___
Cplusplus-sig mailing list
[email protected]
http://mail.python.org/mailman/listinfo/cplusplus-sig
Re: [C++-sig] Member function bp::optional? Or workaround?
On Tue, Jan 12, 2010 at 9:46 PM, Charles Solar wrote:
> And I have tried using Py++, it does not handle the default argument, it
> just puts the call in there and python still requires the param to be there.
Can you explain what you mean?
The following code was generated by Py++:
bp::class_< overloads_macro::Foo >( "Foo")
.def(
"bar"
, (int ( ::overloads_macro::Foo::* )( ::overloads_macro::Y
const * ) )( &::overloads_macro::Foo::bar )
, ( bp::arg("arg0")=bp::object() ) )
.def(
"bar"
, (int ( ::overloads_macro::Foo::* )( ::overloads_macro::X
const &,::overloads_macro::Y const * ) )( &::overloads_macro::Foo::bar
)
, ( bp::arg("arg0"), bp::arg("arg1")=bp::object() ) );
as you can see ( and try ) the generated code does not "requires" the
user to pass default arguments.
--
Roman Yakovenko
C++ Python language binding
http://www.language-binding.net/
___
Cplusplus-sig mailing list
[email protected]
http://mail.python.org/mailman/listinfo/cplusplus-sig
Re: [C++-sig] Member function bp::optional? Or workaround?
On Dienstag 12 Januar 2010, Charles Solar wrote:
> Well I want to define the overloads myself anyway, I just do not know how
> to properly setup the small wrapper that will work.
Oh, OK.
> In the doc it tells
> you how to make flat function wrappers, but nothing on member function
> wrappers.
I am 100% sure that they're documented, yet I am not very lucky with the docs
either.
> I am unsure how I am supposed to handle the this pointer, for
> example.
You can reference the member function pointer like this (untested of course):
.def("bar", (void(Foo::*)(const Y*))&T::bar)
.def("bar", (void(Foo::*)(const X&,const Y*))&T::bar)
> So idealy what I would like to know is what the macro does so I can
> manually write out the wrappers myself.
>
> And I have tried using Py++, it does not handle the default argument, it
> just puts the call in there and python still requires the param to be
> there.
Really? AFAIK, it should work.
You should be able to write (arg("some_x"), arg("some_y") = NULL)) as
extra .def() argument.
Maybe py++ does not output the default args when the arguments are unnamed?
(I wouldn't know how, either.)
--
Ciao, / /.o.
/--/ ..o
/ / ANS ooo
signature.asc
Description: This is a digitally signed message part.
___
Cplusplus-sig mailing list
[email protected]
http://mail.python.org/mailman/listinfo/cplusplus-sig
Re: [C++-sig] Member function bp::optional? Or workaround?
Hmm, well if the arg definition matters like you two are suggesting it does,
then maybe the python code from Py++ does work.
Right now it generates code that I use, but I do not include the bp::object,
so my function in boost python looks like
int (Foo::*bar1)( const Y*) = &Foo::bar;
int (Foo::*bar2)(const X&, const Y*) = &Foo::bar;
...
.def( "bar", bar1 )
.def( "bar", bar2 )
That requires python to supply Y* but if I understand what you two are
saying
.def( "bar", bar1, ( bp::arg("Y") = bp::object() ) )
.def( "bar", bar2, ( bp::arg("X"), bp::arg(Y) = bp::object() ) )
would make python not require that default arg. If that is the case then i
guess all is well. When I saw Py++ generate that I figured bp::object() was
just some weird thing I did not have to worry about.
the documentation page I have been using and could not find an example of
member function default params is here
http://www.boost.org/doc/libs/1_41_0/libs/python/doc/tutorial/doc/html/python/functions.html#python.default_arguments
perhaps it would be nice to note this very handy bp::object somewhere.
Thanks
On Tue, Jan 12, 2010 at 2:09 PM, Hans Meine wrote:
> On Dienstag 12 Januar 2010, Charles Solar wrote:
> > Well I want to define the overloads myself anyway, I just do not know how
> > to properly setup the small wrapper that will work.
>
> Oh, OK.
>
> > In the doc it tells
> > you how to make flat function wrappers, but nothing on member function
> > wrappers.
>
> I am 100% sure that they're documented, yet I am not very lucky with the
> docs
> either.
>
> > I am unsure how I am supposed to handle the this pointer, for
> > example.
>
> You can reference the member function pointer like this (untested of
> course):
>
> .def("bar", (void(Foo::*)(const Y*))&T::bar)
> .def("bar", (void(Foo::*)(const X&,const Y*))&T::bar)
>
> > So idealy what I would like to know is what the macro does so I can
> > manually write out the wrappers myself.
> >
> > And I have tried using Py++, it does not handle the default argument, it
> > just puts the call in there and python still requires the param to be
> > there.
>
> Really? AFAIK, it should work.
>
> You should be able to write (arg("some_x"), arg("some_y") = NULL)) as
> extra .def() argument.
>
> Maybe py++ does not output the default args when the arguments are unnamed?
> (I wouldn't know how, either.)
>
> --
> Ciao, / /.o.
> /--/ ..o
>/ / ANS ooo
>
> ___
> Cplusplus-sig mailing list
> [email protected]
> http://mail.python.org/mailman/listinfo/cplusplus-sig
>
___
Cplusplus-sig mailing list
[email protected]
http://mail.python.org/mailman/listinfo/cplusplus-sig
Re: [C++-sig] [boost.python] How can I wrap operator==?
Um... Sorry, I mean I have a class Document, which defined
class Document
{
public:
bool operator==(const Document& other) const
{
return Compare(other);
}
};
It simply call Compare method, I need to something more when I use it in
python code but I don't want to change my Document class implementation
because it can be used by other language that do not need extra code.
Py++ generates:
Document_exposer.def( bp::self == bp::self );
For other Document method I can change Py++ generated code to do something
more, for example:
Py++:
{
typedef ::StringPtr ( ::Document::*Thumb_function_type )(
int,int ) const;
Document_exposer.def(
"Thumb"
//, Thumb_function_type( &::Document::Thumb )
, &Document__ThumbWrap
, ( bp::arg("width"), bp::arg("height") ) );
}
I can define a Document__ThumbWrap function to write my extra code in it.
But operator==, I don't know how to do that.
I can't simply change
Document_exposer.def( bp::self == bp::self );
to
Document_exposer.def(
bp::self == bp::self
, &Document__EqualWrap
);
to write my extra code in Document__EqualWrap.
Thank you very much.
--
View this message in context:
http://old.nabble.com/-boost.python--How-can-I-wrap-operator%3D%3D--tp27105703p27140350.html
Sent from the Python - c++-sig mailing list archive at Nabble.com.
___
Cplusplus-sig mailing list
[email protected]
http://mail.python.org/mailman/listinfo/cplusplus-sig
Re: [C++-sig] [boost.python] How can I wrap operator==?
On Wed, Jan 13, 2010 at 8:57 AM, blp330 wrote:
>
> Um... Sorry, I mean I have a class Document, which defined
>
> class Document
> {
> public:
>
>
> bool operator==(const Document& other) const
> {
> return Compare(other);
> }
> };
>
> It simply call Compare method, I need to something more when I use it in
> python code but I don't want to change my Document class implementation
> because it can be used by other language that do not need extra code.
>
> Py++ generates:
> Document_exposer.def( bp::self == bp::self );
>
> For other Document method I can change Py++ generated code to do something
> more, for example:
> Py++:
> {
> typedef ::StringPtr ( ::Document::*Thumb_function_type )(
> int,int ) const;
>
> Document_exposer.def(
> "Thumb"
> //, Thumb_function_type( &::Document::Thumb )
> , &Document__ThumbWrap
> , ( bp::arg("width"), bp::arg("height") ) );
>
> }
> I can define a Document__ThumbWrap function to write my extra code in it.
>
> But operator==, I don't know how to do that.
> I can't simply change
> Document_exposer.def( bp::self == bp::self );
> to
> Document_exposer.def(
> bp::self == bp::self
> , &Document__EqualWrap
> );
> to write my extra code in Document__EqualWrap.
If I understand you right, you need:
1. define new global function, which takes Document& as the first argument
bool Document_EqualWrap( const Document& x, const Document& y ){...}
2. Expose it:
...
.def( "__eq__", &Document_EqualWrap )
Is not the working code, but it should give you a direction.
--
Roman Yakovenko
C++ Python language binding
http://www.language-binding.net/
___
Cplusplus-sig mailing list
[email protected]
http://mail.python.org/mailman/listinfo/cplusplus-sig
