X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=blobdiff_plain;f=src%2Fcommon%2Ftypes.h;h=eb0c0ca20b116c2d8b70e9fec1aed3875fe28be9;hp=0fbb2b773113fde769406aceff47356a1db702b3;hb=16f22647e6890d3eb8c3e94f7a0700e12fa29e44;hpb=9fc57dc2c000e80fb8bd746a090e2e8210e1278e diff --git a/src/common/types.h b/src/common/types.h index 0fbb2b77..eb0c0ca2 100644 --- a/src/common/types.h +++ b/src/common/types.h @@ -1,5 +1,5 @@ /*************************************************************************** - * Copyright (C) 2005-2013 by the Quassel Project * + * Copyright (C) 2005-2016 by the Quassel Project * * devel@quassel-irc.org * * * * This program is free software; you can redistribute it and/or modify * @@ -18,14 +18,17 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * ***************************************************************************/ -#ifndef TYPES_H_ -#define TYPES_H_ +#pragma once + +#include #include #include #include +#include #include #include +#include class SignedId { @@ -104,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; +}