From da29af8cba49d51e53d6e68237ccbf6370b6dd1f Mon Sep 17 00:00:00 2001 From: Attila Molnar Date: Thu, 25 Feb 2016 16:12:09 +0100 Subject: Convert WriteNumeric() calls to pass the parameters of the numeric as method parameters --- include/numericbuilder.h | 28 ++++++++++++---------------- 1 file changed, 12 insertions(+), 16 deletions(-) (limited to 'include/numericbuilder.h') 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 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 -- cgit v1.2.3