Boost logo

Boost Users :

Subject: Re: [Boost-users] Auto dispatch metaprogramming tricks
From: John Dlugosz (JDlugosz_at_[hidden])
Date: 2010-05-21 17:50:20


> template<> class message<WM_CREATE> { ... }
> template<> class message<WM_SETTEXT> { ... }
>
> So there is in fact a list of 'PossibleMessages' available to the
> compiler.
> It is every argument to a specialisation of class message<Id>. Is
> there a
> way I can harvest these to build the PossibleMessages list?

Derive message<T> from a "tag" base class. Then you don't build a list, but you have a predicate to test "is this type in my set?" by using is_base_of, that's perfectly useful for enable_if.

On the other hand, you could use a signature that matches the use of the template:

        template<typename Msg>
        LRESULT on (message<T> m);

will only match this templatized member function if it is indeed a specialization of message.

BTW, I take a different approach to the problem in general. Rather than a zillion individual handlers, I use small "pods" of related messages. For example, handling the mouse messages is a class that handles just a few mouse-related messages, and if you deal with one you probably deal with all. The pods are kept in a linked list, which is searched for suitable handlers. This allows run-time "modes" by updating that list or enabling specific entries that lie dormant.
By having different specially declared functions for each Windows message (yet, not a million virtual functions in one class!) each can have a proper signature that wraps its real use, rather than dealing with the raw format.

See also <http://www.dlugosz.com/Repertoire/refman/Tomahawk/message_crack.html>, which might give you some ideas that fit with your current scheme.

--John



TradeStation Group, Inc. is a publicly-traded holding company (NASDAQ GS: TRAD) of three operating subsidiaries, TradeStation Securities, Inc. (Member NYSE, FINRA, SIPC and NFA), TradeStation Technologies, Inc., a trading software and subscription company, and TradeStation Europe Limited, a United Kingdom, FSA-authorized introducing brokerage firm. None of these companies provides trading or investment advice, recommendations or endorsements of any kind. The information transmitted is intended only for the person or entity to which it is addressed and may contain confidential and/or privileged material. Any review, retransmission, dissemination or other use of, or taking of any action in reliance upon, this information by persons or entities other than the intended recipient is prohibited. If you received this in error, please contact the sender and delete the material from any computer.


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net