X-Git-Url: https://git.quassel-irc.org/?a=blobdiff_plain;f=src%2Fcommon%2Ftypes.h;h=5c800952987a1243dec92408e31b56d82097f904;hb=933e1bf5264b6bbd91941f1f06e6e9675e24221a;hp=d683879aad2b80d9a219b4507b23cf8a6a8c1674;hpb=f44459818f34b556df8ff2f400098c50b78501eb;p=quassel.git diff --git a/src/common/types.h b/src/common/types.h index d683879a..5c800952 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,21 +18,18 @@ * 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 -// 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: @@ -110,6 +107,36 @@ Q_DECLARE_METATYPE(QHostAddress) typedef QList MsgIdList; typedef QList BufferIdList; +/** + * 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{}, int>::type = 0> +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[in] value Value to deserialize into + * @returns A reference to the stream + */ +template{}, int>::type = 0> +QDataStream &operator>>(QDataStream &in, T &value) { + typename std::underlying_type::type v; + in >> v; + value = static_cast(v); + return in; +} + //! Base class for exceptions. struct Exception { Exception(QString msg = "Unknown Exception") : _msg(msg) {} @@ -119,5 +146,3 @@ struct Exception { protected: QString _msg; }; - -#endif