Reputation: 2746
I'm implementing a static C++ library for sorting algorithm using Xcode. I want to use this lib (file .a) in my iPhone App. Of course I will have to write a wrapper for C++ and C (file .mm).However my problem is that I want to be notified from this lib after each fixed period.
For example, I'm implementing "Insertion" algorithm, and I want the process happens in 10s, and then after each second, the lib will return a new sorted array (of course it's incomplete) until the last complete sorted array. How can I do this? How to notify Objective C from static lib C++ like this ? If not using static lib, I suppose the problem is not difficult, but I want to re-use this lib in Java also.
Upvotes: 2
Views: 211
Reputation: 122391
I have a similar project where much of the logic is implemented as a C++ library, which can be compiled either as a static or dynamic library. I also have a command line C++ test program, so all of my callbacks, which basically amount to how far they have got with something with the option to cancel, are implemented as simple C++ callbacks:
extern "C"
{
/**
* Callback function from long operations.
*
* @param gameNum The number of the game being processed (1-based).
* @param percentComplete Processing progress. (0.0 to 100.0).
* @param contextInfo Context Info passed to the database method.
*
* @return false to terminate processing, else true.
*/
typedef bool(*DATABASE_CALLBACK_FUNC)(unsigned gameNum, float percentComplete, void *contextInfo);
}
This works equally well in the C++ command line tool as the Objective-C++ based Cocoa app.
Notice that I use extern C
to make it also possible to use from C.
Upvotes: 1