]> git.netwichtig.de Git - user/henk/code/inspircd.git/commitdiff
Strong typing for stacked module results
authordanieldg <danieldg@e03df62e-2008-0410-955e-edbf42e46eb7>
Wed, 2 Sep 2009 00:45:22 +0000 (00:45 +0000)
committerdanieldg <danieldg@e03df62e-2008-0410-955e-edbf42e46eb7>
Wed, 2 Sep 2009 00:45:22 +0000 (00:45 +0000)
git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@11605 e03df62e-2008-0410-955e-edbf42e46eb7

include/modules.h

index 4f21a6000d45b8549e6168a244ff28cc4015d419..84895177be6f2eea19bcc7533c86ca5339d95c21 100644 (file)
@@ -76,6 +76,31 @@ enum MessageType {
        MSG_NOTICE = 1
 };
 
+/** Used to represent an allow/deny module result.
+ * Not constructed as an enum because it reverses the value logic of some functions;
+ * the compiler will inline accesses to have the same efficiency as integer operations.
+ */
+struct ModResult {
+       int res;
+       explicit ModResult(int r) : res(r) {}
+       bool operator==(const ModResult& r) const
+       {
+               return res == r.res;
+       }
+       bool operator!=(const ModResult& r) const
+       {
+               return res != r.res;
+       }
+       bool operator!() const
+       {
+               return !res;
+       }
+};
+
+#define MOD_RES_ALLOW (ModResult(1))
+#define MOD_RES_PASSTHRU (ModResult(0))
+#define MOD_RES_DENY (ModResult(-1))
+
 /** If you change the module API, change this value. */
 #define API_VERSION 13000
 
@@ -240,6 +265,16 @@ do { \
        } \
 } while(0)
 
+#define FIRST_MOD_RESULT(z,n,v,args) do { \
+       v = MOD_RES_PASSTHRU; \
+       DO_EACH_HOOK(z,n,v,args) \
+       { \
+               if (v != MOD_RES_PASSTHRU) \
+                       break; \
+       } \
+       WHILE_EACH_HOOK(z,n); \
+} while (0)
+
 /** Represents a non-local user.
  * (in fact, any FD less than -1 does)
  */