Re: X11/C++ question
> > In message <[EMAIL PROTECTED]> Chuck Robey >writes: > : Uhhh? I've long since got the answer I wanted, but this seems a complete > : mystery, so I'll bite, what's a OI_add_event? From some package? Can't > : find a man page on it. > > OI was a native C++ toolkit that had a nice interface and was ported > to Linux and FreeBSD back in 1993 or so by yours truly. It was > available from ParcPlace. Sadly, it never went anywhere and all > efforts of the engineers to make it open sourced (this was in 1996) > failed. It was ment as a joke for the long timers on the list... > > Warner > > > > To Unsubscribe: send mail to [EMAIL PROTECTED] > with "unsubscribe freebsd-hackers" in the body of the message > Let me add that as a stock holder of ParcPlace (now ObjectShare) and one of the people who tried out OI - I was disappointed it didn't go anywhere. It seemed nice... (I wonder where it is now?) ObjectShare is trading right now at 44-cents/share - an amazing 18.92% increase so far for the day (up 7 cents). Perhaps that outstanding stock price reflects the outcome of some of their decisions? [I believe my last purchase of ObjectShare was somewhere in the $10 range... sigh.] - Dave Rivers - To Unsubscribe: send mail to [EMAIL PROTECTED] with "unsubscribe freebsd-hackers" in the body of the message
Re: X11/C++ question
In message <[EMAIL PROTECTED]> Chuck Robey writes: : Uhhh? I've long since got the answer I wanted, but this seems a complete : mystery, so I'll bite, what's a OI_add_event? From some package? Can't : find a man page on it. OI was a native C++ toolkit that had a nice interface and was ported to Linux and FreeBSD back in 1993 or so by yours truly. It was available from ParcPlace. Sadly, it never went anywhere and all efforts of the engineers to make it open sourced (this was in 1996) failed. It was ment as a joke for the long timers on the list... Warner To Unsubscribe: send mail to [EMAIL PROTECTED] with "unsubscribe freebsd-hackers" in the body of the message
Re: X11/C++ question
On Wed, 3 Nov 1999, Warner Losh wrote: > In message <[EMAIL PROTECTED]> Chuck Robey >writes: > : Does anyone (anyone, that is, who's coded X11 applications) know how you > : handle X11 callbacks to C++ object methods? > > OI_add_event(3OI) :-) Uhhh? I've long since got the answer I wanted, but this seems a complete mystery, so I'll bite, what's a OI_add_event? From some package? Can't find a man page on it. > > Warner > Chuck Robey| Interests include C programming, Electronics, 213 Lakeside Dr. Apt. T-1 | communications, and signal processing. Greenbelt, MD 20770| I run picnic.mat.net: FreeBSD-current(i386) and (301) 220-2114 | jaunt.mat.net : FreeBSD-current(Alpha) To Unsubscribe: send mail to [EMAIL PROTECTED] with "unsubscribe freebsd-hackers" in the body of the message
Re: X11/C++ question
In message <[EMAIL PROTECTED]> Chuck Robey writes: : Does anyone (anyone, that is, who's coded X11 applications) know how you : handle X11 callbacks to C++ object methods? OI_add_event(3OI) :-) Warner To Unsubscribe: send mail to [EMAIL PROTECTED] with "unsubscribe freebsd-hackers" in the body of the message
Re: X11/C++ question
On Wed, 27 Oct 1999, Wes Peters wrote: > Chuck Robey wrote: > > > > On Tue, 26 Oct 1999 [EMAIL PROTECTED] wrote: > > > > > > > > Thomas David Rivers writes: > > > > If you mean Xt (and possibly Motif) - the answer is "very carefully." > > > [...] > > > > > > You're approach would probably work, but there's an easier way. > > > See topic 28 in the Xt FAQ. > > > > > > ftp://ftp.x.org/contrib/faqs/FAQ-Xt > > > > > > It's not name mangling causing problems, it's lack of "this" when the > > > method is invoked as a callback from Xt. > > > > Yes! This is the method! I like it, or at least, it's as close (in C++ > > code) to something I do like. > > I assume they're using a static member function for the callback and storing > the this pointer for the object somewhere handy? This is the canonical way > to re-enter C++ code from C land, and can even be used for C++ interrupt > handlers if you're very careful. Yes, you store the address of the object you want the callback vectored to in the UserData Xt pointer, and when the callback comes into the static func, it just takes the offered object address and reflects the call back out to the right function in the right object. Neat, the user never sees any complication at all. > > Chuck Robey| Interests include C programming, Electronics, 213 Lakeside Dr. Apt. T-1 | communications, and signal processing. Greenbelt, MD 20770| I run picnic.mat.net: FreeBSD-current(i386) and (301) 220-2114 | jaunt.mat.net : FreeBSD-current(Alpha) To Unsubscribe: send mail to [EMAIL PROTECTED] with "unsubscribe freebsd-hackers" in the body of the message
Re: X11/C++ question
Chuck Robey wrote: > > On Tue, 26 Oct 1999 [EMAIL PROTECTED] wrote: > > > > > Thomas David Rivers writes: > > > If you mean Xt (and possibly Motif) - the answer is "very carefully." > > [...] > > > > You're approach would probably work, but there's an easier way. > > See topic 28 in the Xt FAQ. > > > > ftp://ftp.x.org/contrib/faqs/FAQ-Xt > > > > It's not name mangling causing problems, it's lack of "this" when the > > method is invoked as a callback from Xt. > > Yes! This is the method! I like it, or at least, it's as close (in C++ > code) to something I do like. I assume they're using a static member function for the callback and storing the this pointer for the object somewhere handy? This is the canonical way to re-enter C++ code from C land, and can even be used for C++ interrupt handlers if you're very careful. -- "Where am I, and what am I doing in this handbasket?" Wes Peters Softweyr LLC [EMAIL PROTECTED] http://softweyr.com/ To Unsubscribe: send mail to [EMAIL PROTECTED] with "unsubscribe freebsd-hackers" in the body of the message
Re: X11/C++ question
[EMAIL PROTECTED] (Chuck Robey) writes: > Boy, I sure wish Java compiled and ran natively. I'd stop using C++ > forever. gcc-2.95.1 + libgcj already works, at least for simple programs. On FreeBSD 3.x programs seem to work as long as you use statically linked libraries (shared libraries cause the garbage collector to dump core). There already seems to be some awt code in libgcj, I have no idea whether it's actually functional. And the speed isn't quite comparable to what you can achieve lower-level languages (pretty close to the equivalent C++ code with all methods virtual, heavy use of rtti and common-base-class-based containers), but probably good enough for a lot of things. To Unsubscribe: send mail to [EMAIL PROTECTED] with "unsubscribe freebsd-hackers" in the body of the message
Re: X11/C++ question
hi, >> Does anyone (anyone, that is, who's coded X11 applications) know how you >> handle X11 callbacks to C++ object methods? >> >> Thanks, TDR> If you mean Xt (and possibly Motif) - the answer is "very carefully." TDR> The Xt callbacks are C based, so you typically can't directly call a TDR> C++ method. TDR> But, you can have an extern "C" block that declares the call back TDR> function (the extern "C" basically keeps any name mangling from going on) TDR> and then, in that function, invoke the method as appropriate. TDR> I believe you do something like: TDR> class myclass { TDR> void mymethod(void * arg1) { TDR> cout << "Ha! I got to the class" << '\n'; TDR> }; TDR> } TDR> extern "C" { TDR> void TDR> callback_function(arg1) TDR> void *arg1; TDR> { TDR> /* Call the method */ TDR> myclass::mymethod(arg1); TDR> } TDR> } Looks good except one point -- mymethod should be static, i.e. static void mymethod (...) { ... } TDR> Then, you register "callback_function" as the Xt/Motif callback. TDR> I've at least "heard" of doing that kind of thing before... -- /* Alexey Zelkin && [EMAIL PROTECTED]*/ /* Tavric National University && [EMAIL PROTECTED] */ /* http://www.ccssu.crimea.ua/~phantom && [EMAIL PROTECTED] */ To Unsubscribe: send mail to [EMAIL PROTECTED] with "unsubscribe freebsd-hackers" in the body of the message
Re: X11/C++ question
On Tue, 26 Oct 1999, Chris Costello wrote: > On Tue, Oct 26, 1999, Thomas David Rivers wrote: > > extern "C" { > > > > void > > callback_function(arg1) > > void *arg1; > > { > > /* Call the method */ > >myclass::mymethod(arg1); > >As far as I've seen, you can't directly call a class method > without an object. Sure you can. It won't have any access to "this" or any part thereof, however. > > -- > |Chris Costello <[EMAIL PROTECTED]> > |A closed mouth gathers no feet. > `-- > -- Brian Fundakowski Feldman \ FreeBSD: The Power to Serve! / [EMAIL PROTECTED]`--' To Unsubscribe: send mail to [EMAIL PROTECTED] with "unsubscribe freebsd-hackers" in the body of the message
Re: X11/C++ question
On Tue, 26 Oct 1999, Bakul Shah wrote: > Allow me add something to what the FAQ-Xt says. > > I find it more convenient to immediately call a non-static > function as shown below (using a slightly modified example > from the FAQ). Just got out of the shower, where I was wondering why they didn't suggest the same thing. I was going to experiment with this way, since it fit more closely with the way I like to code C++ (I don't like to code C++, you understand, so my C++ code is always straining to look like C). Thanks, Bakul. This looks much better. Thanks, folks, for letting me pull hackers away from FreeBSD for a minute, but let's not let it get out of hand; we better stop before we strain other's patience. Chuck Robey| Interests include C programming, Electronics, 213 Lakeside Dr. Apt. T-1 | communications, and signal processing. Greenbelt, MD 20770| I run picnic.mat.net: FreeBSD-current(i386) and (301) 220-2114 | jaunt.mat.net : FreeBSD-current(Alpha) To Unsubscribe: send mail to [EMAIL PROTECTED] with "unsubscribe freebsd-hackers" in the body of the message
Re: X11/C++ question
Allow me add something to what the FAQ-Xt says. I find it more convenient to immediately call a non-static function as shown below (using a slightly modified example from the FAQ). class Icon { public: Icon(Widget*); private: static void static_callback(Icon*); inline void real_callback(); Widget* button; int count; ... }; Icon::Icon(Widget* parent): count(0) { button = XtVaCreateWidget("Boo!", xmPushButtonWidgetClass, parent, 0); XtAddCallback(button, XmNselectCallback, &Icon::static_callback, (XtPointer)this); ... } inline void Icon::real_callback() { count++; ... } void Icon::static_callback(Icon* icon) { icon->real_callback(); } The reason for calling real_callback from static_callback is to avoid having to specify icon->count etc. to reference components of the Icon object. This makes a difference in readability if your callback function does a bunch of stuff. The reason for inlining to not incur the cost of an additional call (if this matters -- usually it doesn't). Inlining can get in your way during debugging (atleast gdb loses its mind) so provide a way to disable it. BTW, this idiom is useful pretty much any time you have to use C++ callbacks from C code, not just for X11. To Unsubscribe: send mail to [EMAIL PROTECTED] with "unsubscribe freebsd-hackers" in the body of the message
Re: X11/C++ question
On Tue, 26 Oct 1999 [EMAIL PROTECTED] wrote: > > Thomas David Rivers writes: > > If you mean Xt (and possibly Motif) - the answer is "very carefully." > [...] > > You're approach would probably work, but there's an easier way. > See topic 28 in the Xt FAQ. > > ftp://ftp.x.org/contrib/faqs/FAQ-Xt > > It's not name mangling causing problems, it's lack of "this" when the > method is invoked as a callback from Xt. Yes! This is the method! I like it, or at least, it's as close (in C++ code) to something I do like. Thanks very much, Ted. Nice catch. > > -Ted > Chuck Robey| Interests include C programming, Electronics, 213 Lakeside Dr. Apt. T-1 | communications, and signal processing. Greenbelt, MD 20770| I run picnic.mat.net: FreeBSD-current(i386) and (301) 220-2114 | jaunt.mat.net : FreeBSD-current(Alpha) To Unsubscribe: send mail to [EMAIL PROTECTED] with "unsubscribe freebsd-hackers" in the body of the message
Re: X11/C++ question
> Then you just stick a C wrapper function around every C++ callback you > want to register, is that it? Seems a bit inelegant, but I suppose, if > the ultimate test of elegance is that "it's the only one that works", then > it's perhaps elegant *enough*. I believe someone posted a better solution... from the Xt FAQ. - Dave R. - To Unsubscribe: send mail to [EMAIL PROTECTED] with "unsubscribe freebsd-hackers" in the body of the message
Re: X11/C++ question
On Wed, 27 Oct 1999, Daniel O'Connor wrote: > > On 27-Oct-99 Thomas David Rivers wrote: > > If you mean Xt (and possibly Motif) - the answer is "very carefully." > > Or you could just use a toolkit written for C++ or with C++ shims already.. ie > Qt or GTK.. If I wanted to just get X11 done, I would just call some toolkit. I didn't want to be told to go get something else that does it, I wanted to know the right way to do it myself. Thomas's post, at least, was really helpful. I wonder if that's really the way to go, but he surely did give me *one* method, and explained it easily enough so that I can *do* it. Boy, I sure wish Java compiled and ran natively. I'd stop using C++ forever. Chuck Robey| Interests include C programming, Electronics, 213 Lakeside Dr. Apt. T-1 | communications, and signal processing. Greenbelt, MD 20770| I run picnic.mat.net: FreeBSD-current(i386) and (301) 220-2114 | jaunt.mat.net : FreeBSD-current(Alpha) To Unsubscribe: send mail to [EMAIL PROTECTED] with "unsubscribe freebsd-hackers" in the body of the message
Re: X11/C++ question
On Tue, 26 Oct 1999, Thomas David Rivers wrote: > > > > Does anyone (anyone, that is, who's coded X11 applications) know how you > > handle X11 callbacks to C++ object methods? > > > > Thanks, > > If you mean Xt (and possibly Motif) - the answer is "very carefully." > > The Xt callbacks are C based, so you typically can't directly call a > C++ method. > > But, you can have an extern "C" block that declares the call back > function (the extern "C" basically keeps any name mangling from going on) > and then, in that function, invoke the method as appropriate. > > I believe you do something like: [example deleted] Then you just stick a C wrapper function around every C++ callback you want to register, is that it? Seems a bit inelegant, but I suppose, if the ultimate test of elegance is that "it's the only one that works", then it's perhaps elegant *enough*. Chuck Robey| Interests include C programming, Electronics, 213 Lakeside Dr. Apt. T-1 | communications, and signal processing. Greenbelt, MD 20770| I run picnic.mat.net: FreeBSD-current(i386) and (301) 220-2114 | jaunt.mat.net : FreeBSD-current(Alpha) To Unsubscribe: send mail to [EMAIL PROTECTED] with "unsubscribe freebsd-hackers" in the body of the message
Re: X11/C++ question
Thomas David Rivers writes: > If you mean Xt (and possibly Motif) - the answer is "very carefully." [...] You're approach would probably work, but there's an easier way. See topic 28 in the Xt FAQ. ftp://ftp.x.org/contrib/faqs/FAQ-Xt It's not name mangling causing problems, it's lack of "this" when the method is invoked as a callback from Xt. -Ted To Unsubscribe: send mail to [EMAIL PROTECTED] with "unsubscribe freebsd-hackers" in the body of the message
Re: X11/C++ question
On Tue, Oct 26, 1999, Thomas David Rivers wrote: > extern "C" { > > void > callback_function(arg1) > void *arg1; > { > /* Call the method */ > myclass::mymethod(arg1); As far as I've seen, you can't directly call a class method without an object. -- |Chris Costello <[EMAIL PROTECTED]> |A closed mouth gathers no feet. `-- To Unsubscribe: send mail to [EMAIL PROTECTED] with "unsubscribe freebsd-hackers" in the body of the message
Re: X11/C++ question
On 27-Oct-99 Thomas David Rivers wrote: > And, wasn't there a freely available C++ shim for motif floating around > at one time? I don't know.. My X experience begins and ends with Tk :) (Don't like Motif either ;) --- Daniel O'Connor software and network engineer for Genesis Software - http://www.gsoft.com.au "The nice thing about standards is that there are so many of them to choose from." -- Andrew Tanenbaum To Unsubscribe: send mail to [EMAIL PROTECTED] with "unsubscribe freebsd-hackers" in the body of the message
Re: X11/C++ question
> > On 27-Oct-99 Thomas David Rivers wrote: > > If you mean Xt (and possibly Motif) - the answer is "very carefully." > > Or you could just use a toolkit written for C++ or with C++ shims already.. ie > Qt or GTK.. > Good point! Also - I think there were some articles on how to do this in the X11 journals... if you happen to have those lying around. And, wasn't there a freely available C++ shim for motif floating around at one time? - Dave R. - To Unsubscribe: send mail to [EMAIL PROTECTED] with "unsubscribe freebsd-hackers" in the body of the message
Re: X11/C++ question
On 27-Oct-99 Thomas David Rivers wrote: > If you mean Xt (and possibly Motif) - the answer is "very carefully." Or you could just use a toolkit written for C++ or with C++ shims already.. ie Qt or GTK.. --- Daniel O'Connor software and network engineer for Genesis Software - http://www.gsoft.com.au "The nice thing about standards is that there are so many of them to choose from." -- Andrew Tanenbaum To Unsubscribe: send mail to [EMAIL PROTECTED] with "unsubscribe freebsd-hackers" in the body of the message
Re: X11/C++ question
> > Does anyone (anyone, that is, who's coded X11 applications) know how you > handle X11 callbacks to C++ object methods? > > Thanks, If you mean Xt (and possibly Motif) - the answer is "very carefully." The Xt callbacks are C based, so you typically can't directly call a C++ method. But, you can have an extern "C" block that declares the call back function (the extern "C" basically keeps any name mangling from going on) and then, in that function, invoke the method as appropriate. I believe you do something like: class myclass { void mymethod(void * arg1) { cout << "Ha! I got to the class" << '\n'; }; } extern "C" { void callback_function(arg1) void *arg1; { /* Call the method */ myclass::mymethod(arg1); } } Then, you register "callback_function" as the Xt/Motif callback. I've at least "heard" of doing that kind of thing before... - Dave Rivers - To Unsubscribe: send mail to [EMAIL PROTECTED] with "unsubscribe freebsd-hackers" in the body of the message