Browse Source

new experemental C++11 feature
eventID('A','b','c','d')
now could be replaced with
EventID("Abcd")

dmuratshin 9 years ago
parent
commit
4f90a16a32
1 changed files with 8 additions and 0 deletions
  1. 8 0
      oxygine/src/EventDispatcher.h

+ 8 - 0
oxygine/src/EventDispatcher.h

@@ -6,17 +6,25 @@
 
 namespace oxygine
 {
+
     typedef int eventType;
     class Event;
 
 #define makefourcc(a,b,c,d) ( ((unsigned int)a) | (((unsigned int)b)<< 8) | (((unsigned int)c)<<16) | (((unsigned int)d)<<24))
 
+#if __cplusplus > 199711L
+    inline int error_eventID_should_be_size_of_4_chars(int x) { return x; }
+    constexpr size_t constStringLength(const char* str) { return (*str == 0) ? 0 : constStringLength(str + 1) + 1; }
+    constexpr int EventIDc11(const char *str) { return constStringLength(str) == 4 ? makefourcc(str[0], str[1], str[2], str[3]) : error_eventID_should_be_size_of_4_chars(0); }
+#endif
+
     //eventID('_', '_', '_', '_')
 #define eventID(a,b,c,d) makefourcc(a,b,c,d)
 
     /*sysEventID is used for system Oxygine events, use 'eventID' for custom game events*/
 #define sysEventID(b,c,d) makefourcc(0xA,b,c,d)
 
+#define  EventID(str) EventIDc11(str)
 
     typedef Closure<void (Event* ev)> EventCallback;