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 
174 double*** get_d3Darray_1(int x, int y, int z);
175 
183 double*** get_d3Darray_0(int nb_r, int nb_c, int z);
184 
189 void free_d3Darray_0(double*** array3D);
190 void free_d3Darray_1(double*** array3D);
191 
196 void free_d3Darray_0(double ***array3D);
197 
198 /*
199  * Print values of mbs_data (used for debug)
200  *
201  * WARNING: This function is not updated daily with new functionnalities of MbsData.
202  *
203  */
204 void mbs_print_data(MbsData *mbs_data);
205 
227 void mbs_copy_data(MbsData* s, MbsData* s_copy);
228 
234 
239 void mbs_reset_data(MbsData* s);
240 
251 int mbs_write_data(MbsData *mbs, char *filename, char *function_name);
252 
284 int mbs_compare_data(MbsData *s1, MbsData *s2, int accelred);
285 
294 int mbs_strcmp(const char* __s1, const char* __s2);
295 
304 int mbs_stricmp(const char* __s1, const char* __s2);
305 
306 #ifdef __cplusplus
307 }
308 #endif
309 
310 #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:196
MBS_INFO_FAILURE
#define MBS_INFO_FAILURE
Definition: mbs_define.h:31
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:283
free_d3Darray_1
void free_d3Darray_1(double ***array3D)
Definition: useful_functions.c:374
get_char_cpy
char * get_char_cpy(const char *fmt,...)
Copy the provided formatted string into a newly allocated memory.
Definition: useful_functions.c:196
free_char_tab
void free_char_tab(char **mat)
release memory for a matrix of chars
Definition: useful_functions.c:271
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:404
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:29
sign
double sign(double a)
sign function
Definition: useful_functions.c:129
mbs_data.h
free_char_vec
void free_char_vec(char *vec)
release memory for a vector of char
Definition: useful_functions.c:191
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:260
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:283
free_char_vec
void free_char_vec(char *vec)
release memory for a vector of char
Definition: useful_functions.c:191
mbs_define.h
mbs_strcmp
int mbs_strcmp(const char *__s1, const char *__s2)
Compare two char with strcmp.
Definition: useful_functions.c:388
mbs_reset_data
void mbs_reset_data(MbsData *s)
Reset all fields of a MbsData structure to initial values.
Definition: mbs_data.c:242
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:129
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:352
get_char_vec
char * get_char_vec(int size)
create (with memory allocation) a vector (length l_v) of char
Definition: useful_functions.c:164
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:344
free_d3Darray_1
void free_d3Darray_1(double ***array3D)
Definition: useful_functions.c:374
mbs_1D_array.h
free_char_tab
void free_char_tab(char **mat)
release memory for a matrix of chars
Definition: useful_functions.c:271
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:344
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:379
mbs_strcmp
int mbs_strcmp(const char *__s1, const char *__s2)
Compare two char with strcmp.
Definition: useful_functions.c:388
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:379
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:258
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:164
mbs_copy_data
void mbs_copy_data(MbsData *s, MbsData *s_copy)
Copy all fields between two MBSdata structures.
Definition: mbs_data.c:101
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:175
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:231
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:352
mbs_print_data
void mbs_print_data(MbsData *mbs_data)
Definition: mbs_data.c:14
get_time_machine
char * get_time_machine()
returns the current time as a String
Definition: useful_functions.c:136
mbs_message.h
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:175
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:228
get_time_machine
char * get_time_machine()
returns the current time as a String
Definition: useful_functions.c:136
expo_ten_inf
int expo_ten_inf(double nb)
get log with base 10
Definition: useful_functions.c:94
MbsData
Definition: mbs_data.h:246
mbs_free
void * mbs_free(void *__ptr)
Free the pointor ptr and set it to NULL.
Definition: useful_functions.c:18
expo_ten_inf
int expo_ten_inf(double nb)
get log with base 10
Definition: useful_functions.c:94
pow_int
double pow_int(double basis, int expo)
compute efficiently pow with an integer exponent
Definition: useful_functions.c:65
MBS_INFO_SUCCESS
#define MBS_INFO_SUCCESS
Definition: mbs_define.h:29
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:29
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:258
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:228
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:404
pow_int
double pow_int(double basis, int expo)
compute efficiently pow with an integer exponent
Definition: useful_functions.c:65
mbs_compare_data
int mbs_compare_data(MbsData *s1, MbsData *s2, int accelred)
Compare two MbsData.
Definition: mbs_data.c:540
mbs_free
void * mbs_free(void *__ptr)
Free the pointor ptr and set it to NULL.
Definition: useful_functions.c:18
mbs_errors_names.h