]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_spanningtree/commandbuilder.h
59de84052b4d80027d5971c3640ca1b52a0ddaab
[user/henk/code/inspircd.git] / src / modules / m_spanningtree / commandbuilder.h
1 /*
2  * InspIRCd -- Internet Relay Chat Daemon
3  *
4  *   Copyright (C) 2013 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 #include "utils.h"
23
24 class TreeServer;
25
26 class CmdBuilder
27 {
28  protected:
29         std::string content;
30
31  public:
32         CmdBuilder(const char* cmd)
33                 : content(1, ':')
34         {
35                 content.append(ServerInstance->Config->GetSID());
36                 push(cmd);
37         }
38
39         CmdBuilder(const std::string& src, const char* cmd)
40                 : content(1, ':')
41         {
42                 content.append(src);
43                 push(cmd);
44         }
45
46         CmdBuilder(User* src, const char* cmd)
47                 : content(1, ':')
48         {
49                 content.append(src->uuid);
50                 push(cmd);
51         }
52
53         CmdBuilder& push_raw(const std::string& s)
54         {
55                 content.append(s);
56                 return *this;
57         }
58
59         CmdBuilder& push_raw(const char* s)
60         {
61                 content.append(s);
62                 return *this;
63         }
64
65         CmdBuilder& push_raw(char c)
66         {
67                 content.push_back(c);
68                 return *this;
69         }
70
71         template <typename T>
72         CmdBuilder& push_raw_int(T i)
73         {
74                 content.append(ConvToStr(i));
75                 return *this;
76         }
77
78         template <typename InputIterator>
79         CmdBuilder& push_raw(InputIterator first, InputIterator last)
80         {
81                 content.append(first, last);
82                 return *this;
83         }
84
85         CmdBuilder& push(const std::string& s)
86         {
87                 content.push_back(' ');
88                 content.append(s);
89                 return *this;
90         }
91
92         CmdBuilder& push(const char* s)
93         {
94                 content.push_back(' ');
95                 content.append(s);
96                 return *this;
97         }
98
99         CmdBuilder& push(char c)
100         {
101                 content.push_back(' ');
102                 content.push_back(c);
103                 return *this;
104         }
105
106         template <typename T>
107         CmdBuilder& push_int(T i)
108         {
109                 content.push_back(' ');
110                 content.append(ConvToStr(i));
111                 return *this;
112         }
113
114         CmdBuilder& push_last(const std::string& s)
115         {
116                 content.push_back(' ');
117                 content.push_back(':');
118                 content.append(s);
119                 return *this;
120         }
121
122         template<typename T>
123         CmdBuilder& insert(const T& cont)
124         {
125                 for (typename T::const_iterator i = cont.begin(); i != cont.end(); ++i)
126                         push(*i);
127                 return *this;
128         }
129
130         void push_back(const std::string& s) { push(s); }
131
132         const std::string& str() const { return content; }
133         operator const std::string&() const { return str(); }
134
135         void Broadcast() const
136         {
137                 Utils->DoOneToMany(*this);
138         }
139
140         void Forward(TreeServer* omit) const
141         {
142                 Utils->DoOneToAllButSender(*this, omit);
143         }
144
145         void Unicast(User* target) const
146         {
147                 Utils->DoOneToOne(*this, target->server);
148         }
149 };