eliasdaler

Untitled

Nov 29th, 2015
357
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.77 KB | None | 0 0
  1. template <hash_type Hash>
  2. constexpr bool checkRegistered()
  3. {
  4.     return false;
  5. }
  6.  
  7. #define REGISTER_EVENT_TYPE(type)            \
  8. template <>                                  \
  9. constexpr bool checkRegistered<type##_sid>() \
  10. {                                            \
  11.     return true;                             \
  12. }                                            \
  13.  
  14. REGISTER_EVENT_TYPE("LevelChangedEvent")
  15.  
  16. template <hash_type EventType>
  17. void queueEvent()
  18. {
  19.     static_assert(checkRegistered<EventType>(), "Can't queue unregistered type");
  20.     ...
  21. }
  22.  
  23. template <hash_type EventType>
  24. void triggerEvent()
  25. {
  26.     static_assert(checkRegistered<EventType>(), "Can't trigger unregistered type");
  27.     ...
  28. }
  29.  
  30. // call function like this:
  31. queueEvent<"HpChangedEvent"_sid>();
Advertisement
Add Comment
Please, Sign In to add comment