X-Git-Url: https://git.quassel-irc.org/?a=blobdiff_plain;f=src%2Fcommon%2Ftypes.h;h=64bfbbc784860e4993807a1977ac67eea873566c;hb=0d53027b95e4bd9ca369bd909c17cf13612f7dd5;hp=c148d62b4d6530af286943280d07fa3b1edb4196;hpb=99c92e21b3b9eb5ed661632cdfb69aabfc6b2deb;p=quassel.git diff --git a/src/common/types.h b/src/common/types.h index c148d62b..64bfbbc7 100644 --- a/src/common/types.h +++ b/src/common/types.h @@ -1,11 +1,11 @@ /*************************************************************************** - * Copyright (C) 2005-07 by the Quassel IRC Team * + * Copyright (C) 2005-08 by the Quassel Project * * devel@quassel-irc.org * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * + * (at your option) version 3. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * @@ -21,12 +21,68 @@ #ifndef _TYPES_H_ #define _TYPES_H_ +#include #include +#include -typedef uint UserId; //!< Identifies a core user. -typedef uint MsgId; //!< Identifies a message. -typedef uint BufferId; //!< Identifies a buffer. -typedef uint NetworkId; //!< Identifies an IRC Network. +class SignedId { + protected: + qint32 id; + + public: + inline SignedId(int _id = 0) { id = _id; } + inline qint32 toInt() const { return id; } + + inline bool operator==(const SignedId &other) const { return id == other.id; } + inline bool operator!=(const SignedId &other) const { return id != other.id; } + inline bool operator<(const SignedId &other) const { return id < other.id; } + inline bool operator==(int i) const { return id == i; } + inline bool operator!=(int i) const { return id != i; } + inline bool operator<(int i) const { return id < i; } + inline bool operator>(int i) const { return id > i; } + inline bool operator<=(int i) const { return id <= i; } + + inline SignedId operator++(int) { id++; return *this; } + //inline operator int() const { return toInt(); } // no automatic conversion! + + friend QDataStream &operator>>(QDataStream &in, SignedId &signedId); +}; + +inline QDataStream &operator<<(QDataStream &out, const SignedId &signedId) { out << signedId.toInt(); return out; } +inline QDataStream &operator>>(QDataStream &in, SignedId &signedId) { in >> signedId.id; return in; } +inline QDebug operator<<(QDebug dbg, const SignedId &signedId) { dbg.space() << signedId.toInt(); return dbg; } +inline uint qHash(const SignedId &id) { return qHash(id.toInt()); } + +struct UserId : public SignedId { + inline UserId(int _id = 0) : SignedId(_id) {}; + //inline operator QVariant() const { return QVariant::fromValue(*this); } // no automatic conversion! +}; + +struct MsgId : public SignedId { + inline MsgId(int _id = 0) : SignedId(_id) {}; + //inline operator QVariant() const { return QVariant::fromValue(*this); } +}; + +struct BufferId : public SignedId { + inline BufferId(int _id = 0) : SignedId(_id) {}; + //inline operator QVariant() const { return QVariant::fromValue(*this); } +}; + +struct NetworkId : public SignedId { + inline NetworkId(int _id = 0) : SignedId(_id) {}; + //inline operator QVariant() const { return QVariant::fromValue(*this); } +}; + +struct IdentityId : public SignedId { + inline IdentityId(int _id = 0) : SignedId(_id) {}; + //inline operator QVariant() const { return QVariant::fromValue(*this); } +}; + +Q_DECLARE_METATYPE(UserId); +Q_DECLARE_METATYPE(MsgId); +Q_DECLARE_METATYPE(BufferId); +Q_DECLARE_METATYPE(NetworkId); +Q_DECLARE_METATYPE(IdentityId); //! Base class for exceptions. struct Exception {