Max Frai
Max Frai

Reputation: 64276

Defining classes

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?

Upvotes: 0

Views: 114

Answers (1)

InsertNickHere
InsertNickHere

Reputation: 3666

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);

Upvotes: 1

Related Questions