__event?

P

PGP

Anybody here using __event? Could you please discuss any potential issues
with it other than portability?

Priyesh
 
B

Ben Voigt [C++ MVP]

PGP said:
Anybody here using __event? Could you please discuss any potential issues
with it other than portability?

Nope. People using C++ in the managed world are now using C++/CLI (new in
VC++ 2005) which no longer supports the __event keyword, instead using
"context-sensitive" keywords that are only recognized at certain locations.
 
P

PGP

Ben Voigt said:
Nope. People using C++ in the managed world are now using C++/CLI (new in
VC++ 2005) which no longer supports the __event keyword, instead using
"context-sensitive" keywords that are only recognized at certain
locations.
I was wondering about the native C++ part of it. Would you rather look into
a third party library or would you consider using the __event, __hook
and __unhook? Overall, I did not find any good feedback on the __event
mechanism during my research, but I would defenitely want to use it
if it's here to stay. I have done some tests of my own and tried out
MSDN samples. It does exactly what I want it to do. Now I am
looking for some reassurance.

Priyesh
 
B

Ben Voigt [C++ MVP]

PGP said:
I was wondering about the native C++ part of it. Would you rather look
into

You were in the C++/CLI newsgroup... microsoft.public.vc.language is focused
on native features.
a third party library or would you consider using the __event, __hook
and __unhook? Overall, I did not find any good feedback on the __event
mechanism during my research, but I would defenitely want to use it
if it's here to stay. I have done some tests of my own and tried out
MSDN samples. It does exactly what I want it to do. Now I am
looking for some reassurance.

Are you looking for COM compatibility? If you just want event handling in
within a C++ application, then pointer-to-member-function is 100% in the C++
standard and does what you want. In the rare case you need to support
multiple subscribers, then a std::vector or std::list of
pointer-to-member-function will get you there, again 100% standard and
portable. A template helper function can hide the details of iterating
through and calling all receivers. That will get even better in C++0x with
template support for arbitrary argument lists (not sure what the correct
name of the feature is).
 
B

Boris

[...]Are you looking for COM compatibility? If you just want event
handling in within a C++ application, then pointer-to-member-function is
100% in the C++ standard and does what you want. In the rare case you
need to support multiple subscribers, then a std::vector or std::list of
pointer-to-member-function will get you there, again 100% standard and
portable.

Or have a look at Boost.Signals (see
http://www.boost.org/doc/html/signals.html) which is
C++ standard-compatible library which should do what you want out of the
box.

Boris
 
P

PGP

Ben Voigt said:
You were in the C++/CLI newsgroup... microsoft.public.vc.language is
focused on native features.


Are you looking for COM compatibility? If you just want event handling in
within a C++ application, then pointer-to-member-function is 100% in the
C++ standard and does what you want. In the rare case you need to support
multiple subscribers, then a std::vector or std::list of
pointer-to-member-function will get you there, again 100% standard and
portable. A template helper function can hide the details of iterating
through and calling all receivers. That will get even better in C++0x
with template support for arbitrary argument lists (not sure what the
correct name of the feature is).
Ben,
COM is not in the picture. I am also not worried about porting this code
outside MS compilers. Calling multiple subscribers is a needed feature.
__hook supports calling multiple subscribers and it's thread safe. Apart
from potential portability issues, it seems to me that __hook is a perfect
fit.
If i roll my own as you suggest, i am still left with the task of
synchronizing
access from multiple threads.
Priyesh
 
P

PGP

Boris said:
[...]Are you looking for COM compatibility? If you just want event
handling in within a C++ application, then pointer-to-member-function is
100% in the C++ standard and does what you want. In the rare case you
need to support multiple subscribers, then a std::vector or std::list of
pointer-to-member-function will get you there, again 100% standard and
portable.

Or have a look at Boost.Signals (see
http://www.boost.org/doc/html/signals.html) which is C++
standard-compatible library which should do what you want out of the box.

Boris

Boris,

Thanks for the suggestion. Boost looks excellent. I have contemplated on
using
Boost multiple times before and havent yet. Although starting to use Boost
now
will be a good idea as there are other excellent features like regex that i
could
take advantage of, it is too much of a change to introduce at this point to
otherwise
stable code so i am a little worried.
Priyesh
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top