X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=blobdiff_plain;f=src%2Fcommon%2Ftypes.h;h=a801de7cdf7d139d111eee991d25a710877eddd5;hp=aa0521b769b57c82caca5d523082ee590fe92d3a;hb=190d3d00156c568dcc4d248b4dd242180ebdfb9d;hpb=5b686746c880e5cda6d5de3e08180ea4332ff222 diff --git a/src/common/types.h b/src/common/types.h index aa0521b7..a801de7c 100644 --- a/src/common/types.h +++ b/src/common/types.h @@ -1,5 +1,5 @@ /*************************************************************************** - * Copyright (C) 2005-2012 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,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; +}