C/C++ Library, mos@ua 1.0
cpplib-mos
utils

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).
 

Detailed Description

Useful macros.

Author
Miguel Oliveira e Silva
Date
2017, 2026
Version
1.0

Macro Definition Documentation

◆ concat_2str

#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.

Parameters
[in]str1[char*] string 1
[in]str2[char*] string 2
Returns
the concatenated string

◆ concat_3str

#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.

Parameters
[in]str1[char*] string 1
[in]str2[char*] string 2
[in]str3[char*] string 3
Returns
the concatenated string

◆ concat_4str

#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.

Parameters
[in]str1[char*] string 1
[in]str2[char*] string 2
[in]str3[char*] string 3
[in]str4[char*] string 4
Returns
the concatenated string

◆ concat_5str

#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.

Parameters
[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
Returns
the concatenated string

◆ concat_6str

#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.

Parameters
[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
Returns
the concatenated string

◆ concat_7str

#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.

Parameters
[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
Returns
the concatenated string

◆ concat_12str

#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.

Parameters
[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
Returns
the concatenated string

◆ numDigits

#define numDigits (   num)

Number of digits of an integer number (ignores signal!).

Parameters
[in]num[int] integer number
Returns
the number of digits

◆ int2str

#define int2str (   num)

Converts an int value to a stack allocated string (signal is considered).

Parameters
[in]num[int] integer number
Returns
the converted string

◆ int2nstr

#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.

Parameters
[in]num[int] integer number
[in]len[int] minimum length of result string
Precondition:
len > 0
Returns
the converted string

◆ long2str

#define long2str (   num)

Converts an long value to a stack allocated string (signal is considered).

Parameters
[in]num[long] integer number
Returns
the converted string

◆ long2nstr

#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.

Parameters
[in]num[long] integer number
[in]len[int] minimum length of result string
Precondition:
len > 0
Returns
the converted string

◆ perc2str

#define perc2str (   percentage)

Converts an int percentage to a stack allocated string.

Parameters
[in]percentage[int] an integer number with a percentage value
Precondition:
percentage >= 0 && percentage <= 100
Returns
the converted string

◆ random_boolean

#define random_boolean (   trueProb)

Generates a random boolean value.

This function generates boolean values with defined probabilities for true (!=0) and false (0) values.

Parameters
[in]trueProb[int] probability (in interval [0;100]).
Precondition:
trueProb >= 0 && trueProb <= 100
Returns
the random boolean value

◆ random_int

#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.

Parameters
[in]min[int] lower value of interval
[in]max[int] higher value of interval
Precondition:
max >= min
Returns
the random integer value

◆ clear_console

#define clear_console ( )

Clears the terminal.

This function clears the terminal.

◆ move_cursor

#define move_cursor (   line,
  column 
)

Moves the cursor to a position in terminal.

Parameters
[in]line[int] position in the terminal
[in]column[int] position in the terminal
Precondition:
line >= 0 && column >= 0

◆ hide_cursor

#define hide_cursor ( )

Hides the terminal cursor.

This function hides the cursor in the terminal.

◆ show_cursor

#define show_cursor ( )

Shows the terminal cursor.

This function shows the cursor in the terminal.