Go to most recent revision | Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
2 | mjames | 1 | #ifndef _UTIL_H_ |
2 | #define _UTIL_H_ |
||
3 | |||
4 | /*--------------------------------------------------------------------------------*/ |
||
5 | /* Macros and Defines */ |
||
6 | /*--------------------------------------------------------------------------------*/ |
||
7 | |||
8 | /** |
||
9 | * Convert a symbol to a string and add a 'NewLine'. |
||
10 | */ |
||
11 | #define STR_NL(x) STR1_NL(x) |
||
12 | #define STR1_NL(x) (STR2_NL(x)"\n") |
||
13 | #define STR2_NL(x) #x |
||
14 | |||
15 | /** |
||
16 | * Convert a symbol to a string. |
||
17 | */ |
||
18 | #define STR(x) STR1(x) |
||
19 | #define STR1(x) STR2(x) |
||
20 | #define STR2(x) #x |
||
21 | |||
22 | /** |
||
23 | * Concatenate two symbols. |
||
24 | */ |
||
25 | #define CONCAT(a, b) CONCAT1(a, b) |
||
26 | #define CONCAT1(a, b) CONCAT2(a, b) |
||
27 | #define CONCAT2(a, b) a##b |
||
28 | |||
29 | |||
30 | /** |
||
31 | * Place curly braces around a varaible number of macro arguments. |
||
32 | */ |
||
33 | #define CURLY(...) {__VA_ARGS__} |
||
34 | |||
35 | /** |
||
36 | * Place parenthesis around a variable number of macro arguments. |
||
37 | */ |
||
38 | #define PAREN(...) (__VA_ARGS__) |
||
39 | |||
40 | /* Standard min/max macros. */ |
||
41 | #define MIN(x,y) (((x) < (y)) ? (x) : (y) ) |
||
42 | #define MAX(x,y) (((x) > (y)) ? (x) : (y) ) |
||
43 | |||
44 | /** |
||
45 | * Bound value using low and high limits. |
||
46 | * |
||
47 | * Evaluate to a number in the range, endpoint inclusive. |
||
48 | */ |
||
49 | #define BOUND(low, high, value) \ |
||
50 | MAX(MIN(high, value), low) |
||
51 | |||
52 | #endif /* _UTIL_H_ */ |