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 
150  // === Here are errors with no text representation ===
151 
154 
157 
162 
165 
168 
169  // === Here are types which convert to their string counterparts
170  // === letter-by-letter
171 
172  Join,
173  Kick,
174  Kill,
175  Mode,
176  Nick,
177  Notice,
178  Part,
179  Ping,
180  PrivMsg,
181  Quit,
182  Topic,
183 
186  };
187 
196  static IRCResponseType fromIntegerResponseValue(int responseType);
197 
213  static int toRfcNumber(MsgType type);
214 
223  static QString toRfcString(MsgType type);
224 
231  static MsgType typeFromRfcString(const QString& typeRepresentation);
232 
236  IRCResponseType();
237 
241  IRCResponseType(MsgType type);
242 
247  IRCResponseType(const QString& typeRepresentation);
248 
254  bool isCommandResponse() const
255  {
256  return d.numericType >= 200 && d.numericType <= 399;
257  }
258 
264  bool isErrorMessage() const
265  {
266  return d.numericType >= 400;
267  }
268 
272  bool isValid() const
273  {
274  return d.type != Invalid;
275  }
276 
277  bool operator==(const IRCResponseType& other) const;
278  bool operator!=(const IRCResponseType& other) const;
279 
287  int numericType() const
288  {
289  return d.numericType;
290  }
291 
297  QString toRfcString() const
298  {
299  return toRfcString(d.type);
300  }
301 
302  MsgType type() const
303  {
304  return d.type;
305  }
306 
307  private:
308  class PrivData
309  {
310  public:
315  int numericType;
316  MsgType type;
317  };
318 
319  PrivData d;
320 };
321 
322 #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'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).
Definition: dptr.h:31
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'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.