]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - include/modules/stats.h
d2f6eabbb89f01d4f5c3781ac337d7a3b119ac08
[user/henk/code/inspircd.git] / include / modules / stats.h
1 /*
2  * InspIRCd -- Internet Relay Chat Daemon
3  *
4  *   Copyright (C) 2016 Attila Molnar <attilamolnar@hush.com>
5  *
6  * This file is part of InspIRCd.  InspIRCd is free software: you can
7  * redistribute it and/or modify it under the terms of the GNU General Public
8  * License as published by the Free Software Foundation, version 2.
9  *
10  * This program is distributed in the hope that it will be useful, but WITHOUT
11  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12  * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
13  * details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
17  */
18
19
20 #pragma once
21
22 namespace Stats
23 {
24         class Context;
25         class Row;
26 }
27
28 class Stats::Row : public Numeric::Numeric
29 {
30  public:
31         Row(unsigned int num)
32                 : Numeric(num)
33         {
34         }
35 };
36
37 class Stats::Context
38 {
39         /** Source user of the STATS request
40          */
41         User* const source;
42
43         /** List of reply rows
44          */
45         std::vector<Row> rows;
46
47         /** Symbol indicating the type of this STATS request (usually a letter)
48          */
49         const char symbol;
50
51  public:
52         /** Constructor
53          * @param src Source user of the STATS request, can be a local or remote user
54          * @param sym Symbol (letter) indicating the type of the request
55          */
56         Context(User* src, char sym)
57                 : source(src)
58                 , symbol(sym)
59         {
60         }
61
62         /** Get the source user of the STATS request
63          * @return Source user of the STATS request
64          */
65         User* GetSource() const { return source; }
66
67         /** Get the list of reply rows
68          * @return List of rows generated as reply for the request
69          */
70         const std::vector<Row>& GetRows() const { return rows; }
71
72         /** Get the symbol (letter) indicating what type of STATS was requested
73          * @return Symbol specified by the requesting user
74          */
75         char GetSymbol() const { return symbol; }
76
77         /** Add a row to the reply list
78          * @param row Reply to add
79          */
80         void AddRow(const Row& row) { rows.push_back(row); }
81
82         template <typename T1>
83         void AddRow(unsigned int numeric, T1 p1)
84         {
85                 Row n(numeric);
86                 n.push(p1);
87                 AddRow(n);
88         }
89
90         template <typename T1, typename T2>
91         void AddRow(unsigned int numeric, T1 p1, T2 p2)
92         {
93                 Row n(numeric);
94                 n.push(p1);
95                 n.push(p2);
96                 AddRow(n);
97         }
98
99         template <typename T1, typename T2, typename T3>
100         void AddRow(unsigned int numeric, T1 p1, T2 p2, T3 p3)
101         {
102                 Row n(numeric);
103                 n.push(p1);
104                 n.push(p2);
105                 n.push(p3);
106                 AddRow(n);
107         }
108
109         template <typename T1, typename T2, typename T3, typename T4>
110         void AddRow(unsigned int numeric, T1 p1, T2 p2, T3 p3, T4 p4)
111         {
112                 Row n(numeric);
113                 n.push(p1);
114                 n.push(p2);
115                 n.push(p3);
116                 n.push(p4);
117                 AddRow(n);
118         }
119
120         template <typename T1, typename T2, typename T3, typename T4, typename T5>
121         void AddRow(unsigned int numeric, T1 p1, T2 p2, T3 p3, T4 p4, T5 p5)
122         {
123                 Row n(numeric);
124                 n.push(p1);
125                 n.push(p2);
126                 n.push(p3);
127                 n.push(p4);
128                 n.push(p5);
129                 AddRow(n);
130         }
131
132         template <typename T1, typename T2, typename T3, typename T4, typename T5, typename T6>
133         void AddRow(unsigned int numeric, T1 p1, T2 p2, T3 p3, T4 p4, T5 p5, T6 p6)
134         {
135                 Row n(numeric);
136                 n.push(p1);
137                 n.push(p2);
138                 n.push(p3);
139                 n.push(p4);
140                 n.push(p5);
141                 n.push(p6);
142                 AddRow(n);
143         }
144
145         template <typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7>
146         void AddRow(unsigned int numeric, T1 p1, T2 p2, T3 p3, T4 p4, T5 p5, T6 p6, T7 p7)
147         {
148                 Row n(numeric);
149                 n.push(p1);
150                 n.push(p2);
151                 n.push(p3);
152                 n.push(p4);
153                 n.push(p5);
154                 n.push(p6);
155                 n.push(p7);
156                 AddRow(n);
157         }
158
159         template <typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8>
160         void AddRow(unsigned int numeric, T1 p1, T2 p2, T3 p3, T4 p4, T5 p5, T6 p6, T7 p7, T8 p8)
161         {
162                 Row n(numeric);
163                 n.push(p1);
164                 n.push(p2);
165                 n.push(p3);
166                 n.push(p4);
167                 n.push(p5);
168                 n.push(p6);
169                 n.push(p7);
170                 n.push(p8);
171                 AddRow(n);
172         }
173 };