From: danieldg Date: Wed, 2 Sep 2009 00:45:22 +0000 (+0000) Subject: Strong typing for stacked module results X-Git-Tag: v2.0.23~1637 X-Git-Url: https://git.netwichtig.de/gitweb/?a=commitdiff_plain;h=8c149db4615d0206c1c40f6e377cb43271ab690e;p=user%2Fhenk%2Fcode%2Finspircd.git Strong typing for stacked module results git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@11605 e03df62e-2008-0410-955e-edbf42e46eb7 --- 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) */