473,394 Members | 1,773 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Boost.Python create extra functions not in wrapped object

Hi,

I have a python library created by wrapping the C++ library using
Boost.Python, the problem is that the wrappers are not very
pythonic.... so I want to add some methods that do not exist in the C+
+ implementation, that would create a better Python interface.

For example to initialize the data in an object in the library one
must iterate through every point, setting a value for each
individually. That's the way it works in C++ but in python it would
be nice to instead just have one call that can receive a numpy array
or a tuple. I want to add a call like: setData(array) to the python
object, a call that does not exist in the C++ implementation and then
in the C++ wrappers actually use setData to iterate through the array
and set the values using the normal C++ method, say setValue(index,
value).

Something along the lines of this (initData is not in the constructor
on purpose) C++ object:

class Foo
{
public:
void initData(int size)
{
data = new float[size];
}; // Create the data array
void setValue(int index, float value) // Set given value
{
data[index] = value;
}
private:
float *data;
};
In python however I want to do this:

obj = foo()
ar = array([1,2,3,4,5], dtype=float)

foo.setData(ar)

Or even better:

ar = array([1,2,3,4,5], dtype=float)
obj = foo(ar)

And have it somehow call initData() and setValue() iteration inside
the C++ code of the wrapper. I've only used SWIG and don't really
know much about Boost, I am not even sure how to label what I am
trying to do.

Can this be done with Boost, without changing the C++ library?

Regards,

Stou

Apr 19 '07 #1
0 1073

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Steve Knight | last post by:
Hello, I'm new to Boost & Python and I'm diving straight in by trying to write an extension module to a third party library. Foolishness probably, but I don't have much choice! My question...
0
by: Osiris | last post by:
My experiences with BOOST on Windows XP and Visual C++ 2005 I'm new to Python. I built software in more than ten other computer languages. I'm not sure if that is not a handicap, when reading...
0
by: willievdm | last post by:
Hi all I'm working with Boost.Python at the moment and have to do the following: -Using Boost, assign a char* in C++ to a PySwigObject (SWIG exposed object) of type uchar*, which is received in...
4
by: Shawn McGrath | last post by:
Hi, I'm trying to expose a C++ class' internals to python via boost::python. I can do integer/boolean functions fine, but as soon as I do a string get/set it craps out. ...
270
by: Jordan | last post by:
Hi everyone, I'm a big Python fan who used to be involved semi regularly in comp.lang.python (lots of lurking, occasional posting) but kind of trailed off a bit. I just wrote a frustration...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.