Untitled

Published July 13, 2006
Advertisement
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:

someHandlerList.addListener( &myHappyListener );

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 -

someHandlerList.addListener( (QuitListener*)&myHappyListener );

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 -

myHandlerList.addListener(&myListener);

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?
Previous Entry Untitled
Next Entry Untitled
0 likes 0 comments

Comments

Nobody has left a comment. You can be the first!
You must log in to join the conversation.
Don't have a GameDev.net account? Sign up!
Profile
Author
Advertisement

Latest Entries

Untitled

5561 views

Untitled

1075 views

Untitled

1220 views

Untitled

1132 views

Untitled

1178 views

Untitled

1463 views

Untitled

1131 views

Untitled

1032 views

Untitled

1036 views

Untitled

1216 views
Advertisement