X-Git-Url: https://git.quassel-irc.org/?a=blobdiff_plain;f=src%2Fcommon%2Ftypes.h;h=a801de7cdf7d139d111eee991d25a710877eddd5;hb=e30092afc1803d753914a7ab9fa88bba818de559;hp=c9891231cf7f2587c06e71566cc019f29b3b392e;hpb=f13ee12590d103b3512ba74c0bef3b0817c4c947;p=quassel.git diff --git a/src/common/types.h b/src/common/types.h index c9891231..a801de7c 100644 --- a/src/common/types.h +++ b/src/common/types.h @@ -1,5 +1,5 @@ /*************************************************************************** - * Copyright (C) 2005-2014 by the Quassel Project * + * Copyright (C) 2005-2015 by the Quassel Project * * devel@quassel-irc.org * * * * This program is free software; you can redistribute it and/or modify * @@ -18,8 +18,9 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * ***************************************************************************/ -#ifndef TYPES_H_ -#define TYPES_H_ +#pragma once + +#include #include #include @@ -29,11 +30,6 @@ #include #include -// We need to special-case Peer* in attached signals/slots, so typedef it for the meta type system -class Peer; -typedef Peer * PeerPtr; -Q_DECLARE_METATYPE(PeerPtr) - class SignedId { protected: @@ -111,14 +107,32 @@ Q_DECLARE_METATYPE(QHostAddress) typedef QList MsgIdList; typedef QList BufferIdList; -//! Base class for exceptions. -struct Exception { - Exception(QString msg = "Unknown Exception") : _msg(msg) {} - virtual ~Exception() {} // make gcc happy - virtual inline QString msg() { return _msg; } - -protected: - QString _msg; -}; - -#endif +/** + * Catch-all stream serialization operator for enum types. + * + * @param[in,out] out Stream to serialize to + * @param[in] value Value to serialize + * @returns A reference to the stream + */ +template::value>::type> +QDataStream &operator<<(QDataStream &out, T value) { + out << static_cast::type>(value); + return out; +} + +/** + * Catch-all stream serialization operator for enum types. + * + * @param[in,out] in Stream to deserialize from + * @param[out] value Value to deserialize into + * @returns A reference to the stream + */ +template::value>::type> +QDataStream &operator>>(QDataStream &in, T &value) { + typename std::underlying_type::type v; + in >> v; + value = static_cast(v); + return in; +}