diff options
author | Attila Molnar <attilamolnar@hush.com> | 2014-02-15 14:38:24 +0100 |
---|---|---|
committer | Attila Molnar <attilamolnar@hush.com> | 2014-02-15 14:38:24 +0100 |
commit | 0556720b559d7ec5d8badacf0ac9b11e9c864847 (patch) | |
tree | 0435a0e5b8e722fe35afb3f820f804bec8c0c7b2 /include/channels.h | |
parent | 88baaf9e68efd9824b906a69320053734d408e14 (diff) |
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
Diffstat (limited to 'include/channels.h')
-rw-r--r-- | include/channels.h | 31 |
1 files changed, 19 insertions, 12 deletions
diff --git a/include/channels.h b/include/channels.h index 9b018b23e..ba2018e97 100644 --- a/include/channels.h +++ b/include/channels.h @@ -24,6 +24,7 @@ #include "membership.h" #include "mode.h" +#include "parammode.h" /** Holds an entry for a ban list, exemption list, or invite list. * This class contains a single element in a channel list, such as a banlist. @@ -47,11 +48,6 @@ class CoreExport Channel : public Extensible, public InviteBase<Channel> */ std::bitset<64> modes; - /** Parameters for custom modes. - * One for each custom mode letter. - */ - CustomModeList custom_mode_params; - /** Remove the given membership from the channel's internal map of * memberships and destroy the Membership object. * This function does not remove the channel from User::chanlist. @@ -113,13 +109,6 @@ class CoreExport Channel : public Extensible, public InviteBase<Channel> */ void SetMode(ModeHandler* mode, bool value); - /** Sets or unsets a custom mode in the channels info - * @param mode The mode character to set or unset - * @param parameter The parameter string to associate with this mode character. - * If it is empty, the mode is unset; if it is nonempty, the mode is set. - */ - void SetModeParam(ModeHandler* mode, const std::string& parameter); - /** Returns true if a mode is set on a channel * @param mode The mode character you wish to query * @return True if the custom mode is set, false if otherwise @@ -140,6 +129,7 @@ class CoreExport Channel : public Extensible, public InviteBase<Channel> */ std::string GetModeParameter(ModeHandler* mode); std::string GetModeParameter(ChanModeReference& mode); + std::string GetModeParameter(ParamModeBase* pm); /** Sets the channel topic. * @param user The user setting the topic. @@ -344,6 +334,23 @@ inline std::string Channel::GetModeParameter(ChanModeReference& mode) return GetModeParameter(*mode); } +inline std::string Channel::GetModeParameter(ModeHandler* mh) +{ + std::string out; + ParamModeBase* pm = mh->IsParameterMode(); + if (pm && this->IsModeSet(pm)) + pm->GetParameter(this, out); + return out; +} + +inline std::string Channel::GetModeParameter(ParamModeBase* pm) +{ + std::string out; + if (this->IsModeSet(pm)) + pm->GetParameter(this, out); + return out; +} + inline bool Channel::IsModeSet(ChanModeReference& mode) { if (!mode) |