37 lines
1.0 KiB
Diff
37 lines
1.0 KiB
Diff
From a31e52ce77a53313ade55af5a1674cd3fa4c05a8 Mon Sep 17 00:00:00 2001
|
|
From: Juanjo <juanjo.ng.83@gmail.com>
|
|
Date: Tue, 18 Jun 2013 16:32:04 +0200
|
|
Subject: [PATCH 214/249] Add functions for cycling inside an enum.
|
|
|
|
---
|
|
src/core/enum_type.hpp | 13 +++++++++++++
|
|
1 file changed, 13 insertions(+)
|
|
|
|
diff --git a/src/core/enum_type.hpp b/src/core/enum_type.hpp
|
|
index 35a0cb2..b5a12c4 100644
|
|
--- a/src/core/enum_type.hpp
|
|
+++ b/src/core/enum_type.hpp
|
|
@@ -28,6 +28,19 @@
|
|
}
|
|
|
|
|
|
+/** Some enums need to have cycling through values */
|
|
+#define DECLARE_CYCLE(type, min_val, max_val) \
|
|
+ inline type CycleUp(type e) \
|
|
+ { \
|
|
+ assert(!((int)e < min_val || (int)e > max_val)); \
|
|
+ return e == max_val ? (type)min_val : (type)((int)e + 1); \
|
|
+ } \
|
|
+ inline type CycleDown(type e) \
|
|
+ { \
|
|
+ assert(!((int)e < min_val || (int)e > max_val)); \
|
|
+ return e == min_val ? (type)max_val : (type)((int)e - 1); \
|
|
+ }
|
|
+
|
|
|
|
/** Operators to allow to work with enum as with type safe bit set in C++ */
|
|
# define DECLARE_ENUM_AS_BIT_SET(mask_t) \
|
|
--
|
|
1.8.1.2
|
|
|