From 0556720b559d7ec5d8badacf0ac9b11e9c864847 Mon Sep 17 00:00:00 2001 From: Attila Molnar Date: Sat, 15 Feb 2014 14:38:24 +0100 Subject: Add ParamModeBase and ParamMode, change all parameter modes to inherit from ParamMode - Type of the extension used to store data is a template parameter - The extension is automatically unset when the mode is unset - Handlers inheriting from ParamMode have to provide OnSet() and SerializeParam(); may optionally provide OnUnset() - Transparently handle the case when OnSet() modifies the mode parameter - Remove Channel::custom_mode_params map; ask the mode handlers to serialize their parameters instead --- src/channels.cpp | 35 ++++++----------------------------- 1 file changed, 6 insertions(+), 29 deletions(-) (limited to 'src/channels.cpp') diff --git a/src/channels.cpp b/src/channels.cpp index a8f8db43c..448764e1c 100644 --- a/src/channels.cpp +++ b/src/channels.cpp @@ -51,29 +51,6 @@ void Channel::SetMode(ModeHandler* mh, bool on) modes[mh->GetModeChar() - 65] = on; } -void Channel::SetModeParam(ModeHandler* mh, const std::string& parameter) -{ - char mode = mh->GetModeChar(); - if (parameter.empty()) - { - custom_mode_params.erase(mode); - modes[mode-65] = false; - } - else - { - custom_mode_params[mode] = parameter; - modes[mode-65] = true; - } -} - -std::string Channel::GetModeParameter(ModeHandler* mode) -{ - CustomModeList::iterator n = custom_mode_params.find(mode->GetModeChar()); - if (n != custom_mode_params.end()) - return n->second; - return ""; -} - void Channel::SetTopic(User* u, const std::string& ntopic) { this->topic.assign(ntopic, 0, ServerInstance->Config->Limits.MaxTopic); @@ -628,18 +605,18 @@ const char* Channel::ChanModes(bool showkey) if (!mh) continue; + ParamModeBase* pm = mh->IsParameterMode(); + if (!pm) + continue; + if (n == 'k' - 65 && !showkey) { sparam += " "; } else { - const std::string param = this->GetModeParameter(mh); - if (!param.empty()) - { - sparam += ' '; - sparam += param; - } + sparam += ' '; + pm->GetParameter(this, sparam); } } } -- cgit v1.3.1-10-gc9f91