nonwrapper C++ bindings for GTK (just an idea and a script)



Greetings,

I have made a small perl skript that makes my life with GTK+ much easier
and so I thought to share it with you. Basically it takes the general
GTK+ headers and adds a few C++ lines (all ifdef'ed __cplusplus of course).
After the script is run these header files can be both used from C and
C++ code.

The additions are just some C++ inline-methods inside the struct
declarations, and the use of the C++ inclusion/inheritance syntax
at the struct start for the base type of each of the structures 
(again #ifdef __cplusplus of course). 

As a result, the enhenced (GTK) headers are much more easier to use from C++.
For the one thing, a C++ compiler does know now about the inheritance 
relations  for the structures, so you can leave off the ubiquitous big-caps 
cast-macros - instead you will benefit from compile-time type-checking as is 
builtin each C++ compiler. 

For the other thing, you can use the (GTK) procedures as inlined methods 
along the defined objects. Your code will become much shorter - and in 
consequence more readable and maintainable. And you don't have to think 
about which base-type had been introducing the set_border_width method - 
you can just call the method of that object instance (or their
class-scope static-declared counterpart that is also generated). 

Unlike real C++ wrappers, like GTK--, the object size will not increase 
by a single byte. No additional library needs to be linked in, so even the
runtime footprint is the same. And if you don't have a C++ compiler 
at hand (huh?), you can start rewriting the C++ code in an incremental 
way because the methods are directly derived from their underlying C-language
procedure names. Since the very same headers can be used with a C compiler 
you will end up at just changing the file extension and it will compile cleanly. 

If you want to add some functionality you can always switch into to C++ mode, 
make a RAD implementation, and if you're done you can rewrite it back into 
plain C. Nothing could be easier. It does help me a lot in my smallish GTK 
developments - and I don't need a real wrapper bloatware for it (as is
some C++/GTK-wrapper or even Perl/GTK). 

I don't know if the idea may have come up earlier, I checked the mailing list
archive (about 6 months or so), and I didn't find anything like this. I have
made similar stuff even years back but interestingly enough I could not find 
sth. similar at freshmeat, so I thought to wrap it up as a tarball and make 
up a website.

You can get a few more details (and the script of course) from
http://sourceware.de/cc-headers

have fun
-- guido
mailto:guidod@gmx.de                        "Edel sei der Mensch,
gsm:+49 177 5928220                          hilfreich und gut" -Goethe



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]