0

I have some big code line which I want to pack into define for fast using.

EventManager::get_mutable_instance().get<EventManager::KeyEvent>("KeyPressed").Call(EventManager::KeyEvent::ArgsType(localEvent.Key)); 

Here is EventManager is singleton class. I'd prefer to pass into define only EventManager::KeyEvent type and signal name "KeyPressed". Could you help me with this?

1 Answer 1

1

Due to the fact I don't like defines I would make a "wrapper" function like this:

public void call(EventType type, String whatToCall) { EventManager::get_mutable_instance().get<type>(whatToCall).Call(EventManager::KeyEvent::ArgsType(localEvent.Key)); } 

Edit: An untested define could look like:

#define call(Type,Name) \ EventManager::get_mutable_instance().get<Type>(Name).Call(EventManager::KeyEvent::ArgsType(localEvent.Key)); 

Edit2: Im not really used to your code, but what would it more readable and debugable would be sth like this. (Be aware, the class names are not yours but I hope you can see what I mean)

Event event = EventManager::get_mutable_instance().get<type>(whatToCall); ArgType argType = EventManager::KeyEvent::ArgsType(localEvent.Key); event.call(argType); 
Sign up to request clarification or add additional context in comments.

1 Comment

yes always prefer using inline functions over defines (the code will be inlined if it is more performant or you force inlining). #define will always replicate the code what is not a good idea and you most of the time loose type checking and have trouble with repeated arguments with side effects what might create subtle errors...

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.