From 9941a616cbba8ad5dec07bdf908a1d08d81e568e Mon Sep 17 00:00:00 2001 From: brain Date: Mon, 10 Jul 2006 16:51:19 +0000 Subject: If you ask me, it looks a hell of a lot tidier without forcing the cast. git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@4277 e03df62e-2008-0410-955e-edbf42e46eb7 --- include/base.h | 15 ++++++++++++++- include/u_listmode.h | 15 ++++++++++----- 2 files changed, 24 insertions(+), 6 deletions(-) (limited to 'include') diff --git a/include/base.h b/include/base.h index d3cc77e05..ac5fec63f 100644 --- a/include/base.h +++ b/include/base.h @@ -94,7 +94,20 @@ public: * * @return If you provide a non-existent key name, the function returns NULL, otherwise a pointer to the item referenced by the key is returned. */ - char* GetExt(const std::string &key); + template bool GetExt(const std::string &key, T* &p) + { + ExtensibleStore::iterator iter = this->Extension_Items.find(key); + if(iter != this->Extension_Items.end()) + { + p = (T*)iter->second; + return true; + } + else + { + return false; + } + } + //char* GetExt(const std::string &key); /** Get a list of all extension items names. * diff --git a/include/u_listmode.h b/include/u_listmode.h index 1618754a3..9c34cc982 100644 --- a/include/u_listmode.h +++ b/include/u_listmode.h @@ -66,7 +66,8 @@ class ListModeBase : public ModeHandler virtual void DisplayList(userrec* user, chanrec* channel) { - modelist* el = (modelist*)channel->GetExt(infokey); + modelist* el; + channel->GetExt(infokey, el); if (el) { for(modelist::iterator it = el->begin(); it != el->end(); it++) @@ -117,7 +118,8 @@ class ListModeBase : public ModeHandler virtual ModeAction OnModeChange(userrec* source, userrec* dest, chanrec* channel, std::string ¶meter, bool adding) { // Try and grab the list - modelist* el = (modelist*)channel->GetExt(infokey); + modelist* el; + channel->GetExt(infokey, el); if (adding) { @@ -238,7 +240,8 @@ class ListModeBase : public ModeHandler virtual void DoChannelDelete(chanrec* chan) { - modelist* list = (modelist*)chan->GetExt(infokey); + modelist* list; + chan->GetExt(infokey, list); if (list) { @@ -249,7 +252,8 @@ class ListModeBase : public ModeHandler virtual void DoSyncChannel(chanrec* chan, Module* proto, void* opaque) { - modelist* list = (modelist*)chan->GetExt(infokey); + modelist* list; + chan->GetExt(infokey, list); if (list) { for (modelist::iterator it = list->begin(); it != list->end(); it++) @@ -265,7 +269,8 @@ class ListModeBase : public ModeHandler { chanrec* chan = (chanrec*)item; - modelist* list = (modelist*)chan->GetExt(infokey); + modelist* list; + chan->GetExt(infokey, list); if (list) { -- cgit v1.2.3