When you want to wrap functions (or member functions) that either :
Lets move onto see how MACROS makes things easier.
[1] https://wiki.python.org/moin/boost.python/FunctionOverloading
[2] http://www.boost.org/doc/libs/1_55_0/libs/python/doc/tutorial/doc/html/python/functions.html#python.default_arguments
- have default arguments (or)
- are overloaded with a common sequence of initial arguments
we can either do a Manual wrapping or we can go for MACRO INVOCATION introduced by Boost.Python which makes wrapping simpler and easier.
Manual Wrapping
Overloaded Functions
We have here our C++ example class :
Class hello has 3 overloaded functions. To expose these in Python, we have to wrap them manually as shown below, else Python wouldn't understand which function to call when.
Default Arguments
To have an idea about how Boost.Python manual wrapping works with Default arguments, have a look at it here. Boost website provides a clear explanation for this. So, am not gonna explain it here.Lets move onto see how MACROS makes things easier.
MACROS
The macros used for this are as below.
For global functions and static methods :
For Class Methods :
Using MACROS our above program, can be written as,
When built and run using Python interpreter, we get the following desired output.
Reference :
[1] https://wiki.python.org/moin/boost.python/FunctionOverloading
[2] http://www.boost.org/doc/libs/1_55_0/libs/python/doc/tutorial/doc/html/python/functions.html#python.default_arguments
No comments:
Post a Comment