• entries
570
2427
• views
216934

# Untitled

90 views

LOL, sour syntax -

Assuming you have a listener class which is currently listening for multiple events (which wouldn't be uncommon in my code), it might look something like this -
stuct MyHappyListener :     pain::core::QuitListener,     pain::core::KeyDownListener{     void onEvent( pain::core::QuitEvent ) {          ...     }     void onEvent( pain::core::KeyDownEvent ) {          ...     }};

Now, you should already be shaking your head, to a degree, if you've been following along with my rants. Why? Because as soon as we attempt to attach this to one of our handler lists (which supports multiple lists), we immediately run into a problem:

Now, we've got an ambiguous call there, because &myHappyListener can be implicitly downcast to either a QuitListener* or a KeyDownListener*.

The quick cut-and-dry solution for this (at the moment) is to explicitly state which implicit conversion we want to use -

How's that for ugly syntax?

Now I remember thinking about these problems a long time ago, and I think the solution I had in mind was to add a layer of, yes, INDIRECTION between the handler template instances which are inherited by a class implementing more than one of them which would, in essence, look something like this:

template < UNGODLY STUFF >class Middleman :   handler lists to inherit from{   tempate < class EventType >   void addListener( Listener< EventType >* rah ) {      _addListener( rah ); // the old function, adds a listener.   }};

This (I think) would allow us to change the syntax to something, IMO, a little more pleasing -

At least it got rid of the cast.

Now, I remember Loki implemented something along the lines of this, so I'm going to dig that book back up and read through that part again. Possibly. I'm honestly not very decided on the issue at all, since there are very few handlers, and it would almost be easier to just hardcode it instead of relying on dirty template metaprogramming.

In any case, I seem to have a bloody stump where my leg should be. Doctor in the house?

There are no comments to display.

## Create an account

Register a new account