diff options
author | celestar <celestar@openttd.org> | 2007-02-14 11:53:39 +0000 |
---|---|---|
committer | celestar <celestar@openttd.org> | 2007-02-14 11:53:39 +0000 |
commit | 59a814c6d321dcc53cc6d855501062ade8f035f7 (patch) | |
tree | 5cebc76c7639e1dcf5e6ca5716240cb6277da593 /src/macros.h | |
parent | 447b16930e7b03304ca72d0ec3dd240c7a44dc5d (diff) | |
download | openttd-59a814c6d321dcc53cc6d855501062ade8f035f7.tar.xz |
(svn r8732) -Codechange/Fix(r8705): Turned the bit-handling macros into template functions. Fixes a problem with MSVC and 64-bit shifts.
Diffstat (limited to 'src/macros.h')
-rw-r--r-- | src/macros.h | 27 |
1 files changed, 23 insertions, 4 deletions
diff --git a/src/macros.h b/src/macros.h index 2371804f9..56dc219e3 100644 --- a/src/macros.h +++ b/src/macros.h @@ -62,11 +62,30 @@ static inline int64 BIGMULS(int32 a, int32 b) { //#define IS_INSIDE_1D(x, base, size) ((x) >= (base) && (x) < (base) + (size)) #define IS_INSIDE_1D(x, base, size) ( (uint)((x) - (base)) < ((uint)(size)) ) +template <typename T> +static inline bool HASBIT(T x, int y) +{ + return (x & (((T)1) << y)) != 0; +} + +template <typename T> +static inline T SETBIT(T& x, int y) +{ + return x |= (((T)1) << y); +} + +template <typename T> +static inline T CLRBIT(T& x, int y) +{ + return x &= ~(((T)1) << y); +} + +template <typename T> +static inline T TOGGLEBIT(T& x, int y) +{ + return x ^= (((T)1) << y); +} -#define HASBIT(x,y) (((x) & (1 << (y))) != 0) -#define SETBIT(x,y) ((x) |= (1 << (y))) -#define CLRBIT(x,y) ((x) &= ~(1 << (y))) -#define TOGGLEBIT(x,y) ((x) ^= (1 << (y))) // checking more bits. Maybe unneccessary, but easy to use #define HASBITS(x,y) ((x) & (y)) |