Robotran C Documentation
useful_functions.h
Go to the documentation of this file.
1 /*
2  * Main header of some useful functions
3  *
4  * authors: Nicolas Van der Noot & Aubain Verle
5  */
6 #ifndef _USEFUL_FUNCTIONS_H_
7 #define _USEFUL_FUNCTIONS_H_
8 
9 #ifdef __cplusplus
10 extern "C" {
11 #endif
12 
13 #define MIN(a,b) (((a)<(b))?(a):(b))
14 #define MAX(a,b) (((a)>(b))?(a):(b))
15 
16 #include <stdio.h>
17 #include <stdlib.h>
18 #include <string.h>
19 #include <math.h>
20 
21 #include "mbs_data.h"
22 #include "mbs_1D_array.h"
23 #include "mbs_matrix.h"
24 
25 #ifndef DBL_MAX
26 #define DBL_MAX 1.7976931348623158e+308
27 #endif
28 
33 void* mbs_free(void *__ptr);
34 
42 void mbs_log(char* msg, ...);
43 
44 
45 // exponents related functions
52 double pow_int(double basis, int expo);
53 
59 int expo_ten_inf(double nb);
60 
61 // sign function
67 double sign(double a);
68 
69 // time function
74 char* get_time_machine();
75 
76 // char related functions
82 char* get_char_vec(int l_v);
91 char** get_char_tab(int nb_r, int nb_c);
96 void free_char_vec(char *vec);
97 
107 char* get_char_cpy(const char *fmt, ...);
108 
122 int set_char_cpy(char **dest, const char *fmt, ...);
123 
139 int set_um_string(char **um_str, const char *new_txt);
140 
145 void free_char_tab(char** mat);
146 
165 char *str_replace_char(char* orig, const char old_char, const char *new_str, int free_orig);
166 
179 int mbs_is_char_in(const char *text, const char **list, int nb_elem);
180 
193 int mbs_is_char_in_concat(const char *text, const char *list);
194 
207 int mbs_is_char_i_in_concat(const char *text, const char *list);
208 
224 int mbs_is_char_in_concat_full(const char *text, const char *list, char sep, int case_sens);
225 
233 double*** get_d3Darray_1(int x, int y, int z);
234 
242 double*** get_d3Darray_0(int nb_r, int nb_c, int z);
243 
248 void free_d3Darray_0(double*** array3D);
249 void free_d3Darray_1(double*** array3D);
250 
255 void free_d3Darray_0(double ***array3D);
256 
257 /*
258  * Print values of mbs_data (used for debug)
259  *
260  * WARNING: This function is not updated daily with new functionnalities of MbsData.
261  *
262  */
263 void mbs_print_data(MbsData *mbs_data);
264 
286 void mbs_copy_data(MbsData* s, MbsData* s_copy);
287 
305 double *mbs_data_get_IO(MbsData *mbs, const char *io_name, int in_out);
306 
312 
317 void mbs_reset_data(MbsData* s);
318 
329 int mbs_write_data(MbsData *mbs, char *filename, char *function_name);
330 
362 int mbs_compare_data(MbsData *s1, MbsData *s2, int accelred);
363 
387 int mbs_strncmp(const char* __s1, const char* __s2, size_t n);
411 int mbs_strnicmp(const char* __s1, const char* __s2, size_t n);
412 
421 int mbs_strcmp(const char* __s1, const char* __s2);
422 
431 int mbs_stricmp(const char* __s1, const char* __s2);
432 
448 char* mbs_strndup(const char* input_char, size_t char_size);
449 
450 #ifdef __cplusplus
451 }
452 #endif
453 
454 #endif
get_char_cpy
char * get_char_cpy(const char *fmt,...)
Copy the provided formatted string into a newly allocated memory.
Definition: useful_functions.c:235
MBS_INFO_FAILURE
#define MBS_INFO_FAILURE
Definition: mbs_define.h:32
mbs_msg
void mbs_msg(const char *msg,...)
Send a message.
Definition: mbs_message.c:87
str_replace_char
char * str_replace_char(char *orig, const char old_char, const char *new_str, int free_orig)
Create a copy of a string with a specific char replaced by a string.
Definition: useful_functions.c:306
free_d3Darray_1
void free_d3Darray_1(double ***array3D)
Definition: useful_functions.c:508
get_char_cpy
char * get_char_cpy(const char *fmt,...)
Copy the provided formatted string into a newly allocated memory.
Definition: useful_functions.c:235
free_char_tab
void free_char_tab(char **mat)
release memory for a matrix of chars
Definition: useful_functions.c:294
useful_functions.h
mbs_stricmp
int mbs_stricmp(const char *__s1, const char *__s2)
Compare two char with _stricmp (convert strings to lower case, ignoring case sensitive).
Definition: useful_functions.c:584
mbs_is_char_in_concat
int mbs_is_char_in_concat(const char *text, const char *list)
Check if the provided text is in a concatenated list of text separated by ";".
Definition: useful_functions.c:409
mbs_log
void mbs_log(char *msg,...)
Function for logging messages in a file called "log" where the program is executed.
Definition: useful_functions.c:32
sign
double sign(double a)
sign function
Definition: useful_functions.c:132
mbs_data.h
mbs_strnicmp
int mbs_strnicmp(const char *__s1, const char *__s2, size_t n)
Compares only the first (at most) n bytes of of two chars ignoring the case.
Definition: useful_functions.c:542
free_char_vec
void free_char_vec(char *vec)
release memory for a vector of char
Definition: useful_functions.c:194
mbs_write_data
int mbs_write_data(MbsData *mbs, char *filename, char *function_name)
Write a source with a function allocating and setting a MbsData copy of the provided.
Definition: mbs_data.c:324
mbs_is_char_i_in_concat
int mbs_is_char_i_in_concat(const char *text, const char *list)
Check if the provided text (not case sensitive) is in a concatenated list of text separated by ";".
Definition: useful_functions.c:414
mbs_strndup
char * mbs_strndup(const char *input_char, size_t char_size)
(taken from strdup definition in string.h since C23) Returns a pointer to a null-terminated byte stri...
Definition: useful_functions.c:606
str_replace_char
char * str_replace_char(char *orig, const char old_char, const char *new_str, int free_orig)
Create a copy of a string with a specific char replaced by a string.
Definition: useful_functions.c:306
free_char_vec
void free_char_vec(char *vec)
release memory for a vector of char
Definition: useful_functions.c:194
mbs_define.h
mbs_strcmp
int mbs_strcmp(const char *__s1, const char *__s2)
Compare two char with strcmp.
Definition: useful_functions.c:568
mbs_reset_data
void mbs_reset_data(MbsData *s)
Reset all fields of a MbsData structure to initial values.
Definition: mbs_data.c:306
mbs_matrix.h
mbs_warning_msg
void mbs_warning_msg(const char *msg,...)
Send a warning message.
Definition: mbs_message.c:100
sign
double sign(double a)
sign function
Definition: useful_functions.c:132
get_d3Darray_0
double *** get_d3Darray_0(int nb_r, int nb_c, int z)
create (with memory allocation) a [x times y times z] 3D array of doubles, starting at index 0
Definition: useful_functions.c:486
get_char_vec
char * get_char_vec(int size)
create (with memory allocation) a vector (length l_v) of char
Definition: useful_functions.c:167
get_d3Darray_1
double *** get_d3Darray_1(int x, int y, int z)
create (with memory allocation) a [x times y times z] 3D array of doubles, starting at index 1
Definition: useful_functions.c:478
free_d3Darray_1
void free_d3Darray_1(double ***array3D)
Definition: useful_functions.c:508
mbs_1D_array.h
mbs_is_char_i_in_concat
int mbs_is_char_i_in_concat(const char *text, const char *list)
Check if the provided text (not case sensitive) is in a concatenated list of text separated by ";".
Definition: useful_functions.c:414
free_char_tab
void free_char_tab(char **mat)
release memory for a matrix of chars
Definition: useful_functions.c:294
get_d3Darray_1
double *** get_d3Darray_1(int x, int y, int z)
create (with memory allocation) a [x times y times z] 3D array of doubles, starting at index 1
Definition: useful_functions.c:478
mbs_is_char_in
int mbs_is_char_in(const char *text, const char **list, int nb_elem)
Return the index of the provided text in a list of text.
Definition: useful_functions.c:367
mbs_strndup
char * mbs_strndup(const char *input_char, size_t char_size)
(taken from strdup definition in string.h since C23) Returns a pointer to a null-terminated byte stri...
Definition: useful_functions.c:606
free_d3Darray_0
void free_d3Darray_0(double ***array3D)
release memory for a 3D array of doubles, starting at index 0
Definition: useful_functions.c:513
get_char_cpy_varg
char * get_char_cpy_varg(const char *fmt, va_list argptr)
Definition: useful_functions.c:199
mbs_strcmp
int mbs_strcmp(const char *__s1, const char *__s2)
Compare two char with strcmp.
Definition: useful_functions.c:568
free_d3Darray_0
void free_d3Darray_0(double ***array3D)
release memory for a 3D array of doubles, starting at index 1
Definition: useful_functions.c:513
set_um_string
int set_um_string(char **um_str, const char *new_txt)
Redirect the memory of the string user model to a newly allocated char array.
Definition: useful_functions.c:281
mbs_strncmp
int mbs_strncmp(const char *__s1, const char *__s2, size_t n)
Compares only the first (at most) n bytes of of two chars.
Definition: useful_functions.c:522
get_char_vec
char * get_char_vec(int l_v)
create (with memory allocation) a vector (length l_v) of char
Definition: useful_functions.c:167
mbs_copy_data
void mbs_copy_data(MbsData *s, MbsData *s_copy)
Copy all fields between two MBSdata structures.
Definition: mbs_data.c:165
get_char_tab
char ** get_char_tab(int nb_r, int nb_c)
create (with memory allocation) a [nb_r times nb_c] matrix of chars WARNING: only the first dimension...
Definition: useful_functions.c:178
mbs_strncmp
int mbs_strncmp(const char *__s1, const char *__s2, size_t n)
Compares only the first (at most) n bytes of of two chars.
Definition: useful_functions.c:522
mbs_data_get_IO
double * mbs_data_get_IO(MbsData *mbs, const char *io_name, int in_out)
Return the adress of the specified User IO.
Definition: mbs_data.c:900
mbs_strnicmp
int mbs_strnicmp(const char *__s1, const char *__s2, size_t n)
Compares only the first (at most) n bytes of of two chars ignoring the case.
Definition: useful_functions.c:542
mbs_reset_joints_kine
void mbs_reset_joints_kine(MbsData *s)
Reset joints kinematics (q, qd, qdd) of a MbsData structure to initial values.
Definition: mbs_data.c:295
get_d3Darray_0
double *** get_d3Darray_0(int x, int y, int z)
create (with memory allocation) a [x times y times z] 3D array of doubles, starting at index 0
Definition: useful_functions.c:486
_MBS_ERR_LOW_INVALID
#define _MBS_ERR_LOW_INVALID
Invalid value (include NULL pointer) error number Value is not valid for the function = -8.
Definition: mbs_errors_names.h:152
mbs_print_data
void mbs_print_data(MbsData *mbs_data)
Definition: mbs_data.c:78
get_time_machine
char * get_time_machine()
returns the current time as a String
Definition: useful_functions.c:139
mbs_message.h
mbs_is_char_in_concat_full
int mbs_is_char_in_concat_full(const char *text, const char *list, char sep, int case_sens)
Check if the provided text is in a concatenated list of text.
Definition: useful_functions.c:419
get_char_tab
char ** get_char_tab(int nb_r, int nb_c)
create (with memory allocation) a [nb_r times nb_c] matrix of chars WARNING: only the first dimension...
Definition: useful_functions.c:178
set_char_cpy
int set_char_cpy(char **dest, const char *fmt,...)
Set a copy the provided formatted string into a newly allocated memory.
Definition: useful_functions.c:250
get_time_machine
char * get_time_machine()
returns the current time as a String
Definition: useful_functions.c:139
expo_ten_inf
int expo_ten_inf(double nb)
get log with base 10
Definition: useful_functions.c:97
MbsData
Definition: mbs_data.h:247
mbs_free
void * mbs_free(void *__ptr)
Free the pointor ptr and set it to NULL.
Definition: useful_functions.c:21
expo_ten_inf
int expo_ten_inf(double nb)
get log with base 10
Definition: useful_functions.c:97
MSG_PRE
#define MSG_PRE
Definition: useful_functions.c:19
pow_int
double pow_int(double basis, int expo)
compute efficiently pow with an integer exponent
Definition: useful_functions.c:68
MBS_INFO_SUCCESS
#define MBS_INFO_SUCCESS
Definition: mbs_define.h:30
mbs_is_char_in_concat
int mbs_is_char_in_concat(const char *text, const char *list)
Check if the provided text is in a concatenated list of text separated by ";".
Definition: useful_functions.c:409
mbs_log
void mbs_log(char *msg,...)
Function for logging messages in a file called "log" where the program is executed.
Definition: useful_functions.c:32
mbs_is_char_in_concat_full
int mbs_is_char_in_concat_full(const char *text, const char *list, char sep, int case_sens)
Check if the provided text is in a concatenated list of text.
Definition: useful_functions.c:419
MSG_ERR
#define MSG_ERR
Definition: useful_functions.c:18
set_um_string
int set_um_string(char **um_str, const char *new_txt)
Redirect the memory of the string user model to a newly allocated char array.
Definition: useful_functions.c:281
set_char_cpy
int set_char_cpy(char **dest, const char *fmt,...)
Set a copy the provided formatted string into a newly allocated memory.
Definition: useful_functions.c:250
mbs_is_char_in
int mbs_is_char_in(const char *text, const char **list, int nb_elem)
Return the index of the provided text in a list of text.
Definition: useful_functions.c:367
mbs_stricmp
int mbs_stricmp(const char *__s1, const char *__s2)
Compare two char with _stricmp (convert strings to lower case, ignoring case sensitive).
Definition: useful_functions.c:584
pow_int
double pow_int(double basis, int expo)
compute efficiently pow with an integer exponent
Definition: useful_functions.c:68
mbs_compare_data
int mbs_compare_data(MbsData *s1, MbsData *s2, int accelred)
Compare two MbsData.
Definition: mbs_data.c:604
mbs_free
void * mbs_free(void *__ptr)
Free the pointor ptr and set it to NULL.
Definition: useful_functions.c:21
mbs_errors_names.h