summaryrefslogtreecommitdiff
path: root/src/core/bitmath_func.hpp
diff options
context:
space:
mode:
authorrubidium <rubidium@openttd.org>2007-12-21 19:21:21 +0000
committerrubidium <rubidium@openttd.org>2007-12-21 19:21:21 +0000
commit01e20c91403ebe8c88697ec11812fb46d414c770 (patch)
treefc1669fb9cd1857bea972a4378d8ebd1e80facfa /src/core/bitmath_func.hpp
parentd5c4ba8246fbd9b44469037d8224a94c0a5ce5d3 (diff)
downloadopenttd-01e20c91403ebe8c88697ec11812fb46d414c770.tar.xz
(svn r11674) -Codechange: refactor some functions out of macros.h into more logical locations.
Diffstat (limited to 'src/core/bitmath_func.hpp')
-rw-r--r--src/core/bitmath_func.hpp15
1 files changed, 15 insertions, 0 deletions
diff --git a/src/core/bitmath_func.hpp b/src/core/bitmath_func.hpp
index 357a52212..6f9c35806 100644
--- a/src/core/bitmath_func.hpp
+++ b/src/core/bitmath_func.hpp
@@ -276,4 +276,19 @@ template<typename T> static inline T ROR(const T x, const uint8 n)
return (T)(x >> n | x << (sizeof(x) * 8 - n));
}
+/**
+ * Do an operation for each set set bit in a value.
+ *
+ * This macros is used to do an operation for each set
+ * bit in a variable. The first variable can be reused
+ * in the operation due to it's the bit position counter.
+ * The second variable will be cleared during the usage
+ *
+ * @param i The position counter
+ * @param b The value which we check for set bits
+ */
+#define FOR_EACH_SET_BIT(i, b) \
+ for (i = 0; b != 0; i++, b >>= 1) \
+ if (b & 1)
+
#endif /* BITMATH_FUNC_HPP */