Changeset - r7827:c754de5e3818
[Not reviewed]
master
0 1 0
truelight - 17 years ago 2007-11-04 17:43:53
truelight@openttd.org
(svn r11377) -Codechange: some more strictness in macros.h (skidd13)
1 file changed with 8 insertions and 10 deletions:
0 comments (0 inline, 0 general)
src/macros.h
Show inline comments
 
@@ -98,41 +98,39 @@ template<typename T> static inline T min
 

	
 
/**
 
 * Returns the minimum of two integer.
 
 *
 
 * This function returns the smaller value of two given integers.
 
 *
 
 * @param a The first integer
 
 * @param b The second integer
 
 * @return The smaller value
 
 */
 
static inline int min(const int a, const int b)
 
{
 
	if (a <= b) return a;
 
	return b;
 
	return a <= b ? a : b;
 
}
 

	
 
/**
 
 * Returns the minimum of two unsigned integers.
 
 *
 
 * This function returns the smaller value of two given unsigned integers.
 
 *
 
 * @param a The first unsigned integer
 
 * @param b The second unsigned integer
 
 * @return The smaller value
 
 */
 
static inline uint minu(const uint a, const uint b)
 
{
 
	if (a <= b) return a;
 
	return b;
 
	return a <= b ? a : b;
 
}
 

	
 
/**
 
 * Clamp an integer between an interval.
 
 *
 
 * This function returns a value which is between the given interval of
 
 * min and max. If the given value is in this interval the value itself
 
 * is returned otherwise the border of the interval is returned, according
 
 * which side of the interval was 'left'.
 
 *
 
 * @note The min value must be less or equal of max or you get some
 
 *       unexpected results.
 
@@ -195,41 +193,41 @@ static inline int32 ClampToI32(const int
 

	
 
/**
 
 * Multiply two integer values and shift the results to right.
 
 *
 
 * This function multiplies two integer values. The result is
 
 * shifted by the amount of shift to right.
 
 *
 
 * @param a The first integer
 
 * @param b The second integer
 
 * @param shift The amount to shift the value to right.
 
 * @return The shifted result
 
 */
 
static inline int32 BIGMULSS(const int32 a, const int32 b, const int8 shift)
 
static inline int32 BIGMULSS(const int32 a, const int32 b, const uint8 shift)
 
{
 
	return (int32)((int64)a * (int64)b >> shift);
 
}
 

	
 
/**
 
 * Multiply two unsigned integers and shift the results to right.
 
 *
 
 * This function multiplies two unsigned integers. The result is
 
 * shifted by the amount of shift to right.
 
 *
 
 * @param a The first unsigned integer
 
 * @param b The second unsigned integer
 
 * @param shift The amount to shift the value to right.
 
 * @return The shifted result
 
 */
 
static inline uint32 BIGMULUS(const uint32 a, const uint32 b, const int8 shift)
 
static inline uint32 BIGMULUS(const uint32 a, const uint32 b, const uint8 shift)
 
{
 
	return (uint32)((uint64)a * (uint64)b >> shift);
 
}
 

	
 

	
 
/**
 
 * Checks if a value is between a window started at some base point.
 
 *
 
 * This macro checks if the value x is between the value of base
 
 * and base+size. If x equals base this returns true. If x equals
 
 * base+size this returns false.
 
 *
 
@@ -244,73 +242,73 @@ static inline uint32 BIGMULUS(const uint
 

	
 
/**
 
 * Checks if a bit in a value is set.
 
 *
 
 * This function checks if a bit inside a value is set or not.
 
 * The y value specific the position of the bit, started at the
 
 * LSB and count from 0.
 
 *
 
 * @param x The value to check
 
 * @param y The position of the bit to check, started from the LSB
 
 * @return True if the bit is set, false else.
 
 */
 
template<typename T> static inline bool HASBIT(const T x, const int8 y)
 
template<typename T> static inline bool HASBIT(const T x, const uint8 y)
 
{
 
	return (x & ((T)1U << y)) != 0;
 
}
 

	
 
/**
 
 * Set a bit in a variable.
 
 *
 
 * This function sets a bit in a variable. The variable is changed
 
 * and the value is also returned. Parameter y defines the bit and
 
 * starts at the LSB with 0.
 
 *
 
 * @param x The variable to set a bit
 
 * @param y The bit position to set
 
 * @return The new value of the old value with the bit set
 
 */
 
template<typename T> static inline T SETBIT(T& x, const int8 y)
 
template<typename T> static inline T SETBIT(T& x, const uint8 y)
 
{
 
	return x |= (T)1U << y;
 
}
 

	
 
/**
 
 * Clears a bit in a variable.
 
 *
 
 * This function clears a bit in a variable. The variable is
 
 * changed and the value is also returned. Parameter y defines the bit
 
 * to clear and starts at the LSB with 0.
 
 *
 
 * @param x The variable to clear the bit
 
 * @param y The bit position to clear
 
 * @return The new value of the old value with the bit cleared
 
 */
 
template<typename T> static inline T CLRBIT(T& x, const int8 y)
 
template<typename T> static inline T CLRBIT(T& x, const uint8 y)
 
{
 
	return x &= ~((T)1U << y);
 
}
 

	
 
/**
 
 * Toggles a bit in a variable.
 
 *
 
 * This function toggles a bit in a variable. The variable is
 
 * changed and the value is also returned. Parameter y defines the bit
 
 * to toggle and starts at the LSB with 0.
 
 *
 
 * @param x The varliable to toggle the bit
 
 * @param y The bit position to toggle
 
 * @return The new value of the old value with the bit toggled
 
 */
 
template<typename T> static inline T TOGGLEBIT(T& x, const int8 y)
 
template<typename T> static inline T TOGGLEBIT(T& x, const uint8 y)
 
{
 
	return x ^= (T)1U << y;
 
}
 

	
 

	
 
/* checking more bits. Maybe unneccessary, but easy to use */
 
/**
 
 * Check several bits in a value.
 
 *
 
 * This macro checks if a value contains at least one bit of an other
 
 * value.
 
 *
0 comments (0 inline, 0 general)