[RFC] Enum improvements
Yuriy Skalko
yuriy.skalko at gmail.com
Sun Nov 29 08:33:28 UTC 2020
>> The first bit, involving headers, looks most useful.
>
>
> I agree that the first one is the most promising.
Sure. But as it turns out C++ disallows forward declarations for
in-class enums. So these should be moved out of classes (and most common
ones maybe placed into separate headers).
> Another thing to look at: we have plenty of enums used a bitfields where we have defined special operators (some are mine) I only realized recently that it does not make sense. A good example is KeyModifier. I suspect that we should use 'int' instead of casting back to the original enum type. There are complex tamplate-based solutions to this, but I am not sure they are worth the hassle.
>
>
> JMarc
Like in attached patch? I think `unsigned` instead of `int` will be
better for bit fiddling.
Yuriy
-------------- next part --------------
From 41ec9e10bcd1df00fec1b317d50b8333aac85cdc Mon Sep 17 00:00:00 2001
From: Yuriy Skalko <yuriy.skalko at gmail.com>
Date: Sun, 29 Nov 2020 10:19:58 +0200
Subject: [PATCH] Simplify KeyModifier
---
src/frontends/KeyModifier.h | 31 +++++++++----------------------
1 file changed, 9 insertions(+), 22 deletions(-)
diff --git a/src/frontends/KeyModifier.h b/src/frontends/KeyModifier.h
index fba80bec2a..bdae991e63 100644
--- a/src/frontends/KeyModifier.h
+++ b/src/frontends/KeyModifier.h
@@ -16,31 +16,18 @@
namespace lyx {
-/// modifier key states
+/// Set of KeyModifierFlags
+typedef unsigned KeyModifier;
-enum KeyModifier {
- NoModifier = 0, //< no modifiers held
- ControlModifier = 1, //< control button held
- AltModifier = 2, //< alt key held
- ShiftModifier = 4, //< shift key held
- MetaModifier = 8 //< meta key held
+/// modifier key states
+enum KeyModifierFlags : unsigned {
+ NoModifier = 0, //< no modifiers held
+ ControlModifier = 1 << 0, //< control button held
+ AltModifier = 1 << 1, //< alt key held
+ ShiftModifier = 1 << 2, //< shift key held
+ MetaModifier = 1 << 3 //< meta key held
};
-
-inline KeyModifier operator|(KeyModifier s1, KeyModifier s2)
-{
- int const i1 = static_cast<int>(s1);
- int const i2 = static_cast<int>(s2);
- return static_cast<KeyModifier>(i1 | i2);
-}
-
-
-inline void operator|=(KeyModifier & s1, KeyModifier s2)
-{
- s1 = static_cast<KeyModifier>(s1 | s2);
-}
-
-
} // namespace lyx
#endif // KEYMODIFIER_H
--
2.28.0.windows.1
More information about the lyx-devel
mailing list