1 /***************************************************************************
2 * Copyright (C) 2005-08 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 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19 ***************************************************************************/
33 inline SignedId(int _id = 0) { id = _id; }
34 inline qint32 toInt() const { return id; }
35 inline bool isValid() const { return id > 0; }
37 inline bool operator==(const SignedId &other) const { return id == other.id; }
38 inline bool operator!=(const SignedId &other) const { return id != other.id; }
39 inline bool operator<(const SignedId &other) const { return id < other.id; }
40 inline bool operator>(const SignedId &other) const { return id > other.id; }
41 inline bool operator>=(const SignedId &other) const { return id >= other.id; }
42 inline bool operator==(int i) const { return id == i; }
43 inline bool operator!=(int i) const { return id != i; }
44 inline bool operator<(int i) const { return id < i; }
45 inline bool operator>(int i) const { return id > i; }
46 inline bool operator<=(int i) const { return id <= i; }
48 inline SignedId operator++(int) { id++; return *this; }
49 //inline operator int() const { return toInt(); } // no automatic conversion!
51 friend QDataStream &operator>>(QDataStream &in, SignedId &signedId);
54 inline QDataStream &operator<<(QDataStream &out, const SignedId &signedId) { out << signedId.toInt(); return out; }
55 inline QDataStream &operator>>(QDataStream &in, SignedId &signedId) { in >> signedId.id; return in; }
56 inline QDebug operator<<(QDebug dbg, const SignedId &signedId) { dbg.space() << signedId.toInt(); return dbg; }
57 inline uint qHash(const SignedId &id) { return qHash(id.toInt()); }
59 struct UserId : public SignedId {
60 inline UserId(int _id = 0) : SignedId(_id) {};
61 //inline operator QVariant() const { return QVariant::fromValue<UserId>(*this); } // no automatic conversion!
64 struct MsgId : public SignedId {
65 inline MsgId(int _id = 0) : SignedId(_id) {};
66 //inline operator QVariant() const { return QVariant::fromValue<MsgId>(*this); }
69 struct BufferId : public SignedId {
70 inline BufferId(int _id = 0) : SignedId(_id) {};
71 //inline operator QVariant() const { return QVariant::fromValue<BufferId>(*this); }
74 struct NetworkId : public SignedId {
75 inline NetworkId(int _id = 0) : SignedId(_id) {};
76 //inline operator QVariant() const { return QVariant::fromValue<NetworkId>(*this); }
79 struct IdentityId : public SignedId {
80 inline IdentityId(int _id = 0) : SignedId(_id) {};
81 //inline operator QVariant() const { return QVariant::fromValue<IdentityId>(*this); }
84 struct AccountId : public SignedId {
85 inline AccountId(int _id = 0) : SignedId(_id) {};
88 Q_DECLARE_METATYPE(UserId);
89 Q_DECLARE_METATYPE(MsgId);
90 Q_DECLARE_METATYPE(BufferId);
91 Q_DECLARE_METATYPE(NetworkId);
92 Q_DECLARE_METATYPE(IdentityId);
93 Q_DECLARE_METATYPE(AccountId);
95 //! Base class for exceptions.
97 Exception(QString msg = "Unknown Exception") : _msg(msg) {};
98 virtual ~Exception() {}; // make gcc happy
99 virtual inline QString msg() { return _msg; }