X-Git-Url: https://git.quassel-irc.org/?a=blobdiff_plain;f=src%2Fcommon%2Ftypes.h;h=a801de7cdf7d139d111eee991d25a710877eddd5;hb=e30092afc1803d753914a7ab9fa88bba818de559;hp=c69660f8df6abb7c0d7d54a076ef91c123adc8b1;hpb=b65b9f7615165e8700a44d59b7275a55558dd45b;p=quassel.git diff --git a/src/common/types.h b/src/common/types.h index c69660f8..a801de7c 100644 --- a/src/common/types.h +++ b/src/common/types.h @@ -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 @@ -106,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; +}