summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordanieldg <danieldg@e03df62e-2008-0410-955e-edbf42e46eb7>2009-09-02 00:44:24 +0000
committerdanieldg <danieldg@e03df62e-2008-0410-955e-edbf42e46eb7>2009-09-02 00:44:24 +0000
commite27f3380733a4412007a3f023069615d1218ab96 (patch)
treeb5d9f56ff1a40c430e8fe87b50596b414ec44af4
parent5abd3b1cc5fba26486d71c6a415fae797388ddf3 (diff)
Replace FOREACH_RESULT_MAP with a more readable and flexible do_each_hook/while_each_hook macro pair
git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@11598 e03df62e-2008-0410-955e-edbf42e46eb7
-rw-r--r--include/modules.h29
-rw-r--r--src/channels.cpp24
2 files changed, 33 insertions, 20 deletions
diff --git a/include/modules.h b/include/modules.h
index 47f495373..9a23a4fc8 100644
--- a/include/modules.h
+++ b/include/modules.h
@@ -213,25 +213,32 @@ do { \
} \
} while (0);
-#define FOREACH_RESULT_MAP(y,x,f) \
+/**
+ * Custom module result handling loop. This is a paired macro, and should only
+ * be used with while_each_hook.
+ *
+ * See src/channels.cpp for an example of use.
+ */
+#define DO_EACH_HOOK(z,n,v,args) \
do { \
- EventHandlerIter safei; \
- for (EventHandlerIter _i = ServerInstance->Modules->EventHandlers[y].begin(); _i != ServerInstance->Modules->EventHandlers[y].end(); ) \
+ EventHandlerIter iter_ ## n = z->Modules->EventHandlers[I_ ## n].begin(); \
+ while (iter_ ## n != z->Modules->EventHandlers[I_ ## n].end()) \
{ \
- safei = _i; \
- ++safei; \
+ Module* mod_ ## n = *iter_ ## n; \
+ iter_ ## n ++; \
try \
{ \
- int MOD_RESULT = (*_i)->x ; \
- f; \
+ v = (mod_ ## n)->n args;
+
+#define WHILE_EACH_HOOK(z,n) \
} \
- catch (CoreException& modexcept) \
+ catch (CoreException& except_ ## n) \
{ \
- ServerInstance->Logs->Log("MODULE",DEFAULT,"Exception caught: %s",modexcept.GetReason()); \
+ z->Logs->Log("MODULE",DEFAULT,"Exception caught: %s", (except_ ## n).GetReason()); \
+ (void) mod_ ## n; /* catch mismatched pairs */ \
} \
- _i = safei; \
} \
-} while(0);
+} while(0)
/** Represents a non-local user.
* (in fact, any FD less than -1 does)
diff --git a/src/channels.cpp b/src/channels.cpp
index 6e0f4c686..532953db3 100644
--- a/src/channels.cpp
+++ b/src/channels.cpp
@@ -475,9 +475,11 @@ Channel* Channel::ForceChan(InspIRCd* Instance, Channel* Ptr, User* user, const
bool Channel::IsBanned(User* user)
{
int result = 0;
- FOREACH_RESULT_MAP(I_OnCheckBan, OnCheckBan(user, this),
- result = banmatch_reduce(result, MOD_RESULT);
- );
+ DO_EACH_HOOK(ServerInstance, OnCheckBan, int modresult, (user, this))
+ {
+ result = banmatch_reduce(result, modresult);
+ }
+ WHILE_EACH_HOOK(ServerInstance, OnCheckBan);
if (result)
return (result < 0);
@@ -499,9 +501,11 @@ bool Channel::IsBanned(User* user)
int Channel::GetExtBanStatus(const std::string &str, char type)
{
int result = 0;
- FOREACH_RESULT_MAP(I_OnCheckStringExtBan, OnCheckStringExtBan(str, this, type),
- result = banmatch_reduce(result, MOD_RESULT);
- );
+ DO_EACH_HOOK(ServerInstance, OnCheckStringExtBan, int modresult, (str, this, type))
+ {
+ result = banmatch_reduce(result, modresult);
+ }
+ WHILE_EACH_HOOK(ServerInstance, OnCheckStringExtBan);
if (result)
return result;
@@ -525,9 +529,11 @@ int Channel::GetExtBanStatus(const std::string &str, char type)
int Channel::GetExtBanStatus(User *user, char type)
{
int result = 0;
- FOREACH_RESULT_MAP(I_OnCheckExtBan, OnCheckExtBan(user, this, type),
- result = banmatch_reduce(result, MOD_RESULT);
- );
+ DO_EACH_HOOK(ServerInstance, OnCheckExtBan, int modresult, (user, this, type))
+ {
+ result = banmatch_reduce(result, modresult);
+ }
+ WHILE_EACH_HOOK(ServerInstance, OnCheckExtBan);
if (result)
return result;