1 /***************************************************************************
2 * Copyright (C) 2005-2015 by the Quassel Project *
3 * devel@quassel-irc.org *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) version 3. *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the *
17 * Free Software Foundation, Inc., *
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
19 ***************************************************************************/
27 #include <QDataStream>
28 #include <QTextStream>
29 #include <QHostAddress>
30 #include <QDataStream>
38 inline SignedId(int _id = 0) { id = _id; }
39 inline qint32 toInt() const { return id; }
40 inline bool isValid() const { return id > 0; }
42 inline bool operator==(const SignedId &other) const { return id == other.id; }
43 inline bool operator!=(const SignedId &other) const { return id != other.id; }
44 inline bool operator<(const SignedId &other) const { return id < other.id; }
45 inline bool operator<=(const SignedId &other) const { return id <= other.id; }
46 inline bool operator>(const SignedId &other) const { return id > other.id; }
47 inline bool operator>=(const SignedId &other) const { return id >= other.id; }
48 inline bool operator==(int i) const { return id == i; }
49 inline bool operator!=(int i) const { return id != i; }
50 inline bool operator<(int i) const { return id < i; }
51 inline bool operator>(int i) const { return id > i; }
52 inline bool operator<=(int i) const { return id <= i; }
54 inline SignedId operator++(int) { id++; return *this; }
55 //inline operator int() const { return toInt(); } // no automatic conversion!
57 friend QDataStream &operator>>(QDataStream &in, SignedId &signedId);
61 inline QDataStream &operator<<(QDataStream &out, const SignedId &signedId) { out << signedId.toInt(); return out; }
62 inline QDataStream &operator>>(QDataStream &in, SignedId &signedId) { in >> signedId.id; return in; }
63 inline QTextStream &operator<<(QTextStream &out, const SignedId &signedId) { out << QString::number(signedId.toInt()); return out; }
64 inline QDebug operator<<(QDebug dbg, const SignedId &signedId) { dbg.space() << signedId.toInt(); return dbg; }
65 inline uint qHash(const SignedId &id) { return qHash(id.toInt()); }
67 struct UserId : public SignedId {
68 inline UserId(int _id = 0) : SignedId(_id) {}
69 //inline operator QVariant() const { return QVariant::fromValue<UserId>(*this); } // no automatic conversion!
72 struct MsgId : public SignedId {
73 inline MsgId(int _id = 0) : SignedId(_id) {}
74 //inline operator QVariant() const { return QVariant::fromValue<MsgId>(*this); }
77 struct BufferId : public SignedId {
78 inline BufferId(int _id = 0) : SignedId(_id) {}
79 //inline operator QVariant() const { return QVariant::fromValue<BufferId>(*this); }
82 struct NetworkId : public SignedId {
83 inline NetworkId(int _id = 0) : SignedId(_id) {}
84 //inline operator QVariant() const { return QVariant::fromValue<NetworkId>(*this); }
87 struct IdentityId : public SignedId {
88 inline IdentityId(int _id = 0) : SignedId(_id) {}
89 //inline operator QVariant() const { return QVariant::fromValue<IdentityId>(*this); }
92 struct AccountId : public SignedId {
93 inline AccountId(int _id = 0) : SignedId(_id) {}
96 Q_DECLARE_METATYPE(UserId)
97 Q_DECLARE_METATYPE(MsgId)
98 Q_DECLARE_METATYPE(BufferId)
99 Q_DECLARE_METATYPE(NetworkId)
100 Q_DECLARE_METATYPE(IdentityId)
101 Q_DECLARE_METATYPE(AccountId)
103 Q_DECLARE_METATYPE(QHostAddress)
106 typedef QList<MsgId> MsgIdList;
107 typedef QList<BufferId> BufferIdList;
109 //! Base class for exceptions.
111 Exception(QString msg = "Unknown Exception") : _msg(msg) {}
112 virtual ~Exception() {} // make gcc happy
113 virtual inline QString msg() { return _msg; }