From 28dcc1f9e017152f03b0d9bfbcc494260b015a0a Mon Sep 17 00:00:00 2001 From: Attila Molnar Date: Thu, 25 Feb 2016 15:25:02 +0100 Subject: Add Numeric::Numeric --- include/numeric.h | 88 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 88 insertions(+) create mode 100644 include/numeric.h (limited to 'include/numeric.h') diff --git a/include/numeric.h b/include/numeric.h new file mode 100644 index 000000000..e7438b53a --- /dev/null +++ b/include/numeric.h @@ -0,0 +1,88 @@ +/* + * InspIRCd -- Internet Relay Chat Daemon + * + * Copyright (C) 2016 Attila Molnar + * + * This file is part of InspIRCd. InspIRCd is free software: you can + * redistribute it and/or modify it under the terms of the GNU General Public + * License as published by the Free Software Foundation, version 2. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + + +#pragma once + +#include "numerics.h" + +namespace Numeric +{ + class Numeric; +} + +class Numeric::Numeric +{ + /** Numeric number + */ + unsigned int numeric; + + /** Parameters of the numeric + */ + std::vector params; + + public: + /** Constructor + * @param num Numeric number (RPL_*, ERR_*) + */ + Numeric(unsigned int num) + : numeric(num) + { + } + + /** Add a parameter to the numeric. The parameter will be converted to a string first with ConvToStr(). + * @param x Parameter to add + */ + template + Numeric& push(const T& x) + { + params.push_back(ConvToStr(x)); + return *this; + } + + /** Get the number of the numeric as an unsigned integer + * @return Numeric number as an unsigned integer + */ + unsigned int GetNumeric() const { return numeric; } + + /** Get the parameters of the numeric + * @return Parameters of the numeric as a const vector of strings + */ + const std::vector& GetParams() const { return params; } + + /** Get the parameters of the numeric + * @return Parameters of the numeric as a vector of strings + */ + std::vector& GetParams() { return params; } +}; + +namespace Numerics +{ + /** ERR_NOSUCHNICK numeric + */ + class NoSuchNick : public Numeric::Numeric + { + public: + NoSuchNick(const std::string& nick) + : Numeric(ERR_NOSUCHNICK) + { + push(nick); + push("No such nick/channel"); + } + }; +} -- cgit v1.2.3 From ee7567584e4792166a4d6455ca306731d8b5f28a Mon Sep 17 00:00:00 2001 From: Attila Molnar Date: Thu, 25 Feb 2016 16:28:58 +0100 Subject: Make source server settable in Numeric::Numeric --- include/numeric.h | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'include/numeric.h') diff --git a/include/numeric.h b/include/numeric.h index e7438b53a..8044fe5bf 100644 --- a/include/numeric.h +++ b/include/numeric.h @@ -36,12 +36,17 @@ class Numeric::Numeric */ std::vector params; + /** Source server of the numeric, if NULL (the default) then it is the local server + */ + Server* sourceserver; + public: /** Constructor * @param num Numeric number (RPL_*, ERR_*) */ Numeric(unsigned int num) : numeric(num) + , sourceserver(NULL) { } @@ -55,6 +60,16 @@ class Numeric::Numeric return *this; } + /** Set the source server of the numeric. The source server defaults to the local server. + * @param server Server to set as source + */ + void SetServer(Server* server) { sourceserver = server; } + + /** Get the source server of the numeric + * @return Source server or NULL if the source is the local server + */ + Server* GetServer() const { return sourceserver; } + /** Get the number of the numeric as an unsigned integer * @return Numeric number as an unsigned integer */ -- cgit v1.2.3