|
C/C++ Library, mos@ua 1.0
cpplib-mos
|
Useful macros. More...
Files | |
| file | utils.h |
| Useful common functions and macros. | |
Macros | |
| #define | numDigits(num) |
| Number of digits of an integer number (ignores signal!). | |
| #define | int2str(num) |
Converts an int value to a stack allocated string (signal is considered). | |
| #define | int2nstr(num, len) |
Converts an int value to a stack allocated string (signal is considered). | |
| #define | long2str(num) |
Converts an long value to a stack allocated string (signal is considered). | |
| #define | long2nstr(num, len) |
Converts an long value to a stack allocated string (signal is considered). | |
| #define | perc2str(percentage) |
Converts an int percentage to a stack allocated string. | |
| #define | random_boolean(trueProb) |
| Generates a random boolean value. | |
| #define | random_int(min, max) |
| Generates a random integer value within a given interval. | |
| #define | clear_console() |
| Clears the terminal. | |
| #define | move_cursor(line, column) |
| Moves the cursor to a position in terminal. | |
| #define | hide_cursor() |
| Hides the terminal cursor. | |
| #define | show_cursor() |
| Shows the terminal cursor. | |
String concatenation in stack memory (useful to compose contract error messages) | |
| #define | concat_2str(str1, str2) |
| Concatenates two strings in the stack memory (thus it cannot be implemented in a function). | |
| #define | concat_3str(str1, str2, str3) |
| Concatenates three strings in the stack memory (thus it cannot be implemented in a function). | |
| #define | concat_4str(str1, str2, str3, str4) |
| Concatenates four strings in the stack memory (thus it cannot be implemented in a function). | |
| #define | concat_5str(str1, str2, str3, str4, str5) |
| Concatenates five strings in the stack memory (thus it cannot be implemented in a function). | |
| #define | concat_6str(str1, str2, str3, str4, str5, str6) |
| Concatenates six strings in the stack memory (thus it cannot be implemented in a function). | |
| #define | concat_7str(str1, str2, str3, str4, str5, str6, str7) |
| Concatenates seven strings in the stack memory (thus it cannot be implemented in a function). | |
| #define | concat_12str(str1, str2, str3, str4, str5, str6, str7, str8, str9, str10, str11, str12) |
| Concatenates twelve strings in the stack memory (thus it cannot be implemented in a function). | |
Useful macros.
| #define concat_2str | ( | str1, | |
| str2 | |||
| ) |
Concatenates two strings in the stack memory (thus it cannot be implemented in a function).
A NULL reference is treated as an empty string.
| [in] | str1 | [char*] string 1 |
| [in] | str2 | [char*] string 2 |
| #define concat_3str | ( | str1, | |
| str2, | |||
| str3 | |||
| ) |
Concatenates three strings in the stack memory (thus it cannot be implemented in a function).
A NULL reference is treated as an empty string.
| [in] | str1 | [char*] string 1 |
| [in] | str2 | [char*] string 2 |
| [in] | str3 | [char*] string 3 |
| #define concat_4str | ( | str1, | |
| str2, | |||
| str3, | |||
| str4 | |||
| ) |
Concatenates four strings in the stack memory (thus it cannot be implemented in a function).
A NULL reference is treated as an empty string.
| [in] | str1 | [char*] string 1 |
| [in] | str2 | [char*] string 2 |
| [in] | str3 | [char*] string 3 |
| [in] | str4 | [char*] string 4 |
| #define concat_5str | ( | str1, | |
| str2, | |||
| str3, | |||
| str4, | |||
| str5 | |||
| ) |
Concatenates five strings in the stack memory (thus it cannot be implemented in a function).
A NULL reference is treated as an empty string.
| [in] | str1 | [char*] string 1 |
| [in] | str2 | [char*] string 2 |
| [in] | str3 | [char*] string 3 |
| [in] | str4 | [char*] string 4 |
| [in] | str5 | [char*] string 5 |
| #define concat_6str | ( | str1, | |
| str2, | |||
| str3, | |||
| str4, | |||
| str5, | |||
| str6 | |||
| ) |
Concatenates six strings in the stack memory (thus it cannot be implemented in a function).
A NULL reference is treated as an empty string.
| [in] | str1 | [char*] string 1 |
| [in] | str2 | [char*] string 2 |
| [in] | str3 | [char*] string 3 |
| [in] | str4 | [char*] string 4 |
| [in] | str5 | [char*] string 5 |
| [in] | str6 | [char*] string 6 |
| #define concat_7str | ( | str1, | |
| str2, | |||
| str3, | |||
| str4, | |||
| str5, | |||
| str6, | |||
| str7 | |||
| ) |
Concatenates seven strings in the stack memory (thus it cannot be implemented in a function).
A NULL reference is treated as an empty string.
| [in] | str1 | [char*] string 1 |
| [in] | str2 | [char*] string 2 |
| [in] | str3 | [char*] string 3 |
| [in] | str4 | [char*] string 4 |
| [in] | str5 | [char*] string 5 |
| [in] | str6 | [char*] string 6 |
| [in] | str7 | [char*] string 7 |
| #define concat_12str | ( | str1, | |
| str2, | |||
| str3, | |||
| str4, | |||
| str5, | |||
| str6, | |||
| str7, | |||
| str8, | |||
| str9, | |||
| str10, | |||
| str11, | |||
| str12 | |||
| ) |
Concatenates twelve strings in the stack memory (thus it cannot be implemented in a function).
A NULL reference is treated as an empty string.
| [in] | str1 | [char*] string 1 |
| [in] | str2 | [char*] string 2 |
| [in] | str3 | [char*] string 3 |
| [in] | str4 | [char*] string 4 |
| [in] | str5 | [char*] string 5 |
| [in] | str6 | [char*] string 6 |
| [in] | str7 | [char*] string 7 |
| [in] | str8 | [char*] string 8 |
| [in] | str9 | [char*] string 9 |
| [in] | str10 | [char*] string 10 |
| [in] | str11 | [char*] string 11 |
| [in] | str12 | [char*] string 12 |
| #define numDigits | ( | num | ) |
Number of digits of an integer number (ignores signal!).
| [in] | num | [int] integer number |
| #define int2str | ( | num | ) |
Converts an int value to a stack allocated string (signal is considered).
| [in] | num | [int] integer number |
| #define int2nstr | ( | num, | |
| len | |||
| ) |
Converts an int value to a stack allocated string (signal is considered).
If necessary, fills the result string with left zeros.
| [in] | num | [int] integer number |
| [in] | len | [int] minimum length of result string |
len > 0 | #define long2str | ( | num | ) |
Converts an long value to a stack allocated string (signal is considered).
| [in] | num | [long] integer number |
| #define long2nstr | ( | num, | |
| len | |||
| ) |
Converts an long value to a stack allocated string (signal is considered).
If necessary, fills the result string with left zeros.
| [in] | num | [long] integer number |
| [in] | len | [int] minimum length of result string |
len > 0 | #define perc2str | ( | percentage | ) |
Converts an int percentage to a stack allocated string.
| [in] | percentage | [int] an integer number with a percentage value |
percentage >= 0 && percentage <= 100 | #define random_boolean | ( | trueProb | ) |
Generates a random boolean value.
This function generates boolean values with defined probabilities for true (!=0) and false (0) values.
| [in] | trueProb | [int] probability (in interval [0;100]). |
trueProb >= 0 && trueProb <= 100 | #define random_int | ( | min, | |
| max | |||
| ) |
Generates a random integer value within a given interval.
This function generates integer values in the interval [min;max]with an uniform distribution for all values.
| [in] | min | [int] lower value of interval |
| [in] | max | [int] higher value of interval |
max >= min | #define clear_console | ( | ) |
Clears the terminal.
This function clears the terminal.
| #define move_cursor | ( | line, | |
| column | |||
| ) |
Moves the cursor to a position in terminal.
| [in] | line | [int] position in the terminal |
| [in] | column | [int] position in the terminal |
line >= 0 && column >= 0 | #define hide_cursor | ( | ) |
Hides the terminal cursor.
This function hides the cursor in the terminal.
| #define show_cursor | ( | ) |
Shows the terminal cursor.
This function shows the cursor in the terminal.