diff options
author | Attila Molnar <attilamolnar@hush.com> | 2016-02-25 16:12:09 +0100 |
---|---|---|
committer | Attila Molnar <attilamolnar@hush.com> | 2016-02-25 16:12:09 +0100 |
commit | da29af8cba49d51e53d6e68237ccbf6370b6dd1f (patch) | |
tree | 5546764f28ff9457efa3a0f90ae6778953590293 /include | |
parent | 28dcc1f9e017152f03b0d9bfbcc494260b015a0a (diff) |
Convert WriteNumeric() calls to pass the parameters of the numeric as method parameters
Diffstat (limited to 'include')
-rw-r--r-- | include/isupportmanager.h | 6 | ||||
-rw-r--r-- | include/modules.h | 2 | ||||
-rw-r--r-- | include/numericbuilder.h | 28 | ||||
-rw-r--r-- | include/users.h | 53 |
4 files changed, 67 insertions, 22 deletions
diff --git a/include/isupportmanager.h b/include/isupportmanager.h index 1f41de5d2..3a0df78f9 100644 --- a/include/isupportmanager.h +++ b/include/isupportmanager.h @@ -24,7 +24,7 @@ class CoreExport ISupportManager { private: /** The generated lines which are sent to clients. */ - std::vector<std::string> cachedlines; + std::vector<Numeric::Numeric> cachedlines; public: /** (Re)build the ISUPPORT vector. @@ -34,9 +34,9 @@ class CoreExport ISupportManager void Build(); /** Returns the cached std::vector of ISUPPORT lines. - * @return A list of strings prepared for sending to users + * @return A list of Numeric::Numeric objects prepared for sending to users */ - const std::vector<std::string>& GetLines() const { return cachedlines; } + const std::vector<Numeric::Numeric>& GetLines() const { return cachedlines; } /** Send the 005 numerics (ISUPPORT) to a user. * @param user The user to send the ISUPPORT numerics to diff --git a/include/modules.h b/include/modules.h index 526c283b2..86ee7f4f3 100644 --- a/include/modules.h +++ b/include/modules.h @@ -987,7 +987,7 @@ class CoreExport Module : public classbase, public usecountbase */ virtual ModResult OnNamesListItem(User* issuer, Membership* item, std::string& prefixes, std::string& nick); - virtual ModResult OnNumeric(User* user, unsigned int numeric, const std::string &text); + virtual ModResult OnNumeric(User* user, const Numeric::Numeric& numeric); /** Called whenever a result from /WHO is about to be returned * @param source The user running the /WHO query diff --git a/include/numericbuilder.h b/include/numericbuilder.h index 371f275a9..726aeff3f 100644 --- a/include/numericbuilder.h +++ b/include/numericbuilder.h @@ -40,9 +40,9 @@ class Numeric::WriteNumericSink { } - void operator()(unsigned int numeric, const std::string& params) const + void operator()(Numeric& numeric) const { - user->WriteNumeric(numeric, params); + user->WriteNumeric(numeric); } }; @@ -50,14 +50,12 @@ template <char Sep, bool SendEmpty, typename Sink> class Numeric::GenericBuilder { Sink sink; - std::string data; - const unsigned int numeric; + Numeric numeric; const std::string::size_type max; - std::string::size_type beginpos; bool HasRoom(const std::string::size_type additional) const { - return (data.size() + additional <= max); + return (numeric.GetParams().back().size() + additional <= max); } public: @@ -67,28 +65,28 @@ class Numeric::GenericBuilder , max(ServerInstance->Config->Limits.MaxLine - ServerInstance->Config->ServerName.size() - additionalsize - 9) { if (addparam) - data.push_back(':'); - SaveBeginPos(); + numeric.push(std::string()); } - std::string& GetNumeric() { return data; } + Numeric& GetNumeric() { return numeric; } void Add(const std::string& entry) { if (!HasRoom(entry.size())) Flush(); - data.append(entry).push_back(Sep); + numeric.GetParams().back().append(entry).push_back(Sep); } void Add(const std::string& entry1, const std::string& entry2) { if (!HasRoom(entry1.size() + entry2.size())) Flush(); - data.append(entry1).append(entry2).push_back(Sep); + numeric.GetParams().back().append(entry1).append(entry2).push_back(Sep); } void Flush() { + std::string& data = numeric.GetParams().back(); if (IsEmpty()) { if (!SendEmpty) @@ -99,13 +97,11 @@ class Numeric::GenericBuilder data.erase(data.size()-1); } - sink(numeric, data); - if (data.size() > beginpos) - data.erase(beginpos); + sink(numeric); + data.clear(); } - bool IsEmpty() const { return (data.size() == beginpos); } - void SaveBeginPos() { beginpos = data.size(); } + bool IsEmpty() const { return (numeric.GetParams().back().empty()); } }; template <char Sep, bool SendEmpty> diff --git a/include/users.h b/include/users.h index fa346a329..8aa88798c 100644 --- a/include/users.h +++ b/include/users.h @@ -519,9 +519,58 @@ class CoreExport User : public Extensible */ void WriteNotice(const std::string& text) { this->WriteCommand("NOTICE", ":" + text); } - void WriteNumeric(unsigned int numeric, const char* text, ...) CUSTOM_PRINTF(3, 4); - void WriteNumeric(unsigned int numeric, const std::string &text); + void WriteNumeric(const Numeric::Numeric& numeric); + + template <typename T1> + void WriteNumeric(unsigned int numeric, T1 p1) + { + Numeric::Numeric n(numeric); + n.push(p1); + WriteNumeric(n); + } + + template <typename T1, typename T2> + void WriteNumeric(unsigned int numeric, T1 p1, T2 p2) + { + Numeric::Numeric n(numeric); + n.push(p1); + n.push(p2); + WriteNumeric(n); + } + + template <typename T1, typename T2, typename T3> + void WriteNumeric(unsigned int numeric, T1 p1, T2 p2, T3 p3) + { + Numeric::Numeric n(numeric); + n.push(p1); + n.push(p2); + n.push(p3); + WriteNumeric(n); + } + + template <typename T1, typename T2, typename T3, typename T4> + void WriteNumeric(unsigned int numeric, T1 p1, T2 p2, T3 p3, T4 p4) + { + Numeric::Numeric n(numeric); + n.push(p1); + n.push(p2); + n.push(p3); + n.push(p4); + WriteNumeric(n); + } + + template <typename T1, typename T2, typename T3, typename T4, typename T5> + void WriteNumeric(unsigned int numeric, T1 p1, T2 p2, T3 p3, T4 p4, T5 p5) + { + Numeric::Numeric n(numeric); + n.push(p1); + n.push(p2); + n.push(p3); + n.push(p4); + n.push(p5); + WriteNumeric(n); + } /** Write text to this user, appending CR/LF and prepending :nick!user\@host of the user provided in the first parameter. * @param user The user to prepend the :nick!user\@host of |