diff options
author | Kitsune Ral <Kitsune-Ral@users.sf.net> | 2018-03-26 11:43:00 +0900 |
---|---|---|
committer | Kitsune Ral <Kitsune-Ral@users.sf.net> | 2018-03-26 11:43:00 +0900 |
commit | e7e9330d665c1d8d2391707d27019a7f454cbcdf (patch) | |
tree | ed33b8a454bb14fcc4bc0d26d81c2d5f1618955b /joinstate.h | |
parent | 7a2e843dde6b78aabab05811d3f481176537098e (diff) | |
download | libquotient-e7e9330d665c1d8d2391707d27019a7f454cbcdf.tar.gz libquotient-e7e9330d665c1d8d2391707d27019a7f454cbcdf.zip |
Introduce JoinStates (QFlags<JoinState>)
This required to change numeric values for JoinState enum; so anybody
who relied on them being 0-based and/or contiguous, beware.
Diffstat (limited to 'joinstate.h')
-rw-r--r-- | joinstate.h | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/joinstate.h b/joinstate.h index d6c374d2..42613895 100644 --- a/joinstate.h +++ b/joinstate.h @@ -18,17 +18,21 @@ #pragma once +#include <QtCore/QFlags> + #include <array> namespace QMatrixClient { enum class JoinState { - Join = 0, - Invite, - Leave + Join = 0x1, + Invite = 0x2, + Leave = 0x4 }; + Q_DECLARE_FLAGS(JoinStates, JoinState) + // We cannot use REGISTER_ENUM outside of a Q_OBJECT and besides, we want // to use strings that match respective JSON keys. static const std::array<const char*, 3> JoinStateStrings @@ -36,6 +40,9 @@ namespace QMatrixClient inline const char* toCString(JoinState js) { - return JoinStateStrings[size_t(js)]; + size_t state = size_t(js), index = 0; + while (state >>= 1) ++index; + return JoinStateStrings[index]; } } // namespace QMatrixClient +Q_DECLARE_OPERATORS_FOR_FLAGS(QMatrixClient::JoinStates) |