Howdy, y’all
I’m a long-time sometimes-maintainer of the Geeqie image-viewer. For a variety of reasons, it makes sense to investigate porting the codebase from C to C++. The codebase is around 20 years old, and is around 100k lines of C. So if this project is going to go anywhere, I’d need to find incremental ways to make progress. I can’t just re-type everything from scratch. It doesn’t matter too much whether the end state is GTK+, GTKMM, or some other GTK wrapper. But it needs to be C++.
I did the dumb thing first (just compile the C files as C++), and it took surprisingly little work to get that working.
But now, as I’m trying to turn a C-style class (aka a struct and a 4,000-line implementation) into a C++-style class, I’m running into trouble. Specifically, I need to use methods for callbacks instead of just unbound functions. To keep things concrete, I’m working on a g_hash_table_foreach
call right now.
The obvious approach here is to pass some kind of functor object through user_data
. But for cases that already include a user_data
pointer, that means I’d have to re-do those to wrap the original user_data
pointer, along with the this
and the method pointer. That’s doable, but it could turn into a lot of code changes (and also a lot of memory allocations that I’d need to manage.)
Is there a better way? Whether for this question specifically, or for this project more generally?