ircresponsetype.h
1 //------------------------------------------------------------------------------
2 // ircresponsetype.h
3 //
4 // Copyright (C) 2011 "Zalewa" <zalewapl@gmail.com>
5 //------------------------------------------------------------------------------
6 #ifndef __IRCRESPONSETYPE_H__
7 #define __IRCRESPONSETYPE_H__
8 
9 #include <QString>
10 
17 {
18  public:
25  enum MsgType
26  {
27  // === IMPORTANT!!! ===
28  // Remember to fix toRfcString() if values here change!
29  // Also IRCResponseParser::parseMessage() must be
30  // fixed.
31 
39  Invalid = 0,
40 
48 
49  // === Here are types with no text representation ===
50 
55 
62 
65 
68 
71 
74 
80 
88 
91 
94 
97 
100 
103 
106 
116 
119 
122 
125 
128 
131 
134 
137 
140 
143 
146 
149 
152 
155 
158 
159  // === Here are errors with no text representation ===
160 
163 
166 
171 
172  ERRChannelIsFull, // 471
173  ERRInviteOnlyChan, // 473
174  ERRBannedFromChan, // 474
175  ERRBadChannelKey, // 475
176  ERRBadChannelMask, // 476
177  ERRNoChanModes, // 477
178 
181 
184 
185  // === Here are types which convert to their string counterparts
186  // === letter-by-letter
187 
188  Join,
189  Kick,
190  Kill,
191  Mode,
192  Nick,
193  Notice,
194  Part,
195  Ping,
196  PrivMsg,
197  Quit,
198  Topic,
199 
202  };
203 
212  static IRCResponseType fromIntegerResponseValue(int responseType);
213 
229  static int toRfcNumber(MsgType type);
230 
239  static QString toRfcString(MsgType type);
240 
247  static MsgType typeFromRfcString(const QString& typeRepresentation);
248 
252  IRCResponseType();
253 
257  IRCResponseType(MsgType type);
258 
263  IRCResponseType(const QString& typeRepresentation);
264 
270  bool isCommandResponse() const
271  {
272  return d.numericType >= 200 && d.numericType <= 399;
273  }
274 
280  bool isErrorMessage() const
281  {
282  return d.numericType >= 400;
283  }
284 
288  bool isValid() const
289  {
290  return d.type != Invalid;
291  }
292 
293  bool operator==(const IRCResponseType& other) const;
294  bool operator!=(const IRCResponseType& other) const;
295 
303  int numericType() const
304  {
305  return d.numericType;
306  }
307 
313  QString toRfcString() const
314  {
315  return toRfcString(d.type);
316  }
317 
318  MsgType type() const
319  {
320  return d.type;
321  }
322 
323  private:
324  class PrivData
325  {
326  public:
331  int numericType;
332  MsgType type;
333  };
334 
335  PrivData d;
336 };
337 
338 #endif
bool isErrorMessage() const
Check if numeric value is equal to or above 400.
QString toRfcString() const
String representation of the message type.
375 - start of the message of the day
372 - message of the day
Not a real type, denotes number of all types.
254 - how many channels,
253 - how many unknown connections
366 - end of names list
251 - how many users on how many servers
320 - it&#39;s inconclusive what this code means.
Defines types of IRC network response message.
static IRCResponseType fromIntegerResponseValue(int responseType)
Creates IRCResponseType objects taking numeric value as the more important here.
static MsgType typeFromRfcString(const QString &typeRepresentation)
Returns MsgType basing on typeRepresentation.
353 - names list for a channel
376 - end of the message of the day
bool isCommandResponse() const
Check if numeric value is between 200 and 399 (inclusive).
001 - sent when client connects.
005 - all sorts of server flags.
static int toRfcNumber(MsgType type)
If type can be represented as an integer, this will convert it.
MsgType
Represents types defined by RFC 1459.
307 - no idea what this is, but we&#39;ll treat it the same way we treat RPLWhoIsSpecial.
255 - how many clients on how many servers,
int numericType() const
If message type can be represented as number, this will contain its value.
IRCResponseType()
Initializes an invalid IRCResponseType object.
bool isValid() const
Response is valid if type is different than Invalid.
Type unknown to this IRC client.