[C++-sig] variable argument number and BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS

2009-05-21 Thread Hans Roessler

Hello,
I try to wrap a class with a function info([int arg]) that takes either zero or 
one argument (exact colde below). For some reason I can't get 
BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS to work.

The examples at 
http://www.boost.org/doc/libs/1_39_0/libs/python/doc/tutorial/doc/html/python/functions.html#python.overloading
 and
http://www.boost.org/doc/libs/1_39_0/libs/python/doc/v2/overloads.html#BOOST_PYTHON_FUNCTION_OVERLOADS-spec
 only show the situation where either
- the *member* function has up to three arguments with default values assigned 
or
- three *free* functions have one to three  arguments.

I don't find an example where a class has several *member* functions with the 
same name, that take a variable number of (non-default!) arguments.

My attempt below gives the error
"pytest.cpp:17: error: no matching function for call to 
‘boost::python::class_::def(const char [5], , A_info_overloads)’"

Do I have to replace the ".def("info",&A::info, ..." with something like  
".def("foo", (void(*)(int,int))0, ..." as shown in the Auto-Overloading section 
in the tutorial? If yes, how must this function signature look like? It doesn't 
work like this.

Hope someone can help
Hans

=== pytest.py ===
#include 
#include 

using namespace boost::python;

class A{
public:
  void info() {printf("This is an A\n");}
  void info(int arg) {printf("Unnecessary arg.\n");}
};

BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(A_info_overloads, info, 0,1)

BOOST_PYTHON_MODULE(test)
{
  class_("A")
  .def("info",&A::info,A_info_overloads()) //line 17
;
}



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

Re: [C++-sig] variable argument number and BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS

2009-05-21 Thread William Ladwig
I haven't tried this myself, but I think all you need to do to wrap the member 
function is this:

.def("info", (void(A::*)(int))0, A_info_overloads());

Hope this helps,
Bill

-Original Message-
From: [email protected] 
[mailto:[email protected]] On Behalf Of Hans 
Roessler
Sent: Thursday, May 21, 2009 8:40 AM
To: [email protected]
Subject: [C++-sig] variable argument number and 
BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS


Hello,
I try to wrap a class with a function info([int arg]) that takes either zero or 
one argument (exact colde below). For some reason I can't get 
BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS to work.

The examples at 
http://www.boost.org/doc/libs/1_39_0/libs/python/doc/tutorial/doc/html/python/functions.html#python.overloading
 and
http://www.boost.org/doc/libs/1_39_0/libs/python/doc/v2/overloads.html#BOOST_PYTHON_FUNCTION_OVERLOADS-spec
 only show the situation where either
- the *member* function has up to three arguments with default values assigned 
or
- three *free* functions have one to three  arguments.

I don't find an example where a class has several *member* functions with the 
same name, that take a variable number of (non-default!) arguments.

My attempt below gives the error
"pytest.cpp:17: error: no matching function for call to 
'boost::python::class_::def(const char [5], , A_info_overloads)'"

Do I have to replace the ".def("info",&A::info, ..." with something like  
".def("foo", (void(*)(int,int))0, ..." as shown in the Auto-Overloading section 
in the tutorial? If yes, how must this function signature look like? It doesn't 
work like this.

Hope someone can help
Hans

=== pytest.py ===
#include 
#include 

using namespace boost::python;

class A{
public:
  void info() {printf("This is an A\n");}
  void info(int arg) {printf("Unnecessary arg.\n");}
};

BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(A_info_overloads, info, 0,1)

BOOST_PYTHON_MODULE(test)
{
  class_("A")
  .def("info",&A::info,A_info_overloads()) //line 17
;
}



  
___
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] variable argument numberand BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS

2009-05-21 Thread Matthew Scouten (TT)
Well I think that's probably the 'proper' way to do things, but I
usually use the stupid-but-obvious ways.

Overloaded functions:
Class A
{
void info_1(int i){//Do Stuff}
void info_2(){//Do Stuff}
}

class_("A")
  .def("info",&A::info_1)
.def("info",&A::info_2)

Boost::python will sort out which to call. If bp can't correctly
distinguish the types, there may be surprises. (bool vs. int) 

Functions with defaults:
Class A
{
void info(int i = 0){//Do Stuff}
}

class_("A")
  .def("info",
&A::info, 
(arg('i') = 0) 
  )






-Original Message-
From:
cplusplus-sig-bounces+matthew.scouten=tradingtechnologies@python.org
[mailto:cplusplus-sig-bounces+matthew.scouten=tradingtechnologies@py
thon.org] On Behalf Of William Ladwig
Sent: Thursday, May 21, 2009 11:31 AM
To: Development of Python/C++ integration
Subject: Re: [C++-sig] variable argument numberand
BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS

I haven't tried this myself, but I think all you need to do to wrap the
member function is this:

.def("info", (void(A::*)(int))0, A_info_overloads());

Hope this helps,
Bill

-Original Message-
From: [email protected]
[mailto:[email protected]] On Behalf
Of Hans Roessler
Sent: Thursday, May 21, 2009 8:40 AM
To: [email protected]
Subject: [C++-sig] variable argument number and
BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS


Hello,
I try to wrap a class with a function info([int arg]) that takes either
zero or one argument (exact colde below). For some reason I can't get
BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS to work.

The examples at
http://www.boost.org/doc/libs/1_39_0/libs/python/doc/tutorial/doc/html/p
ython/functions.html#python.overloading and
http://www.boost.org/doc/libs/1_39_0/libs/python/doc/v2/overloads.html#B
OOST_PYTHON_FUNCTION_OVERLOADS-spec only show the situation where either
- the *member* function has up to three arguments with default values
assigned or
- three *free* functions have one to three  arguments.

I don't find an example where a class has several *member* functions
with the same name, that take a variable number of (non-default!)
arguments.

My attempt below gives the error
"pytest.cpp:17: error: no matching function for call to
'boost::python::class_::def(const char [5], , A_info_overloads)'"

Do I have to replace the ".def("info",&A::info, ..." with something like
".def("foo", (void(*)(int,int))0, ..." as shown in the Auto-Overloading
section in the tutorial? If yes, how must this function signature look
like? It doesn't work like this.

Hope someone can help
Hans

=== pytest.py ===
#include 
#include 

using namespace boost::python;

class A{
public:
  void info() {printf("This is an A\n");}
  void info(int arg) {printf("Unnecessary arg.\n");}
};

BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(A_info_overloads, info, 0,1)

BOOST_PYTHON_MODULE(test)
{
  class_("A")
  .def("info",&A::info,A_info_overloads()) //line 17
;
}



  
___
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
___
Cplusplus-sig mailing list
[email protected]
http://mail.python.org/mailman/listinfo/cplusplus-sig


Re: [C++-sig] variable argument number and BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS

2009-05-21 Thread Hans Roessler

Thanks, ".def("info", (void(A::*)(int))0, A_info_overloads());" does it.

Could somebody explain what the meaning of this "(void(A::*)(int))0" construct 
is? Is it a function pointer? Why the 0?
(Just now I am fine with the proposed solution, but if I even understand it, 
you will read fewer stupid question from me in this list ;-)


Hans



- Ursprüngliche Mail 
> Von: William Ladwig 
> An: Development of Python/C++ integration 
> Gesendet: Donnerstag, den 21. Mai 2009, 18:30:46 Uhr
> Betreff: Re: [C++-sig] variable argument number and 
> BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS
> 
> I haven't tried this myself, but I think all you need to do to wrap the 
> member 
> function is this:
> 
> .def("info", (void(A::*)(int))0, A_info_overloads());
> 
> Hope this helps,
> Bill



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


[C++-sig] iterate a boost::python::list

2009-05-21 Thread Hans Roessler

How can I iterate in C++ over a boost::python::list?

According to http://www.boost.org/doc/libs/1_39_0/libs/python/doc/v2/list.html 
it has no begin() and end() functions.
Neither a size() function that would allow to call pop(size()-1). Neither an 
isEmpty() function that would allow to call pop(0) until the list is empty.

I'm sure I'm missing something trivial. Can somebody help me?

Thanks
Hans



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


Re: [C++-sig] variable argument number and BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS

2009-05-21 Thread William Ladwig
It's making a NULL pointer to a member function of A with an integer argument 
and a void return type.  

I'm not sure what's going on under the hood with why the NULL is required, but 
I suspect that it has something to do with the fact that 

void info();
void info(int i);

require two function pointers, but 

void info(int i=0) 

can only use one function pointer.  I suspect that they're trying to handle 
both cases with the same interface.  I'm just guessing though, so I could be 
wrong about this.

Regards,
Bill


-Original Message-
From: [email protected] 
[mailto:[email protected]] On Behalf Of Hans 
Roessler
Sent: Thursday, May 21, 2009 4:00 PM
To: Development of Python/C++ integration
Subject: Re: [C++-sig] variable argument number and 
BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS


Thanks, ".def("info", (void(A::*)(int))0, A_info_overloads());" does it.

Could somebody explain what the meaning of this "(void(A::*)(int))0" construct 
is? Is it a function pointer? Why the 0?
(Just now I am fine with the proposed solution, but if I even understand it, 
you will read fewer stupid question from me in this list ;-)


Hans



- Ursprüngliche Mail 
> Von: William Ladwig 
> An: Development of Python/C++ integration 
> Gesendet: Donnerstag, den 21. Mai 2009, 18:30:46 Uhr
> Betreff: Re: [C++-sig] variable argument number and 
> BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS
> 
> I haven't tried this myself, but I think all you need to do to wrap the 
> member 
> function is this:
> 
> .def("info", (void(A::*)(int))0, A_info_overloads());
> 
> Hope this helps,
> Bill



  
___
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] iterate a boost::python::list

2009-05-21 Thread Ralf W. Grosse-Kunstleve

It should work like this (untested):

  boost::python::ssize_t n = boost::python::len(your_list);
  for(boost::python::ssize_t i=0;i
To: Development of Python/C++ integration 
Sent: Thursday, May 21, 2009 2:08:03 PM
Subject: [C++-sig] iterate a boost::python::list


How can I iterate in C++ over a boost::python::list?

According to http://www.boost.org/doc/libs/1_39_0/libs/python/doc/v2/list.html 
it has no begin() and end() functions.
Neither a size() function that would allow to call pop(size()-1). Neither an 
isEmpty() function that would allow to call pop(0) until the list is empty.

I'm sure I'm missing something trivial. Can somebody help me?

Thanks
Hans

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