From 529f16e84b4ba1328a13be32e40a71156c4725f8 Mon Sep 17 00:00:00 2001 From: brain Date: Wed, 25 Jul 2007 17:36:13 +0000 Subject: Shorthand macros DEFINE_HANDLER1()...DEFINE_HANDLER9() to save on defining functor classes that just implement Call() git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@7569 e03df62e-2008-0410-955e-edbf42e46eb7 --- include/caller.h | 9 +++++++++ include/inspircd.h | 25 +++++-------------------- src/inspircd.cpp | 4 +++- src/modules.cpp | 4 ++-- 4 files changed, 19 insertions(+), 23 deletions(-) diff --git a/include/caller.h b/include/caller.h index 9f251d16c..396a5ba5a 100644 --- a/include/caller.h +++ b/include/caller.h @@ -237,5 +237,14 @@ template { InspIRCd* Server; public: NAME(InspIRCd* Srv) : Server(Srv) { } virtual ~NAME() { } virtual RETURN Call(); }; + +#define DEFINE_HANDLER1(NAME, RETURN, V1) \ + class CoreExport NAME : public HandlerBase1 { InspIRCd* Server; public: NAME(InspIRCd* Srv) : Server(Srv) { } virtual ~NAME() { } virtual RETURN Call(V1); }; + +#define DEFINE_HANDLER2(NAME, RETURN, V1, V2) \ + class CoreExport NAME : public HandlerBase2 { InspIRCd* Server; public: NAME(InspIRCd* Srv) : Server(Srv) { } virtual ~NAME() { } virtual RETURN Call(V2); }; + #endif diff --git a/include/inspircd.h b/include/inspircd.h index c2ea3f048..13b66ade7 100644 --- a/include/inspircd.h +++ b/include/inspircd.h @@ -239,24 +239,9 @@ typedef std::map clonemap; class InspIRCd; -class CoreExport IsNickHandler : public HandlerBase1 -{ - InspIRCd* Server; - public: - IsNickHandler(InspIRCd* Srv) : Server(Srv) { } - virtual ~IsNickHandler() { } - virtual bool Call(const char*); -}; - -class CoreExport IsIdentHandler : public HandlerBase1 -{ - InspIRCd* Server; - public: - IsIdentHandler(InspIRCd* Srv) : Server(Srv) { } - virtual ~IsIdentHandler() { } - virtual bool Call(const char*); -}; - +DEFINE_HANDLER1(IsNickHandler, bool, const char*); +DEFINE_HANDLER1(IsIdentHandler, bool, const char*); +DEFINE_HANDLER1(FindDescriptorHandler, userrec*, int); /* Forward declaration - required */ class XLineManager; @@ -399,8 +384,8 @@ class CoreExport InspIRCd : public classbase /**** Functors ****/ IsNickHandler HandleIsNick; - IsIdentHandler HandleIsIdent; + FindDescriptorHandler HandleFindDescriptor; /** InspSocket classes pending deletion after being closed. * We don't delete these immediately as this may cause a segmentation fault. @@ -886,7 +871,7 @@ class CoreExport InspIRCd : public classbase * @param socket The file descriptor of a user * @return A pointer to the user if the user exists locally on this descriptor */ - userrec* FindDescriptor(int socket); + caller1 FindDescriptor; /** Add a new mode to this server's mode parser * @param mh The modehandler to add diff --git a/src/inspircd.cpp b/src/inspircd.cpp index dea2f0a58..449bb005b 100644 --- a/src/inspircd.cpp +++ b/src/inspircd.cpp @@ -396,8 +396,10 @@ InspIRCd::InspIRCd(int argc, char** argv) GlobalCulls(this), HandleIsNick(this), HandleIsIdent(this), + HandleFindDescriptor(this), IsNick(&HandleIsNick), - IsIdent(&HandleIsIdent) + IsIdent(&HandleIsIdent), + FindDescriptor(&HandleFindDescriptor) { int found_ports = 0; FailedPortList pl; diff --git a/src/modules.cpp b/src/modules.cpp index 720de3b96..28d746323 100644 --- a/src/modules.cpp +++ b/src/modules.cpp @@ -755,9 +755,9 @@ void InspIRCd::DumpText(userrec* User, const std::string &LinePrefix, stringstre User->WriteServ(CompleteLine); } -userrec* InspIRCd::FindDescriptor(int socket) +userrec* FindDescriptorHandler::Call(int socket) { - return reinterpret_cast(this->SE->GetRef(socket)); + return reinterpret_cast(Server->SE->GetRef(socket)); } bool InspIRCd::AddMode(ModeHandler* mh, const unsigned char mode) -- cgit v1.2.3