From 304b6dbbf56710b1310fce8c5cf71b73334c060a Mon Sep 17 00:00:00 2001 From: Attila Molnar Date: Thu, 25 Feb 2016 17:02:03 +0100 Subject: Introduce Stats::Context, pass it to the OnStats hook and switch all code to it --- include/modules/stats.h | 172 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 172 insertions(+) create mode 100644 include/modules/stats.h (limited to 'include/modules') diff --git a/include/modules/stats.h b/include/modules/stats.h new file mode 100644 index 000000000..b1e27b4e7 --- /dev/null +++ b/include/modules/stats.h @@ -0,0 +1,172 @@ +/* + * 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 + +namespace Stats +{ + class Context; + class Row; +} + +class Stats::Row : public Numeric::Numeric +{ + public: + Row(unsigned int num) + : Numeric(num) + { + } +}; + +class Stats::Context +{ + /** Source user of the STATS request + */ + User* const source; + + /** List of reply rows + */ + std::vector rows; + + /** Symbol indicating the type of this STATS request (usually a letter) + */ + const char symbol; + + public: + /** Constructor + * @param src Source user of the STATS request, can be a local or remote user + * @param sym Symbol (letter) indicating the type of the request + */ + Context(User* src, char sym) + : source(src) + , symbol(sym) + { + } + + /** Get the source user of the STATS request + * @return Source user of the STATS request + */ + User* GetSource() const { return source; } + + /** Get the list of reply rows + * @return List of rows generated as reply for the request + */ + const std::vector& GetRows() const { return rows; } + + /** Get the symbol (letter) indicating what type of STATS was requested + * @return Symbol specified by the requesting user + */ + char GetSymbol() const { return symbol; } + + /** Add a row to the reply list + * @param row Reply to add + */ + void AddRow(const Row& row) { rows.push_back(row); } + + template + void AddRow(unsigned int numeric, T1 p1) + { + Row n(numeric); + n.push(p1); + AddRow(n); + } + + template + void AddRow(unsigned int numeric, T1 p1, T2 p2) + { + Row n(numeric); + n.push(p1); + n.push(p2); + AddRow(n); + } + + template + void AddRow(unsigned int numeric, T1 p1, T2 p2, T3 p3) + { + Row n(numeric); + n.push(p1); + n.push(p2); + n.push(p3); + AddRow(n); + } + + template + void AddRow(unsigned int numeric, T1 p1, T2 p2, T3 p3, T4 p4) + { + Row n(numeric); + n.push(p1); + n.push(p2); + n.push(p3); + n.push(p4); + AddRow(n); + } + + template + void AddRow(unsigned int numeric, T1 p1, T2 p2, T3 p3, T4 p4, T5 p5) + { + Row n(numeric); + n.push(p1); + n.push(p2); + n.push(p3); + n.push(p4); + n.push(p5); + AddRow(n); + } + + template + void AddRow(unsigned int numeric, T1 p1, T2 p2, T3 p3, T4 p4, T5 p5, T6 p6) + { + Row n(numeric); + n.push(p1); + n.push(p2); + n.push(p3); + n.push(p4); + n.push(p5); + n.push(p6); + AddRow(n); + } + + template + void AddRow(unsigned int numeric, T1 p1, T2 p2, T3 p3, T4 p4, T5 p5, T6 p6, T7 p7) + { + Row n(numeric); + n.push(p1); + n.push(p2); + n.push(p3); + n.push(p4); + n.push(p5); + n.push(p6); + n.push(p7); + AddRow(n); + } + + template + void AddRow(unsigned int numeric, T1 p1, T2 p2, T3 p3, T4 p4, T5 p5, T6 p6, T7 p7, T8 p8) + { + Row n(numeric); + n.push(p1); + n.push(p2); + n.push(p3); + n.push(p4); + n.push(p5); + n.push(p6); + n.push(p7); + AddRow(n); + } +}; -- cgit v1.2.3