5 #ifndef BALL_COMMON_MACROS_H 6 #define BALL_COMMON_MACROS_H 8 #include <BALL/CONFIG/config.h> 22 std::this_thread::sleep_for(std::chrono::milliseconds(ms));
34 return a > b ? (a > c ? a :
c) : (b > c ? b : c);
46 return a < b ? (a < c ? a :
c) : (b < c ? b : c);
52 return x >= 0 ? x : -x;
58 return (x < 0 ? -1 : (x == 0) ? 0 : 1);
70 return (x & 0x1) == 1;
76 return (x & 0x1) == 0;
82 return (X)(x > 0 ? long(x + 0.5) : long(x - 0.5));
85 template<
class X,
class Y,
class E>
88 return std::fabs(x - y) <= e;
91 template<
class X,
class Y,
class E>
94 return std::fabs(x - y) > e;
97 template<
class X,
class Y,
class E>
103 template<
class X,
class Y,
class E>
109 template<
class X,
class Y,
class E>
115 template<
class X,
class Y,
class E>
118 return (x - y) >= -e;
130 return fmod(x, 2) != 0;
136 return fmod(x, 2) == 0;
142 return (
long)(x > 0 ? x : (x == (long)(x) ? x : x - 1));
148 return (
long)(x < 0 ? x : (x == (long)(x) ? x : x + 1));
154 return (x > 0 ? (
int)(x + 0.5) : -(
int)(0.5 - x));
160 return T(BALL_CHAR_SIZE * 8);
166 return T(BALL_CHAR_SIZE * 8) - 1;
172 unsigned bits = BALL_CHAR_SIZE * 8;
173 return T(bits == 8 ? 3 : (bits == 16) ? 4 : 5);
191 unsigned bits = BALL_CHAR_SIZE * 8;
192 unsigned shift = (bits == 8 ? 3u : (bits == 16) ? 4u : 5u);
193 return (x + bits - 1) >> shift;
196 template<
class T, std::
size_t N>
205 unsigned bits = BALL_CHAR_SIZE * 8;
206 unsigned shift = (bits == 8 ? 3u : (bits == 16) ? 4u : 5u);
207 return ((x - 1) >> shift) + 1;
210 template<
class BitArray,
class X>
213 unsigned bits = BALL_CHAR_SIZE * 8;
214 unsigned shift = (bits == 8 ? 3u : (bits == 16) ? 4u : 5u);
215 a[x >> shift] &= ~(1 << (x & (bits - 1)));
218 template<
class BitArray,
class X>
221 unsigned bits = BALL_CHAR_SIZE * 8;
222 unsigned shift = (bits == 8 ? 3u : (bits == 16) ? 4u : 5u);
223 a[x >> shift] |= (1 << (x & (bits - 1)));
226 template<
class BitArray,
class X>
229 unsigned bits = BALL_CHAR_SIZE * 8;
230 unsigned shift = (bits == 8 ? 3u : (bits == 16) ? 4u : 5u);
231 a[x >> shift] ^= (1 << (x & (bits - 1)));
234 template<
class BitArray,
class X>
237 unsigned bits = BALL_CHAR_SIZE * 8;
238 unsigned shift = (bits == 8 ? 3u : (bits == 16) ? 4u : 5u);
239 return (a[x >> shift] & (1 << (x & (bits - 1)))) != 0;
248 template<
class Bitset,
class Bit>
251 bitset |= (1 << bit);
254 template<
class Bitset>
260 template<
class Bitset,
class Bit>
263 bitset |= ~(-1 << (bit + 1));
266 template<
class Bitset,
class Bit>
269 bitset |= (-1 << bit);
272 template<
class Bitset,
class Bit>
275 bitset &= ~(1 << bit);
278 template<
class Bitset>
284 template<
class Bitset,
class Bit>
287 bitset &= (-1 << (bit + 1));
290 template<
class Bitset,
class Bit>
293 bitset &= ~(-1 << bit);
296 template<
class Bitset,
class Bit>
299 return bitset & (1 << bit);
302 template<
class Bitset,
class Bit>
305 return !(bitset & (1 << bit));
328 #define BALL_SLEEPFOR(x) BALL::ball_macro_sleepfor(x) 330 #define BALL_MAX(a, b) BALL::ball_macro_max(a, b) 331 #define BALL_MAX3(x, y, z) BALL::ball_macro_max3(x, y, z) 332 #define BALL_MIN(a, b) BALL::ball_macro_min(a, b) 333 #define BALL_MIN3(x, y, z) BALL::ball_macro_min3(x, y ,z) 334 #define BALL_ABS(x) BALL::ball_macro_abs(x) 335 #define BALL_SGN(x) BALL::ball_macro_sgn(x) 336 #define BALL_ODD(x) BALL::ball_macro_odd(x) 338 #define BALL_INT_ODD(x) BALL::ball_macro_int_odd(x) 339 #define BALL_INT_EVEN(x) BALL::ball_macro_int_even(x) 341 #define BALL_REAL_ROUND(x) BALL::ball_macro_real_round(x) 342 #define BALL_REAL_EQUAL(x, y, e) BALL::ball_macro_real_equal(x, y, e) 343 #define BALL_REAL_NOT_EQUAL(x, y, e) BALL::ball_macro_real_not_equal(x, y, e) 344 #define BALL_REAL_LESS(x, y, e) BALL::ball_macro_real_less(x, y, e) 345 #define BALL_REAL_LESS_OR_EQUAL(x, y, e) BALL::ball_macro_real_less_or_equal(x, y, e) 346 #define BALL_REAL_GREATER(x, y, e) BALL::ball_macro_real_greater(x, y, e) 347 #define BALL_REAL_GREATER_OR_EQUAL(x, y, e) BALL::ball_macro_real_greater_or_equal(x, y, e) 348 #define BALL_REAL_ABS(x) BALL::ball_macro_real_abs(x) 349 #define BALL_REAL_SGN(x) BALL::ball_macro_sgn(x) 350 #define BALL_REAL_ODD(x) BALL::ball_macro_real_odd(x) 351 #define BALL_REAL_EVEN(x) BALL::ball_macro_real_even(x) 352 #define BALL_REAL_FLOOR(x) BALL::ball_macro_real_floor(x) 353 #define BALL_REAL_CEILING(x) BALL::ball_macro_real_ceiling(x) 354 #define BALL_REAL_ROUND_INT(x) BALL::ball_macro_real_round_int(x) 358 #define BALL_CHAR_BITS BALL::ball_macro_char_bits<unsigned>() 359 #define BALL_CHAR_MASK BALL::ball_macro_char_mask<unsigned>() 360 #define BALL_CHAR_SHIFT BALL::ball_macro_char_shift<unsigned>() 361 #define BALL_CHAR_ALL_BITS_SET BALL::ball_macro_all_bits_set<char>() 362 #define BALL_CHAR_ALL_BITS_CLEARED BALL::ball_macro_all_bits_cleared<char>() 363 #define BALL_NUMBER_OF_BYTES(bits) BALL::ball_macro_number_of_bytes(bits) 365 #define BALL_SIZEOF_ARRAY(a) BALL::ball_macro_sizeof_array(a) 367 #define BALL_BITARRAY_SIZE(number_of_bits) BALL::ball_macro_bitarray_size(number_of_bits) 368 #define BALL_BITARRAY_CLEAR_BIT(array, x) BALL::ball_macro_bitarray_clear_bit(array, x) 369 #define BALL_BITARRAY_SET_BIT(array, x) BALL::ball_macro_bitarray_set_bit(array, x) 370 #define BALL_BITARRAY_TOGGLE_BIT(array, x) BALL::ball_macro_bitarray_toggle_bit(array, x) 371 #define BALL_BITARRAY_IS_BIT_SET(array, x) BALL::ball_macro_bitarray_is_bit_set(array, x) 373 #define BALL_BIT(bit) BALL::ball_macro_bit(bit) 374 #define BALL_BIT_SET(bitset, bit) BALL::ball_macro_bit_set(bitset, bit) 375 #define BALL_BIT_SET_ALL(bitset) BALL::ball_macro_bit_set_all(bitset) 376 #define BALL_BIT_SET_ALL_TO(bitset, bit) BALL::ball_macro_bit_set_all_to(bitset, bit) 377 #define BALL_BIT_SET_ALL_FROM(bitset, bit) BALL::ball_macro_bit_set_all_from(bitset, bit) 378 #define BALL_BIT_CLEAR(bitset, bit) BALL::ball_macro_bit_clear(bitset, bit) 379 #define BALL_BIT_CLEAR_ALL(bitset) BALL::ball_macro_bit_clear_all(bitset) 380 #define BALL_BIT_CLEAR_ALL_TO(bitset, bit) BALL::ball_macro_bit_clear_all_to(bitset, bit) 381 #define BALL_BIT_CLEAR_ALL_FROM(bitset, bit) BALL::ball_macro_bit_clear_all_from(bitset, bit) 382 #define BALL_BIT_IS_SET(bitset, bit) BALL::ball_macro_bit_is_set(bitset, bit) 383 #define BALL_BIT_IS_CLEARED(bitset, bit) BALL::ball_macro_bit_is_cleared(bitset, bit) 385 #define BALL_ANGLE_RADIAN_TO_DEGREE(rad_angle) BALL::ball_macro_angle_radian_to_degree(rad_angle) 386 #define BALL_ANGLE_DEGREE_TO_RADIAN(deg_angle) BALL::ball_macro_angle_degree_to_radian(deg_angle) 388 #define BALL_OFFSET_OF(struct_name, struct_var_name) BALL::ball_macro_generic_echo((long)&(((struct_name*)0)->struct_var_name)) 390 #define BALL_DUMP_DEPTH(os, depth) for (dump_indent_depth_ = 0; dump_indent_depth_ < depth; ++dump_indent_depth_) { os << " "; } 391 #define BALL_DUMP_STREAM_PREFIX(os) Size dump_indent_depth_ = 0; 393 #define BALL_DUMP_HEADER(os,cl,ob) os << "Object: " << (void *)ob << " is instance of class: " << streamClassName(typeid(*ob)) << std::endl; 394 #define BALL_DUMP_CLASS_HEADER(os,cl,ob) os << "Object: " << (void *)ob << " is instance of class: " << #cl << ::std::endl; 395 #define BALL_DUMP_STREAM_SUFFIX(os) 397 #endif // BALL_COMMON_MACROS_H bool BALL_DEPRECATED BALL_INLINE ball_macro_odd(X x)
T BALL_DEPRECATED BALL_INLINE ball_macro_all_bits_cleared()
void BALL_DEPRECATED BALL_INLINE ball_macro_sleepfor(T ms)
T BALL_DEPRECATED BALL_INLINE ball_macro_bitarray_size(T x)
void BALL_DEPRECATED BALL_INLINE ball_macro_bit_clear_all_from(Bitset &bitset, Bit bit)
bool BALL_DEPRECATED BALL_INLINE ball_macro_real_equal(X x, Y y, E e)
T BALL_DEPRECATED BALL_INLINE ball_macro_min3(T a, T b, T c)
long BALL_DEPRECATED BALL_INLINE ball_macro_real_ceiling(X x)
bool BALL_DEPRECATED BALL_INLINE ball_macro_real_not_equal(X x, Y y, E e)
bool BALL_DEPRECATED BALL_INLINE ball_macro_int_odd(X x)
T BALL_DEPRECATED BALL_INLINE ball_macro_char_shift()
bool BALL_DEPRECATED BALL_INLINE ball_macro_real_odd(X x)
T BALL_DEPRECATED BALL_INLINE ball_macro_char_mask()
void BALL_DEPRECATED BALL_INLINE ball_macro_bit_set_all_to(Bitset &bitset, Bit bit)
void BALL_DEPRECATED BALL_INLINE ball_macro_bitarray_toggle_bit(BitArray *a, X x)
void BALL_DEPRECATED BALL_INLINE ball_macro_bit_set_all_from(Bitset &bitset, Bit bit)
BALL_EXTERN_VARIABLE const double E
Euler's number - base of the natural logarithm.
BALL_EXTERN_VARIABLE const double c
bool BALL_DEPRECATED BALL_INLINE ball_macro_real_greater(X x, Y y, E e)
T BALL_DEPRECATED BALL_INLINE ball_macro_char_bits()
void BALL_DEPRECATED BALL_INLINE ball_macro_bit_clear_all_to(Bitset &bitset, Bit bit)
T BALL_DEPRECATED BALL_INLINE ball_macro_number_of_bytes(T x)
T BALL_DEPRECATED BALL_INLINE ball_macro_generic_echo(T value)
bool BALL_DEPRECATED BALL_INLINE ball_macro_real_less_or_equal(X x, Y y, E e)
T BALL_DEPRECATED BALL_INLINE ball_macro_all_bits_set()
int BALL_DEPRECATED BALL_INLINE ball_macro_sgn(X x)
bool BALL_DEPRECATED BALL_INLINE ball_macro_real_greater_or_equal(X x, Y y, E e)
bool BALL_DEPRECATED BALL_INLINE ball_macro_bitarray_is_bit_set(BitArray *a, X x)
T BALL_DEPRECATED BALL_INLINE ball_macro_angle_degree_to_radian(T deg_angle)
T BALL_DEPRECATED BALL_INLINE ball_macro_max(T a, T b)
BALL_EXTERN_VARIABLE const double PI
PI.
bool BALL_DEPRECATED BALL_INLINE ball_macro_bit_is_cleared(Bitset &bitset, Bit bit)
long BALL_DEPRECATED BALL_INLINE ball_macro_real_floor(X x)
void BALL_DEPRECATED BALL_INLINE ball_macro_bitarray_clear_bit(BitArray *a, X x)
bool BALL_DEPRECATED BALL_INLINE ball_macro_int_even(X x)
bool BALL_DEPRECATED BALL_INLINE ball_macro_bit_is_set(Bitset &bitset, Bit bit)
void BALL_DEPRECATED BALL_INLINE ball_macro_bit_clear(Bitset &bitset, Bit bit)
X BALL_DEPRECATED BALL_INLINE ball_macro_real_abs(X x)
unsigned BALL_DEPRECATED BALL_INLINE ball_macro_bit(Bit bit)
T BALL_DEPRECATED BALL_INLINE ball_macro_max3(T a, T b, T c)
T BALL_DEPRECATED BALL_INLINE ball_macro_min(T a, T b)
void BALL_DEPRECATED BALL_INLINE ball_macro_bit_set(Bitset &bitset, Bit bit)
void BALL_DEPRECATED BALL_INLINE ball_macro_bitarray_set_bit(BitArray *a, X x)
T BALL_DEPRECATED BALL_INLINE ball_macro_angle_radians_to_degree(T rad_angle)
int BALL_DEPRECATED BALL_INLINE ball_macro_abs(X x)
int BALL_DEPRECATED BALL_INLINE ball_macro_real_round_int(X x)
void BALL_DEPRECATED BALL_INLINE ball_macro_bit_clear_all(Bitset &bitset)
std::size_t BALL_DEPRECATED BALL_INLINE ball_macro_sizeof_array(T(&)[N])
bool BALL_DEPRECATED BALL_INLINE ball_macro_real_less(X x, Y y, E e)
void BALL_DEPRECATED BALL_INLINE ball_macro_bit_set_all(Bitset &bitset)
bool BALL_DEPRECATED BALL_INLINE ball_macro_real_even(X x)
X BALL_DEPRECATED BALL_INLINE ball_macro_real_round(X x)