summaryrefslogtreecommitdiff
path: root/include/modules.h
diff options
context:
space:
mode:
authordanieldg <danieldg@e03df62e-2008-0410-955e-edbf42e46eb7>2009-09-02 00:45:22 +0000
committerdanieldg <danieldg@e03df62e-2008-0410-955e-edbf42e46eb7>2009-09-02 00:45:22 +0000
commit8c149db4615d0206c1c40f6e377cb43271ab690e (patch)
tree33df85dedd524359a1c82f73ccdd0bc73a30e574 /include/modules.h
parentcfa482e1868fe466d8bea4b7696b36fe01618f85 (diff)
Strong typing for stacked module results
git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@11605 e03df62e-2008-0410-955e-edbf42e46eb7
Diffstat (limited to 'include/modules.h')
-rw-r--r--include/modules.h35
1 files changed, 35 insertions, 0 deletions
diff --git a/include/modules.h b/include/modules.h
index 4f21a6000..84895177b 100644
--- a/include/modules.h
+++ b/include/modules.h
@@ -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)
*/