Преглед изворни кода

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

dmuratshin пре 9 година
родитељ
комит
4f90a16a32
1 измењених фајлова са 8 додато и 0 уклоњено
  1. 8 0
      oxygine/src/EventDispatcher.h

+ 8 - 0
oxygine/src/EventDispatcher.h

@@ -6,17 +6,25 @@
 
 
 namespace oxygine
 namespace oxygine
 {
 {
+
     typedef int eventType;
     typedef int eventType;
     class Event;
     class Event;
 
 
 #define makefourcc(a,b,c,d) ( ((unsigned int)a) | (((unsigned int)b)<< 8) | (((unsigned int)c)<<16) | (((unsigned int)d)<<24))
 #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('_', '_', '_', '_')
     //eventID('_', '_', '_', '_')
 #define eventID(a,b,c,d) makefourcc(a,b,c,d)
 #define eventID(a,b,c,d) makefourcc(a,b,c,d)
 
 
     /*sysEventID is used for system Oxygine events, use 'eventID' for custom game events*/
     /*sysEventID is used for system Oxygine events, use 'eventID' for custom game events*/
 #define sysEventID(b,c,d) makefourcc(0xA,b,c,d)
 #define sysEventID(b,c,d) makefourcc(0xA,b,c,d)
 
 
+#define  EventID(str) EventIDc11(str)
 
 
     typedef Closure<void (Event* ev)> EventCallback;
     typedef Closure<void (Event* ev)> EventCallback;